454
|
1 /* |
|
2 |
1827
|
3 Copyright (C) 1996 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 |
1740
|
30 class ostream; |
|
31 class ostrstream; |
581
|
32 |
524
|
33 class tree_command; |
454
|
34 class tree_plot_command; |
578
|
35 class plot_limits; |
|
36 class plot_range; |
|
37 class subplot_using; |
|
38 class subplot_style; |
|
39 class subplot; |
|
40 class subplot_list; |
454
|
41 |
2124
|
42 class tree_walker; |
|
43 |
1745
|
44 #include <string> |
|
45 |
578
|
46 #include <SLList.h> |
|
47 |
872
|
48 #include "dColVector.h" |
|
49 |
|
50 #include "idx-vector.h" |
1740
|
51 #include "pt-cmd.h" |
|
52 #include "pt-exp.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; |
454
|
85 }; |
|
86 |
|
87 class |
2124
|
88 plot_limits |
454
|
89 { |
593
|
90 public: |
2124
|
91 |
1740
|
92 plot_limits (plot_range *xlim = 0, plot_range *ylim = 0, |
|
93 plot_range *zlim = 0) |
2124
|
94 : x_range (xlim), y_range (ylim), z_range (zlim) { } |
454
|
95 |
578
|
96 ~plot_limits (void); |
454
|
97 |
1827
|
98 void print (int ndim, ostrstream& plot_buf); |
454
|
99 |
2124
|
100 plot_range *x_limits (void) { return x_range; } |
|
101 plot_range *y_limits (void) { return y_range; } |
|
102 plot_range *z_limits (void) { return z_range; } |
|
103 |
|
104 void accept (tree_walker& tw); |
593
|
105 |
|
106 private: |
2124
|
107 |
|
108 // Specified limits of the x, y, and z axes we should display for |
|
109 // this plot. |
578
|
110 plot_range *x_range; |
|
111 plot_range *y_range; |
|
112 plot_range *z_range; |
454
|
113 }; |
|
114 |
|
115 class |
2124
|
116 plot_range |
454
|
117 { |
593
|
118 public: |
2124
|
119 |
1740
|
120 plot_range (tree_expression *l = 0, tree_expression *u = 0) |
2124
|
121 : lower (l), upper (u) { } |
454
|
122 |
578
|
123 ~plot_range (void); |
454
|
124 |
|
125 void print (ostrstream& plot_buf); |
|
126 |
2124
|
127 tree_expression *lower_bound (void) { return lower; } |
|
128 |
|
129 tree_expression *upper_bound (void) { return upper; } |
|
130 |
|
131 void accept (tree_walker& tw); |
593
|
132 |
|
133 private: |
2124
|
134 |
|
135 // A range can specify a lower or upper bound or both. If neither |
|
136 // is specified, the range to display is determined from the data. |
491
|
137 tree_expression *lower; |
|
138 tree_expression *upper; |
454
|
139 }; |
|
140 |
|
141 class |
2124
|
142 subplot_using |
454
|
143 { |
593
|
144 public: |
1622
|
145 |
2124
|
146 subplot_using (tree_expression *fmt = 0) |
|
147 : qual_count (0), scanf_fmt (fmt), val (4, -1) |
|
148 { |
|
149 x[0] = x[1] = x[2] = x[3] = 0; |
|
150 } |
454
|
151 |
578
|
152 ~subplot_using (void); |
454
|
153 |
1622
|
154 subplot_using *set_format (tree_expression *fmt) |
|
155 { |
|
156 scanf_fmt = fmt; |
|
157 return this; |
|
158 } |
454
|
159 |
1622
|
160 subplot_using *add_qualifier (tree_expression *t) |
|
161 { |
2124
|
162 if (qual_count < 4) |
|
163 x[qual_count] = t; |
1622
|
164 |
2124
|
165 qual_count++; |
1622
|
166 |
|
167 return this; |
|
168 } |
454
|
169 |
872
|
170 int eval (int ndim, int n_max); |
|
171 |
|
172 ColumnVector values (int ndim, int n_max = 0); |
|
173 |
454
|
174 int print (int ndim, int n_max, ostrstream& plot_buf); |
|
175 |
2124
|
176 int qualifier_count (void) { return qual_count; } |
|
177 |
|
178 tree_expression **qualifiers (void) { return x; } |
|
179 |
|
180 tree_expression *scanf_format (void) { return scanf_fmt; } |
|
181 |
|
182 void accept (tree_walker& tw); |
593
|
183 |
|
184 private: |
2124
|
185 |
|
186 // The number of using qualifiers (in "using 1:2", 1 and 2 are the |
|
187 // qualifiers). |
|
188 int qual_count; |
|
189 |
|
190 // An optional scanf-style format. This is parsed and stored but |
|
191 // not currently used. |
|
192 tree_expression *scanf_fmt; |
|
193 |
|
194 // This is a cache for evaluated versions of the qualifiers stored |
|
195 // in x. |
|
196 ColumnVector val; |
|
197 |
|
198 // A vector to hold using qualifiers. |
491
|
199 tree_expression *x[4]; |
454
|
200 }; |
|
201 |
|
202 class |
2124
|
203 subplot_style |
454
|
204 { |
593
|
205 public: |
1622
|
206 |
2124
|
207 subplot_style (const string& s = string (), |
|
208 tree_expression *lt = 0, tree_expression *pt = 0) |
|
209 : sp_style (s), sp_linetype (lt), sp_pointtype (pt) { } |
454
|
210 |
578
|
211 ~subplot_style (void); |
454
|
212 |
|
213 int print (ostrstream& plot_buf); |
|
214 |
872
|
215 int errorbars (void); |
|
216 |
2124
|
217 string style (void) { return sp_style; } |
|
218 |
|
219 tree_expression *linetype (void) { return sp_linetype; } |
|
220 |
|
221 tree_expression *pointtype (void) { return sp_pointtype; } |
|
222 |
|
223 void accept (tree_walker& tw); |
593
|
224 |
|
225 private: |
2124
|
226 |
|
227 // The style we are using: `lines', `points', etc. |
|
228 string sp_style; |
|
229 |
|
230 // The number of the line type to use. |
|
231 tree_expression *sp_linetype; |
|
232 |
|
233 // The number of the point type to use. |
|
234 tree_expression *sp_pointtype; |
454
|
235 }; |
|
236 |
578
|
237 class |
2124
|
238 subplot |
578
|
239 { |
|
240 public: |
2124
|
241 |
1740
|
242 subplot (tree_expression *data = 0) |
2124
|
243 : sp_plot_data (data), sp_using_clause (0), sp_title_clause (0), |
|
244 sp_style_clause (0) { } |
1622
|
245 |
|
246 subplot (subplot_using *u, tree_expression *t, subplot_style *s) |
2124
|
247 : sp_plot_data (0), sp_using_clause (u), sp_title_clause (t), |
|
248 sp_style_clause (s) { } |
578
|
249 |
878
|
250 ~subplot (void); |
578
|
251 |
1622
|
252 subplot *set_data (tree_expression *data) |
|
253 { |
2124
|
254 sp_plot_data = data; |
1622
|
255 return this; |
|
256 } |
578
|
257 |
2086
|
258 octave_value extract_plot_data (int ndim, octave_value& data); |
872
|
259 |
|
260 int handle_plot_data (int ndim, ostrstream& plot_buf); |
|
261 |
878
|
262 int print (int ndim, ostrstream& plot_buf); |
|
263 |
2124
|
264 tree_expression *plot_data (void) { return sp_plot_data; } |
|
265 |
|
266 subplot_using *using_clause (void) { return sp_using_clause; } |
|
267 |
|
268 tree_expression *title_clause (void) { return sp_title_clause; } |
|
269 |
|
270 subplot_style *style_clause (void) { return sp_style_clause; } |
|
271 |
|
272 void accept (tree_walker& tw); |
593
|
273 |
578
|
274 private: |
2124
|
275 |
|
276 // The data to plot. |
|
277 tree_expression *sp_plot_data; |
|
278 |
|
279 // The `using' option |
|
280 subplot_using *sp_using_clause; |
|
281 |
|
282 // The `title' option |
|
283 tree_expression *sp_title_clause; |
|
284 |
|
285 // The `style' option |
|
286 subplot_style *sp_style_clause; |
578
|
287 }; |
|
288 |
|
289 class |
2124
|
290 subplot_list : public SLList<subplot *> |
578
|
291 { |
1740
|
292 public: |
878
|
293 |
2124
|
294 subplot_list (void) |
|
295 : SLList<subplot *> () { } |
|
296 |
|
297 subplot_list (subplot *t) |
|
298 : SLList<subplot *> () { append (t); } |
578
|
299 |
1622
|
300 ~subplot_list (void); |
593
|
301 |
|
302 int print (int ndim, ostrstream& plot_buf); |
|
303 |
2124
|
304 void accept (tree_walker& tw); |
578
|
305 }; |
|
306 |
2086
|
307 extern string save_in_tmp_file (octave_value& t, int ndim = 2, |
1827
|
308 bool parametric = false); |
524
|
309 |
1745
|
310 extern void mark_for_deletion (const string&); |
524
|
311 |
|
312 extern void cleanup_tmp_files (void); |
|
313 |
|
314 extern void close_plot_stream (void); |
|
315 |
1755
|
316 extern void do_external_plotter_cd (const string& newdir); |
1328
|
317 |
454
|
318 #endif |
|
319 |
|
320 /* |
|
321 ;;; Local Variables: *** |
|
322 ;;; mode: C++ *** |
|
323 ;;; End: *** |
|
324 */ |