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