|
22 | 22 | """Provides a wrapper to aid in plotting.""" |
23 | 23 | from abc import abstractmethod |
24 | 24 |
|
25 | | -from beartype.typing import Any, Dict, List, Optional, Union |
26 | | -import numpy as np |
| 25 | +from beartype.typing import TYPE_CHECKING, Any, Dict, List, Optional, Union |
27 | 26 | import pyvista as pv |
28 | 27 | from vtkmodules.vtkCommonCore import vtkCommand |
29 | 28 | from vtkmodules.vtkInteractionWidgets import vtkHoverWidget |
|
32 | 31 | import ansys.tools.visualization_interface |
33 | 32 | from ansys.tools.visualization_interface.backends._base import BaseBackend |
34 | 33 | from ansys.tools.visualization_interface.backends.pyvista.pyvista_interface import PyVistaInterface |
35 | | -from ansys.tools.visualization_interface.backends.pyvista.trame_local import ( |
36 | | - _HAS_TRAME, |
37 | | - TrameVisualizer, |
38 | | -) |
39 | 34 | from ansys.tools.visualization_interface.backends.pyvista.widgets.displace_arrows import ( |
40 | 35 | CameraPanDirection, |
41 | 36 | DisplacementArrow, |
|
57 | 52 | from ansys.tools.visualization_interface.utils.color import Color |
58 | 53 | from ansys.tools.visualization_interface.utils.logger import logger |
59 | 54 |
|
| 55 | +if TYPE_CHECKING: |
| 56 | + import numpy as np |
| 57 | + |
60 | 58 |
|
61 | 59 | class PyVistaBackendInterface(BaseBackend): |
62 | 60 | """Provides the interface for the Visualization Interface Tool plotter. |
@@ -131,6 +129,8 @@ def __init__( |
131 | 129 | self._origin_colors = {} |
132 | 130 |
|
133 | 131 | # Enable the use of trame if requested and available |
| 132 | + from ansys.tools.visualization_interface.backends.pyvista.trame_local import _HAS_TRAME |
| 133 | + |
134 | 134 | if self._use_trame and _HAS_TRAME: |
135 | 135 | # avoids GUI window popping up |
136 | 136 | pv.OFF_SCREEN = True |
@@ -193,7 +193,7 @@ def add_widget(self, widget: Union[PlotterWidget, List[PlotterWidget]]): |
193 | 193 | self._widgets.append(widget) |
194 | 194 | widget.update() |
195 | 195 |
|
196 | | - def select_object(self, custom_object: Union[MeshObjectPlot, EdgePlot], pt: np.ndarray) -> None: |
| 196 | + def select_object(self, custom_object: Union[MeshObjectPlot, EdgePlot], pt: "np.ndarray") -> None: |
197 | 197 | """Select a custom object in the plotter. |
198 | 198 |
|
199 | 199 | This method highlights the edges of a body and adds a label. It also adds |
@@ -462,7 +462,13 @@ def show_plotter(self, screenshot: Optional[str] = None) -> None: |
462 | 462 | Path for saving a screenshot of the image that is being represented. |
463 | 463 |
|
464 | 464 | """ |
| 465 | + from ansys.tools.visualization_interface.backends.pyvista.trame_local import ( |
| 466 | + _HAS_TRAME, |
| 467 | + TrameVisualizer, |
| 468 | + ) |
| 469 | + |
465 | 470 | if self._use_trame and _HAS_TRAME: |
| 471 | + |
466 | 472 | visualizer = TrameVisualizer() |
467 | 473 | visualizer.set_scene(self._pl) |
468 | 474 | visualizer.show() |
|
0 commit comments