Skip to content

Commit

Permalink
fix(vtkEvent): properly handle vtk views events
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Apr 27, 2022
1 parent 7885183 commit 7d85420
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 9 deletions.
87 changes: 86 additions & 1 deletion examples/VTK/SimpleCone/RemoteRendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,92 @@ def update_reset_resolution():
# GUI
# -----------------------------------------------------------------------------

html_view = vtk.VtkRemoteView(renderWindow, ref="view")

def event(*args, **kwargs):
print("event", args, kwargs)


html_view = vtk.VtkRemoteView(
renderWindow,
ref="view",
interactor_events=(
"event_types",
[
"StartAnimation",
"Animation",
"EndAnimation",
"MouseEnter",
"MouseLeave",
"StartMouseMove",
"MouseMove",
"EndMouseMove",
"LeftButtonPress",
"LeftButtonRelease",
"MiddleButtonPress",
"MiddleButtonRelease",
"RightButtonPress",
"RightButtonRelease",
"KeyPress",
"KeyDown",
"KeyUp",
"StartMouseWheel",
"MouseWheel",
"EndMouseWheel",
"StartPinch",
"Pinch",
"EndPinch",
"StartPan",
"Pan",
"EndPan",
"StartRotate",
"Rotate",
"EndRotate",
"Button3D",
"Move3D",
"StartPointerLock",
"EndPointerLock",
"StartInteraction",
"Interaction",
"EndInteraction",
],
),
StartAnimation=(event, "[vtkEvent($event)]"),
Animation=(event, "[vtkEvent($event)]"),
EndAnimation=(event, "[vtkEvent($event)]"),
MouseEnter=(event, "[vtkEvent($event)]"),
MouseLeave=(event, "[vtkEvent($event)]"),
StartMouseMove=(event, "[vtkEvent($event)]"),
MouseMove=(event, "[vtkEvent($event)]"),
EndMouseMove=(event, "[vtkEvent($event)]"),
LeftButtonPress=(event, "[vtkEvent($event)]"),
LeftButtonRelease=(event, "[vtkEvent($event)]"),
MiddleButtonPress=(event, "[vtkEvent($event)]"),
MiddleButtonRelease=(event, "[vtkEvent($event)]"),
RightButtonPress=(event, "[vtkEvent($event)]"),
RightButtonRelease=(event, "[vtkEvent($event)]"),
KeyPress=(event, "[vtkEvent($event)]"),
KeyDown=(event, "[vtkEvent($event)]"),
KeyUp=(event, "[vtkEvent($event)]"),
StartMouseWheel=(event, "[vtkEvent($event)]"),
MouseWheel=(event, "[vtkEvent($event)]"),
EndMouseWheel=(event, "[vtkEvent($event)]"),
StartPinch=(event, "[vtkEvent($event)]"),
Pinch=(event, "[vtkEvent($event)]"),
EndPinch=(event, "[vtkEvent($event)]"),
StartPan=(event, "[vtkEvent($event)]"),
Pan=(event, "[vtkEvent($event)]"),
EndPan=(event, "[vtkEvent($event)]"),
StartRotate=(event, "[vtkEvent($event)]"),
Rotate=(event, "[vtkEvent($event)]"),
EndRotate=(event, "[vtkEvent($event)]"),
Button3D=(event, "[vtkEvent($event)]"),
Move3D=(event, "[vtkEvent($event)]"),
StartPointerLock=(event, "[vtkEvent($event)]"),
EndPointerLock=(event, "[vtkEvent($event)]"),
StartInteraction=(event, "[tkEvent($event)']"),
Interaction=(event, "[vtkEvent($event)]"),
EndInteraction=(event, "[vtkEvent($event)]"),
)

layout = SinglePage("VTK Remote rendering", on_ready=update_cone)
layout.logo.click = html_view.reset_camera
Expand Down
165 changes: 157 additions & 8 deletions trame/html/vtk/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,48 @@ def __init__(self, view, enable_rendering=True, **kwargs):
"context_name",
"interactive_quality",
"interactive_ratio",
"interactor_events",
("interactor_events", "interactorEvents"),
"interactor_settings",
("box_selection", "boxSelection"),
]
self._event_names += kwargs.get("interactor_events", [])
self._event_names += [
("box_selection_change", "BoxSelection"),
"StartAnimation",
"Animation",
"EndAnimation",
"MouseEnter",
"MouseLeave",
"StartMouseMove",
"MouseMove",
"EndMouseMove",
"LeftButtonPress",
"LeftButtonRelease",
"MiddleButtonPress",
"MiddleButtonRelease",
"RightButtonPress",
"RightButtonRelease",
"KeyPress",
"KeyDown",
"KeyUp",
"StartMouseWheel",
"MouseWheel",
"EndMouseWheel",
"StartPinch",
"Pinch",
"EndPinch",
"StartPan",
"Pan",
"EndPan",
"StartRotate",
"Rotate",
"EndRotate",
"Button3D",
"Move3D",
"StartPointerLock",
"EndPointerLock",
"StartInteraction",
"Interaction",
"EndInteraction",
]

