Run commands, tools and the plugin API through one operations layer

A Speed Dial command, the MCP tool that does the same thing and the plugin
API's preset calls now run one shared operation, so every route accepts and
refuses the same states, with one wording and a code for each refusal. An
import by a command or a tool is one undo step, and import_file adds geometry
only.

The cases where two routes behaved differently now behave the same: a project
is not saved under a .gcode.3mf name, an empty project exports as .3mf but not
as STL, arrange runs from any view and with a gizmo open, a mixed-colour
filament slot is refused as one, a hidden preset is shown before it is
selected, and a layer is refused while the Preview has none.
This commit is contained in:
SoftFever committed 2026-11-12 22:06:10 +08:00
1 parent a9c73c76b2
commit 0616068e26
84 files changed
+6416 -1093

No files matched your search

@@ -0,0 +1,36 @@
name: Check operation calls
# The Speed Dial's command runners, the MCP tools and the plugin API's bindings change the app through
# src/slic3r/GUI/Operations. This fails when one of their files calls an owner method an operation
# stands for and scripts/operation_calls_baseline.txt does not list the line with its reason.
on:
push:
paths:
- 'src/slic3r/GUI/NativeCommands.cpp'
- 'src/slic3r/GUI/Mcp/McpTools*.cpp'
- 'src/slic3r/plugin/host/*.cpp'
- 'scripts/check_operation_calls.py'
- 'scripts/operation_calls_baseline.txt'
- '.github/workflows/check_operation_calls.yml'
pull_request:
paths:
- 'src/slic3r/GUI/NativeCommands.cpp'
- 'src/slic3r/GUI/Mcp/McpTools*.cpp'
- 'src/slic3r/plugin/host/*.cpp'
- 'scripts/check_operation_calls.py'
- 'scripts/operation_calls_baseline.txt'
- '.github/workflows/check_operation_calls.yml'
permissions: {}
jobs:
check_operation_calls:
name: Check operation calls
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Check the callers of the operations layer
run: python3 scripts/check_operation_calls.py
+178 -20
View File
@@ -351,7 +351,8 @@ unchanged number means it never started; otherwise its `ExportRecord` ends `ok`,
`cancelled` or `superseded`. A G-code export with a path is refused while slicing runs, and
`run_action export_gcode` needs a path: without one it would ask in a native file dialog that MCP
can't fill in. The
decision logic is in `McpOperations`, which uses neither wx nor `Plater`.
decision logic is in `Operations/RunStatus`, which uses neither wx nor `Plater` (see The operations
layer).
**Idle.** `wait {for: "idle"}` holds when no modal is open, nothing slices (`Plater::is_slicing_any()`:
the background process, Slice All, a scheduled background update or a pending automatic reslice)
@@ -363,6 +364,144 @@ so a replay or script waiting for idle doesn't wait on itself. Only the job regi
snapshot and the journal are shared between threads, each behind a mutex. All app state is read on
the UI thread.
## The operations layer
Three interfaces ask the app to do things by name: the Speed Dial's commands, the MCP tools, and the
plugin API (`orca.host`). What one of them does is often what another does too: exporting G-code is a
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
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
apply, is a public method of the owner (`Plater`, `Sidebar`, `Tab`, `GCodeViewer`) or a function in
its header: `Tab::can_delete_preset()` is what the tab's Delete and the `delete_preset` tool both ask,
and `locked_save_location()` what the Save preset dialog and `save_preset` both follow. What an
automation caller invokes by name is an operation, for every function that more than one interface
reaches and for every function added from now on. A caller calls an operation to change something
and an owner to read. A tool that changes something through a function with one entry point is left
as it is: nothing can drift there until a second entry point appears, and then the rule applies to it.
**Shape.** An operation is a free function, `Outcome<Result> op(const Args&)`. `Args` and `Result`
are plain structs of bool, int, double, string, path, enum, optional and vector, with fields named
as the tool's arguments are: no JSON, no `wxString`, no pointer to a GUI object. An `Outcome` holds
the result or a `Refusal`:
| Field | What it holds |
|---|---|
| `kind` | `Precondition` (the caller can change something and call again), `Busy` (the same call works later) or `Failed` (it was tried and did not happen) |
| `code` | a stable id, such as `slicing_in_progress` |
| `msgid`, `args` | one English message, marked with `L()`, and the values of its `%1%` placeholders |
| `names` | names that help the caller: the candidates of an ambiguous name, the closest names to an unknown one |
The palette shows `translated()`. A tool and a Python exception carry `english()`, and a tool's
error also carries the code (`code`) and puts the names under the key it has always used (`similar`,
`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
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
tool may still make one call one undo step with `Plater::SingleSnapshot`, as `set_settings` does;
that is the tool's own contract.
**Threads and waits.** An operation runs on the UI thread and returns at once. It does not marshal
and does not wait for background work: it returns a ticket, and a status function, itself an
operation, says how the work stands (`start_gcode_export()` and `gcode_export_state()`;
`start_slice()` with `slice_status()` of `Operations/RunStatus`). The caller owns the loop, the
timeout and the cancel, and reaches the status function through its own way to the UI thread:
`ctx.run_ui()` and `poll_ui()` for a tool, nothing for the palette, `run_on_ui_thread()` for Python.
An operation adds no guard and refuses on the state of the project only; each interface keeps its
own guards.
**Dialogs.** An operation asks nothing of its own. An answer the owner lets a caller give is a field
of `Args`: whether unsaved project changes are refused or dropped (`UnsavedChanges`), whether a
preset's unsaved changes are transferred or dropped (`PresetChanges`). An owner's effect can still
open a dialog of its own (a STEP file's mesh options, the modified-presets question of
`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
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
takes its refusals, raised as the exception type the binding has always raised for that case. Its
way to the UI thread stays its own. `orca.host.preset.process` and `.printer`'s
`begin_update(preset_name)` resolve and select through `resolve_preset()` and `select_preset()`,
and `orca.host.preset.filament.begin_update(slot_number, preset_name)` resolves and assigns through
`resolve_preset()` and `assign_filament_preset()`, with one step of its own between the two: it
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
nothing from it, and `plugin/` includes nothing from `GUI/Mcp`.
| File | Operations | Reached by |
|---|---|---|
| `ExportOps` | `start_gcode_export`, `gcode_export_state` | command `export_gcode`, tool `export`, `run_action` |
| | `export_sliced_3mf`, `export_model_3mf`, `export_stl` | commands `export_sliced_file`, `export_all_sliced_file`, `export_3mf`, `export_stl`; tool `export` |
| | `send_gcode_to_host` | command `send_gcode` |
| `ProjectOps` | `import_models` | command `import_file`, tool `open_files` |
| | `open_project`, `new_project` | tools `open_files`, `new_project` |
| | `save_project_as` | command `save_project_as`, tool `save_project` |
| | `set_instance_count` | command `obj_set_instances` |
| `PlateOps` | `select_plate` | command `plate_goto`; the exports of `ExportOps` that write their file at once, for a plate their caller names |
| | `set_plate_locked` | command `plate_toggle_lock`, tool `set_settings` (the plate's lock icon calls the same owner effect) |
| | `start_arrange` | command `obj_arrange`, tool `arrange` |
| | `start_slice` | commands `slice_and_preview`, `slice_all`; tool `slice` |
| | `show_layer_range` | command `go_to_layer`, tool `set_view` |
| `PresetOps` | `resolve_preset`, `select_preset` | tool `select_preset`, the plugin API's `begin_update(preset_name)` |
| | `assign_filament_preset` | tool `select_preset`, the plugin API's `begin_update(slot_number, preset_name)` (the sidebar's selector calls the same owner effect, `Sidebar::select_filament_preset()`) |
| | `import_presets` | command `import_configs` |
| `RunStatus` | `slice_status`, `export_status`, `classify_plates` | the status rules of a slice and an export, free of wx and `Plater` |
**What every route gets.** An operation holds what every route of its function does, so these are
the same whichever interface asks:
- A project is not saved under a name ending in `.gcode.3mf`, which is a sliced file's name, since a
project file holds no G-code.
- An STL, a sliced file and G-code need objects. A `.3mf` of the model does not: a project that
holds only a Design-tab recipe has none.
- An arrangement shows the Prepare view first, runs with a gizmo open as the toolbar's does, and is
refused while the job worker is busy.
- A slice is requested as the Slice button requests it, with no check of the printer's technology.
- A mixed-colour filament slot is refused as one, since it holds no preset of its own.
- A hidden preset that suits the printer is shown in the selectors and then selected.
- A printer or process selection that leaves another preset selected is a refusal, and that preset
stays selected.
- A layer asked of a Preview that has none is a refusal: the layer slider has a range from the
start, so what counts is whether a print gave it layers (`Ops::layer_count()`). It keeps the last
slice's layers, so a plate that is no longer sliced can still have layers to show.
A check only one route makes stays with that route, as a step of its own before the call:
- The `arrange` tool refuses a locked or an empty plate it was given by index; the `obj_arrange`
command names no plate. Fill bed is the tool's alone.
- The plugin API refuses a filament slot whose preset is empty or does not resolve, since its
transaction edits that preset; the `select_preset` tool only assigns one.
**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.
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.
## Tool catalog
A tool's name says what it does in the words the GUI uses, so a person's request and an agent's search for a
@@ -616,8 +755,12 @@ camera looks.
`PREPARE_STATE_MENU` and `arrange()`, as the plate's Arrange icon does, without its
`last_arrange_job_is_finished()` flag, which a cancelled job never clears; with `fill`, the object's
row selected and `fill_bed_with_instances()` or `fill_bed_with_copies()`, which fill the object's own
plate. Each takes one "Arrange" undo snapshot. It refuses the assemble view, an open gizmo, a locked
or empty plate, `fill` with `plates`, and an object Fill bed refuses (`can_increase_instances()`).
plate. Each takes one "Arrange" undo snapshot. An arrangement shows the Prepare view first and runs
with a gizmo open, as the toolbar's does (`Ops::start_arrange()`, which the `obj_arrange` command
calls too), and is refused while another job runs. Fill bed selects the object's row, so it refuses
the assemble view and an open gizmo as the tools that select do. The tool also refuses a locked or
empty plate given by index, `fill` with `plates`, and an object Fill bed refuses
(`can_increase_instances()`).
`spacing`, `rotate`, `align_y` and `multi_material` go into the current print mode's
`GLCanvas3D::ArrangeSettings`, which both jobs read, by the panel's rules (`apply_arrange_args()`:
Align to Y axis stays off while rotation is on), and `GLCanvas3D::store_arrange_settings()` saves
@@ -870,8 +1013,11 @@ of `compare`), as its lock icon does. The value joins the call's other values in
transaction, so its handling runs as for a typed value. `reset_to` without a null value, and in the
object and part scopes, is refused.
`select_preset` finds the name in the selector the GUI picks from: the sidebar's filament combo of the
slot, or the tab's combo, by the label shown or the internal name. A selector lists the visible,
`select_preset` finds the name in the selector the GUI picks from (`Ops::resolve_preset()`, which the
plugin API's `begin_update()` uses too): the sidebar's filament combo of the
slot, or the tab's combo, by the label shown or the internal name. It then selects the printer or process
preset (`Ops::select_preset()`), or assigns the filament to its slot as a pick in the slot's selector does
(`Ops::assign_filament_preset()`, `Sidebar::select_filament_preset()`). A selector lists the visible,
compatible presets, and a hidden one is a system filament or printer the setup wizard has not added,
which a fresh data folder has for all but a few. Such a name is shown first (`show_hidden_preset()`):
the preset becomes visible in memory and the selectors are rebuilt, as they show the selected preset and
@@ -880,7 +1026,9 @@ stays as it is; the reply names it in `shown`. A printer shown this way also sho
filaments when no shown filament suits it, as adding the printer in the wizard does
(`PresetBundle::load_installed_filaments()`), so the switch lands on one of them rather than on the
default filament. A preset's own name wins over another's alias that reads the same. An incompatible preset is refused as such, since no selector lists it, and an unknown name with
the closest names.
the closest names. A mixed-colour slot is refused as one (`mixed_filament_slot`), since it holds no
preset of its own. A printer or process selection that leaves another preset selected than the one
asked for is refused too (`other_preset_selected`), and that preset stays selected.
`Tab::select_preset()` asks about unsaved changes through `Tab::may_discard_current_dirty_preset()`:
for the preset it leaves, and for each modified preset a process or printer switch may replace (the
@@ -894,7 +1042,7 @@ before anything changes. The GUI's outcomes stay as they are: a modified filamen
process keeps its changes whatever the answer. Without `preset_changes` the prompt opens, as it does for a
person, and the reply is `blocked_by_dialog`. The message box that a printer switch shows when it drops
other extruder variants' values is shown only to a person. With several filament slots the sidebar does
not move the filament tab when a slot's filament changes (`Plater::priv::on_select_preset()`), so no
not move the filament tab when a slot's filament changes (`Plater::priv::filament_preset_picked()`), so no
prompt opens there: the edits stay with the preset the tab edits, and the reply's `modified` lists them.
`new_project` without `preset_changes`, or with `"keep"`, keeps modified presets for the new project, as
@@ -1426,20 +1574,21 @@ with `completes_in_background` that gets a path runs as an export operation and
file is written.
Given a path, a command with a `Path` param skips its file dialog and calls an entry point that has
none. Without a param, it behaves as it does in the palette. The param is an absolute path, or, for
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.
| Command | Takes | Entry point |
|---|---|---|
| `load_project` | `.3mf` | `Plater::load_project(path)`; still asks about unsaved changes |
| `import_file` | model file | `Plater::load_files({path})` |
| `import_configs` | `.json`, `.zip`, `.orca_printer`, `.orca_filament`, `.orca_bundle`; `.gcode` | `MainFrame::import_configs(files, confirm)`; for G-code `MainFrame::load_config_file(path)` |
| `save_project_as` | output `.3mf` | `Plater::save_project(true, path)` |
| `export_gcode` | output `.gcode` | `Plater::export_gcode_to(path)`; completion `Export` |
| `export_sliced_file`, `export_all_sliced_file` | output `.gcode.3mf` | `Plater::export_gcode_3mf(all, path)` |
| `export_stl` | output `.stl` | `Plater::export_stl(..., path)` |
| `export_3mf` | output `.3mf` | `Plater::export_core_3mf(path)` |
| `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 |
@@ -1458,7 +1607,7 @@ Order By. Like those items, they act on the object list's selected rows, which `
|---|---|---|---|
| `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 | `Plater::set_number_of_copies(num)` | no object selected; 0 (use `obj_delete`); a cut object; an unprintable instance |
| `obj_set_instances` | Index: 1-1000 | `Ops::set_instance_count()` | no object selected; 0 (use `obj_delete`); 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 |
@@ -1530,6 +1679,11 @@ Most features need only a Speed Dial command:
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
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.
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,
read-only and unjournaled. Use `mutate_tool()` for anything that changes the app; it runs as a
@@ -1537,8 +1691,11 @@ journaled job under the mutate guard and may be marked `destructive`, and a tool
the app sets `open_world` (see Tool catalog). Build the schema with
`object_schema()`, `prop()`, `enum_prop()` and `array_prop()`. It is validated before the handler
runs, so `arg_string()` and its siblings can read the arguments. Do all wx work in `ctx.run_ui()`,
and get the plater with `ui_plater()`, which fails until the main window is up. Throw `ToolFailure`
with a message the model can act on. Call `settle()` after a change so queued events are handled
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
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
@@ -3464,8 +3621,9 @@ and values read in place of a tool's own, and the error for an unknown tool anot
`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_mcp_operations` the slice and
export outcomes; `test_mcp_replay` parsing, substitution, matchers and await; `test_mcp_ui` labels,
jobs, blocked_by_dialog, admission, slots, idle, journal); `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
parents (with a display), how ImGui items are labelled and named, value
matching and the model-target projection and surface check (`CanvasTarget`); `test_mcp_results`
+27 -14
View File
@@ -70,9 +70,10 @@ coroutine loop are described in
- **Filament:** `slot_number` identifies the slot. If `preset_name` is omitted,
the transaction targets the preset currently assigned to that slot. If supplied,
it requests that preset for the slot and selects it through the normal UI flow;
the name must be among the presets offered by that slot's dropdown, with one
exception: the preset currently assigned to the slot stays targetable even when the
slot's dropdown hides it (for example an incompatible-but-selected preset). Selecting
the name must be among the presets offered by that slot's dropdown, with two
exceptions: a hidden preset that suits the printer is shown in the selectors first,
and the preset currently assigned to the slot stays targetable even when the
slot's dropdown omits it (for example an incompatible-but-selected preset). Selecting
a different preset changes the slot-to-preset mapping. In both cases the transaction
edits the shared preset, not an isolated slot override.
- **Process and printer:** omitting `preset_name` targets the currently active
@@ -80,6 +81,9 @@ coroutine loop are described in
dropdown. It must be one of the choices the dropdown currently offers, rather
than merely any preset present in the collection. This is particularly important
for process presets, whose selectable choices can depend on the current context.
A hidden preset that suits the printer (a system printer or filament the setup
wizard has not added) is shown in the selectors first and stays shown until the
app restarts.
- A transaction targets exactly one preset. Multi-preset transactions are not
supported: applying them would require switching among targets while the
application has only one managed edited copy per collection.
@@ -216,21 +220,30 @@ undo decisions the user already accepted in an earlier dialog. Target resolution
preserves those side effects and then verifies the resulting edited target.
Filament `preset_name` is an additional integration on top of `Tab::select_preset()`:
selecting a different name for a slot also updates the slot-to-preset mapping and its
dependent UI/configuration state, mirroring the filament branch of the Plater's normal
selection path (`PresetBundle::set_filament_preset()` plus the project/selection refresh,
the dynamic filament list, the conditional support-filament flushing recalc, the slot
combo refresh and its AMS sync badge). A mixed-color virtual slot is not targetable.
once the filament tab edits the preset, a different name for a slot is assigned to the
slot by `GUI::Ops::assign_filament_preset()`, the operation the MCP `select_preset` tool
calls too (docs/HLSD/mcp-server.md, "The operations layer"). It does what picking the
preset in the slot's sidebar selector does (`Sidebar::select_filament_preset()`): the
slot's colour settings follow the preset, the slot-to-preset mapping, the dynamic
filament list and the slot's AMS sync badge are updated, the flushing volumes are
recalculated as the automatic calculation's setting says, the project is marked changed
and every plate's slice result is invalidated. The tab is not switched a second time,
which would ask again about changes the first switch transferred. A mixed-color virtual
slot is not targetable.
Process and printer dropdown choices are constrained by visibility and compatibility,
and compatibility may depend on the active context. Target resolution checks the tab
and compatibility may depend on the active context. Target resolution
(`GUI::Ops::resolve_preset()`, the rule the `select_preset` tool resolves by, which
words its refusals) checks the tab
dropdown's actual items before the selection flow, so a target the user cannot pick
fails without raising that flow's unsaved-edit prompt; a name two entries carry is
rejected as ambiguous. A filament `preset_name` resolves against the requested slot's
own sidebar selector rather than the tab's, so that slot's compatibility filter is the
one that applies. A name the slot's dropdown does not show is rejected unless it names
that slot's current assignment (a hidden or incompatible-but-selected preset), which
stays targetable.
rejected as ambiguous. A hidden preset that suits the printer is shown in the
selectors first, as for the tool, and a process or printer selection that leaves
another preset edited is refused by `GUI::Ops::select_preset()`. A filament
`preset_name` resolves against the requested slot's own sidebar selector rather than
the tab's, so that slot's compatibility filter is the one that applies. A name the
slot's dropdown still does not show is rejected unless it names that slot's current
assignment (an incompatible-but-selected preset), which stays targetable.
`commit()` applies its batch through `Tab::apply_preset_config_values`, which parses and
validates the whole batch before touching the edited preset and restores the edited
+4
View File
@@ -184,6 +184,10 @@ src/slic3r/GUI/NotificationManager.hpp
src/slic3r/GUI/NotificationManager.cpp
src/slic3r/GUI/ObjectDataViewModel.cpp
src/slic3r/GUI/OpenGLManager.cpp
src/slic3r/GUI/Operations/ExportOps.cpp
src/slic3r/GUI/Operations/PlateOps.cpp
src/slic3r/GUI/Operations/PresetOps.cpp
src/slic3r/GUI/Operations/ProjectOps.cpp
src/slic3r/GUI/OptionsGroup.cpp
src/slic3r/GUI/OptionStateRegistry.cpp
src/slic3r/GUI/PrintOptionsDialog.cpp
+145
View File
@@ -0,0 +1,145 @@
#!/usr/bin/env python3
"""Checks that the callers of the operations layer make no owner call an operation stands for.
The Speed Dial's command runners, the MCP tools and the plugin API's bindings change the app through
src/slic3r/GUI/Operations (docs/HLSD/mcp-server.md, "Operations"). This script bans, in their source
files, the owner methods those operations call, by method name. A ban is on a name, so it also meets
calls that belong to another function: a banned call that stays is listed in
scripts/operation_calls_baseline.txt, by file and exact source line, under the reason it stays.
The check fails on a banned call that is not listed, and on a listed line that is no longer in the
source, so the list shrinks, or is edited in plain sight.
python3 scripts/check_operation_calls.py # check
python3 scripts/check_operation_calls.py --print # print every banned call found, as baseline lines
It does not catch a rule written again through calls that are not banned, such as a check made of
getters; the rule in the design doc and review cover that.
"""
import argparse
import collections
import glob
import os
import re
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.
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"}
# Owner methods an operation calls, by the operation that stands for them.
BANNED = {
"start_gcode_export": ["export_gcode_to"],
"import_models": ["load_files"],
"open_project": ["load_project"],
"new_project": ["new_project"],
"save_project_as": ["save_project"],
"export_sliced_3mf": ["export_gcode_3mf"],
"export_model_3mf": ["export_core_3mf"],
"export_stl": ["export_stl"],
"select_plate": ["select_plate"],
"set_plate_locked": ["lock_plate", "set_plate_locked"],
"start_arrange": ["set_prepare_state", "arrange"],
"start_slice": ["request_slice"],
"show_layer_range": ["SetHigherValue", "SetLowerValue", "show_layer_range"],
"select_preset": ["select_preset"],
"assign_filament_preset": ["set_filament_preset", "select_filament_preset"],
"import_presets": ["import_configs"],
"set_instance_count": ["set_number_of_copies"],
"send_gcode_to_host": ["send_gcode_legacy"],
"the undo snapshot of an operation": ["take_snapshot"],
}
# A call of a method: obj.name( or obj->name( . An operation is a free function (Ops::name), so the
# operations that share a name with an owner method are not met.
CALL = re.compile(r"(?:\.|->)\s*(" + "|".join(sorted({m for names in BANNED.values() for m in names})) + r")\s*\(")
def caller_files():
files = set()
for pattern in CALLERS:
for path in glob.glob(os.path.join(REPO, pattern)):
rel = os.path.relpath(path, REPO).replace(os.sep, "/")
if rel not in NOT_CALLERS:
files.add(rel)
return sorted(files)
def banned_calls():
"""{file: [stripped source line, ...]} for every line that makes a banned call, in file order."""
found = collections.OrderedDict()
for rel in caller_files():
with open(os.path.join(REPO, rel), encoding="utf-8") as f:
for line in f:
text = line.strip()
if text.startswith("//"):
continue
if CALL.search(text.split("//")[0]):
found.setdefault(rel, []).append(text)
return found
def read_baseline():
"""{file: Counter of listed lines}. A [file] line starts a file's section, # starts a reason."""
listed = collections.OrderedDict()
current = None
with open(os.path.join(REPO, BASELINE), encoding="utf-8") as f:
for number, line in enumerate(f, 1):
text = line.strip()
if not text or text.startswith("#"):
continue
if text.startswith("[") and text.endswith("]") and "(" not in text:
current = listed.setdefault(text[1:-1], collections.Counter())
elif current is None:
sys.exit(f"{BASELINE}:{number}: a source line before any [file] section")
else:
current[text] += 1
return listed
def main():
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--print", action="store_true", help="print every banned call found, as baseline lines")
args = ap.parse_args()
found = banned_calls()
if args.print:
for rel, lines in found.items():
print(f"[{rel}]")
for text in lines:
print(text)
print()
return 0
listed = read_baseline()
problems = []
for rel, lines in found.items():
left = collections.Counter(lines)
left.subtract(listed.get(rel, collections.Counter()))
for text, count in left.items():
if count > 0:
problems.append(f"{rel}: a banned owner call that is not in {BASELINE}:\n {text}")
for rel, counts in listed.items():
left = collections.Counter(counts)
left.subtract(collections.Counter(found.get(rel, [])))
for text, count in left.items():
if count > 0:
problems.append(f"{BASELINE}: [{rel}] lists a line the source no longer has:\n {text}")
if problems:
print("\n".join(problems))
print("\nA command runner, a tool or a plugin API binding changes the app through an operation of "
"src/slic3r/GUI/Operations.\nCall the operation, or, where the call belongs to another function or to "
f"a path that asks a person, list the line in {BASELINE} under its reason.")
return 1
calls = sum(len(lines) for lines in found.values())
print(f"{calls} banned owner calls in {len(caller_files())} caller files, all listed in {BASELINE}")
return 0
if __name__ == "__main__":
sys.exit(main())
+54
View File
@@ -0,0 +1,54 @@
# Owner calls that scripts/check_operation_calls.py bans in the callers of the operations layer and
# that stay where they are, by file and exact source line (trimmed), each under the reason it stays.
# A [file] line starts a file's lines; a # line is a reason for the lines after it.
#
# The check fails on a banned call that is not here and on a line here that the source no longer has.
# Generate candidates with: python3 scripts/check_operation_calls.py --print
[src/slic3r/GUI/NativeCommands.cpp]
# The asking path of a command: with no param, and for load_project with or without one, the command
# 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);
plater->set_number_of_copies();
# Another function that uses the same owner method: every object as its own STL, and the Draco exports.
plater->export_stl(false, false, true);
plater->export_stl(false, false, true, FT_STL, from_path(*dir));
plater->export_stl(false, false, false, FT_DRC);
plater->export_stl(false, false, true, FT_DRC);
# Another function that uses the same owner method: orient, which leaves a plate-only state behind as arrange does.
plater->set_prepare_state(Job::PREPARE_STATE_DEFAULT);
[src/slic3r/GUI/Mcp/McpToolsConfig.cpp]
# The undo step of a tool whose function has one automation entry point (set_settings' object, plate
# and project scopes).
plater.take_snapshot("Move object");
plater.take_snapshot("Plate Settings");
plater.take_snapshot("Change object settings");
# A tool selecting the plate it was given before its own work, as the plate's settings icon does.
plater.select_plate(index);
# Another function that uses the same owner method: set_settings makes the filament tab edit a slot's
# preset, and delete_preset selects the preset, deletes it and selects back.
if (!tab->select_preset(name))
if (!tab->select_preset(name))
tab->select_preset(selected);
[src/slic3r/GUI/Mcp/McpToolsLayers.cpp]
# 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/McpToolsScene.cpp]
# The undo step of a tool whose function has one automation entry point (transform).
plater.take_snapshot("Transform object");
plater.take_snapshot("Transform part", UndoRedo::SnapshotType::GizmoAction);
[src/slic3r/plugin/host/PluginHostPresets.cpp]
# The plugin API's own step between resolving a filament and assigning it: its transaction edits the
# preset, so the filament tab is made to edit it first, and a declined prompt ends the call there.
if (!tab->select_preset(target))
+6 -1
View File
@@ -97,6 +97,10 @@ std::pair<double, double> cornering_end_limits(const DynamicPrintConfig& printer
return has_junction_deviation(printer) ? std::make_pair(0.3, 0.25) : std::make_pair(100., 20.);
}
double clamp_calib_temp(double temperature) { return std::clamp(temperature, kCalibTempMin, kCalibTempMax); }
double round_calib_temp(double temperature) { return std::floor(temperature / kCalibTempBlock) * kCalibTempBlock; }
CalibParamsError check_calib_params(const Calib_Params& p, const DynamicPrintConfig& printer)
{
using E = CalibParamsError;
@@ -104,7 +108,8 @@ CalibParamsError check_calib_params(const Calib_Params& p, const DynamicPrintCon
const auto* flavor = printer.option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor");
const bool rrf = flavor != nullptr && flavor->value == GCodeFlavor::gcfRepRapFirmware;
switch (p.mode) {
case CalibMode::Calib_Temp_Tower: return p.start > 500 || p.end < 155 || p.end > p.start - 5 ? E::Range : E::None;
case CalibMode::Calib_Temp_Tower:
return p.start > kCalibTempMax || p.end < kCalibTempMin || p.end > p.start - kCalibTempBlock ? E::Range : E::None;
case CalibMode::Calib_Vol_speed_Tower: return p.start <= 0 || p.step <= 0 || p.end < p.start + p.step ? E::Range : E::None;
case CalibMode::Calib_PA_Tower:
case CalibMode::Calib_PA_Line:
+6
View File
@@ -77,6 +77,12 @@ bool has_junction_deviation(const DynamicPrintConfig& printer);
// are junction deviation or jerk values, as the printer corners.
Calib_Params calib_default_params(CalibMode mode, const DynamicPrintConfig& printer, bool bowden = false);
// A temperature tower's start and end, as its dialog takes them when a field loses focus: brought into
// the range a tower is made for, then rounded down to the tower's blocks.
inline constexpr double kCalibTempMin = 155., kCalibTempMax = 500., kCalibTempBlock = 5.;
double clamp_calib_temp(double temperature);
double round_calib_temp(double temperature);
// The first rule of its dialog that `params` breaks for its mode on `printer`, in the order the dialog
// checks them. Each dialog shows its own message for the error.
enum class CalibParamsError { None, Range, Damping, AccelBelowSpeed, BeltMethod };
+12 -2
View File
@@ -147,6 +147,18 @@ set(SLIC3R_GUI_SOURCES
GUI/ActionReplayDialog.hpp
GUI/NativeCommands.cpp
GUI/NativeCommands.hpp
GUI/Operations/ExportOps.cpp
GUI/Operations/ExportOps.hpp
GUI/Operations/Outcome.cpp
GUI/Operations/Outcome.hpp
GUI/Operations/PlateOps.cpp
GUI/Operations/PlateOps.hpp
GUI/Operations/PresetOps.cpp
GUI/Operations/PresetOps.hpp
GUI/Operations/ProjectOps.cpp
GUI/Operations/ProjectOps.hpp
GUI/Operations/RunStatus.cpp
GUI/Operations/RunStatus.hpp
GUI/SyntheticInput.cpp
GUI/SyntheticInput.hpp
GUI/Mcp/CanvasTarget.cpp
@@ -159,8 +171,6 @@ set(SLIC3R_GUI_SOURCES
GUI/Mcp/McpHttpServer.hpp
GUI/Mcp/McpJournal.cpp
GUI/Mcp/McpJournal.hpp
GUI/Mcp/McpOperations.cpp
GUI/Mcp/McpOperations.hpp
GUI/Mcp/McpPersonRun.cpp
GUI/Mcp/McpPersonRun.hpp
GUI/Mcp/McpProtocol.cpp
+7
View File
@@ -26,6 +26,10 @@ enum class AppActionKind { Plugin, Command };
// Result of running an AppAction, in the action layer's own vocabulary. Concrete
// actions translate their runner-specific result into this generic shape.
namespace Ops {
struct Refusal;
}
struct AppActionRunResult
{
enum class Level { Success, Info, Error, Busy };
@@ -39,6 +43,9 @@ struct AppActionRunResult
// (the new object order, the object an Assemble made). run_action adds its fields to the reply;
// 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.
std::shared_ptr<const Ops::Refusal> refusal;
};
// Tag carrying a precomputed action id, used by the explicit-id ctor below. It exists so the
+16
View File
@@ -2904,6 +2904,22 @@ void GCodeViewer::update_sequential_view_current(unsigned int first, unsigned in
#endif // ENABLE_ACTUAL_SPEED_DEBUG
}
void GCodeViewer::show_layer_range(std::optional<int> low, int high)
{
if (m_layers_slider == nullptr)
return;
m_layers_slider->SetHigherValue(high);
if (low)
m_layers_slider->SetLowerValue(*low);
else if (m_layers_slider->is_one_layer())
m_layers_slider->SetLowerValue(high);
m_layers_slider->set_as_dirty();
if (m_moves_slider != nullptr) {
m_moves_slider->SetHigherValue(m_moves_slider->GetMaxValue());
m_moves_slider->set_as_dirty();
}
}
void GCodeViewer::enable_moves_slider(bool enable) const
{
bool render_as_disabled = !enable;
+6
View File
@@ -515,6 +515,12 @@ public:
/* BBS IMSlider */
IMSlider *get_moves_slider() { return m_moves_slider; }
IMSlider *get_layers_slider() { return m_layers_slider; }
// Shows layers `low`..`high` (slider ticks) with every move of the top one, as dragging the layer
// slider's thumbs does: the upper thumb, then the lower one. Where the slider shows one layer at a
// time the two are one, so that layer is `low`. Without `low` the upper thumb alone is moved, and the
// slider brings the lower one to `high` as it does under the mouse: when `high` is at or below it,
// and always where it shows one layer at a time.
void show_layer_range(std::optional<int> low, int high);
void enable_moves_slider(bool enable) const;
void update_moves_slider(bool set_to_max = false);
void update_layers_slider_mode();
+1 -1
View File
@@ -7007,7 +7007,7 @@ void GLCanvas3D::_render_arrange_menu(float left, float right, float bottom, flo
{
if (settings_out.enable_rotation) { // do not allow align to Y axis if rotation is enabled
imgui->disabled_begin(true);
settings_out.align_to_y_axis = false;
settings_out.apply_option_rules();
}
imgui->bbl_checkbox(_L("Align to Y axis"), settings_out.align_to_y_axis);
+10
View File
@@ -624,6 +624,16 @@ public:
//BBS: add more arrangeSettings
bool is_seq_print = false;
bool align_to_y_axis = false;
// The Arrange options panel's rule between two of its options: Align to Y axis is off while auto
// rotation is on. Returns whether that turned it off.
bool apply_option_rules()
{
const bool turned_off = enable_rotation && align_to_y_axis;
if (turned_off)
align_to_y_axis = false;
return turned_off;
}
};
struct OrientSettings
+14 -10
View File
@@ -2565,6 +2565,14 @@ std::vector<const char*> primitive_size_names(const std::string& type_name)
return {};
}
// A dimension a primitive can have.
static bool is_primitive_dimension(double value) { return std::isfinite(value) && value > 0.; }
bool is_primitive_size(const std::string& type_name, const std::vector<double>& size)
{
return size.size() == primitive_size_names(type_name).size() && std::all_of(size.begin(), size.end(), is_primitive_dimension);
}
// The dimensions the size dialog asks for, filled with the default size of the primitive.
static std::vector<PrimitiveSizeDialog::Field> primitive_size_fields(const std::string& type_name)
{
@@ -2587,27 +2595,23 @@ static void apply_saved_primitive_size(std::vector<PrimitiveSizeDialog::Field>&
{
std::vector<std::string> tokens;
boost::split(tokens, saved, boost::is_space(), boost::token_compress_on);
if (tokens.size() != fields.size())
return;
std::vector<double> values;
for (const std::string& token : tokens) {
const double value = string_to_double_decimal_point(token);
if (!std::isfinite(value) || value <= 0.)
return;
values.push_back(value);
}
for (const std::string& token : tokens)
values.push_back(string_to_double_decimal_point(token));
if (values.size() != fields.size() || !std::all_of(values.begin(), values.end(), is_primitive_dimension))
return;
for (size_t i = 0; i < fields.size(); ++i)
fields[i].value = values[i];
}
// The size given, when it has a value per field. Otherwise interactive starts from the size the user saved and asks
// for the size unless the user turned the dialog off, and a call that is not interactive gets the built-in default
// size. nullopt when the user cancels or the given size has the wrong number of values.
// size. nullopt when the user cancels or the given size is not one for the shape (is_primitive_size()).
static std::optional<std::vector<double>> primitive_size(const std::string& type_name, bool interactive, const std::vector<double>& given)
{
std::vector<PrimitiveSizeDialog::Field> fields = primitive_size_fields(type_name);
if (!given.empty())
return given.size() == fields.size() ? std::optional(given) : std::nullopt;
return is_primitive_size(type_name, given) ? std::optional(given) : std::nullopt;
AppConfig* app_config = wxGetApp().app_config;
if (interactive && !fields.empty()) {
apply_saved_primitive_size(fields, app_config->get("primitive_size", type_name));
+3
View File
@@ -70,6 +70,9 @@ void set_import_volume_order(ModelObject& object, bool sort_names);
// The dimensions the Primitive size dialog asks for a shape ("Cube", "Cylinder", "Sphere", "Cone", "Disc", "Torus"), in its
// order, as untranslated labels; none for another name.
std::vector<const char*> primitive_size_names(const std::string& type_name);
// Whether `size` is a size for that shape: one value per dimension the dialog asks for, each a number above 0.
// A name the dialog asks nothing for takes the empty size alone.
bool is_primitive_size(const std::string& type_name, const std::vector<double>& size);
// The layer heights the height range editor accepts for a range printed with filament extruder_idx (0 = the
// object's): the printer's min_layer_height and max_layer_height, the latter 75 % of the nozzle diameter when 0.
+2
View File
@@ -70,6 +70,8 @@ public:
int GetMinValue() const { return m_min_value; }
int GetMaxValue() const { return m_max_value; }
// How many values the slider was given (SetSliderValues()): none until then, whatever its range says.
size_t values_count() const { return m_values.size(); }
double GetMinValueD() { return m_values.empty() ? 0. : m_values[m_min_value]; }
double GetMaxValueD() { return m_values.empty() ? 0. : m_values[m_max_value]; }
int GetLowerValue() const { return m_lower_value; }
+1 -2
View File
@@ -149,8 +149,7 @@ void describe_command(Builder& b, const std::string& key, const std::string& par
b.flag(StepFlag::ChangesPresets);
b.replace("app_asked");
}
if (one_of(key, {"load_project", "new_project"}) ||
(key == "import_file" && file && has_extension(*file, {".3mf", ".gcode", ".bgcode"}))) {
if (one_of(key, {"load_project", "new_project"})) {
b.flag(StepFlag::ReplacesProject);
b.replace("app_asked");
}
+15 -2
View File
@@ -42,6 +42,11 @@ class IMSlider;
class PartPlateList;
class Plater;
namespace Ops {
struct ExportTicket;
struct Refusal;
} // namespace Ops
namespace Mcp {
class McpService;
@@ -94,6 +99,8 @@ nlohmann::json array_prop(nlohmann::json items, const std::string& description);
// 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);
// 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);
@@ -117,9 +124,15 @@ void settle(ToolContext& ctx);
// UI thread only.
Plater& ui_plater();
// What a tool says of a plate index the project does not have: the index, and the plates there are.
// What a tool says of a plate index the project does not have: the index, and the plates there are
// (Ops::no_such_plate()'s text).
std::string no_such_plate(int plate, int count);
// What a tool replies when an operation refuses: the refusal's English text, then `hint` when the tool
// has something to add for an agent, with the refusal's code as `code` and the names it carries under
// `names_key` when the tool gives one.
ToolFailure refused(const Ops::Refusal& refusal, const std::string& hint = {}, const char* names_key = nullptr);
// Typed argument access with defaults; schema validation has already checked the types.
std::string arg_string(const nlohmann::json& args, const char* key, const std::string& fallback = {});
int arg_int(const nlohmann::json& args, const char* key, int fallback);
@@ -356,7 +369,7 @@ nlohmann::json page(const nlohmann::json& items, const nlohmann::json& args, std
// Waits for a G-code export started between Plater export sequence numbers `before` and `after`
// (unchanged = it never started: `rejection` explains why) and reports how it ended; `revision` is
// the project revision when it started.
ToolResult await_gcode_export(ToolContext& ctx, uint64_t before, uint64_t after, uint64_t revision, const std::string& rejection);
ToolResult await_gcode_export(ToolContext& ctx, const Ops::ExportTicket& ticket);
// Polls `poll` on the UI thread every 200 ms until it returns a non-null value or `timeout`
// passes; throws ToolFailure on timeout or cancellation.
+36 -22
View File
@@ -1,7 +1,6 @@
// search_actions and run_action: every Speed Dial action - built-in commands, plates, recent projects,
// plugin scripts and pages, and (on request) settings - is reachable through these two tools.
#include "McpOperations.hpp"
#include "slic3r/GUI/I18N.hpp"
#include "McpService.hpp"
#include "McpTools.hpp"
@@ -13,6 +12,9 @@
#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>
@@ -161,25 +163,19 @@ std::string other_catalog_hint(const ToolRegistry& registry, const std::string&
return {};
}
ToolResult await_gcode_export(ToolContext& ctx, uint64_t before, uint64_t after, uint64_t revision, const std::string& rejection)
ToolResult await_gcode_export(ToolContext& ctx, const Ops::ExportTicket& ticket)
{
if (after == before)
return ToolResult::error(rejection.empty() ? "The export did not start" : rejection);
json done = poll_ui(
ctx,
[before, after, revision]() -> json {
Plater& plater = ui_plater();
auto run = plater.export_run(after);
std::optional<ExportRecord> record;
if (run) {
record = ExportRecord{run->seq, run->path, run->finished, run->ok, run->cancelled, run->error, run->revision_at_finish};
}
const ExportStatus status = export_status(before, after, record, revision);
if (status == ExportStatus::Pending)
[&ticket]() -> json {
ui_plater();
std::string error;
const Ops::ExportStatus status = Ops::gcode_export_state(ticket, &error);
if (status == Ops::ExportStatus::Pending)
return json();
json out{{"export", to_string(status)}, {"path", run ? run->path : std::string()}};
if (run && !run->error.empty())
out["error"] = run->error;
json out{{"export", Ops::to_string(status)}, {"path", ticket.path}};
if (!error.empty())
out["error"] = error;
return out;
},
std::chrono::minutes(10), "the export to finish");
@@ -243,6 +239,7 @@ void register_action_tools(McpService& service)
[&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 {
ActionRegistry& actions = registry_or_fail();
const AppAction& action = find_action(actions, id, service.registry());
@@ -262,24 +259,41 @@ void register_action_tools(McpService& service)
}
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)
out.update({{"before", before}, {"after", plater->export_seq()}, {"revision", revision}});
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;
});
// 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 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>());
return await_gcode_export(ctx, started["before"], started["after"], started["revision"], started["message"]);
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);
}
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>());
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"];
+15 -3
View File
@@ -4,6 +4,8 @@
#include "McpTypes.hpp"
#include "UiInspector.hpp"
#include "slic3r/GUI/Operations/Outcome.hpp"
#include "slic3r/GUI/Operations/PlateOps.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/MainFrame.hpp"
@@ -70,6 +72,12 @@ ToolDef inspect_tool(std::string name, std::string title, std::string descriptio
return d;
}
ToolDef reaching(std::vector<std::string> operations, ToolDef def)
{
def.operations = std::move(operations);
return def;
}
ToolDef mutate_tool(std::string name, std::string title, std::string description, json schema, ToolHandler handler, bool destructive)
{
ToolDef d;
@@ -227,10 +235,14 @@ std::string arg_string(const json& args, const char* key, const std::string& fal
return it != args.end() && it->is_string() ? it->get<std::string>() : fallback;
}
std::string no_such_plate(int plate, int count)
std::string no_such_plate(int plate, int count) { return Ops::no_such_plate(plate, count).english(); }
ToolFailure refused(const Ops::Refusal& refusal, const std::string& hint, const char* names_key)
{
return "Plate " + std::to_string(plate) + " does not exist (the project has " +
(count == 1 ? "plate 0 only" : "plates 0.." + std::to_string(count - 1)) + ")";
json details{{"code", refusal.code}};
if (names_key != nullptr)
details[names_key] = refusal.names;
return ToolFailure(refusal.english() + (hint.empty() ? "" : " " + hint), std::move(details));
}
int arg_int(const json& args, const char* key, int fallback)
+79 -179
View File
@@ -18,6 +18,9 @@
#include "slic3r/GUI/IMSlider.hpp"
#include "slic3r/GUI/MainFrame.hpp"
#include "slic3r/GUI/ObjectDataViewModel.hpp"
#include "slic3r/GUI/Operations/Outcome.hpp"
#include "slic3r/GUI/Operations/PlateOps.hpp"
#include "slic3r/GUI/Operations/PresetOps.hpp"
#include "slic3r/GUI/PartPlate.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/PresetComboBoxes.hpp"
@@ -170,91 +173,22 @@ std::map<std::string, std::string> setting_places(Preset::Type type)
// Preset names that share the most words with `name`, those compatible with the printer first, for a
// name no preset has.
json similar_presets(const PresetCollection& presets, const std::string& name)
{
std::vector<std::string> words;
std::istringstream in(lower(name));
for (std::string w; in >> w;)
words.push_back(w);
std::vector<std::pair<int, std::string>> scored;
for (std::size_t i = 0; i < presets.size(); ++i) {
const Preset& p = presets.preset(i);
if (p.is_default)
continue;
const std::string n = lower(p.name);
const int matched = int(std::count_if(words.begin(), words.end(), [&n](const std::string& w) { return n.find(w) != std::string::npos; }));
if (matched > 0)
scored.emplace_back(-(2 * matched + (p.is_compatible ? 1 : 0)), p.name);
}
std::sort(scored.begin(), scored.end());
json out = json::array();
for (std::size_t i = 0; i < scored.size() && i < 5; ++i)
out.push_back(scored[i].second);
return out;
}
json similar_presets(const PresetCollection& presets, const std::string& name) { return Ops::similar_preset_names(presets, name); }
// The presets `name` names, by name or alias, that `keep` accepts. The real presets, not the edited copy. UI thread.
template<class Keep> std::vector<Preset*> presets_named(PresetCollection& presets, const std::string& name, Keep keep)
// What select_preset replies when a preset operation refuses: the hint an agent can act on, and the names
// under the key each refusal has had here.
ToolFailure preset_refused(const Ops::Refusal& refusal)
{
const std::string want = Preset::remove_suffix_modified(name);
std::vector<Preset*> found;
for (std::size_t i = 0; i < presets.size(); ++i)
if (Preset& p = presets.preset(i, true); (p.name == want || p.alias == want) && keep(p))
found.push_back(&p);
return found;
}
// Shows the hidden preset `name` names in the selectors, as they show the preset selected and the filaments an AMS
// holds: in memory, so the setup wizard's list, and with it what the next start shows, stays as it is. A hidden
// preset is one the wizard has not added (a filament, a printer model), not a refusal, so selecting one by name
// needs no detour through the wizard. Only a compatible one, as the selectors list no other. Returns its name, empty
// when `name` names no hidden compatible preset. UI thread.
std::string show_hidden_preset(PresetCollection& presets, const std::string& name)
{
std::vector<Preset*> hidden = presets_named(presets, name, [](const Preset& p) { return !p.is_visible && p.is_compatible; });
// A preset's own name wins over another's alias that reads the same ("Generic PLA").
const std::string want = Preset::remove_suffix_modified(name);
const auto exact = std::find_if(hidden.begin(), hidden.end(), [&want](const Preset* p) { return p->name == want; });
if (exact != hidden.end())
hidden = {*exact};
if (hidden.size() > 1) {
json names = json::array();
for (const Preset* p : hidden)
names.push_back(p->name);
throw ToolFailure("\"" + name + "\" names several hidden presets; use the internal name", {{"presets", std::move(names)}});
}
if (hidden.empty())
return {};
hidden.front()->is_visible = true;
return hidden.front()->name;
}
// Shows the default filaments of a printer show_hidden_preset() showed when no shown filament suits it, as adding the
// printer in the setup wizard does (PresetBundle::load_installed_filaments()), so selecting the printer lands on
// one of them rather than on the default filament. In memory, as the printer is. UI thread.
void show_default_filaments(PresetBundle& bundle, const std::string& printer_name)
{
const Preset* printer = bundle.printers.find_preset(printer_name, false);
const VendorProfile::PrinterModel* model = printer != nullptr ? PresetUtils::system_printer_model(*printer) : nullptr;
if (model == nullptr)
return;
const PresetWithVendorProfile with_vendor = bundle.printers.get_preset_with_vendor_profile(*printer);
for (const Preset& filament : bundle.filaments)
if (filament.is_visible && is_compatible_with_printer(bundle.filaments.get_preset_with_vendor_profile(filament), with_vendor))
return;
for (const std::string& name : model->default_materials)
if (Preset* filament = bundle.filaments.find_preset(name, false, true); filament != nullptr && filament->is_system)
filament->is_visible = true;
}
// The refusal of a name `selector` does not list: incompatible with the printer, or no preset's name, with the
// closest names. UI thread.
ToolFailure not_offered(PresetCollection& presets, const std::string& name, const std::string& selector)
{
if (!presets_named(presets, name, [](const Preset& p) { return !p.is_compatible; }).empty())
return ToolFailure("\"" + name + "\" is not compatible with the selected printer (list_presets include_incompatible "
"lists such presets)");
return ToolFailure(selector + " does not offer \"" + name + "\" (see list_presets)", {{"similar", similar_presets(presets, name)}});
const std::string code = refusal.code;
if (code == "preset_not_offered")
return refused(refusal, "See list_presets.", "similar");
if (code == "ambiguous_hidden_preset")
return refused(refusal, "", "presets");
if (code == "preset_incompatible")
return refused(refusal, "list_presets include_incompatible lists such presets.");
if (code == "transfer_not_offered")
return refused(refusal, "Pass preset_changes: \"discard\", or save_preset first.");
return refused(refusal);
}
struct ConfigTarget
@@ -719,10 +653,12 @@ ToolResult set_plate_settings(const json& args, ToolContext& ctx)
plater.take_snapshot("Plate Settings");
plater.apply_plate_settings(index, bed_type, first_layer, other_layers, sequence, spiral);
}
if (values_in.contains("locked") && values_in["locked"].get<bool>() != plate.is_locked()) {
plater.take_snapshot("lock partplate");
plates.lock_plate(index, values_in["locked"].get<bool>());
plater.set_current_canvas_as_dirty();
if (values_in.contains("locked")) {
Ops::SetPlateLockedArgs lock;
lock.plate = index;
lock.locked = values_in["locked"].get<bool>();
if (const Ops::Outcome<Ops::PlateLocked> locked = Ops::set_plate_locked(lock); !locked)
throw refused(locked.refusal());
}
if (rename)
plater.rename_plate(index, values_in["name"].get<std::string>());
@@ -1106,13 +1042,14 @@ bool save_preset_inside_project(const PresetCollection& presets, const std::stri
throw ToolFailure("Preset \"" + name + "\" already exists" +
(existing != nullptr && !existing->is_compatible ? " and is incompatible with the current printer" : "") +
"; pass overwrite: true to replace it");
if (existing == nullptr)
// The dialog locks the choice to where an existing preset is (locked_save_location()).
const std::optional<bool> locked = locked_save_location(presets, name);
if (!locked)
return arg_bool(args, "inside_project", presets.get_edited_preset().is_project_embedded);
// The dialog locks the choice to where the existing preset is.
if (args.contains("inside_project") && args["inside_project"].get<bool>() != existing->is_project_embedded)
throw ToolFailure("Preset \"" + name + "\" is " + (existing->is_project_embedded ? "kept inside the project" : "a user preset") +
if (args.contains("inside_project") && args["inside_project"].get<bool>() != *locked)
throw ToolFailure("Preset \"" + name + "\" is " + (*locked ? "kept inside the project" : "a user preset") +
" and is saved there; leave inside_project out");
return existing->is_project_embedded;
return *locked;
}
json option_meta(const ConfigOptionDef& def)
@@ -1375,21 +1312,20 @@ json check_preset_deletable(const PresetCollection& presets, const std::string&
const Preset* preset = presets.find_preset(name, false);
if (preset == nullptr)
throw ToolFailure(std::string("No ") + type + " preset \"" + name + "\" (see list_presets)", {{"similar", similar_presets(presets, name)}});
// The tab shows its Delete button for these only (Tab::update_btns_enabling()).
if (preset->is_system || preset->is_default)
// The tab's own rule (Tab::can_delete_preset()), worded for an agent.
std::vector<std::string> inherited_by;
switch (Tab::can_delete_preset(presets, *preset, &inherited_by)) {
case Tab::DeleteBlock::System:
throw ToolFailure("\"" + name + "\" is a system preset; only user presets and presets inside the project can be deleted");
if (preset->is_from_bundle())
case Tab::DeleteBlock::FromBundle:
throw ToolFailure("\"" + name + "\" comes from a preset bundle; only user presets and presets inside the project can be deleted");
case Tab::DeleteBlock::InheritedFrom:
throw ToolFailure("\"" + name + "\" cannot be deleted while other presets inherit from it; delete them first",
{{"inherited_by", inherited_by}});
case Tab::DeleteBlock::None: break;
}
if (presets.get_preset_base(*preset) != preset)
return json::object();
// A base preset: the tab refuses it while presets inherit from it, since they would no longer load.
json children = json::array();
for (const Preset& p : presets)
if (p.inherits() == preset->name)
children.push_back(p.name);
if (!children.empty())
throw ToolFailure("\"" + name + "\" cannot be deleted while other presets inherit from it; delete them first",
{{"inherited_by", std::move(children)}});
// A custom printer takes the user presets made for it alone with it (Tab::select_preset()).
json attached = json::object();
if (presets.type() == Preset::TYPE_PRINTER)
@@ -1438,10 +1374,12 @@ std::vector<double> check_flush_multipliers(std::vector<double> multipliers, std
multipliers = std::vector<double>(nozzles, multipliers.front());
if (multipliers.size() != nozzles)
throw ToolFailure("flush_multiplier takes one value per nozzle (" + std::to_string(nozzles) + "), or one for all");
// The Flushing volumes dialog's range (g_min_flush_multiplier, g_max_flush_multiplier).
// The Flushing volumes dialog's range.
for (const double m : multipliers)
if (m < 0. || m > 3.)
throw ToolFailure("flush_multiplier " + to_config_string(json(m)) + " is outside 0..3, the Flushing volumes dialog's range");
if (m < g_min_flush_multiplier || m > g_max_flush_multiplier)
throw ToolFailure("flush_multiplier " + to_config_string(json(m)) + " is outside " +
to_config_string(json(double(g_min_flush_multiplier))) + ".." +
to_config_string(json(double(g_max_flush_multiplier))) + ", the Flushing volumes dialog's range");
return multipliers;
}
@@ -1910,7 +1848,7 @@ void register_config_tools(McpService& service)
{"type"}),
[](const json& args, ToolContext& ctx) { return ToolResult::ok(ctx.run_ui([&] { return list_presets(args); })); }));
reg.add(mutate_tool(
reg.add(reaching({"resolve_preset", "select_preset", "assign_filament_preset"}, mutate_tool(
"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 "
@@ -1930,84 +1868,46 @@ void register_config_tools(McpService& service)
const std::string name = arg_string(args, "name");
const std::string changes = arg_string(args, "preset_changes");
json result = ctx.run_ui([&]() -> json {
Plater& plater = ui_plater();
PresetBundle& bundle = *wxGetApp().preset_bundle;
Tab* tab = wxGetApp().get_tab(type);
if (tab == nullptr)
throw ToolFailure("The settings tab is not available");
const int slot = arg_int(args, "filament_slot", 1);
PlaterPresetComboBox* filament_combo = nullptr;
int filament_item = -1;
std::string target = name;
std::string shown;
if (type == Preset::TYPE_FILAMENT) {
auto& combos = plater.sidebar().combos_filament();
if (slot < 1 || slot > int(combos.size()) || combos[size_t(slot - 1)] == nullptr)
throw ToolFailure("filament_slot must be 1.." + std::to_string(combos.size()));
filament_combo = combos[size_t(slot - 1)];
auto match = filament_combo->find_by_name(name);
if (match.item < 0 && !match.ambiguous && !(shown = show_hidden_preset(bundle.filaments, name)).empty()) {
for (PlaterPresetComboBox* combo : combos)
if (combo != nullptr)
combo->update();
match = filament_combo->find_by_name(shown);
}
if (match.ambiguous)
throw ToolFailure("\"" + name + "\" is ambiguous in filament slot " + std::to_string(slot) + "'s selector; use the internal name");
if (match.item < 0)
throw not_offered(bundle.filaments, name, "Filament slot " + std::to_string(slot));
filament_item = match.item;
target = match.internal_name;
} else if (TabPresetComboBox* combo = tab->get_combo_box(); combo != nullptr && combo->GetCount() > 0) {
auto match = combo->find_by_name(name);
if (match.item < 0 && !match.ambiguous && !(shown = show_hidden_preset(collection(type), name)).empty()) {
if (type == Preset::TYPE_PRINTER)
show_default_filaments(bundle, shown);
combo->update();
match = combo->find_by_name(shown);
}
if (match.ambiguous)
throw ToolFailure("\"" + name + "\" is ambiguous; use the internal name");
if (match.item < 0)
throw not_offered(collection(type), name, "The selector");
target = match.internal_name;
}
// The prompt about the tab's own changes offers Transfer only where can_transfer_changes_to() says;
// refused here, before anything changes. The sidebar switches the filament tab for a single filament only.
const bool switches_tab = type != Preset::TYPE_FILAMENT || !plater.sidebar().is_multifilament();
if (changes == "transfer" && switches_tab && collection(type).current_is_dirty() && !tab->can_transfer_changes_to(target))
throw ToolFailure(std::string("The unsaved-changes prompt offers no Transfer here: ") +
(type == Preset::TYPE_PRINTER ? "a printer's changes stay with it" :
"\"" + target + "\" is a filament of another type") +
". Pass preset_changes: \"discard\", or save_preset first.");
ui_plater();
const int slot = arg_int(args, "filament_slot", 1);
const Ops::PresetKind kind = type == Preset::TYPE_PRINTER ? Ops::PresetKind::Printer :
type == Preset::TYPE_FILAMENT ? Ops::PresetKind::Filament :
Ops::PresetKind::Process;
const Ops::PresetChanges answer = changes == "transfer" ? Ops::PresetChanges::Transfer :
changes == "discard" ? Ops::PresetChanges::Discard :
Ops::PresetChanges::Ask;
Ops::ResolvePresetArgs resolve;
resolve.kind = kind;
resolve.name = name;
resolve.filament_slot = slot;
const Ops::Outcome<Ops::ResolvedPreset> resolved = Ops::resolve_preset(resolve);
if (!resolved)
throw preset_refused(resolved.refusal());
const json before = unsaved_changes();
tab->m_dirty_preset_answer = changes == "transfer" ? Tab::DirtyPresetAnswer::Transfer :
changes == "discard" ? Tab::DirtyPresetAnswer::Discard :
Tab::DirtyPresetAnswer::Ask;
ScopeGuard ask_again([tab] { tab->m_dirty_preset_answer = Tab::DirtyPresetAnswer::Ask; });
json out;
if (filament_combo != nullptr) {
// The sidebar's own selection path: mapping, flush volumes, badges, project state.
filament_combo->SetSelection(filament_item);
wxCommandEvent evt(wxEVT_COMBOBOX, filament_combo->GetId());
evt.SetEventObject(filament_combo);
evt.SetInt(filament_item);
evt.SetString(filament_combo->GetString(filament_item));
filament_combo->GetEventHandler()->ProcessEvent(evt);
out = {{"type", "filament"}, {"filament_slot", slot}, {"selected", bundle.filament_presets[size_t(slot - 1)]}};
json out;
if (kind == Ops::PresetKind::Filament) {
Ops::AssignFilamentArgs assign;
assign.filament_slot = slot;
assign.preset = resolved.value().name;
assign.changes = answer;
const Ops::Outcome<std::string> assigned = Ops::assign_filament_preset(assign);
if (!assigned)
throw preset_refused(assigned.refusal());
out = {{"type", "filament"}, {"filament_slot", slot}, {"selected", assigned.value()}};
} else {
if (!tab->select_preset(target))
throw ToolFailure("Selecting \"" + target + "\" was cancelled");
out = {{"type", arg_string(args, "type")}, {"selected", collection(type).get_selected_preset_name()}};
const Ops::Outcome<Ops::Done> selected = Ops::select_preset({kind, resolved.value().name, answer});
if (!selected)
throw preset_refused(selected.refusal());
out = {{"type", arg_string(args, "type")}, {"selected", resolved.value().name}};
}
if (!shown.empty())
out["shown"] = shown;
if (!resolved.value().shown.empty())
out["shown"] = resolved.value().shown;
out.update(unsaved_changes_outcome(before));
return out;
});
settle(ctx);
return ToolResult::ok(result);
}));
})));
ToolDef save = mutate_tool(
"save_preset", L("Save a preset"),
@@ -2192,7 +2092,7 @@ void register_config_tools(McpService& service)
}));
}));
reg.add(mutate_tool(
reg.add(reaching({"set_plate_locked"}, mutate_tool(
"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 "
@@ -2360,7 +2260,7 @@ void register_config_tools(McpService& service)
});
settle(ctx);
return ToolResult::ok(result);
}));
})));
reg.add(inspect_tool(
"list_plates", L("List plates"),
+89 -79
View File
@@ -1,7 +1,6 @@
// open_files, new_project, save_project and export: files in and out without file dialogs. generate_calibration_test: the
// Calibration menu's tests, which start a new project.
#include "libslic3r/Format/ProjectStrategy.hpp"
#include "slic3r/GUI/I18N.hpp"
#include "McpPaths.hpp"
#include "McpService.hpp"
@@ -10,6 +9,10 @@
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/MainFrame.hpp"
#include "slic3r/GUI/Operations/ExportOps.hpp"
#include "slic3r/GUI/Operations/Outcome.hpp"
#include "slic3r/GUI/Operations/PlateOps.hpp"
#include "slic3r/GUI/Operations/ProjectOps.hpp"
#include "slic3r/GUI/PartPlate.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/calib_dlg.hpp"
@@ -31,6 +34,7 @@
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@@ -59,20 +63,21 @@ json objects_summary(Plater& plater)
return {{"objects", plater.model().objects.size()}, {"names", std::move(names)}, {"plates", plater.get_partplate_list().get_plate_count()}};
}
// Fails when the project has unsaved changes the caller did not say to drop.
void require_project_discardable(Plater& plater, bool discard)
json project_json(const Ops::ProjectSummary& project)
{
if (plater.is_project_dirty() && !discard)
throw ToolFailure("The project has unsaved changes; save_project first, or pass discard_changes: true");
return {{"objects", project.object_names.size()}, {"names", project.object_names}, {"plates", project.plates}};
}
// Discards unsaved changes without a prompt when the caller said so, or fails.
void require_clean_or_discard(Plater& plater, bool discard)
Ops::UnsavedChanges unsaved_changes_answer(bool discard) { return discard ? Ops::UnsavedChanges::Discard : Ops::UnsavedChanges::Refuse; }
// What a tool that replaces the project adds to the refusal of unsaved changes.
constexpr const char* kUnsavedChangesHint = "save_project first, or pass discard_changes: true.";
// Fails when the project has unsaved changes the caller did not say to drop.
void require_project_discardable(bool discard)
{
if (!plater.is_project_dirty())
return;
require_project_discardable(plater, discard);
plater.new_project(/*skip_confirm=*/true, /*silent=*/true);
if (const std::optional<Ops::Refusal> refusal = Ops::unsaved_changes_refusal(unsaved_changes_answer(discard)))
throw refused(*refusal, kUnsavedChangesHint);
}
// A number for a message, as an agent writes it: 250, not 250.0.
@@ -283,11 +288,12 @@ Calib_Params calib_params_from_args(const json& args, const DynamicPrintConfig&
// As the dialog's fields do when they lose focus: clamp, then round down to the tower's 5 °C blocks.
for (auto [name, t] : {std::make_pair("start", &p.start), std::make_pair("end", &p.end)}) {
const double given = *t;
if (*t > 500 || *t < 155) {
*t = *t > 500 ? 500 : 155;
warnings.push_back(std::string(name) + " " + num(given) + " °C is outside the supported range 155-500 °C; clamped to " + num(*t) + " °C");
if (const double clamped = clamp_calib_temp(*t); clamped != *t) {
*t = clamped;
warnings.push_back(std::string(name) + " " + num(given) + " °C is outside the supported range " + num(kCalibTempMin) +
"-" + num(kCalibTempMax) + " °C; clamped to " + num(*t) + " °C");
}
if (const double rounded = std::floor(*t / 5) * 5; rounded != *t) {
if (const double rounded = round_calib_temp(*t); rounded != *t) {
warnings.push_back(std::string(name) + " " + num(*t) + " °C rounded down to " + num(rounded) + " °C, the tower's 5 °C blocks");
*t = rounded;
}
@@ -384,7 +390,7 @@ void register_project_tools(McpService& service)
{
ToolRegistry& reg = service.registry();
reg.add(mutate_tool(
reg.add(reaching({"open_project", "import_models"}, mutate_tool(
"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 "
@@ -417,26 +423,31 @@ void register_project_tools(McpService& service)
return {{"opened", "gcode"}, {"path", path_to_utf8(paths[0])}};
}
if (paths.size() == 1 && as != "geometry" && has_extension(paths[0], {".3mf"})) {
require_clean_or_discard(plater, discard);
plater.load_project(from_path(paths[0]));
json o = objects_summary(plater);
Ops::OpenProjectArgs open;
open.path = paths[0];
open.unsaved = unsaved_changes_answer(discard);
const Ops::Outcome<Ops::ProjectSummary> opened = Ops::open_project(open);
if (!opened)
throw refused(opened.refusal(), kUnsavedChangesHint);
json o = project_json(opened.value());
o["opened"] = "project";
return o;
}
const size_t before = plater.model().objects.size();
const auto loaded = plater.load_files(paths, LoadStrategy::LoadModel);
if (loaded.empty() && plater.model().objects.size() == before)
throw ToolFailure("Nothing was loaded (see get_log for the reason)");
Ops::ImportModelsArgs models;
models.paths = paths;
const Ops::Outcome<Ops::ImportModelsResult> imported = Ops::import_models(models);
if (!imported)
throw refused(imported.refusal(), "See get_log for the reason.");
json o = objects_summary(plater);
o["opened"] = "models";
o["added"] = plater.model().objects.size() - before;
o["added"] = imported.value().added;
return o;
});
settle(ctx);
return ToolResult::ok(out);
}));
})));
reg.add(mutate_tool(
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 "
"discard_changes. The presets' unsaved changes carry over to the new project unless preset_changes is \"discard\", as "
@@ -450,21 +461,21 @@ void register_project_tools(McpService& 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([&] {
Plater& plater = ui_plater();
require_project_discardable(plater, discard);
const json before = unsaved_changes();
// The prompt's Discard, before the reset as in the GUI; only with changes to drop, since it
// reloads the presets, which can ask about the printer's.
if (discard_presets && wxGetApp().has_current_preset_changes())
wxGetApp().discard_current_preset_changes();
plater.new_project(/*skip_confirm=*/true, /*silent=*/true);
json o = objects_summary(plater);
ui_plater();
const json before = unsaved_changes();
Ops::NewProjectArgs fresh;
fresh.unsaved = unsaved_changes_answer(discard);
fresh.discard_preset_changes = discard_presets;
const Ops::Outcome<Ops::ProjectSummary> started = Ops::new_project(fresh);
if (!started)
throw refused(started.refusal(), kUnsavedChangesHint);
json o = project_json(started.value());
o.update(unsaved_changes_outcome(before));
return o;
});
settle(ctx);
return ToolResult::ok(out);
}));
})));
reg.add(mutate_tool(
"generate_calibration_test", L("Generate a calibration test"),
@@ -524,7 +535,7 @@ void register_project_tools(McpService& service)
bundle.printers.get_edited_preset().config;
std::vector<std::string> warnings;
Calib_Params params = calib_params_from_args(args, printer, warnings);
require_project_discardable(plater, discard);
require_project_discardable(discard);
// The GUI asks whether to keep or discard modified presets here; the caller answers with preset_changes.
const json before = unsaved_changes();
if (!before.empty() && !args.contains("preset_changes")) {
@@ -615,30 +626,30 @@ void register_project_tools(McpService& service)
return ToolResult::ok(out);
}));
reg.add(mutate_tool(
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.",
object_schema({{"path", prop("string", "Absolute .3mf path.")}, {"overwrite", prop("boolean", "Replace an existing file.")}}, {"path"}),
[](const json& args, ToolContext& ctx) {
// A project file holds no G-code, so a .gcode.3mf saved here would lack what its name promises.
if (boost::algorithm::iends_with(arg_string(args, "path"), ".gcode.3mf"))
throw ToolFailure("save_project writes the project without G-code; a .gcode.3mf with the sliced plates is "
"export {format: \"sliced_3mf\"} (plates \"all\" for every plate)");
std::string err;
auto path = resolve_output_path(arg_string(args, "path"), arg_bool(args, "overwrite", false), err);
if (!path)
throw ToolFailure(err);
ctx.run_ui([&] {
ui_plater().save_project(true, from_path(*path));
ui_plater();
Ops::SaveProjectAsArgs save;
save.path = *path;
if (const Ops::Outcome<Ops::Done> saved = Ops::save_project_as(save); !saved)
throw refused(saved.refusal(), std::string(saved.refusal().code) == "sliced_file_name" ?
"That is export {format: \"sliced_3mf\"} (plates \"all\" for every plate)." :
"See get_log.");
return json();
});
settle(ctx);
if (!fs::exists(*path))
throw ToolFailure("The project was not saved (see get_log)");
return ToolResult::ok({{"path", path_to_utf8(*path)}, {"bytes", fs::file_size(*path)}});
}));
})));
reg.add(mutate_tool(
reg.add(reaching({"start_gcode_export", "export_sliced_3mf", "export_model_3mf", "export_stl"}, mutate_tool(
"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: "
@@ -661,47 +672,46 @@ void register_project_tools(McpService& service)
const bool all = plate.is_string() && plate.get<std::string>() == "all";
if (all && format != "sliced_3mf")
throw ToolFailure("plates \"all\" applies to sliced_3mf only");
json started = ctx.run_ui([&]() -> json {
std::optional<Ops::ExportTicket> ticket;
ctx.run_ui([&]() -> json {
// A G-code export finishes in the background: held from before it starts.
if (format == "gcode")
ctx.begin_operation();
Plater& plater = ui_plater();
if (plater.model().objects.empty())
throw ToolFailure("The project has no objects");
if (plate.is_number_integer()) {
const int index = plate.get<int>();
if (index < 0 || index >= plater.get_partplate_list().get_plate_count())
throw ToolFailure(no_such_plate(index, plater.get_partplate_list().get_plate_count()));
plater.select_plate(index);
}
ui_plater();
const std::optional<int> index = plate.is_number_integer() ? std::optional<int>(plate.get<int>()) : std::nullopt;
if (format == "gcode") {
if (plater.is_slicing_any())
throw ToolFailure("Slicing is in progress; wait {for:\"idle\"} and export again");
if (!plater.get_partplate_list().get_curr_plate()->is_slice_result_valid())
throw ToolFailure("The plate is not sliced; slice it first");
const uint64_t before = plater.export_seq();
const uint64_t revision = plater.project_revision();
plater.export_gcode_to(*path);
return {{"before", before}, {"after", plater.export_seq()}, {"revision", revision}};
}
if (format == "sliced_3mf") {
if (!plater.export_gcode_3mf(all, *path))
throw ToolFailure("The sliced file was not written; slice first and check for errors");
} else if (format == "3mf") {
plater.export_core_3mf(from_path(*path));
} else {
plater.export_stl(false, false, false, FT_STL, from_path(*path));
Ops::ExportGcodeArgs gcode;
gcode.path = *path;
gcode.plate = index;
const Ops::Outcome<Ops::ExportTicket> started = Ops::start_gcode_export(gcode);
if (!started) {
const std::string code = started.refusal().code;
throw refused(started.refusal(), code == "slicing_in_progress" ? "wait {for:\"idle\"} waits for it." :
code == "export_not_started" ? "Check get_app_state.notifications." :
"");
}
ticket = started.value();
return json();
}
Ops::ExportSlicedArgs sliced;
sliced.path = *path;
sliced.all_plates = all;
sliced.plate = index;
Ops::ExportFileArgs file;
file.path = *path;
file.plate = index;
const Ops::Outcome<Ops::Done> written = format == "sliced_3mf" ? Ops::export_sliced_3mf(sliced) :
format == "3mf" ? Ops::export_model_3mf(file) :
Ops::export_stl(file);
if (!written)
throw refused(written.refusal(), std::string(written.refusal().code) == "file_not_written" ? "See get_log." : "");
return json();
});
if (format == "gcode")
return await_gcode_export(ctx, started["before"], started["after"], started["revision"],
"The export did not start; check get_app_state.notifications");
if (ticket)
return await_gcode_export(ctx, *ticket);
settle(ctx);
if (!fs::exists(*path))
throw ToolFailure("The file was not written (see get_log)");
return ToolResult::ok({{"path", path_to_utf8(*path)}, {"bytes", fs::file_size(*path)}});
}));
})));
}
}}} // namespace Slic3r::GUI::Mcp
+59 -57
View File
@@ -1,6 +1,6 @@
// list_objects, select_objects, transform, add_part, arrange, slice and cancel_job: the model on the plates, the
// arrange and Fill bed jobs, and the slice operation, which reports its own outcome per plate (see
// McpOperations).
// Operations/RunStatus).
#include "CanvasTarget.hpp"
#include "slic3r/GUI/I18N.hpp"
@@ -8,7 +8,6 @@
#include "McpCore.hpp"
#include "libslic3r/Config.hpp"
#include "libslic3r/Point.hpp"
#include "McpOperations.hpp"
#include "McpPaths.hpp"
#include "McpService.hpp"
#include "McpTools.hpp"
@@ -22,10 +21,12 @@
#include "slic3r/GUI/GUI_Geometry.hpp"
#include "slic3r/GUI/GUI_ObjectList.hpp"
#include "slic3r/GUI/Gizmos/GLGizmosManager.hpp"
#include "slic3r/GUI/Jobs/Job.hpp"
#include "slic3r/GUI/Jobs/Worker.hpp"
#include "slic3r/GUI/MainFrame.hpp"
#include "slic3r/GUI/NotificationManager.hpp"
#include "slic3r/GUI/Operations/Outcome.hpp"
#include "slic3r/GUI/Operations/PlateOps.hpp"
#include "slic3r/GUI/Operations/RunStatus.hpp"
#include "slic3r/GUI/PartPlate.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/Selection.hpp"
@@ -68,6 +69,11 @@
namespace Slic3r { namespace GUI { namespace Mcp {
using nlohmann::json;
using Ops::PlateObservation;
using Ops::PlateOutcome;
using Ops::SliceObservation;
using Ops::SliceTicketState;
using Ops::TicketStatus;
namespace {
@@ -95,6 +101,17 @@ GLCanvas3D& object_canvas()
return *plater.canvas3D();
}
// The Prepare view's canvas, the view shown first when another is, as Ops::start_arrange() shows it.
GLCanvas3D& shown_prepare_canvas(Plater& plater)
{
Ops::show_prepare_view();
GLCanvas3D& canvas = *plater.canvas3D();
// A canvas hidden while the model changed loads its scene on its next draw; it is loaded now.
if (canvas.is_reload_delayed())
canvas.reload_scene(true);
return canvas;
}
} // namespace
// Refused in the assemble view, which shows another canvas, and while a gizmo owns the selection.
@@ -253,6 +270,8 @@ json list_objects(const json& args)
return out;
}
// The slice tool's view of its request: slice_status()'s state, which adds when the tool started
// waiting to what the operation's ticket holds.
struct SliceTicket
{
SliceTicketState state;
@@ -413,17 +432,19 @@ std::set<std::pair<int, std::string>> shown_notifications(Plater& plater)
// plate's Arrange icon or Fill bed starts. UI thread.
ArrangeStart start_arrange(Plater& plater, const json& args)
{
GLCanvas3D& canvas = require_prepare_scene(plater);
const bool fill = args.contains("fill");
// Fill bed selects its object first, so it needs what every tool that selects needs. An arrangement
// runs from whatever view and with whatever gizmo is open, as the toolbar's Arrange does.
GLCanvas3D& canvas = fill ? require_prepare_scene(plater) : shown_prepare_canvas(plater);
PartPlateList& plates = plater.get_partplate_list();
const ModelObjectPtrs& objects = plater.model().objects;
ArrangeStart start;
const bool fill = args.contains("fill");
if (fill && args.contains("plates"))
throw ToolFailure("fill fills the object's own plate; leave plates out");
if (!fill && args.contains("fill_with"))
throw ToolFailure("fill_with goes with fill");
if (objects.empty())
throw ToolFailure("There are no objects to arrange");
if (const std::optional<Ops::Refusal> refusal = Ops::arrange_refusal({}))
throw refused(*refusal);
int plate = -1; // every unlocked plate
if (fill) {
start.fill_object = arg_int(args, "fill", 0);
@@ -480,14 +501,12 @@ ArrangeStart start_arrange(Plater& plater, const json& args)
plater.fill_bed_with_copies();
else
plater.fill_bed_with_instances();
} else if (plate < 0) {
plater.set_prepare_state(Job::PREPARE_STATE_DEFAULT);
plater.arrange();
} else {
if (plate != plates.get_curr_plate_index() && plater.select_plate(plate) != 0)
throw ToolFailure(plate_name + " could not be selected");
plater.set_prepare_state(Job::PREPARE_STATE_MENU);
plater.arrange();
Ops::ArrangeArgs arrange;
if (plate >= 0)
arrange.plate = plate;
if (const Ops::Outcome<Ops::Done> started = Ops::start_arrange(arrange); !started)
throw refused(started.refusal());
}
if (plater.get_ui_job_worker().is_idle())
throw ToolFailure("The arrangement did not start");
@@ -697,11 +716,9 @@ std::vector<double> part_shape_size(const std::string& shape, const json& size)
return {};
const std::vector<const char*> names = primitive_size_names(type_name);
std::vector<double> out;
if (size.is_array() && size.size() == names.size())
for (const json& value : size)
if (value.is_number() && std::isfinite(value.get<double>()) && value.get<double>() > 0.)
out.push_back(value.get<double>());
if (out.size() != names.size()) {
if (size.is_array() && std::all_of(size.begin(), size.end(), [](const json& value) { return value.is_number(); }))
out = size.get<std::vector<double>>();
if (!is_primitive_size(type_name, out)) {
std::string fields;
for (const char* name : names)
fields += (fields.empty() ? "" : ", ") + std::string(name);
@@ -865,11 +882,8 @@ std::string apply_arrange_args(GLCanvas3D::ArrangeSettings& settings, const json
if (args.contains("align_y"))
settings.align_to_y_axis = args["align_y"].get<bool>();
// The panel disables Align to Y axis while rotation is on, and clears it.
if (settings.enable_rotation && settings.align_to_y_axis) {
settings.align_to_y_axis = false;
if (arg_bool(args, "align_y", false))
return "align_y is off while rotate is on, as in the Arrange options panel.";
}
if (settings.apply_option_rules() && arg_bool(args, "align_y", false))
return "align_y is off while rotate is on, as in the Arrange options panel.";
return {};
}
@@ -1164,7 +1178,7 @@ void register_scene_tools(McpService& service)
return ToolResult::ok(out);
}));
reg.add(mutate_tool(
reg.add(reaching({"start_arrange"}, mutate_tool(
"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 "
@@ -1209,9 +1223,9 @@ void register_scene_tools(McpService& service)
ctx.observe_ui([&] { return json(service.core().cancel_worker(ctx.job_id())); });
throw ToolFailure("The arrangement did not finish within " + std::to_string(timeout.count()) + " s, so it was cancelled");
}
}));
})));
ToolDef slice = mutate_tool(
ToolDef slice = reaching({"start_slice"}, mutate_tool(
"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, "
@@ -1229,8 +1243,6 @@ void register_scene_tools(McpService& service)
// under the slice, and a cancel meanwhile finds the operation.
const uint64_t cancels_before = ctx.run_ui([&] {
ctx.begin_operation();
if (ui_plater().printer_technology() != ptFFF)
throw ToolFailure("Slicing through MCP supports FFF printers only");
return json(ui_plater().slice_cancel_seq());
}).get<uint64_t>();
// A change made just before (set_settings, open_files) is validated by an update
@@ -1245,36 +1257,26 @@ void register_scene_tools(McpService& service)
std::chrono::seconds(10), "the pending update of the slicing state");
const bool cancelled = ctx.run_ui([&] {
Plater& plater = ui_plater();
PartPlateList& list = plater.get_partplate_list();
const bool all = plates_arg.is_string() && plates_arg.get<std::string>() == "all";
if (all) {
for (int i = 0; i < list.get_plate_count(); ++i)
ticket->plates.push_back(i);
} else if (plates_arg.is_number_integer()) {
const int index = plates_arg.get<int>();
if (index < 0 || index >= list.get_plate_count())
throw ToolFailure(no_such_plate(index, list.get_plate_count()));
ticket->plates.push_back(index);
} else {
ticket->plates.push_back(list.get_curr_plate_index());
}
Ops::SliceArgs slice;
slice.all_plates = plates_arg.is_string() && plates_arg.get<std::string>() == "all";
if (plates_arg.is_number_integer())
slice.plate = plates_arg.get<int>();
const Ops::Outcome<std::vector<int>> plates = Ops::slice_plates(slice);
if (!plates)
throw refused(plates.refusal());
ticket->plates = plates.value();
// A cancel that came while the update was pending stops the slice before it starts.
if (plater.slice_cancel_seq() != cancels_before)
return json(true);
if (!all && ticket->plates.front() != list.get_curr_plate_index())
plater.select_plate(ticket->plates.front());
ticket->state.run_seq_before = plater.slice_run_seq();
ticket->state.revision_at_start = plater.project_revision();
ticket->state.started = std::chrono::steady_clock::now();
plater.request_slice(all);
ticket->state.request_seq_mine = plater.slice_request_seq();
ticket->state.seen_running = plater.is_slicing_any();
if (plater.slice_run_seq() == ticket->state.run_seq_before)
if (auto running = plater.slice_run(ticket->state.run_seq_before); running && !running->finished)
ticket->state.adopted_run = running->seq;
// The Preview tab shows the result, as after the Slice button.
if (MainFrame* frame = wxGetApp().mainframe)
frame->select_tab(wxString(TAB_ID_PREVIEW));
ticket->state.started = std::chrono::steady_clock::now();
const Ops::Outcome<Ops::SliceTicket> started = Ops::start_slice(slice);
if (!started)
throw refused(started.refusal());
ticket->state.run_seq_before = started.value().run_seq_before;
ticket->state.revision_at_start = started.value().revision;
ticket->state.request_seq_mine = started.value().request_seq;
ticket->state.seen_running = started.value().slicing;
ticket->state.adopted_run = started.value().adopted_run;
return json(false);
}).get<bool>();
if (cancelled) {
@@ -1344,7 +1346,7 @@ void register_scene_tools(McpService& service)
},
timeout, "slicing to finish");
return ToolResult::ok(result);
});
}));
slice.budget_ms = 45000;
reg.add(slice);
+26 -21
View File
@@ -20,6 +20,8 @@
#include "slic3r/GUI/IMSlider.hpp"
#include "slic3r/GUI/LibVGCode/LibVGCodeWrapper.hpp"
#include "slic3r/GUI/MainFrame.hpp"
#include "slic3r/GUI/Operations/Outcome.hpp"
#include "slic3r/GUI/Operations/PlateOps.hpp"
#include "slic3r/GUI/PartPlate.hpp"
#include "slic3r/GUI/Plater.hpp"
#ifdef SLIC3R_CAD
@@ -664,7 +666,7 @@ void register_view_tools(McpService& service)
tabs.insert(tabs.begin() + 1, "design");
#endif
reg.add(mutate_tool(
reg.add(reaching({"show_layer_range"}, mutate_tool(
"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 "
@@ -788,37 +790,40 @@ void register_view_tools(McpService& service)
done["time_mode"] = arg_string(args, "time_mode");
}
if (args.contains("layer") || args.contains("layer_range") || args.contains("layer_z")) {
const Ops::Outcome<int> count = Ops::layer_count();
if (!count)
throw refused(count.refusal());
IMSlider* layers = viewer.get_layers_slider();
if (layers == nullptr || layers->GetMaxValue() <= 0)
throw ToolFailure("The preview has no layers; slice first");
const int max = layers->GetMaxValue();
int lo = 0, hi = max;
const int max = count.value() - 1;
// Every layer up to the one asked for, unless a range says where to start. The
// operation brings the numbers into the plate's layers.
Ops::ShowLayerRangeArgs range;
range.first = 1;
range.last = max + 1;
if (args.contains("layer"))
hi = std::clamp(args["layer"].get<int>() - 1, 0, max);
range.last = args["layer"].get<int>();
if (args.contains("layer_range")) {
const json& r = args["layer_range"];
if (!r.is_array() || r.size() != 2)
throw ToolFailure("layer_range must be [first, last]");
lo = std::clamp(r[0].get<int>() - 1, 0, max);
hi = std::clamp(r[1].get<int>() - 1, lo, max);
range.first = r[0].get<int>();
range.last = r[1].get<int>();
}
if (args.contains("layer_z")) {
// The slider's own rule for a height, which set_custom_gcode_at_layer's z follows too.
const double z = args["layer_z"].get<double>();
hi = layers->get_tick_from_value(z, true);
if (hi < 0 || hi > max)
const double z = args["layer_z"].get<double>();
const int tick = layers->get_tick_from_value(z, true);
if (tick < 0 || tick > max)
throw ToolFailure("layer_z " + json(z).dump() + " is above the top layer (" +
json(rounded(layers->GetMaxValueD(), 1000.)).dump() + " mm)");
range.last = tick + 1;
}
layers->SetHigherValue(hi);
layers->SetLowerValue(lo);
layers->set_as_dirty();
if (IMSlider* moves = viewer.get_moves_slider()) {
moves->SetHigherValue(moves->GetMaxValue());
moves->set_as_dirty();
}
done["layers"] = {lo + 1, hi + 1, max + 1};
done["z"] = {rounded(layers->GetLowerValueD(), 1000.), rounded(layers->GetHigherValueD(), 1000.)};
const Ops::Outcome<Ops::ShownLayers> shown = Ops::show_layer_range(range);
if (!shown)
throw refused(shown.refusal());
// The reply echoes the range asked for; z is of the layers the slider shows.
done["layers"] = {shown.value().asked_first, shown.value().asked_last, shown.value().count};
done["z"] = {rounded(shown.value().z_first, 1000.), rounded(shown.value().z_last, 1000.)};
}
canvas->set_as_dirty();
}
@@ -895,7 +900,7 @@ void register_view_tools(McpService& service)
return read;
}));
return ToolResult::ok(out);
}));
})));
}
}}} // namespace Slic3r::GUI::Mcp
+3
View File
@@ -157,6 +157,9 @@ struct ToolDef
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;
};
+145 -145
View File
@@ -4,7 +4,6 @@
#include "Camera.hpp"
#include "CreatePresetsDialog.hpp"
#include "DailyTips.hpp"
#include "GCodeViewer.hpp"
#include "GLCanvas3D.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp"
@@ -14,13 +13,17 @@
#include "Gizmos/GLGizmosManager.hpp"
#include "I18N.hpp"
#include "Shortcuts.hpp"
#include "IMSlider.hpp"
#include "Jobs/Job.hpp"
#include "Jobs/Worker.hpp"
#include "MainFrame.hpp"
#include "RunScriptPanel.hpp"
#include "ObjectDataViewModel.hpp"
#include "NetworkTestDialog.hpp"
#include "Operations/ExportOps.hpp"
#include "Operations/Outcome.hpp"
#include "Operations/PlateOps.hpp"
#include "Operations/PresetOps.hpp"
#include "Operations/ProjectOps.hpp"
#include "Plater.hpp"
#include "PluginsDialog.hpp"
#include "PartPlate.hpp"
@@ -120,20 +123,41 @@ AppActionRunResult object_op(Plater* plater, bool (*ok)(Plater*), void (*op)(Pla
return {AppActionRunResult::Level::Success};
}
// Arrange and orient as the toolbar runs them: on every plate, in the background. Plater::can_arrange()
// is false with no objects or while another job runs, and each gets its own message.
AppActionRunResult arrange_op(Plater* plater, void (*op)(Plater*), const wxString& no_objects)
// What a command answers when its operation refuses: the refusal in the UI's language, shown at
// `level`, as a command that did nothing; automation reads the refusal itself.
AppActionRunResult refused(const Ops::Refusal& refusal, AppActionRunResult::Level level = AppActionRunResult::Level::Error)
{
AppActionRunResult result{level, refusal.translated(), false};
result.refusal = std::make_shared<const Ops::Refusal>(refusal);
return result;
}
AppActionRunResult worker_busy() { return {AppActionRunResult::Level::Info, _L("Wait for the running background job to finish."), false}; }
// Arrange as the toolbar runs it: on every unlocked plate, in the background. No objects and a running
// job each get their own message.
AppActionRunResult arrange_all(Plater* plater)
{
if (!plater)
return {AppActionRunResult::Level::Info, _L("Open the 3D view first."), false};
if (const Ops::Outcome<Ops::Done> started = Ops::start_arrange({}); !started)
return refused(started.refusal(), AppActionRunResult::Level::Info);
return {AppActionRunResult::Level::Success};
}
// Orient as the toolbar runs it, with the guards arrange has.
AppActionRunResult orient_all(Plater* plater)
{
if (!plater)
return {AppActionRunResult::Level::Info, _L("Open the 3D view first."), false};
ensure_3d_view(plater);
if (plater->model().objects.empty())
return {AppActionRunResult::Level::Info, no_objects, false};
return {AppActionRunResult::Level::Info, _L("There are no objects to orient."), false};
if (!plater->get_ui_job_worker().is_idle())
return {AppActionRunResult::Level::Info, _L("Wait for the running background job to finish."), false};
// A plate's Arrange or Auto Rotate icon leaves the plate-only state behind.
return worker_busy();
// A plate's Auto Rotate icon leaves the plate-only state behind.
plater->set_prepare_state(Job::PREPARE_STATE_DEFAULT);
op(plater);
plater->orient();
return {AppActionRunResult::Level::Success};
}
@@ -191,38 +215,24 @@ AppActionRunResult ordered(Plater& plater, ObjectOrder order, bool all_plates)
return with_reply({{"order", list}, {"descending", descending}});
}
// Jump the preview to a layer selected by a 0-100 percent of the layer range. The caller has already
// switched to Preview (which may request a slice); if a slicer result is present the slider is
// repositioned immediately, otherwise the jump is a no-op until the user re-slices.
void go_to_layer(Plater* plater, const std::string& param)
// 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)
{
if (!plater)
return;
double pct = 50.0;
try {
pct = std::stod(param);
} catch (const std::exception&) {}
pct = std::clamp(pct, 0.0, 100.0);
GLCanvas3D* canvas = plater->get_current_canvas3D();
if (!canvas)
return;
GCodeViewer& viewer = canvas->get_gcode_viewer();
IMSlider* layers = viewer.get_layers_slider();
IMSlider* moves = viewer.get_moves_slider();
if (!layers || layers->GetMaxValue() <= 0)
return;
const double max = double(layers->GetMaxValue());
const int target = int(std::lround(pct / 100.0 * max));
layers->SetHigherValue(target);
if (layers->is_one_layer())
layers->SetLowerValue(target);
layers->set_as_dirty();
if (moves) {
moves->SetHigherValue(moves->GetMaxValue());
moves->set_as_dirty();
}
const Ops::Outcome<int> count = Ops::layer_count();
if (!count)
return refused(count.refusal(), AppActionRunResult::Level::Info);
Ops::ShowLayerRangeArgs range;
range.last = int(std::lround(pct / 100.0 * double(count.value() - 1))) + 1;
if (const Ops::Outcome<Ops::ShownLayers> shown = Ops::show_layer_range(range); !shown)
return refused(shown.refusal(), AppActionRunResult::Level::Info);
return {AppActionRunResult::Level::Success};
}
// The path a command was given, checked for reading (`output` false) or writing. nullopt with an
@@ -239,12 +249,10 @@ std::optional<boost::filesystem::path> path_param(const std::string& param, bool
return path;
}
AppActionRunResult written(const boost::filesystem::path& path)
// 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)
{
boost::system::error_code ec;
if (boost::filesystem::exists(path, ec))
return {AppActionRunResult::Level::Success, from_u8(path.string())};
return {AppActionRunResult::Level::Error, _L("The file was not written.")};
return outcome ? AppActionRunResult{AppActionRunResult::Level::Success, from_u8(path.string())} : refused(outcome.refusal());
}
// A screenshot or recording saved into the MCP output folder, which a person would not find by themselves: a
@@ -403,29 +411,16 @@ std::optional<bool> import_overwrites(const std::string& param, AppActionRunResu
return conflict == "overwrite";
}
// Imports preset files from `path` (UTF-8) as the Import Configs dialog does, answering for each preset
// that exists already as the dialog's Yes or No would, so that every one of them is asked about and can
// be named: the message lists the presets imported, replaced and kept.
AppActionRunResult import_preset_file(MainFrame& mf, const std::string& path, bool 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)
{
const PresetBundle& bundle = *wxGetApp().preset_bundle;
const auto names = [&bundle] {
std::set<std::pair<int, std::string>> out;
for (const PresetCollection* presets : std::initializer_list<const PresetCollection*>{&bundle.prints, &bundle.filaments, &bundle.printers})
for (const Preset& preset : presets->get_presets())
out.emplace(int(presets->type()), preset.name);
return out;
};
const auto before = names();
std::vector<std::string> replaced, kept;
mf.import_configs({path}, [&](const std::string& name) {
(overwrite ? replaced : kept).push_back(name);
return overwrite ? 1 : 0; // never "to all", which would stop the questions
});
std::vector<std::string> added;
for (const auto& name : names())
if (before.count(name) == 0)
added.push_back(name.second);
Ops::ImportPresetsArgs presets;
presets.path = path;
presets.overwrite = overwrite;
const Ops::Outcome<Ops::ImportedPresets> imported = Ops::import_presets(presets);
if (!imported)
return refused(imported.refusal());
wxString message;
const auto add = [&message](const wxString& text, const std::vector<std::string>& list) {
@@ -433,14 +428,11 @@ AppActionRunResult import_preset_file(MainFrame& mf, const std::string& path, bo
message += (message.empty() ? "" : " ") + format_wxstr(text, boost::algorithm::join(list, ", "));
};
// TRN %1% is a comma-separated list of preset names.
add(_L("Imported presets: %1%."), added);
add(_L("Imported presets: %1%."), imported.value().imported);
// TRN %1% is a comma-separated list of preset names.
add(_L("Replaced presets: %1%."), replaced);
add(_L("Replaced presets: %1%."), imported.value().replaced);
// TRN %1% is a comma-separated list of preset names.
add(_L("Kept the existing presets: %1%."), kept);
if (message.empty())
return {AppActionRunResult::Level::Error,
_L("No presets were imported.") + _L("\nHint: Make sure you have added the corresponding printer before importing the configs.")};
add(_L("Kept the existing presets: %1%."), imported.value().kept);
return {AppActionRunResult::Level::Success, message};
}
@@ -489,11 +481,11 @@ void describe_commands(std::vector<NativeCommand>& commands)
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.", CommandParamType::Percent, "0-100"},
{"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.", CommandParamType::Path, "absolute output path, or {\"path\": ..., \"overwrite\": true}"},
{"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."},
@@ -547,7 +539,9 @@ void describe_commands(std::vector<NativeCommand>& commands)
"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"},
{"import_file", "Import models (3MF/STL/STEP/SVG/OBJ/AMF). With a path, imports that file without a dialog.", CommandParamType::Path, "absolute path of a model file"},
{"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"},
{"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, "
@@ -604,7 +598,7 @@ void describe_commands(std::vector<NativeCommand>& commands)
{"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.", CommandParamType::Index, "0-based plate index"},
{"plate_goto", "Make a plate the current one; an index the project lacks is an error.", CommandParamType::Index, "0-based plate index"},
{"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."},
@@ -636,7 +630,29 @@ void describe_commands(std::vector<NativeCommand>& commands)
"filament (project scope filament_is_mixed) is refused.", CommandParamType::Index,
"1-based filament slot; without it, the last physical slot, as the - button"},
};
// The operations (GUI/Operations) a runner 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"}},
{"go_to_layer", {"show_layer_range"}},
{"save_project_as", {"save_project_as"}},
{"export_gcode", {"start_gcode_export"}},
{"export_stl", {"export_stl"}},
{"export_3mf", {"export_model_3mf"}},
{"export_sliced_file", {"export_sliced_3mf"}},
{"export_all_sliced_file", {"export_sliced_3mf"}},
{"send_gcode", {"send_gcode_to_host"}},
{"import_file", {"import_models"}},
{"import_configs", {"import_presets"}},
{"obj_arrange", {"start_arrange"}},
{"obj_set_instances", {"set_instance_count"}},
{"plate_toggle_lock", {"set_plate_locked"}},
{"plate_goto", {"select_plate"}},
};
for (NativeCommand& c : commands) {
if (const auto ops = std::find_if(std::begin(reaches), std::end(reaches), [&](const auto& r) { return c.key == r.first; });
ops != std::end(reaches))
c.operations = ops->second;
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;
@@ -671,21 +687,15 @@ std::vector<NativeCommand> build_command_catalog()
// ---- 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&) {
Plater* plater = wxGetApp().plater();
if (plater) {
plater->request_slice(false);
plater->select_view_3D("Preview", false);
if (MainFrame* mf = wxGetApp().mainframe; mf)
mf->select_tab(TAB_ID_PREVIEW);
}
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&) {
Plater* plater = wxGetApp().plater();
if (plater) {
plater->request_slice(true);
if (MainFrame* mf = wxGetApp().mainframe; mf)
mf->select_tab(TAB_ID_PREVIEW);
if (wxGetApp().plater() != nullptr) {
Ops::SliceArgs slice;
slice.all_plates = true;
Ops::start_slice(slice);
}
return AppActionRunResult{AppActionRunResult::Level::Success};
});
@@ -694,13 +704,12 @@ std::vector<NativeCommand> build_command_catalog()
"go_to_layer", L("Go to layer (percent)"), L("Commands"), "height_range_layer",
[](const std::string& param) {
Plater* plater = wxGetApp().plater();
if (plater) {
plater->select_view_3D("Preview", false);
if (MainFrame* mf = wxGetApp().mainframe; mf)
mf->select_tab(TAB_ID_PREVIEW);
go_to_layer(plater, param);
}
return AppActionRunResult{AppActionRunResult::Level::Success};
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);
},
"percent");
@@ -747,9 +756,7 @@ std::vector<NativeCommand> build_command_catalog()
const auto path = path_param(param, true, fail);
if (!path)
return fail;
if (plater->save_project(true, from_path(*path)) != wxID_YES && !boost::filesystem::exists(*path))
return AppActionRunResult{AppActionRunResult::Level::Error, _L("The project was not saved.")};
return written(*path);
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())
@@ -868,10 +875,10 @@ std::vector<NativeCommand> build_command_catalog()
const auto path = path_param(param, true, fail);
if (!path)
return fail;
if (plater->is_slicing_any())
return AppActionRunResult{AppActionRunResult::Level::Error, _L("Slicing is in progress. Wait for it to finish and export again.")};
if (!plater->export_gcode_to(*path))
return AppActionRunResult{AppActionRunResult::Level::Error, _L("The export could not start. Slice the plate first and check for slicing errors.")};
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) {
@@ -886,8 +893,7 @@ std::vector<NativeCommand> build_command_catalog()
const auto path = path_param(param, true, fail);
if (!path)
return fail;
plater->export_stl(false, false, false, FT_STL, from_path(*path));
return written(*path);
return written(Ops::export_stl({*path}), *path);
});
add_with_icon("export_3mf", L("Export 3MF"), L("Slice & Export"), "menu_save", [](const std::string& param) {
Plater* plater = wxGetApp().plater();
@@ -901,8 +907,7 @@ std::vector<NativeCommand> build_command_catalog()
const auto path = path_param(param, true, fail);
if (!path)
return fail;
plater->export_core_3mf(from_path(*path));
return written(*path);
return written(Ops::export_model_3mf({*path}), *path);
});
auto export_sliced = [](bool all) {
return [all](const std::string& param) {
@@ -917,9 +922,10 @@ std::vector<NativeCommand> build_command_catalog()
const auto path = path_param(param, true, fail);
if (!path)
return fail;
if (!plater->export_gcode_3mf(all, *path))
return AppActionRunResult{AppActionRunResult::Level::Error, _L("The sliced file was not written. Slice first and check for slicing errors.")};
return written(*path);
Ops::ExportSlicedArgs sliced;
sliced.path = *path;
sliced.all_plates = all;
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));
@@ -929,19 +935,10 @@ std::vector<NativeCommand> build_command_catalog()
// 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&) {
Plater* plater = wxGetApp().plater();
if (plater == nullptr)
if (wxGetApp().plater() == nullptr)
return AppActionRunResult{};
PresetBundle& bundle = *wxGetApp().preset_bundle;
if (bundle.use_bbl_network() || wxGetApp().app_config->get_bool("use_printer_agents"))
// TRN "Print plate" is the print button's action, which sends to such a printer through its own dialog.
return AppActionRunResult{AppActionRunResult::Level::Error, _L("This printer prints with Print plate, not through a print host.")};
// The Print button sends only to a printer with a print host address, as MainFrame::can_send_gcode() checks.
const auto* host = bundle.printers.get_edited_preset().config.option<ConfigOptionString>("print_host");
if (host == nullptr || host->value.empty())
return AppActionRunResult{AppActionRunResult::Level::Error,
_L("This printer has no print host. Set one in the printer's connection settings.")};
plater->send_gcode_legacy();
if (const Ops::Outcome<Ops::Done> sent = Ops::send_gcode_to_host(); !sent)
return refused(sent.refusal());
return AppActionRunResult{AppActionRunResult::Level::Success};
});
@@ -1062,10 +1059,10 @@ std::vector<NativeCommand> build_command_catalog()
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&) {
return arrange_op(wxGetApp().plater(), [](Plater* p) { p->arrange(); }, _L("There are no objects to arrange."));
return arrange_all(wxGetApp().plater());
});
add_with_icon("obj_orient", L("Auto-Orient"), L("Object"), "toolbar_orient", [](const std::string&) {
return arrange_op(wxGetApp().plater(), [](Plater* p) { p->orient(); }, _L("There are no objects to orient."));
return orient_all(wxGetApp().plater());
});
// ---- Object structure ---- (the object list's context menus and the plate menu's Order By)
@@ -1109,28 +1106,28 @@ std::vector<NativeCommand> build_command_catalog()
ObjectList* list = object_list_in_3d_view();
if (list == nullptr)
return AppActionRunResult{};
// A selection to make and a job to wait for are told as information, the other reasons as errors.
const auto refused_count = [](const Ops::Refusal& refusal) {
const std::string code = refusal.code;
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 || *count > 1000))
return AppActionRunResult{AppActionRunResult::Level::Error, from_u8("The number of instances is a whole number from 1 to 1000.")};
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.")};
const int obj_idx = plater->get_selected_object_idx();
if (obj_idx < 0)
return AppActionRunResult{AppActionRunResult::Level::Info, _L("Select an object first."), false};
// The menu item is enabled by can_increase_instances(); each of its reasons gets a message.
const ModelObject* object = plater->model().objects[obj_idx];
if (list->has_selected_cut_object())
return AppActionRunResult{AppActionRunResult::Level::Error, _L("A cut object keeps its number of instances.")};
if (std::any_of(object->instances.begin(), object->instances.end(), [](const ModelInstance* i) { return !i->printable; }))
return AppActionRunResult{AppActionRunResult::Level::Error, _L("Make every instance of the object printable first.")};
if (!plater->can_increase_instances())
return AppActionRunResult{AppActionRunResult::Level::Info, _L("Wait for the running background job to finish."), false};
if (!count) {
// 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};
}
plater->set_number_of_copies(*count);
return with_reply({{"object", obj_idx}, {"instances", object->instances.size()}});
const Ops::Outcome<Ops::InstanceCount> set = Ops::set_instance_count({*count});
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&) {
ObjectList* list = object_list_in_3d_view();
@@ -1201,7 +1198,7 @@ std::vector<NativeCommand> build_command_catalog()
std::vector<double> size;
if (!param.empty()) {
const std::optional<std::vector<double>> parsed = NativeCommands::parse_sizes(param);
if (!parsed || parsed->size() != primitive_size_names(type_name).size())
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;
@@ -1305,10 +1302,11 @@ std::vector<NativeCommand> build_command_catalog()
Plater* plater = wxGetApp().plater();
if (!is_fff_plater(plater))
return plate_unavailable();
PartPlateList& plates = plater->get_partplate_list();
const int index = plates.get_curr_plate_index();
plater->take_snapshot("lock partplate");
plates.lock_plate(index, !plates.is_locked(index));
PartPlateList& plates = plater->get_partplate_list();
Ops::SetPlateLockedArgs lock;
lock.locked = !plates.is_locked(plates.get_curr_plate_index());
if (const Ops::Outcome<Ops::PlateLocked> locked = Ops::set_plate_locked(lock); !locked)
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) {
@@ -1319,12 +1317,12 @@ std::vector<NativeCommand> build_command_catalog()
const int count = plates.get_plate_count();
if (count <= 0)
return AppActionRunResult{AppActionRunResult::Level::Info, _L("No plates available.")};
int index = 0;
Ops::SelectPlateArgs plate;
try {
index = std::stoi(param);
plate.plate = std::stoi(param);
} catch (const std::exception&) {}
index = std::clamp(index, 0, count - 1);
plater->select_plate(index, false);
if (const Ops::Outcome<Ops::Done> selected = Ops::select_plate(plate); !selected)
return refused(selected.refusal());
return AppActionRunResult{AppActionRunResult::Level::Success};
});
@@ -1421,8 +1419,10 @@ std::vector<NativeCommand> build_command_catalog()
const auto path = path_param(param, false, fail);
if (!path)
return fail;
if (plater->load_files(std::vector<boost::filesystem::path>{*path}).empty())
return AppActionRunResult{AppActionRunResult::Level::Error, _L("Nothing was imported.")};
Ops::ImportModelsArgs models;
models.paths = {*path};
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&) {
@@ -1451,7 +1451,7 @@ 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(*mf, file, *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"};
});
+3
View File
@@ -41,6 +41,9 @@ struct NativeCommand
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 {
+158
View File
@@ -0,0 +1,158 @@
#include "ExportOps.hpp"
#include "Outcome.hpp"
#include "PlateOps.hpp"
#include "RunStatus.hpp"
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/I18N.hpp"
#include "slic3r/GUI/PartPlate.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "libslic3r/AppConfig.hpp"
#include "libslic3r/Config.hpp"
#include "libslic3r/Model.hpp"
#include "libslic3r/Preset.hpp"
#include "libslic3r/PresetBundle.hpp"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/system/error_code.hpp>
#include <cassert>
#include <optional>
#include <string>
#include <wx/thread.h>
namespace Slic3r { namespace GUI { namespace Ops {
namespace {
// The one success check of an export that writes its file before it returns.
Outcome<Done> written(const boost::filesystem::path& path)
{
boost::system::error_code ec;
if (!boost::filesystem::exists(path, ec))
return Refusal{RefusalKind::Failed, "file_not_written", L("The file was not written.")};
return Done{};
}
// The refusal for a project with nothing in it to write.
Refusal no_objects() { return {RefusalKind::Precondition, "no_objects", L("The project has no objects.")}; }
// Makes the plate a caller named the current one, or says why it is not.
std::optional<Refusal> select_named_plate(const std::optional<int>& plate)
{
if (!plate)
return std::nullopt;
const Outcome<Done> selected = select_plate({*plate});
return selected ? std::nullopt : std::optional<Refusal>(selected.refusal());
}
} // namespace
Outcome<ExportTicket> start_gcode_export(const ExportGcodeArgs& args)
{
assert(wxThread::IsMain());
Plater& plater = *wxGetApp().plater();
PartPlateList& plates = plater.get_partplate_list();
if (plater.model().objects.empty())
return no_objects();
if (args.plate) {
if (*args.plate < 0 || *args.plate >= plates.get_plate_count())
return no_such_plate(*args.plate, plates.get_plate_count());
// The owner exports the current plate.
plater.select_plate(*args.plate);
}
ExportTicket ticket;
ticket.seq_before = plater.export_seq();
ticket.revision = plater.project_revision();
ticket.path = args.path.string();
switch (plater.export_gcode_to(args.path)) {
case Plater::ExportRefusal::None: break;
case Plater::ExportRefusal::NoObjects: return no_objects();
case Plater::ExportRefusal::AlreadyExporting:
return Refusal{RefusalKind::Busy, "export_already_running", L("Another export job is running.")};
case Plater::ExportRefusal::Slicing:
return Refusal{RefusalKind::Busy, "slicing_in_progress", L("Slicing is in progress. Wait for it to finish and export again.")};
case Plater::ExportRefusal::SliceHasErrors:
return Refusal{RefusalKind::Precondition, "slice_has_errors",
L("The plate's slice ended with an error. Fix what it reports and slice again before exporting.")};
case Plater::ExportRefusal::NotSliced:
return Refusal{RefusalKind::Precondition, "plate_not_sliced", L("The plate is not sliced. Slice it first.")};
case Plater::ExportRefusal::NotStarted: return Refusal{RefusalKind::Failed, "export_not_started", L("The export did not start.")};
}
ticket.seq_after = plater.export_seq();
if (ticket.seq_after == ticket.seq_before)
return Refusal{RefusalKind::Failed, "export_not_started", L("The export did not start.")};
return ticket;
}
ExportStatus gcode_export_state(const ExportTicket& ticket, std::string* error)
{
assert(wxThread::IsMain());
const std::optional<Plater::ExportRun> run = wxGetApp().plater()->export_run(ticket.seq_after);
std::optional<ExportRecord> record;
if (run)
record = ExportRecord{run->seq, run->path, run->finished, run->ok, run->cancelled, run->error, run->revision_at_finish};
if (error != nullptr)
*error = run ? run->error : std::string();
return export_status(ticket.seq_before, ticket.seq_after, record, ticket.revision);
}
Outcome<Done> export_sliced_3mf(const ExportSlicedArgs& args)
{
assert(wxThread::IsMain());
Plater& plater = *wxGetApp().plater();
if (plater.model().objects.empty())
return no_objects();
if (std::optional<Refusal> refusal = select_named_plate(args.plate))
return *refusal;
if (!plater.export_gcode_3mf(args.all_plates, args.path))
return Refusal{RefusalKind::Precondition, "sliced_file_not_written",
L("The sliced file was not written. Slice first and check for slicing errors.")};
return written(args.path);
}
Outcome<Done> export_model_3mf(const ExportFileArgs& args)
{
assert(wxThread::IsMain());
if (std::optional<Refusal> refusal = select_named_plate(args.plate))
return *refusal;
wxGetApp().plater()->export_core_3mf(from_path(args.path));
return written(args.path);
}
Outcome<Done> export_stl(const ExportFileArgs& args)
{
assert(wxThread::IsMain());
Plater& plater = *wxGetApp().plater();
if (plater.model().objects.empty())
return no_objects();
if (std::optional<Refusal> refusal = select_named_plate(args.plate))
return *refusal;
plater.export_stl(false, false, false, FT_STL, from_path(args.path));
return written(args.path);
}
Outcome<Done> send_gcode_to_host(const SendGcodeToHostArgs&)
{
assert(wxThread::IsMain());
PresetBundle& bundle = *wxGetApp().preset_bundle;
if (bundle.use_bbl_network() || wxGetApp().app_config->get_bool("use_printer_agents"))
// TRN "Print plate" is the print button's action, which sends to such a printer through its own dialog.
return Refusal{RefusalKind::Precondition, "not_a_print_host_printer",
L("This printer prints with Print plate, not through a print host.")};
// The Print button sends only to a printer with a print host address.
const auto* host = bundle.printers.get_edited_preset().config.option<ConfigOptionString>("print_host");
if (host == nullptr || host->value.empty())
return Refusal{RefusalKind::Precondition, "no_print_host",
L("This printer has no print host. Set one in the printer's connection settings.")};
wxGetApp().plater()->send_gcode_legacy();
return Done{};
}
}}} // namespace Slic3r::GUI::Ops
+73
View File
@@ -0,0 +1,73 @@
#pragma once
#include "Outcome.hpp"
#include "RunStatus.hpp"
#include <boost/filesystem/path.hpp>
#include <cstdint>
#include <optional>
#include <string>
// Writing the project or its G-code to a file the caller names, without a file dialog.
namespace Slic3r { namespace GUI { namespace Ops {
struct ExportGcodeArgs
{
boost::filesystem::path path;
std::optional<int> plate; // none: the current plate
};
// A started export, in Plater's own numbering (export_seq(), project_revision()).
struct ExportTicket
{
uint64_t seq_before = 0;
uint64_t seq_after = 0;
uint64_t revision = 0; // the project revision when it started
std::string path;
};
// Selects the plate when one is given, then starts writing its G-code in the background and returns
// at once; gcode_export_state() says how the export stands.
// Refuses: no_objects, no_such_plate, export_already_running, slicing_in_progress, slice_has_errors,
// plate_not_sliced, export_not_started.
Outcome<ExportTicket> start_gcode_export(const ExportGcodeArgs& args);
// export_status() over Plater's record of the ticket's export. `error` gets the export's own error
// text when it has one.
ExportStatus gcode_export_state(const ExportTicket& ticket, std::string* error = nullptr);
struct ExportSlicedArgs
{
boost::filesystem::path path;
bool all_plates = false; // else the current plate
std::optional<int> plate; // made the current plate first
};
// Writes the sliced plate, or every plate, as a .gcode.3mf. The owner writes a plate that is not
// sliced too, as a file with no G-code.
// Refuses: no_objects, no_such_plate, plate_not_selected, sliced_file_not_written
// (Plater::export_gcode_3mf() declined: a slice of the current plate that ended with an
// error, or a configuration that fails validation), file_not_written.
Outcome<Done> export_sliced_3mf(const ExportSlicedArgs& args);
struct ExportFileArgs
{
boost::filesystem::path path;
std::optional<int> plate; // made the current plate first; the file holds every plate's objects all the same
};
// Writes the project's model as a .3mf without slicing data. A project with no objects is written
// too: one that holds only a Design-tab recipe has none.
// Refuses: no_such_plate, plate_not_selected, file_not_written.
Outcome<Done> export_model_3mf(const ExportFileArgs& args);
// Writes all objects as one STL.
// Refuses: no_objects, no_such_plate, plate_not_selected, file_not_written.
Outcome<Done> export_stl(const ExportFileArgs& args);
struct SendGcodeToHostArgs
{};
// Opens the Send G-code dialog for the printer's print host, as the Print button does for such a
// printer; the upload follows what the person answers there.
// Refuses: not_a_print_host_printer, no_print_host.
Outcome<Done> send_gcode_to_host(const SendGcodeToHostArgs& args = {});
}}} // namespace Slic3r::GUI::Ops
+35
View File
@@ -0,0 +1,35 @@
#include "Outcome.hpp"
#include "slic3r/GUI/I18N.hpp"
#include <boost/format.hpp>
#include <string>
#include <vector>
#include <wx/string.h>
namespace Slic3r { namespace GUI { namespace Ops {
namespace {
// `text` with its %1%.. placeholders filled. A message and its values that do not match (a
// translation that drops a placeholder) still give text rather than an exception.
std::string filled(const std::string& text, const std::vector<std::string>& args)
{
if (args.empty())
return text;
boost::format format(text);
format.exceptions(boost::io::no_error_bits);
for (const std::string& arg : args)
format % arg;
return format.str();
}
} // namespace
wxString Refusal::translated() const { return wxString::FromUTF8(filled(I18N::translate_utf8(msgid), args)); }
std::string Refusal::english() const { return filled(msgid, args); }
}}} // namespace Slic3r::GUI::Ops
+58
View File
@@ -0,0 +1,58 @@
#pragma once
#include <string>
#include <utility>
#include <variant>
#include <vector>
#include <wx/string.h>
// The operations: what the Speed Dial's commands, the MCP tools and the plugin API (orca.host) each
// run by name, one function per thing the app can be asked to do. An operation holds the checks, the
// refusals and their wording, the undo snapshot and the sequence of owner calls; the three callers
// convert their arguments and its result around it. docs/HLSD/mcp-server.md, "Operations", has the
// rules: what is an operation and what stays a method of its owner, and what an operation may include.
//
// Every operation runs on the UI thread and returns at once. One whose work goes on in the background
// returns a ticket, and a status function reads how that work stands.
namespace Slic3r { namespace GUI { namespace Ops {
// Precondition: the caller can change something and call again. Busy: the same call works later.
// Failed: it was tried and did not happen.
enum class RefusalKind { Precondition, Busy, Failed };
// Why an operation did not run, in one wording for every caller.
struct Refusal
{
RefusalKind kind = RefusalKind::Precondition;
const char* code = ""; // stable id: "slicing_in_progress"
std::string msgid; // English, marked with L() where it is written; %1% placeholders
std::vector<std::string> args; // the placeholders' values
std::vector<std::string> names; // names that help the caller: candidates, closest matches
// In the UI's language, for the palette and notifications.
wxString translated() const;
// For a tool's reply and a Python exception.
std::string english() const;
};
// A value or a Refusal, never both.
template<class T> class Outcome
{
public:
Outcome(T value) : m_state(std::in_place_index<0>, std::move(value)) {}
Outcome(Refusal why) : m_state(std::in_place_index<1>, std::move(why)) {}
explicit operator bool() const { return m_state.index() == 0; }
const T& value() const { return std::get<0>(m_state); }
const Refusal& refusal() const { return std::get<1>(m_state); }
private:
std::variant<T, Refusal> m_state;
};
// What an operation with nothing to report returns.
struct Done
{};
}}} // namespace Slic3r::GUI::Ops
+204
View File
@@ -0,0 +1,204 @@
#include "PlateOps.hpp"
#include "Outcome.hpp"
#include "slic3r/GUI/GCodeViewer.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/I18N.hpp"
#include "slic3r/GUI/IMSlider.hpp"
#include "slic3r/GUI/Jobs/Worker.hpp"
#include "slic3r/GUI/MainFrame.hpp"
#include "slic3r/GUI/PartPlate.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "libslic3r/Model.hpp"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
#include <wx/string.h>
#include <wx/thread.h>
namespace Slic3r { namespace GUI { namespace Ops {
namespace {
Plater& the_plater()
{
assert(wxThread::IsMain());
return *wxGetApp().plater();
}
Refusal plate_not_selected(int plate)
{
return {RefusalKind::Failed, "plate_not_selected", L("Plate %1% could not be selected."), {std::to_string(plate)}};
}
Refusal no_layers() { return {RefusalKind::Precondition, "no_layers", L("The preview has no layers. Slice the plate first.")}; }
} // namespace
Refusal no_such_plate(int plate, int count)
{
if (count == 1)
// TRN %1% is the plate index asked for.
return {RefusalKind::Precondition, "no_such_plate", L("Plate %1% does not exist (the project has plate 0 only)"), {std::to_string(plate)}};
// TRN %1% is the plate index asked for, %2% the last plate's index.
return {RefusalKind::Precondition, "no_such_plate", L("Plate %1% does not exist (the project has plates 0..%2%)"),
{std::to_string(plate), std::to_string(count - 1)}};
}
Refusal job_running() { return {RefusalKind::Busy, "job_running", L("Wait for the running background job to finish.")}; }
void show_prepare_view()
{
Plater& plater = the_plater();
if (plater.is_view3D_shown())
return;
plater.select_view_3D("3D");
if (MainFrame* frame = wxGetApp().mainframe)
frame->select_tab(wxString(TAB_ID_PREPARE));
}
Outcome<Done> select_plate(const SelectPlateArgs& args)
{
Plater& plater = the_plater();
const int count = plater.get_partplate_list().get_plate_count();
if (args.plate < 0 || args.plate >= count)
return no_such_plate(args.plate, count);
if (plater.select_plate(args.plate) != 0)
return plate_not_selected(args.plate);
return Done{};
}
Outcome<PlateLocked> set_plate_locked(const SetPlateLockedArgs& args)
{
Plater& plater = the_plater();
PartPlateList& plates = plater.get_partplate_list();
const int index = args.plate ? *args.plate : plates.get_curr_plate_index();
if (index < 0 || index >= plates.get_plate_count())
return no_such_plate(index, plates.get_plate_count());
if (plates.is_locked(index) == args.locked)
return PlateLocked{index, false};
plater.set_plate_locked(index, args.locked);
return PlateLocked{index, true};
}
std::optional<Refusal> arrange_refusal(const ArrangeArgs& args)
{
Plater& plater = the_plater();
if (plater.model().objects.empty())
return Refusal{RefusalKind::Precondition, "no_objects_to_arrange", L("There are no objects to arrange.")};
const int count = plater.get_partplate_list().get_plate_count();
if (args.plate && (*args.plate < 0 || *args.plate >= count))
return no_such_plate(*args.plate, count);
// Plater::arrange() starts nothing while another job runs.
if (!plater.get_ui_job_worker().is_idle())
return job_running();
return std::nullopt;
}
Outcome<Done> start_arrange(const ArrangeArgs& args)
{
show_prepare_view();
if (std::optional<Refusal> refusal = arrange_refusal(args))
return *refusal;
Plater& plater = the_plater();
if (args.plate && *args.plate != plater.get_partplate_list().get_curr_plate_index() && plater.select_plate(*args.plate) != 0)
return plate_not_selected(*args.plate);
plater.arrange(/*current_plate_only=*/args.plate.has_value());
return Done{};
}
Outcome<std::vector<int>> slice_plates(const SliceArgs& args)
{
PartPlateList& list = the_plater().get_partplate_list();
std::vector<int> plates;
if (args.all_plates) {
for (int i = 0; i < list.get_plate_count(); ++i)
plates.push_back(i);
} else if (args.plate) {
if (*args.plate < 0 || *args.plate >= list.get_plate_count())
return no_such_plate(*args.plate, list.get_plate_count());
plates.push_back(*args.plate);
} else {
plates.push_back(list.get_curr_plate_index());
}
return plates;
}
Outcome<SliceTicket> start_slice(const SliceArgs& args)
{
Outcome<std::vector<int>> plates = slice_plates(args);
if (!plates)
return plates.refusal();
Plater& plater = the_plater();
SliceTicket ticket;
ticket.plates = plates.value();
if (!args.all_plates && ticket.plates.front() != plater.get_partplate_list().get_curr_plate_index())
plater.select_plate(ticket.plates.front());
ticket.run_seq_before = plater.slice_run_seq();
ticket.revision = plater.project_revision();
plater.request_slice(args.all_plates);
ticket.request_seq = plater.slice_request_seq();
ticket.slicing = plater.is_slicing_any();
// A request that returned early (a gizmo in editing mode, say) left a run that was slicing
// already to finish; its result is the one the request gets.
if (plater.slice_run_seq() == ticket.run_seq_before)
if (const std::optional<Plater::SliceRun> running = plater.slice_run(ticket.run_seq_before); running && !running->finished)
ticket.adopted_run = running->seq;
// The Preview tab shows the result, as after the Slice button.
if (MainFrame* frame = wxGetApp().mainframe)
frame->select_tab(wxString(TAB_ID_PREVIEW));
return ticket;
}
LayerTicks layer_ticks(std::optional<int> first, int last, int count)
{
const int max = std::max(count - 1, 0);
LayerTicks ticks;
ticks.high = std::clamp(last - 1, 0, max);
if (first) {
ticks.low = std::clamp(*first - 1, 0, max);
ticks.high = std::max(ticks.high, *ticks.low);
}
return ticks;
}
Outcome<int> layer_count()
{
GLCanvas3D* canvas = the_plater().get_preview_canvas3D();
IMSlider* layers = canvas != nullptr ? canvas->get_gcode_viewer().get_layers_slider() : nullptr;
// The slider's range alone says nothing: it starts at 0..100 before a print gives it its layers.
if (layers == nullptr || layers->values_count() == 0)
return no_layers();
return layers->GetMaxValue() + 1;
}
Outcome<ShownLayers> show_layer_range(const ShowLayerRangeArgs& args)
{
const Outcome<int> count = layer_count();
if (!count)
return count.refusal();
GCodeViewer& viewer = the_plater().get_preview_canvas3D()->get_gcode_viewer();
IMSlider* layers = viewer.get_layers_slider();
const LayerTicks ticks = layer_ticks(args.first, args.last, count.value());
viewer.show_layer_range(ticks.low, ticks.high);
ShownLayers shown;
shown.first = layers->GetLowerValue() + 1;
shown.last = layers->GetHigherValue() + 1;
shown.z_first = layers->GetLowerValueD();
shown.z_last = layers->GetHigherValueD();
shown.asked_first = ticks.low ? *ticks.low + 1 : shown.first;
shown.asked_last = ticks.high + 1;
shown.count = count.value();
return shown;
}
}}} // namespace Slic3r::GUI::Ops
+125
View File
@@ -0,0 +1,125 @@
#pragma once
#include "Outcome.hpp"
#include <cstdint>
#include <optional>
#include <vector>
// Plates, what is arranged and sliced on them, and the sliced plate's layers in the Preview.
namespace Slic3r { namespace GUI { namespace Ops {
// The refusal for a plate index the project lacks (no_such_plate), `count` being how many it has.
Refusal no_such_plate(int plate, int count);
struct SelectPlateArgs
{
int plate = 0;
};
// Makes the plate the current one.
// Refuses: no_such_plate, plate_not_selected.
Outcome<Done> select_plate(const SelectPlateArgs& args);
struct SetPlateLockedArgs
{
std::optional<int> plate; // none: the current plate
bool locked = true;
};
struct PlateLocked
{
int plate = 0;
bool changed = false; // false: the plate was in that state already, and no undo step was taken
};
// Locks or unlocks the plate, as one undo step.
// Refuses: no_such_plate.
Outcome<PlateLocked> set_plate_locked(const SetPlateLockedArgs& args);
// The refusal while the UI job worker runs a job, such as an arrangement or an orientation (job_running).
Refusal job_running();
// Shows the Prepare view when another view is shown. start_arrange() does it first; a caller with
// work of its own in that view before the start calls it earlier.
void show_prepare_view();
struct ArrangeArgs
{
std::optional<int> plate; // none: every unlocked plate, as the toolbar's Arrange; else that plate alone, as its Arrange icon
};
// What start_arrange() would refuse now (no_objects_to_arrange, no_such_plate, job_running), for a
// caller with work of its own between the check and the start.
std::optional<Refusal> arrange_refusal(const ArrangeArgs& args);
// Shows the Prepare view, selects the plate when one is given and starts the arrangement in the
// background, as one undo step; the UI job worker is busy until it ends. As the toolbar's Arrange
// does, it runs whatever gizmo is open.
// Refuses: no_objects_to_arrange, no_such_plate, job_running, plate_not_selected.
Outcome<Done> start_arrange(const ArrangeArgs& args);
struct SliceArgs
{
bool all_plates = false;
std::optional<int> plate; // none: the current plate
};
// A slice request, in Plater's own numbering (slice_request_seq(), slice_run_seq(), project_revision()),
// from which a caller builds slice_status()'s state.
struct SliceTicket
{
std::vector<int> plates; // the plates asked for
uint64_t run_seq_before = 0; // the run sequence before the request
uint64_t request_seq = 0; // the request sequence right after it
uint64_t revision = 0; // the project revision when it was made
uint64_t adopted_run = 0; // a run already slicing that the request left running, or 0
bool slicing = false; // slicing in any form right after the request
};
// The plates a slice of `args` covers.
// Refuses: no_such_plate.
Outcome<std::vector<int>> slice_plates(const SliceArgs& args);
// Selects the plate when it is not the current one, requests the slice as the Slice button does and
// shows the Preview tab. Returns at once; slice_status() says how the slice stands.
// Refuses: no_such_plate.
Outcome<SliceTicket> start_slice(const SliceArgs& args);
// How many layers the Preview has to show, for a caller that turns an argument of its own into a
// layer. The slider keeps the last slice's layers until another slice replaces them, so a plate that
// is empty or not sliced can still have layers to show.
// Refuses: no_layers (the layer slider is absent or was given no layers, as before the first slice).
Outcome<int> layer_count();
struct ShowLayerRangeArgs
{
// 1-based. None: the upper thumb alone is dragged to `last`. The bottom of the shown range stays
// while `last` is above it; at or below it, or where the slider shows one layer at a time, the one
// layer `last` is shown.
std::optional<int> first;
int last = 1; // 1-based
};
// The slider ticks (0-based) a range of layers is shown by.
struct LayerTicks
{
std::optional<int> low; // none: the lower thumb is not moved
int high = 0;
};
// The ticks for layers `first`..`last` (1-based) of a plate with `count` layers: each number is brought
// into the plate's layers, and a last below the first is raised to it, so a range given backwards
// shows its first layer alone.
LayerTicks layer_ticks(std::optional<int> first, int last, int count);
struct ShownLayers
{
// The range the slider shows afterwards, 1-based, and the heights of its bottom and top layer.
int first = 1;
int last = 1;
double z_first = 0.;
double z_last = 0.;
// The range that was asked for, brought into the plate's layers by layer_ticks(); `asked_first` is
// `first` when no first layer was given. It is the range shown, except where the slider shows one
// layer at a time: it then shows the first layer asked for when one was given, else the last.
int asked_first = 1;
int asked_last = 1;
int count = 0; // layers the plate has
};
// Shows these layers of the sliced plate in the Preview, with every move of the top one. The numbers
// are brought into the plate's layers by layer_ticks().
// Refuses: no_layers.
Outcome<ShownLayers> show_layer_range(const ShowLayerRangeArgs& args);
}}} // namespace Slic3r::GUI::Ops
+371
View File
@@ -0,0 +1,371 @@
#include "PresetOps.hpp"
#include "Outcome.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/Plater.hpp"
#include "slic3r/GUI/PresetComboBoxes.hpp"
#include "slic3r/GUI/Tab.hpp"
#include "libslic3r/Preset.hpp"
#include "libslic3r/PresetBundle.hpp"
#include <boost/filesystem/path.hpp>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstddef>
#include <initializer_list>
#include <optional>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <wx/thread.h>
namespace Slic3r { namespace GUI { namespace Ops {
namespace {
Preset::Type preset_type(PresetKind kind)
{
switch (kind) {
case PresetKind::Printer: return Preset::TYPE_PRINTER;
case PresetKind::Filament: return Preset::TYPE_FILAMENT;
default: return Preset::TYPE_PRINT;
}
}
PresetCollection& collection(PresetBundle& bundle, PresetKind kind)
{
switch (kind) {
case PresetKind::Printer: return bundle.printers;
case PresetKind::Filament: return bundle.filaments;
default: return bundle.prints;
}
}
std::string lower(std::string s)
{
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return char(std::tolower(c)); });
return s;
}
// The presets `name` names, by name or alias, that `keep` accepts. The real presets, not the edited copy.
template<class Keep> std::vector<Preset*> presets_named(PresetCollection& presets, const std::string& name, Keep keep)
{
const std::string want = Preset::remove_suffix_modified(name);
std::vector<Preset*> found;
for (std::size_t i = 0; i < presets.size(); ++i)
if (Preset& p = presets.preset(i, true); (p.name == want || p.alias == want) && keep(p))
found.push_back(&p);
return found;
}
std::vector<std::string> names_of(const std::vector<Preset*>& presets)
{
std::vector<std::string> names;
for (const Preset* p : presets)
names.push_back(p->name);
return names;
}
// Shows the hidden preset `name` names in the selectors, as they show the preset selected and the filaments an AMS
// holds: in memory, so the setup wizard's list, and with it what the next start shows, stays as it is. A hidden
// preset is one the wizard has not added (a filament, a printer model), not a refusal, so selecting one by name
// needs no detour through the wizard. Only a compatible one, as the selectors list no other. Returns its name, empty
// when `name` names no hidden compatible preset.
Outcome<std::string> show_hidden_preset(PresetCollection& presets, const std::string& name)
{
std::vector<Preset*> hidden = presets_named(presets, name, [](const Preset& p) { return !p.is_visible && p.is_compatible; });
// A preset's own name wins over another's alias that reads the same ("Generic PLA").
const std::string want = Preset::remove_suffix_modified(name);
const auto exact = std::find_if(hidden.begin(), hidden.end(), [&want](const Preset* p) { return p->name == want; });
if (exact != hidden.end())
hidden = {*exact};
if (hidden.size() > 1)
return Refusal{RefusalKind::Precondition, "ambiguous_hidden_preset", L("\"%1%\" names several hidden presets. Use the preset's internal name."),
{name}, names_of(hidden)};
if (hidden.empty())
return std::string();
hidden.front()->is_visible = true;
return hidden.front()->name;
}
// Shows the default filaments of a printer show_hidden_preset() showed when no shown filament suits it, as adding the
// printer in the setup wizard does (PresetBundle::load_installed_filaments()), so selecting the printer lands on
// one of them rather than on the default filament. In memory, as the printer is.
void show_default_filaments(PresetBundle& bundle, const std::string& printer_name)
{
const Preset* printer = bundle.printers.find_preset(printer_name, false);
const VendorProfile::PrinterModel* model = printer != nullptr ? PresetUtils::system_printer_model(*printer) : nullptr;
if (model == nullptr)
return;
const PresetWithVendorProfile with_vendor = bundle.printers.get_preset_with_vendor_profile(*printer);
for (const Preset& filament : bundle.filaments)
if (filament.is_visible && is_compatible_with_printer(bundle.filaments.get_preset_with_vendor_profile(filament), with_vendor))
return;
for (const std::string& name : model->default_materials)
if (Preset* filament = bundle.filaments.find_preset(name, false, true); filament != nullptr && filament->is_system)
filament->is_visible = true;
}
// The refusal of a name a selector does not list: incompatible with the printer, or no preset's name. `filament_slot`
// names the slot whose selector it is, 0 for a tab's.
Refusal not_offered(PresetCollection& presets, const std::string& name, int filament_slot)
{
if (const std::vector<Preset*> incompatible = presets_named(presets, name, [](const Preset& p) { return !p.is_compatible; });
!incompatible.empty())
return {RefusalKind::Precondition, "preset_incompatible", L("\"%1%\" is not compatible with the selected printer."), {name},
names_of(incompatible)};
if (filament_slot > 0)
// TRN %1% is a preset name, %2% a filament slot number.
return {RefusalKind::Precondition, "preset_not_offered", L("The selector of filament slot %2% does not offer \"%1%\"."),
{name, std::to_string(filament_slot)}, similar_preset_names(presets, name)};
return {RefusalKind::Precondition, "preset_not_offered", L("The preset selector does not offer \"%1%\"."), {name},
similar_preset_names(presets, name)};
}
Refusal ambiguous(const std::string& name, int filament_slot)
{
if (filament_slot > 0)
// TRN %1% is a preset name, %2% a filament slot number.
return {RefusalKind::Precondition, "ambiguous_preset_name",
L("The name \"%1%\" is ambiguous in the selector of filament slot %2%. Use the preset's internal name."),
{name, std::to_string(filament_slot)}};
return {RefusalKind::Precondition, "ambiguous_preset_name",
L("The name \"%1%\" is ambiguous in the preset selector. Use the preset's internal name."), {name}};
}
Refusal tab_unavailable() { return {RefusalKind::Failed, "tab_unavailable", L("The settings tab is not available.")}; }
// The filament slots a caller can name: the sidebar's selectors, one per physical filament.
std::size_t filament_slots(Sidebar& sidebar, const PresetBundle& bundle)
{
const std::size_t selectors = sidebar.combos_filament().size();
return selectors > 0 ? selectors : bundle.num_physical_filaments();
}
Refusal no_such_slot(int slot, std::size_t slots)
{
// TRN %1% is the filament slot number asked for, %2% the last slot's number.
return {RefusalKind::Precondition, "no_such_slot", L("Filament slot %1% does not exist (the slots are 1..%2%)"),
{std::to_string(slot), std::to_string(slots)}};
}
// The prompt about a tab's own unsaved changes offers Transfer only where Tab::can_transfer_changes_to() says;
// refused before anything changes.
std::optional<Refusal> transfer_refusal(const Tab& tab, const PresetCollection& presets, PresetKind kind, const std::string& preset,
PresetChanges changes)
{
if (changes != PresetChanges::Transfer || !presets.current_is_dirty() || tab.can_transfer_changes_to(preset))
return std::nullopt;
if (kind == PresetKind::Printer)
return Refusal{RefusalKind::Precondition, "transfer_not_offered",
L("The unsaved changes cannot be transferred: a printer's changes stay with it.")};
return Refusal{RefusalKind::Precondition, "transfer_not_offered",
L("The unsaved changes cannot be transferred: \"%1%\" is a filament of another type."), {preset}};
}
// Gives a tab the caller's answer to its unsaved-changes prompt for one switch.
class AnswerScope
{
public:
AnswerScope(Tab& tab, PresetChanges changes) : m_tab(tab)
{
m_tab.m_dirty_preset_answer = changes == PresetChanges::Transfer ? Tab::DirtyPresetAnswer::Transfer :
changes == PresetChanges::Discard ? Tab::DirtyPresetAnswer::Discard :
Tab::DirtyPresetAnswer::Ask;
}
~AnswerScope() { m_tab.m_dirty_preset_answer = Tab::DirtyPresetAnswer::Ask; }
AnswerScope(const AnswerScope&) = delete;
AnswerScope& operator=(const AnswerScope&) = delete;
private:
Tab& m_tab;
};
} // namespace
std::optional<Refusal> mixed_slot_refusal(int filament_slot)
{
assert(wxThread::IsMain());
const PresetBundle& bundle = *wxGetApp().preset_bundle;
if (filament_slot < 1 || std::size_t(filament_slot) > bundle.filament_presets.size() ||
!bundle.is_mixed_filament(std::size_t(filament_slot) - 1))
return std::nullopt;
// TRN %1% is a filament slot number.
return Refusal{RefusalKind::Precondition, "mixed_filament_slot",
L("Filament slot %1% is a mixed-color virtual slot, which has no filament preset of its own."),
{std::to_string(filament_slot)}};
}
std::vector<std::string> similar_preset_names(const PresetCollection& presets, const std::string& name)
{
std::vector<std::string> words;
std::istringstream in(lower(name));
for (std::string w; in >> w;)
words.push_back(w);
std::vector<std::pair<int, std::string>> scored;
for (std::size_t i = 0; i < presets.size(); ++i) {
const Preset& p = presets.preset(i);
if (p.is_default)
continue;
const std::string n = lower(p.name);
const int matched = int(std::count_if(words.begin(), words.end(), [&n](const std::string& w) { return n.find(w) != std::string::npos; }));
if (matched > 0)
scored.emplace_back(-(2 * matched + (p.is_compatible ? 1 : 0)), p.name);
}
std::sort(scored.begin(), scored.end());
std::vector<std::string> out;
for (std::size_t i = 0; i < scored.size() && i < 5; ++i)
out.push_back(scored[i].second);
return out;
}
Outcome<ResolvedPreset> resolve_preset(const ResolvePresetArgs& args)
{
assert(wxThread::IsMain());
PresetBundle& bundle = *wxGetApp().preset_bundle;
PresetCollection& presets = collection(bundle, args.kind);
Tab* tab = wxGetApp().get_tab(preset_type(args.kind));
// The selector whose list decides: the slot's for a filament, else, or where that one is not
// populated, the tab's.
PresetComboBox* selector = nullptr;
int slot = 0; // the slot whose selector it is, 0 for the tab's
if (args.kind == PresetKind::Filament) {
if (std::optional<Refusal> refusal = mixed_slot_refusal(args.filament_slot))
return *refusal;
Sidebar& sidebar = wxGetApp().plater()->sidebar();
std::vector<PlaterPresetComboBox*>& combos = sidebar.combos_filament();
const std::size_t slots = filament_slots(sidebar, bundle);
if (args.filament_slot < 1 || std::size_t(args.filament_slot) > slots)
return no_such_slot(args.filament_slot, slots);
PlaterPresetComboBox* combo = std::size_t(args.filament_slot) <= combos.size() ? combos[std::size_t(args.filament_slot) - 1] : nullptr;
if (combo != nullptr && combo->GetCount() > 0) {
selector = combo;
slot = args.filament_slot;
}
}
if (selector == nullptr && tab != nullptr)
if (TabPresetComboBox* combo = tab->get_combo_box(); combo != nullptr && combo->GetCount() > 0)
selector = combo;
if (selector == nullptr) {
// Nothing is laid out to resolve against: internal names.
const Preset* preset = presets.find_preset(args.name);
if (preset == nullptr)
return not_offered(presets, args.name, 0);
return ResolvedPreset{preset->name, {}};
}
ResolvedPreset resolved;
PresetComboBox::NameMatch match = selector->find_by_name(args.name);
if (match.item < 0 && !match.ambiguous) {
const Outcome<std::string> shown = show_hidden_preset(presets, args.name);
if (!shown)
return shown.refusal();
if (!shown.value().empty()) {
resolved.shown = shown.value();
if (args.kind == PresetKind::Printer)
show_default_filaments(bundle, resolved.shown);
if (slot > 0) {
// Every slot's selector lists the filaments.
for (PlaterPresetComboBox* combo : wxGetApp().plater()->sidebar().combos_filament())
if (combo != nullptr)
combo->update();
} else {
selector->update();
}
match = selector->find_by_name(resolved.shown);
}
}
if (match.ambiguous)
return ambiguous(args.name, slot);
if (match.item < 0)
return not_offered(presets, args.name, slot);
resolved.name = match.internal_name;
return resolved;
}
Outcome<Done> select_preset(const SelectPresetArgs& args)
{
assert(wxThread::IsMain());
assert(args.kind != PresetKind::Filament);
PresetCollection& presets = collection(*wxGetApp().preset_bundle, args.kind);
Tab* tab = wxGetApp().get_tab(preset_type(args.kind));
if (tab == nullptr)
return tab_unavailable();
if (std::optional<Refusal> refusal = transfer_refusal(*tab, presets, args.kind, args.preset, args.changes))
return *refusal;
AnswerScope answer(*tab, args.changes);
if (!tab->select_preset(args.preset))
return Refusal{RefusalKind::Failed, "selection_cancelled", L("Selecting \"%1%\" was cancelled."), {args.preset}};
// The tab can end on another preset than the one it was given, where that one is not among its choices.
if (const std::string selected = presets.get_selected_preset_name(); selected != args.preset)
// TRN %1% is the preset asked for, %2% the one that is selected.
return Refusal{RefusalKind::Failed, "other_preset_selected", L("\"%2%\" was selected instead of \"%1%\"."), {args.preset, selected}};
return Done{};
}
Outcome<std::string> assign_filament_preset(const AssignFilamentArgs& args)
{
assert(wxThread::IsMain());
PresetBundle& bundle = *wxGetApp().preset_bundle;
Sidebar& sidebar = wxGetApp().plater()->sidebar();
const std::size_t slots = filament_slots(sidebar, bundle);
if (std::optional<Refusal> refusal = mixed_slot_refusal(args.filament_slot))
return *refusal;
if (args.filament_slot < 1 || std::size_t(args.filament_slot) > slots || std::size_t(args.filament_slot) > bundle.filament_presets.size())
return no_such_slot(args.filament_slot, slots);
// The sidebar switches the filament tab for a single filament only, and there its prompt applies.
Tab* tab = wxGetApp().get_tab(Preset::TYPE_FILAMENT);
const bool switches_tab = args.switch_tab && !sidebar.is_multifilament();
if (switches_tab) {
if (tab == nullptr)
return tab_unavailable();
if (std::optional<Refusal> refusal = transfer_refusal(*tab, bundle.filaments, PresetKind::Filament, args.preset, args.changes))
return *refusal;
}
std::optional<AnswerScope> answer;
if (tab != nullptr)
answer.emplace(*tab, args.changes);
sidebar.select_filament_preset(std::size_t(args.filament_slot) - 1, args.preset, args.switch_tab);
return bundle.filament_presets[std::size_t(args.filament_slot) - 1];
}
Outcome<ImportedPresets> import_presets(const ImportPresetsArgs& args)
{
assert(wxThread::IsMain());
const PresetBundle& bundle = *wxGetApp().preset_bundle;
const auto names = [&bundle] {
std::set<std::pair<int, std::string>> out;
for (const PresetCollection* presets : std::initializer_list<const PresetCollection*>{&bundle.prints, &bundle.filaments, &bundle.printers})
for (const Preset& preset : presets->get_presets())
out.emplace(int(presets->type()), preset.name);
return out;
};
const auto before = names();
ImportedPresets result;
// Answered for each preset that exists already as the dialog's Yes or No would be, never "to all",
// which would stop the questions, so that every one of them can be named.
wxGetApp().mainframe->import_configs({into_u8(from_path(args.path))}, [&](const std::string& name) {
(args.overwrite ? result.replaced : result.kept).push_back(name);
return args.overwrite ? 1 : 0;
});
for (const auto& name : names())
if (before.count(name) == 0)
result.imported.push_back(name.second);
if (result.imported.empty() && result.replaced.empty() && result.kept.empty())
return Refusal{RefusalKind::Failed, "no_presets_imported",
L("No presets were imported.\nHint: Make sure you have added the corresponding printer before importing the configs.")};
return result;
}
}}} // namespace Slic3r::GUI::Ops
+99
View File
@@ -0,0 +1,99 @@
#pragma once
#include "Outcome.hpp"
#include <boost/filesystem/path.hpp>
#include <optional>
#include <string>
#include <vector>
namespace Slic3r {
class PresetCollection;
// Presets: the one a printer or process tab edits, the one a filament slot holds, and preset files
// imported.
//
// A caller selects in two steps. resolve_preset() turns the name a person or an agent gives into the
// preset the selector takes for it; select_preset() or assign_filament_preset() then acts on the name
// it returned. A caller with a step of its own between the two (the plugin API switches the preset its
// transaction edits) takes it there.
namespace GUI { namespace Ops {
enum class PresetKind { Printer, Process, Filament };
// What becomes of the unsaved changes of the preset a tab leaves: the owner's Transfer-or-discard
// prompt opens (Ask), or it is answered for the person.
enum class PresetChanges { Ask, Transfer, Discard };
// The refusal for a filament slot (1-based) that is a mixed-color virtual one (mixed_filament_slot),
// or none. Such a slot is made of other slots' filaments and holds no preset of its own.
std::optional<Refusal> mixed_slot_refusal(int filament_slot);
struct ResolvePresetArgs
{
PresetKind kind = PresetKind::Process;
std::string name; // as the selector shows it, or the internal name
int filament_slot = 1; // Filament only, 1-based
};
struct ResolvedPreset
{
std::string name; // internal name
std::string shown; // the hidden preset that was shown, or ""
};
// The preset the selector takes for the name: the slot's selector for a filament, the tab's otherwise;
// where no selector is populated, or the settings tab is missing, the tab's for a filament slot, then
// internal names. A hidden compatible preset the name stands for is shown in the selectors first, and
// stays shown until the app restarts, whatever comes of the call after it.
// Refuses: mixed_filament_slot, no_such_slot, ambiguous_preset_name, ambiguous_hidden_preset (with the
// candidates), preset_incompatible (with the incompatible presets of that name),
// preset_not_offered (with the closest names).
Outcome<ResolvedPreset> resolve_preset(const ResolvePresetArgs& args);
struct SelectPresetArgs
{
PresetKind kind = PresetKind::Process; // Printer or Process
std::string preset; // internal name, as resolve_preset() returned it
PresetChanges changes = PresetChanges::Ask;
};
// Makes the preset the one its tab edits, as picking it in the tab's selector does.
// Refuses: tab_unavailable, transfer_not_offered, selection_cancelled, other_preset_selected (the tab
// ended on another preset, which stays selected).
Outcome<Done> select_preset(const SelectPresetArgs& args);
struct AssignFilamentArgs
{
int filament_slot = 1; // 1-based
std::string preset; // internal name, as resolve_preset() returned it
PresetChanges changes = PresetChanges::Ask; // for the filament tab's switch on a printer with one filament
bool switch_tab = true; // false: the caller has made the tab edit the preset already
};
// Assigns the preset to the slot as picking it in the slot's selector does (Sidebar::select_filament_preset()).
// Returns the preset the slot holds afterwards. A declined prompt on a printer with one filament is no
// refusal: the slot is assigned before the tab asks.
// Refuses: mixed_filament_slot, no_such_slot, transfer_not_offered, and tab_unavailable where the
// assignment would switch the filament tab (one filament, `switch_tab`) and there is none.
Outcome<std::string> assign_filament_preset(const AssignFilamentArgs& args);
struct ImportPresetsArgs
{
boost::filesystem::path path; // a preset .json, a .zip of them, or an .orca_printer, .orca_filament or .orca_bundle
bool overwrite = false; // replace a preset that exists already; else keep it
};
struct ImportedPresets
{
std::vector<std::string> imported; // presets that are new
std::vector<std::string> replaced;
std::vector<std::string> kept; // presets that exist already and were left as they are
};
// Imports the file's presets as the Import Configs dialog does, with its question about each preset
// that exists already answered by `overwrite`.
// Refuses: no_presets_imported.
Outcome<ImportedPresets> import_presets(const ImportPresetsArgs& args);
// The names of `presets` closest to `name`, those compatible with the printer first: what a refusal
// of an unknown preset name carries, for a caller that refuses one itself.
std::vector<std::string> similar_preset_names(const PresetCollection& presets, const std::string& name);
}} // namespace GUI::Ops
} // namespace Slic3r
+147
View File
@@ -0,0 +1,147 @@
#include "ProjectOps.hpp"
#include "Outcome.hpp"
#include "PlateOps.hpp"
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/GUI_ObjectList.hpp"
#include "slic3r/GUI/I18N.hpp"
#include "slic3r/GUI/PartPlate.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "libslic3r/Format/ProjectStrategy.hpp"
#include "libslic3r/Model.hpp"
#include "libslic3r/Utils.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/system/error_code.hpp>
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <optional>
#include <string>
#include <vector>
#include <wx/string.h>
#include <wx/thread.h>
namespace Slic3r { namespace GUI { namespace Ops {
namespace {
Plater& the_plater()
{
assert(wxThread::IsMain());
return *wxGetApp().plater();
}
ProjectSummary summary(Plater& plater)
{
ProjectSummary out;
for (const ModelObject* object : plater.model().objects)
out.object_names.push_back(object->name);
out.plates = plater.get_partplate_list().get_plate_count();
return out;
}
} // namespace
std::optional<Refusal> unsaved_changes_refusal(UnsavedChanges unsaved)
{
if (unsaved == UnsavedChanges::Discard || !the_plater().is_project_dirty())
return std::nullopt;
return Refusal{RefusalKind::Precondition, "unsaved_changes", L("The project has unsaved changes.")};
}
Outcome<ImportModelsResult> import_models(const ImportModelsArgs& args)
{
Plater& plater = the_plater();
// The label File > Import gives its own undo step (Plater::add_file()).
std::string label = "Import Objects";
for (size_t i = 0; i < args.paths.size(); ++i)
label += (i == 0 ? ": " : ", ") + encode_path(args.paths[i].filename().string().c_str());
const size_t before = plater.model().objects.size();
Plater::TakeSnapshot snapshot(&plater, label);
const std::vector<size_t> loaded = plater.load_files(args.paths, LoadStrategy::LoadModel);
if (loaded.empty() && plater.model().objects.size() == before)
return Refusal{RefusalKind::Failed, "nothing_loaded", L("Nothing was imported.")};
return ImportModelsResult{plater.model().objects.size() - before};
}
Outcome<ProjectSummary> open_project(const OpenProjectArgs& args)
{
Plater& plater = the_plater();
if (std::optional<Refusal> refusal = unsaved_changes_refusal(args.unsaved))
return *refusal;
// Dropped here, so Plater::load_project() finds nothing to ask about; the reset tells no plugin
// and switches no tab, since the project that counts is the one about to load.
if (plater.is_project_dirty())
plater.new_project(/*skip_confirm=*/true, /*silent=*/true);
plater.load_project(from_path(args.path));
return summary(plater);
}
Outcome<ProjectSummary> new_project(const NewProjectArgs& args)
{
Plater& plater = the_plater();
if (std::optional<Refusal> refusal = unsaved_changes_refusal(args.unsaved))
return *refusal;
// New Project's prompt drops them before the reset; only with changes to drop, since dropping
// reloads the presets, which can ask about the printer's.
if (args.discard_preset_changes && wxGetApp().has_current_preset_changes())
wxGetApp().discard_current_preset_changes();
plater.new_project(/*skip_confirm=*/true, /*silent=*/true, wxString(), /*reload_presets=*/true, /*tell_plugins=*/true);
return summary(plater);
}
Outcome<Done> save_project_as(const SaveProjectAsArgs& args)
{
if (boost::algorithm::iends_with(args.path.string(), ".gcode.3mf"))
return Refusal{RefusalKind::Precondition, "sliced_file_name",
L("A project is saved without G-code, so its file name cannot end in .gcode.3mf. Export the sliced file instead.")};
the_plater().save_project(/*saveAs=*/true, from_path(args.path));
boost::system::error_code ec;
if (!boost::filesystem::exists(args.path, ec))
return Refusal{RefusalKind::Failed, "project_not_saved", L("The project was not saved.")};
return Done{};
}
std::optional<Refusal> instance_count_refusal()
{
Plater& plater = the_plater();
const int obj_idx = plater.get_selected_object_idx();
if (obj_idx < 0)
return Refusal{RefusalKind::Precondition, "no_object_selected", L("Select an object first.")};
const ModelObject* object = plater.model().objects[size_t(obj_idx)];
if (const ObjectList* list = wxGetApp().obj_list(); list != nullptr && list->has_selected_cut_object())
return Refusal{RefusalKind::Precondition, "cut_object", L("A cut object keeps its number of instances.")};
if (std::any_of(object->instances.begin(), object->instances.end(), [](const ModelInstance* i) { return !i->printable; }))
return Refusal{RefusalKind::Precondition, "unprintable_instance", L("Make every instance of the object printable first.")};
if (!plater.can_increase_instances())
return job_running();
return std::nullopt;
}
Refusal bad_instance_count()
{
return {RefusalKind::Precondition, "bad_instance_count", L("The number of instances is a whole number from 1 to 1000.")};
}
Outcome<InstanceCount> set_instance_count(const SetInstanceCountArgs& args)
{
Plater& plater = the_plater();
if (args.count < 1 || args.count > 1000)
return bad_instance_count();
if (std::optional<Refusal> refusal = instance_count_refusal())
return *refusal;
const int obj_idx = plater.get_selected_object_idx();
plater.set_number_of_copies(args.count);
return InstanceCount{obj_idx, plater.model().objects[size_t(obj_idx)]->instances.size()};
}
}}} // namespace Slic3r::GUI::Ops
+97
View File
@@ -0,0 +1,97 @@
#pragma once
#include "Outcome.hpp"
#include <boost/filesystem/path.hpp>
#include <cstddef>
#include <optional>
#include <string>
#include <vector>
// The project as a whole: models imported into it, a project file opened, saved or started anew, and
// its objects' instance counts.
namespace Slic3r { namespace GUI { namespace Ops {
// What becomes of the open project's unsaved changes when a call replaces the project. No operation
// asks about them: a caller that wants the person asked calls the owner's own method.
enum class UnsavedChanges { Refuse, Discard };
// The refusal for a project with unsaved changes that the caller did not say to drop
// (unsaved_changes), or none when the call may go ahead.
std::optional<Refusal> unsaved_changes_refusal(UnsavedChanges unsaved);
// What a project holds once a call has replaced it.
struct ProjectSummary
{
std::vector<std::string> object_names;
int plates = 0;
};
struct ImportModelsArgs
{
std::vector<boost::filesystem::path> paths;
};
struct ImportModelsResult
{
size_t added = 0; // objects the import added
};
// Adds the files' geometry to the open project (LoadStrategy::LoadModel: a project file's settings
// are not loaded), as one "Import Objects: <files>" undo step. The owner's import can open a dialog
// of its own (a STEP file's mesh options).
// Refuses: nothing_loaded. The undo step stays in the history then, as after an import from the
// File menu whose load fails.
Outcome<ImportModelsResult> import_models(const ImportModelsArgs& args);
struct OpenProjectArgs
{
boost::filesystem::path path;
UnsavedChanges unsaved = UnsavedChanges::Refuse;
};
// Replaces the open project with the file. Unsaved changes of the open project are dropped without a
// question when the caller says so; what Plater::load_project() asks beyond that (modified presets,
// how to open the 3mf) it still asks.
// Refuses: unsaved_changes.
Outcome<ProjectSummary> open_project(const OpenProjectArgs& args);
struct NewProjectArgs
{
UnsavedChanges unsaved = UnsavedChanges::Refuse;
bool discard_preset_changes = false; // drop the presets' unsaved changes first; else they carry over
};
// Starts a new, empty project without a question. Plugins get the NewProject event; the shown tab
// stays as it is.
// Refuses: unsaved_changes.
Outcome<ProjectSummary> new_project(const NewProjectArgs& args);
struct SaveProjectAsArgs
{
boost::filesystem::path path;
};
// Saves the project to the path, which becomes the project's file. A name ending in .gcode.3mf is a
// sliced file's, and a project file holds no G-code, so it is refused.
// Refuses: sliced_file_name, project_not_saved.
Outcome<Done> save_project_as(const SaveProjectAsArgs& args);
// What keeps the number of instances of the object selected in the Prepare view from being set
// (no_object_selected, cut_object, unprintable_instance, job_running), or none: the reasons the
// object menu's item is disabled, each with its own message.
std::optional<Refusal> instance_count_refusal();
// The refusal for a number of instances outside 1..1000 (bad_instance_count).
Refusal bad_instance_count();
struct SetInstanceCountArgs
{
int count = 1;
};
struct InstanceCount
{
int object = 0; // the selected object's index
size_t instances = 0; // the instances it has now
};
// Sets how many instances the object selected in the Prepare view has, as the object menu's item does
// once its dialog is answered.
// Refuses: bad_instance_count, and what instance_count_refusal() gives.
Outcome<InstanceCount> set_instance_count(const SetInstanceCountArgs& args);
}}} // namespace Slic3r::GUI::Ops
@@ -1,4 +1,4 @@
#include "McpOperations.hpp"
#include "RunStatus.hpp"
#include <algorithm>
#include <chrono>
@@ -6,7 +6,7 @@
#include <optional>
#include <vector>
namespace Slic3r { namespace GUI { namespace Mcp {
namespace Slic3r { namespace GUI { namespace Ops {
const char* to_string(PlateOutcome outcome)
{
@@ -132,4 +132,4 @@ ExportStatus export_status(uint64_t seq_before, uint64_t seq_after, const std::o
return ExportStatus::Ok;
}
}}} // namespace Slic3r::GUI::Mcp
}}} // namespace Slic3r::GUI::Ops
@@ -6,10 +6,11 @@
#include <string>
#include <vector>
namespace Slic3r { namespace GUI { namespace Mcp {
namespace Slic3r { namespace GUI { namespace Ops {
// The decision logic of the slice and export operations, kept free of wx and Plater so it can be
// unit-tested: the tools observe Plater on the UI thread and feed the observations in here.
// How a started slice or export stands, decided from what Plater recorded of it. Free of wx and of
// Plater, so it is unit-tested: a caller observes Plater on the UI thread and feeds the observations
// in here.
enum class PlateOutcome { Ok, Error, Cancelled, Empty, Skipped };
@@ -126,4 +127,4 @@ const char* to_string(ExportStatus status);
// export; an unchanged sequence means it never started. `record` is the record of `seq_after`.
ExportStatus export_status(uint64_t seq_before, uint64_t seq_after, const std::optional<ExportRecord>& record, uint64_t revision_at_start);
}}} // namespace Slic3r::GUI::Mcp
}}} // namespace Slic3r::GUI::Ops
+136 -59
View File
@@ -7662,6 +7662,11 @@ struct Plater::priv
void on_combobox_select(wxCommandEvent&);
void on_select_bed_type(wxCommandEvent&);
void on_select_preset(wxCommandEvent&);
// The plater's part of a filament preset picked for slot `idx`, after the selector's own
// (PlaterPresetComboBox::item_picked()): the mapping, the flushing volumes, the project state and, on a
// printer with one filament, the filament tab unless `switch_tab` is false. `combo` is the slot's
// selector and `item` the picked item, -1 when the selector lists none for the preset.
void filament_preset_picked(int idx, const std::string& preset_name, PlaterPresetComboBox* combo, int item, bool switch_tab);
void on_slicing_update(SlicingStatusEvent&);
void on_slicing_completed(wxCommandEvent&);
void on_process_completed(SlicingProcessCompletedEvent&);
@@ -13292,6 +13297,98 @@ void Plater::priv::on_select_bed_type(wxCommandEvent &evt)
}
}
// The internal name of the preset that item `selection` of `combo` stands for.
static std::string preset_name_of_item(PlaterPresetComboBox& combo, int selection)
{
//! Because of The MSW and GTK version of wxBitmapComboBox derived from wxComboBox,
//! but the OSX version derived from wxOwnerDrawnCombo.
//! So, to get selected string we do
//! combo->GetString(combo->GetSelection())
//! instead of
//! combo->GetStringSelection().ToUTF8().data());
// Prefer the internal preset name stored per combo item to avoid alias collisions
// (e.g. user preset and bundle preset sharing the same display alias).
wxString wx_stored_name = combo.GetItemAlias(selection);
if (!wx_stored_name.empty())
return Preset::remove_suffix_modified(wx_stored_name.ToUTF8().data());
wxString wx_name = combo.GetString(selection);
return wxGetApp().preset_bundle->get_preset_name_by_alias(combo.get_type(), Preset::remove_suffix_modified(wx_name.ToUTF8().data()));
}
void Sidebar::select_filament_preset(size_t slot_index, const std::string& preset_name, bool switch_tab)
{
PlaterPresetComboBox* combo = slot_index < p->combos_filament.size() ? p->combos_filament[slot_index] : nullptr;
const int item = combo != nullptr ? combo->item_for_preset(preset_name) : -1;
std::string name = preset_name;
if (item >= 0) {
// The selector's part of a pick, then the plater's, in the order its event runs them.
combo->SetSelection(item);
combo->item_picked(item);
name = preset_name_of_item(*combo, item);
}
p->plater->p->filament_preset_picked(int(slot_index), name, combo, item, switch_tab);
// What the sidebar's handler does after the plater's part of any selector's pick
// (Plater::priv::on_combobox_select()).
update_printer_thumbnail();
}
void Plater::priv::filament_preset_picked(int idx, const std::string& preset_name, PlaterPresetComboBox* combo, int item, bool switch_tab)
{
const bool was_support = is_support_filament(idx);
wxGetApp().preset_bundle->set_filament_preset(idx, preset_name);
wxGetApp().plater()->update_project_dirty_from_presets();
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
sidebar->update_dynamic_filament_list();
if (was_support != is_support_filament(idx) && wxGetApp().app_config->get("auto_calculate_flush") == "all") {
sidebar->auto_calc_flushing_volumes(idx);
}
if (combo != nullptr && item >= 0)
combo->set_sync_badge(combo->GetFlag(item) == (int)PresetComboBox::FilamentAMSType::FROM_AMS);
q->on_filament_change(idx);
if (sidebar->is_multifilament()) {
// Only update the plater UI for the 2nd and other filaments.
if (combo != nullptr)
combo->update();
}
else if (switch_tab) {
wxWindowUpdateLocker noUpdates2(sidebar->filament_panel());
wxGetApp().get_tab(Preset::TYPE_FILAMENT)->select_preset(preset_name);
// update plater with new config
q->on_config_change(wxGetApp().preset_bundle->full_config());
}
// ORCA: Always refresh the selected filament combo so its color swatch (clr_picker)
// matches the chosen preset. update_ams_color() (in item_picked()) updates the project
// filament color when the preset defines one; this repaints the swatch to match.
if (combo != nullptr)
combo->update();
// update plater with new config
q->on_config_change(wxGetApp().preset_bundle->full_config());
#ifdef __WXMSW__
// From the Win 2004 preset combobox lose a focus after change the preset selection
// and that is why the up/down arrow doesn't work properly
// So, set the focus to the combobox explicitly
if (combo != nullptr && item >= 0)
combo->SetFocus();
#endif
if (wxGetApp().app_config->get("auto_calculate_flush") == "all") {
wxGetApp().plater()->sidebar().auto_calc_flushing_volumes(idx);
}
// BBS: log modify of filament selection
Slic3r::put_other_changes();
// update slice state and set bedtype default for 3rd-party printer
auto plate_list = partplate_list.get_plate_list();
for (auto plate : plate_list) {
plate->update_slice_result_valid_state(false);
}
}
void Plater::priv::on_select_preset(wxCommandEvent &evt)
{
PlaterPresetComboBox* combo = static_cast<PlaterPresetComboBox*>(evt.GetEventObject());
@@ -13310,6 +13407,11 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
auto idx = combo->get_filament_idx();
if (preset_type == Preset::TYPE_FILAMENT) {
filament_preset_picked(idx, preset_name_of_item(*combo, selection), combo, selection, /*switch_tab=*/true);
return;
}
// BBS:Save the plate parameters before switching
PartPlateList& old_plate_list = this->partplate_list;
PartPlate* old_plate = old_plate_list.get_selected_plate();
@@ -13328,46 +13430,10 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
plate_object.emplace_back(obj_idxs);
}
bool flag = is_support_filament(idx);
//! Because of The MSW and GTK version of wxBitmapComboBox derived from wxComboBox,
//! but the OSX version derived from wxOwnerDrawnCombo.
//! So, to get selected string we do
//! combo->GetString(combo->GetSelection())
//! instead of
//! combo->GetStringSelection().ToUTF8().data());
std::string preset_name = preset_name_of_item(*combo, selection);
// Prefer the internal preset name stored per combo item to avoid alias collisions
// (e.g. user preset and bundle preset sharing the same display alias).
wxString wx_stored_name = combo->GetItemAlias(selection);
std::string preset_name;
if (!wx_stored_name.empty()) {
preset_name = Preset::remove_suffix_modified(wx_stored_name.ToUTF8().data());
} else {
wxString wx_name = combo->GetString(selection);
preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type,
Preset::remove_suffix_modified(wx_name.ToUTF8().data()));
}
if (preset_type == Preset::TYPE_FILAMENT) {
wxGetApp().preset_bundle->set_filament_preset(idx, preset_name);
wxGetApp().plater()->update_project_dirty_from_presets();
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
sidebar->update_dynamic_filament_list();
bool flag_is_change = is_support_filament(idx);
if (flag != flag_is_change && wxGetApp().app_config->get("auto_calculate_flush") == "all") {
sidebar->auto_calc_flushing_volumes(idx);
}
auto select_flag = combo->GetFlag(selection);
combo->set_sync_badge(select_flag == (int)PresetComboBox::FilamentAMSType::FROM_AMS);
q->on_filament_change(idx);
}
bool select_preset = !combo->selection_is_changed_according_to_physical_printers();
// TODO: ?
if (preset_type == Preset::TYPE_FILAMENT && sidebar->is_multifilament()) {
// Only update the plater UI for the 2nd and other filaments.
combo->update();
}
else if (select_preset) {
if (select_preset) {
if (preset_type == Preset::TYPE_PRINTER) {
PhysicalPrinterCollection& physical_printers = wxGetApp().preset_bundle->physical_printers;
if(combo->is_selected_physical_printer())
@@ -13431,12 +13497,6 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
}
}
// ORCA: Always refresh the selected filament combo so its color swatch (clr_picker)
// matches the chosen preset. update_ams_color() (in OnSelect) updates the project
// filament color when the preset defines one; this repaints the swatch to match.
if (preset_type == Preset::TYPE_FILAMENT)
combo->update();
// update plater with new config
q->on_config_change(wxGetApp().preset_bundle->full_config());
if (preset_type == Preset::TYPE_PRINTER) {
@@ -13495,9 +13555,6 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
// So, set the focus to the combobox explicitly
combo->SetFocus();
#endif
if (preset_type == Preset::TYPE_FILAMENT && wxGetApp().app_config->get("auto_calculate_flush") == "all") {
wxGetApp().plater()->sidebar().auto_calc_flushing_volumes(idx);
}
// BBS: log modify of filament selection
Slic3r::put_other_changes();
@@ -16466,7 +16523,7 @@ Print& Plater::fff_print() { return p->fff_print; }
const SLAPrint& Plater::sla_print() const { return p->sla_print; }
SLAPrint& Plater::sla_print() { return p->sla_print; }
int Plater::new_project(bool skip_confirm, bool silent, const wxString& project_name, bool reload_presets)
int Plater::new_project(bool skip_confirm, bool silent, const wxString& project_name, bool reload_presets, bool tell_plugins)
{
model().calib_pa_pattern.reset(nullptr);
model().plates_custom_gcodes.clear();
@@ -16503,7 +16560,7 @@ int Plater::new_project(bool skip_confirm, bool silent, const wxString& project_
//get_partplate_list().reinit();
//get_partplate_list().update_slice_context_to_current_plate(p->background_process);
//p->preview->update_gcode_result(p->partplate_list.get_current_slice_result());
if (!silent) {
if (!silent || tell_plugins) {
Slic3r::LifecycleEventContext ctx;
ctx.code = Slic3r::LifecycleEvtCode::Ok;
Slic3r::fire_lifecycle_event(Slic3r::LifecycleEvent::NewProject, ctx);
@@ -22736,6 +22793,12 @@ void Plater::arrange()
}
}
void Plater::arrange(bool current_plate_only)
{
set_prepare_state(current_plate_only ? Job::PREPARE_STATE_MENU : Job::PREPARE_STATE_DEFAULT);
arrange();
}
void Plater::set_current_canvas_as_dirty()
{
p->set_current_canvas_as_dirty();
@@ -23213,6 +23276,14 @@ void Plater::apply_background_progress()
}
//BBS: select Plate
int Plater::set_plate_locked(int plate_index, bool locked)
{
take_snapshot("lock partplate");
const int ret = p->partplate_list.lock_plate(plate_index, locked);
set_current_canvas_as_dirty();
return ret;
}
int Plater::select_plate(int plate_index, bool need_slice)
{
int ret;
@@ -24000,8 +24071,7 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi
else if ((action == 4)&&(!right_click))
{
//lock the plate
take_snapshot("lock partplate");
ret = p->partplate_list.lock_plate(plate_index, !p->partplate_list.is_locked(plate_index));
ret = set_plate_locked(plate_index, !p->partplate_list.is_locked(plate_index));
}
else if ((action == 5)&&(!right_click))
{
@@ -24221,24 +24291,31 @@ void Plater::cancel_slicing()
p->background_process.stop();
}
bool Plater::export_gcode_to(const boost::filesystem::path& output_path)
Plater::ExportRefusal Plater::export_gcode_to(const boost::filesystem::path& output_path)
{
if (p->model.objects.empty())
return ExportRefusal::NoObjects;
// priv::export_gcode() answers a scheduled export with an error dialog, which suits the Export
// button and not a caller that named the file.
if (p->background_process.is_export_scheduled())
return ExportRefusal::AlreadyExporting;
// Only a finished, valid slice is exported: anything that would start the background process
// first could leave the export scheduled behind a running slice, out of the caller's sight.
if (p->model.objects.empty() || is_slicing_any())
return false;
if (p->process_completed_with_error == p->partplate_list.get_curr_plate_index() ||
!p->partplate_list.get_curr_plate()->is_slice_result_valid())
return false;
if (is_slicing_any())
return ExportRefusal::Slicing;
if (p->process_completed_with_error == p->partplate_list.get_curr_plate_index())
return ExportRefusal::SliceHasErrors;
if (!p->partplate_list.get_curr_plate()->is_slice_result_valid())
return ExportRefusal::NotSliced;
p->notification_manager->new_export_began(false);
p->exporting_status = ExportingStatus::EXPORTING_TO_LOCAL;
p->last_output_path = output_path.string();
p->last_output_dir_path = output_path.parent_path().string();
if (!p->export_gcode(output_path, false, /*tracked=*/true)) {
p->exporting_status = ExportingStatus::NOT_EXPORTING;
return false;
return ExportRefusal::NotStarted;
}
return true;
return ExportRefusal::None;
}
uint64_t Plater::project_revision() const { return p->project_revision; }
+21 -4
View File
@@ -295,6 +295,11 @@ public:
#endif
std::vector<PlaterPresetComboBox*>& combos_filament();
// Assigns the filament preset `preset_name` (internal name) to slot `slot_index` as picking it in the
// slot's selector does: the slot's colour, the mapping, the flushing volumes, the project state and,
// on a printer with one filament, the filament tab. `switch_tab` false leaves the tab to a caller
// that has made it edit the preset already.
void select_filament_preset(size_t slot_index, const std::string& preset_name, bool switch_tab = true);
void clear_combos_filament_badge();
void udpate_combos_filament_badge();
@@ -380,7 +385,10 @@ public:
// Helper: returns config indices where filament_is_mixed == false
std::vector<size_t> physical_filament_config_indices() const;
int new_project(bool skip_confirm = false, bool silent = false, const wxString& project_name = wxString(), bool reload_presets = true);
// `silent` leaves the shown tab as it is and sends plugins no NewProject event; `tell_plugins` sends
// the event all the same, for a silent caller whose new project is one a person asked for.
int new_project(bool skip_confirm = false, bool silent = false, const wxString& project_name = wxString(), bool reload_presets = true,
bool tell_plugins = false);
// BBS: save & backup
void load_project(wxString const & filename = "", wxString const & originfile = "-");
// `path` saves there without asking (automation); empty keeps the interactive behaviour.
@@ -757,6 +765,9 @@ public:
void show_uv_editor(bool show);
void arrange();
// Arranges every unlocked plate as the toolbar's Arrange does, or the current plate alone as its
// Arrange icon does.
void arrange(bool current_plate_only);
void orient();
void find_new_position(const ModelInstancePtrs &instances);
//BBS: add job state related functions
@@ -891,6 +902,8 @@ public:
bool plugins_block_slicing() const;
//BBS: select the plate by index
int select_plate(int plate_index, bool need_slice = false);
// Locks or unlocks a plate as its lock icon does, as one undo step. Returns PartPlateList::lock_plate()'s result.
int set_plate_locked(int plate_index, bool locked);
//BBS: update progress result
void apply_background_progress();
//BBS: select the plate by hover_id
@@ -916,9 +929,12 @@ public:
void request_slice(bool all_plates);
// What the slicing progress notification's cancel button does.
void cancel_slicing();
// Starts a G-code export to `output_path` without a dialog. Refused while the background process
// is running; when it cannot start, nothing is left scheduled. Returns whether it started.
bool export_gcode_to(const boost::filesystem::path& output_path);
// Why export_gcode_to() started no export: None when it did.
enum class ExportRefusal { None, NoObjects, AlreadyExporting, Slicing, SliceHasErrors, NotSliced, NotStarted };
// Starts a G-code export of the current plate to `output_path` without a dialog. Refused while the
// background process is running or another export is scheduled; when it cannot start, nothing is
// left scheduled and no dialog opens.
ExportRefusal export_gcode_to(const boost::filesystem::path& output_path);
// Bookkeeping that lets an automated caller tell its own slice or export from anyone else's.
// The project revision moves on every edit (snapshot, undo/redo, preset or setting change,
@@ -1220,6 +1236,7 @@ private:
void on_filament_map_mode_change();
friend class SuppressBackgroundProcessingUpdate;
friend class Sidebar; // select_filament_preset() runs the plater's part of a selector pick
friend class PlaterDropTarget;
};
+29 -12
View File
@@ -229,19 +229,31 @@ PresetComboBox::NameMatch PresetComboBox::find_by_name(const std::string& reques
return match;
}
int row_for_preset(const std::vector<PresetRow>& rows, const std::string& name)
{
int labelled = -1;
for (std::size_t row = 0; row < rows.size(); ++row) {
if (rows[row].marker)
continue;
if (!rows[row].stored.empty() && rows[row].stored == name)
return int(row);
if (labelled < 0 && rows[row].stored.empty() && rows[row].label == name)
labelled = int(row);
}
return labelled;
}
int PresetComboBox::item_for_preset(const std::string& preset_name)
{
const std::string want = Preset::remove_suffix_modified(preset_name);
const int item_count = GetCount();
// One row for each item, so a row's index is its item's.
std::vector<PresetRow> rows;
const int item_count = GetCount();
for (int item = 0; item < item_count; ++item) {
if (is_marker_item(item))
continue;
const wxString alias = GetItemAlias(item);
const std::string alias_name = alias.empty() ? std::string() : Preset::remove_suffix_modified(alias.ToUTF8().data());
if (!alias_name.empty() && alias_name == want)
return item;
const wxString alias = GetItemAlias(item);
rows.push_back({alias.empty() ? std::string() : Preset::remove_suffix_modified(alias.ToUTF8().data()),
Preset::remove_suffix_modified(GetString(item).ToUTF8().data()), is_marker_item(item)});
}
return -1;
return row_for_preset(rows, Preset::remove_suffix_modified(preset_name));
}
void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type)
@@ -1089,14 +1101,19 @@ void PlaterPresetComboBox::OnSelect(wxCommandEvent &evt)
//}
return;
} else if (marker == LABEL_ITEM_PHYSICAL_PRINTER || selected_item >= 0 || m_collection->current_is_dirty()) {
m_last_selected = selected_item;
if (m_type == Preset::TYPE_FILAMENT)
update_ams_color();
item_picked(selected_item);
}
evt.Skip();
}
void PlaterPresetComboBox::item_picked(int item)
{
m_last_selected = item;
if (m_type == Preset::TYPE_FILAMENT)
update_ams_color();
}
void PlaterPresetComboBox::update_badge_according_flag() {
auto selection = GetSelection();
auto select_flag = GetFlag(selection);
+17 -1
View File
@@ -36,6 +36,17 @@ namespace GUI {
class BitmapCache;
// A selector's row as a pick of a preset by name sees it.
struct PresetRow
{
std::string stored; // the preset name the row stores; empty for a row that stores none, as an AMS filament's
std::string label; // what the row shows
bool marker = false; // a group header or another row that is not a preset
};
// The index of the row a pick of preset `name` selects: the row that stores `name`, else the first
// that stores no name and is labelled `name`; never a marker. -1 when there is none.
int row_for_preset(const std::vector<PresetRow>& rows, const std::string& name);
// ---------------------------------
// *** PresetComboBox ***
// ---------------------------------
@@ -86,7 +97,9 @@ public:
// filament slot combo that slot's compatibility). A name two distinct items carry is reported
// ambiguous instead of being resolved by position. Used by scripts and automation.
NameMatch find_by_name(const std::string& requested);
// Index of the item whose internal name is `preset_name`, or -1.
// The item a pick of `preset_name` selects (row_for_preset()), or -1. `preset_name` is a name as
// find_by_name() resolves one (internal_name): a preset's name, or the label of a row that stores
// none.
int item_for_preset(const std::string& preset_name);
void set_selection_changed_function(std::function<void(int)> sel_changed) { on_selection_changed = sel_changed; }
@@ -231,6 +244,9 @@ public:
void update() override;
void msw_rescale() override;
void OnSelect(wxCommandEvent& evt) override;
// The selector's own part of a pick of `item`, which OnSelect() runs before the plater's: the item
// becomes the last selection and, for a filament, the slot's colour follows the preset.
void item_picked(int item);
void update_badge_according_flag();
void set_sync_badge(bool show);
+10 -10
View File
@@ -17,6 +17,7 @@
#include "slic3r/GUI/GUI_Utils.hpp"
#include "slic3r/GUI/OptionsGroup.hpp"
#include <vector>
#include <optional>
#include <string>
#include <set>
#include <algorithm>
@@ -292,6 +293,12 @@ PresetNameStatus check_preset_name(const PresetCollection &presets, const std::s
return PresetNameStatus::Valid;
}
std::optional<bool> locked_save_location(const PresetCollection &presets, const std::string &name)
{
const Preset *existing = presets.find_preset(name, false);
return existing != nullptr ? std::optional<bool>(existing->is_project_embedded) : std::nullopt;
}
void SavePresetDialog::Item::update()
{
m_preset_name = into_u8(m_input_ctrl->GetTextCtrl()->GetValue());
@@ -300,17 +307,10 @@ void SavePresetDialog::Item::update()
const PresetNameStatus status = check_preset_name(*m_presets, m_preset_name, info_line);
m_valid_type = status == PresetNameStatus::Invalid ? NoValid : status == PresetNameStatus::Warning ? Warning : Valid;
const Preset *existing = m_presets->find_preset(m_preset_name, false);
// BBS: add project embedded presets logic
if (existing) { // ORCA RadioGroup
if (existing->is_project_embedded) {
m_radio_group->SetSelection(1);
m_save_to_project = true;
} else {
m_radio_group->SetSelection(0);
m_save_to_project = false;
}
if (const std::optional<bool> locked = locked_save_location(*m_presets, m_preset_name)) { // ORCA RadioGroup
m_radio_group->SetSelection(*locked ? 1 : 0);
m_save_to_project = *locked;
m_radio_group->Disable();
} else {
m_radio_group->Enable();
+6
View File
@@ -6,6 +6,7 @@
#include "libslic3r/Preset.hpp"
#include "slic3r/GUI/Widgets/Button.hpp"
#include "GUI_Utils.hpp"
#include <optional>
#include <string>
#include <wx/anybutton.h>
#include <wx/sizer.h>
@@ -35,6 +36,11 @@ enum class PresetNameStatus { Valid, Warning, Invalid };
// ORCA Shared profile name validation for SavePresetDialog and PhysicalPrinterDialog.
PresetNameStatus check_preset_name(const PresetCollection &presets, const std::string &name, wxString &info_line);
// Where a preset saved under `name` goes when that is not the person's to choose: a preset that exists is
// saved where it is (true: inside the project), and the dialog locks its choice to that. nullopt for a new
// name, which can go either way.
std::optional<bool> locked_save_location(const PresetCollection &presets, const std::string &name);
class SavePresetDialog : public DPIDialog
{
public:
+25 -7
View File
@@ -8404,6 +8404,25 @@ bool Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_proje
return true;
}
Tab::DeleteBlock Tab::can_delete_preset(const PresetCollection& presets, const Preset& preset, std::vector<std::string>* inherited_by)
{
std::vector<std::string> children;
// Only a base preset is inherited from: the presets under it would no longer load.
if (presets.get_preset_base(preset) == &preset)
for (const Preset& other : presets)
if (other.inherits() == preset.name)
children.push_back(other.name);
const bool inherited = !children.empty();
if (inherited_by != nullptr)
*inherited_by = std::move(children);
// Preset::can_overwrite(), which shows the Delete button, is these two.
if (preset.is_system || preset.is_default)
return DeleteBlock::System;
if (preset.is_from_bundle())
return DeleteBlock::FromBundle;
return inherited ? DeleteBlock::InheritedFrom : DeleteBlock::None;
}
// Called for a currently selected preset.
void Tab::delete_preset(bool ask)
{
@@ -8434,13 +8453,12 @@ void Tab::delete_preset(bool ask)
confirm_delete_third_party_printer = true;
}
}
int count = 0;
wxString presets;
for (auto &preset2 : *m_presets)
if (preset2.inherits() == current_preset.name) {
++count;
presets += "\n - " + from_u8(preset2.name);
}
std::vector<std::string> inherited_by;
can_delete_preset(*m_presets, current_preset, &inherited_by);
const int count = int(inherited_by.size());
wxString presets;
for (const std::string& name : inherited_by)
presets += "\n - " + from_u8(name);
if (count > 0) {
msg = _L("Presets inherited by other presets cannot be deleted!");
msg += "\n";
+8
View File
@@ -398,6 +398,14 @@ public:
// Deletes the selected preset. `ask` false skips the confirmations, for a caller that has made the
// same checks itself; the refusal for a preset other presets inherit from still shows.
void delete_preset(bool ask = true);
// What keeps a preset from being deleted: a system (or default) preset and a preset of a bundle are
// never deleted, and a base preset is not while other presets inherit from it.
enum class DeleteBlock { None, System, FromBundle, InheritedFrom };
// What keeps `preset` of `presets` from being deleted. The tab applies it in two places: it shows no
// Delete button for the first two (Preset::can_overwrite()), and delete_preset() refuses the third in
// a dialog. `inherited_by` gets the presets that inherit from it when it is a base preset, whatever
// blocks it first.
static DeleteBlock can_delete_preset(const PresetCollection& presets, const Preset& preset, std::vector<std::string>* inherited_by = nullptr);
void toggle_show_hide_incompatible();
void update_show_hide_incompatible_button();
void update_ui_from_settings();
-3
View File
@@ -233,9 +233,6 @@ std::string RammingPanel::get_parameters()
return stream.str();
}
static const float g_min_flush_multiplier = 0.f;
static const float g_max_flush_multiplier = 3.f;
bool is_flush_config_modified()
{
const auto &project_config = wxGetApp().preset_bundle->project_config;
+4
View File
@@ -16,6 +16,10 @@
#include "RammingChart.hpp"
// The range the Flushing volumes dialog takes for a nozzle's flush multiplier.
inline constexpr float g_min_flush_multiplier = 0.f;
inline constexpr float g_max_flush_multiplier = 3.f;
class RammingPanel : public wxPanel {
public:
+3 -6
View File
@@ -515,18 +515,15 @@ Temp_Calibration_Dlg::Temp_Calibration_Dlg(wxWindow* parent, wxWindowID id, Plat
unsigned long t = 0;
if(!ti->GetTextCtrl()->GetValue().ToULong(&t))
return;
if(t> 500 || t < 155){
if (const unsigned long clamped = (unsigned long) clamp_calib_temp(double(t)); clamped != t) {
// TRN %s is the temperature unit
MessageDialog msg_dlg(nullptr, wxString::Format(_L("Supported range: 170%s - 500%s"),
_L("\u2103" /* °C */), _L("\u2103" /* °C */)),
wxEmptyString, wxICON_WARNING | wxOK);
msg_dlg.ShowModal();
if(t > 500)
t = 500;
else
t = 155;
t = clamped;
}
t = (t / 5) * 5;
t = (unsigned long) round_calib_temp(double(t));
ti->GetTextCtrl()->SetValue(std::to_string(t));
};
+107 -147
View File
@@ -15,6 +15,8 @@
#include <slic3r/GUI/GUI.hpp>
#include <slic3r/GUI/GUI_App.hpp>
#include <slic3r/GUI/MainFrame.hpp>
#include <slic3r/GUI/Operations/Outcome.hpp>
#include <slic3r/GUI/Operations/PresetOps.hpp>
#include <slic3r/GUI/Plater.hpp>
#include <slic3r/GUI/PresetComboBoxes.hpp> // TabPresetComboBox::set_filament_idx
#include <slic3r/GUI/Tab.hpp>
@@ -23,6 +25,7 @@
#include <wx/string.h>
#include <optional>
#include <set>
#include <stdexcept>
#include <string>
@@ -105,21 +108,22 @@ struct SelectionCancelled : std::runtime_error
// pipeline hook.
//
// Known limits of this implementation, kept explicit rather than hidden:
// * A requested preset_name is resolved by the exact name its dropdown entry shows: the item's
// display label or its stored item alias (the internal preset name). A name two entries carry
// is rejected as ambiguous instead of being resolved by position. Process and printer resolve
// against the tab dropdown; a filament preset_name resolves against the requested slot's own
// sidebar selector, not the tab's, so its compatibility filter is the one that applies. A
// target the selector does not offer fails before the flow's unsaved-edit prompt. The flow
// itself is unchanged and the target is still confirmed as the edited preset afterwards.
// * A filament preset_name that names a different preset for a slot selects it through
// Tab::select_preset() (the normal flow, honouring unsaved-edit prompts) and then updates the
// slot mapping with PresetBundle::set_filament_preset() plus every dependent side effect the
// sidebar selection path performs: the project-dirty/selection refresh, the dynamic filament
// list, the slot's own combo (re-run so it lists and selects the assigned target), the
// conditional support-filament flushing recalc and the slot's AMS sync badge (read from the
// slot combo's own flag). The private Plater::priv::on_select_preset() path cannot be reused
// from here, so this mirrors its filament branch rather than calling it.
// * A requested preset_name is resolved by GUI::Ops::resolve_preset(), the rule every caller that
// selects a preset by name shares: the exact name a dropdown entry shows, its display label or
// its stored item alias (the internal preset name). A name two entries carry is rejected as
// ambiguous instead of being resolved by position. Process and printer resolve against the tab
// dropdown; a filament preset_name resolves against the requested slot's own sidebar selector,
// not the tab's, so its compatibility filter is the one that applies. A hidden compatible
// preset the name stands for is shown in the selectors first, where it stays until the app
// restarts. A target the selector does not offer fails before the flow's unsaved-edit prompt. A
// process or printer selection that leaves another preset edited is refused
// (GUI::Ops::select_preset()).
// * A filament preset_name that names a different preset for a slot first makes the filament tab
// edit it through Tab::select_preset() (the normal flow, honouring unsaved-edit prompts), since
// the transaction edits that preset, and then assigns it to the slot with
// GUI::Ops::assign_filament_preset(), which does what picking the preset in the slot's sidebar
// selector does: the slot's colour follows the preset, the mapping, the flushing volumes and the
// project state are updated and every plate's slice result is invalidated.
// * A user-declined selection does not undo decisions the user already accepted in an earlier
// dialog. It aborts before any slot assignment or transaction is created, so no staged
// setting is applied.
@@ -182,19 +186,31 @@ GUI::Tab* require_tab(GUI::GUI_App& app, Preset::Type type)
return tab;
}
// Resolve `requested` to the internal preset name its dropdown entry names, or throw. `category`
// and `selector` are used only for the error text. A name the selector does not offer, or that two
// entries share, raises std::invalid_argument.
std::string resolve_preset_in_combo(GUI::PresetComboBox& combo, const std::string& requested,
const std::string& category, const std::string& selector)
GUI::Ops::PresetKind preset_kind(Preset::Type type)
{
const GUI::PresetComboBox::NameMatch match = combo.find_by_name(requested);
if (match.ambiguous)
throw std::invalid_argument("The " + category + " name \"" + requested + "\" is ambiguous in the " + selector
+ "; more than one entry shows it, so name the preset by its own entry");
if (match.item < 0)
throw std::invalid_argument("The " + category + " preset \"" + requested + "\" is not offered by the " + selector);
return match.internal_name;
switch (type) {
case Preset::TYPE_PRINTER: return GUI::Ops::PresetKind::Printer;
case Preset::TYPE_FILAMENT: return GUI::Ops::PresetKind::Filament;
default: return GUI::Ops::PresetKind::Process;
}
}
// Raises a preset operation's refusal as the exception a plugin has had for it, which pybind11 maps:
// IndexError for a slot the printer lacks, ValueError for a mixed-color slot and for a name that
// resolves to no selectable preset, SelectionCancelled for a declined prompt, RuntimeError
// otherwise. The text is the operation's.
[[noreturn]] void throw_refusal(const GUI::Ops::Refusal& refusal)
{
const std::string code = refusal.code;
const std::string text = refusal.english();
if (code == "no_such_slot")
throw std::out_of_range(text);
if (code == "mixed_filament_slot" || code == "ambiguous_preset_name" || code == "ambiguous_hidden_preset" ||
code == "preset_incompatible" || code == "preset_not_offered")
throw std::invalid_argument(text);
if (code == "selection_cancelled")
throw SelectionCancelled(text);
throw std::runtime_error(text);
}
// The preset a filament slot currently resolves to, by its internal name. A slot whose stored
@@ -292,12 +308,12 @@ PresetUpdateResult PresetTransaction::commit()
// Process/printer target resolution: the active preset when no name is given, otherwise the named
// preset selected through the normal tab-selection flow (which enforces the dropdown/compatibility
// rules and the unsaved-edit prompt). Binds only after confirming the requested preset is edited.
// rules and the unsaved-edit prompt, and refuses when it leaves another preset edited).
// Runs on the UI thread with the GIL released, called from begin_preset_update().
void bind_preset_target(Preset::Type type, const std::string& preset_name, PresetTransaction& transaction)
{
GUI::GUI_App& app = require_gui_app();
GUI::Tab* tab = require_tab(app, type);
GUI::GUI_App& app = require_gui_app();
require_tab(app, type);
PresetCollection& collection = collection_for(*app.preset_bundle, type);
const std::string current = collection.get_edited_preset().name;
@@ -305,39 +321,25 @@ void bind_preset_target(Preset::Type type, const std::string& preset_name, Prese
bool selection_changed = false;
if (!preset_name.empty()) {
// Resolve by the name the tab's dropdown actually shows (display label or item alias), so a
// plugin can pass exactly what the user sees. With no populated dropdown there is nothing
// to resolve against, so fall back to collection internal names.
GUI::TabPresetComboBox* combo = tab->get_combo_box();
std::string resolved;
if (combo != nullptr && combo->GetCount() > 0)
resolved = resolve_preset_in_combo(*combo, preset_name, preset_tab_name(type),
"preset selector for the selected printer");
else
resolved = preset_name;
Preset* requested = collection.find_preset(resolved);
if (requested == nullptr)
throw std::invalid_argument("No " + std::string(preset_tab_name(type)) + " preset named \"" + resolved
+ "\" is available to select");
target = requested->name;
// Resolved by the name the tab's dropdown shows (display label or item alias), so a plugin
// can pass exactly what the user sees.
GUI::Ops::ResolvePresetArgs resolve;
resolve.kind = preset_kind(type);
resolve.name = preset_name;
const GUI::Ops::Outcome<GUI::Ops::ResolvedPreset> resolved = GUI::Ops::resolve_preset(resolve);
if (!resolved)
throw_refusal(resolved.refusal());
target = resolved.value().name;
if (target != current) {
// Normal UI selection: honours the unsaved-edit prompt; a declined prompt returns false
// and is a user cancellation, distinct from any other resolution failure.
if (!tab->select_preset(target))
throw SelectionCancelled("Switching the edited " + std::string(preset_tab_name(type)) + " preset to \""
+ target + "\" was canceled; nothing was staged");
// Normal UI selection: honours the unsaved-edit prompt; a declined prompt is a user
// cancellation, distinct from any other resolution failure.
const GUI::Ops::Outcome<GUI::Ops::Done> selected = GUI::Ops::select_preset({preset_kind(type), target, GUI::Ops::PresetChanges::Ask});
if (!selected)
throw_refusal(selected.refusal());
selection_changed = true;
}
}
// select_preset() can still leave a different preset edited (e.g. the target is not an
// allowed dropdown choice), so confirm before binding.
if (collection.get_edited_preset().name != target)
throw std::runtime_error("The edited " + std::string(preset_tab_name(type)) + " preset is \""
+ collection.get_edited_preset().name + "\", not \"" + target
+ "\"; the transaction was not created");
transaction.type = type;
transaction.target_name = target;
transaction.selection_changed = selection_changed;
@@ -366,72 +368,46 @@ void bind_filament_target(int slot_number, const std::string& preset_name, Prese
{
GUI::GUI_App& app = require_gui_app();
PresetBundle& bundle = *app.preset_bundle;
GUI::Plater* plater = app.plater();
// A mixed-color virtual slot has no single filament preset behind it, so every form of this
// call is rejected: with or without a preset_name there is no one preset to edit or assign.
// Range-guarded so an out-of-range slot still gets resolved_slot_preset()'s clear error.
if (slot_number >= 1 && static_cast<size_t>(slot_number) <= bundle.filament_presets.size()
&& bundle.is_mixed_filament(static_cast<size_t>(slot_number) - 1))
throw std::invalid_argument("Filament slot " + std::to_string(slot_number)
+ " is a mixed-color virtual slot; it has no single filament preset to edit or assign");
if (const std::optional<GUI::Ops::Refusal> refusal = GUI::Ops::mixed_slot_refusal(slot_number))
throw_refusal(*refusal);
// Resolve and validate before any selection, so a bad slot fails without a prompt.
const std::string assigned_internal = resolved_slot_preset(bundle, slot_number);
GUI::Tab* tab = require_tab(app, Preset::TYPE_FILAMENT);
const size_t slot_index = static_cast<size_t>(slot_number) - 1;
std::string target = assigned_internal;
if (!preset_name.empty()) {
// Resolve against the requested sidebar slot's own selector, not the tab's: that is the
// model the user picks this slot's filament from, including its compatibility filter. The
// selector matches the exact name shown (display label or item alias).
std::vector<GUI::PlaterPresetComboBox*>& slot_combos = plater->sidebar().combos_filament();
GUI::PlaterPresetComboBox* slot_combo = slot_index < slot_combos.size() ? slot_combos[slot_index] : nullptr;
std::string resolved;
if (slot_combo != nullptr && slot_combo->GetCount() > 0) {
const GUI::PresetComboBox::NameMatch match = slot_combo->find_by_name(preset_name);
if (match.ambiguous)
throw std::invalid_argument("The filament name \"" + preset_name
+ "\" is ambiguous in the filament preset selector for filament slot "
+ std::to_string(slot_number)
+ "; more than one entry shows it, so name the preset by its own entry");
if (match.item >= 0) {
resolved = match.internal_name;
} else {
// Not shown by this slot's selector. Only the slot's current assignment stays
// targetable (a hidden or incompatible-but-selected preset the dropdown omits);
// resolve it by internal name or by display alias and accept only that preset. A
// different preset the tab happens to edit is a globally edited target, not an
// offered choice for this slot, and is rejected.
Preset* by_name = bundle.filaments.find_preset(preset_name);
if (by_name == nullptr) {
const std::string& alias_name = bundle.filaments.get_preset_name_by_alias(preset_name);
by_name = bundle.filaments.find_preset(alias_name);
}
if (by_name == nullptr || by_name->name != assigned_internal)
throw std::invalid_argument("Filament preset \"" + preset_name
+ "\" is not offered by the filament preset selector for filament slot "
+ std::to_string(slot_number));
resolved = by_name->name;
}
// Resolved against the requested sidebar slot's own selector, not the tab's: that is the
// model the user picks this slot's filament from, including its compatibility filter.
GUI::Ops::ResolvePresetArgs resolve;
resolve.kind = GUI::Ops::PresetKind::Filament;
resolve.name = preset_name;
resolve.filament_slot = slot_number;
const GUI::Ops::Outcome<GUI::Ops::ResolvedPreset> resolved = GUI::Ops::resolve_preset(resolve);
if (resolved) {
target = resolved.value().name;
} else {
// The slot selector is not populated; fall back to the tab selector, then to collection
// internal names, so the call still works when the sidebar has not been laid out.
GUI::TabPresetComboBox* tab_combo = tab->get_combo_box();
if (tab_combo != nullptr && tab_combo->GetCount() > 0)
resolved = resolve_preset_in_combo(*tab_combo, preset_name, "filament",
"filament preset selector for the selected printer");
else
resolved = preset_name;
// Not shown by this slot's selector. Only the slot's current assignment stays
// targetable (a hidden or incompatible-but-selected preset the dropdown omits);
// resolve it by internal name or by display alias and accept only that preset. A
// different preset the tab happens to edit is a globally edited target, not an
// offered choice for this slot, and is rejected.
const std::string code = resolved.refusal().code;
if (code != "preset_not_offered" && code != "preset_incompatible")
throw_refusal(resolved.refusal());
Preset* by_name = bundle.filaments.find_preset(preset_name);
if (by_name == nullptr) {
const std::string& alias_name = bundle.filaments.get_preset_name_by_alias(preset_name);
by_name = bundle.filaments.find_preset(alias_name);
}
if (by_name == nullptr || by_name->name != assigned_internal)
throw_refusal(resolved.refusal());
target = by_name->name;
}
Preset* requested = bundle.filaments.find_preset(resolved);
if (requested == nullptr)
throw std::invalid_argument("No filament preset named \"" + resolved + "\" is available to select");
target = requested->name;
}
bool selection_changed = false;
@@ -452,36 +428,16 @@ void bind_filament_target(int slot_number, const std::string& preset_name, Prese
if (!preset_name.empty() && target != assigned_internal) {
if (app.app_config == nullptr)
throw std::runtime_error("Application configuration is not available");
// Mirror the filament branch of Plater::priv::on_select_preset() (the sidebar's normal
// preset selection): update the mapping, then every dependent project/UI side effect,
// rather than the vector entry alone.
const bool was_support = GUI::is_support_filament(static_cast<int>(slot_index));
bundle.set_filament_preset(slot_index, target);
plater->update_project_dirty_from_presets();
bundle.export_selections(*app.app_config);
plater->sidebar().update_dynamic_filament_list();
// Assigning a support filament (or moving away from one) changes which filaments the
// flush rules apply to, so the normal flow recalculates the flushing volumes when
// auto-calc covers every filament.
if (GUI::is_support_filament(static_cast<int>(slot_index)) != was_support
&& app.app_config->get("auto_calculate_flush") == "all")
plater->sidebar().auto_calc_flushing_volumes(static_cast<int>(slot_index));
// Refresh the requested slot's own sidebar combo so its list and current selection show the
// newly assigned target (the list may not have contained it), matching the sidebar
// selection path. Fetch the pointer after update_dynamic_filament_list(), which may
// rebuild the combo vector.
std::vector<GUI::PlaterPresetComboBox*>& slot_combos = plater->sidebar().combos_filament();
if (slot_index < slot_combos.size() && slot_combos[slot_index] != nullptr) {
GUI::PlaterPresetComboBox* slot_combo = slot_combos[slot_index];
slot_combo->update();
// Keep the slot's AMS sync badge truthful, reading the item's own flag, the same source
// on_select_preset() reads, so no UI state is invented here.
const int item = slot_combo->item_for_preset(target);
if (item >= 0)
slot_combo->set_sync_badge(slot_combo->GetFlag(item)
== static_cast<int>(GUI::PresetComboBox::FilamentAMSType::FROM_AMS));
}
plater->on_filament_change(slot_index);
// What picking the preset in the slot's sidebar selector does. The tab edits it already, so
// it is not switched again: a second switch would ask again about changes the first one
// transferred.
GUI::Ops::AssignFilamentArgs assign;
assign.filament_slot = slot_number;
assign.preset = target;
assign.switch_tab = false;
const GUI::Ops::Outcome<std::string> assigned = GUI::Ops::assign_filament_preset(assign);
if (!assigned)
throw_refusal(assigned.refusal());
assignment_changed = true;
}
@@ -695,8 +651,10 @@ void host_bindings::register_presets(py::module_& host)
},
py::arg("preset_name") = "",
"Resolve and bind this category's target preset and return a PresetTransaction. With no preset_name the "
"currently active preset is targeted; a preset_name must be a preset this category can select, and is "
"selected through the normal preset-selection flow (which prompts about unsaved edits). The call blocks "
"currently active preset is targeted; a preset_name must be a preset this category's selector offers, by "
"the name it shows or its internal name, and is "
"selected through the normal preset-selection flow (which prompts about unsaved edits). A hidden preset "
"that suits the printer is shown in the selectors first and stays shown until the app restarts. The call blocks "
"the background Script worker until any such dialog is answered, leaving the UI thread responsive. A "
"selection the user cancels raises RuntimeError; an unavailable or invalid target raises ValueError. "
"Either failure creates no transaction and stages no setting. Call it from the background Script worker, "
@@ -713,10 +671,12 @@ void host_bindings::register_presets(py::module_& host)
py::arg("slot_number"), py::arg("preset_name") = "",
"Resolve and bind a filament preset by 1-based slot and return a PresetTransaction. Omitting preset_name "
"targets the preset assigned to the slot; supplying a different name selects it for the slot through the "
"normal flow (prompting about unsaved edits) and, once that succeeds, records the new slot assignment with "
"the same Plater side effects the sidebar selection performs (project/selection refresh, dynamic filament "
"list, conditional support-filament flushing recalc and the slot's AMS sync badge). A requested preset "
"this slot's dropdown does not offer is rejected before that flow, so it raises no prompt; the slot's own "
"normal flow (prompting about unsaved edits) and, once that succeeds, assigns it to the slot as picking it "
"in the slot's sidebar selector does: the slot's filament colour follows the preset, the flushing volumes "
"are recalculated unless their automatic calculation is disabled, the project is marked changed and every "
"plate's slice result is invalidated. A hidden preset that suits the printer is shown in the selectors "
"first and stays shown until the app restarts. A requested preset "
"this slot's dropdown still does not offer is rejected before that flow, so it raises no prompt; the slot's own "
"current assignment stays targetable even when the dropdown hides it. A selection the user cancels raises "
"RuntimeError and changes neither the slot assignment nor any setting. An out-of-range, empty or "
"unresolved slot is rejected, and a mixed-color virtual slot is rejected whether or not preset_name is "
+16
View File
@@ -113,3 +113,19 @@ TEST_CASE("PA pattern resets the extruder after the final layer in absolute E mo
REQUIRE(state.max_e > 1.);
REQUIRE_THAT(state.final_e, Catch::Matchers::WithinAbs(0., 1e-9));
}
TEST_CASE("a temperature tower's temperatures are brought into 155-500 and rounded down to 5 degree blocks", "[Calib]")
{
using Catch::Matchers::WithinAbs;
CHECK_THAT(clamp_calib_temp(154.), WithinAbs(155., 1e-9));
CHECK_THAT(clamp_calib_temp(155.), WithinAbs(155., 1e-9));
CHECK_THAT(clamp_calib_temp(230.), WithinAbs(230., 1e-9));
CHECK_THAT(clamp_calib_temp(500.), WithinAbs(500., 1e-9));
CHECK_THAT(clamp_calib_temp(501.), WithinAbs(500., 1e-9));
CHECK_THAT(round_calib_temp(232.), WithinAbs(230., 1e-9));
CHECK_THAT(round_calib_temp(234.9), WithinAbs(230., 1e-9));
CHECK_THAT(round_calib_temp(235.), WithinAbs(235., 1e-9));
CHECK_THAT(round_calib_temp(clamp_calib_temp(999.)), WithinAbs(500., 1e-9));
CHECK_THAT(round_calib_temp(clamp_calib_temp(1.)), WithinAbs(155., 1e-9));
}
+1 -1
View File
@@ -31,7 +31,7 @@ add_executable(${_TEST_NAME}_tests
test_mcp_config.cpp
test_mcp_core.cpp
test_mcp_http.cpp
test_mcp_operations.cpp
test_operations.cpp
test_mcp_protocol.cpp
test_mcp_recording.cpp
test_mcp_replay.cpp
-272
View File
@@ -1,272 +0,0 @@
#include <catch2/catch_test_macros.hpp>
#include "slic3r/GUI/Mcp/McpOperations.hpp"
#include <chrono>
#include <cstdint>
#include <optional>
#include <string>
#include <utility>
#include <vector>
using namespace Slic3r::GUI::Mcp;
using namespace std::chrono_literals;
namespace {
// A run that started for request `started_for` (5, the test ticket's own, unless given).
SliceRunRecord run(uint64_t seq, uint64_t revision, uint64_t request, bool cancelled = false, bool finished = true,
uint64_t started_for = 5, int plate = 0)
{
SliceRunRecord r;
r.seq = seq;
r.finished = finished;
r.cancelled = cancelled;
r.ok = finished && !cancelled;
r.revision_at_finish = revision;
r.request_seq_at_finish = request;
r.request_seq_at_start = started_for;
r.plate = plate;
return r;
}
SliceRunRecord plate_run(uint64_t seq, int plate, std::string error = {}, bool cancelled = false)
{
SliceRunRecord r = run(seq, 1, 5, cancelled, true, 5, plate);
r.ok = r.ok && error.empty();
r.error = std::move(error);
return r;
}
std::vector<PlateOutcome> outcomes(const std::vector<PlateResult>& results)
{
std::vector<PlateOutcome> out;
for (const PlateResult& r : results)
out.push_back(r.outcome);
return out;
}
SliceTicketState ticket(uint64_t request_mine, uint64_t run_before, uint64_t revision)
{
SliceTicketState t;
t.request_seq_mine = request_mine;
t.run_seq_before = run_before;
t.revision_at_start = revision;
t.seen_running = true;
t.started = std::chrono::steady_clock::now() - 10s;
return t;
}
SliceObservation observe(uint64_t request, uint64_t revision, std::vector<SliceRunRecord> runs, bool slicing = false)
{
SliceObservation o;
o.slicing_any = slicing;
o.request_seq = request;
o.current_revision = revision;
o.runs_since_start = std::move(runs);
return o;
}
} // namespace
TEST_CASE("classify_plates reports ok, error, empty, skipped and cancelled", "[Mcp]")
{
const std::vector<PlateObservation> plates{{0, true, false}, {1, false, false}, {2, false, true}, {3, false, false}};
const auto results = classify_plates({0, 1, 2, 3, 7}, plates, {plate_run(11, 0), plate_run(12, 1, "boom")});
CHECK(outcomes(results) == std::vector<PlateOutcome>{PlateOutcome::Ok, PlateOutcome::Error, PlateOutcome::Empty,
PlateOutcome::Skipped, PlateOutcome::Skipped});
CHECK(results[1].error == "boom");
CHECK(outcomes(classify_plates({3}, plates, {plate_run(11, 0, {}, true)})) == std::vector<PlateOutcome>{PlateOutcome::Cancelled});
// Finished without a result and without saying why.
SliceRunRecord no_result = plate_run(11, 1);
no_result.ok = false;
const auto failed = classify_plates({1}, plates, {no_result});
CHECK(failed[0].outcome == PlateOutcome::Error);
CHECK(failed[0].error == "the slice finished without a result");
}
TEST_CASE("a plate keeps the outcome of its own run whatever happened to it afterwards", "[Mcp]")
{
// An edit replaced the result.
CHECK(outcomes(classify_plates({0}, {{0, false, false}}, {plate_run(11, 0)})) == std::vector<PlateOutcome>{PlateOutcome::Ok});
// Someone deleted the objects.
CHECK(outcomes(classify_plates({0}, {{0, false, true}}, {plate_run(11, 0)})) == std::vector<PlateOutcome>{PlateOutcome::Ok});
// Someone else's slice succeeded after ours failed.
const auto results = classify_plates({0}, {{0, true, false}}, {plate_run(11, 0, "Floating regions")});
CHECK(results[0].outcome == PlateOutcome::Error);
CHECK(results[0].error == "Floating regions");
// The plate was deleted.
CHECK(outcomes(classify_plates({0}, {}, {plate_run(11, 0)})) == std::vector<PlateOutcome>{PlateOutcome::Ok});
}
TEST_CASE("Slice All stopping at a failing plate leaves the later plates skipped", "[Mcp]")
{
const std::vector<PlateObservation> plates{{0, true, false}, {1, false, false}, {2, false, false}};
const auto results = classify_plates({0, 1, 2}, plates, {plate_run(11, 0), plate_run(12, 1, "Floating regions")});
CHECK(outcomes(results) == std::vector<PlateOutcome>{PlateOutcome::Ok, PlateOutcome::Error, PlateOutcome::Skipped});
CHECK(results[2].error.empty());
}
TEST_CASE("a plate the validation refused reports that error", "[Mcp]")
{
// Refused at the request: Plater records a finished run carrying the validation message.
auto results = classify_plates({0}, {{0, false, false}}, {plate_run(11, 0, "Nozzle too small")});
CHECK(results[0].outcome == PlateOutcome::Error);
CHECK(results[0].error == "Nozzle too small");
// Refused before the request (the setting change validated it), so no run at all.
results = classify_plates({0}, {{0, false, false, "Layer height cannot exceed nozzle diameter"}}, {});
CHECK(results[0].outcome == PlateOutcome::Error);
CHECK(results[0].error == "Layer height cannot exceed nozzle diameter");
}
TEST_CASE("a slice stays pending until it was seen running or the grace period passed", "[Mcp]")
{
SliceTicketState t = ticket(5, 10, 1);
t.seen_running = false;
t.started = std::chrono::steady_clock::now();
CHECK(slice_status(t, observe(5, 1, {}), t.started + 100ms) == TicketStatus::Pending);
CHECK(slice_status(t, observe(5, 1, {}), t.started + kSliceStartGrace + 1ms) == TicketStatus::Done);
CHECK(slice_status(ticket(5, 10, 1), observe(5, 1, {}, true), std::chrono::steady_clock::now()) == TicketStatus::Pending);
}
TEST_CASE("a slice is superseded by another request or an edit while it ran", "[Mcp]")
{
const auto now = std::chrono::steady_clock::now();
const SliceTicketState t = ticket(5, 10, 1);
CHECK(slice_status(t, observe(6, 1, {run(11, 1, 6)}), now) == TicketStatus::Superseded); // a GUI slice request during it
CHECK(slice_status(t, observe(5, 2, {run(11, 2, 5)}), now) == TicketStatus::Superseded); // an edit before its run finished
CHECK(slice_status(t, observe(5, 1, {run(11, 1, 5)}), now) == TicketStatus::Done);
}
TEST_CASE("actions after a slice finished do not supersede it", "[Mcp]")
{
const auto now = std::chrono::steady_clock::now();
const SliceTicketState t = ticket(5, 10, 1);
// Another request and an edit, both after the run recorded its finish.
CHECK(slice_status(t, observe(6, 2, {run(11, 1, 5)}), now) == TicketStatus::Done);
}
TEST_CASE("a slice with no run of its own never reads an earlier run's completion", "[Mcp]")
{
const auto now = std::chrono::steady_clock::now();
// Empty slice after a project reset: the last earlier run (seq 10) finished at another revision.
SliceTicketState empty = ticket(5, 10, 7);
empty.seen_running = false;
CHECK(slice_status(empty, observe(5, 7, {run(10, 3, 4)}), now) == TicketStatus::Done);
// Cached slice whose start revision differs from the last earlier run's.
CHECK(slice_status(empty, observe(5, 7, {}), now) == TicketStatus::Done);
// No run, but the project changed before the terminal poll.
CHECK(slice_status(empty, observe(5, 8, {}), now) == TicketStatus::Superseded);
}
TEST_CASE("cancellation is taken only from the operation's own runs", "[Mcp]")
{
const SliceTicketState t = ticket(5, 10, 1);
CHECK_FALSE(slice_cancelled(t, observe(5, 1, {run(10, 1, 5, true), run(11, 1, 5)})));
CHECK(slice_cancelled(t, observe(5, 1, {run(11, 1, 5, true)})));
// A person's slice started during the operation (a later request) and cancelled is not ours.
CHECK_FALSE(slice_cancelled(t, observe(6, 1, {run(11, 1, 5), run(12, 1, 6, true, true, 6)})));
}
TEST_CASE("a later request supersedes at once only when it came while the slice ran", "[Mcp]")
{
const auto now = std::chrono::steady_clock::now();
const SliceTicketState t = ticket(5, 10, 1);
// A person's slice for request 6, still running, restarted ours.
SliceObservation during = observe(6, 1, {run(11, 1, 6, true), run(12, 0, 0, false, false, 6)}, true);
during.interrupted = true;
CHECK(slice_status(t, during, now) == TicketStatus::Superseded);
// Slice All asked again between two of its plates: the first plate's run finished cleanly.
SliceObservation between = observe(6, 1, {run(11, 1, 5), run(12, 0, 0, false, false, 6)}, true);
between.interrupted = true;
CHECK(slice_status(t, between, now) == TicketStatus::Superseded);
// Requested after ours had finished: our result stands, and their slice is not waited for.
CHECK(slice_status(t, observe(6, 1, {run(11, 1, 5), run(12, 0, 0, false, false, 6)}, true), now) == TicketStatus::Done);
// Our own run still running, nobody else's: pending.
CHECK(slice_status(t, observe(5, 1, {run(11, 0, 0, false, false)}, true), now) == TicketStatus::Pending);
}
TEST_CASE("a plate's result is the operation's until someone else slices it", "[Mcp]")
{
const SliceTicketState t = ticket(5, 10, 1);
// Already sliced: no run touched plate 0.
CHECK(plate_result_is_own(0, t, observe(5, 1, {})));
// Our run was the plate's last.
CHECK(plate_result_is_own(0, t, observe(5, 1, {plate_run(11, 0)})));
// A person sliced plate 0 again after ours finished (request 6).
CHECK_FALSE(plate_result_is_own(0, t, observe(6, 1, {plate_run(11, 0), run(12, 1, 6, false, true, 6, 0)})));
// Their slice of another plate leaves ours alone.
CHECK(plate_result_is_own(0, t, observe(6, 1, {plate_run(11, 0), run(12, 1, 6, false, true, 6, 1)})));
}
TEST_CASE("a reslice or export under the request's number that the request did not start is not the operation's", "[Mcp]")
{
const SliceTicketState t = ticket(5, 10, 1);
// Our run, then a GUI export of the same plate that failed (no new slice request).
SliceRunRecord export_run = run(12, 1, 5, false, true, 5, 0);
export_run.for_request = false;
export_run.ok = false;
export_run.error = "Disk full";
const SliceObservation obs = observe(5, 1, {plate_run(11, 0), export_run});
REQUIRE(own_runs(t, obs).size() == 1);
CHECK(outcomes(classify_plates({0}, {{0, true, false}}, own_runs(t, obs))) == std::vector<PlateOutcome>{PlateOutcome::Ok});
// Its result is no longer known to be ours, so no statistics.
CHECK_FALSE(plate_result_is_own(0, t, obs));
}
TEST_CASE("a slice request refused before validating reports the refusal over a cached result", "[Mcp]")
{
// Plater records the refusal (a broken mixed filament here) as a rejected run of the request.
const auto results = classify_plates({0}, {{0, true, false}}, {plate_run(11, 0, "A mixed filament has a deleted or mismatched component")});
CHECK(results[0].outcome == PlateOutcome::Error);
CHECK(results[0].error == "A mixed filament has a deleted or mismatched component");
}
TEST_CASE("a run already slicing that the request left running is the operation's", "[Mcp]")
{
const auto now = std::chrono::steady_clock::now();
SliceTicketState t = ticket(5, 10, 1);
t.adopted_run = 10;
// Started for an earlier request, finished under ours with an error.
SliceRunRecord adopted = run(10, 1, 5, false, true, 4);
adopted.ok = false;
adopted.error = "Floating regions";
const SliceObservation obs = observe(5, 1, {adopted});
REQUIRE(own_runs(t, obs).size() == 1);
CHECK(slice_status(t, obs, now) == TicketStatus::Done);
const auto results = classify_plates({0}, {{0, false, false}}, own_runs(t, obs));
CHECK(results[0].outcome == PlateOutcome::Error);
CHECK(results[0].error == "Floating regions");
// Not adopted, the same run is someone else's.
CHECK(own_runs(ticket(5, 10, 1), obs).empty());
}
TEST_CASE("early runs of a long Slice All are still seen", "[Mcp]")
{
const SliceTicketState t = ticket(5, 100, 1);
std::vector<SliceRunRecord> runs;
for (uint64_t i = 1; i <= 20; ++i)
runs.push_back(run(100 + i, 1, 5, i == 2));
CHECK(slice_cancelled(t, observe(5, 1, runs)));
runs[1].cancelled = false;
runs[2].revision_at_finish = 9;
CHECK(slice_status(t, observe(5, 1, runs), std::chrono::steady_clock::now()) == TicketStatus::Superseded);
}
TEST_CASE("export status follows its own sequence number", "[Mcp]")
{
ExportRecord rec;
rec.seq = 4;
CHECK(export_status(3, 3, std::nullopt, 1) == ExportStatus::Rejected);
CHECK(export_status(3, 4, rec, 1) == ExportStatus::Pending);
rec.finished = true;
rec.ok = true;
rec.revision_at_finish = 1;
CHECK(export_status(3, 4, rec, 1) == ExportStatus::Ok);
rec.revision_at_finish = 2;
CHECK(export_status(3, 4, rec, 1) == ExportStatus::Superseded);
rec.ok = false;
CHECK(export_status(3, 4, rec, 2) == ExportStatus::Failed);
rec.cancelled = true;
CHECK(export_status(3, 4, rec, 2) == ExportStatus::Cancelled);
}
@@ -118,9 +118,9 @@ TEST_CASE("speed dial actions are flagged by their id", "[Mcp]")
{"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"), {"replaces_project"}, "app_asked"},
{"orca_command:import_file:orca", json{{"path", abs_path("p.3mf")}, {"overwrite", true}}.dump(), {"replaces_project"}, "app_asked"},
{"orca_command:import_file:orca", json{{"path", abs_path("x.gcode")}}.dump(), {"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", "", {}, ""},
+34
View File
@@ -50,6 +50,7 @@
#include <algorithm>
#include <chrono>
#include <limits>
#include <cmath>
#include <condition_variable>
#include <cstddef>
@@ -88,6 +89,39 @@ TEST_CASE("size targets scale uniformly when one axis is given", "[Mcp][Scene]")
CHECK_THROWS_AS(Mcp::size_factors(Vec3d(50., 50., 0.), json::array({nullptr, nullptr, 2})), Mcp::ToolFailure);
}
TEST_CASE("a primitive's size has one number above 0 per dimension its dialog asks for", "[Mcp][Scene]")
{
CHECK(is_primitive_size("Cube", {40., 40., 10.}));
CHECK(is_primitive_size("Cylinder", {90., 4.}));
CHECK(is_primitive_size("Sphere", {25.6}));
CHECK(is_primitive_size("Torus", {30., 10.}));
CHECK_FALSE(is_primitive_size("Cube", {40., 40.}));
CHECK_FALSE(is_primitive_size("Sphere", {25., 25.}));
CHECK_FALSE(is_primitive_size("Cube", {40., 0., 10.}));
CHECK_FALSE(is_primitive_size("Cube", {40., -1., 10.}));
CHECK_FALSE(is_primitive_size("Cube", {40., std::numeric_limits<double>::infinity(), 10.}));
CHECK_FALSE(is_primitive_size("Cube", {}));
// A shape with no size dialog takes the empty size alone.
CHECK(is_primitive_size("Benchy", {}));
CHECK_FALSE(is_primitive_size("Benchy", {10.}));
}
TEST_CASE("the arrange options keep Align to Y axis off while auto rotation is on", "[Mcp][Scene]")
{
GLCanvas3D::ArrangeSettings settings;
settings.align_to_y_axis = true;
CHECK_FALSE(settings.apply_option_rules());
CHECK(settings.align_to_y_axis);
settings.enable_rotation = true;
CHECK(settings.apply_option_rules());
CHECK_FALSE(settings.align_to_y_axis);
// Nothing left to turn off.
CHECK_FALSE(settings.apply_option_rules());
CHECK(settings.enable_rotation);
}
TEST_CASE("primitive size params parse numbers separated by spaces or commas", "[Mcp][Scene]")
{
CHECK(NativeCommands::parse_sizes("90 4") == std::vector<double>{90., 4.});
+553
View File
@@ -0,0 +1,553 @@
#include <catch2/catch_message.hpp>
#include <catch2/catch_test_macros.hpp>
#include "slic3r/GUI/Mcp/McpService.hpp"
#include "slic3r/GUI/Mcp/McpTypes.hpp"
#include "slic3r/GUI/NativeCommands.hpp"
#include "slic3r/GUI/Operations/Outcome.hpp"
#include "slic3r/GUI/Operations/PlateOps.hpp"
#include "slic3r/GUI/Operations/ProjectOps.hpp"
#include "slic3r/GUI/Operations/RunStatus.hpp"
#include "slic3r/GUI/PresetComboBoxes.hpp"
#include <boost/filesystem/path.hpp>
#include <chrono>
#include <cstdint>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace Slic3r::GUI::Ops;
using namespace std::chrono_literals;
namespace {
// A run that started for request `started_for` (5, the test ticket's own, unless given).
SliceRunRecord run(uint64_t seq, uint64_t revision, uint64_t request, bool cancelled = false, bool finished = true,
uint64_t started_for = 5, int plate = 0)
{
SliceRunRecord r;
r.seq = seq;
r.finished = finished;
r.cancelled = cancelled;
r.ok = finished && !cancelled;
r.revision_at_finish = revision;
r.request_seq_at_finish = request;
r.request_seq_at_start = started_for;
r.plate = plate;
return r;
}
SliceRunRecord plate_run(uint64_t seq, int plate, std::string error = {}, bool cancelled = false)
{
SliceRunRecord r = run(seq, 1, 5, cancelled, true, 5, plate);
r.ok = r.ok && error.empty();
r.error = std::move(error);
return r;
}
std::vector<PlateOutcome> outcomes(const std::vector<PlateResult>& results)
{
std::vector<PlateOutcome> out;
for (const PlateResult& r : results)
out.push_back(r.outcome);
return out;
}
SliceTicketState ticket(uint64_t request_mine, uint64_t run_before, uint64_t revision)
{
SliceTicketState t;
t.request_seq_mine = request_mine;
t.run_seq_before = run_before;
t.revision_at_start = revision;
t.seen_running = true;
t.started = std::chrono::steady_clock::now() - 10s;
return t;
}
SliceObservation observe(uint64_t request, uint64_t revision, std::vector<SliceRunRecord> runs, bool slicing = false)
{
SliceObservation o;
o.slicing_any = slicing;
o.request_seq = request;
o.current_revision = revision;
o.runs_since_start = std::move(runs);
return o;
}
} // namespace
TEST_CASE("classify_plates reports ok, error, empty, skipped and cancelled", "[Operations]")
{
const std::vector<PlateObservation> plates{{0, true, false}, {1, false, false}, {2, false, true}, {3, false, false}};
const auto results = classify_plates({0, 1, 2, 3, 7}, plates, {plate_run(11, 0), plate_run(12, 1, "boom")});
CHECK(outcomes(results) == std::vector<PlateOutcome>{PlateOutcome::Ok, PlateOutcome::Error, PlateOutcome::Empty,
PlateOutcome::Skipped, PlateOutcome::Skipped});
CHECK(results[1].error == "boom");
CHECK(outcomes(classify_plates({3}, plates, {plate_run(11, 0, {}, true)})) == std::vector<PlateOutcome>{PlateOutcome::Cancelled});
// Finished without a result and without saying why.
SliceRunRecord no_result = plate_run(11, 1);
no_result.ok = false;
const auto failed = classify_plates({1}, plates, {no_result});
CHECK(failed[0].outcome == PlateOutcome::Error);
CHECK(failed[0].error == "the slice finished without a result");
}
TEST_CASE("a plate keeps the outcome of its own run whatever happened to it afterwards", "[Operations]")
{
// An edit replaced the result.
CHECK(outcomes(classify_plates({0}, {{0, false, false}}, {plate_run(11, 0)})) == std::vector<PlateOutcome>{PlateOutcome::Ok});
// Someone deleted the objects.
CHECK(outcomes(classify_plates({0}, {{0, false, true}}, {plate_run(11, 0)})) == std::vector<PlateOutcome>{PlateOutcome::Ok});
// Someone else's slice succeeded after ours failed.
const auto results = classify_plates({0}, {{0, true, false}}, {plate_run(11, 0, "Floating regions")});
CHECK(results[0].outcome == PlateOutcome::Error);
CHECK(results[0].error == "Floating regions");
// The plate was deleted.
CHECK(outcomes(classify_plates({0}, {}, {plate_run(11, 0)})) == std::vector<PlateOutcome>{PlateOutcome::Ok});
}
TEST_CASE("Slice All stopping at a failing plate leaves the later plates skipped", "[Operations]")
{
const std::vector<PlateObservation> plates{{0, true, false}, {1, false, false}, {2, false, false}};
const auto results = classify_plates({0, 1, 2}, plates, {plate_run(11, 0), plate_run(12, 1, "Floating regions")});
CHECK(outcomes(results) == std::vector<PlateOutcome>{PlateOutcome::Ok, PlateOutcome::Error, PlateOutcome::Skipped});
CHECK(results[2].error.empty());
}
TEST_CASE("a plate the validation refused reports that error", "[Operations]")
{
// Refused at the request: Plater records a finished run carrying the validation message.
auto results = classify_plates({0}, {{0, false, false}}, {plate_run(11, 0, "Nozzle too small")});
CHECK(results[0].outcome == PlateOutcome::Error);
CHECK(results[0].error == "Nozzle too small");
// Refused before the request (the setting change validated it), so no run at all.
results = classify_plates({0}, {{0, false, false, "Layer height cannot exceed nozzle diameter"}}, {});
CHECK(results[0].outcome == PlateOutcome::Error);
CHECK(results[0].error == "Layer height cannot exceed nozzle diameter");
}
TEST_CASE("a slice stays pending until it was seen running or the grace period passed", "[Operations]")
{
SliceTicketState t = ticket(5, 10, 1);
t.seen_running = false;
t.started = std::chrono::steady_clock::now();
CHECK(slice_status(t, observe(5, 1, {}), t.started + 100ms) == TicketStatus::Pending);
CHECK(slice_status(t, observe(5, 1, {}), t.started + kSliceStartGrace + 1ms) == TicketStatus::Done);
CHECK(slice_status(ticket(5, 10, 1), observe(5, 1, {}, true), std::chrono::steady_clock::now()) == TicketStatus::Pending);
}
TEST_CASE("a slice is superseded by another request or an edit while it ran", "[Operations]")
{
const auto now = std::chrono::steady_clock::now();
const SliceTicketState t = ticket(5, 10, 1);
CHECK(slice_status(t, observe(6, 1, {run(11, 1, 6)}), now) == TicketStatus::Superseded); // a GUI slice request during it
CHECK(slice_status(t, observe(5, 2, {run(11, 2, 5)}), now) == TicketStatus::Superseded); // an edit before its run finished
CHECK(slice_status(t, observe(5, 1, {run(11, 1, 5)}), now) == TicketStatus::Done);
}
TEST_CASE("actions after a slice finished do not supersede it", "[Operations]")
{
const auto now = std::chrono::steady_clock::now();
const SliceTicketState t = ticket(5, 10, 1);
// Another request and an edit, both after the run recorded its finish.
CHECK(slice_status(t, observe(6, 2, {run(11, 1, 5)}), now) == TicketStatus::Done);
}
TEST_CASE("a slice with no run of its own never reads an earlier run's completion", "[Operations]")
{
const auto now = std::chrono::steady_clock::now();
// Empty slice after a project reset: the last earlier run (seq 10) finished at another revision.
SliceTicketState empty = ticket(5, 10, 7);
empty.seen_running = false;
CHECK(slice_status(empty, observe(5, 7, {run(10, 3, 4)}), now) == TicketStatus::Done);
// Cached slice whose start revision differs from the last earlier run's.
CHECK(slice_status(empty, observe(5, 7, {}), now) == TicketStatus::Done);
// No run, but the project changed before the terminal poll.
CHECK(slice_status(empty, observe(5, 8, {}), now) == TicketStatus::Superseded);
}
TEST_CASE("cancellation is taken only from the operation's own runs", "[Operations]")
{
const SliceTicketState t = ticket(5, 10, 1);
CHECK_FALSE(slice_cancelled(t, observe(5, 1, {run(10, 1, 5, true), run(11, 1, 5)})));
CHECK(slice_cancelled(t, observe(5, 1, {run(11, 1, 5, true)})));
// A person's slice started during the operation (a later request) and cancelled is not ours.
CHECK_FALSE(slice_cancelled(t, observe(6, 1, {run(11, 1, 5), run(12, 1, 6, true, true, 6)})));
}
TEST_CASE("a later request supersedes at once only when it came while the slice ran", "[Operations]")
{
const auto now = std::chrono::steady_clock::now();
const SliceTicketState t = ticket(5, 10, 1);
// A person's slice for request 6, still running, restarted ours.
SliceObservation during = observe(6, 1, {run(11, 1, 6, true), run(12, 0, 0, false, false, 6)}, true);
during.interrupted = true;
CHECK(slice_status(t, during, now) == TicketStatus::Superseded);
// Slice All asked again between two of its plates: the first plate's run finished cleanly.
SliceObservation between = observe(6, 1, {run(11, 1, 5), run(12, 0, 0, false, false, 6)}, true);
between.interrupted = true;
CHECK(slice_status(t, between, now) == TicketStatus::Superseded);
// Requested after ours had finished: our result stands, and their slice is not waited for.
CHECK(slice_status(t, observe(6, 1, {run(11, 1, 5), run(12, 0, 0, false, false, 6)}, true), now) == TicketStatus::Done);
// Our own run still running, nobody else's: pending.
CHECK(slice_status(t, observe(5, 1, {run(11, 0, 0, false, false)}, true), now) == TicketStatus::Pending);
}
TEST_CASE("a plate's result is the operation's until someone else slices it", "[Operations]")
{
const SliceTicketState t = ticket(5, 10, 1);
// Already sliced: no run touched plate 0.
CHECK(plate_result_is_own(0, t, observe(5, 1, {})));
// Our run was the plate's last.
CHECK(plate_result_is_own(0, t, observe(5, 1, {plate_run(11, 0)})));
// A person sliced plate 0 again after ours finished (request 6).
CHECK_FALSE(plate_result_is_own(0, t, observe(6, 1, {plate_run(11, 0), run(12, 1, 6, false, true, 6, 0)})));
// Their slice of another plate leaves ours alone.
CHECK(plate_result_is_own(0, t, observe(6, 1, {plate_run(11, 0), run(12, 1, 6, false, true, 6, 1)})));
}
TEST_CASE("a reslice or export under the request's number that the request did not start is not the operation's", "[Operations]")
{
const SliceTicketState t = ticket(5, 10, 1);
// Our run, then a GUI export of the same plate that failed (no new slice request).
SliceRunRecord export_run = run(12, 1, 5, false, true, 5, 0);
export_run.for_request = false;
export_run.ok = false;
export_run.error = "Disk full";
const SliceObservation obs = observe(5, 1, {plate_run(11, 0), export_run});
REQUIRE(own_runs(t, obs).size() == 1);
CHECK(outcomes(classify_plates({0}, {{0, true, false}}, own_runs(t, obs))) == std::vector<PlateOutcome>{PlateOutcome::Ok});
// Its result is no longer known to be ours, so no statistics.
CHECK_FALSE(plate_result_is_own(0, t, obs));
}
TEST_CASE("a slice request refused before validating reports the refusal over a cached result", "[Operations]")
{
// Plater records the refusal (a broken mixed filament here) as a rejected run of the request.
const auto results = classify_plates({0}, {{0, true, false}}, {plate_run(11, 0, "A mixed filament has a deleted or mismatched component")});
CHECK(results[0].outcome == PlateOutcome::Error);
CHECK(results[0].error == "A mixed filament has a deleted or mismatched component");
}
TEST_CASE("a run already slicing that the request left running is the operation's", "[Operations]")
{
const auto now = std::chrono::steady_clock::now();
SliceTicketState t = ticket(5, 10, 1);
t.adopted_run = 10;
// Started for an earlier request, finished under ours with an error.
SliceRunRecord adopted = run(10, 1, 5, false, true, 4);
adopted.ok = false;
adopted.error = "Floating regions";
const SliceObservation obs = observe(5, 1, {adopted});
REQUIRE(own_runs(t, obs).size() == 1);
CHECK(slice_status(t, obs, now) == TicketStatus::Done);
const auto results = classify_plates({0}, {{0, false, false}}, own_runs(t, obs));
CHECK(results[0].outcome == PlateOutcome::Error);
CHECK(results[0].error == "Floating regions");
// Not adopted, the same run is someone else's.
CHECK(own_runs(ticket(5, 10, 1), obs).empty());
}
TEST_CASE("early runs of a long Slice All are still seen", "[Operations]")
{
const SliceTicketState t = ticket(5, 100, 1);
std::vector<SliceRunRecord> runs;
for (uint64_t i = 1; i <= 20; ++i)
runs.push_back(run(100 + i, 1, 5, i == 2));
CHECK(slice_cancelled(t, observe(5, 1, runs)));
runs[1].cancelled = false;
runs[2].revision_at_finish = 9;
CHECK(slice_status(t, observe(5, 1, runs), std::chrono::steady_clock::now()) == TicketStatus::Superseded);
}
TEST_CASE("export status follows its own sequence number", "[Operations]")
{
ExportRecord rec;
rec.seq = 4;
CHECK(export_status(3, 3, std::nullopt, 1) == ExportStatus::Rejected);
CHECK(export_status(3, 4, rec, 1) == ExportStatus::Pending);
rec.finished = true;
rec.ok = true;
rec.revision_at_finish = 1;
CHECK(export_status(3, 4, rec, 1) == ExportStatus::Ok);
rec.revision_at_finish = 2;
CHECK(export_status(3, 4, rec, 1) == ExportStatus::Superseded);
rec.ok = false;
CHECK(export_status(3, 4, rec, 2) == ExportStatus::Failed);
rec.cancelled = true;
CHECK(export_status(3, 4, rec, 2) == ExportStatus::Cancelled);
}
TEST_CASE("an outcome holds a value or a refusal", "[Operations]")
{
const Outcome<int> value(7);
REQUIRE(value);
CHECK(value.value() == 7);
const Outcome<int> refused(Refusal{RefusalKind::Busy, "slicing_in_progress", "Slicing is in progress."});
REQUIRE_FALSE(refused);
CHECK(refused.refusal().kind == RefusalKind::Busy);
CHECK(std::string(refused.refusal().code) == "slicing_in_progress");
}
TEST_CASE("an outcome of a string is not taken for a refusal", "[Operations]")
{
const Outcome<std::string> value(std::string("Generic PLA"));
REQUIRE(value);
CHECK(value.value() == "Generic PLA");
}
TEST_CASE("a refusal's English text fills its placeholders in order", "[Operations]")
{
const Refusal refusal{RefusalKind::Precondition, "preset_not_offered", "%1% does not offer \"%2%\".", {"Filament slot 2", "Generic PETG"}};
CHECK(refusal.english() == "Filament slot 2 does not offer \"Generic PETG\".");
}
TEST_CASE("a refusal with no placeholders keeps a percent sign", "[Operations]")
{
const Refusal refusal{RefusalKind::Failed, "fill_failed", "The bed is 100% full."};
CHECK(refusal.english() == "The bed is 100% full.");
}
TEST_CASE("a refusal whose values do not match its placeholders still gives text", "[Operations]")
{
const Refusal too_few{RefusalKind::Precondition, "x", "%1% and %2%", {"one"}};
CHECK(too_few.english() == "one and ");
const Refusal too_many{RefusalKind::Precondition, "x", "%1% only", {"one", "two"}};
CHECK(too_many.english() == "one only");
}
TEST_CASE("a refusal without a translation reads in the UI's language as it does in English", "[Operations]")
{
const Refusal refusal{RefusalKind::Precondition, "no_such_thing", "Thing %1% of the test does not exist", {"3"}};
CHECK(std::string(refusal.translated().ToUTF8().data()) == refusal.english());
}
TEST_CASE("no_such_plate names the plates the project has", "[Operations]")
{
const Refusal one = no_such_plate(4, 1);
CHECK(std::string(one.code) == "no_such_plate");
CHECK(one.kind == RefusalKind::Precondition);
CHECK(one.english() == "Plate 4 does not exist (the project has plate 0 only)");
CHECK(no_such_plate(-1, 3).english() == "Plate -1 does not exist (the project has plates 0..2)");
}
TEST_CASE("a project is not saved under a sliced file's name", "[Operations]")
{
// Refused on the name alone, before anything is asked of the app.
const Outcome<Done> saved = save_project_as({boost::filesystem::path("C:/out/part.gcode.3mf")});
REQUIRE_FALSE(saved);
CHECK(std::string(saved.refusal().code) == "sliced_file_name");
CHECK(saved.refusal().kind == RefusalKind::Precondition);
const Outcome<Done> upper = save_project_as({boost::filesystem::path("C:/out/PART.GCODE.3MF")});
REQUIRE_FALSE(upper);
CHECK(std::string(upper.refusal().code) == "sliced_file_name");
}
// ---- The catalogs name their operations ---------------------------------------------------------------
//
// A tool that changes something, and a command that takes a param, 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
// for the owner calls an operation stands for.
namespace {
// 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",
"import_models", "open_project", "new_project", "save_project_as", "set_instance_count",
"select_plate", "set_plate_locked", "start_arrange", "start_slice", "show_layer_range",
"resolve_preset", "select_preset", "assign_filament_preset", "import_presets",
};
// What an exception is, so that the reason reads the same for every entry of a kind.
constexpr const char* kRunsWhatItIsGiven = "runs what its arguments name, which is classified where it is defined";
constexpr const char* kDrivesTheGui = "drives the GUI as a person does: the widget it acts on decides what happens";
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";
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},
{"press_keys", kDrivesTheGui},
{"mouse_gesture", kDrivesTheGui},
{"pick_gizmo_file", kDrivesTheGui},
{"answer_dialog", kDrivesTheGui},
{"auto_answer_dialogs", kDrivesTheGui},
{"set_window", kDrivesTheGui},
{"cancel_job", kSessionState},
{"export_replay", kSessionState},
{"start_recording", kSessionState},
{"stop_recording", kSessionState},
{"encode_recording", kSessionState},
{"generate_calibration_test", kOneEntryPoint},
{"save_preset", kOneEntryPoint},
{"delete_preset", kOneEntryPoint},
{"transform", kOneEntryPoint},
{"add_part", kOneEntryPoint},
{"select_objects", kOneEntryPoint},
{"set_height_ranges", kOneEntryPoint},
{"set_variable_layer_height", kOneEntryPoint},
{"set_custom_gcode_at_layer", kOneEntryPoint},
};
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},
{"obj_order_by_name", kOneEntryPoint},
{"obj_order_by_filament", kOneEntryPoint},
{"obj_order_by_height", kOneEntryPoint},
{"obj_order_by_size", kOneEntryPoint},
{"add_primitive_svg", kOneEntryPoint},
{"add_primitive_cube", kOneEntryPoint},
{"add_primitive_cylinder", kOneEntryPoint},
{"add_primitive_sphere", kOneEntryPoint},
{"add_primitive_cone", kOneEntryPoint},
{"add_primitive_disc", kOneEntryPoint},
{"add_primitive_torus", kOneEntryPoint},
{"install_local_plugin", kOneEntryPoint},
{"filament_delete", kOneEntryPoint},
};
} // namespace
TEST_CASE("a range of layers is brought into the plate's layers, and one given backwards shows its first layer", "[Operations]")
{
// 100 layers are the slider's ticks 0..99.
LayerTicks ticks = layer_ticks(20, 60, 100);
CHECK(ticks.low == std::optional<int>(19));
CHECK(ticks.high == 59);
ticks = layer_ticks(60, 20, 100);
CHECK(ticks.low == std::optional<int>(59));
CHECK(ticks.high == 59);
ticks = layer_ticks(-5, 500, 100);
CHECK(ticks.low == std::optional<int>(0));
CHECK(ticks.high == 99);
ticks = layer_ticks(500, 600, 100);
CHECK(ticks.low == std::optional<int>(99));
CHECK(ticks.high == 99);
ticks = layer_ticks(1, 0, 100);
CHECK(ticks.low == std::optional<int>(0));
CHECK(ticks.high == 0);
// Without a first layer the lower thumb is not moved.
ticks = layer_ticks(std::nullopt, 10, 100);
CHECK_FALSE(ticks.low.has_value());
CHECK(ticks.high == 9);
CHECK(layer_ticks(std::nullopt, 500, 100).high == 99);
CHECK(layer_ticks(std::nullopt, -3, 100).high == 0);
}
TEST_CASE("a filament pick finds the selector's row that stores the preset, else an unnamed row labelled with it", "[Operations]")
{
using Slic3r::GUI::PresetRow;
using Slic3r::GUI::row_for_preset;
// A filament selector as the sidebar lays it out: the AMS filaments under their header, which store
// no preset name, then the presets under theirs. A row's index is its item's, headers included.
const std::vector<PresetRow> rows = {{"", "AMS filaments", true},
{"", "Bambu ABS"},
{"", "Generic PETG"},
{"", "System presets", true},
{"Bambu PLA Basic @BBL X1C", "Bambu PLA Basic"},
{"Generic PETG", "Generic PETG"},
{"", "Bambu PLA Basic", true}};
CHECK(row_for_preset(rows, "Bambu PLA Basic @BBL X1C") == 4);
// An AMS filament's row stores no name, so its label is the name a pick of it carries.
CHECK(row_for_preset(rows, "Bambu ABS") == 1);
// The row that stores the name is taken, wherever an unnamed one labelled with it is.
CHECK(row_for_preset(rows, "Generic PETG") == 5);
// A row that stores a name is picked by that name and not by its label, and a header never is.
CHECK(row_for_preset(rows, "Bambu PLA Basic") == -1);
CHECK(row_for_preset(rows, "AMS filaments") == -1);
CHECK(row_for_preset(rows, "Bambu PETG HF") == -1);
CHECK(row_for_preset({}, "Bambu ABS") == -1);
}
TEST_CASE("a tool that changes something 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)
continue;
INFO(tool.name);
const bool excepted = kToolExceptions.count(tool.name) != 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]")
{
for (const Slic3r::GUI::NativeCommand& command : Slic3r::GUI::NativeCommands::catalog()) {
if (command.param.type == Slic3r::GUI::CommandParamType::None)
continue;
INFO(command.key);
const bool excepted = kCommandExceptions.count(command.key) != 0;
CHECK(command.operations.empty() == excepted);
}
}
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 std::string& operation : command.operations) {
INFO(command.key << " names " << operation);
CHECK(kOperations.count(operation) == 1);
}
}
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);
REQUIRE(tool != nullptr);
// A read-only tool needs no exception.
CHECK_FALSE(tool->read_only);
}
for (const auto& [key, reason] : kCommandExceptions) {
INFO(key << ": " << reason);
const Slic3r::GUI::NativeCommand* command = Slic3r::GUI::NativeCommands::find(key);
REQUIRE(command != nullptr);
CHECK(command->param.type != Slic3r::GUI::CommandParamType::None);
}
}
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");
REQUIRE(tool != nullptr);
REQUIRE_FALSE(tool->operations.empty());
CHECK(tool->input_schema.dump().find("start_gcode_export") == std::string::npos);
CHECK(tool->description.find("start_gcode_export") == std::string::npos);
}
+30
View File
@@ -274,6 +274,36 @@ refusals that leave the project as it was (modified presets without `preset_chan
does not take), `preset_changes: "keep"` keeping an edit, and `new_project` dropping the test's settings. It
starts from the harness's default printer and reruns on the same datadir.
`tests/ops_*.json` drive each operation of the operations layer (`docs/HLSD/mcp-server.md`, "The
operations layer") through every route that reaches it: the Speed Dial command run with `run_action`,
the typed tool and, for presets, a pick in the sidebar and the plugin API called from a `run_script`
step. One replay per operation, named after it: G-code, sliced 3MF, model 3MF and STL exports, a model
import, a project opened, started anew and saved, a plate selected and locked, arrange, slice, the
Preview's layer range, a printer or process preset selected (`ops_select_preset`), a filament assigned
to a slot on a printer with one slot and with several (`ops_assign_filament_preset_one_slot`,
`_multi_slot`), presets imported, an object's instance count, and the refusals of `send_gcode`, which
never sets a print host, so nothing is sent. Each records what a call leaves: its reply or its
refusal's text, the state read back after it, and the undo snapshots it took, which
`tests/fixtures/ops_undo.py` reads from the app's log since no tool lists the undo history. Their
`expect`s are on the setup and on what is read back. A replay cannot assert a refusal's text, so a
call that a route refuses is `optional`, and `result.json` is the record of those texts, to compare
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.
`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
accept the same ones. It covers a project saved under a `.gcode.3mf` name, the exports of a project
with no objects, a layer asked of a Preview with none, an arrangement from the assemble view and with
a gizmo open, a mixed-colour filament slot, and a hidden printer selected through the plugin API. Run
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
marked `optional` are calls that must be refused and change nothing.
+174
View File
@@ -0,0 +1,174 @@
#!/usr/bin/env python3
"""Checks that the routes to one function accept and refuse the same states, in the same words.
tools/mcp/orca_mcp.py launch
tools/mcp/test_operation_routes.py
A Speed Dial command (run with run_action), the tool that does the same thing and the plugin API's
binding run one operation of GUI/Operations, so each pair here gets one answer: a project saved under
a .gcode.3mf name; an export of a project with no objects (a .3mf is written, an STL and a sliced file
are refused); a layer asked of a Preview that has none; an arrangement from the assemble view and with
a gizmo open; a preset for a mixed-colour filament slot; and a hidden printer selected by name through
the plugin API, as the select_preset tool selects one. The last two need the Bambu Lab X1 Carbon among
the printers, which the harness's datadir has. Run it on a freshly launched app: the Preview keeps the
layers of the last slice, and a hidden preset stays shown until the app restarts. Exits 0 when every
check passes.
"""
import json
import os
import sys
import tempfile
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
import orca_mcp # noqa: E402
FIXTURE = os.path.join(HERE, "tests", "fixtures", "ops_presets.py")
PRINTER = "Bambu Lab X1 Carbon 0.4 nozzle"
def refusal(error):
"""(code, text) of a failed call: an operation's refusal has its details, the code among them, on
the line after its text. The code is "" when the error is not an operation's."""
text, _, tail = str(error).rpartition("\n")
try:
return json.loads(tail).get("code", ""), text
except (ValueError, AttributeError):
return "", str(error)
def main():
client, _session = orca_mcp.session_client()
out = tempfile.mkdtemp(prefix="orca-routes-")
checks = []
def check(name, ok, detail=""):
checks.append((name, bool(ok), detail))
def path(name):
return os.path.join(out, name)
def answer(tool, **args):
"""(code, text) of a refused call, or (None, reply) of one that went through."""
try:
reply = client.call(tool, **args)
except orca_mcp.McpError as e:
return refusal(e)
# No call here should stop at a dialog; one that does is reported, not waited on.
if isinstance(reply, dict) and reply.get("status") == "blocked_by_dialog":
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 plugin_api(**args):
code = "import ops_presets\nresult = ops_presets.preset_api(args)"
return client.call("run_script", filename=FIXTURE, code=code, args=args)["result"]
def offsets():
return [o["instances"][0]["offset"][:2] for o in client.call("list_objects")["plates"][0]["objects"]]
client.call("new_project", discard_changes=True, preset_changes="discard")
client.call("set_view", tab="prepare")
# ---- A project with no objects ----
code_c, text_c = command("save_project_as", 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))
check("the tool's refusal is the command's, with its hint after it",
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_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_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_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))
check("in the same words (layer)", text_c == text_t, (text_c, text_t))
client.call("set_view", tab="prepare")
# ---- 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("wait", **{"for": "idle"})
before = offsets()
client.call("set_view", canvas="assemble")
code, reply = answer("arrange")
state = client.call("get_app_state")
check("the tool arranges from the assemble view", code is None and reply.get("off_plate") == [], reply)
check("and the arrangement moved a cube", offsets() != before, (before, offsets()))
check("and the Prepare view is shown afterwards", state["selection"].get("canvas") == "3d", state["selection"])
client.call("set_view", canvas="3d")
client.call("select_objects", objects=[0])
opened = client.call("click", target={"gizmo": "Move"})
code, reply = answer("arrange")
state = client.call("get_app_state")
check("the tool arranges with the Move gizmo open", opened.get("active") is True and code is None, (opened, reply))
check("and the gizmo stays open", state.get("gizmo") is not None, state.get("gizmo"))
if state.get("gizmo") is not None:
client.call("click", target={"gizmo": "Move"})
# ---- A mixed-colour filament slot, and a hidden printer ----
client.call("new_project", discard_changes=True, preset_changes="discard")
client.call("select_preset", type="printer", name=PRINTER, preset_changes="discard")
while len(client.call("get_app_state")["presets"]["filaments"]) < 2:
client.call("run_action", id="orca_command:filament_add:orca")
slot_preset = client.call("get_app_state")["presets"]["filaments"][0]
blocked = client.call("click", target={"label": "Add Mixed Filament"})
if blocked.get("status") == "blocked_by_dialog":
client.call("answer_dialog", button="OK")
client.await_job(blocked)
flags = client.call("get_settings", scope="project", keys=["filament_is_mixed"])["items"][0]["value"].split(",")
check("a mixed filament was added", "1" in flags, flags)
if "1" in flags:
slot = flags.index("1") + 1
code_t, text_t = answer("select_preset", type="filament", name=slot_preset, filament_slot=slot)
raised = plugin_api(editor="filament", form="begin_update", slot=slot, name=slot_preset, commit=True).get("raised", {})
check("the tool refuses a mixed-colour slot as one", code_t == "mixed_filament_slot", (code_t, text_t))
check("the plugin API refuses it with a ValueError in the same words",
raised.get("type") == "ValueError" and raised.get("message") == text_t, (raised, text_t))
client.call("click", target={"label": "Remove last mixed filament"})
listed = client.call("list_presets", type="printer", include_hidden=True, limit=500)["items"]
hidden = [p["name"] for p in listed if p.get("visible") is False and p.get("compatible", True) is not False]
# A printer of the same family first: its process and filament suit the one selected.
hidden.sort(key=lambda name: not name.startswith("Bambu Lab X1"))
check("a printer is still hidden (else restart the app)", bool(hidden), len(listed))
if hidden:
got = plugin_api(editor="printer", form="begin_update", name=hidden[0], commit=True)
client.call("wait", **{"for": "idle"})
selected = client.call("get_app_state")["presets"]["printer"]
check("the plugin API shows a hidden printer and selects it", "raised" not in got and selected == hidden[0], (got, selected))
client.call("select_preset", type="printer", name=PRINTER, preset_changes="discard")
while len(client.call("get_app_state")["presets"]["filaments"]) > 1:
client.call("run_action", id="orca_command:filament_delete:orca")
client.call("new_project", discard_changes=True, preset_changes="discard")
failed = [c for c in checks if not c[1]]
for name, ok, detail in checks:
print(("ok " if ok else "FAIL ") + name + ("" if ok else " " + json.dumps(detail, default=str)[:600]))
print("%d of %d checks passed" % (len(checks) - len(failed), len(checks)))
return 1 if failed else 0
if __name__ == "__main__":
sys.exit(main())
+18 -1
View File
@@ -3,7 +3,8 @@
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
ends by unticking the fixture in the Plugins dialog, as a person unloads it. Run it as
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
@@ -72,6 +73,15 @@ def wait_for(predicate, timeout):
return predicate()
def lines_of(path):
"""How many lines a file has, 0 while it does not exist."""
try:
with open(path, encoding="utf-8") as f:
return len(f.readlines())
except OSError:
return 0
def harness(env, *args):
return subprocess.run([sys.executable, os.path.join(HERE, "orca_mcp.py"), *args], env=env, capture_output=True, text=True,
timeout=300)
@@ -156,6 +166,13 @@ def main():
journal)
broken = orca.call_raw("search_tools", {"tool": f"plugin.{BROKEN}.measure"})
check("a plugin whose load failed offers none of its operations", broken.get("isError"), broken)
# A project started by the tool or by the command tells plugins, as File > New Project does.
started = lambda: lines_of(os.path.join(plugin_dir, "new_projects.txt"))
before = started()
orca.call("new_project", discard_changes=True)
check("the new_project tool sends plugins the NewProject event", wait_for(lambda: started() == before + 1, 10), started())
orca.call("run_action", id="orca_command:new_project:orca")
check("and so does the new_project command", wait_for(lambda: started() == before + 2, 10), started())
held = run_plugin_script(orca, plugin_dir, "handle", CAPABILITIES[4])
check("the plugin opens a progress dialog and keeps its handle", held.get("ok") is True, held)
grab = orca.await_job(orca.call("run_script", code=GRAB_HANDLE))
+16 -1
View File
@@ -8,7 +8,9 @@ Picking a view type is the legend combo's pick: a feature type hidden by a click
shows again when Line Type is picked, and the pick is written to the app config for the "Last used"
preview default. A canvas screenshot taken straight after a layer change shows the new layers, not
the previous ones under the new slider position, and one after a view type change shows the legend
laid out for it. The refusals: legend rows before a slice, a height above the top layer, layer with
laid out for it. A range given backwards shows its first layer alone, and in the slider's one-layer
mode the reply still echoes the range asked for while the one layer shown is its first. The refusals:
legend rows before a slice, a height above the top layer, layer with
layer_z, an unknown legend row (named with the rows the print has), a value that is not true or
false, and a silent-mode estimate the print does not have; a refused call changes nothing. Exits 0
when every check passes.
@@ -107,6 +109,19 @@ def main():
check("layer_z between two tops shows up to the upper one", reply.get("layers") == [1, 6, 128] and reply.get("z") == [0.2, 1.2], reply)
check("the legend reply gives each row's state", reply.get("legend") == {"Sparse infill": False, "travel": True}, reply)
reply = client.call("set_view", layer_range=[60, 20])
check("a range given backwards shows its first layer alone", reply.get("layers") == [60, 60, 128] and reply.get("z") == [12.0, 12.0],
reply)
# L switches the layer slider's one-layer mode.
client.call("press_keys", keys="L")
reply = client.call("set_view", layer_range=[2, 5])
shown = client.call("get_app_state")["preview"]
check("in one-layer mode the reply echoes the range and the slider shows its first layer",
reply.get("layers") == [2, 5, 128] and reply.get("z") == [0.4, 0.4] and shown.get("layers") == [2, 2], (reply, shown))
client.call("press_keys", keys="L")
shown = client.call("get_app_state")["preview"]
check("leaving one-layer mode shows every layer again", shown.get("layers") == [1, 128], shown)
message = refusal(layer_z=80)
check("a height above the top layer is refused", "above the top layer (25.6 mm)" in message, message)
check("layer with layer_z is refused", "not both" in refusal(layer=3, layer_z=1.0))
+151
View File
@@ -0,0 +1,151 @@
"""Helpers for the ops_select_preset and ops_assign_filament_preset replays, run with run_script:
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py",
"code": "import ops_presets\nresult = ops_presets.probe()"}}
A run whose filename is an existing file imports the modules beside it, so the replays share one copy of each
helper. Each returns what it saw as a dict, which the step's result keeps. A call into the plugin API that raises
is reported by its exception's type and message rather than failing the step.
"""
import orca
try:
import ops_undo
except ImportError: # ops_undo.py reads the undo snapshots from the log; without it they are not reported
ops_undo = None
call = orca.host.tools.call
# Filament colours and a flushing volume no preset or calculation gives, so a probe shows what a call wrote.
SENTINEL_COLOURS = ["#111111", "#222222", "#333333", "#444444"]
SENTINEL_FLUSH = 777
def _name(preset):
return preset.name + (" (modified)" if preset.is_dirty else "")
def _undo():
return ops_undo.taken()["taken"] if ops_undo is not None else "ops_undo.py missing"
def probe():
"""What a call left: the slot mapping, the preset each tab edits, the three filament colour settings that
PlaterPresetComboBox::update_ams_color() writes, the project scope's colours and flushing volumes, the open
dialogs, the project's dirty flag and the undo snapshots taken since the last probe or arrange."""
bundle = orca.host.preset_bundle()
state = call("get_app_state", {})
project = call("get_settings", {"scope": "project", "keys": ["filament_colour", "flush_volumes_matrix"],
"include_meta": False})
return {
"slots": bundle.current_filament_preset_names(),
"filament_tab": _name(bundle.filaments.edited_preset()),
"process_tab": _name(bundle.prints.edited_preset()),
"printer_tab": _name(bundle.printers.edited_preset()),
"filament_colour": bundle.full_config_value("filament_colour"),
"filament_colour_type": bundle.full_config_value("filament_colour_type"),
"filament_multi_colour": bundle.full_config_value("filament_multi_colour"),
"project": {item["key"]: item["value"] for item in project["items"]},
"dialogs": [dialog.get("title") for dialog in state["dialogs"]],
"project_dirty": state["project"]["dirty"],
"undo_taken": _undo(),
}
def drop_filament_edits():
"""Drops the unsaved changes of the filament preset the tab edits. set_settings reaches the filament tab
through a slot (slot 1 by default) and switches the tab to that slot's preset first, which asks about
the changes, so it is given the slot that holds the edited preset; when no slot holds it, the question
that opens is answered with Discard."""
bundle = orca.host.preset_bundle()
edited = bundle.filaments.edited_preset()
if not edited.is_dirty:
return
names = bundle.current_filament_preset_names()
slot = names.index(edited.name) + 1 if edited.name in names else 1
reply = call("set_settings", {"scope": "filament", "filament_slot": slot, "reset_all": True})
if isinstance(reply, dict) and reply.get("status") == "blocked_by_dialog":
call("answer_dialog", {"button": "Discard"})
call("wait", {"for": "job", "job": reply["job"]})
def arrange_filaments(args):
"""The state a filament case starts from. args: slots (each slot's preset, by the name its selector shows;
the slot count must already match), tab_slot (1-based: the filament tab edits that slot's preset, default
1), dirty (an unsaved slow_down_layer_time on the preset the tab edits). Colours and flushing volumes are
set to the sentinels. The slot presets are assigned with select_preset and the tab switched with
set_settings filament_slot, both after the edits are dropped, so no prompt opens."""
bundle = orca.host.preset_bundle()
wanted = args["slots"]
if len(bundle.current_filament_preset_names()) != len(wanted):
raise RuntimeError("the project has %d slots, the case wants %d"
% (len(bundle.current_filament_preset_names()), len(wanted)))
drop_filament_edits()
for slot, name in enumerate(wanted, 1):
call("select_preset", {"type": "filament", "name": name, "filament_slot": slot})
call("set_settings", {"scope": "filament", "filament_slot": args.get("tab_slot", 1), "reset_all": True})
n = len(wanted)
matrix = [0 if i == j else SENTINEL_FLUSH for i in range(n) for j in range(n)]
call("set_settings", {"scope": "project", "values": {"filament_colour": SENTINEL_COLOURS[:n],
"flush_volumes_matrix": matrix}})
if args.get("dirty"):
call("set_settings", {"scope": "filament", "values": {"slow_down_layer_time": 9}})
call("wait", {"for": "idle"})
_undo()
return probe()
def arrange_presets(args):
"""The state a printer or process case starts from. args: printer, process (names), dirty ("process": an
unsaved wall_loops; "printer": unsaved printer notes). Every preset's edits are dropped first."""
drop_filament_edits()
for scope in ("process", "printer"):
call("set_settings", {"scope": scope, "reset_all": True})
bundle = orca.host.preset_bundle()
if bundle.printers.edited_preset().name != args["printer"]:
call("select_preset", {"type": "printer", "name": args["printer"], "preset_changes": "discard"})
if bundle.prints.edited_preset().name != args["process"]:
call("select_preset", {"type": "process", "name": args["process"], "preset_changes": "discard"})
dirty = args.get("dirty")
if dirty == "process":
call("set_settings", {"scope": "process", "values": {"wall_loops": 5}})
elif dirty == "printer":
call("set_settings", {"scope": "printer", "values": {"printer_notes": "MCP pin"}})
call("wait", {"for": "idle"})
_undo()
return probe()
def _transaction(t):
return {"target_name": t.target_name, "selection_changed": t.selection_changed, "slot_number": t.slot_number,
"category": t.category}
def _update_result(r):
return {"target_name": r.target_name, "selection_changed": r.selection_changed,
"slot_assignment_changed": r.slot_assignment_changed, "shared_slots": list(r.shared_slots),
"keys": list(r.keys), "dirty": r.dirty}
def preset_api(args):
"""One call into orca.host.preset.<editor> (process, printer or filament). args: form "begin_update" with
slot and name as given (either may be left out), then set [key, value] and commit when asked; or form
"update" with slot when given, key and value."""
editor = getattr(orca.host.preset, args["editor"])
out = {"call": args}
try:
if args["form"] == "begin_update":
positional = [args[k] for k in ("slot", "name") if k in args]
t = editor.begin_update(*positional)
out["begin_update"] = _transaction(t)
if "set" in args:
t.set(args["set"][0], args["set"][1])
if args.get("commit"):
out["commit"] = _update_result(t.commit())
else:
positional = [args[k] for k in ("slot", "key", "value") if k in args]
editor.update(*positional)
out["update"] = "returned"
except Exception as e:
out["raised"] = {"type": type(e).__name__, "message": str(e)}
return out
+41
View File
@@ -0,0 +1,41 @@
"""The undo snapshots the app took since the last call, read from its log, for the ops_*.json replays.
No tool lists the undo history, and Plater::priv::take_snapshot() logs every snapshot it takes
("Undo / Redo snapshot taken: <name>"), so this reads those lines and keeps how many it has seen in
<datadir>/mcp/ops_undo_mark.txt. The first call of a run sets the mark; each later one returns the names
of the snapshots taken since the previous call, in order. A replay calls it with
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_undo.py",
"code": "import ops_undo\nresult = ops_undo.taken()"}}
log_lines(text) returns the last log lines that contain a text, for what only the log says (a picker a
rule cancelled, for one).
"""
import os
import orca
KEY = "Undo / Redo snapshot taken: "
def taken():
log = orca.host.tools.call("get_log", {"lines": 1})["file"]
with open(log, encoding="utf-8", errors="replace") as f:
names = [line.split(KEY, 1)[1].split(", Undo / Redo stack memory")[0] for line in f if KEY in line]
mark = os.path.join(os.path.dirname(os.path.dirname(log)), "mcp", "ops_undo_mark.txt")
try:
with open(mark) as f:
seen = int(f.read())
except (OSError, ValueError):
seen = 0
if seen > len(names): # another log file: the app was restarted
seen = 0
with open(mark, "w") as f:
f.write(str(len(names)))
return {"taken": names[seen:], "count": len(names) - seen}
def log_lines(text, last=3):
"""The last `last` lines of the app's log that contain `text`, without their timestamps."""
log = orca.host.tools.call("get_log", {"lines": 1})["file"]
with open(log, encoding="utf-8", errors="replace") as f:
lines = [line.rstrip("\n") for line in f if text in line]
return [line.split("]:", 1)[-1] for line in lines[-last:]]
@@ -0,0 +1,414 @@
// Records the assignment of a filament preset to a slot on a printer with three slots. Slot 2 is assigned
// through each route: a pick in its selector in the sidebar (its list opened with click and the row clicked),
// the select_preset tool, and the plugin API's orca.host.preset.filament.begin_update(2, name) run from
// run_script; for an ordinary change to a filament with a default colour and to one without, and for a change to
// a support filament, under each value of the automatic flush calculation (Preferences > Behaviour > Auto flush
// after changing...). Then the plugin API's other forms, unsaved changes in the preset the filament tab edits,
// the refusals (no such slot, no such name, an incompatible preset, a mixed-colour slot) and a hidden preset. Each
// case starts from slot presets, colours and flushing volumes set to sentinels by fixtures/ops_presets.py, and
// after each call reads what it left once queued events have settled (the slot mapping, the edited filament
// preset, the three colour settings, the project's colours and flushing volumes, dialogs, undo snapshots).
// Refused calls are optional. Run it on a freshly launched app (a hidden preset stays shown until a restart)
// with
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_assign_filament_preset_multi_slot.json --out <dir>
{
"orca_replay": 1,
"name": "ops assign_filament_preset, several slots",
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_window", "args": {"size": [1920, 1040]}},
{"tool": "set_view", "args": {"tab": "prepare"}},
// Simple mode, as on a fresh datadir: the unsaved-changes prompt lists the settings the mode shows.
{"tool": "run_action", "args": {"id": "orca_command:mode_simple:orca"}},
// One slot first, so the presets below are shown and selected on the harness's default printer.
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1 Carbon 0.4 nozzle", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.20mm Standard @BBL X1C", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1, "preset_changes": "discard"}},
// The filaments the cases pick, hidden on a fresh datadir, are shown in every selector (until the app
// restarts) by selecting each once with the tool. FilAr PLA Blanco Calido has a default colour
// (#FFF8E7); the Bambu ones have none.
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 1}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Matte", "filament_slot": 1}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support For PLA", "filament_slot": 1}},
{"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": "run_action", "args": {"id": "orca_command:filament_add:orca"}},
{"tool": "run_action", "args": {"id": "orca_command:filament_add:orca"}},
{"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"},
// 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"}}},
{"tool": "answer_dialog", "args": {"dialog": {"title": "Preferences"}, "button": "close"}},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.prefs1}"}},
{"tool": "get_settings", "args": {"scope": "preferences", "keys": ["auto_calculate_flush"]}, "expect": {"/items/0/value": {"eq": "all"}}},
// ---- Slot 2, an ordinary change to a filament with a default colour: FilAr PLA Blanco Calido ----
// Picked in slot 2's selector, its list opened with a click and the row clicked.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}}},
{"tool": "click", "args": {"target": {"row": "FilAr PLA Blanco Calido"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The tool.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API, begin_update(2, name) and commit().
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "FilAr PLA Blanco Calido", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Slot 2, an ordinary change to a filament without one: Bambu PLA Matte ----
// Picked in slot 2's selector, its list opened with a click and the row clicked.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}}},
{"tool": "click", "args": {"target": {"row": "Bambu PLA Matte"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The tool.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Matte", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API, begin_update(2, name) and commit().
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "Bambu PLA Matte", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Slot 2, a change that makes the slot hold a support filament: Bambu Support For PLA ----
// Picked in slot 2's selector, its list opened with a click and the row clicked.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}}},
{"tool": "click", "args": {"target": {"row": "Bambu Support For PLA"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The tool.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support For PLA", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API, begin_update(2, name) and commit().
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "Bambu Support For PLA", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"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"},
// 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"}}},
{"tool": "answer_dialog", "args": {"dialog": {"title": "Preferences"}, "button": "close"}},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.prefs2}"}},
{"tool": "get_settings", "args": {"scope": "preferences", "keys": ["auto_calculate_flush"]}, "expect": {"/items/0/value": {"eq": "color change"}}},
// ---- Slot 2, an ordinary change to a filament with a default colour: FilAr PLA Blanco Calido ----
// Picked in slot 2's selector, its list opened with a click and the row clicked.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}}},
{"tool": "click", "args": {"target": {"row": "FilAr PLA Blanco Calido"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The tool.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API, begin_update(2, name) and commit().
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "FilAr PLA Blanco Calido", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Slot 2, an ordinary change to a filament without one: Bambu PLA Matte ----
// Picked in slot 2's selector, its list opened with a click and the row clicked.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}}},
{"tool": "click", "args": {"target": {"row": "Bambu PLA Matte"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The tool.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Matte", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API, begin_update(2, name) and commit().
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "Bambu PLA Matte", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Slot 2, a change that makes the slot hold a support filament: Bambu Support For PLA ----
// Picked in slot 2's selector, its list opened with a click and the row clicked.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}}},
{"tool": "click", "args": {"target": {"row": "Bambu Support For PLA"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The tool.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support For PLA", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API, begin_update(2, name) and commit().
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "Bambu Support For PLA", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"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"},
// 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"}}},
{"tool": "answer_dialog", "args": {"dialog": {"title": "Preferences"}, "button": "close"}},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.prefs3}"}},
{"tool": "get_settings", "args": {"scope": "preferences", "keys": ["auto_calculate_flush"]}, "expect": {"/items/0/value": {"eq": "disabled"}}},
// ---- Slot 2, an ordinary change to a filament with a default colour: FilAr PLA Blanco Calido ----
// Picked in slot 2's selector, its list opened with a click and the row clicked.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}}},
{"tool": "click", "args": {"target": {"row": "FilAr PLA Blanco Calido"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The tool.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API, begin_update(2, name) and commit().
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "FilAr PLA Blanco Calido", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Slot 2, an ordinary change to a filament without one: Bambu PLA Matte ----
// Picked in slot 2's selector, its list opened with a click and the row clicked.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}}},
{"tool": "click", "args": {"target": {"row": "Bambu PLA Matte"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The tool.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Matte", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API, begin_update(2, name) and commit().
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "Bambu PLA Matte", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Slot 2, a change that makes the slot hold a support filament: Bambu Support For PLA ----
// Picked in slot 2's selector, its list opened with a click and the row clicked.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}}},
{"tool": "click", "args": {"target": {"row": "Bambu Support For PLA"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The tool.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support For PLA", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API, begin_update(2, name) and commit().
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "Bambu Support For PLA", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"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"},
// 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"}}},
{"tool": "answer_dialog", "args": {"dialog": {"title": "Preferences"}, "button": "close"}},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.prefs4}"}},
{"tool": "get_settings", "args": {"scope": "preferences", "keys": ["auto_calculate_flush"]}, "expect": {"/items/0/value": {"eq": "all"}}},
// ---- The selector's value set with set_widget_value, which also reaches both handlers ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "set_widget_value", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}, "value": "FilAr PLA Blanco Calido"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- The plugin API's other forms. begin_update(2, name) without commit(): it assigns at once ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "FilAr PLA Blanco Calido"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// begin_update(2, name) naming the preset slot 2 already holds: the tab switches, nothing is assigned.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Matte", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "Bambu PLA Matte", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// begin_update(2) with no name, slot 2 holding another preset than the tab edits.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Matte", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// begin_update(2) with a setting staged and committed.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Matte", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "set": ["slow_down_layer_time", "8"], "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// update(2, key, value).
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Matte", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "update", "slot": 2, "key": "slow_down_layer_time", "value": "8"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// update(key, value): the preset the tab edits.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Matte", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "update", "key": "slow_down_layer_time", "value": "8"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes in the preset the tab edits (slot 1's): only the plugin API switches the tab ----
// The sidebar.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 2}}},
{"tool": "click", "args": {"target": {"row": "FilAr PLA Blanco Calido"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The tool without preset_changes, then with each value.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 2, "preset_changes": "transfer"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 2, "preset_changes": "discard"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API, begin_update(2, name) and commit(): the prompt answered Transfer, Discard and closed.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "FilAr PLA Blanco Calido", "commit": true}}, "await": false, "save_as": "api5"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Transfer"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api5}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "FilAr PLA Blanco Calido", "commit": true}}, "await": false, "save_as": "api6"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api6}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "FilAr PLA Blanco Calido", "commit": true}}, "await": false, "save_as": "api7"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api7}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// begin_update(2) and update(2, key, value), slot 2 holding another preset: the prompt closed.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Matte", "Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "commit": true}}, "await": false, "save_as": "api8"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api8}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Matte", "Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "update", "slot": 2, "key": "slow_down_layer_time", "value": "8"}}, "await": false, "save_as": "api9"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api9}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Refusals. A slot the project lacks ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 5}, "optional": true},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 5, "name": "FilAr PLA Blanco Calido", "commit": true}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 0, "name": "FilAr PLA Blanco Calido", "commit": true}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "update", "slot": 5, "key": "slow_down_layer_time", "value": "8"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// A name that matches nothing.
{"tool": "select_preset", "args": {"type": "filament", "name": "No Such Filament", "filament_slot": 2}, "optional": true},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "No Such Filament", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// A preset that is not compatible with the printer.
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic @BBL A1", "filament_slot": 2}, "optional": true},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "Bambu PLA Basic @BBL A1", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// A hidden preset is shown and assigned: the plugin API takes Bambu PETG HF, the tool Bambu PETG Basic
// (on a rerun without a restart both are shown already).
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 2, "name": "Bambu PETG HF @BBL X1C", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PETG Basic", "filament_slot": 2}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The filament editor's begin_update() takes a slot number first.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "name": "FilAr PLA Blanco Calido"}}},
// A mixed-colour slot (slot 4, made from slots 1 and 2 in the Add Mixed Filament dialog).
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic", "Bambu PLA Basic", "Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0,777,777,777,0,777,777,777,0"}}},
{"tool": "click", "args": {"target": {"label": "Add Mixed Filament"}}, "await": false, "save_as": "mix10"},
{"tool": "wait", "args": {"for": "dialog"}},
{"tool": "get_app_state", "expect": {"/dialogs/0/title": {"eq": "Add Mixed Filament"}}},
{"tool": "answer_dialog", "args": {"button": "OK"}},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.mix10}"}},
{"tool": "get_settings", "args": {"scope": "project", "keys": ["filament_is_mixed"]}, "expect": {"/items/0/value": {"eq": "0,0,0,1"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 4}, "optional": true},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 4, "name": "FilAr PLA Blanco Calido", "commit": true}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 4, "commit": true}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "update", "slot": 4, "key": "slow_down_layer_time", "value": "8"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "click", "args": {"target": {"label": "Remove last mixed filament"}}},
{"tool": "get_settings", "args": {"scope": "project", "keys": ["filament_is_mixed"]}, "expect": {"/items/0/value": {"eq": "0,0,0"}}},
// ---- Back to the harness's default printer with one slot ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.drop_filament_edits()"}},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1 Carbon 0.4 nozzle", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.20mm Standard @BBL X1C", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1, "preset_changes": "discard"}}
]
}
@@ -0,0 +1,312 @@
// Records the assignment of a filament preset to the only slot of a printer, where the assignment also switches
// the filament tab and its unsaved-changes prompt applies. Slot 1 is assigned through each route: a pick in its
// selector in the sidebar (its list opened with click and the row clicked), the select_preset tool, and the
// plugin API's orca.host.preset.filament.begin_update(1, name) run from run_script; for an ordinary change and
// for a change to a support filament of another type, without and with unsaved changes in the edited filament
// preset (the tool's preset_changes values and none; the prompt answered each way, counted, and read while it is
// open). Then the plugin API's forms that name no preset. Each case starts from fixtures/ops_presets.py's
// sentinels and reads what the call left once queued events have settled. The flush calculation stays "All":
// with one slot the flushing volumes matrix has no entry to recalculate. Run it on a freshly launched app with
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_assign_filament_preset_one_slot.json --out <dir>
{
"orca_replay": 1,
"name": "ops assign_filament_preset, one slot",
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_window", "args": {"size": [1920, 1040]}},
{"tool": "set_view", "args": {"tab": "prepare"}},
// Simple mode, as on a fresh datadir: the unsaved-changes prompt lists the settings the mode shows.
{"tool": "run_action", "args": {"id": "orca_command:mode_simple:orca"}},
// One slot first, so the presets below are shown and selected on the harness's default printer.
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1 Carbon 0.4 nozzle", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.20mm Standard @BBL X1C", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1, "preset_changes": "discard"}},
// The filaments the cases pick, hidden on a fresh datadir, are shown in every selector (until the app
// restarts) by selecting each once with the tool. FilAr PLA Blanco Calido has a default colour
// (#FFF8E7); the Bambu ones have none.
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 1}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Matte", "filament_slot": 1}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support For PLA", "filament_slot": 1}},
{"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"},
// 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"}}},
{"tool": "answer_dialog", "args": {"dialog": {"title": "Preferences"}, "button": "close"}},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.prefs1}"}},
{"tool": "get_settings", "args": {"scope": "preferences", "keys": ["auto_calculate_flush"]}, "expect": {"/items/0/value": {"eq": "all"}}},
// ==== FilAr PLA Blanco Calido: an ordinary change (PLA to PLA, Transfer offered) ====
// ---- No unsaved changes: the sidebar, the tool, the plugin API ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 1}}},
{"tool": "click", "args": {"target": {"row": "FilAr PLA Blanco Calido"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 1}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 1, "name": "FilAr PLA Blanco Calido", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes, the sidebar: the prompt answered Transfer, Discard, cancel ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 1}}},
{"tool": "click", "args": {"target": {"row": "FilAr PLA Blanco Calido"}}, "await": false, "save_as": "pick2"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Transfer"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.pick2}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 1}}},
{"tool": "click", "args": {"target": {"row": "FilAr PLA Blanco Calido"}}, "await": false, "save_as": "pick3"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.pick3}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 1}}},
{"tool": "click", "args": {"target": {"row": "FilAr PLA Blanco Calido"}}, "await": false, "save_as": "pick4"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.pick4}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes, the tool: preset_changes transfer and discard, then none and the prompt ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 1, "preset_changes": "transfer"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 1, "preset_changes": "discard"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 1}, "await": false, "save_as": "tool5"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Transfer"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool5}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 1}, "await": false, "save_as": "tool6"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool6}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 1}, "await": false, "save_as": "tool7"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool7}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes, the plugin API: begin_update(1, name) and commit() ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 1, "name": "FilAr PLA Blanco Calido", "commit": true}}, "await": false, "save_as": "api8"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Transfer"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api8}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 1, "name": "FilAr PLA Blanco Calido", "commit": true}}, "await": false, "save_as": "api9"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api9}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 1, "name": "FilAr PLA Blanco Calido", "commit": true}}, "await": false, "save_as": "api10"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api10}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ==== Bambu Support for ABS: a change to a support filament of another type (no Transfer) ====
// ---- No unsaved changes: the sidebar, the tool, the plugin API ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 1}}},
{"tool": "click", "args": {"target": {"row": "Bambu Support for ABS"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support for ABS", "filament_slot": 1}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 1, "name": "Bambu Support for ABS", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes, the sidebar: the prompt answered Discard, cancel ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 1}}},
{"tool": "click", "args": {"target": {"row": "Bambu Support for ABS"}}, "await": false, "save_as": "pick11"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.pick11}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "click", "args": {"target": {"class": "PlaterPresetComboBox", "index": 1}}},
{"tool": "click", "args": {"target": {"row": "Bambu Support for ABS"}}, "await": false, "save_as": "pick12"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.pick12}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes, the tool: preset_changes transfer and discard, then none and the prompt ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support for ABS", "filament_slot": 1, "preset_changes": "transfer"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support for ABS", "filament_slot": 1, "preset_changes": "discard"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support for ABS", "filament_slot": 1}, "await": false, "save_as": "tool13"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool13}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support for ABS", "filament_slot": 1}, "await": false, "save_as": "tool14"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool14}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes, the plugin API: begin_update(1, name) and commit() ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 1, "name": "Bambu Support for ABS", "commit": true}}, "await": false, "save_as": "api15"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api15}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 1, "name": "Bambu Support for ABS", "commit": true}}, "await": false, "save_as": "api16"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api16}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ==== The plugin API's forms that name no preset: the tab already edits slot 1's preset ====
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 1, "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "update", "slot": 1, "key": "slow_down_layer_time", "value": "8"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"]}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "update", "key": "slow_down_layer_time", "value": "8"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 1, "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "update", "slot": 1, "key": "slow_down_layer_time", "value": "8"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "update", "key": "slow_down_layer_time", "value": "8"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// begin_update(1, name) naming the preset the slot holds, with unsaved changes: no switch, no prompt.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_filaments(args)", "args": {"slots": ["Bambu PLA Basic"], "dirty": true}}, "expect": {"/result/dialogs": {"empty": true}, "/result/project/flush_volumes_matrix": {"eq": "0"}, "/result/filament_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "filament", "form": "begin_update", "slot": 1, "name": "Bambu PLA Basic", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Back to the harness's default state ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.drop_filament_edits()"}},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1 Carbon 0.4 nozzle", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.20mm Standard @BBL X1C", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1, "preset_changes": "discard"}}
]
}
+126
View File
@@ -0,0 +1,126 @@
// 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
// 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
// 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
// left; the run_script steps (fixtures/ops_undo.py) list the undo snapshots taken since the last one. An stl
// 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):
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_export_gcode.json --out <new dir>
{
"orca_replay": 1,
"name": "ops export_gcode",
"vars": {
"benchy": "${replay_dir}/../../../resources/handy_models/3DBenchy.drc",
"undo": "${replay_dir}/fixtures/ops_undo.py"
},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "auto_answer_dialogs", "args": {"rules": [{"match": "Spiral mode only works", "button": "yes"}]}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"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()"}},
// ---- 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": "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": "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": "list_plates"},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- A plate index the project lacks (the command takes no plate) ----
{"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": "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": "list_plates"},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "set_settings", "args": {"scope": "plate", "plate": 0, "values": {"spiral_mode": null}}},
// ---- Success, and whether the file is there when the reply comes ----
{"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": "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": "export", "args": {"format": "stl", "path": "${out_dir}/ok_cmd.gcode", "plates": 999}, "optional": true},
{"tool": "list_plates"},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- Two exports back to back: tool and tool, command and command, tool then command ----
// A modal error would show in get_app_state; answer_dialog closes it if one opened.
{"tool": "export", "args": {"format": "gcode", "path": "${out_dir}/twice_tool_1.gcode", "overwrite": true}, "await": false, "save_as": "tool_1", "optional": true},
{"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": "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": "get_app_state"},
{"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/twice_tool_2.gcode", "plates": 999}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/twice_cmd_2.gcode", "plates": 999}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/twice_mix_2.gcode", "plates": 999}, "optional": true},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- While a slice runs: slice_and_preview, then slice_all, both return at once ----
{"tool": "new_project", "args": {"discard_changes": true}},
{"tool": "open_files", "args": {"paths": ["${vars.benchy}"]}, "expect": {"/added": {"eq": 1}}},
{"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": "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": "export", "args": {"format": "gcode", "path": "${out_dir}/busy2_tool.gcode", "overwrite": true}, "optional": true},
{"tool": "get_app_state"},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "list_plates"},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/busy_cmd.gcode", "plates": 999}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/busy2_cmd.gcode", "plates": 999}, "optional": true},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
+58
View File
@@ -0,0 +1,58 @@
// 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
// 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):
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_export_model_3mf.json --out <new dir>
{
"orca_replay": 1,
"name": "ops export_model_3mf",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"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()"}},
// ---- No objects ----
{"tool": "run_action", "args": {"id": "orca_command:export_3mf:orca", "param": "${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"},
{"tool": "search_actions", "args": {"group": "Recent Projects"}},
{"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": "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": "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()"}},
{"tool": "export", "args": {"format": "3mf", "path": "${out_dir}/ok_tool.3mf", "overwrite": true}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ok_tool.3mf", "plates": 999}, "optional": true},
{"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()"}},
// ---- What the files hold: each opened as geometry into an empty project ----
{"tool": "new_project", "args": {"discard_changes": true}},
{"tool": "open_files", "args": {"paths": ["${out_dir}/empty_cmd.3mf"], "as": "geometry"}, "await": false, "save_as": "open_empty", "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.open_empty}"}, "optional": true},
{"tool": "open_files", "args": {"paths": ["${out_dir}/ok_cmd.3mf"], "as": "geometry"}, "optional": true},
{"tool": "open_files", "args": {"paths": ["${out_dir}/ok_tool.3mf"], "as": "geometry"}, "optional": true},
{"tool": "list_objects"},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
@@ -0,0 +1,89 @@
// 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
// 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):
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_export_sliced_3mf.json --out <new dir>
{
"orca_replay": 1,
"name": "ops export_sliced_3mf",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"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()"}},
// ---- 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": "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": "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": "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"},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/empty_cmd.gcode.3mf", "plates": 999}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/empty_all_cmd.gcode.3mf", "plates": 999}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ns_cmd.gcode.3mf", "plates": 999}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ns_all_cmd.gcode.3mf", "plates": 999}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ns_tool.gcode.3mf", "plates": 999}, "optional": true},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- Sliced ----
{"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": "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": "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},
{"tool": "list_plates"},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- 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": "select_objects", "args": {"none": true}},
{"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "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": "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": "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": "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": "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"},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
+59
View File
@@ -0,0 +1,59 @@
// 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
// 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):
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_export_stl.json --out <new dir>
{
"orca_replay": 1,
"name": "ops export_stl",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"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()"}},
// ---- No objects ----
{"tool": "run_action", "args": {"id": "orca_command:export_stl:orca", "param": "${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": "select_objects", "args": {"none": true}},
{"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "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": "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()"}},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ok_tool.stl", "overwrite": true}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ok_tool.stl", "plates": 999}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- What the files hold ----
{"tool": "new_project", "args": {"discard_changes": true}},
{"tool": "open_files", "args": {"paths": ["${out_dir}/empty_cmd.stl"]}, "await": false, "save_as": "open_empty", "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.open_empty}"}, "optional": true},
{"tool": "open_files", "args": {"paths": ["${out_dir}/ok_cmd.stl"]}, "optional": true},
{"tool": "open_files", "args": {"paths": ["${out_dir}/ok_tool.stl"]}, "optional": true},
{"tool": "list_objects"},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
+178
View File
@@ -0,0 +1,178 @@
// 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'
// 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
// 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>
{
"orca_replay": 1,
"name": "ops import_models",
"vars": {
"stl": "${replay_dir}/../../../tests/data/test_stl/ASCII/20mmbox-LF.stl",
"png": "${replay_dir}/fixtures/heightmap.png",
"preset_json": "${replay_dir}/fixtures/mcp_import_pla.json",
"undo": "${replay_dir}/fixtures/ops_undo.py"
},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"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": "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"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "search_actions", "args": {"group": "Recent Projects"}},
{"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": "get_app_state"},
{"tool": "list_objects"},
{"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:undo:orca"}},
{"tool": "list_objects"},
// ---- the tool ----
{"tool": "new_project", "args": {"discard_changes": true}},
{"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": ["${vars.stl}"]}, "optional": true},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"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:undo:orca"}},
{"tool": "list_objects"},
// ---- 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": "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": "get_app_state"},
{"tool": "list_objects"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"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"},
// ---- the tool ----
{"tool": "new_project", "args": {"discard_changes": true}},
{"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "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()"}},
{"tool": "open_files", "args": {"paths": ["${vars.stl}"]}, "optional": true},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"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"},
// ---- 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": "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": "get_app_state"},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.cmd3mf}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"tool": "get_settings", "args": {"scope": "filament", "compare": ":saved"}},
{"tool": "get_settings", "args": {"scope": "printer", "compare": ":saved"}},
{"tool": "get_settings", "args": {"keys": ["wall_loops", "top_shell_layers"]}},
{"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:undo:orca"}},
{"tool": "list_objects"},
{"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": "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()"}},
{"tool": "open_files", "args": {"paths": ["${out_dir}/src_project.3mf"], "as": "geometry"}, "await": false, "save_as": "tool3mf", "optional": true},
{"tool": "get_app_state"},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool3mf}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"tool": "get_settings", "args": {"scope": "filament", "compare": ":saved"}},
{"tool": "get_settings", "args": {"scope": "printer", "compare": ":saved"}},
{"tool": "get_settings", "args": {"keys": ["wall_loops", "top_shell_layers"]}},
{"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:undo:orca"}},
{"tool": "list_objects"},
// ---- 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": "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": "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": "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.cmdpng}"}, "optional": true},
{"tool": "open_files", "args": {"paths": ["${vars.png}"]}, "await": false, "save_as": "toolpng", "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.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": "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.cmdjson}"}, "optional": true},
{"tool": "open_files", "args": {"paths": ["${vars.preset_json}"]}, "await": false, "save_as": "tooljson", "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.tooljson}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"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"},
// ---- File > Import: the multi-select picker takes no path, so the rule cancels it ----
{"tool": "new_project", "args": {"discard_changes": true}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "auto_answer_dialogs", "args": {"rules": [{"match": "Choose one or more files", "button": "ok", "path": "${vars.stl}"}]}},
{"tool": "run_action", "args": {"id": "orca_command:import_file:orca"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.log_lines('multi-select', 1)"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}
]
}
+84
View File
@@ -0,0 +1,84 @@
// Records what the import_configs command (run_action with a path param) 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
// 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
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_import_presets.json --out <dir>
{
"orca_replay": 1,
"name": "ops import_presets",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py",
"pla": "${replay_dir}/fixtures/mcp_import_pla.json",
"zip": "${out_dir}/Filament presets.zip"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "auto_answer_dialogs", "args": {"rules": [{"match": "already exists", "button": "yes"}]}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1}},
{"tool": "delete_preset", "args": {"type": "filament", "name": "MCP Import PLA"}, "optional": true},
{"tool": "delete_preset", "args": {"type": "filament", "name": "MCP Ops Export PLA"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"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": "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": "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()"}},
// ---- A filament exported with the Export Preset Bundle dialog ----
{"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": "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"},
{"tool": "get_app_state"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "Info"}, "button": "ok"}},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.export_ok}"}},
{"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": "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": "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": "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},
{"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": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- The presets it made go ----
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1}},
{"tool": "delete_preset", "args": {"type": "filament", "name": "MCP Import PLA"}, "optional": true},
{"tool": "delete_preset", "args": {"type": "filament", "name": "MCP Ops Export PLA"}, "optional": true},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}
]
}
+112
View File
@@ -0,0 +1,112 @@
// 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
// 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
// NewProject event on both routes, which no replay can observe without a plugin. Every call it records is
// optional. Run it with
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_new_project.json --out <dir>
{
"orca_replay": 1,
"name": "ops new_project",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
// ---- A clean project: the command, then the tool ----
{"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": "run_action", "args": {"id": "orca_command:new_project:orca"}, "await": false, "save_as": "clean_cmd", "optional": true},
{"tool": "get_app_state"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "- Save"}, "button": "no"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.clean_cmd}"}, "optional": true},
{"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": "set_view", "args": {"tab": "home"}},
{"tool": "new_project", "args": {}, "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": "set_view", "args": {"tab": "home"}},
{"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:new_project:orca"}, "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"},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.dirty_cmd}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"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": "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": "get_app_state"},
{"tool": "new_project", "args": {"discard_changes": true}, "optional": true},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- Unsaved preset changes, no objects: the command, answered Discard ----
{"tool": "set_settings", "args": {"values": {"top_shell_layers": 7}}},
{"tool": "set_view", "args": {"tab": "home"}},
{"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:new_project:orca"}, "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"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "unsaved changes"}, "button": "Discard"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.presets_cmd}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- answered Transfer ----
{"tool": "set_settings", "args": {"values": {"top_shell_layers": 7}}},
{"tool": "set_view", "args": {"tab": "home"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_action", "args": {"id": "orca_command:new_project:orca"}, "await": false, "save_as": "presets_cmd2", "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": "Transfer"}, "optional": true},
{"tool": "answer_dialog", "args": {"dialog": {"title": "unsaved changes"}, "button": "Discard"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.presets_cmd2}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- the tool: no discard_changes, then preset_changes keep (default) and discard ----
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_settings", "args": {"values": {"top_shell_layers": 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": "get_app_state"},
{"tool": "new_project", "args": {"discard_changes": true}, "optional": true},
{"tool": "get_app_state"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"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": {"discard_changes": true, "preset_changes": "discard"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}
]
}
+146
View File
@@ -0,0 +1,146 @@
// 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
// (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
// saving the project, Discard for the presets. After each it reads the objects, the project's name and file, the
// presets and their unsaved keys, the recent projects and the tab, and the undo snapshots taken since the last
// read (fixtures/ops_undo.py). Every call it records is optional. Run it with
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_open_project.json --out <dir>
{
"orca_replay": 1,
"name": "ops open_project",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"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": "set_settings", "args": {"values": {"wall_loops": 5}}},
{"tool": "save_project", "args": {"path": "${out_dir}/open_src.3mf", "overwrite": true}},
// ---- A clean project: the command ----
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_view", "args": {"tab": "home"}},
{"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": "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},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.clean_cmd}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"tool": "search_actions", "args": {"group": "Recent Projects"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- the tool ----
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_view", "args": {"tab": "home"}},
{"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": "open_files", "args": {"paths": ["${out_dir}/open_src.3mf"]}, "await": false, "save_as": "clean_tool", "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},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.clean_tool}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"tool": "search_actions", "args": {"group": "Recent Projects"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- 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": "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": "get_app_state"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "- Save"}, "button": "no"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "unsaved changes"}, "button": "Discard"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.dirty_cmd}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"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": "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},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"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"], "discard_changes": true}, "await": false, "save_as": "dirty_tool", "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},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.dirty_tool}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- Unsaved preset changes (top_shell_layers 7) on an empty project: the command ----
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_settings", "args": {"values": {"top_shell_layers": 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": "get_app_state"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "- Save"}, "button": "no"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "unsaved changes"}, "button": "Discard"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.presets_cmd}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"tool": "get_settings", "args": {"keys": ["wall_loops", "top_shell_layers"]}},
{"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": "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()"}},
{"tool": "open_files", "args": {"paths": ["${out_dir}/open_src.3mf"]}, "await": false, "save_as": "presets_tool", "optional": true},
{"tool": "get_app_state"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "- Save"}, "button": "no"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "unsaved changes"}, "button": "Discard"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.presets_tool}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "get_settings", "args": {"keys": ["wall_loops", "top_shell_layers"]}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_settings", "args": {"values": {"top_shell_layers": 7}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "open_files", "args": {"paths": ["${out_dir}/open_src.3mf"], "discard_changes": true}, "await": false, "save_as": "presets_tool2", "optional": true},
{"tool": "get_app_state"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "- Save"}, "button": "no"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "answer_dialog", "args": {"dialog": {"title": "unsaved changes"}, "button": "Discard"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.presets_tool2}"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_objects"},
{"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}},
{"tool": "get_settings", "args": {"keys": ["wall_loops", "top_shell_layers"]}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}
]
}
+71
View File
@@ -0,0 +1,71 @@
// 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
// 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):
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_save_project_as.json --out <new dir>
{
"orca_replay": 1,
"name": "ops save_project_as",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_view", "args": {"tab": "prepare"}},
// ---- 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": "get_app_state"},
{"tool": "save_project", "args": {"path": "${out_dir}/empty_tool.3mf", "overwrite": true}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- 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": "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": "export", "args": {"format": "stl", "path": "${out_dir}/cmd.3mf", "plates": 999}, "optional": true},
{"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": "transform", "args": {"object": 0, "translate": [5, 0, 0]}},
{"tool": "save_project", "args": {"path": "${out_dir}/tool.3mf", "overwrite": true}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/tool.3mf", "plates": 999}, "optional": true},
{"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()"}},
// ---- 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": "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()"}},
{"tool": "save_project", "args": {"path": "${out_dir}/tool.gcode.3mf", "overwrite": true}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/tool.gcode.3mf", "plates": 999}, "optional": true},
{"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": "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": "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()"}},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
+92
View File
@@ -0,0 +1,92 @@
// 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
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_select_plate.json --out <dir>
{
"orca_replay": 1,
"name": "ops select_plate",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"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:plate_add:orca"}},
{"tool": "run_action", "args": {"id": "orca_command:plate_add:orca"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "list_plates", "expect": {"/total": {"eq": 3}}},
{"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},
{"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": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "0"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "3"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "7"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "-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": "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": "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"}, "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": "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},
{"tool": "slice", "args": {"plates": -1}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/noplate.stl", "plates": 5, "overwrite": true}, "optional": true},
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/noplate.stl", "plates": -1, "overwrite": true}, "optional": true},
{"tool": "arrange", "args": {"plates": 5}, "optional": true},
{"tool": "arrange", "args": {"plates": -1}, "optional": true},
{"tool": "set_settings", "args": {"scope": "plate", "plate": 5, "values": {"name": "x"}}, "optional": true},
{"tool": "get_settings", "args": {"scope": "plate", "plate": 5, "keys": ["name"]}, "optional": true},
{"tool": "list_objects", "args": {"plate": 5}, "optional": true},
{"tool": "transform", "args": {"object": 0, "plate": 5}, "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 has: which one is current afterwards ----
{"tool": "export", "args": {"format": "stl", "path": "${out_dir}/plate2.stl", "plates": 2, "overwrite": true}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "set_settings", "args": {"scope": "plate", "plate": 1, "values": {"name": "One"}}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "get_settings", "args": {"scope": "plate", "plate": 2, "keys": ["name"]}, "optional": true},
{"tool": "get_app_state"},
{"tool": "slice", "args": {"plates": 0}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "arrange", "args": {"plates": 2}, "optional": true},
{"tool": "arrange", "args": {"plates": 0}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "transform", "args": {"object": 0, "plate": 2}, "optional": true},
{"tool": "get_app_state"},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
+306
View File
@@ -0,0 +1,306 @@
// Records the selection of a printer or process preset, the one its tab then edits, through the select_preset
// tool and the plugin API's orca.host.preset.process / .printer begin_update(name) run from run_script: an
// ordinary selection, unsaved changes (the tool's preset_changes values and none, the prompt answered each way
// for both routes and read while it is open), the preset already edited, a hidden printer (each route shows
// one) and the refusals. Each case starts from fixtures/ops_presets.py's arrange_presets()
// and reads what the call left once queued events have settled (the preset each tab edits, slots, dialogs, undo
// snapshots). Refused calls are optional. Run it on a freshly launched app (a hidden preset stays shown until a
// restart) with
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_select_preset.json --out <dir>
{
"orca_replay": 1,
"name": "ops select_preset",
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_window", "args": {"size": [1920, 1040]}},
{"tool": "set_view", "args": {"tab": "prepare"}},
// Simple mode, as on a fresh datadir: the unsaved-changes prompt lists the settings the mode shows.
{"tool": "run_action", "args": {"id": "orca_command:mode_simple:orca"}},
// One slot first, so the presets below are shown and selected on the harness's default printer.
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1 Carbon 0.4 nozzle", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.20mm Standard @BBL X1C", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1, "preset_changes": "discard"}},
// The filaments the cases pick, hidden on a fresh datadir, are shown in every selector (until the app
// restarts) by selecting each once with the tool. FilAr PLA Blanco Calido has a default colour
// (#FFF8E7); the Bambu ones have none.
{"tool": "select_preset", "args": {"type": "filament", "name": "FilAr PLA Blanco Calido", "filament_slot": 1}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Matte", "filament_slot": 1}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support For PLA", "filament_slot": 1}},
{"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}}},
// ==== A process preset: 0.20mm Standard to 0.16mm Optimal ====
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.16mm Optimal @BBL X1C"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "begin_update", "name": "0.16mm Optimal @BBL X1C", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes in the process: the tool's preset_changes, then none and the prompt ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.16mm Optimal @BBL X1C", "preset_changes": "transfer"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.16mm Optimal @BBL X1C", "preset_changes": "discard"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.16mm Optimal @BBL X1C"}, "await": false, "save_as": "tool1"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Transfer"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool1}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.16mm Optimal @BBL X1C"}, "await": false, "save_as": "tool2"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool2}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.16mm Optimal @BBL X1C"}, "await": false, "save_as": "tool3"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool3}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes, the plugin API: the prompt answered each way ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "begin_update", "name": "0.16mm Optimal @BBL X1C", "commit": true}}, "await": false, "save_as": "api4"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Transfer"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api4}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "begin_update", "name": "0.16mm Optimal @BBL X1C", "commit": true}}, "await": false, "save_as": "api5"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api5}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "begin_update", "name": "0.16mm Optimal @BBL X1C", "commit": true}}, "await": false, "save_as": "api6"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api6}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- The preset the tab already edits, with unsaved changes: the tool selects it again, the plugin
// API binds it ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.20mm Standard @BBL X1C"}, "await": false, "save_as": "tool7"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool7}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "begin_update", "name": "0.20mm Standard @BBL X1C", "commit": true}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "begin_update", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Refusals: no such name, a name the selector does not show (an alias), an incompatible preset,
// and the slot form on the process editor ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "select_preset", "args": {"type": "process", "name": "No Such Process"}, "optional": true},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "begin_update", "name": "No Such Process", "commit": true}}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.16mm Optimal"}, "optional": true},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "begin_update", "name": "0.16mm Optimal", "commit": true}}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.20mm Standard @BBL A1"}, "optional": true},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "begin_update", "name": "0.20mm Standard @BBL A1", "commit": true}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "begin_update", "slot": 1, "name": "0.16mm Optimal @BBL X1C"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "process", "form": "update", "slot": 1, "key": "wall_loops", "value": "3"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ==== A printer preset: X1 Carbon to X1E, both 0.4 nozzle (the X1C's filament and process suit both) ====
// A hidden printer is shown and selected: the plugin API takes the X1, the tool the X1E (on a rerun
// without a restart both are shown already).
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "printer", "form": "begin_update", "name": "Bambu Lab X1 0.4 nozzle", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1E 0.4 nozzle"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- No unsaved changes ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1E 0.4 nozzle"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "printer", "form": "begin_update", "name": "Bambu Lab X1E 0.4 nozzle", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes in the printer: Transfer is not offered ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "printer"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": " \\(modified\\)$"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1E 0.4 nozzle", "preset_changes": "transfer"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "printer"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": " \\(modified\\)$"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1E 0.4 nozzle", "preset_changes": "discard"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "printer"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": " \\(modified\\)$"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1E 0.4 nozzle"}, "await": false, "save_as": "tool8"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool8}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "printer"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": " \\(modified\\)$"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1E 0.4 nozzle"}, "await": false, "save_as": "tool9"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool9}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "printer"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": " \\(modified\\)$"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "printer", "form": "begin_update", "name": "Bambu Lab X1E 0.4 nozzle", "commit": true}}, "await": false, "save_as": "api10"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Discard"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api10}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "printer"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": " \\(modified\\)$"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "printer", "form": "begin_update", "name": "Bambu Lab X1E 0.4 nozzle", "commit": true}}, "await": false, "save_as": "api11"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api11}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Unsaved changes in the process, which suits the new printer: the printer switch asks about them ----
// The tool with preset_changes transfer (answered Transfer if the prompt opens), then none: Transfer, closed.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1E 0.4 nozzle", "preset_changes": "transfer"}, "await": false, "save_as": "tool12"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Transfer"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool12}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1E 0.4 nozzle"}, "await": false, "save_as": "tool13"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Transfer"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool13}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1E 0.4 nozzle"}, "await": false, "save_as": "tool14"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.tool14}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// The plugin API: Transfer, closed.
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "printer", "form": "begin_update", "name": "Bambu Lab X1E 0.4 nozzle", "commit": true}}, "await": false, "save_as": "api15"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "Transfer"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api15}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C", "dirty": "process"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": " \\(modified\\)$"}}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "printer", "form": "begin_update", "name": "Bambu Lab X1E 0.4 nozzle", "commit": true}}, "await": false, "save_as": "api16"},
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 10}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
// A second prompt, if one opens, is counted here and answered so the call can end.
{"tool": "wait", "args": {"for": "dialog", "timeout_s": 3}},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.api16}", "timeout_s": 30}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Refusals: no such name, and a name the tool's resolution and the plugin API's both lack ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.arrange_presets(args)", "args": {"printer": "Bambu Lab X1 Carbon 0.4 nozzle", "process": "0.20mm Standard @BBL X1C"}}, "expect": {"/result/dialogs": {"empty": true}, "/result/printer_tab": {"regex": "^Bambu Lab X1 Carbon 0.4 nozzle"}, "/result/process_tab": {"regex": "^0.20mm Standard @BBL X1C"}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "No Such Printer"}, "optional": true},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "printer", "form": "begin_update", "name": "No Such Printer", "commit": true}}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1 Carbon"}, "optional": true},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.preset_api(args)", "args": {"editor": "printer", "form": "begin_update", "name": "Bambu Lab X1 Carbon", "commit": true}}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}},
// ---- Back to the harness's default state ----
{"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.drop_filament_edits()"}},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca"}, "optional": true},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "printer", "name": "Bambu Lab X1 Carbon 0.4 nozzle", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "process", "name": "0.20mm Standard @BBL X1C", "preset_changes": "discard"}},
{"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1, "preset_changes": "discard"}}
]
}
@@ -0,0 +1,52 @@
// Records the refusals of the send_gcode command (run_action), and nothing else: it never sets a print host, so
// nothing is ever sent. A Bambu network printer (the harness's X1 Carbon as it starts, then with
// bbl_use_printhost off) with no objects, on a plate not sliced and on a sliced one; then the same printer set
// to print through a host (bbl_use_printhost on, OctoPrint) with no host address, sliced, not sliced and with no
// objects. After each it reads the dialogs and uploads (get_app_state) and the undo snapshots taken since the
// last read (fixtures/ops_undo.py). It ends by discarding the printer changes. Every call it records is
// optional. Run it with
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_send_gcode_to_host.json --out <dir>
{
"orca_replay": 1,
"name": "ops send_gcode_to_host",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "get_settings", "args": {"scope": "printer", "keys": ["bbl_use_printhost", "host_type", "print_host"]}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- 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": "wait", "args": {"for": "idle"}},
{"tool": "run_action", "args": {"id": "orca_command:send_gcode:orca"}, "optional": true},
{"tool": "slice", "expect": {"/plates/0/outcome": {"eq": "ok"}}},
{"tool": "run_action", "args": {"id": "orca_command:send_gcode:orca"}, "optional": true},
{"tool": "set_settings", "args": {"scope": "printer", "values": {"bbl_use_printhost": false}}},
{"tool": "run_action", "args": {"id": "orca_command:send_gcode:orca"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- Through a print host with no address: sliced, not sliced, no objects ----
{"tool": "set_settings", "args": {"scope": "printer", "values": {"bbl_use_printhost": true, "host_type": "octoprint", "print_host": "", "use_3mf": false}}},
{"tool": "slice", "expect": {"/plates/0/outcome": {"eq": "ok"}}},
{"tool": "list_plates"},
{"tool": "run_action", "args": {"id": "orca_command:send_gcode:orca"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "transform", "args": {"object": 0, "translate": [5, 0, 0]}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "list_plates"},
{"tool": "run_action", "args": {"id": "orca_command:send_gcode:orca"}, "optional": true},
{"tool": "new_project", "args": {"discard_changes": true}},
{"tool": "run_action", "args": {"id": "orca_command:send_gcode:orca"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "get_settings", "args": {"scope": "printer", "keys": ["bbl_use_printhost", "host_type", "print_host"]}}
]
}
+118
View File
@@ -0,0 +1,118 @@
// 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
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_set_instance_count.json --out <dir>
{
"orca_replay": 1,
"name": "ops set_instance_count",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"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": "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": "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": "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": "list_objects"},
{"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "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": "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": "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": "list_objects"},
{"tool": "select_objects", "args": {"objects": [0]}},
{"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "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": "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": "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": "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"}, "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 ----
{"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"},
{"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true},
{"tool": "wait", "args": {"for": "job", "job": "${jobs.dialog}"}, "optional": true},
{"tool": "list_objects"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- 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": "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}},
{"tool": "click", "args": {"target": {"imgui": "Add connectors"}}},
{"tool": "mouse_gesture", "args": {"at": {"object": 0, "spot": "top"}, "check": "point"}},
{"tool": "click", "args": {"target": {"imgui": "Confirm connectors"}}},
{"tool": "click", "args": {"target": {"imgui": "Perform cut"}}},
{"tool": "wait", "args": {"for": "idle"}},
{"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": "list_objects"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
+80
View File
@@ -0,0 +1,80 @@
// Records how a plate is locked through its three routes: the plate_toggle_lock command run with run_action (the
// current plate), set_settings' plate scope with locked, and a click on the plate's lock icon ({plate_icon:
// "lock", plate}). Each is run twice on plate 0, then on plate 1 while plate 0 is current; the tool also with a
// plate the project lacks. After each it reads the lock state and the current plate (list_plates) and the undo
// snapshots taken since the last read (fixtures/ops_undo.py), and last it locks through each route and runs undo
// once, to show that the lock is one undo step. Every call it records is optional. Run it with
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_set_plate_locked.json --out <dir>
{
"orca_replay": 1,
"name": "ops set_plate_locked",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"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:plate_add:orca"}},
{"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "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()"}},
// ---- The command, twice on plate 0 ----
{"tool": "run_action", "args": {"id": "orca_command:plate_toggle_lock:orca"}, "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_toggle_lock:orca"}, "optional": true},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- The tool, locked true twice, then false, then a plate the project lacks ----
{"tool": "set_settings", "args": {"scope": "plate", "plate": 0, "values": {"locked": true}}, "optional": true},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "set_settings", "args": {"scope": "plate", "plate": 0, "values": {"locked": true}}, "optional": true},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "set_settings", "args": {"scope": "plate", "plate": 0, "values": {"locked": false}}, "optional": true},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "set_settings", "args": {"scope": "plate", "plate": 5, "values": {"locked": true}}, "optional": true},
{"tool": "list_plates"},
// ---- The lock icon, twice on plate 0 ----
{"tool": "click", "args": {"target": {"plate_icon": "lock", "plate": 0}}, "optional": true},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "click", "args": {"target": {"plate_icon": "lock", "plate": 0}}, "optional": true},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- Plate 1 while plate 0 is current: the tool and the icon (the command has no plate) ----
{"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": "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_toggle_lock:orca"}, "optional": true},
{"tool": "list_plates"},
{"tool": "run_action", "args": {"id": "orca_command:undo:orca"}},
{"tool": "list_plates"},
{"tool": "set_settings", "args": {"scope": "plate", "plate": 0, "values": {"locked": true}}, "optional": true},
{"tool": "list_plates"},
{"tool": "run_action", "args": {"id": "orca_command:undo:orca"}},
{"tool": "list_plates"},
{"tool": "click", "args": {"target": {"plate_icon": "lock", "plate": 0}}, "optional": true},
{"tool": "list_plates"},
{"tool": "run_action", "args": {"id": "orca_command:undo:orca"}},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
+121
View File
@@ -0,0 +1,121 @@
// 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
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_show_layer_range.json --out <dir>
{
"orca_replay": 1,
"name": "ops show_layer_range",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "auto_answer_dialogs", "args": {"rules": [{"match": "Spiral mode only works", "button": "yes"}]}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"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": "slice", "expect": {"/plates/0/layers": {"eq": 100}}},
{"tool": "new_project", "args": {"discard_changes": true}},
{"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()"}},
// ---- No objects ----
{"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "50"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "set_view", "args": {"layer": 10}, "optional": true},
{"tool": "set_view", "args": {"layer_range": [2, 5]}, "optional": true},
{"tool": "set_view", "args": {"layer_z": 5.0}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- 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": "select_objects", "args": {"none": true}},
{"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "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": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_plates"},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "set_view", "args": {"layer": 10}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "set_view", "args": {"layer_range": [2, 5]}, "optional": true},
{"tool": "set_view", "args": {"layer_z": 5.0}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- 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": "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": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "50"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "100"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "25.5"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "150"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "-5"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "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"}, "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": "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": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- A sliced plate: the tool ----
{"tool": "set_view", "args": {"layer": 1}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"layer": 50}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"layer": 100}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"layer": 9999}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"layer_range": [5, 20]}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"layer_range": [30, 10]}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"layer_range": [5]}, "optional": true},
{"tool": "set_view", "args": {"layer_z": 5.0}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"layer_z": 999}, "optional": true},
{"tool": "set_view", "args": {"layer": 3, "layer_z": 5.0}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "set_view", "args": {"layer": 40}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
+93
View File
@@ -0,0 +1,93 @@
// Records what an arrange does through its two routes, the obj_arrange command run with run_action and the
// arrange tool (every plate, and one plate by index): with no objects, with two cubes on one spot, in the
// assemble view, with the Move gizmo open, and with the plate locked. After each it reads the objects' offsets,
// the tab, canvas and gizmo, and the undo snapshots taken since the last read (fixtures/ops_undo.py), and once
// runs undo to show what the arrange's step takes back. An arrange running while another call comes needs two
// clients. Every call it records is optional. Run it with
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_start_arrange.json --out <dir>
{
"orca_replay": 1,
"name": "ops start_arrange",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"tool": "set_window", "args": {"size": [1600, 1000]}},
{"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()"}},
// ---- No objects ----
{"tool": "run_action", "args": {"id": "orca_command:obj_arrange:orca"}, "optional": true},
{"tool": "arrange", "args": {}, "optional": true},
{"tool": "arrange", "args": {"plates": 0}, "optional": true},
{"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": "select_objects", "args": {"none": true}},
{"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "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}}},
{"tool": "set_view", "args": {"tab": "preview"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "run_action", "args": {"id": "orca_command:obj_arrange:orca"}, "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": "set_view", "args": {"tab": "preview"}},
{"tool": "arrange", "args": {}, "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": "arrange", "args": {"plates": 0}, "optional": true},
{"tool": "list_objects"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- In the assemble view ----
{"tool": "set_view", "args": {"canvas": "assemble"}},
{"tool": "get_app_state"},
{"tool": "run_action", "args": {"id": "orca_command:obj_arrange:orca"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"canvas": "assemble"}},
{"tool": "arrange", "args": {}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"canvas": "3d"}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- With the Move gizmo open ----
{"tool": "select_objects", "args": {"objects": [0]}},
{"tool": "click", "args": {"target": {"gizmo": "Move"}}, "expect": {"/active": {"eq": true}}},
{"tool": "run_action", "args": {"id": "orca_command:obj_arrange:orca"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "arrange", "args": {}, "optional": true},
{"tool": "get_app_state"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "get_app_state"},
{"tool": "click", "args": {"target": {"gizmo": "Move"}}, "optional": true},
{"tool": "get_app_state"},
// ---- With the plate locked (the cubes back on one spot) ----
{"tool": "transform", "args": {"object": 0, "translate": [128, 128, 10], "mode": "absolute"}},
{"tool": "transform", "args": {"object": 1, "translate": [128, 128, 10], "mode": "absolute"}},
{"tool": "run_action", "args": {"id": "orca_command:plate_toggle_lock:orca"}},
{"tool": "list_plates", "expect": {"/items/0/locked": {"eq": true}}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "run_action", "args": {"id": "orca_command:obj_arrange:orca"}, "optional": true},
{"tool": "list_objects"},
{"tool": "arrange", "args": {}, "optional": true},
{"tool": "list_objects"},
{"tool": "arrange", "args": {"plates": 0}, "optional": true},
{"tool": "list_objects"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "run_action", "args": {"id": "orca_command:plate_toggle_lock:orca"}},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
+122
View File
@@ -0,0 +1,122 @@
// Records what starting a slice does through its routes, the slice_and_preview and slice_all commands run with
// run_action (they return at once) and the slice tool (the current plate, all, an index): with no objects, on
// one plate, on two plates, and with objects that fail validation (spiral vase on a plate with two objects).
// Each call starts from the Prepare tab; after it, the replay waits for idle and reads the plates' slice state,
// the tab, the notifications and the undo snapshots taken since the last read (fixtures/ops_undo.py). Every call
// it records is optional. Run it with
// tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_start_slice.json --out <dir>
{
"orca_replay": 1,
"name": "ops start_slice",
"vars": {"undo": "${replay_dir}/fixtures/ops_undo.py"},
"steps": [
{"tool": "wait", "args": {"for": "ready"}},
{"tool": "auto_answer_dialogs", "args": {"rules": [{"match": "Spiral mode only works", "button": "yes"}]}},
{"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}},
{"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()"}},
// ---- No objects ----
{"tool": "run_action", "args": {"id": "orca_command:slice_and_preview:orca"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_plates"},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "run_action", "args": {"id": "orca_command:slice_all:orca"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "slice", "args": {}, "optional": true},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "slice", "args": {"plates": "all"}, "optional": true},
{"tool": "get_app_state"},
{"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": "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()"}},
{"tool": "run_action", "args": {"id": "orca_command:slice_and_preview:orca"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "transform", "args": {"object": 0, "translate": [5, 0, 0]}},
{"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()"}},
{"tool": "slice", "args": {}, "optional": true},
{"tool": "get_app_state"},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- 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": "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": "set_view", "args": {"tab": "prepare"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "list_plates", "expect": {"/total": {"eq": 2}, "/items/1/objects": {"eq": 1}}},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "run_action", "args": {"id": "orca_command:slice_and_preview:orca"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_plates"},
{"tool": "transform", "args": {"object": 0, "translate": [5, 0, 0]}},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "run_action", "args": {"id": "orca_command:slice_all:orca"}, "optional": true},
{"tool": "get_app_state"},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "transform", "args": {"object": 0, "translate": [5, 0, 0]}},
{"tool": "transform", "args": {"object": 1, "translate": [5, 0, 0]}},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "slice", "args": {"plates": "all"}, "optional": true},
{"tool": "get_app_state"},
{"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": "wait", "args": {"for": "idle"}},
{"tool": "slice", "args": {"plates": 1}, "optional": true},
{"tool": "get_app_state"},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
// ---- 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": "select_objects", "args": {"none": true}},
{"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}},
{"tool": "arrange", "args": {}},
{"tool": "set_settings", "args": {"scope": "plate", "plate": 0, "values": {"spiral_mode": true}}},
{"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()"}},
{"tool": "run_action", "args": {"id": "orca_command:slice_and_preview:orca"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "list_plates"},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "run_action", "args": {"id": "orca_command:slice_all:orca"}, "optional": true},
{"tool": "wait", "args": {"for": "idle"}},
{"tool": "get_app_state"},
{"tool": "set_view", "args": {"tab": "prepare"}},
{"tool": "slice", "args": {}, "optional": true},
{"tool": "get_app_state"},
{"tool": "list_plates"},
{"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}},
{"tool": "new_project", "args": {"discard_changes": true}}
]
}
@@ -15,7 +15,8 @@ Each script writes what happened to out_<name>.json in the plugin's storage fold
"thread" calls it from a thread the script starts, "rule" registers an auto-answer rule, "export" asks for
export_replay, which a plugin is refused, and "handle" opens a progress dialog and keeps its handle in
HANDLE, for a script to find and use. The plugin also offers the operation "measure", which doubles its
argument a.
argument a, and its first capability adds a line to new_projects.txt in the storage folder for each
NewProject event it is sent.
"""
import json
import os
@@ -60,6 +61,11 @@ class CallTool(orca.script.ScriptPluginCapabilityBase):
def execute(self):
return record("call", lambda: orca.host.tools.call("get_app_state").get("ready"))
def on_lifecycle_event(self, event, ctx):
if event == orca.LifecycleEvent.NewProject:
with open(os.path.join(orca.host.plugin.storage(), "new_projects.txt"), "a", encoding="utf-8") as f:
f.write("new\n")
class CallFromThread(orca.script.ScriptPluginCapabilityBase):
def get_name(self):