44from typing import List , Optional , Union
55
66import numpy as np
7+
78from ansys .fluent .core .session import Session
89from ansys .fluent .core .utils .generic import AbstractSingletonMeta , in_notebook
10+ from ansys .fluent .post import get_config
911from ansys .fluent .post .matplotlib .plotter_defns import Plotter , ProcessPlotter
1012from ansys .fluent .post .post_object_defns import GraphicsDefn , PlotDefn
1113from ansys .fluent .post .post_windows_manager import (
@@ -40,6 +42,9 @@ def plot(self, data):
4042 def set_properties (self , properties ):
4143 self .plot_pipe .send ({"properties" : properties })
4244
45+ def save_graphic (self , name : str ):
46+ self .plot_pipe .send ({"save_graphic" : name })
47+
4348 def is_closed (self ):
4449 if self ._closed :
4550 return True
@@ -82,15 +87,13 @@ def __init__(self, id: str, post_object: Union[GraphicsDefn, PlotDefn]):
8287 self .animate : bool = False
8388 self .close : bool = False
8489 self .refresh : bool = False
85- if in_notebook ():
86- self .plotter ()
8790
8891 def plot (self ):
8992 """Draw plot."""
9093 if not self .post_object :
9194 return
9295 xy_data = self ._get_xy_plot_data ()
93- if in_notebook ():
96+ if in_notebook () or get_config ()[ "blocking" ] :
9497 self .plotter .set_properties (self .properties )
9598 else :
9699 try :
@@ -106,7 +109,7 @@ def plot(self):
106109 def _get_plotter (self ):
107110 return (
108111 Plotter (self .id )
109- if in_notebook ()
112+ if in_notebook () or get_config ()[ "blocking" ]
110113 else _ProcessPlotterHandle (self .id )
111114 )
112115
@@ -244,6 +247,31 @@ def plot(
244247 window .post_object = object
245248 window .plot ()
246249
250+ def save_graphic (
251+ self ,
252+ window_id : str ,
253+ format : str ,
254+ ) -> None :
255+ """
256+ Save graphics.
257+
258+ Parameters
259+ ----------
260+ window_id : str
261+ Window id for which graphic should be saved.
262+ format : str
263+ Graphic format. Supported formats are eps, jpeg, jpg,
264+ pdf, pgf, png, ps, raw, rgba, svg, svgz, tif and tiff.
265+
266+ Raises
267+ ------
268+ ValueError
269+ If window does not support specified format.
270+ """
271+ window = self ._post_windows .get (window_id )
272+ if window :
273+ window .plotter .save_graphic (f"{ window_id } .{ format } " )
274+
247275 def refresh_windows (
248276 self ,
249277 session_id : Optional [str ] = "" ,
@@ -332,7 +360,10 @@ def _open_window(
332360 if (
333361 window
334362 and not window .plotter .is_closed ()
335- and (not in_notebook () or window .refresh )
363+ and (
364+ not (in_notebook () or get_config ()["blocking" ])
365+ or window .refresh
366+ )
336367 ):
337368 window .refresh = False
338369 else :
0 commit comments