diff --git a/doc/changelog.d/846.added.md b/doc/changelog.d/846.added.md new file mode 100644 index 000000000..43db8a47d --- /dev/null +++ b/doc/changelog.d/846.added.md @@ -0,0 +1 @@ +Feat: Integrate ansys visualization tool \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 62f3be9ec..7037610f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,7 +80,7 @@ doc = [ "sphinxemoji==0.3.1", ] viz = [ - "pyvista>=0.39.1", + "ansys-tools-visualization-interface>=0.2.6", "usd-core==24.8", ] @@ -255,4 +255,18 @@ passenv = * extras = doc commands = sphinx-build -d "{toxworkdir}/doc_doctree" doc/source "{toxinidir}/doc/_build/html" --color -vW -bhtml -""" \ No newline at end of file +""" +[[tool.towncrier.type]] +directory = "documentation" +name = "Documentation" +showcontent = true + +[[tool.towncrier.type]] +directory = "maintenance" +name = "Maintenance" +showcontent = true + +[[tool.towncrier.type]] +directory = "test" +name = "Test" +showcontent = true diff --git a/src/ansys/mechanical/core/embedding/app.py b/src/ansys/mechanical/core/embedding/app.py index fc9b8e713..69c464549 100644 --- a/src/ansys/mechanical/core/embedding/app.py +++ b/src/ansys/mechanical/core/embedding/app.py @@ -34,13 +34,13 @@ from ansys.mechanical.core.embedding.warnings import connect_warnings, disconnect_warnings try: - import pyvista # noqa: F401 + import ansys.tools.visualization_interface # noqa: F401 - HAS_PYVISTA = True + HAS_ANSYS_VIZ = True """Whether or not PyVista exists.""" except: - HAS_PYVISTA = False + HAS_ANSYS_VIZ = False def _get_default_addin_configuration() -> AddinConfiguration: @@ -229,13 +229,9 @@ def execute_script(self, script: str) -> typing.Any: rets = None return self.script_engine.ExecuteCode(script, SCRIPT_SCOPE, light_mode, args, rets) - def plot(self) -> None: - """Visualize the model in 3d. - - Requires installation using the viz option. E.g. - pip install ansys-mechanical-core[viz] - """ - if not HAS_PYVISTA: + def plotter(self) -> None: + """Returns ``ansys.tools.visualization_interface.Plotter`` object.""" + if not HAS_ANSYS_VIZ: warnings.warn( "Installation of viz option required! Use pip install ansys-mechanical-core[viz]" ) @@ -245,9 +241,20 @@ def plot(self) -> None: warnings.warn("Plotting is only supported with version 2024R2 and later!") return - from ansys.mechanical.core.embedding.viz.pyvista_plotter import plot_model + # TODO Check if anything loaded inside app or else show warning and return + + from ansys.mechanical.core.embedding.viz.embedding_plotter import to_plotter - plot_model(self) + return to_plotter(self) + + def plot(self) -> None: + """Visualize the model in 3d. + + Requires installation using the viz option. E.g. + pip install ansys-mechanical-core[viz] + """ + _plotter = self.plotter() + return _plotter.show() @property def poster(self) -> Poster: diff --git a/src/ansys/mechanical/core/embedding/viz/pyvista_plotter.py b/src/ansys/mechanical/core/embedding/viz/embedding_plotter.py similarity index 89% rename from src/ansys/mechanical/core/embedding/viz/pyvista_plotter.py rename to src/ansys/mechanical/core/embedding/viz/embedding_plotter.py index dd3f5b82a..aca7977fd 100644 --- a/src/ansys/mechanical/core/embedding/viz/pyvista_plotter.py +++ b/src/ansys/mechanical/core/embedding/viz/embedding_plotter.py @@ -29,6 +29,7 @@ import Ansys # isort: skip +from ansys.tools.visualization_interface import Plotter import numpy as np import pyvista as pv @@ -68,9 +69,9 @@ def _get_nodes_and_coords(node: "Ansys.Mechanical.Scenegraph.Node"): return None, None -def to_pyvista_plotter(app: "ansys.mechanical.core.embedding.App"): - """Convert the app's geometry to a pyvista plotter instance.""" - plotter = pv.Plotter() +def to_plotter(app: "ansys.mechanical.core.embedding.App"): + """Convert the app's geometry to an ``ansys.tools.visualization_interface.Plotter`` instance.""" + plotter = Plotter() for body in app.DataModel.GetObjectsByType( Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body ): @@ -81,11 +82,5 @@ def to_pyvista_plotter(app: "ansys.mechanical.core.embedding.App"): pv_transform = _transform_to_pyvista(scenegraph_node.Transform) polydata = pv.PolyData(np_coordinates, np_indices).transform(pv_transform) color = pv.Color(bgr_to_rgb_tuple(body.Color)) - plotter.add_mesh(polydata, color=color, smooth_shading=True) + plotter.plot(polydata, color=color, smooth_shading=True) return plotter - - -def plot_model(app: "ansys.mechanical.core.embedding.App"): - """Plot the model.""" - plotter = to_pyvista_plotter(app) - plotter.show()