21
21
# SOFTWARE.
22
22
"""Provides a wrapper to aid in plotting."""
23
23
from abc import abstractmethod
24
- from enum import Enum
25
24
26
25
from beartype .typing import Any , Dict , List , Optional , Union
27
26
import numpy as np
59
58
from ansys .tools .visualization_interface .utils .logger import logger
60
59
61
60
62
- class PickingMode (Enum ):
63
- """Enumerate with the available picking modes."""
64
- PICK = "pick"
65
- HOVER = "hover"
66
-
67
-
68
61
class PyVistaBackendInterface (BaseBackend ):
69
62
"""Provides the interface for the Visualization Interface Tool plotter.
70
63
@@ -108,14 +101,12 @@ def __init__(
108
101
109
102
self ._use_trame = use_trame
110
103
self ._allow_picking = allow_picking
111
- if self ._allow_picking :
112
- if allow_hovering :
113
- logger .warning (
114
- "Picking and hovering are incompatible. Picking will take precedence."
115
- )
104
+ self ._allow_hovering = allow_hovering
105
+ if self . _allow_picking and self . _allow_hovering :
106
+ logger .warning (
107
+ "Picking and hovering are incompatible. Picking will take precedence."
108
+ )
116
109
self ._allow_hovering = False
117
- else :
118
- self ._allow_hovering = allow_hovering
119
110
self ._pv_off_screen_original = bool (pv .OFF_SCREEN )
120
111
self ._plot_picked_names = plot_picked_names
121
112
# Map that relates PyVista actors with PyAnsys objects
@@ -158,8 +149,8 @@ def __init__(
158
149
159
150
self ._enable_widgets = self ._pl ._enable_widgets
160
151
161
- self ._hover_picker = vtkPointPicker ()
162
- self ._hover_widget = vtkHoverWidget ()
152
+ self ._hover_picker = vtkPointPicker () if self . _allow_hovering else None
153
+ self ._hover_widget = vtkHoverWidget () if self . _allow_hovering else None
163
154
self ._added_hover_labels = []
164
155
165
156
@property
@@ -324,8 +315,10 @@ def hover_callback(self, _widget, event_name) -> None:
324
315
renderer = plotter .iren .get_poked_renderer (x , y )
325
316
self ._hover_picker .Pick (x , y , 0 , renderer )
326
317
actor = self ._hover_picker .GetActor ()
327
- if event_name == "TimerEvent" and actor is not None and actor in self ._object_to_actors_map :
318
+ if actor in self ._object_to_actors_map :
328
319
custom_object = self ._object_to_actors_map [actor ]
320
+ for label in self ._added_hover_labels :
321
+ self ._pl .scene .remove_actor (label )
329
322
label_actor = self ._pl .scene .add_point_labels (
330
323
[actor .GetCenter ()],
331
324
[custom_object .name ],
@@ -335,7 +328,7 @@ def hover_callback(self, _widget, event_name) -> None:
335
328
show_points = False ,
336
329
)
337
330
self ._added_hover_labels .append (label_actor )
338
- elif event_name == "EndInteractionEvent" :
331
+ else :
339
332
for label in self ._added_hover_labels :
340
333
self ._pl .scene .remove_actor (label )
341
334
@@ -416,8 +409,8 @@ def show(
416
409
417
410
"""
418
411
self .plot (plottable_object , name_filter , ** plotting_options )
419
- if self ._pl ._object_to_actors_map :
420
- self ._object_to_actors_map = self ._pl ._object_to_actors_map
412
+ if self ._pl .object_to_actors_map :
413
+ self ._object_to_actors_map = self ._pl .object_to_actors_map
421
414
else :
422
415
logger .warning ("No actors were added to the plotter." )
423
416
0 commit comments