Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -21,9 +21,9 @@
# SOFTWARE.
"""Provides a wrapper to aid in plotting."""
from abc import abstractmethod
import importlib.util

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 +32,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 +53,11 @@
from ansys.tools.visualization_interface.utils.color import Color
from ansys.tools.visualization_interface.utils.logger import logger

_HAS_TRAME = importlib.util.find_spec("pyvista.trame") and importlib.util.find_spec("trame.app")

if TYPE_CHECKING:
import numpy as np


class PyVistaBackendInterface(BaseBackend):
"""Provides the interface for the Visualization Interface Tool plotter.
Expand Down Expand Up @@ -193,7 +194,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 @@ -463,6 +464,9 @@ def show_plotter(self, screenshot: Optional[str] = None) -> None:

"""
if self._use_trame and _HAS_TRAME:
from ansys.tools.visualization_interface.backends.pyvista.trame_local import (
TrameVisualizer,
)
visualizer = TrameVisualizer()
visualizer.set_scene(self._pl)
visualizer.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Provides `trame <https://kitware.github.io/trame/index.html>`_ visualizer interface for visualization."""

try:
from pyvista.trame.ui import plotter_ui
from trame.app import get_server
Expand Down
Loading