From 6cd2ce1a2ea3202297feab35d739d67156cfcae5 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Thu, 19 Nov 2026 13:49:20 +0800 Subject: [PATCH] Check every area of the MCP sweep with Python tests that read each step back The sweep's objects, presets, filaments, settings, project files, slicing, gizmos and GUI tools are tested by Python tests that compare the app's state after every step with the values their entries write out, in place of the replays, and the existing tests' checks that could not fail now can. The calls these tests found wrong now behave as described: moving one instance no longer sinks the others, a toolpath export writes the layers shown, an auto-answered dialog no longer reports its call blocked, and a web dialog that has just opened takes requests. --- docs/HLSD/mcp-server.md | 75 +- src/slic3r/GUI/GLCanvas3D.cpp | 6 +- src/slic3r/GUI/GLCanvas3D.hpp | 5 +- src/slic3r/GUI/Mcp/AutomationRuntime.cpp | 6 +- src/slic3r/GUI/Mcp/McpCore.cpp | 12 + src/slic3r/GUI/Mcp/McpToolsProject.cpp | 20 +- src/slic3r/GUI/Mcp/McpToolsScene.cpp | 8 +- src/slic3r/GUI/Mcp/McpToolsUi.cpp | 3 +- src/slic3r/GUI/Mcp/UiInspector.cpp | 8 +- src/slic3r/GUI/Mcp/UiInvoker.cpp | 8 +- src/slic3r/GUI/Mcp/UiInvoker.hpp | 2 +- src/slic3r/GUI/Mcp/WebPages.cpp | 47 +- src/slic3r/GUI/Operations/ExportOps.cpp | 94 +- src/slic3r/GUI/Operations/ExportOps.hpp | 4 +- src/slic3r/GUI/Operations/ObjectOps.cpp | 11 +- src/slic3r/GUI/Operations/ObjectOps.hpp | 13 +- src/slic3r/GUI/Operations/PlateOps.cpp | 14 +- src/slic3r/GUI/Operations/PlateOps.hpp | 8 +- src/slic3r/GUI/Operations/PresetOps.cpp | 4 +- src/slic3r/GUI/Operations/PresetOps.hpp | 4 +- src/slic3r/GUI/Operations/ProjectOps.cpp | 4 + src/slic3r/GUI/Operations/ProjectOps.hpp | 3 +- src/slic3r/GUI/Plater.cpp | 9 + src/slic3r/GUI/Plater.hpp | 3 + tests/automation/test_mcp_core.cpp | 22 + tests/data/command_catalog.json | 6 +- tools/mcp/README.md | 256 ++-- tools/mcp/TESTS.md | 111 +- tools/mcp/checks.py | 260 ++++ tools/mcp/run_sweep.py | 10 +- tools/mcp/sweep.json | 42 +- tools/mcp/test-entries/commands.md | 9 +- tools/mcp/test-entries/filaments_settings.md | 121 +- tools/mcp/test-entries/files.md | 86 +- tools/mcp/test-entries/gizmos.md | 114 +- tools/mcp/test-entries/gui_tools.md | 192 +-- tools/mcp/test-entries/objects.md | 254 +--- tools/mcp/test-entries/presets.md | 149 +- tools/mcp/test-entries/runtime.md | 2 +- tools/mcp/test-entries/slice_preview.md | 133 +- tools/mcp/test-entries/windows_web.md | 5 +- tools/mcp/test_action_replay_hidden.py | 53 +- tools/mcp/test_additions_refusals.py | 11 +- tools/mcp/test_calibration.py | 588 ++++++++ tools/mcp/test_call_forms.py | 338 +++++ tools/mcp/test_cancel_pending_slice.py | 63 +- tools/mcp/test_command_line.py | 49 +- tools/mcp/test_every_action.py | 19 +- tools/mcp/test_filaments.py | 910 ++++++++++++ tools/mcp/test_files.py | 1117 ++++++++++++++ tools/mcp/test_gizmos.py | 1118 ++++++++++++++ tools/mcp/test_gui_tools.py | 744 ++++++++++ tools/mcp/test_install_filaments.py | 6 +- tools/mcp/test_install_printers.py | 35 +- tools/mcp/test_menu_items_refusals.py | 51 + tools/mcp/test_object_structure.py | 757 ++++++++++ tools/mcp/test_objects.py | 918 ++++++++++++ tools/mcp/test_operation_routes.py | 10 +- tools/mcp/test_orca_mcp_attach.py | 16 +- tools/mcp/test_person_forms.py | 14 +- tools/mcp/test_plugin_commands.py | 8 +- tools/mcp/test_plugin_tools.py | 58 +- tools/mcp/test_preferences.py | 5 +- tools/mcp/test_presets.py | 1292 ++++++++++++++++ tools/mcp/test_recording.py | 516 +++++++ tools/mcp/test_recovery_under_load.py | 41 +- tools/mcp/test_ref_locator_export.py | 33 +- tools/mcp/test_run_sweep.py | 16 +- tools/mcp/test_set_view_camera.py | 9 +- tools/mcp/test_set_window.py | 30 +- tools/mcp/test_settings.py | 374 +++++ tools/mcp/test_sidebar_floating.py | 12 +- tools/mcp/test_slice_preview.py | 1317 +++++++++++++++++ tools/mcp/test_speed_dial_open.py | 99 +- tools/mcp/test_stdio_bridge.py | 100 +- tools/mcp/test_web_ui.py | 22 +- tools/mcp/test_webview_modal.py | 18 +- tools/mcp/tests/actions_ask.json | 66 - tools/mcp/tests/agent_forms.json | 55 - tools/mcp/tests/calibration.json | 136 -- tools/mcp/tests/context_menus.json | 74 - tools/mcp/tests/dialogs_canvas_input.json | 59 - tools/mcp/tests/filaments_and_files.json | 141 -- .../mcp/tests/fixtures/filaments_and_files.py | 54 +- tools/mcp/tests/fixtures/objects_files.py | 122 -- tools/mcp/tests/fixtures/ops_presets.py | 117 +- .../tests/fixtures/presets_and_plate_map.py | 67 - tools/mcp/tests/fixtures/settings_targets.py | 53 - tools/mcp/tests/gizmos.json | 326 ---- tools/mcp/tests/layers.json | 240 --- tools/mcp/tests/menu_items_objects.json | 61 - tools/mcp/tests/menu_items_placement.json | 107 -- tools/mcp/tests/menu_items_structure.json | 64 - tools/mcp/tests/multicolor.json | 110 -- .../tests/new_project_keeps_layer_gcode.json | 43 - tools/mcp/tests/objects_files.json | 132 -- tools/mcp/tests/objects_order.json | 47 - tools/mcp/tests/objects_state.json | 93 -- ...ops_assign_filament_preset_multi_slot.json | 414 ------ .../ops_assign_filament_preset_one_slot.json | 312 ---- tools/mcp/tests/ops_open_project.json | 83 -- tools/mcp/tests/ops_select_preset.json | 307 ---- tools/mcp/tests/presets.json | 393 ----- tools/mcp/tests/presets_and_plate_map.json | 73 - tools/mcp/tests/preview.json | 144 -- tools/mcp/tests/recording.json | 95 -- tools/mcp/tests/rows.json | 96 -- tools/mcp/tests/scene.json | 337 ----- tools/mcp/tests/settings_targets.json | 125 -- tools/mcp/tests/slice_stats.json | 59 - tools/mcp/tests/view_switches.json | 108 -- tools/mcp/tests/web_dialogs.json | 55 - 112 files changed, 11599 insertions(+), 6079 deletions(-) create mode 100644 tools/mcp/test_calibration.py create mode 100644 tools/mcp/test_call_forms.py create mode 100644 tools/mcp/test_filaments.py create mode 100644 tools/mcp/test_files.py create mode 100644 tools/mcp/test_gizmos.py create mode 100644 tools/mcp/test_gui_tools.py create mode 100644 tools/mcp/test_object_structure.py create mode 100644 tools/mcp/test_objects.py create mode 100644 tools/mcp/test_presets.py create mode 100644 tools/mcp/test_recording.py create mode 100644 tools/mcp/test_settings.py create mode 100644 tools/mcp/test_slice_preview.py delete mode 100644 tools/mcp/tests/actions_ask.json delete mode 100644 tools/mcp/tests/agent_forms.json delete mode 100644 tools/mcp/tests/calibration.json delete mode 100644 tools/mcp/tests/context_menus.json delete mode 100644 tools/mcp/tests/dialogs_canvas_input.json delete mode 100644 tools/mcp/tests/filaments_and_files.json delete mode 100644 tools/mcp/tests/fixtures/objects_files.py delete mode 100644 tools/mcp/tests/fixtures/presets_and_plate_map.py delete mode 100644 tools/mcp/tests/fixtures/settings_targets.py delete mode 100644 tools/mcp/tests/gizmos.json delete mode 100644 tools/mcp/tests/layers.json delete mode 100644 tools/mcp/tests/menu_items_objects.json delete mode 100644 tools/mcp/tests/menu_items_placement.json delete mode 100644 tools/mcp/tests/menu_items_structure.json delete mode 100644 tools/mcp/tests/multicolor.json delete mode 100644 tools/mcp/tests/new_project_keeps_layer_gcode.json delete mode 100644 tools/mcp/tests/objects_files.json delete mode 100644 tools/mcp/tests/objects_order.json delete mode 100644 tools/mcp/tests/objects_state.json delete mode 100644 tools/mcp/tests/ops_assign_filament_preset_multi_slot.json delete mode 100644 tools/mcp/tests/ops_assign_filament_preset_one_slot.json delete mode 100644 tools/mcp/tests/ops_open_project.json delete mode 100644 tools/mcp/tests/ops_select_preset.json delete mode 100644 tools/mcp/tests/presets.json delete mode 100644 tools/mcp/tests/presets_and_plate_map.json delete mode 100644 tools/mcp/tests/preview.json delete mode 100644 tools/mcp/tests/recording.json delete mode 100644 tools/mcp/tests/rows.json delete mode 100644 tools/mcp/tests/scene.json delete mode 100644 tools/mcp/tests/settings_targets.json delete mode 100644 tools/mcp/tests/slice_stats.json delete mode 100644 tools/mcp/tests/view_switches.json delete mode 100644 tools/mcp/tests/web_dialogs.json diff --git a/docs/HLSD/mcp-server.md b/docs/HLSD/mcp-server.md index a949af3aa6..17ed4dd04a 100644 --- a/docs/HLSD/mcp-server.md +++ b/docs/HLSD/mcp-server.md @@ -301,7 +301,9 @@ tests that need a call to outlive its budget without waiting 45 s for it. **blocked_by_dialog.** A handler that opens a modal blocks in its nested loop, so every 1.5 s the request thread posts a probe closure, which runs inside a wx dialog's loop and returns the `ModalTracker` snapshot as JSON; no `wxDialog*` crosses threads. With a modal open, the reply is -`{status: "blocked_by_dialog", job, dialogs}`. Its note says how to answer the topmost dialog: +`{status: "blocked_by_dialog", job, dialogs}`, once a second probe, posted at once, finds the same dialog on top: +an auto-answer rule presses a wx dialog's button from a closure queued as the dialog opens, which a probe posted +before the dialog opened runs ahead of, and the second probe runs after it. Its note says how to answer the topmost dialog: `dialog_answer` for a wx dialog or a native message box whose buttons are listed, a person for any other dialog marked `native: true` (a picker, or any native dialog on macOS), which `dialog_answer` can't press. @@ -3056,7 +3058,9 @@ shown, left out when none is shown. `ModalTracker`, a `wxModalDialogHook`, sees every `ShowModal()`, native dialogs included, and publishes the snapshot `[{title, message, class, native, buttons}]`, which other threads read. Read on the UI thread, as `app_state`, the `blocked_by_dialog` probe, the guards' refusals and the input tools' -`dialogs` read it, the snapshot describes the open dialogs again first. So it shows a dialog as it is +`dialogs` read it, the snapshot describes the open dialogs again first. The guards themselves only ask whether a +dialog is open: describing one reads every control, and done for every closure the UI thread runs, it would keep +a dialog's own events waiting while many calls queue. So it shows a dialog as it is now: text the dialog filled in once it showed (a printer's name, a list from a scan), a field typed in, a page switched. Should describing fail, the last description stands. Only a native dialog that holds the UI thread (macOS) leaves readers with the description published before it; its content does not @@ -3261,7 +3265,9 @@ port, and a page may close its dialog, destroying the web view, at any time. `Pa on the UI thread and wait for them on the job thread, a destruction watcher ending the wait for a web view that goes. Job and request threads hold a web view as a `WebHandle`, a number only the UI thread maps back to it, never as a `wxWeakRef`: making or dropping one edits the window's list of -refs, which the UI thread edits at the same time. +refs, which the UI thread edits at the same time. A web view whose native view is not made yet, which WebView2 +makes a moment after its window opens, holds the call's request and sends it once the view is there, trying every +100 ms for up to 10 s. What a page lists, after Playwright's accessibility snapshot: each element with a role as a kind (button, link, text, checkbox, radio, choice with its options, slider, spin, tab, heading, row, @@ -4633,26 +4639,25 @@ the app on Linux on the XWayland of a private headless compositor (KWin, else mu tested yet), which gives it the GPU's OpenGL and a window manager, or, on a machine without a desktop, on a private Xvfb display (with `-noreset`, and the pointer parked in a corner so no tooltip lands in a screenshot); on macOS and Windows it opens the app on the desktop. It runs -`tools/mcp/smoke_test.json`, which `--run` also runs headless. `tools/mcp/tests/gizmos.json` -checks every gizmo through the GUI tools, -`tools/mcp/tests/multicolor.json` object and part filaments and the project's settings, `tools/mcp/tests/presets.json` saving, +`tools/mcp/smoke_test.json`, which `--run` also runs headless. `tools/mcp/test_gizmos.py` +checks every gizmo through the GUI tools, with auto-answers that run a button's handler and canvas targets on +negative parts and from below the bed, `tools/mcp/test_filaments.py` a filament preset assigned to a slot by every +route, the Auto-flush preference, object and part filaments and the project's settings, +`tools/mcp/test_presets.py` selecting presets by the names their selectors show, hidden ones included, saving, reading and comparing presets, explaining settings, per-variant entries, `changed`, reverting keys, answering the -unsaved-changes prompts of a preset switch and a new project, deleting presets, exporting and importing -presets with a path, and reading a preference changed in the Preferences dialog, +unsaved-changes prompts of a preset switch and a new project, deleting presets, exporting and importing presets +with a path, and reading a preference changed in the Preferences dialog, `tools/mcp/test_plates.py` plates added, duplicated, named, locked, selected and deleted, what a lock keeps Arrange and Auto-Orient from doing, a plate's settings, the filament slot commands and the plate icons and menu, -`tools/mcp/tests/calibration.json` every calibration test and its preset answers, -`tools/mcp/tests/dialogs_canvas_input.json` auto-answers that run a button's handler and canvas -targets on negative parts and from below the bed, `tools/mcp/tests/slice_stats.json` the slice -reply's statistics on one and two colours, `tools/mcp/tests/preview.json` `plate_slice_stats`, -`app_state.preview` and `view_set`'s preview arguments, `tools/mcp/tests/context_menus.json` context -and button menus listed and run without one ever showing, and the Edit menu's Undo and Redo picked by -their paths, `tools/mcp/tests/rows.json` object list -rows, checklist rows, the object settings table and the print button's popup, -`tools/mcp/tests/recording.json` a recording with clicks, a dialog and a slice, stopped and encoded, -and one a replay ends, `tools/mcp/test_webview_modal.py` JavaScript in modal dialogs' web views, the ones -`webview_run_javascript` is refused in and a page that closes its dialog, `tools/mcp/tests/web_dialogs.json` the preset bundle dialog, the colour picker -(hex field and spectrum) and the setup wizard's first steps through the GUI tools alone, +`tools/mcp/test_calibration.py` every calibration test, its preset answers and its towers in the G-code, +`tools/mcp/test_slice_preview.py` what a slice slices and reports on one and two colours, `plate_slice_stats`, +`app_state.preview` and `view_set`'s preview arguments, `tools/mcp/test_gui_tools.py` context and button menus +listed and run without one ever showing, the Edit menu's Undo and Redo picked by their paths, object list rows, +checklist rows, the object settings table, the print button's popup, and the preset bundle dialog, the colour +picker (hex field and spectrum) and the setup wizard's first steps through the GUI tools alone, +`tools/mcp/test_recording.py` a recording with clicks, a dialog and a slice, stopped and encoded, and one a replay +ends, `tools/mcp/test_webview_modal.py` JavaScript in modal dialogs' web views, the ones +`webview_run_javascript` is refused in and a page that closes its dialog, `tools/mcp/test_web_ui.py` every page control kind, action, refusal, locator, timeout and close of the MCP web fixture plugin's dialog, window, dock panel and configuration UI (side-loaded with `--install DATADIR`), `tools/mcp/test_set_view_preview.py` the @@ -4680,17 +4685,16 @@ instruments going off with the server, `tools/mcp/test_recovery_under_load.py` answering a dialog while stalled clients hold every connection. See `tools/mcp/README.md`. -The commands that do a menu item's job by index, and the gaps they close, have their checks on the app. The -replays `tools/mcp/tests/menu_items_objects.json`, `menu_items_structure.json` and `menu_items_placement.json`, -and for the plates `tools/mcp/test_plates.py`, call the commands made from menu items by index and on the -selection, and read each back; `objects_state.json` (printable, Fix Model, Auto Drop), `objects_files.json` (clone, reload, replace), -`objects_order.json` (`object_order {order}`), `filaments_and_files.json` (slots merged and mixed, exports of -some objects, a ZIP's entries), `settings_targets.json` (`settings_list` and the targets of the settings -commands), `presets_and_plate_map.json` (`preset_list`'s filters, a plate's filament map, a nozzle variant), -`view_switches.json` (`view_set`'s switches, the sidebar and the legend, a plate's origin and size) and -`actions_ask.json` (a call with an action's arguments, the two actions that collect a value, and the actions -whose menu item is the command's function). The Python tests check what a replay cannot, a refusal: -`tools/mcp/test_menu_items_refusals.py` and `test_additions_refusals.py` each refusal's reason, +The commands that do a menu item's job by index, and the gaps they close, have their checks on the app. +`tools/mcp/test_objects.py` and `test_object_structure.py`, and for the plates `tools/mcp/test_plates.py`, call the +commands made from menu items by index and on the selection, and read each back, printable, Fix Model, Auto Drop, +clone, reload, replace and `object_order {order}` among them; `test_files.py` checks the project's files (slots +merged and mixed, exports of some objects, a ZIP's entries), `test_settings.py` `settings_list` and the targets of +the settings commands, `test_presets.py` `preset_list`'s filters, a plate's filament map and a nozzle variant, +`test_slice_preview.py` `view_set`'s switches, the sidebar and the legend, and `test_call_forms.py` a call with an +action's arguments and the forms agents write in place of the schema's. Others check the refusals and what +needs a launch of its own: `tools/mcp/test_menu_items_refusals.py` and `test_additions_refusals.py` each refusal's +reason, `test_person_forms.py` the person's forms and a pick that runs in place, `test_preferences.py` the preferences against the dialog, `test_install_printers.py` and `test_install_filaments.py` the installs, also after a restart, `test_plugin_commands.py` the plugin commands against the Plugins window, @@ -4709,11 +4713,10 @@ sizes, the object structure commands' arguments, the height ranges `object_set_h overlaps, a range that keeps its settings) and the keys and layer heights a range's settings take, and `plate_set_custom_gcode`'s edits of a layer slider built in the test (by layer and height, in-place edits, refusals that leave the slider as it was, the type names). On the app, -`tools/mcp/tests/scene.json` checks object structure and placement (transform on instances, plates and -parts, what `object_list` reports of them, the selection `object_select` and `app_state` report, shapes at a -size, arrange and Fill bed, `part_add`, the -object structure commands, then all of them on one scene through to a slice); -`tools/mcp/tests/layers.json` height range modifiers and variable layer height profiles (set, read +`tools/mcp/test_objects.py` and `test_object_structure.py` check object placement and structure (transforms on +instances, plates and parts, what `object_list` reports of them, the selection `object_select` and `app_state` +report, shapes at a size, arrange and Fill bed, `part_add`, the object structure commands); +`tools/mcp/test_slice_preview.py` height range modifiers and variable layer height profiles (set, read back, undone, sliced, refused, kept by a 3MF) and layer G-codes (placed by layer and height, edited in place, refused, sliced, kept by a 3MF); and `tools/mcp/test_worker_admission.py` admission while an arrange started three ways runs. diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 1c7529fe98..063063fb0e 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3268,7 +3268,7 @@ void GLCanvas3D::_render_frame(bool scene_dirty, bool only_init) const bool render_gcode = m_canvas_type == ECanvasType::CanvasPreview && m_render_preview; // Slider moves made since the last frame reach the toolpaths before they are drawn, so a frame drawn // right after a move, such as a screenshot, shows it. - if (render_gcode && _apply_gcode_sliders()) + if (render_gcode && apply_gcode_sliders()) scene_dirty = true; // Orca: found again by the regular picking pass, which is not run while dragging. @@ -10912,11 +10912,11 @@ void GLCanvas3D::_render_gcode_overlay(int canvas_width, int canvas_height) send_layer_ticks_changes(); // A slider dragged in this overlay moved after the scene was drawn; the next frame shows the move. - if (_apply_gcode_sliders()) + if (apply_gcode_sliders()) post_event(SimpleEvent(EVT_GLCANVAS_UPDATE)); } -bool GLCanvas3D::_apply_gcode_sliders() +bool GLCanvas3D::apply_gcode_sliders() { IMSlider *layers_slider = m_gcode_viewer.get_layers_slider(); IMSlider *moves_slider = m_gcode_viewer.get_moves_slider(); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 534bc4569b..1d936ef701 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -1138,6 +1138,9 @@ private: public: //BBS GCodeViewer& get_gcode_viewer() { return m_gcode_viewer; } + // Hands the layers and moves sliders' positions to the toolpaths, which otherwise take them when the canvas next + // draws. Returns whether either slider had moved. + bool apply_gcode_sliders(); void init_gcode_viewer(ConfigOptionMode mode, Slic3r::PresetBundle* preset_bundle) { m_gcode_viewer.init(mode, preset_bundle); } void reset_gcode_toolpaths() { _set_shown_canvas_current(); m_gcode_viewer.reset(); } const GCodeViewer::SequentialView& get_gcode_sequential_view() const { return m_gcode_viewer.get_sequential_view(); } @@ -1731,8 +1734,6 @@ private: // Realistic view: binds, or unbinds, the shadow map the toolpaths read on texture unit 4. False without a map. bool _bind_gcode_shadow_map(bool bind) const; void _render_gcode_overlay(int canvas_width, int canvas_height); - // Hands the layers and moves sliders' positions to the toolpaths. Returns whether either slider had moved. - bool _apply_gcode_sliders(); // decides whether the preview draws its reduced set this frame and returns whether what the scene // pass draws changed; runs before the cached scene is consulted bool _update_preview_interaction(); diff --git a/src/slic3r/GUI/Mcp/AutomationRuntime.cpp b/src/slic3r/GUI/Mcp/AutomationRuntime.cpp index 68de0f2443..8abd65d1b3 100644 --- a/src/slic3r/GUI/Mcp/AutomationRuntime.cpp +++ b/src/slic3r/GUI/Mcp/AutomationRuntime.cpp @@ -124,9 +124,11 @@ GuardState AutomationRuntime::guards_on_ui() const GuardState g; g.closing = m_stopping || wxTheApp == nullptr || wxGetApp().is_closing(); g.suspended = m_suspended; + // Whether a dialog is open is all a guard needs. Describing the dialogs reads every control of each, so it is left + // to the replies that name them (UiInvoker's open_dialogs()): made for every queued closure, it would keep the UI + // thread from the dialog's own events while many calls wait. if (m_modals) { - g.dialogs = m_modals->snapshot(); - g.modal = !g.dialogs.empty(); + g.modal = m_modals->top() != nullptr; g.top_dialog = m_modals->serial(m_modals->top()); } return g; diff --git a/src/slic3r/GUI/Mcp/McpCore.cpp b/src/slic3r/GUI/Mcp/McpCore.cpp index 963309c4f1..3cd640e9bd 100644 --- a/src/slic3r/GUI/Mcp/McpCore.cpp +++ b/src/slic3r/GUI/Mcp/McpCore.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -432,6 +433,8 @@ ToolResult McpCore::run(const NativeCommand& def, const nlohmann::json& args, co budget = std::min(budget, m_timing.reply_budget_cap); const auto deadline = start + budget; auto next_probe = start + m_timing.soft_budget; + // The dialog the last probe found on top of the job, which a second probe must find there too. + std::optional seen_on_top; for (;;) { const auto now = std::chrono::steady_clock::now(); const auto stop = std::min(deadline, next_probe); @@ -452,8 +455,17 @@ ToolResult McpCore::run(const NativeCommand& def, const nlohmann::json& args, co // A dialog can close between the probe and here; a finished job wins. if (auto r = m_jobs.wait(job, std::chrono::milliseconds(0))) return finish(std::move(*r)); + // An auto-answer rule presses a wx dialog's button from a call queued as the dialog opens, which a + // probe queued before the dialog opened runs ahead of. A second probe, queued now, runs after that + // press, so a dialog holds the job only when the second probe still finds it on top. + if (seen_on_top != p->guards.top_dialog) { + seen_on_top = p->guards.top_dialog; + next_probe = std::chrono::steady_clock::now(); + continue; + } return finish(blocked(p->guards.dialogs, false)); } + seen_on_top.reset(); // An unanswered probe with a native dialog on top: that dialog holds the UI thread, so the // snapshot published for other threads is all there is to report. if (!p) { diff --git a/src/slic3r/GUI/Mcp/McpToolsProject.cpp b/src/slic3r/GUI/Mcp/McpToolsProject.cpp index 4e0314a935..864d8e5af2 100644 --- a/src/slic3r/GUI/Mcp/McpToolsProject.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsProject.cpp @@ -854,15 +854,17 @@ void register_project_tools(CommandCatalog& catalog) throw ToolFailure("per_object writes every object into the folder path names: plates and overwrite go with one file"); if (format == "toolpaths_obj" && args.contains("plates")) throw ToolFailure("toolpaths_obj writes the toolpaths the Preview shows: plates goes with the other formats"); + const json plate = args.value("plates", json("current")); + const bool all = plate.is_string() && plate.get() == "all"; + if (plate.is_string() && !all && plate.get() != "current") + throw ToolFailure("plates is \"all\", \"current\" or a plate index"); + if (all && format != "sliced_3mf") + throw ToolFailure("plates \"all\" applies to sliced_3mf only"); std::string err; const auto path = per_object ? resolve_output_dir(arg_string(args, "path"), err) : resolve_output_path(arg_string(args, "path"), arg_bool(args, "overwrite", false), err); if (!path) throw ToolFailure(err); - const json plate = args.value("plates", json("current")); - const bool all = plate.is_string() && plate.get() == "all"; - if (all && format != "sliced_3mf") - throw ToolFailure("plates \"all\" applies to sliced_3mf only"); std::optional ticket; json written = json::object(); // what the reply adds for stl and drc ctx.run_ui([&]() -> json { @@ -871,6 +873,16 @@ void register_project_tools(CommandCatalog& catalog) ctx.begin_operation(); Plater& plater = ui_plater(); const std::optional index = plate.is_number_integer() ? std::optional(plate.get()) : std::nullopt; + // The export's own refusals of the object indices given come before the target check, which + // refuses an index the project lacks without no_such_object's code. + std::vector indices; + if (args.contains("object") && args.at("object").is_number_integer()) + indices.push_back(args.at("object").get()); + for (const json& entry : args.value("objects", json::array())) + if (entry.is_number_integer()) + indices.push_back(entry.get()); + if (const std::optional refusal = Ops::export_objects_refusal(format, indices, per_object, plater.model())) + throw refused(*refusal); // The objects named, by index or id; none named: every object. Targets named; if (names_targets(args)) { diff --git a/src/slic3r/GUI/Mcp/McpToolsScene.cpp b/src/slic3r/GUI/Mcp/McpToolsScene.cpp index e80d38aad6..4afae80b58 100644 --- a/src/slic3r/GUI/Mcp/McpToolsScene.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsScene.cpp @@ -1864,7 +1864,8 @@ void register_object_menu_commands(CommandCatalog& catalog) "actions, it shows the Prepare view and, as Order By does, reverses the order the objects already have. " "With order in place of by, the plate's objects go in the order given, as dragging them in the object list " "puts them: order names each of the plate's objects once, by index, and anything else is refused; the " - "other plates' objects keep their order. One undo step; object indices change. Reply: the new order (order: " + "other plates' objects keep their order. One undo step, none when the order stays as it was; object indices " + "change. Reply: the new order (order: " "[{object, name, plate}]), and descending with by.", object_schema({{"plate", {{"type", "integer"}, {"minimum", 0}, {"description", "Order this plate's objects. Default: the current plate."}}}, {"by", enum_prop({"name", "filament", "height", "size"}, "What to order by.")}, @@ -2320,7 +2321,8 @@ void register_object_tools(CommandCatalog& catalog) "file. A part whose file is gone is not asked for: it is listed under missing. A part keeps its settings, type, " "filament and placement, and its painting when the keep_painting preference is on. Parts loaded from no file " "(primitives, the built-in models) are left out; cut objects are refused, since a reload would replace a cut part " - "with its whole file, and so is a call while a gizmo is open. One undo step. Reply: reloaded (parts), missing " + "with its whole file, and so is a call while a gizmo is open. One undo step, none when every part's file is " + "missing and nothing is reloaded. Reply: reloaded (parts), missing " "(with each part's path), unmatched (parts their file holds no part to take for) and unreadable (a file that " "could not be read, after which nothing more was loaded).", with_targets(object_schema({{"all", prop("boolean", "Reload every object but the cut ones. Default false: the targets.")}}), @@ -2714,6 +2716,8 @@ void register_scene_tools(CommandCatalog& catalog) "Preview and Slice All Plates actions.")}}), [](const json& args, ToolContext& ctx) { const json plates_arg = args.value("plates", json("current")); + if (plates_arg.is_string() && plates_arg != "all" && plates_arg != "current") + throw ToolFailure("plates is \"all\", \"current\" or a plate index"); auto ticket = std::make_shared(); // Held from before the wait below, so no call admitted meanwhile can change the project // under the slice, and a cancel meanwhile finds the operation. diff --git a/src/slic3r/GUI/Mcp/McpToolsUi.cpp b/src/slic3r/GUI/Mcp/McpToolsUi.cpp index b2d1da8dee..8755402248 100644 --- a/src/slic3r/GUI/Mcp/McpToolsUi.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsUi.cpp @@ -1598,7 +1598,8 @@ void register_ui_tools(CommandCatalog& catalog) "selects it; false on the " "selected one is refused, as only selecting another unselects it). " "ImGui items, by their kind, with the value read back: a field is typed into (a slider through the number field " - "beside it, multiline text with \\n), a combo's option is picked by its text or 0-based index, and a checkbox, radio " + "beside it, multiline text with \\n), and one that then shows another value, the edit in its own terms or bounded, " + "replies typed and a note beside it; a combo's option is picked by its text or 0-based index, and a checkbox, radio " "or toggle is clicked when it differs. A web page's fields, as typing would leave them: text, number, range, colour " "and date fields and editable text get the value with input and change events (submit then leaves the field; " "keyboard_press Return presses Enter), a select its option by text, value or index, and a checkbox or radio is clicked when " diff --git a/src/slic3r/GUI/Mcp/UiInspector.cpp b/src/slic3r/GUI/Mcp/UiInspector.cpp index ed97bf1147..4f51d173cf 100644 --- a/src/slic3r/GUI/Mcp/UiInspector.cpp +++ b/src/slic3r/GUI/Mcp/UiInspector.cpp @@ -3514,8 +3514,14 @@ json UiInspector::imgui_input(UiTarget t, const json& value, bool submit) key(&field, "Return", ""); } const std::string shown = imgui_record(field).value; + // A field can show the edit it took in its own terms (the Move panel's Object coordinates measure from the place + // the object moved to, an angle may read as an equal one) or bounded: what it shows is the reply, with the text + // typed beside it, and no error, which would have a caller make the edit again. if (!imgui_value_matches(shown, field_kind == "multiline" ? json(text) : value)) - throw ToolFailure("\"" + t.imgui_label + "\" shows \"" + shown + "\" after typing \"" + text + "\"", {{"value", shown}}); + return {{"value", shown}, + {"typed", text}, + {"note", "The field shows another value than the one typed: it shows the edit in its own terms or bounded it. Read the " + "model back to see what changed."}}; return {{"value", shown}}; } diff --git a/src/slic3r/GUI/Mcp/UiInvoker.cpp b/src/slic3r/GUI/Mcp/UiInvoker.cpp index 3e8dc83e6e..74bb1c2315 100644 --- a/src/slic3r/GUI/Mcp/UiInvoker.cpp +++ b/src/slic3r/GUI/Mcp/UiInvoker.cpp @@ -99,7 +99,7 @@ nlohmann::json UiInvoker::run(GuardClass guard, const std::string& tool, const s error = "The UI was recreated (language change) before the call ran; it was not run, so it is safe to retry"; else if (guard == GuardClass::Mutate && g.modal) { error = "A modal dialog is open; answer it first (widget_list, dialog_answer)"; - details = {{"dialogs", g.dialogs}}; + details = {{"dialogs", shared->open_dialogs ? shared->open_dialogs() : g.dialogs}}; } else if (guard == GuardClass::Mutate && !shared->running_tools.empty()) error = "Busy: " + shared->running_tools.front() + " is still running; only inspection and dialog tools can run now"; } @@ -170,6 +170,9 @@ std::optional UiInvoker::probe(std::chrono::milliseconds timeo p.running_tool = shared->running_tools.front(); if (!shared->stopped && shared->guards_on_ui) p.guards = shared->guards_on_ui(); + // A dialog the probe finds is reported, so it is described, as it is now. + if (p.guards.modal && shared->open_dialogs) + p.guards.dialogs = shared->open_dialogs(); { std::lock_guard lock(call->mutex); call->probe = std::move(p); @@ -190,7 +193,8 @@ void UiInvoker::require_mutate() const if (m_shared->guards_on_ui) { const GuardState g = m_shared->guards_on_ui(); if (g.modal) - throw ToolFailure("A modal dialog is open; answer it first (widget_list, dialog_answer)", {{"dialogs", g.dialogs}}); + throw ToolFailure("A modal dialog is open; answer it first (widget_list, dialog_answer)", + {{"dialogs", m_shared->open_dialogs ? m_shared->open_dialogs() : g.dialogs}}); } if (m_shared->running_tools.size() > 1) throw ToolFailure("Busy: " + m_shared->running_tools.front() + diff --git a/src/slic3r/GUI/Mcp/UiInvoker.hpp b/src/slic3r/GUI/Mcp/UiInvoker.hpp index 2f2d07652d..a6d8bcbe3f 100644 --- a/src/slic3r/GUI/Mcp/UiInvoker.hpp +++ b/src/slic3r/GUI/Mcp/UiInvoker.hpp @@ -29,7 +29,7 @@ struct GuardState bool closing = false; // the app is shutting down bool suspended = false; // the main frame is being recreated (language change) bool modal = false; // a modal dialog or an ImGui modal popup is open - nlohmann::json dialogs = nlohmann::json::array(); + nlohmann::json dialogs = nlohmann::json::array(); // the open dialogs where the guards describe them; replies read open_dialogs() std::uint64_t top_dialog = 0; // the topmost modal dialog's serial (ModalTracker::serial()), 0 for none }; diff --git a/src/slic3r/GUI/Mcp/WebPages.cpp b/src/slic3r/GUI/Mcp/WebPages.cpp index 6c7411bfab..5278cdd73f 100644 --- a/src/slic3r/GUI/Mcp/WebPages.cpp +++ b/src/slic3r/GUI/Mcp/WebPages.cpp @@ -54,10 +54,51 @@ using namespace std::chrono_literals; namespace { -// Sends `request` to `web`'s agent and hands the outcome to `done` on the UI thread; a page without -// the agent (or with another version) is sent it with the request once. UI thread only. -void call_page(wxWebView* web, const json& request, std::function done, bool install = false) +void call_page(wxWebView* web, const json& request, std::function done, bool install = false, + bool wait_for_page = true); + +// Holds a page request while its web view has no native view to run a script in, which WebView2 creates a moment +// after the window opens, and sends it once the view is there: tried every 100 ms for up to 10 s, the time a page +// gets to answer by default. UI thread only; it deletes itself. +class PageWait : public wxTimer { +public: + PageWait(wxWebView* web, json request, std::function done, bool install) + : m_web(web), m_request(std::move(request)), m_done(std::move(done)), m_install(install) + {} + + void Notify() override + { + wxWebView* web = m_web.get(); + if (web != nullptr && web->GetNativeBackend() == nullptr && ++m_tries < 100) + return; + Stop(); + if (web == nullptr) + m_done(PageReply{PageReply::State::Destroyed, json(), std::string()}); + else + call_page(web, m_request, std::move(m_done), m_install, false); + // Not from inside the timer's own callback, which wx may still touch afterwards. + if (wxTheApp != nullptr) + wxTheApp->CallAfter([this] { delete this; }); + } + +private: + wxWeakRef m_web; + json m_request; + std::function m_done; + bool m_install; + int m_tries = 0; +}; + +// Sends `request` to `web`'s agent and hands the outcome to `done` on the UI thread; a page without +// the agent (or with another version) is sent it with the request once, and a web view whose native view +// is not made yet, once it is (PageWait). UI thread only. +void call_page(wxWebView* web, const json& request, std::function done, bool install, bool wait_for_page) +{ + if (wait_for_page && web->GetNativeBackend() == nullptr) { + (new PageWait(web, request, std::move(done), install))->Start(100); + return; + } wxWeakRef weak = web; WebView::RunScriptAsync(web, from_u8(page_script(request, install)), [weak, request, install, done = std::move(done)](bool ok, const std::string& text) { diff --git a/src/slic3r/GUI/Operations/ExportOps.cpp b/src/slic3r/GUI/Operations/ExportOps.cpp index 29d205a335..9e671b67e4 100644 --- a/src/slic3r/GUI/Operations/ExportOps.cpp +++ b/src/slic3r/GUI/Operations/ExportOps.cpp @@ -4,6 +4,7 @@ #include "PlateOps.hpp" #include "RunStatus.hpp" +#include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/I18N.hpp" @@ -54,6 +55,48 @@ std::optional select_named_plate(const std::optional& plate) return selected ? std::nullopt : std::optional(selected.refusal()); } +// An export that selected the plate it named and then failed makes the plate that was current before current +// again, so that a failed export leaves the current plate as it was. Both selections stay in the undo history. +template T select_back(const std::optional& named, int previous, T failure) +{ + if (named && *named != previous) + wxGetApp().plater()->select_plate(previous); + return failure; +} + +Refusal export_already_running() { return {RefusalKind::Busy, "export_already_running", L("Another export job is running.")}; } +Refusal slicing_in_progress() +{ + return {RefusalKind::Busy, "slicing_in_progress", L("Slicing is in progress. Wait for it to finish and export again.")}; +} +Refusal slice_has_errors() +{ + return {RefusalKind::Precondition, "slice_has_errors", + L("The plate's slice ended with an error. Fix what it reports and slice again before exporting.")}; +} +Refusal plate_not_sliced() { return {RefusalKind::Precondition, "plate_not_sliced", L("The plate is not sliced. Slice it first.")}; } +Refusal export_not_started() { return {RefusalKind::Failed, "export_not_started", L("The export did not start.")}; } +Refusal sliced_file_not_written() +{ + return {RefusalKind::Precondition, "sliced_file_not_written", + L("The sliced file was not written. Slice first and check for slicing errors.")}; +} + +// What Plater::export_gcode_to() would refuse on `plate`, in its order, asked before the export selects the plate +// so that a refused export changes nothing. +std::optional gcode_export_refusal(Plater& plater, int plate) +{ + if (plater.is_export_gcode_scheduled()) + return export_already_running(); + if (plater.is_slicing_any()) + return slicing_in_progress(); + if (!plater.plate_validation_error(plate).empty()) + return slice_has_errors(); + if (!plater.get_partplate_list().get_plate(plate)->is_slice_result_valid()) + return plate_not_sliced(); + return std::nullopt; +} + } // namespace Outcome start_gcode_export(const ExportGcodeArgs& args) @@ -63,9 +106,12 @@ Outcome start_gcode_export(const ExportGcodeArgs& args) PartPlateList& plates = plater.get_partplate_list(); if (plater.model().objects.empty()) return no_objects(); + const int previous = plates.get_curr_plate_index(); if (args.plate) { if (*args.plate < 0 || *args.plate >= plates.get_plate_count()) return no_such_plate(*args.plate, plates.get_plate_count()); + if (std::optional refusal = gcode_export_refusal(plater, *args.plate)) + return *refusal; // The owner exports the current plate. plater.select_plate(*args.plate); } @@ -74,23 +120,21 @@ Outcome start_gcode_export(const ExportGcodeArgs& args) ticket.seq_before = plater.export_seq(); ticket.revision = plater.project_revision(); ticket.path = args.path.string(); + std::optional refusal; 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.")}; + case Plater::ExportRefusal::NoObjects: refusal = no_objects(); break; + case Plater::ExportRefusal::AlreadyExporting: refusal = export_already_running(); break; + case Plater::ExportRefusal::Slicing: refusal = slicing_in_progress(); break; + case Plater::ExportRefusal::SliceHasErrors: refusal = slice_has_errors(); break; + case Plater::ExportRefusal::NotSliced: refusal = plate_not_sliced(); break; + case Plater::ExportRefusal::NotStarted: refusal = export_not_started(); break; } 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.")}; + if (!refusal && ticket.seq_after == ticket.seq_before) + refusal = export_not_started(); + if (refusal) + return select_back(args.plate, previous, Outcome(*refusal)); return ticket; } @@ -112,21 +156,28 @@ Outcome export_sliced_3mf(const ExportSlicedArgs& args) Plater& plater = *wxGetApp().plater(); if (plater.model().objects.empty()) return no_objects(); + const int previous = plater.get_partplate_list().get_curr_plate_index(); + // The named plate's slice error refuses before the plate is selected, as export_gcode_3mf() refuses it after. + if (args.plate && *args.plate >= 0 && *args.plate < plater.get_partplate_list().get_plate_count() && + !plater.plate_validation_error(*args.plate).empty()) + return sliced_file_not_written(); if (std::optional 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); + return select_back(args.plate, previous, Outcome(sliced_file_not_written())); + const Outcome done = written(args.path); + return done ? done : select_back(args.plate, previous, done); } Outcome export_model_3mf(const ExportFileArgs& args) { assert(wxThread::IsMain()); + const int previous = wxGetApp().plater()->get_partplate_list().get_curr_plate_index(); if (std::optional refusal = select_named_plate(args.plate)) return *refusal; wxGetApp().plater()->export_core_3mf(from_path(args.path)); - return written(args.path); + const Outcome done = written(args.path); + return done ? done : select_back(args.plate, previous, done); } std::optional export_objects_refusal(const std::string& format, const std::vector& objects, bool per_object, @@ -153,17 +204,19 @@ Outcome> export_stl(const ExportStlArgs& ar return no_objects(); if (std::optional refusal = export_objects_refusal(args.draco ? "drc" : "stl", args.objects, args.per_object, plater.model())) return *refusal; + const int previous = plater.get_partplate_list().get_curr_plate_index(); if (std::optional refusal = select_named_plate(args.plate)) return *refusal; + using Files = Outcome>; std::vector files; for (const std::string& file : plater.export_stl(false, false, args.per_object, args.draco ? FT_DRC : FT_STL, from_path(args.path), args.objects)) { files.push_back(into_path(from_u8(file))); if (!written(files.back())) - return file_not_written(); + return select_back(args.plate, previous, Files(file_not_written())); } if (files.empty()) - return file_not_written(); + return select_back(args.plate, previous, Files(file_not_written())); return files; } @@ -182,6 +235,9 @@ Outcome export_toolpaths_obj(const ExportToolpathsArgs& args) assert(wxThread::IsMain()); if (std::optional refusal = toolpaths_refusal()) return *refusal; + // A layer range shown since the canvas last drew reaches the toolpaths only when it draws again: the file + // holds what the Preview shows. + wxGetApp().plater()->get_preview_canvas3D()->apply_gcode_sliders(); wxGetApp().plater()->export_toolpaths_to_obj(from_path(args.path)); return written(args.path); } diff --git a/src/slic3r/GUI/Operations/ExportOps.hpp b/src/slic3r/GUI/Operations/ExportOps.hpp index f32b19a4e9..7e1c0cda93 100644 --- a/src/slic3r/GUI/Operations/ExportOps.hpp +++ b/src/slic3r/GUI/Operations/ExportOps.hpp @@ -33,7 +33,9 @@ struct ExportTicket }; // 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. +// at once; gcode_export_state() says how the export stands. An export that names a plate and is refused +// leaves the current plate as it was: what can be told on the plate is refused before it is selected, and +// a failure after that selects the plate that was current back. The exports below do the same. // Refuses: no_objects, no_such_plate, export_already_running, slicing_in_progress, slice_has_errors, // plate_not_sliced, export_not_started. Outcome start_gcode_export(const ExportGcodeArgs& args); diff --git a/src/slic3r/GUI/Operations/ObjectOps.cpp b/src/slic3r/GUI/Operations/ObjectOps.cpp index 06779c5cb8..b15387e457 100644 --- a/src/slic3r/GUI/Operations/ObjectOps.cpp +++ b/src/slic3r/GUI/Operations/ObjectOps.cpp @@ -1232,10 +1232,15 @@ void placed_instance(int object, int instance, bool drop) { Plater& plater = the_plater(); ModelObject& owner = *plater.model().objects[std::size_t(object)]; - // The bounding box is cached: ensure_on_bed() must measure the new placement. + // The bounding box is cached: the drop must measure the new placement. owner.invalidate_bounding_box(); - if (drop) - owner.ensure_on_bed(); + // Only the instance placed comes to rest on the bed, by its own lowest point, as the canvas drops the instances a + // move or scale changed: the object's other instances keep their heights. + if (drop && owner.auto_drop) { + const double min_z = owner.get_instance_min_z(std::size_t(instance)); + if (min_z != 0.0) + owner.translate_instance(std::size_t(instance), Vec3d(0.0, 0.0, -min_z)); + } plater.get_partplate_list().notify_instance_update(object, instance); wxGetApp().obj_list()->update_plate_values_for_items(); plater.changed_object(object); diff --git a/src/slic3r/GUI/Operations/ObjectOps.hpp b/src/slic3r/GUI/Operations/ObjectOps.hpp index ff03fb351e..cfc69dfddd 100644 --- a/src/slic3r/GUI/Operations/ObjectOps.hpp +++ b/src/slic3r/GUI/Operations/ObjectOps.hpp @@ -215,7 +215,8 @@ struct OrderObjectsArgs std::optional descending; // none: descending when the order they have is ascending already, as Order By does }; // Orders a plate's objects, or every plate's, as the plate menu's Order By does (ObjectList::order_objects()), which -// sets the object list and print order, in one undo step. Returns whether they are in descending order. +// sets the object list and print order, in one undo step, or none when the order stays as it was. Returns whether they +// are in descending order. // Refuses: no_such_plate, no_objects_to_order, gizmo_open. Outcome order_objects(const OrderObjectsArgs& args); @@ -225,8 +226,8 @@ struct ReorderObjectsArgs std::vector order; // the plate's objects, each once, in the order wanted }; // Puts a plate's objects in `order`, which sets the object list and print order, as dragging each in the object list -// onto the one in its place does (ObjectList::OnDrop(), the drops object_order_moves() gives), in one undo step. The -// objects of other plates keep their order. Returns the plate's objects, by their indices afterwards, in that order. +// onto the one in its place does (ObjectList::OnDrop(), the drops object_order_moves() gives), in one undo step, or none +// when the order stays as it was. The objects of other plates keep their order. Returns the plate's objects, by their indices afterwards, in that order. // Refuses: no_such_plate, and what object_order_moves() refuses. Outcome> reorder_objects(const ReorderObjectsArgs& args); @@ -470,7 +471,7 @@ struct ReloadedParts // Reloads the targets' parts from their files (reload_sources()), as Reload from disk does // (Plater::reload_parts_from_disk()), in one "Reload from disk" undo step: each keeps its settings, type, filament and // placement, and its painting with the keep_painting preference on. A part whose file is gone is listed as missing; no -// dialog opens. +// dialog opens. A call that reloads nothing, every part's file being missing, takes no undo step. // Refuses: gizmo_open (a gizmo is open), cut_object (a cut object named: a reload would replace a cut part with its whole // file), no_objects (all, with none that is not cut), no_source (none of the parts was loaded from a file). Outcome reload_parts(const ReloadFromDiskArgs& args); @@ -500,8 +501,8 @@ struct ReplacePartArgs // cancelled), several_parts (replacement_refusal()). Outcome replace_part(const ReplacePartArgs& args); -// Brings the app up to date with instance `instance` of object `object`, placed anew in the model: dropped onto the bed -// with `drop`, its plate registered (slicing and the object list read the plate from the registry, which a move on the +// Brings the app up to date with instance `instance` of object `object`, placed anew in the model: with `drop` and the +// object's Auto Drop on, the instance alone set on the bed by its lowest point, its plate registered (slicing and the object list read the plate from the registry, which a move on the // canvas updates) and the object reloaded. UI thread. void placed_instance(int object, int instance, bool drop); diff --git a/src/slic3r/GUI/Operations/PlateOps.cpp b/src/slic3r/GUI/Operations/PlateOps.cpp index c1ef242a2b..b166a16693 100644 --- a/src/slic3r/GUI/Operations/PlateOps.cpp +++ b/src/slic3r/GUI/Operations/PlateOps.cpp @@ -13,6 +13,7 @@ #include "slic3r/GUI/Plater.hpp" #include "libslic3r/Config.hpp" +#include "libslic3r/GCode/GCodeProcessor.hpp" #include "libslic3r/Model.hpp" #include @@ -267,9 +268,16 @@ LayerTicks layer_ticks(std::optional first, int last, int count) Outcome 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) + if (canvas == nullptr) + return no_layers(); + GCodeViewer& viewer = canvas->get_gcode_viewer(); + IMSlider* layers = viewer.get_layers_slider(); + const GCodeProcessorResult* result = the_plater().get_partplate_list().get_curr_plate()->get_slice_result(); + // The slider alone says nothing: its range starts at 0..100 before a print gives it layers, and the Preview + // hides it without clearing it for a plate that has none. Only a viewer that holds the current plate's + // toolpaths has the layers of that plate, the test app_state's preview makes too. + if (layers == nullptr || layers->values_count() == 0 || result == nullptr || !viewer.has_data() || + viewer.last_result_id() != result->id) return no_layers(); return layers->GetMaxValue() + 1; } diff --git a/src/slic3r/GUI/Operations/PlateOps.hpp b/src/slic3r/GUI/Operations/PlateOps.hpp index e1ab8fb997..1882a3fb48 100644 --- a/src/slic3r/GUI/Operations/PlateOps.hpp +++ b/src/slic3r/GUI/Operations/PlateOps.hpp @@ -134,10 +134,10 @@ Outcome> slice_plates(const SliceArgs& args); // Refuses: no_such_plate. Outcome 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). +// How many layers the Preview has to show of the current plate, for a caller that turns an argument of +// its own into a layer. +// Refuses: no_layers (the Preview does not hold the current plate's toolpaths: the plate is empty, not +// sliced, or its slice failed). Outcome layer_count(); struct ShowLayerRangeArgs diff --git a/src/slic3r/GUI/Operations/PresetOps.cpp b/src/slic3r/GUI/Operations/PresetOps.cpp index 7da2ede25f..fe47680573 100644 --- a/src/slic3r/GUI/Operations/PresetOps.cpp +++ b/src/slic3r/GUI/Operations/PresetOps.cpp @@ -130,8 +130,10 @@ void show_default_filaments(PresetBundle& bundle, const std::string& printer_nam // names the slot whose selector it is, 0 for a tab's. Refusal not_offered(PresetCollection& presets, const std::string& name, int filament_slot) { + // Incompatible only when no compatible preset carries the name: one that does is listed under another name (an + // alias such as "0.16mm Optimal" names presets for many printers), which the similar names point to. if (const std::vector incompatible = presets_named(presets, name, [](const Preset& p) { return !p.is_compatible; }); - !incompatible.empty()) + !incompatible.empty() && presets_named(presets, name, [](const Preset& p) { return p.is_compatible; }).empty()) return {RefusalKind::Precondition, "preset_incompatible", L("\"%1%\" is not compatible with the selected printer."), {name}, names_of(incompatible)}; if (filament_slot > 0) diff --git a/src/slic3r/GUI/Operations/PresetOps.hpp b/src/slic3r/GUI/Operations/PresetOps.hpp index fe3e487ce4..cc2296efd8 100644 --- a/src/slic3r/GUI/Operations/PresetOps.hpp +++ b/src/slic3r/GUI/Operations/PresetOps.hpp @@ -52,8 +52,8 @@ struct ResolvedPreset // 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). +// candidates), preset_incompatible (with the incompatible presets of that name, when no +// compatible preset carries it), preset_not_offered (with the closest names). Outcome resolve_preset(const ResolvePresetArgs& args); struct SelectPresetArgs diff --git a/src/slic3r/GUI/Operations/ProjectOps.cpp b/src/slic3r/GUI/Operations/ProjectOps.cpp index add68088bb..ab28ef26f5 100644 --- a/src/slic3r/GUI/Operations/ProjectOps.cpp +++ b/src/slic3r/GUI/Operations/ProjectOps.cpp @@ -125,6 +125,10 @@ Outcome import_models(const ImportModelsArgs& args) plater.import_zip_archive(archive.path, &archive.entries); if (plater.model().objects.size() == before) return Refusal{RefusalKind::Failed, "nothing_loaded", L("Nothing was imported.")}; + // Named as File > Import names it, after the first model file; an archive alone names nothing, as Import ZIP + // Archive names nothing. + if (!files.empty()) + plater.name_untitled_project(files.front()); result.added = plater.model().objects.size() - before; return result; } diff --git a/src/slic3r/GUI/Operations/ProjectOps.hpp b/src/slic3r/GUI/Operations/ProjectOps.hpp index 647c355561..8d78edc3c6 100644 --- a/src/slic3r/GUI/Operations/ProjectOps.hpp +++ b/src/slic3r/GUI/Operations/ProjectOps.hpp @@ -59,7 +59,8 @@ struct ImportModelsResult // are not loaded), as one "Import Objects: " undo step. A .zip archive is taken apart as Import // ZIP Archive does (Plater::import_zip_archive()): the files `entries` names, or every model file it // holds, in place of its file list. The owner's import can open a dialog of its own (a STEP file's -// mesh options). +// mesh options). An untitled project is named after the first file that is not an archive, as File > +// Import names it. // Refuses: unreadable_archive and what zip_entries_refusal() gives, before anything is imported; // nothing_loaded. The undo step stays in the history then, as after an import from the File menu // whose load fails. diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 4eb6a7ee55..2079ddb257 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -18979,6 +18979,15 @@ wxString Plater::get_project_name() return p->get_project_name(); } +void Plater::name_untitled_project(const boost::filesystem::path& file) +{ + // The test add_file() makes: a new project's name is the translated "Untitled". + if (get_project_name() != _L("Untitled")) + return; + p->set_project_name(from_u8(file.stem().string())); + wxGetApp().mainframe->update_title(); +} + void Plater::update_all_plate_thumbnails(bool force_update) { for (int i = 0; i < get_partplate_list().get_plate_count(); i++) diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index af74087d18..c7ad0468cb 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -494,6 +494,9 @@ public: // BBS bool is_new_project_and_check_state() { return m_new_project_and_check_state; } wxString get_project_name(); + // Names an untitled project after `file` without its extension and shows the name in the title, as File > + // Import does after its first model loads; the project keeps no file. A project with a name keeps it. + void name_untitled_project(const boost::filesystem::path& file); void update_all_plate_thumbnails(bool force_update = false); void update_plate_thumbnails(int plate_idx, bool force_update); void update_obj_preview_thumbnail(ModelObject *, int obj_idx, int vol_idx, std::vector colors, int camera_view_angle_type); diff --git a/tests/automation/test_mcp_core.cpp b/tests/automation/test_mcp_core.cpp index f62e11e56b..c1bc32ca6a 100644 --- a/tests/automation/test_mcp_core.cpp +++ b/tests/automation/test_mcp_core.cpp @@ -392,6 +392,28 @@ TEST_CASE("blocked_by_dialog is reported after the soft budget when the probe se CHECK(result->data["closed"] == true); } +TEST_CASE("a dialog whose answer was queued as it opened does not hold the call", "[Mcp]") +{ + Harness h; + h.registry.add(tool("answered_modal", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { + ctx.run_ui([&] { + // Past the 100 ms soft budget the first probe is queued behind this closure. The dialog then + // opens and queues its answer behind that probe, as an auto-answer rule queues its press. + std::this_thread::sleep_for(250ms); + std::atomic answered{false}; + h.ui.post([&] { answered = true; }); + h.modal_loop(answered, json::array({{{"title", "Orca Slicer info"}}})); + return json(); + }); + return ToolResult::ok({{"closed", true}}); + })); + h.start(); + + const ToolResult r = h.call("answered_modal"); + CHECK(r.data.value("status", "") != "blocked_by_dialog"); + CHECK(r.data.value("closed", false) == true); +} + TEST_CASE("a call working in the topmost dialog is blocked only by another dialog on top", "[Mcp]") { Harness h; diff --git a/tests/data/command_catalog.json b/tests/data/command_catalog.json index 51deff783e..faf5446daf 100644 --- a/tests/data/command_catalog.json +++ b/tests/data/command_catalog.json @@ -2386,7 +2386,7 @@ } ], "completion": "immediate", - "description": "Order the objects of a plate (the current one, or plate), or with all of every plate, by name, filament, height or size (bounding box volume), which sets the object list and print order, as the plate menu's Order By does: ascending, or with descending true descending. Called with by alone, as its Speed Dial actions, it shows the Prepare view and, as Order By does, reverses the order the objects already have. With order in place of by, the plate's objects go in the order given, as dragging them in the object list puts them: order names each of the plate's objects once, by index, and anything else is refused; the other plates' objects keep their order. One undo step; object indices change. Reply: the new order (order: [{object, name, plate}]), and descending with by.", + "description": "Order the objects of a plate (the current one, or plate), or with all of every plate, by name, filament, height or size (bounding box volume), which sets the object list and print order, as the plate menu's Order By does: ascending, or with descending true descending. Called with by alone, as its Speed Dial actions, it shows the Prepare view and, as Order By does, reverses the order the objects already have. With order in place of by, the plate's objects go in the order given, as dragging them in the object list puts them: order names each of the plate's objects once, by index, and anything else is refused; the other plates' objects keep their order. One undo step, none when the order stays as it was; object indices change. Reply: the new order (order: [{object, name, plate}]), and descending with by.", "destructive": false, "group": "Objects", "guard": "mutate", @@ -3082,7 +3082,7 @@ }, { "completion": "immediate", - "description": "Load parts again from the files they were loaded from, as Reload from disk does: every part of the objects named, the parts named, every object's (all, as Reload All does, cut objects left out), else what is selected in the Prepare view. A part's file is the one it was loaded from, else the file of that name beside its object's file. A part whose file is gone is not asked for: it is listed under missing. A part keeps its settings, type, filament and placement, and its painting when the keep_painting preference is on. Parts loaded from no file (primitives, the built-in models) are left out; cut objects are refused, since a reload would replace a cut part with its whole file, and so is a call while a gizmo is open. One undo step. Reply: reloaded (parts), missing (with each part's path), unmatched (parts their file holds no part to take for) and unreadable (a file that could not be read, after which nothing more was loaded).", + "description": "Load parts again from the files they were loaded from, as Reload from disk does: every part of the objects named, the parts named, every object's (all, as Reload All does, cut objects left out), else what is selected in the Prepare view. A part's file is the one it was loaded from, else the file of that name beside its object's file. A part whose file is gone is not asked for: it is listed under missing. A part keeps its settings, type, filament and placement, and its painting when the keep_painting preference is on. Parts loaded from no file (primitives, the built-in models) are left out; cut objects are refused, since a reload would replace a cut part with its whole file, and so is a call while a gizmo is open. One undo step, none when every part's file is missing and nothing is reloaded. Reply: reloaded (parts), missing (with each part's path), unmatched (parts their file holds no part to take for) and unreadable (a file that could not be read, after which nothing more was loaded).", "destructive": false, "examples": [ { @@ -18125,7 +18125,7 @@ }, { "completion": "immediate", - "description": "Set a widget's value and send the events a person's edit would. Widgets: text fields (submit, the default, also presses Enter and leaves the field, which is when Orca's setting fields commit), spin controls, sliders, choice, combo and list boxes (by option text or index), checkboxes, toggles and a row's checkbox (true or false), and a radio button (an Orca radio box too) or a selector's option, as the dialog message shows them (*) / ( ) (true selects it; false on the selected one is refused, as only selecting another unselects it). ImGui items, by their kind, with the value read back: a field is typed into (a slider through the number field beside it, multiline text with \\n), a combo's option is picked by its text or 0-based index, and a checkbox, radio or toggle is clicked when it differs. A web page's fields, as typing would leave them: text, number, range, colour and date fields and editable text get the value with input and change events (submit then leaves the field; keyboard_press Return presses Enter), a select its option by text, value or index, and a checkbox or radio is clicked when it differs; the value is read back and page says what changed, as for widget_click. File fields can't be set. For settings, settings_set is more reliable.", + "description": "Set a widget's value and send the events a person's edit would. Widgets: text fields (submit, the default, also presses Enter and leaves the field, which is when Orca's setting fields commit), spin controls, sliders, choice, combo and list boxes (by option text or index), checkboxes, toggles and a row's checkbox (true or false), and a radio button (an Orca radio box too) or a selector's option, as the dialog message shows them (*) / ( ) (true selects it; false on the selected one is refused, as only selecting another unselects it). ImGui items, by their kind, with the value read back: a field is typed into (a slider through the number field beside it, multiline text with \\n), and one that then shows another value, the edit in its own terms or bounded, replies typed and a note beside it; a combo's option is picked by its text or 0-based index, and a checkbox, radio or toggle is clicked when it differs. A web page's fields, as typing would leave them: text, number, range, colour and date fields and editable text get the value with input and change events (submit then leaves the field; keyboard_press Return presses Enter), a select its option by text, value or index, and a checkbox or radio is clicked when it differs; the value is read back and page says what changed, as for widget_click. File fields can't be set. For settings, settings_set is more reliable.", "destructive": false, "group": "Driving the GUI", "guard": "recover", diff --git a/tools/mcp/README.md b/tools/mcp/README.md index 44b4dae5de..3663a03e26 100644 --- a/tools/mcp/README.md +++ b/tools/mcp/README.md @@ -235,95 +235,65 @@ the `pages.get()` above does. While a modal it opened is up, tool calls that cha so interactive scripts use modeless windows. `docs/HLSD/mcp-server.md` ("Python scripts") has the rules for overlapping runs, imports, pools, `atexit` and Stop. -`tests/gizmos.json` drives every gizmo through the GUI tools, the way a person does: each one's icon, -its panel's fields, combos, toggles and links, and clicks or strokes at points of the model, then -checks what it left on the model (`object_list`), with an undo and redo and a canvas screenshot per -gizmo. It uses the fixtures beside it (`tests/fixtures/star.svg`, `tests/fixtures/heightmap.png`). -Run it at a second window size through `replay_run`'s `vars`: +`test_gizmos.py` drives every gizmo through the GUI tools, the way a person does: each one's icon, its panel's +fields, combos, toggles and links, and clicks or strokes at points of the model. It reads each gizmo's work back from +the model it leaves (placements, painted facets, texture layers, text and SVG parts, brim ears), checks its undo +before any redo, and reads what a person keeps again from a saved and reopened project. It also checks the canvas +input the gizmos rely on (a press held across gestures, a toolbar item a selection has just enabled, points on a +negative part and seen from below the bed) and that auto-answer rules run the preset prompt's Transfer and Discard. +It uses the fixtures beside it (`tests/fixtures/star.svg`, `tests/fixtures/heightmap.png`), and scenarios named on +its command line run alone. -```bash -tools/mcp/orca_mcp.py call replay_run '{"path": "/abs/tools/mcp/tests/gizmos.json", "out_dir": "/tmp/gizmos-small", "vars": {"window_size": [1100, 760]}}' --wait -``` +`test_objects.py` and `test_object_structure.py` check the object commands, each called by index and, where its +menu item acts on the selection, on the selection. `test_objects.py` checks where objects stand and how many there +are: shapes added at a size, a place, a plate and a name; instances moved, turned, scaled and sent to another plate, +and what Auto Drop does to a move; parts moved and scaled; the selection; Mirror, Drop to Bed, Center, Scale to Fit +and Auto-Orient; the number of instances and Set as Individual Objects; Arrange, Fill bed and Clone; and instances +left out of the print. `test_object_structure.py` checks what objects are made of and how the list orders them: +renaming and deleting, Split and Assemble, parts of every type, Change Type, Order By and an order given, Fix Model, +Reload from disk, Replace 3D file and the keep_painting preference. Both read every object back from `object_list` +after each step, through the readers in `checks.py`. -`tests/scene.json` checks object structure and placement: `object_transform` on an instance (the drop after a -scale, `size`, a move to another plate), on a part, what `object_list` reports of them (bounding boxes -on the bed, filament, the scaled volume, a mirrored part and instance), the selection as `object_select` and -`app_state` report it (parts, whole instances, one instance of two), shapes given a size -(`object_add_primitive {shape, size}`), `object_arrange` on one plate and every plate, Fill bed, the Speed -Dial no-op that `action_run` reports as an error, `part_add` (shapes at a size and a position, a model -file, one undo step, and what it refuses), and the object structure commands (Change Type, Rename, -number of instances, individual objects, Assemble, Order By and its reversal, and what each refuses). It -ends with all of them on one scene: a block with a magnet pocket and a boss, sized, moved to a second -plate, copied six times and arranged there, split into objects, one mirrored, two assembled, ordered, -the plate filled and sliced. +`test_slice_preview.py` checks slicing and what a slice leaves: what `plate_slice` and the Slice and Preview and +Slice All Plates actions slice (no objects, a plate that fails validation, two plates); the statistics of a slice in +one colour and in two; the Preview's tables, legend and layers as `plate_slice_stats`, `view_set`, the Go to layer +action and `app_state` give them, and a G-code file opened for viewing; height range modifiers, variable layer +heights and a plate's layer G-codes, each read in the G-code and kept by a 3MF; every command that takes a plate +index; `view_set`'s display switches, sidebar, legend and G-code window; and `app_state`'s account, network plug-in +and configuration folder. It slices about thirty times. -`tests/layers.json` checks height range modifiers: `object_set_height_ranges` with ranges given out of order -and their settings set with `settings_set` (target `height_range`), their read-back in `object_list`, one -undo step each (and none for the same ranges again, which keep their settings), the layer count of a slice -with them, the refusals (an overlap, a layer height beyond the printer's, a missing filament, an object -setting, an empty range), a range in the second filament, a 3MF round trip, and `[]`. Then -variable layer height profiles on a Benchy with `object_set_variable_layer_height`: Adaptive called from the -Preview tab, its quality's effect on the point count, the layer count of a slice with it, Smooth as one -undo step, Reset and a Reset that changes nothing, the refusals (an argument of another action, the -assemble view), Smooth and Adaptive over height ranges, and a 3MF round trip. Last, layer G-codes on a -cube with `plate_set_custom_gcode`: refused before a slice, a pause by layer and custom G-code by height called -from Prepare (it shows the Preview), the same code again changing nothing, a removal and an in-place -custom edit in one call, the refusals (a layer above the top, a code where another is, nothing to remove, -a missing filament, a missing plate, a plate changed since its slice that the Preview does not show), a -filament change, a 3MF round trip, and `clear`. - -`tests/settings_targets.json` checks `settings_list` (each type whole, a saved preset's and a slot's values, -what an object and a region take) and the settings tools' targets on a cube with a modifier and two height -ranges: a value set on the object, the modifier and a range, each read back by index and from the selection -with the value it prints with and where that comes from, and ranges replaced keeping the settings of the one -that stays. `tests/view_switches.json` checks `view_set`'s sidebar, legend, G-code window, section view and -display switches, each set and read back from its reply and `app_state`; a cube placed in the middle of a -plate from `plate_list`'s origin and size; and `app_state`'s account, network plug-in and configuration folder. +`test_settings.py` checks `settings_list` (each type whole, a saved preset's and a slot's values, what an object and +a region take) and the settings commands' targets: a value set on an object, a part, a modifier and a height range, +by index and from the selection, read back with the value it prints with and where that comes from, shown to reach +the print, and ranges replaced keeping the settings of the one that stays. `test_sidebar_floating.py` launches its own app twice, the second time with the sidebar floating in the saved window layout, and checks that `view_set`'s `sidebar_width` is refused there. -`tests/recording.json` records while it drives the GUI: clicks on the 3D view, a setting typed, the -Preferences dialog opened and closed, a slice. It stops the recording (frames, length, size) and encodes -it to H.265, then has a nested replay start a recording of the 3D view that it never stops, checks the -replay's end closed it, and encodes that to H.264. Short recordings check that a recording has no overlays -unless `captions` or `pointer` turns one on, that one started with a path and no `max_seconds` runs under an -hour's limit, and that one started with `encode` is encoded as a job once `recording_stop` reports it, the -encode deleting its `.mkv` unless `keep_raw_video_file` keeps it. Its -`project_new` and `recording_stop` calls pass `silent: true`: with no arguments they would do what a -person's pick does, asking and stopping without a report. The encodes need an ffmpeg with libx265 and libx264 -(`ORCA_FFMPEG`, or `ffmpeg` on `PATH`) and are optional without one. Look at the videos, or at frames -`ffmpeg -i session.mkv -vf fps=1 frame%02d.png` extracts, for the caption, the pointer and the dialog. +`test_recording.py` records while it drives the GUI (clicks on the 3D view, a setting typed, the Preferences dialog +opened and closed, a slice) and reads the recording back from its file. A nested replay starts a recording it never +stops, which the replay's end closes. Short recordings check that a recording has no overlays unless `captions` or +`pointer` turns one on, that one started with a path and no `max_seconds` runs under an hour's limit, and that one +started with `encode` is encoded as a job once `recording_stop` reports it, the encode deleting its `.mkv` unless +`keep_raw_video_file` keeps it. The encodes need an ffmpeg with libx265 and libx264 (`ORCA_FFMPEG`, or `ffmpeg` on +`PATH`); the checks that need one are skipped without it. The recordings are kept in `--out` (a new temporary +folder without it): look at the videos, or at frames `ffmpeg -i session.mkv -vf fps=1 frame%02d.png` extracts, for +the caption, the pointer and the dialog. -`tests/multicolor.json` assigns filaments to objects and parts through `settings_set`'s object and -part targets, with undo and redo, and reads them back with `settings_get`'s effective values. It then -sets the project's slot colours, flushing multiplier, one flushing volume and plate type through -`project_set_settings` (in one call, the colour first), checks the refusals that leave everything as it was -(the read-only `filament_is_mixed`, a bad colour, a purge mode the printer has no button for, a non-zero -diagonal, a tower off the plate), and moves the prime tower with an undo, before slicing. +`test_filaments.py` assigns filament presets to slots through each route a person or a plugin has: a pick in the +sidebar's selector, its value set with `widget_set_value`, `preset_select` and the plugin API. On one slot it answers +the filament tab's unsaved-changes prompt every way; on three it checks what the Auto-flush preference does to the +flushing volumes when a slot's preset or colour changes. Then it assigns filaments to objects and parts with +`settings_set` and sets the project's slot colours, flushing volumes, plate type and prime tower with +`project_set_settings`, and checks what reaches the print and what the project file keeps. -`tests/presets.json` saves filament, process and printer presets with `preset_save` (a user preset, -one inside the project that a saved and reopened project keeps, a detached one, and the overwrite -rule), and drops unsaved edits with `settings_set {"reset_all": true}`. It selects a filament the selector -does not offer, one the setup wizard has not installed, by name. It reads presets that are not selected and -compares presets (`settings_get` `preset` and `compare`), writes one entry of a -per-variant value, and checks `settings_set`'s `changed` after the spiral vase dialog. It reads what -settings do from their meta (`description`, `where`): by key with `settings_get`, for one group with -`settings_list`, and found by the words of their descriptions, in one type and in all three. Keys named -without a type are read from the type that has each one, and a key named in the wrong type is listed with -the type that has it (`type_of`) and refused by `settings_set`. It reverts single keys (`null`, `reset_to`), -and answers the unsaved-changes prompts: -`preset_select` without `preset_changes` still opens the prompt, `preset_changes` transfers or discards without it, -and `project_new` keeps modified presets unless `preset_changes` is `"discard"`. It ends by deleting the -presets it made with `preset_delete`: filaments the tab edits and does not, a base process and its -child, and a printer once selected, with the refusals for system presets, a preset another inherits -from, unsaved changes and a printer that is not selected. It exports a filament with the Export -Preset Bundle dialog to its `out_dir` (`preset_export` with a directory), imports the archive again -with `preset_import` and a path (kept while the preset exists, imported once it is deleted) and -imports `tests/fixtures/mcp_import_pla.json`. It changes a preference in the Preferences dialog -opened with `window_open {"window": "preferences", "tab": "behaviour", "key": "auto_arrange"}`, by the -control's name, and reads it back with `preferences_get`. It starts from the harness's default printer with one -filament slot in Simple mode, deleting slots and selecting the mode first, and reruns on the same -datadir. +`test_presets.py` checks the presets of the three types: selecting one by the name its selector shows, hidden ones +included; `preset_list`'s filters; what a setting is and where it lives (`settings_get`, `settings_list`); saving, +overwriting, reverting and deleting presets; the unsaved-changes prompt of a preset switch and of a new project, +answered ahead with `preset_changes` or in the dialog; the same selections through the plugin API; a preset kept +inside the project; the Export Preset Bundle dialog and `preset_import` (with `tests/fixtures/mcp_import_pla.json`); +a printer variant picked by its nozzle; a preference changed in the Preferences dialog; and that the presets +selected are what the G-code is sliced with. It needs a freshly launched app on a fresh data folder: a hidden preset +that `preset_select` shows stays shown until a restart. `test_plates.py` checks the plates of the Prepare view: plates added, duplicated, named, locked, selected and deleted by index and on the current plate, with undo; what a lock keeps Arrange and Auto-Orient from doing; a @@ -331,37 +301,21 @@ plate's own settings through `plate_set_settings`; the filament slots its filame icons and the plate menu. After every step it reads the plates back with `plate_list` and compares them whole with the state its entry in `test-entries/plates.md` writes out. -`tests/calibration.json` makes every calibration test with `calibration_generate_test` (each pressure advance method, -a 2 x 2 pattern batch, the four flow ratio passes) and checks the objects it added, the parameters -it used and the presets it changed, slicing some of them. It checks the temperature rounding, the -refusals that leave the project as it was (modified presets without `preset_changes`, an argument the test -does not take), `preset_changes: "keep"` keeping an edit, and `project_new` dropping the test's settings. It -starts from the harness's default printer and reruns on the same datadir. +`test_calibration.py` makes every calibration test with `calibration_generate_test` and checks the project it makes, +the parameters it uses, the presets and objects it changes, the warnings for values it rounds, and the refusals that +leave the project and presets as they were; `preset_changes` "keep" and "discard"; and, in the exported G-code, that +the temperature, pressure advance and retraction towers change their value band by band. -`tests/ops_open_project.json`, `ops_select_preset.json`, `ops_assign_filament_preset_one_slot.json` and -`ops_assign_filament_preset_multi_slot.json` drive an operation of the operations layer (`docs/HLSD/mcp-server.md`, -"The operations layer") through the routes that reach it: the command, a Speed Dial action run with `action_run` -where one runs it from a call, and, for presets, a pick in the sidebar and the plugin API called from a -`script_run` step. They open a project, select a printer or process preset, and assign a filament to a slot on a -printer with one slot and with several. 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. -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 `preset_select` shows stays shown until a restart. 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 `script_run` needs. - -`test_operation_routes.py` asserts what those replays only record: that a command, a Speed Dial action that -runs it and the plugin API's binding refuse the same states with the same code and words, and accept the +`test_operation_routes.py` drives an operation of the operations layer (`docs/HLSD/mcp-server.md`, "The operations +layer") through the routes that reach it, and checks that a command, a Speed Dial action that runs it and the plugin +API's binding refuse the same states with the same code and words, and accept the same ones: a layer asked of a Preview with none (the Go to layer action and `view_set`), a mixed-colour filament slot, and a hidden printer selected through the plugin API. It also checks what a command refuses or does in those states alone: a project saved under a `.gcode.3mf` name, the exports of a project with no -objects, and an arrangement from the assemble view and with a gizmo open. Run -it on a freshly launched app, for the reasons above and because the Preview keeps the last slice's -layers. +objects, and an arrangement from the assemble view and with a gizmo open. Run it on a freshly launched app, +since a hidden preset that `preset_select` shows stays shown until a restart, and 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 `script_run` needs. The Design-tab replays drive the Design commands through `tool_call` and need an instance launched with `--cad`. Each starts from a new project and checks what it builds by volume and by what the reading @@ -478,20 +432,13 @@ answers in `/log/debug_*.log.0`, with the reason when it cancels one a input reaches the app through wxWidgets, not the OS, so a focus problem that only a window manager causes is out of the tests' reach. -`tests/dialogs_canvas_input.json` checks that an auto-answered Transfer or Discard on the -unsaved-changes dialog does its work, that a toolbar item a selection just enabled takes a click at -once, and that a negative part, and a point seen through the bed from below, are click targets. - -`tests/context_menus.json` right-clicks a cube, the empty bed and two selected objects, and clicks a -preset edit button that opens a menu: each menu is listed in the reply, or an item of it run with -`popup_item` (a modifier, a primitive, Delete), and none is ever shown, so on macOS the run finishes -with nobody pressing Escape. It also picks the Edit menu's Undo and Redo by the paths `Edit>Undo` and -`Edit>Redo`, which name them on every platform, though macOS shows their keys after them. - -`tests/rows.json` drives rows and popups: object list rows (plates, an object and its parts, Ctrl -to add a row, the Printable column, a double click), the object's and a part's menus run from their -rows, Compare presets' rows, the object settings table, the print button's popup and the plate type -drop-down list. On Linux run it with `--headless`: under Xvfb those popups close as soon as they open. +`test_gui_tools.py` drives the generic GUI tools on the app's own widgets: context menus and a button's menu listed +in the reply, or an item of them run with `popup_item`, none ever shown, so on macOS the run finishes with nobody +pressing Escape; the Edit menu's Undo and Redo by the paths `Edit>Undo` and `Edit>Redo`, which name them on every +platform; the rows of the object list, Compare presets and the parameter table; the print button's popup and a +drop-down list; and Orca's web dialogs. Each item, row or page element it runs is checked by what it does to the +project, the selection, the camera or the settings. On Linux run it with `--headless`: under Xvfb those popups close +as soon as they open. `test_webview_modal.py` runs JavaScript in the web views of modal dialogs: the preset bundle dialog's page takes it by default and by locator, `webview_run_javascript` is refused in the Home tab's web view behind a @@ -500,7 +447,7 @@ dialog's does, and a page that closes its dialog replies `closed` at once. Web pages are driven like widgets: `widget_list` lists each shown page's elements under its web view with `d` refs, and `widget_click`, `widget_set_value`, `keyboard_press`, `mouse_gesture` and `dialog_answer` act on them, by -ref or by `{web: "Next", kind, css, within, index}`. `tests/web_dialogs.json` drives Orca's own web +ref or by `{web: "Next", kind, css, within, index}`. `test_gui_tools.py` drives Orca's own web dialogs that way alone: the preset bundle dialog, the colour picker behind a filament swatch (its hex field, and a drag on its spectrum) and the setup wizard's first steps. `test_web_ui.py` covers every kind of page control, action and what it changed on its page, refusal, locator, timeout and close on @@ -542,31 +489,22 @@ proved only where no pointer rests on the view: on a native Wayland display, or elsewhere. Where KWin runs the display, it also checks through KWin's D-Bus that KWin draws no title bar on the dial. -`tests/slice_stats.json` slices one cube, then two cubes in two colours, and checks the statistics of -`plate_slice`'s reply: layers, max Z, filament changes, and each filament slot's model, flush and -prime tower grams. - -`tests/preview.json` slices a cube and reads it back with `plate_slice_stats` (summary, feature and layer -tables, the object, the legend's state and colour ranges) and `app_state.preview` as `view_set` -changes the layer (by number and by height), the view type, legend rows and time estimate, then -reads the cube's G-code opened for viewing the same way. Run it on a fresh datadir: modified presets -left by an earlier replay make opening the G-code ask about them. `test_set_view_preview.py` checks -what that replay cannot: `view_set {view_type}` acts as the legend's combo (a feature type hidden by -a click on its row shows again on Line Type, and the pick reaches the app config), a canvas -screenshot straight after a layer or view type change shows the new layers and the legend laid out -(it matches the capture after it), and the refusals of the preview arguments. +`test_set_view_preview.py` checks that `view_set {view_type}` acts as the legend's combo (a feature type hidden by a +click on its row shows again on Line Type, and the pick reaches the app config), that a canvas screenshot straight +after a layer or view type change shows the new layers and the legend laid out (it matches the capture after it), +and the refusals of the preview arguments. `test_set_view_camera.py`, on an instance launched with `--cad`, checks `view_set`'s `look_at` and `zoom` on Prepare, Preview and the Design tab, and `orbit` on Prepare and the Design tab, against the reply's `camera_state` and `app_state.camera`, including straight after `project_new`, whose fit runs at the next frame, and a fit on Prepare after the window was sized on the Home tab. -`tests/agent_forms.json` calls commands the way agents often write them: a lone path for `paths`, -`object` for `objects` with the index as a string, an action by the key inside its id, `action` for -`id`, a camera direction as `view_set`'s `canvas`, which is read as its `camera`, `object_transform` to a -`position`, `key` for `keys`, `app_wait` with no condition, a gizmo by its toolbar title, `plate` for -`plates`, legend rows in another case or with `_` for a space, and `project_export` with the format taken -from the path. It also checks that a type's whole `settings_list` listing leaves meta out. +`test_call_forms.py`, on an instance launched with `--cad`, calls commands the way agents often write them: a lone +path for `paths`, `object` for `objects` with the index as a string, an action by its short name, `action` for +`id`, a camera direction as `view_set`'s `canvas`, which is read as its `camera`, `key` for `keys`, `app_wait` with +no condition, a gizmo by its toolbar title, `plate` as a string, legend rows in another case or with `_` for a space, +and `project_export` with the format taken from the path, each shown by what the call did. It also checks that a +type's whole `settings_list` listing leaves meta out. `test_stdio_bridge.py [--bin PATH]` checks `orca-slicer --mcp-stdio` against the launched instance: the handshake, notifications, tool calls in both protocol eras, and errors. With no instance @@ -594,11 +532,11 @@ reads uploading at 99 until the stub answers and then completed in `app_state.up replay uploads again, and one the stub refuses with HTTP 500 never reads completed and ends as an error whose dialog `dialog_answer` closes. -`tests/actions_ask.json` and `test_person_forms.py` check a call with exactly an action's arguments, which may -ask as a person's pick of the action does: `calibration_generate_test {test}` asks in the test's dialog and with -`silent` runs with its defaults, View: Top turns the Design tab's camera, Go to tab and Go to layer take their -value through `action_run`, and the slice actions slice and show the Preview tab (the replay, on an instance -launched with `--cad`); `project_save {save_as: true}` and `project_export {format: gcode}` open their file +`test_call_forms.py` and `test_person_forms.py` check a call with exactly an action's arguments, which may ask +as a person's pick of the action does: `calibration_generate_test {test}` asks in the test's dialog and with +`silent` runs with its defaults, View: Top turns the camera of the view shown, Deselect All closes the open gizmo +too, Go to layer takes its value through `action_run`, and `plate_slice {preview: true}` slices and shows the +Preview tab (`test_call_forms.py`); `project_save {save_as: true}` and `project_export {format: gcode}` open their file pickers while a path writes without one, `preset_export` always opens its dialog, `object_arrange {}` and `object_select {all: true}` (and `action_run` of their actions) reply as their commands do, the selection in the assemble view's too, and the Speed Dial's own picks of a view action, Deselect All, Go to layer, Auto-Arrange and @@ -606,21 +544,12 @@ Select All Objects run in place (the script). `test_project_open_settings.py` launches its own app, whose Preferences load a project's geometry only, and checks that `project_open` loads the settings a project was saved with all the same. -The commands that do a menu item's job take their targets by index, and the replays call them so and read each -back: `tests/menu_items_objects.json` (rename, instances, separate, delete, height ranges), -`menu_items_structure.json` (split, assemble, change type, order) and `menu_items_placement.json` (add a -primitive by numbers, mirror, drop, centre, scale to fit, auto-orient), and `test_plates.py` the plate ones; -`objects_state.json` (`object_set_printable`, `object_fix`, `object_set_auto_drop`), `objects_files.json` -(`object_clone`, `object_reload_from_disk`, `part_replace`, with the files `tests/fixtures/objects_files.py` -writes), `objects_order.json` (`object_order {order}`), `filaments_and_files.json` (a slot merged into -another, a mixed filament, exports of some objects and of each object, a ZIP's entries, a STEP file), -`settings_targets.json` (`settings_list`, and the settings commands' targets object, part and height range), -`presets_and_plate_map.json` (`preset_list`'s filters, a plate's filament map, a nozzle variant) and -`view_switches.json` (`view_set`'s display switches, sidebar and legend, and an object placed by a plate's -`origin` and `size`). A replay cannot expect an error, so the refusals are Python tests: -`test_menu_items_refusals.py` checks that each object command made from menu items refuses with its own -reason, and `test_additions_refusals.py` the filament, preset, export and import commands'. -`test_preferences.py` checks +The commands that do a menu item's job take their targets by index, and `test_objects.py`, +`test_object_structure.py` and `test_plates.py` call them so and read each back. `test_menu_items_refusals.py` +checks that each object command made from menu items refuses with its own reason, and `test_additions_refusals.py` +the filament, preset, export and import commands'. `test_files.py` checks the project's files: a new project and its +question, opening, saving, importing models, every export read back from its file, and the filament slots a merge +and a mix leave in the project file. `test_preferences.py` checks `preferences_get` and `preferences_set` against the Preferences dialog, tab by tab. Some launch their own app, on a fresh data folder and printers the sweep does not seed: `test_install_printers.py` and `test_install_filaments.py` (installs and uninstalls, read back after a restart), `test_plugin_commands.py` @@ -643,7 +572,8 @@ and defaults to half the cores, up to six. It exits 0 when all of them pass and report appeared (macOS). `sweep.json` lists each test with what it needs, and a test file it does not list stops the run before anything starts, so a new test is never skipped by accident. Each test runs in a folder of its own under `--out` (by default a -new `orca-sweep-