Skip to content

Commit

Permalink
fix: Hovering issues (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
AlejandroFernandezLuces and pyansys-ci-bot authored Jul 22, 2024
1 parent 7643914 commit 447cbff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/104.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: Hovering issues
33 changes: 13 additions & 20 deletions src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# SOFTWARE.
"""Provides a wrapper to aid in plotting."""
from abc import abstractmethod
from enum import Enum

from beartype.typing import Any, Dict, List, Optional, Union
import numpy as np
Expand Down Expand Up @@ -59,12 +58,6 @@
from ansys.tools.visualization_interface.utils.logger import logger


class PickingMode(Enum):
"""Enumerate with the available picking modes."""
PICK = "pick"
HOVER = "hover"


class PyVistaBackendInterface(BaseBackend):
"""Provides the interface for the Visualization Interface Tool plotter.
Expand Down Expand Up @@ -108,14 +101,12 @@ def __init__(

self._use_trame = use_trame
self._allow_picking = allow_picking
if self._allow_picking:
if allow_hovering:
logger.warning(
"Picking and hovering are incompatible. Picking will take precedence."
)
self._allow_hovering = allow_hovering
if self._allow_picking and self._allow_hovering:
logger.warning(
"Picking and hovering are incompatible. Picking will take precedence."
)
self._allow_hovering = False
else:
self._allow_hovering = allow_hovering
self._pv_off_screen_original = bool(pv.OFF_SCREEN)
self._plot_picked_names = plot_picked_names
# Map that relates PyVista actors with PyAnsys objects
Expand Down Expand Up @@ -158,8 +149,8 @@ def __init__(

self._enable_widgets = self._pl._enable_widgets

self._hover_picker = vtkPointPicker()
self._hover_widget = vtkHoverWidget()
self._hover_picker = vtkPointPicker() if self. _allow_hovering else None
self._hover_widget = vtkHoverWidget() if self. _allow_hovering else None
self._added_hover_labels = []

@property
Expand Down Expand Up @@ -324,8 +315,10 @@ def hover_callback(self, _widget, event_name) -> None:
renderer = plotter.iren.get_poked_renderer(x, y)
self._hover_picker.Pick(x, y, 0, renderer)
actor = self._hover_picker.GetActor()
if event_name == "TimerEvent" and actor is not None and actor in self._object_to_actors_map:
if actor in self._object_to_actors_map:
custom_object = self._object_to_actors_map[actor]
for label in self._added_hover_labels:
self._pl.scene.remove_actor(label)
label_actor = self._pl.scene.add_point_labels(
[actor.GetCenter()],
[custom_object.name],
Expand All @@ -335,7 +328,7 @@ def hover_callback(self, _widget, event_name) -> None:
show_points=False,
)
self._added_hover_labels.append(label_actor)
elif event_name == "EndInteractionEvent":
else:
for label in self._added_hover_labels:
self._pl.scene.remove_actor(label)

Expand Down Expand Up @@ -416,8 +409,8 @@ def show(
"""
self.plot(plottable_object, name_filter, **plotting_options)
if self._pl._object_to_actors_map:
self._object_to_actors_map = self._pl._object_to_actors_map
if self._pl.object_to_actors_map:
self._object_to_actors_map = self._pl.object_to_actors_map
else:
logger.warning("No actors were added to the plotter.")

Expand Down

0 comments on commit 447cbff

Please sign in to comment.