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