6257
|
1 ## Copyright (C) 2005 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} drawnow () |
|
22 ## Display the current graphics. |
|
23 ## @end deftypefn |
|
24 |
|
25 ## Author: jwe |
|
26 |
|
27 function drawnow (term, file) |
|
28 |
6298
|
29 ## Use this instead of persistent and mlock so that drawnow can be |
|
30 ## replaced. |
|
31 global __uiobject_close_all_registered__; |
|
32 if (isempty (__uiobject_close_all_registered__)) |
|
33 __lock_global__ ("__uiobject_close_all_registered__"); |
|
34 endif |
|
35 |
6257
|
36 ## Use this instead of calling gcf to avoid creating a figure. |
|
37 |
|
38 h = get (0, "currentfigure"); |
|
39 |
|
40 if (h) |
|
41 |
|
42 f = get (h); |
|
43 |
|
44 plot_stream = f.__plot_stream__; |
|
45 |
|
46 if (isempty (plot_stream)) |
6286
|
47 cmd = gnuplot_binary (); |
|
48 if (gnuplot_use_title_option ()) |
6289
|
49 cmd = sprintf ("%s -title \"Figure %d\"", cmd, h); |
6286
|
50 endif |
|
51 plot_stream = popen (cmd, "w"); |
6298
|
52 if (isempty (__uiobject_close_all_registered__)) |
|
53 atexit ("__uiobject_close_all__"); |
|
54 __uiobject_close_all_registered__ = true; |
|
55 endif |
6257
|
56 if (plot_stream < 0) |
|
57 error ("drawnow: failed to open connection to gnuplot"); |
|
58 else |
|
59 set (h, "__plot_stream__", plot_stream); |
6298
|
60 if (isunix () && isempty (getenv ("DISPLAY"))) |
6257
|
61 fprintf (plot_stream, "set terminal dumb\n;"); |
|
62 endif |
|
63 endif |
|
64 endif |
|
65 |
|
66 if (nargin == 2) |
|
67 fprintf (plot_stream, |
|
68 "set terminal push; set terminal %s; set output '%s'\n", |
|
69 term, file); |
|
70 endif |
|
71 |
|
72 if (nargin == 2 || strcmp (f.visible, "on")) |
|
73 __uiobject_draw_figure__ (f, plot_stream); |
|
74 endif |
|
75 |
|
76 __request_drawnow__ (false); |
|
77 |
|
78 if (nargin == 2) |
|
79 fputs (plot_stream, "set terminal pop; set output;\n"); |
|
80 endif |
|
81 |
|
82 else |
|
83 |
|
84 __request_drawnow__ (false); |
|
85 |
|
86 endif |
|
87 |
|
88 endfunction |