Make canvas screenshots taken right after a layer or view type change show the change

This commit is contained in:
SoftFever committed 2026-11-01 17:39:07 +08:00
1 parent 55bc33dad3
commit 39705d7bb9
5 files changed
+78 -14

No files matched your search

+8 -3
View File
@@ -1891,7 +1891,10 @@ dialog natively; cross-origin frames other than plugin configuration UIs are lis
- `canvas`: the visible 3D view, the Design view while the Design tab is shown, exactly as drawn,
toolbars and ImGui panels included (the Design view's sketch overlay and status line too), on
every platform. `GLCanvas3D::render_and_capture()` forces a frame and reads the back buffer just
before the swap; it fails, saying why, when the canvas is hidden or mid-frame.
before the swap; it fails, saying why, when the canvas is hidden or mid-frame. That frame is often
the first since a tool's change, yet it shows the change settled, since slider moves reach the
toolpaths before they are drawn and the capture first draws any extra frames the change asked for:
a capture right after `set_view` shows the layers its slider shows and the legend laid out.
- `window`: the main window's own pixels, never the screen, from `capture_native_window()`, with
every visible 3D canvas composited in from its canvas capture, since window capture loses OpenGL
content on several platforms.
@@ -1962,7 +1965,8 @@ Wayland, where the app can't know where its windows are, dialogs are not composi
`note` says which applies. The `canvas` target is `shown_canvas()`. A recording captures with
`CaptureOptions::hide_covering` off, so X11 never hides and re-shows the script runner at each frame.
The costly part is a 3D view: `render_and_capture()` draws a frame and reads it back. A recording
The costly part is a 3D view: `render_and_capture()` draws a frame, after any extra frames a change
asked for, and reads it back. A recording
keeps each canvas's last capture with `GLCanvas3D::presented_frames()`, which counts the frames the
canvas presented, and its size and the UI generation; while all three are unchanged, the frame on
screen is the kept one, so the canvas is drawn only when it changed. Each tick measures its capture
@@ -2448,7 +2452,8 @@ closes its dialog, `tools/mcp/tests/web_dialogs.json` the preset bundle 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
legend combo's semantics of `set_view {view_type}` and its preview refusals,
legend combo's semantics of `set_view {view_type}`, a canvas screenshot straight after a layer or
view type change, and the preview refusals of `set_view`,
`tools/mcp/test_export_running_job.py` an export during and after a job that outlived its reply,
`tools/mcp/test_send_gcode.py` `send_gcode` and `get_state.uploads` against a stub print host that
answers 200 or 500,
+33 -5
View File
@@ -2564,6 +2564,17 @@ bool GLCanvas3D::render_and_capture(wxImage& out, std::string& err)
err = "The 3D view is not shown; switch to its tab first";
return false;
}
// A change that takes more than one frame to show, such as an ImGui window sizing itself to new
// content, asks for extra frames, which the idle loop draws next. A capture is often the first frame
// after the change, so it first draws those frames as the idle loop does, redrawing the scene only
// when something asked for it: a few at most, since a fading tooltip keeps asking.
ImGuiWrapper& imgui = *wxGetApp().imgui();
for (int i = 0; i < 3 && (m_extra_frame_requested || imgui.requires_extra_frame()); ++i) {
const bool scene_dirty = m_dirty || m_extra_frame_requested;
m_dirty = m_extra_frame_requested = false;
imgui.reset_requires_extra_frame();
_refresh_if_shown_on_screen(scene_dirty);
}
out = wxImage();
m_frame_capture = &out;
Slic3r::ScopeGuard reset([this]() { m_frame_capture = nullptr; });
@@ -2666,6 +2677,13 @@ void GLCanvas3D::_render_frame(bool scene_dirty, bool only_init)
if (_update_inactive_plates_visibility())
scene_dirty = true;
// Only the Preview showing G-code draws the sliders and toolpaths.
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())
scene_dirty = true;
if (m_picking_enabled && !m_benchmarking) {
if (m_rectangle_selection.is_dragging())
// picking pass using rectangle selection
@@ -2701,7 +2719,7 @@ void GLCanvas3D::_render_frame(bool scene_dirty, bool only_init)
m_render_stats.increment_scene_fps_counter();
}
if (m_canvas_type == ECanvasType::CanvasPreview && m_render_preview) {
if (render_gcode) {
// BBS: GUI refactor: add canvas size as parameters
_render_gcode_overlay(cnv_size.get_width(), cnv_size.get_height());
m_frame_profiler.mark("legend");
@@ -10103,25 +10121,35 @@ bool GLCanvas3D::_bind_gcode_shadow_map(bool bind) const
void GLCanvas3D::_render_gcode_overlay(int canvas_width, int canvas_height)
{
m_gcode_viewer.render_overlay(canvas_width, canvas_height, SLIDER_RIGHT_MARGIN * GCODE_VIEWER_SLIDER_SCALE);
IMSlider *layers_slider = m_gcode_viewer.get_layers_slider();
IMSlider *moves_slider = m_gcode_viewer.get_moves_slider();
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())
post_event(SimpleEvent(EVT_GLCANVAS_UPDATE));
}
bool GLCanvas3D::_apply_gcode_sliders()
{
IMSlider *layers_slider = m_gcode_viewer.get_layers_slider();
IMSlider *moves_slider = m_gcode_viewer.get_moves_slider();
bool moved = false;
if (layers_slider->is_dirty()) {
set_volumes_z_range({layers_slider->GetLowerValueD(), layers_slider->GetHigherValueD()});
if (m_gcode_viewer.has_data()) {
m_gcode_viewer.set_layers_z_range({static_cast<unsigned int>(layers_slider->GetLowerValue()), static_cast<unsigned int>(layers_slider->GetHigherValue())});
}
layers_slider->set_as_dirty(false);
post_event(SimpleEvent(EVT_GLCANVAS_UPDATE));
moved = true;
}
if (moves_slider->is_dirty()) {
moves_slider->set_as_dirty(false);
m_gcode_viewer.update_sequential_view_current((moves_slider->GetLowerValueD() - 1.0), static_cast<unsigned int>(moves_slider->GetHigherValueD() - 1.0));
post_event(SimpleEvent(EVT_GLCANVAS_UPDATE));
moved = true;
}
return moved;
}
void GLCanvas3D::send_layer_ticks_changes()
+5 -3
View File
@@ -1169,9 +1169,9 @@ public:
void render(bool only_init = false);
// Draws a full frame now and copies it, as presented (scene, toolpaths, toolbars and ImGui
// overlays), into `out` at the canvas's pixel size. Used by automation screenshots. Fails with
// `err` when the canvas is hidden, not drawable, or already inside a frame (a dialog opened
// from one of its panels). UI thread.
// overlays), into `out` at the canvas's pixel size, after any extra frames a change asked for to
// settle. Used by automation screenshots. Fails with `err` when the canvas is hidden, not
// drawable, or already inside a frame (a dialog opened from one of its panels). UI thread.
bool render_and_capture(wxImage& out, std::string& err);
// How many frames this canvas has presented. While it stays the same, the frame on screen is the last
// one presented, so a recording can reuse its capture of it instead of drawing another.
@@ -1598,6 +1598,8 @@ 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();
//BBS: render a plane for assemble
void _render_plane() const;
void _render_selection();
+3 -2
View File
@@ -278,8 +278,9 @@ changes the layer (by number and by height), the view type, legend rows and time
reads the cube's G-code opened for viewing the same way. Run it on a fresh datadir: modified presets
left by an earlier script make opening the G-code ask about them. `test_set_view_preview.py` checks
what that script cannot: `set_view {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), and the refusals
of the preview arguments.
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.
`tests/agent_forms.json` calls tools 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
+29 -1
View File
@@ -6,7 +6,9 @@
Picking a view type is the legend combo's pick: a feature type hidden by a click on its legend row
shows again when Line Type is picked, and the pick is written to the app config for the "Last used"
preview default. The refusals: legend rows before a slice, a height above the top layer, layer with
preview default. A canvas screenshot taken straight after a layer change shows the new layers, not
the previous ones under the new slider position, and one after a view type change shows the legend
laid out for it. The refusals: legend rows before a slice, a height above the top layer, layer with
layer_z, an unknown legend row (named with the rows the print has), a value that is not true or
false, and a silent-mode estimate the print does not have; a refused call changes nothing. Exits 0
when every check passes.
@@ -75,6 +77,32 @@ def main():
check("picking Line Type shows it again", legend()["features"]["Sparse infill"] is True)
check("Line Type is remembered", last_view_type("feature_type") == "feature_type", last_view_type("feature_type"))
# Each change is captured twice. One script runs the calls back to back, which seldom leaves the app
# an idle frame between a change and its first capture to draw the change before the capture does.
# The last view type is the one picked above.
out_dir = os.path.join(session["datadir"], "set_view_captures")
changes = [{"layer_range": [1, 40]}, {"view_type": "speed"}, {"layer_range": [64, 64]}, {"view_type": "height"},
{"layer_range": [20, 100]}, {"view_type": "fan_speed"}, {"layer_range": [1, 128]}, {"view_type": "feature_type"}]
steps = []
for i, change in enumerate(changes):
steps.append({"tool": "set_view", "args": change})
steps += [{"tool": "screenshot", "args": {"target": "canvas", "save_path": f"${{out_dir}}/{i}{shot}.png",
"overwrite": True, "include_image": False}}
for shot in "ab"]
ran = client.await_job(client.call("run_script", script={"orca_script": 1, "name": "captures after view changes", "steps": steps},
out_dir=out_dir))
check("the capture script runs", ran.get("passed") is True, ran)
if ran.get("passed") is True:
def png(name):
with open(os.path.join(out_dir, name), "rb") as f:
return f.read()
a = [png(f"{i}a.png") for i in range(len(changes))]
b = [png(f"{i}b.png") for i in range(len(changes))]
stale = [c for c, first, second in zip(changes, a, b) if first != second]
unchanged = [c for c, first, before in zip(changes[1:], a[1:], b) if first == before]
check("a capture right after a layer or view type change shows it settled", not stale, f"stale after {stale}")
check("every change shows in the capture", not unchanged, f"unchanged after {unchanged}")
reply = client.call("set_view", legend={"Sparse infill": False, "travel": True}, layer_z=1.05)
check("layer_z between two tops shows up to the upper one", reply.get("layers") == [1, 6, 128] and reply.get("z") == [0.2, 1.2], reply)
check("the legend reply gives each row's state", reply.get("legend") == {"Sparse infill": False, "travel": True}, reply)