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