def update_geometry(self, reset_camera=False):
Expand Down Expand Up @@ -260,7 +295,9 @@ def replace_view(self, new_view, **kwargs):
state[self.__view_key_id] = MODULE.id(new_view)
_mode = state[self.__mode_key]
self.__view = new_view
self.__wrapped_view = MODULE.view(new_view, name=self.__namespace, mode=_mode, force_replace=True)
self.__wrapped_view = MODULE.view(
new_view, name=self.__namespace, mode=_mode, force_replace=True
)
self.update()
self.resize()

Expand Down Expand Up @@ -320,12 +357,47 @@ def __init__(self, view, ref="view", **kwargs):
"enable_picking",
"interactive_quality",
"interactive_ratio",
"interactor_events",
("interactor_events", "interactorEvents"),
("box_selection", "boxSelection"),
]
self._event_names += kwargs.get("interactor_events", [])
self._event_names += [
("box_selection_change", "BoxSelection"),
"StartAnimation",
"Animation",
"EndAnimation",
"MouseEnter",
"MouseLeave",
"StartMouseMove",
"MouseMove",
"EndMouseMove",
"LeftButtonPress",
"LeftButtonRelease",
"MiddleButtonPress",
"MiddleButtonRelease",
"RightButtonPress",
"RightButtonRelease",
"KeyPress",
"KeyDown",
"KeyUp",
"StartMouseWheel",
"MouseWheel",
"EndMouseWheel",
"StartPinch",
"Pinch",
"EndPinch",
"StartPan",
"Pan",
"EndPan",
"StartRotate",
"Rotate",
"EndRotate",
"Button3D",
"Move3D",
"StartPointerLock",
"EndPointerLock",
"StartInteraction",
"Interaction",
"EndInteraction",
]

def update(self, **kwargs):
Expand All @@ -346,6 +418,7 @@ def replace_view(self, new_view, **kwargs):
def resize(self, **kwargs):
self.__app.update(ref=self.__ref, method="resize")


class VtkShareDataset(AbstractElement):
def __init__(self, children=None, **kwargs):
super().__init__("vtk-share-dataset", children, **kwargs)
Expand Down Expand Up @@ -382,14 +455,49 @@ def __init__(self, view, ref="view", **kwargs):
self._attributes["ref"] = f'ref="{ref}"'
self._attributes["view_state"] = f':viewState="{self.__scene_id}"'
self._attr_names += [
"interactor_events",
("interactor_events", "interactorEvents"),
"interactor_settings",
"context_name",
("box_selection", "boxSelection"),
]
self._event_names += kwargs.get("interactor_events", [])
self._event_names += [
("box_selection_change", "BoxSelection"),
"StartAnimation",
"Animation",
"EndAnimation",
"MouseEnter",
"MouseLeave",
"StartMouseMove",
"MouseMove",
"EndMouseMove",
"LeftButtonPress",
"LeftButtonRelease",
"MiddleButtonPress",
"MiddleButtonRelease",
"RightButtonPress",
"RightButtonRelease",
"KeyPress",
"KeyDown",
"KeyUp",
"StartMouseWheel",
"MouseWheel",
"EndMouseWheel",
"StartPinch",
"Pinch",
"EndPinch",
"StartPan",
"Pan",
"EndPan",
"StartRotate",
"Rotate",
"EndRotate",
"Button3D",
"Move3D",
"StartPointerLock",
"EndPointerLock",
"StartInteraction",
"Interaction",
"EndInteraction",
]
self.update()

Expand All @@ -409,7 +517,11 @@ def reset_camera(self, **kwargs):

def replace_view(self, new_view, **kwargs):
self.__view = new_view
self.__app.update(ref=self.__ref, method="setSynchronizedViewId", args=f"[{MODULE.id(new_view)}]")
self.__app.update(
ref=self.__ref,
method="setSynchronizedViewId",
args=f"[{MODULE.id(new_view)}]",
)
self.update()

def resize(self, **kwargs):
Expand All @@ -424,6 +536,7 @@ def __init__(self, children=None, ref="view", **kwargs):
self._attr_names += [
"background",
"cube_axes_style",
("interactor_events", "interactorEvents"),
"interactor_settings",
"picking_modes",
"show_cube_axes",
Expand All @@ -433,6 +546,42 @@ def __init__(self, children=None, ref="view", **kwargs):
"click",
"select",
"resize",
"StartAnimation",
"Animation",
"EndAnimation",
"MouseEnter",
"MouseLeave",
"StartMouseMove",
"MouseMove",
"EndMouseMove",
"LeftButtonPress",
"LeftButtonRelease",
"MiddleButtonPress",
"MiddleButtonRelease",
"RightButtonPress",
"RightButtonRelease",
"KeyPress",
"KeyDown",
"KeyUp",
"StartMouseWheel",
"MouseWheel",
"EndMouseWheel",
"StartPinch",
"Pinch",
"EndPinch",
"StartPan",
"Pan",
"EndPan",
"StartRotate",
"Rotate",
"EndRotate",
"Button3D",
"Move3D",
"StartPointerLock",
"EndPointerLock",
"StartInteraction",
"Interaction",
"EndInteraction",
]

def reset_camera(self, **kwargs):
Expand Down

0 comments on commit 7d85420

Please sign in to comment.