Skip to content

Commit

Permalink
Graphics view setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajain-work authored and dnwillia-work committed Apr 27, 2022
1 parent 6799924 commit ee113f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ansys.fluent.post.matplotlib import Plots
from ansys.fluent.post.pyvista import Graphics

set_config(blocking=True)
set_config(blocking=True, set_view_on_display="isometric")

###############################################################################
# First, download the case and data file and start Fluent as a service with
Expand Down
10 changes: 6 additions & 4 deletions src/ansys/fluent/post/_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Global configuration state for post."""
import threading

_global_config = {
"blocking": False,
}
_global_config = {"blocking": False, "set_view_on_display": None}
_threadlocal = threading.local()


Expand All @@ -24,13 +22,17 @@ def get_config() -> dict:
return _get_threadlocal_config().copy()


def set_config(blocking: bool = False):
def set_config(blocking: bool = False, set_view_on_display: str = None):
"""Set post configuration.
Parameters
----------
blocking : bool, default=False
If True, then graphics/plot display will block the current thread.
set_view_on_display : str, default=None
If specified, then graphics will always be displayed in the specified view.
Valid values are xy, xz, yx, yz, zx, zy and isometric.
"""
local_config = _get_threadlocal_config()
local_config["blocking"] = blocking
local_config["set_view_on_display"] = set_view_on_display
23 changes: 17 additions & 6 deletions src/ansys/fluent/post/pyvista/pyvista_windows_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,20 @@ def plot(self):
self._display_vector(obj, plotter)
if self.animate:
plotter.write_frame()
plotter.camera = camera.copy()
view = get_config()["set_view_on_display"]
view_fun = {
"xy": plotter.view_xy,
"xz": plotter.view_xz,
"yx": plotter.view_yx,
"yz": plotter.view_yz,
"zx": plotter.view_zx,
"zy": plotter.view_zy,
"isometric": plotter.view_isometric,
}.get(view)
if view_fun:
view_fun()
else:
plotter.camera = camera.copy()
if not self._visible:
plotter.show()
self._visible = True
Expand Down Expand Up @@ -443,16 +456,14 @@ def set_object_for_window(
If window does not support object.
"""
if not isinstance(object, GraphicsDefn):
raise RuntimeError("object not implemented.")
raise RuntimeError("Object type currently not supported.")
with self._condition:
window = self._post_windows.get(window_id)
if window:
window.post_object = object

def plot(
self,
object: Union[GraphicsDefn, PlotDefn],
window_id: Optional[str] = None,
self, object: Union[GraphicsDefn, PlotDefn], window_id: Optional[str] = None
) -> None:
"""Draw plot.
Expand All @@ -470,7 +481,7 @@ def plot(
If window does not support object.
"""
if not isinstance(object, GraphicsDefn):
raise RuntimeError("object not implemented.")
raise RuntimeError("Object type currently not supported.")
with self._condition:
if not window_id:
window_id = self._get_unique_window_id()
Expand Down

0 comments on commit ee113f4

Please sign in to comment.