454
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
454
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
454
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_tree_plot_h) |
|
24 #define octave_tree_plot_h 1 |
|
25 |
1297
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
3503
|
30 #include <iostream> |
|
31 #include <strstream> |
581
|
32 |
2878
|
33 class tree_expression; |
454
|
34 class tree_plot_command; |
578
|
35 class plot_limits; |
|
36 class plot_range; |
|
37 class subplot_using; |
|
38 class subplot_style; |
3165
|
39 class subplot_axes; |
578
|
40 class subplot; |
|
41 class subplot_list; |
454
|
42 |
2124
|
43 class tree_walker; |
|
44 |
2220
|
45 #include <csignal> |
|
46 |
1745
|
47 #include <string> |
|
48 |
578
|
49 #include <SLList.h> |
|
50 |
872
|
51 #include "dColVector.h" |
|
52 |
1740
|
53 #include "pt-cmd.h" |
454
|
54 |
|
55 class |
|
56 tree_plot_command : public tree_command |
|
57 { |
593
|
58 public: |
2124
|
59 |
1740
|
60 tree_plot_command (subplot_list *plt = 0, plot_limits *rng = 0, int nd = 0) |
|
61 : tree_command (), ndim (nd), range (rng), plot_list (plt) { } |
454
|
62 |
|
63 ~tree_plot_command (void); |
|
64 |
578
|
65 void eval (void); |
454
|
66 |
2124
|
67 int num_dimensions (void) { return ndim; } |
|
68 |
|
69 plot_limits *limits (void) { return range; } |
|
70 |
|
71 subplot_list *subplots (void) { return plot_list; } |
|
72 |
|
73 void accept (tree_walker& tw); |
581
|
74 |
593
|
75 private: |
2124
|
76 |
|
77 // The number of dimensions. 1 indicates a replot command. |
454
|
78 int ndim; |
2124
|
79 |
|
80 // The data ranges for the plot. |
578
|
81 plot_limits *range; |
2124
|
82 |
|
83 // The list of plots for this plot command. For example, the |
|
84 // command "plot sin(x), cos(x)" has two subplot commands. |
578
|
85 subplot_list *plot_list; |
2988
|
86 |
|
87 // No copying! |
|
88 |
|
89 tree_plot_command (const tree_plot_command&); |
|
90 |
|
91 tree_plot_command& operator = (const tree_plot_command&); |
454
|
92 }; |
|
93 |
|
94 class |
2124
|
95 plot_limits |
454
|
96 { |
593
|
97 public: |
2124
|
98 |
1740
|
99 plot_limits (plot_range *xlim = 0, plot_range *ylim = 0, |
|
100 plot_range *zlim = 0) |
2124
|
101 : x_range (xlim), y_range (ylim), z_range (zlim) { } |
454
|
102 |
578
|
103 ~plot_limits (void); |
454
|
104 |
1827
|
105 void print (int ndim, ostrstream& plot_buf); |
454
|
106 |
2124
|
107 plot_range *x_limits (void) { return x_range; } |
|
108 plot_range *y_limits (void) { return y_range; } |
|
109 plot_range *z_limits (void) { return z_range; } |
|
110 |
|
111 void accept (tree_walker& tw); |
593
|
112 |
|
113 private: |
2124
|
114 |
|
115 // Specified limits of the x, y, and z axes we should display for |
|
116 // this plot. |
578
|
117 plot_range *x_range; |
|
118 plot_range *y_range; |
|
119 plot_range *z_range; |
2988
|
120 |
|
121 // No copying! |
|
122 |
|
123 plot_limits (const plot_limits&); |
|
124 |
|
125 plot_limits& operator = (const plot_limits&); |
454
|
126 }; |
|
127 |
|
128 class |
2124
|
129 plot_range |
454
|
130 { |
593
|
131 public: |
2124
|
132 |
1740
|
133 plot_range (tree_expression *l = 0, tree_expression *u = 0) |
2124
|
134 : lower (l), upper (u) { } |
454
|
135 |
578
|
136 ~plot_range (void); |
454
|
137 |
|
138 void print (ostrstream& plot_buf); |
|
139 |
2124
|
140 tree_expression *lower_bound (void) { return lower; } |
|
141 |
|
142 tree_expression *upper_bound (void) { return upper; } |
|
143 |
|
144 void accept (tree_walker& tw); |
593
|
145 |
|
146 private: |
2124
|
147 |
|
148 // A range can specify a lower or upper bound or both. If neither |
|
149 // is specified, the range to display is determined from the data. |
491
|
150 tree_expression *lower; |
|
151 tree_expression *upper; |
2988
|
152 |
|
153 // No copying! |
|
154 |
|
155 plot_range (const plot_range&); |
|
156 |
|
157 plot_range& operator = (const plot_range&); |
454
|
158 }; |
|
159 |
|
160 class |
2124
|
161 subplot_using |
454
|
162 { |
593
|
163 public: |
1622
|
164 |
2124
|
165 subplot_using (tree_expression *fmt = 0) |
|
166 : qual_count (0), scanf_fmt (fmt), val (4, -1) |
|
167 { |
|
168 x[0] = x[1] = x[2] = x[3] = 0; |
|
169 } |
454
|
170 |
578
|
171 ~subplot_using (void); |
454
|
172 |
1622
|
173 subplot_using *set_format (tree_expression *fmt) |
|
174 { |
|
175 scanf_fmt = fmt; |
|
176 return this; |
|
177 } |
454
|
178 |
1622
|
179 subplot_using *add_qualifier (tree_expression *t) |
|
180 { |
2124
|
181 if (qual_count < 4) |
|
182 x[qual_count] = t; |
1622
|
183 |
2124
|
184 qual_count++; |
1622
|
185 |
|
186 return this; |
|
187 } |
454
|
188 |
872
|
189 int eval (int ndim, int n_max); |
|
190 |
|
191 ColumnVector values (int ndim, int n_max = 0); |
|
192 |
454
|
193 int print (int ndim, int n_max, ostrstream& plot_buf); |
|
194 |
2124
|
195 int qualifier_count (void) { return qual_count; } |
|
196 |
|
197 tree_expression **qualifiers (void) { return x; } |
|
198 |
|
199 tree_expression *scanf_format (void) { return scanf_fmt; } |
|
200 |
|
201 void accept (tree_walker& tw); |
593
|
202 |
|
203 private: |
2124
|
204 |
|
205 // The number of using qualifiers (in "using 1:2", 1 and 2 are the |
|
206 // qualifiers). |
|
207 int qual_count; |
|
208 |
|
209 // An optional scanf-style format. This is parsed and stored but |
|
210 // not currently used. |
|
211 tree_expression *scanf_fmt; |
|
212 |
|
213 // This is a cache for evaluated versions of the qualifiers stored |
|
214 // in x. |
|
215 ColumnVector val; |
|
216 |
|
217 // A vector to hold using qualifiers. |
491
|
218 tree_expression *x[4]; |
2988
|
219 |
|
220 // No copying! |
|
221 |
|
222 subplot_using (const subplot_using&); |
|
223 |
|
224 subplot_using& operator = (const subplot_using&); |
454
|
225 }; |
|
226 |
|
227 class |
2124
|
228 subplot_style |
454
|
229 { |
593
|
230 public: |
1622
|
231 |
2124
|
232 subplot_style (const string& s = string (), |
|
233 tree_expression *lt = 0, tree_expression *pt = 0) |
|
234 : sp_style (s), sp_linetype (lt), sp_pointtype (pt) { } |
454
|
235 |
578
|
236 ~subplot_style (void); |
454
|
237 |
|
238 int print (ostrstream& plot_buf); |
|
239 |
2543
|
240 bool columns_ok (int nc); |
872
|
241 |
2124
|
242 string style (void) { return sp_style; } |
|
243 |
|
244 tree_expression *linetype (void) { return sp_linetype; } |
|
245 |
|
246 tree_expression *pointtype (void) { return sp_pointtype; } |
|
247 |
|
248 void accept (tree_walker& tw); |
593
|
249 |
|
250 private: |
2124
|
251 |
|
252 // The style we are using: `lines', `points', etc. |
|
253 string sp_style; |
|
254 |
|
255 // The number of the line type to use. |
|
256 tree_expression *sp_linetype; |
|
257 |
|
258 // The number of the point type to use. |
|
259 tree_expression *sp_pointtype; |
2988
|
260 |
|
261 // No copying! |
|
262 |
|
263 subplot_style (const subplot_style&); |
|
264 |
|
265 subplot_style& operator = (const subplot_style&); |
454
|
266 }; |
|
267 |
578
|
268 class |
3165
|
269 subplot_axes |
|
270 { |
|
271 public: |
|
272 |
|
273 subplot_axes (const string& s = string ()) |
|
274 : sp_axes (s) { } |
|
275 |
|
276 ~subplot_axes (void) { } |
|
277 |
|
278 int print (ostrstream& plot_buf); |
|
279 |
|
280 string axes (void) { return sp_axes; } |
|
281 |
|
282 void accept (tree_walker& tw); |
|
283 |
|
284 private: |
|
285 |
|
286 // The axes we are using: `x1y1', `x1y2', etc. |
|
287 string sp_axes; |
|
288 |
|
289 // No copying! |
|
290 |
|
291 subplot_axes (const subplot_axes&); |
|
292 |
|
293 subplot_axes& operator = (const subplot_axes&); |
|
294 }; |
|
295 |
|
296 class |
2124
|
297 subplot |
578
|
298 { |
|
299 public: |
2124
|
300 |
1740
|
301 subplot (tree_expression *data = 0) |
2124
|
302 : sp_plot_data (data), sp_using_clause (0), sp_title_clause (0), |
3165
|
303 sp_style_clause (0), sp_axes_clause (0) { } |
578
|
304 |
878
|
305 ~subplot (void); |
578
|
306 |
3165
|
307 subplot *add_data (tree_expression *data) |
1622
|
308 { |
2124
|
309 sp_plot_data = data; |
1622
|
310 return this; |
|
311 } |
578
|
312 |
3165
|
313 subplot *add_clause (subplot_using *u) |
|
314 { |
|
315 if (! sp_using_clause) |
|
316 { |
|
317 sp_using_clause = u; |
|
318 return this; |
|
319 } |
|
320 else |
|
321 return 0; |
|
322 } |
|
323 |
|
324 subplot *add_clause (tree_expression *t) |
|
325 { |
|
326 if (! sp_title_clause) |
|
327 { |
|
328 sp_title_clause = t; |
|
329 return this; |
|
330 } |
|
331 else |
|
332 return 0; |
|
333 } |
|
334 |
|
335 subplot *add_clause (subplot_style *s) |
|
336 { |
|
337 if (! sp_style_clause) |
|
338 { |
|
339 sp_style_clause = s; |
|
340 return this; |
|
341 } |
|
342 else |
|
343 return 0; |
|
344 } |
|
345 |
|
346 subplot *add_clause (subplot_axes *a) |
|
347 { |
|
348 if (! sp_axes_clause) |
|
349 { |
|
350 sp_axes_clause = a; |
|
351 return this; |
|
352 } |
|
353 else |
|
354 return 0; |
|
355 } |
|
356 |
2086
|
357 octave_value extract_plot_data (int ndim, octave_value& data); |
872
|
358 |
|
359 int handle_plot_data (int ndim, ostrstream& plot_buf); |
|
360 |
878
|
361 int print (int ndim, ostrstream& plot_buf); |
|
362 |
2124
|
363 tree_expression *plot_data (void) { return sp_plot_data; } |
|
364 |
|
365 subplot_using *using_clause (void) { return sp_using_clause; } |
|
366 |
|
367 tree_expression *title_clause (void) { return sp_title_clause; } |
|
368 |
|
369 subplot_style *style_clause (void) { return sp_style_clause; } |
|
370 |
3165
|
371 subplot_axes *axes_clause (void) { return sp_axes_clause; } |
|
372 |
2124
|
373 void accept (tree_walker& tw); |
593
|
374 |
578
|
375 private: |
2124
|
376 |
|
377 // The data to plot. |
|
378 tree_expression *sp_plot_data; |
|
379 |
|
380 // The `using' option |
|
381 subplot_using *sp_using_clause; |
|
382 |
|
383 // The `title' option |
|
384 tree_expression *sp_title_clause; |
|
385 |
|
386 // The `style' option |
|
387 subplot_style *sp_style_clause; |
2988
|
388 |
3165
|
389 // The `axes' option |
|
390 subplot_axes *sp_axes_clause; |
|
391 |
2988
|
392 // No copying! |
|
393 |
|
394 subplot (const subplot&); |
|
395 |
|
396 subplot& operator = (const subplot&); |
578
|
397 }; |
|
398 |
|
399 class |
2124
|
400 subplot_list : public SLList<subplot *> |
578
|
401 { |
1740
|
402 public: |
878
|
403 |
2124
|
404 subplot_list (void) |
|
405 : SLList<subplot *> () { } |
|
406 |
|
407 subplot_list (subplot *t) |
|
408 : SLList<subplot *> () { append (t); } |
578
|
409 |
1622
|
410 ~subplot_list (void); |
593
|
411 |
|
412 int print (int ndim, ostrstream& plot_buf); |
|
413 |
2124
|
414 void accept (tree_walker& tw); |
2988
|
415 |
|
416 private: |
|
417 |
|
418 // No copying! |
|
419 |
|
420 subplot_list (const subplot_list&); |
|
421 |
|
422 subplot_list& operator = (const subplot_list&); |
578
|
423 }; |
|
424 |
2086
|
425 extern string save_in_tmp_file (octave_value& t, int ndim = 2, |
1827
|
426 bool parametric = false); |
524
|
427 |
1745
|
428 extern void mark_for_deletion (const string&); |
524
|
429 |
|
430 extern void cleanup_tmp_files (void); |
|
431 |
|
432 extern void close_plot_stream (void); |
|
433 |
1755
|
434 extern void do_external_plotter_cd (const string& newdir); |
1328
|
435 |
454
|
436 #endif |
|
437 |
|
438 /* |
|
439 ;;; Local Variables: *** |
|
440 ;;; mode: C++ *** |
|
441 ;;; End: *** |
|
442 */ |