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