|
| 1 | +""" |
| 2 | +Streamed-render protocols |
| 3 | +========================= |
| 4 | +The names a streamed view's renderer, window, loop bridge and state publisher |
| 5 | +share, kept apart from :mod:`ansys.visor.viewer.renderer.server_renderer` so |
| 6 | +that importing them does not import the off-screen VTK pipeline. |
| 7 | +""" |
| 8 | + |
| 9 | +from __future__ import annotations |
| 10 | + |
| 11 | +from typing import TYPE_CHECKING, Protocol |
| 12 | + |
| 13 | +from ansys.visor.viewer.models.common.visor_camera_state import VisorCameraState |
| 14 | +from ansys.visor.viewer.models.common.visor_cross_section_state import VisorCrossSectionState |
| 15 | + |
| 16 | +if TYPE_CHECKING: |
| 17 | + from vtkmodules.vtkRenderingCore import vtkRenderWindow |
| 18 | + |
| 19 | +INITIAL_WINDOW_SIZE: tuple[int, int] = (300, 300) |
| 20 | +"""Window size before the client reports its canvas; trame-rca's pre-resize image size.""" |
| 21 | + |
| 22 | +BACKGROUND_RGB: dict[bool, tuple[float, float, float]] = { |
| 23 | + False: (247 / 255, 247 / 255, 247 / 255), |
| 24 | + True: (54 / 255, 60 / 255, 67 / 255), |
| 25 | +} |
| 26 | +"""Viewer background per theme, keyed on dark. |
| 27 | +
|
| 28 | +The values of ``--visor-viewer-background`` in the client's |
| 29 | +``public/css/theme-light.css`` and ``public/css/theme-dark.css``. |
| 30 | +""" |
| 31 | + |
| 32 | + |
| 33 | +class FrameRequester(Protocol): |
| 34 | + """Where a ServerRenderer asks for a streamed frame.""" |
| 35 | + |
| 36 | + def request_frame(self) -> None: |
| 37 | + """Ask for a streamed frame; callable from any thread.""" |
| 38 | + |
| 39 | + |
| 40 | +class ViewRecordPublisher(Protocol): |
| 41 | + """Where a ServerRenderer publishes its camera and cross-section plane records.""" |
| 42 | + |
| 43 | + def publish_camera(self, camera_state: VisorCameraState | None) -> None: |
| 44 | + """Publish the camera record to clients, or None when there is none; callable from any thread.""" |
| 45 | + |
| 46 | + def publish_cross_section(self, cross_section_state: VisorCrossSectionState | None) -> None: |
| 47 | + """Publish the plane record to clients, or None when there is none; callable from any thread.""" |
| 48 | + |
| 49 | + |
| 50 | +class RcaRenderTarget(Protocol): |
| 51 | + """The renderer surface VisorRcaWindow captures from and resizes.""" |
| 52 | + |
| 53 | + @property |
| 54 | + def render_window(self) -> vtkRenderWindow: |
| 55 | + """The window the capture reads and releases.""" |
| 56 | + |
| 57 | + @property |
| 58 | + def background_rgb(self) -> tuple[float, float, float]: |
| 59 | + """The colour the placeholder frame is filled with.""" |
| 60 | + |
| 61 | + def set_viewport_size(self, width: int, height: int) -> None: |
| 62 | + """Resize to the client canvas in device pixels.""" |
| 63 | + |
| 64 | + def set_pixel_scale(self, pixel_scale: float) -> None: |
| 65 | + """Take the client's device pixels per CSS pixel.""" |
| 66 | + |
| 67 | + def record_pipeline_camera(self) -> None: |
| 68 | + """Record and publish the camera after a gesture; caller holds the lock.""" |
| 69 | + |
| 70 | + def record_cross_section_plane(self) -> None: |
| 71 | + """Record and publish a dragged plane after a gesture; caller holds the lock.""" |
0 commit comments