Mercurial > hg > octave-lyh
comparison scripts/plot/gnuplot_drawnow.m @ 8789:d9bff42fec43
gnuplot_drawnow.m: Only close the gnuplot window and send position/size info when the figure's position property has changed.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Wed, 18 Feb 2009 00:43:03 -0500 |
parents | 2476ce55d4b5 |
children | 4c989d52f35c |
comparison
equal
deleted
inserted
replaced
8788:d0bc587fce55 | 8789:d9bff42fec43 |
---|---|
38 ## debug file. | 38 ## debug file. |
39 plot_stream = []; | 39 plot_stream = []; |
40 fid = []; | 40 fid = []; |
41 unwind_protect | 41 unwind_protect |
42 plot_stream = open_gnuplot_stream (1, []); | 42 plot_stream = open_gnuplot_stream (1, []); |
43 enhanced = gnuplot_set_term (plot_stream (1), h, term, file); | 43 enhanced = gnuplot_set_term (plot_stream (1), true, h, term, file); |
44 __go_draw_figure__ (h, plot_stream, enhanced, mono); | 44 __go_draw_figure__ (h, plot_stream, enhanced, mono); |
45 if (nargin == 5) | 45 if (nargin == 5) |
46 fid = fopen (debug_file, "wb"); | 46 fid = fopen (debug_file, "wb"); |
47 enhanced = gnuplot_set_term (fid, h, term, file); | 47 enhanced = gnuplot_set_term (fid, true, h, term, file); |
48 __go_draw_figure__ (h, fid, enhanced, mono); | 48 __go_draw_figure__ (h, fid, enhanced, mono); |
49 endif | 49 endif |
50 unwind_protect_cleanup | 50 unwind_protect_cleanup |
51 if (! isempty (plot_stream)) | 51 if (! isempty (plot_stream)) |
52 pclose (plot_stream); | 52 pclose (plot_stream); |
56 endif | 56 endif |
57 end_unwind_protect | 57 end_unwind_protect |
58 elseif (nargin == 1) | 58 elseif (nargin == 1) |
59 ## Graphics terminal for display. | 59 ## Graphics terminal for display. |
60 plot_stream = get (h, "__plot_stream__"); | 60 plot_stream = get (h, "__plot_stream__"); |
61 tag = "gnuplot_drawnow"; | |
61 if (isempty (plot_stream)) | 62 if (isempty (plot_stream)) |
62 plot_stream = open_gnuplot_stream (2, h); | 63 plot_stream = open_gnuplot_stream (2, h); |
63 endif | 64 new_stream = true; |
64 enhanced = gnuplot_set_term (plot_stream (1), h); | 65 ha = axes ("tag", tag, "visible", "off"); |
66 set (ha, "userdata", get (h, "position")); | |
67 else | |
68 new_stream = false; | |
69 unwind_protect | |
70 set (0, "showhiddenhandles", "on"); | |
71 ha = findobj (h, "type", "axes", "tag", tag); | |
72 position = get (h, "position"); | |
73 if (! isempty (ha)) | |
74 prior_position = get (ha, "userdata"); | |
75 if (! all (position == prior_position)) | |
76 new_stream = true; | |
77 else | |
78 ## FIXME -- Obtain the x11 window id from gnuplot and | |
79 ## determine the current position via xwininfo. The | |
80 ## "position" property may then be updated to reflect | |
81 ## changes in window position/size made by the mouse. | |
82 endif | |
83 else | |
84 ha = axes ("tag", tag, "visible", "off"); | |
85 endif | |
86 set (ha, "userdata", position); | |
87 unwind_protect_cleanup | |
88 set (0, "showhiddenhandles", "off"); | |
89 end_unwind_protect | |
90 endif | |
91 enhanced = gnuplot_set_term (plot_stream (1), new_stream, h); | |
65 __go_draw_figure__ (h, plot_stream (1), enhanced, mono); | 92 __go_draw_figure__ (h, plot_stream (1), enhanced, mono); |
66 fflush (plot_stream (1)); | 93 fflush (plot_stream (1)); |
67 else | 94 else |
68 print_usage (); | 95 print_usage (); |
69 endif | 96 endif |
70 | 97 |
71 endfunction | 98 endfunction |
72 | 99 |
73 function [plot_stream, enhanced] = open_gnuplot_stream (npipes, h) | 100 function plot_stream = open_gnuplot_stream (npipes, h) |
74 cmd = gnuplot_binary (); | 101 cmd = gnuplot_binary (); |
75 if (npipes > 1) | 102 if (npipes > 1) |
76 [plot_stream(1), plot_stream(2), pid] = popen2 (cmd); | 103 [plot_stream(1), plot_stream(2), pid] = popen2 (cmd); |
77 if (pid < 0) | 104 if (pid < 0) |
78 error ("drawnow: failed to open connection to gnuplot"); | 105 error ("drawnow: failed to open connection to gnuplot"); |
86 if (! isempty (h)) | 113 if (! isempty (h)) |
87 set (h, "__plot_stream__", plot_stream); | 114 set (h, "__plot_stream__", plot_stream); |
88 endif | 115 endif |
89 endfunction | 116 endfunction |
90 | 117 |
91 function enhanced = gnuplot_set_term (plot_stream, h, term, file) | 118 function enhanced = gnuplot_set_term (plot_stream, new_stream, h, term, file) |
92 ## Generate the gnuplot "set terminal <term> ..." command. Include | 119 ## Generate the gnuplot "set terminal <term> ..." command. Include |
93 ## the subset of properties "position", "units", "paperposition", | 120 ## the subset of properties "position", "units", "paperposition", |
94 ## "paperunits", "name", and "numbertitle". When "term" originates | 121 ## "paperunits", "name", and "numbertitle". When "term" originates |
95 ## from print.m, it may include gnuplot terminal options. | 122 ## from print.m, it may include gnuplot terminal options. |
96 if (nargin == 2) | 123 if (nargin == 3) |
97 ## This supports the gnuplot backend. | 124 ## This supports the gnuplot backend. |
98 term = gnuplot_term (); | 125 term = gnuplot_term (); |
99 opts_str = ""; | 126 opts_str = ""; |
100 else | 127 else |
101 ## Get the one word terminal id and save the remaining as options to | 128 ## Get the one word terminal id and save the remaining as options to |
202 endif | 229 endif |
203 | 230 |
204 ## Set the gnuplot terminal (type, enhanced?, title, & size). | 231 ## Set the gnuplot terminal (type, enhanced?, title, & size). |
205 if (! isempty (term)) | 232 if (! isempty (term)) |
206 term_str = sprintf ("set terminal %s", term); | 233 term_str = sprintf ("set terminal %s", term); |
207 if (any (strncmpi (term, {"x11", "wxt"}, 3)) | 234 if (any (strncmpi (term, {"x11", "wxt"}, 3)) && new_stream |
208 && __gnuplot_has_feature__ ("x11_figure_position")) | 235 && __gnuplot_has_feature__ ("x11_figure_position")) |
209 ## The "close" is added to allow the figure position property | 236 ## The "close" is added to allow the figure position property |
210 ## to remain active. | 237 ## to remain active. |
211 term_str = sprintf ("%s close", term_str); | 238 term_str = sprintf ("%s close", term_str); |
212 endif | 239 endif |
214 term_str = sprintf ("%s %s", term_str, enh_str); | 241 term_str = sprintf ("%s %s", term_str, enh_str); |
215 endif | 242 endif |
216 if (! isempty (title_str)) | 243 if (! isempty (title_str)) |
217 term_str = sprintf ("%s %s", term_str, title_str); | 244 term_str = sprintf ("%s %s", term_str, title_str); |
218 endif | 245 endif |
219 if (! isempty (size_str)) | 246 if (! isempty (size_str) && new_stream) |
220 ## size_str goes last to permit specification of canvas size | 247 ## size_str goes last to permit specification of canvas size |
221 ## for terminals cdr/corel. | 248 ## for terminals cdr/corel. |
222 term_str = sprintf ("%s %s", term_str, size_str); | 249 term_str = sprintf ("%s %s", term_str, size_str); |
223 endif | 250 endif |
224 if (nargin > 2 && ischar (opts_str)) | 251 if (nargin > 2 && ischar (opts_str)) |