Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/179.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: Reduce import time of the library
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"""Provides a wrapper to aid in plotting."""
from abc import abstractmethod

from beartype.typing import Any, Dict, List, Optional, Union
import numpy as np
from beartype.typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
import pyvista as pv
from vtkmodules.vtkCommonCore import vtkCommand
from vtkmodules.vtkInteractionWidgets import vtkHoverWidget
Expand All @@ -32,10 +31,6 @@
import ansys.tools.visualization_interface
from ansys.tools.visualization_interface.backends._base import BaseBackend
from ansys.tools.visualization_interface.backends.pyvista.pyvista_interface import PyVistaInterface
from ansys.tools.visualization_interface.backends.pyvista.trame_local import (
_HAS_TRAME,
TrameVisualizer,
)
from ansys.tools.visualization_interface.backends.pyvista.widgets.displace_arrows import (
CameraPanDirection,
DisplacementArrow,
Expand All @@ -57,6 +52,9 @@
from ansys.tools.visualization_interface.utils.color import Color
from ansys.tools.visualization_interface.utils.logger import logger

if TYPE_CHECKING:
import numpy as np


class PyVistaBackendInterface(BaseBackend):
"""Provides the interface for the Visualization Interface Tool plotter.
Expand Down Expand Up @@ -131,6 +129,8 @@ def __init__(
self._origin_colors = {}

# Enable the use of trame if requested and available
from ansys.tools.visualization_interface.backends.pyvista.trame_local import _HAS_TRAME

if self._use_trame and _HAS_TRAME:
# avoids GUI window popping up
pv.OFF_SCREEN = True
Expand Down Expand Up @@ -193,7 +193,7 @@ def add_widget(self, widget: Union[PlotterWidget, List[PlotterWidget]]):
self._widgets.append(widget)
widget.update()

def select_object(self, custom_object: Union[MeshObjectPlot, EdgePlot], pt: np.ndarray) -> None:
def select_object(self, custom_object: Union[MeshObjectPlot, EdgePlot], pt: "np.ndarray") -> None:
"""Select a custom object in the plotter.

This method highlights the edges of a body and adds a label. It also adds
Expand Down Expand Up @@ -462,7 +462,13 @@ def show_plotter(self, screenshot: Optional[str] = None) -> None:
Path for saving a screenshot of the image that is being represented.

"""
from ansys.tools.visualization_interface.backends.pyvista.trame_local import (
_HAS_TRAME,
TrameVisualizer,
)

if self._use_trame and _HAS_TRAME:

visualizer = TrameVisualizer()
visualizer.set_scene(self._pl)
visualizer.show()
Expand Down
Loading