diff --git a/doc/changelog.d/4025.fixed.md b/doc/changelog.d/4025.fixed.md new file mode 100644 index 0000000000..a457c0111d --- /dev/null +++ b/doc/changelog.d/4025.fixed.md @@ -0,0 +1 @@ +Fix: adapt new visualizer version \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index bf14ec2254..1f9ebb76c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,7 +63,7 @@ all = [ tests = [ "ansys-dpf-core[graphics]==0.13.6", - "ansys-tools-visualization-interface==0.9.2", + "ansys-tools-visualization-interface==0.10.0", "autopep8==2.3.2", "matplotlib==3.10.3", "pandas==2.3.0", @@ -86,7 +86,7 @@ doc = [ "ansys-dpf-core[graphics]==0.13.6", "ansys-mapdl-reader==0.55.1", "ansys-sphinx-theme==1.5.2", - "ansys-tools-visualization-interface==0.9.2", + "ansys-tools-visualization-interface==0.10.0", "grpcio==1.73.0", "imageio-ffmpeg==0.6.0", "imageio==2.37.0", diff --git a/src/ansys/mapdl/core/mapdl_extended.py b/src/ansys/mapdl/core/mapdl_extended.py index 3681bee8a5..632323487e 100644 --- a/src/ansys/mapdl/core/mapdl_extended.py +++ b/src/ansys/mapdl/core/mapdl_extended.py @@ -466,6 +466,10 @@ def kplot( if graphics_backend is GraphicsBackend.PYVISTA: from ansys.mapdl.core.plotting.visualizer import MapdlPlotter + return_plotter = kwargs.pop("return_plotter", False) + savefig = kwargs.pop("savefig", None) + cpos = kwargs.pop("cpos", None) + return_cpos = kwargs.pop("return_cpos", False) pl = kwargs.get("plotter", None) pl = MapdlPlotter().switch_scene(pl) @@ -477,7 +481,12 @@ def kplot( "the database." ) pl.plot([], [], [], **kwargs) - return pl.show(**kwargs) + return pl.show( + return_plotter=return_plotter, + savefig=savefig, + return_cpos=return_cpos, + cpos=cpos, + ) keypoints = self.geometry.get_keypoints(return_as_array=True) points = [{"points": keypoints}] @@ -488,7 +497,12 @@ def kplot( {"points": keypoints, "labels": self.geometry.knum.astype(int)} ) pl.plot([], points, labels, **kwargs) - return pl.show(**kwargs) + return pl.show( + return_plotter=return_plotter, + savefig=savefig, + return_cpos=return_cpos, + cpos=cpos, + ) # otherwise, use the legacy plotter if graphics_backend is GraphicsBackend.MAPDL: @@ -560,6 +574,11 @@ def lplot( from ansys.mapdl.core.plotting.theme import get_ansys_colors from ansys.mapdl.core.plotting.visualizer import MapdlPlotter + return_plotter = kwargs.pop("return_plotter", False) + savefig = kwargs.pop("savefig", None) + cpos = kwargs.pop("cpos", None) + return_cpos = kwargs.pop("return_cpos", False) + kwargs.setdefault("show_scalar_bar", False) kwargs.setdefault("title", "MAPDL Line Plot") if not self.geometry.n_line: @@ -568,7 +587,13 @@ def lplot( ) pl = MapdlPlotter() pl.plot([], [], [], **kwargs) - return pl.show(**kwargs) + + return pl.show( + return_plotter=return_plotter, + savefig=savefig, + return_cpos=return_cpos, + cpos=cpos, + ) lines = self.geometry.get_lines(return_as_list=True) meshes = [] @@ -626,7 +651,13 @@ def lplot( ) pl = MapdlPlotter() pl.plot(meshes, [], labels, **kwargs) - return pl.show(**kwargs) + obj = pl.show( + return_plotter=return_plotter, + savefig=savefig, + return_cpos=return_cpos, + cpos=cpos, + ) + return obj else: with self._enable_interactive_plotting(): return super().lplot(nl1=nl1, nl2=nl2, ninc=ninc, **kwargs) @@ -747,14 +778,22 @@ def aplot( kwargs.setdefault("show_scalar_bar", False) kwargs.setdefault("title", "MAPDL Area Plot") kwargs.setdefault("scalar_bar_args", {"title": "Scalar Bar Title"}) - + return_plotter = kwargs.pop("return_plotter", False) + return_cpos = kwargs.pop("return_cpos", False) + savefig = kwargs.pop("savefig", None) + cpos = kwargs.pop("cpos", None) if not self.geometry.n_area: warnings.warn( "Either no areas have been selected or there is nothing to plot." ) pl = MapdlPlotter() pl.plot([], [], [], **kwargs) - return pl.show(**kwargs) + return pl.show( + return_plotter=return_plotter, + savefig=savefig, + return_cpos=return_cpos, + cpos=cpos, + ) surfs = self.geometry.get_areas(return_as_list=True, quality=quality) meshes = [] @@ -859,7 +898,12 @@ def aplot( ) pl = MapdlPlotter() pl.plot(meshes, [], labels, **kwargs) - return pl.show(**kwargs) + return pl.show( + return_plotter=return_plotter, + savefig=savefig, + return_cpos=return_cpos, + cpos=cpos, + ) if graphics_backend is GraphicsBackend.MAPDL: with self._enable_interactive_plotting(): return super().aplot( @@ -943,6 +987,11 @@ def vplot( if graphics_backend is GraphicsBackend.PYVISTA: from ansys.mapdl.core.plotting.visualizer import MapdlPlotter + return_plotter = kwargs.pop("return_plotter", False) + return_cpos = kwargs.pop("return_cpos", False) + savefig = kwargs.pop("savefig", None) + cpos = kwargs.pop("cpos", None) + pl = kwargs.get("plotter", None) pl = MapdlPlotter().switch_scene(pl) @@ -953,7 +1002,12 @@ def vplot( ) pl = MapdlPlotter() pl.plot([], [], [], **kwargs) - return pl.show(**kwargs) + return pl.show( + return_plotter=return_plotter, + savefig=savefig, + return_cpos=return_cpos, + cpos=cpos, + ) # Storing entities selection with self.save_selection: @@ -962,7 +1016,6 @@ def vplot( points = [] labels = [] - return_plotter = kwargs.pop("return_plotter", False) color_areas = True for each_volu in volumes: @@ -990,7 +1043,12 @@ def vplot( meshes = [{"mesh": meshes}] pl.plot(meshes, points, labels, **kwargs) - return pl.show(return_plotter=return_plotter, **kwargs) + return pl.show( + return_plotter=return_plotter, + savefig=savefig, + return_cpos=return_cpos, + cpos=cpos, + ) elif graphics_backend is GraphicsBackend.MAPDL: with self._enable_interactive_plotting(): @@ -1125,6 +1183,10 @@ def nplot(self, nnum="", *, graphics_backend=None, **kwargs): from ansys.mapdl.core.plotting.visualizer import MapdlPlotter + return_plotter = kwargs.pop("return_plotter", False) + savefig = kwargs.pop("savefig", None) + cpos = kwargs.pop("cpos", None) + return_cpos = kwargs.pop("return_cpos", False) pl = kwargs.get("plotter", None) pl = MapdlPlotter().switch_scene(pl) @@ -1132,7 +1194,12 @@ def nplot(self, nnum="", *, graphics_backend=None, **kwargs): if not self.mesh.n_node: warnings.warn("There are no nodes to plot.") pl.plot([], [], [], **kwargs) - return pl.show(**kwargs) + return pl.show( + return_plotter=return_plotter, + savefig=savefig, + return_cpos=return_cpos, + cpos=cpos, + ) labels = [] if nnum: @@ -1146,7 +1213,13 @@ def nplot(self, nnum="", *, graphics_backend=None, **kwargs): ] points = [{"points": self.mesh.nodes}] pl.plot([], points, labels, mapdl=self, **kwargs) - return pl.show(**kwargs) + + return pl.show( + return_plotter=return_plotter, + savefig=savefig, + return_cpos=return_cpos, + cpos=cpos, + ) elif graphics_backend is GraphicsBackend.MAPDL: # otherwise, use the built-in nplot @@ -1261,6 +1334,10 @@ def eplot(self, show_node_numbering=False, *, graphics_backend=None, **kwargs): if graphics_backend is GraphicsBackend.PYVISTA: from ansys.mapdl.core.plotting.visualizer import MapdlPlotter + return_plotter = kwargs.pop("return_plotter", False) + cpos = kwargs.pop("cpos", None) + return_cpos = kwargs.pop("return_cpos", False) + savefig = kwargs.pop("savefig", None) pl = kwargs.get("plotter", None) pl = MapdlPlotter().switch_scene(pl) pl.mapdl = self @@ -1269,7 +1346,12 @@ def eplot(self, show_node_numbering=False, *, graphics_backend=None, **kwargs): if not self._mesh.n_elem: warnings.warn("There are no elements to plot.") pl.plot([], [], [], mapdl=self, **kwargs) - return pl.show(**kwargs) + return pl.show( + return_plotter=return_plotter, + cpos=cpos, + return_cpos=return_cpos, + savefig=savefig, + ) # TODO: Consider caching the surface esurf = self.mesh._grid.linear_copy().extract_surface().clean() @@ -1292,7 +1374,13 @@ def eplot(self, show_node_numbering=False, *, graphics_backend=None, **kwargs): mapdl=self, **kwargs, ) - return pl.show(**kwargs) + + return pl.show( + return_plotter=return_plotter, + cpos=cpos, + return_cpos=return_cpos, + savefig=savefig, + ) elif graphics_backend is GraphicsBackend.MAPDL: # otherwise, use MAPDL plotter with self._enable_interactive_plotting(): diff --git a/src/ansys/mapdl/core/plotting/visualizer.py b/src/ansys/mapdl/core/plotting/visualizer.py index 264b394485..fc45e6e8de 100644 --- a/src/ansys/mapdl/core/plotting/visualizer.py +++ b/src/ansys/mapdl/core/plotting/visualizer.py @@ -807,11 +807,6 @@ def plot( if title: # Added here to avoid labels overlapping title self.scene.add_title(title, color=text_color) - if return_cpos and return_plotter: - raise ValueError( - "'return_cpos' and 'return_plotter' cannot be both 'True' at the same time." - ) - def switch_scene(self, pl: Union["pv.Plotter", "MapdlPlotter"]) -> "MapdlPlotter": """Switches the backend scene to the given plotter. @@ -849,6 +844,10 @@ def show( **kwargs, ) -> None: """Show the plotter.""" + if return_cpos and return_plotter: + raise ValueError( + "'return_cpos' and 'return_plotter' cannot be both 'True' at the same time." + ) self._off_screen = off_screen if notebook: @@ -864,7 +863,6 @@ def show( auto_close=False, window_size=window_size, screenshot=savefig, - **kwargs, ) self.scene.screenshot(self._savefig) diff --git a/src/ansys/mapdl/core/post.py b/src/ansys/mapdl/core/post.py index 92acca6953..9a414548f5 100644 --- a/src/ansys/mapdl/core/post.py +++ b/src/ansys/mapdl/core/post.py @@ -631,6 +631,11 @@ def _plot_point_scalars(self, scalars, show_node_numbering=False, **kwargs): from ansys.mapdl.core.plotting.visualizer import MapdlPlotter + return_cpos = kwargs.pop("return_cpos", False) + return_plotter = kwargs.pop("return_plotter", False) + savefig = kwargs.pop("savefig", None) + cpos = kwargs.pop("cpos", None) + with self._mapdl.save_selection: mask = self.selected_nodes nodes_ids = self._mapdl.get_array("NODE", item1="NLIST") @@ -665,7 +670,12 @@ def _plot_point_scalars(self, scalars, show_node_numbering=False, **kwargs): pl = MapdlPlotter() pl.plot(meshes, [], labels, mapdl=self, **kwargs) - return pl.show(**kwargs) + return pl.show( + return_cpos=return_cpos, + return_plotter=return_plotter, + savefig=savefig, + cpos=cpos, + ) @requires_package("ansys.tools.visualization_interface") def _plot_cell_scalars(self, scalars, show_elem_numbering=False, **kwargs): @@ -679,6 +689,10 @@ def _plot_cell_scalars(self, scalars, show_elem_numbering=False, **kwargs): from ansys.mapdl.core.plotting.visualizer import MapdlPlotter + return_cpos = kwargs.pop("return_cpos", False) + return_plotter = kwargs.pop("return_plotter", False) + savefig = kwargs.pop("savefig", None) + cpos = kwargs.pop("cpos", None) with self._mapdl.save_selection: # Select nodes to avoid segfault self._mapdl.nsle("s", "all") @@ -756,7 +770,12 @@ def _plot_cell_scalars(self, scalars, show_elem_numbering=False, **kwargs): ] pl = MapdlPlotter() pl.plot(meshes, [], labels, mapdl=self, **kwargs) - return pl.show(**kwargs) + return pl.show( + return_cpos=return_cpos, + return_plotter=return_plotter, + savefig=savefig, + cpos=cpos, + ) @property @supress_logging