Skip to content

Expose snapshot size to gRPC / rips clients#14042

Open
hakonhagland wants to merge 2 commits into
OPM:devfrom
hakonhagland:feature/grpc-set-snapshot-size
Open

Expose snapshot size to gRPC / rips clients#14042
hakonhagland wants to merge 2 commits into
OPM:devfrom
hakonhagland:feature/grpc-set-snapshot-size

Conversation

@hakonhagland
Copy link
Copy Markdown
Contributor

Adds a setSnapshotSize(width, height) scripting command so Python clients can request a specific snapshot resolution before exporting, instead of being stuck with whatever geometry Qt happens to give the plot widget.

Motivation: snapshots exported over gRPC (Instance.export_snapshots, PlotWindow.export_snapshot) render at the plot widget's current size. In offscreen mode that is typically much smaller than expected, because set_plot_window_size only resizes the outer RiuPlotMainWindow and leaves the MDI sub-windows at their original layout geometry. The --snapshotsize CLI flag already works around this via RiuMainWindowTools::setWindowSizeOnWidgetsInMdiWindows, but that helper had no scripting binding — so headless, rips-driven export had no way to control the output resolution.

Add setSnapshotSize gRPC command (commit 1)

  • New RicfSetSnapshotSize scriptable command in ApplicationLibCode/CommandFileInterface/, registered in CMakeLists_files.cmake.
  • Wraps the same RiuMainWindowTools::setWindowSizeOnWidgetsInMdiWindows helper the --snapshotsize CLI flag uses, and also resizes 3D views via setFixedWindowSizeFor3dViews, mirroring RiaGuiApplication.
  • Validates width/height > 0, returning a clear COMMAND_ERROR otherwise.
  • New setSnapshotSize entry in the CommandParams oneof in Commands.proto (tag 40); dispatch is automatic via the reflection-based command service, so no RiaGrpcCommandService change is needed.
  • A code comment documents the prerequisite: the caller must invoke set_plot_window_size first so the plots are realized inside MDI sub-windows; otherwise only the outer wrapper resizes and the inner qwt canvas stays anchored at its initial geometry.

Add Instance.set_snapshot_size to the rips Python client (commit 2)

  • New Instance.set_snapshot_size(width, height) wrapper mirroring the existing set_plot_window_size shape.
  • Docstring spells out the recommended call order for a filled snapshot: set_plot_window_size before creating plots → create plots → project.plots()set_snapshot_sizeexport_snapshot. (project.plots() can re-tile the MDI sub-windows back to defaults, so set_snapshot_size must come after it.)
  • Updates the headless_plot_export example to demonstrate the call.

Notes

Test plan

  • setSnapshotSize rejects width/height <= 0 with FAILED_PRECONDITION.
  • Headless export (-platform offscreen) after set_plot_window_size + set_snapshot_size(W, H) produces a W x H PNG with the plot filling the canvas (verified at 1600×1000 and 1000×800).
  • CI passes.

Snapshots exported via gRPC (rips Instance.export_snapshots,
PlotWindow.export_snapshot) use whatever geometry Qt happens to give
the plot widget at the time of export. In offscreen mode the widget
is typically much smaller than the user expects, because
set_plot_window_size resizes the outer RiuPlotMainWindow but leaves
the MDI sub-windows maximized at the original layout geometry.

The CLI --snapshotsize flag avoids this by calling
RiuMainWindowTools::setWindowSizeOnWidgetsInMdiWindows, which
un-maximizes each MDI sub-window and resizes the inner viewWidget to
the requested dimensions. This commit wraps the same helper as a
scripting command (setSnapshotSize) so Python clients can request a
specific snapshot resolution before calling export_snapshot.

Also handles 3D views via setFixedWindowSizeFor3dViews, mirroring
what --snapshotsize does in RiaGuiApplication.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Wraps the new setSnapshotSize gRPC command so callers can do

    ri.set_snapshot_size(1600, 1000)
    for plot in ri.project.plots():
        plot.export_snapshot(export_folder=...)

and get 1600x1000 PNGs back. Mirrors the existing
Instance.set_plot_window_size wrapper shape. The headless_plot_export
example is updated to demonstrate the call between plot creation and
the export_snapshot loop.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@hakonhagland hakonhagland force-pushed the feature/grpc-set-snapshot-size branch from 4de6fa7 to 898a847 Compare May 25, 2026 08:01
@magnesj
Copy link
Copy Markdown
Member

magnesj commented May 26, 2026

We are now working on replacing the MDI concept with docking widgets. The changes you suggest here will be revisited after this change is merged to dev.

#759

@jonjenssen
Copy link
Copy Markdown
Collaborator

Should be part of work done in #14056

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants