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 |
6454
|
29 persistent drawnow_executing = 0; |
|
30 |
|
31 unwind_protect |
|
32 |
|
33 ## If this is a recursive call, do nothing. |
|
34 if (++drawnow_executing > 1) |
|
35 return; |
6425
|
36 endif |
6454
|
37 |
|
38 if (nargin == 2) |
|
39 h = get (0, "currentfigure"); |
|
40 if (h) |
6425
|
41 f = get (h); |
6454
|
42 plot_stream = []; |
|
43 unwind_protect |
|
44 plot_stream = open_gnuplot_stream ([], term, file); |
|
45 __go_draw_figure__ (f, plot_stream); |
|
46 unwind_protect_cleanup |
|
47 if (! isempty (plot_stream)) |
6432
|
48 pclose (plot_stream); |
6425
|
49 endif |
6454
|
50 end_unwind_protect |
|
51 else |
|
52 error ("drawnow: nothing to draw"); |
6425
|
53 endif |
6454
|
54 elseif (nargin == 0) |
|
55 for h = __go_figure_handles__ () |
|
56 if (! (isnan (h) || h == 0)) |
|
57 f = get (h); |
|
58 if (f.__modified__) |
|
59 plot_stream = f.__plot_stream__; |
|
60 figure_is_visible = strcmp (f.visible, "on"); |
|
61 if (figure_is_visible) |
|
62 if (isempty (plot_stream)) |
|
63 plot_stream = open_gnuplot_stream (h); |
|
64 endif |
|
65 __go_draw_figure__ (f, plot_stream); |
|
66 elseif (! isempty (plot_stream)) |
|
67 pclose (plot_stream); |
|
68 set (h, "__plot_stream__", []); |
|
69 endif |
|
70 set (h, "__modified__", false); |
|
71 endif |
|
72 endif |
|
73 endfor |
|
74 else |
|
75 print_usage (); |
|
76 endif |
6425
|
77 |
6454
|
78 unwind_protect_cleanup |
|
79 |
|
80 drawnow_executing--; |
|
81 __request_drawnow__ (false); |
|
82 |
|
83 end_unwind_protect |
6425
|
84 |
|
85 endfunction |
|
86 |
|
87 function plot_stream = open_gnuplot_stream (h, term, file) |
|
88 |
6418
|
89 ## If drawnow is cleared, it is possible to register __go_close_all__ |
|
90 ## more than once, but that is not fatal. |
|
91 persistent __go_close_all_registered__; |
6298
|
92 |
6425
|
93 cmd = gnuplot_binary (); |
6257
|
94 |
6425
|
95 if (! isempty (h) && gnuplot_use_title_option ()) |
|
96 cmd = sprintf ("%s -title \"Figure %d\"", cmd, h); |
|
97 endif |
6257
|
98 |
6425
|
99 plot_stream = popen (cmd, "w"); |
|
100 |
|
101 if (plot_stream < 0) |
|
102 error ("drawnow: failed to open connection to gnuplot"); |
|
103 else |
|
104 |
|
105 if (! isempty (h)) |
|
106 set (h, "__plot_stream__", plot_stream); |
6257
|
107 endif |
|
108 |
6425
|
109 if (nargin == 3) |
|
110 fprintf (plot_stream, "set terminal %s\n;", term); |
|
111 fprintf (plot_stream, "set output \"%s\"\n;", file); |
|
112 elseif (isunix () && isempty (getenv ("DISPLAY"))) |
6754
|
113 if (strcmp (getenv ("GNUTERM"), "aqua")) |
|
114 fprintf (plot_stream, "set terminal aqua title \"Figure %d\";\n", h); |
|
115 else |
|
116 fprintf (plot_stream, "set terminal dumb\n;"); |
|
117 endif |
6451
|
118 elseif (! isempty (h) && strcmp (getenv ("GNUTERM"), "wxt")) |
|
119 fprintf (plot_stream, "set terminal wxt title \"Figure %d\";\n", h); |
6257
|
120 endif |
|
121 |
6425
|
122 if (isempty (__go_close_all_registered__)) |
|
123 atexit ("__go_close_all__"); |
|
124 __go_close_all_registered__ = true; |
6257
|
125 endif |
|
126 |
|
127 endif |
|
128 |
|
129 endfunction |