6874
|
1 /* |
|
2 |
|
3 Copyright (C) 2007 John W. Eaton |
|
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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
6874
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
6874
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (graphics_h) |
|
24 #define graphics_h 1 |
|
25 |
|
26 #ifdef HAVE_CONFIG_H |
|
27 #include <config.h> |
|
28 #endif |
|
29 |
|
30 #include <cctype> |
|
31 |
|
32 #include <algorithm> |
|
33 #include <list> |
|
34 #include <map> |
|
35 #include <set> |
|
36 #include <string> |
|
37 |
6890
|
38 #include "gripes.h" |
6874
|
39 #include "oct-map.h" |
|
40 #include "ov.h" |
|
41 |
7189
|
42 class caseless_str : public std::string |
|
43 { |
|
44 public: |
|
45 typedef std::string::iterator iterator; |
|
46 typedef std::string::const_iterator const_iterator; |
|
47 |
|
48 caseless_str (void) : std::string () { } |
|
49 caseless_str (const std::string& s) : std::string (s) { } |
|
50 caseless_str (const char *s) : std::string (s) { } |
|
51 |
|
52 caseless_str (const caseless_str& name) : std::string (name) { } |
|
53 |
|
54 caseless_str& operator = (const caseless_str& pname) |
|
55 { |
|
56 std::string::operator = (pname); |
|
57 return *this; |
|
58 } |
|
59 |
|
60 operator std::string (void) const { return *this; } |
|
61 |
|
62 // Case-insensitive comparison. |
|
63 bool compare (const std::string& s, size_t limit = NPOS) const |
|
64 { |
|
65 const_iterator p1 = begin (); |
|
66 const_iterator p2 = s.begin (); |
|
67 |
|
68 size_t k = 0; |
|
69 |
|
70 while (p1 != end () && p2 != s.end () && k++ < limit) |
|
71 { |
|
72 if (std::tolower (*p1) != std::tolower (*p2)) |
|
73 return false; |
|
74 |
|
75 *p1++; |
|
76 *p2++; |
|
77 } |
|
78 |
|
79 return (limit == NPOS) ? size () == s.size () : k == limit; |
|
80 } |
|
81 }; |
|
82 |
|
83 // --------------------------------------------------------------------- |
|
84 |
7212
|
85 class radio_values |
6874
|
86 { |
|
87 public: |
|
88 radio_values (const std::string& opt_string = std::string ()); |
7168
|
89 |
6874
|
90 radio_values (const radio_values& a) |
|
91 : default_val (a.default_val), possible_vals (a.possible_vals) { } |
|
92 |
|
93 radio_values& operator = (const radio_values& a) |
|
94 { |
|
95 if (&a != this) |
|
96 { |
|
97 default_val = a.default_val; |
|
98 possible_vals = a.possible_vals; |
|
99 } |
|
100 |
|
101 return *this; |
|
102 } |
|
103 |
|
104 std::string default_value (void) const { return default_val; } |
|
105 |
|
106 bool validate (const std::string& val) |
|
107 { |
|
108 bool retval = true; |
|
109 |
6898
|
110 if (! contains (val)) |
6874
|
111 { |
|
112 error ("invalid value = %s", val.c_str ()); |
|
113 retval = false; |
|
114 } |
|
115 |
|
116 return retval; |
|
117 } |
6898
|
118 |
|
119 bool contains (const std::string& val) |
|
120 { |
|
121 return (possible_vals.find (val) != possible_vals.end ()); |
|
122 } |
6874
|
123 |
|
124 private: |
|
125 // Might also want to cache |
|
126 std::string default_val; |
7189
|
127 std::set<caseless_str> possible_vals; |
6874
|
128 }; |
|
129 |
7212
|
130 class radio_property |
6874
|
131 { |
|
132 public: |
7222
|
133 radio_property (const radio_values& v = radio_values ()) |
6874
|
134 : vals (v), current_val (v.default_value ()) { } |
|
135 |
|
136 radio_property (const radio_property& a) |
|
137 : vals (a.vals), current_val (a.current_val) { } |
|
138 |
|
139 radio_property& operator = (const radio_property& a) |
|
140 { |
|
141 if (&a != this) |
|
142 { |
|
143 vals = a.vals; |
|
144 current_val = a.current_val; |
|
145 } |
|
146 |
|
147 return *this; |
|
148 } |
|
149 |
|
150 radio_property& operator = (const std::string& newval) |
|
151 { |
|
152 if (vals.validate (newval)) |
|
153 current_val = newval; |
7189
|
154 else |
|
155 error ("invalid value"); |
6874
|
156 |
|
157 return *this; |
|
158 } |
|
159 |
7189
|
160 radio_property& operator = (const octave_value& newval) |
|
161 { |
|
162 if (newval.is_string ()) |
|
163 { |
|
164 std::string s = newval.string_value (); |
|
165 if (vals.validate (s)) |
|
166 current_val = s; |
|
167 else |
|
168 error ("invalid value"); |
|
169 } |
|
170 else |
|
171 error ("invalid value"); |
|
172 |
|
173 return *this; |
|
174 } |
|
175 |
|
176 operator octave_value (void) const { return current_val; } |
|
177 |
6874
|
178 const std::string& current_value (void) const { return current_val; } |
|
179 |
|
180 private: |
|
181 radio_values vals; |
|
182 std::string current_val; |
|
183 }; |
|
184 |
7212
|
185 class color_values |
6874
|
186 { |
|
187 public: |
|
188 color_values (double r = 0, double g = 0, double b = 1) |
|
189 { |
|
190 xrgb[0] = r; |
|
191 xrgb[1] = g; |
|
192 xrgb[2] = b; |
|
193 |
|
194 validate (); |
|
195 } |
|
196 |
|
197 color_values (std::string str) |
|
198 { |
|
199 if (! str2rgb (str)) |
|
200 error ("invalid color specification"); |
|
201 } |
|
202 |
|
203 color_values (const color_values& c) |
|
204 { |
|
205 xrgb[0] = c.xrgb[0]; |
|
206 xrgb[1] = c.xrgb[1]; |
|
207 xrgb[2] = c.xrgb[2]; |
|
208 } |
|
209 |
|
210 color_values& operator = (const color_values& c) |
|
211 { |
|
212 if (&c != this) |
|
213 { |
|
214 xrgb[0] = c.xrgb[0]; |
|
215 xrgb[1] = c.xrgb[1]; |
|
216 xrgb[2] = c.xrgb[2]; |
|
217 |
|
218 } |
|
219 |
|
220 return *this; |
|
221 } |
|
222 |
|
223 const double* rgb (void) const { return xrgb; } |
|
224 |
|
225 void validate (void) const |
|
226 { |
|
227 for (int i = 0; i < 3; i++) |
|
228 { |
|
229 if (xrgb[i] < 0 || xrgb[i] > 1) |
|
230 { |
|
231 error ("invalid RGB color specification"); |
|
232 break; |
|
233 } |
|
234 } |
|
235 } |
|
236 |
|
237 private: |
|
238 double xrgb[3]; |
|
239 |
|
240 bool str2rgb (std::string str); |
|
241 }; |
|
242 |
|
243 |
7212
|
244 class color_property |
6874
|
245 { |
|
246 public: |
|
247 color_property (const color_values& c = color_values (), |
|
248 const radio_values& v = radio_values ()) |
|
249 : current_type (color_t), color_val (c), radio_val (v), |
|
250 current_val (v.default_value ()) |
|
251 { } |
|
252 |
|
253 color_property (const radio_values& v) |
|
254 : current_type (radio_t), color_val (color_values ()), radio_val (v), |
|
255 current_val (v.default_value ()) |
|
256 { } |
|
257 |
|
258 color_property (const radio_values& v, const std::string& initial_value) |
|
259 : current_type (radio_t), color_val (color_values ()), radio_val (v), |
|
260 current_val (initial_value) |
|
261 { } |
|
262 |
6938
|
263 color_property (const octave_value& val); |
6874
|
264 |
|
265 operator octave_value (void) const |
|
266 { |
|
267 if (current_type == color_t) |
|
268 { |
|
269 Matrix retval (1, 3); |
|
270 const double *xrgb = color_val.rgb (); |
|
271 |
|
272 for (int i = 0; i < 3 ; i++) |
|
273 retval(i) = xrgb[i]; |
|
274 |
|
275 return retval; |
|
276 } |
|
277 |
|
278 return current_val; |
|
279 } |
|
280 |
|
281 color_property& operator = (const color_property& a) |
|
282 { |
|
283 if (&a != this) |
|
284 { |
|
285 current_type = a.current_type; |
|
286 color_val = a.color_val; |
|
287 radio_val = a.radio_val; |
|
288 current_val = a.current_val; |
|
289 } |
|
290 |
|
291 return *this; |
|
292 } |
|
293 |
|
294 color_property& operator = (const std::string& newval) |
|
295 { |
|
296 if (radio_val.validate (newval)) |
|
297 { |
|
298 current_val = newval; |
|
299 current_type = radio_t; |
|
300 } |
|
301 |
|
302 return *this; |
|
303 } |
|
304 |
|
305 color_property& operator = (const color_values& newval) |
|
306 { |
|
307 color_val = newval; |
|
308 current_type = color_t; |
|
309 |
|
310 return *this; |
|
311 } |
|
312 |
|
313 color_property& operator = (const octave_value& newval); |
|
314 |
|
315 bool is_rgb (void) const { return (current_type == color_t); } |
|
316 |
|
317 bool is_radio (void) const { return (current_type == radio_t); } |
|
318 |
|
319 const double* rgb (void) const |
|
320 { |
|
321 if (current_type != color_t) |
|
322 error ("color has no rgb value"); |
|
323 |
|
324 return color_val.rgb (); |
|
325 } |
|
326 |
|
327 const std::string& current_value (void) const |
|
328 { |
|
329 if (current_type != radio_t) |
|
330 error ("color has no radio value"); |
|
331 |
|
332 return current_val; |
|
333 } |
|
334 |
|
335 private: |
|
336 enum current_enum { color_t, radio_t } current_type; |
|
337 color_values color_val; |
|
338 radio_values radio_val; |
|
339 std::string current_val; |
|
340 }; |
|
341 |
7212
|
342 class colormap_property |
6874
|
343 { |
|
344 public: |
|
345 colormap_property (const Matrix& m = Matrix ()) |
|
346 : cmap (m) |
|
347 { |
|
348 if (cmap.is_empty ()) |
|
349 { |
6893
|
350 cmap = Matrix (64, 3, 0.0); |
6874
|
351 |
|
352 for (octave_idx_type i = 0; i < 64; i++) |
6893
|
353 { |
|
354 // This is the jet colormap. It would be nice to be able |
|
355 // to feval the jet function but since there is a static |
|
356 // property object that includes a colormap_property |
|
357 // object, we need to initialize this before main is even |
|
358 // called, so calling an interpreted function is not |
|
359 // possible. |
|
360 |
|
361 double x = i / 63.0; |
|
362 |
|
363 if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
364 cmap(i,0) = 4.0 * x - 3.0/2.0; |
|
365 else if (x >= 5.0/8.0 && x < 7.0/8.0) |
|
366 cmap(i,0) = 1.0; |
|
367 else if (x >= 7.0/8.0) |
|
368 cmap(i,0) = -4.0 * x + 9.0/2.0; |
|
369 |
|
370 if (x >= 1.0/8.0 && x < 3.0/8.0) |
|
371 cmap(i,1) = 4.0 * x - 1.0/2.0; |
|
372 else if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
373 cmap(i,1) = 1.0; |
|
374 else if (x >= 5.0/8.0 && x < 7.0/8.0) |
|
375 cmap(i,1) = -4.0 * x + 7.0/2.0; |
|
376 |
6931
|
377 if (x < 1.0/8.0) |
6893
|
378 cmap(i,2) = 4.0 * x + 1.0/2.0; |
|
379 else if (x >= 1.0/8.0 && x < 3.0/8.0) |
|
380 cmap(i,2) = 1.0; |
|
381 else if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
382 cmap(i,2) = -4.0 * x + 5.0/2.0; |
|
383 } |
6874
|
384 } |
|
385 |
|
386 validate (); |
|
387 } |
|
388 |
|
389 colormap_property (const octave_value& val) |
|
390 { |
|
391 cmap = val.matrix_value (); |
|
392 |
|
393 validate (); |
|
394 } |
|
395 |
|
396 void validate (void) const |
|
397 { |
|
398 if (error_state || cmap.columns () != 3) |
|
399 error ("invalid colormap specification"); |
|
400 } |
|
401 |
|
402 operator octave_value (void) const { return cmap; } |
|
403 |
|
404 private: |
|
405 Matrix cmap; |
|
406 }; |
|
407 |
7212
|
408 class data_property |
|
409 { |
|
410 public: |
7276
|
411 data_property (const NDArray& m = NDArray ()) |
|
412 : data (m), xmin (octave_Inf), xmax (-octave_Inf), xminp (octave_Inf) |
|
413 { |
|
414 get_data_limits (); |
|
415 } |
|
416 |
|
417 data_property (const Matrix& m) |
7222
|
418 : data (m), xmin (octave_Inf), xmax (-octave_Inf), xminp (octave_Inf) |
7213
|
419 { |
|
420 get_data_limits (); |
|
421 } |
7212
|
422 |
|
423 data_property (const octave_value& val) |
7222
|
424 : data (), xmin (octave_Inf), xmax (-octave_Inf), xminp (octave_Inf) |
7212
|
425 { |
7276
|
426 data = val.array_value (); |
7212
|
427 |
7213
|
428 get_data_limits (); |
7212
|
429 } |
|
430 |
|
431 data_property& operator = (const data_property& a) |
|
432 { |
|
433 if (&a != this) |
|
434 { |
|
435 data = a.data; |
7222
|
436 xmin = a.xmin; |
|
437 xmax = a.xmax; |
|
438 xminp = a.xminp; |
7212
|
439 } |
|
440 |
|
441 return *this; |
|
442 } |
|
443 |
|
444 operator octave_value (void) const { return data; } |
|
445 |
7222
|
446 double min_val (void) const { return xmin; } |
|
447 double max_val (void) const { return xmax; } |
|
448 double min_pos (void) const { return xminp; } |
|
449 |
7212
|
450 private: |
7276
|
451 NDArray data; |
7222
|
452 double xmin; |
|
453 double xmax; |
|
454 double xminp; |
7213
|
455 |
|
456 void get_data_limits (void) |
7212
|
457 { |
7213
|
458 octave_idx_type nel = data.numel (); |
7212
|
459 |
|
460 if (nel > 0) |
|
461 { |
7213
|
462 const double *d = data.data (); |
7212
|
463 |
|
464 for (octave_idx_type i = 0; i < nel; i++) |
|
465 { |
7213
|
466 double val = d[i]; |
|
467 |
|
468 if (! (xisinf (val) || xisnan (val))) |
|
469 { |
7222
|
470 if (val < xmin) |
|
471 xmin = val; |
|
472 |
|
473 if (val > xmax) |
|
474 xmax = val; |
|
475 |
|
476 if (val > 0 && val < xminp) |
|
477 xminp = val; |
7213
|
478 } |
7212
|
479 } |
|
480 } |
|
481 } |
|
482 }; |
6874
|
483 |
|
484 class property_list |
|
485 { |
|
486 public: |
|
487 typedef std::map<std::string, octave_value> pval_map_type; |
|
488 typedef std::map<std::string, pval_map_type> plist_map_type; |
|
489 |
|
490 typedef pval_map_type::iterator pval_map_iterator; |
|
491 typedef pval_map_type::const_iterator pval_map_const_iterator; |
|
492 |
|
493 typedef plist_map_type::iterator plist_map_iterator; |
|
494 typedef plist_map_type::const_iterator plist_map_const_iterator; |
|
495 |
|
496 property_list (const plist_map_type& m = plist_map_type ()) |
|
497 : plist_map (m) { } |
|
498 |
|
499 ~property_list (void) { } |
|
500 |
7189
|
501 void set (const caseless_str& name, const octave_value& val); |
6874
|
502 |
7189
|
503 octave_value lookup (const caseless_str& name) const; |
6874
|
504 |
|
505 plist_map_iterator begin (void) { return plist_map.begin (); } |
|
506 plist_map_const_iterator begin (void) const { return plist_map.begin (); } |
|
507 |
|
508 plist_map_iterator end (void) { return plist_map.end (); } |
|
509 plist_map_const_iterator end (void) const { return plist_map.end (); } |
|
510 |
|
511 plist_map_iterator find (const std::string& go_name) |
|
512 { |
|
513 return plist_map.find (go_name); |
|
514 } |
|
515 |
|
516 plist_map_const_iterator find (const std::string& go_name) const |
|
517 { |
|
518 return plist_map.find (go_name); |
|
519 } |
|
520 |
|
521 Octave_map as_struct (const std::string& prefix_arg) const; |
|
522 |
|
523 private: |
|
524 plist_map_type plist_map; |
|
525 }; |
|
526 |
|
527 // --------------------------------------------------------------------- |
|
528 |
|
529 class graphics_handle |
|
530 { |
|
531 public: |
|
532 graphics_handle (void) : val (octave_NaN) { } |
|
533 |
|
534 graphics_handle (const octave_value& a); |
|
535 |
|
536 graphics_handle (int a) : val (a) { } |
|
537 |
|
538 graphics_handle (double a) : val (a) { } |
|
539 |
|
540 graphics_handle (const graphics_handle& a) : val (a.val) { } |
|
541 |
|
542 graphics_handle& operator = (const graphics_handle& a) |
|
543 { |
|
544 if (&a != this) |
|
545 val = a.val; |
|
546 |
|
547 return *this; |
|
548 } |
|
549 |
|
550 ~graphics_handle (void) { } |
|
551 |
|
552 double value (void) const { return val; } |
|
553 |
|
554 octave_value as_octave_value (void) const |
|
555 { |
|
556 return ok () ? octave_value (val) : octave_value (Matrix ()); |
|
557 } |
|
558 |
|
559 graphics_handle operator ++ (void) |
|
560 { |
|
561 ++val; |
|
562 return *this; |
|
563 } |
|
564 |
|
565 graphics_handle operator ++ (int) |
|
566 { |
|
567 graphics_handle h = *this; |
|
568 ++val; |
|
569 return h; |
|
570 } |
|
571 |
|
572 graphics_handle operator -- (void) |
|
573 { |
|
574 --val; |
|
575 return *this; |
|
576 } |
|
577 |
|
578 graphics_handle operator -- (int) |
|
579 { |
|
580 graphics_handle h = *this; |
|
581 --val; |
|
582 return h; |
|
583 } |
|
584 |
|
585 bool ok (void) const { return ! xisnan (val); } |
|
586 |
|
587 private: |
|
588 double val; |
|
589 }; |
|
590 |
|
591 inline bool |
|
592 operator == (const graphics_handle& a, const graphics_handle& b) |
|
593 { |
|
594 return a.value () == b.value (); |
|
595 } |
|
596 |
|
597 inline bool |
|
598 operator != (const graphics_handle& a, const graphics_handle& b) |
|
599 { |
|
600 return a.value () != b.value (); |
|
601 } |
|
602 |
|
603 inline bool |
|
604 operator < (const graphics_handle& a, const graphics_handle& b) |
|
605 { |
|
606 return a.value () < b.value (); |
|
607 } |
|
608 |
|
609 inline bool |
|
610 operator <= (const graphics_handle& a, const graphics_handle& b) |
|
611 { |
|
612 return a.value () <= b.value (); |
|
613 } |
|
614 |
|
615 inline bool |
|
616 operator >= (const graphics_handle& a, const graphics_handle& b) |
|
617 { |
|
618 return a.value () >= b.value (); |
|
619 } |
|
620 |
|
621 inline bool |
|
622 operator > (const graphics_handle& a, const graphics_handle& b) |
|
623 { |
|
624 return a.value () > b.value (); |
|
625 } |
|
626 |
|
627 // --------------------------------------------------------------------- |
|
628 |
|
629 class base_graphics_object; |
|
630 |
|
631 class base_properties |
|
632 { |
|
633 public: |
7176
|
634 base_properties (const std::string& ty = "unknown", |
6874
|
635 const graphics_handle& mh = graphics_handle (), |
|
636 const graphics_handle& p = graphics_handle ()) |
7176
|
637 : tag (), type (ty), __modified__ (true), __myhandle__ (mh), |
|
638 parent (p), children () { } |
6874
|
639 |
|
640 virtual ~base_properties (void) { } |
|
641 |
|
642 virtual std::string graphics_object_name (void) const { return "unknonwn"; } |
|
643 |
|
644 void mark_modified (void); |
|
645 |
|
646 void override_defaults (base_graphics_object& obj); |
|
647 |
|
648 // Look through DEFAULTS for properties with given CLASS_NAME, and |
|
649 // apply them to the current object with set (virtual method). |
|
650 |
|
651 void set_from_list (base_graphics_object& obj, property_list& defaults); |
|
652 |
7189
|
653 virtual void set (const caseless_str&, const octave_value&) { } |
6874
|
654 |
7176
|
655 std::string get_tag (void) const { return tag; } |
|
656 |
6874
|
657 graphics_handle get_parent (void) const { return parent; } |
|
658 |
7251
|
659 std::string get_type (void) const { return type; } |
|
660 |
|
661 bool is_modified (void) const { return __modified__; } |
|
662 |
|
663 graphics_handle get___myhandle__ (void) const { return __myhandle__; } |
|
664 |
6874
|
665 void remove_child (const graphics_handle& h); |
|
666 |
|
667 void adopt (const graphics_handle& h) |
|
668 { |
|
669 octave_idx_type n = children.numel (); |
|
670 children.resize (1, n+1); |
7056
|
671 children(n) = h.value (); |
6874
|
672 } |
|
673 |
7176
|
674 void set_tag (const octave_value& val); |
|
675 |
6874
|
676 void set_parent (const octave_value& val); |
|
677 |
|
678 void reparent (const graphics_handle& new_parent) { parent = new_parent; } |
|
679 |
7214
|
680 // Update data limits for AXIS_TYPE (xdata, ydata, etc.) in the parent |
|
681 // axes object. |
|
682 |
|
683 void update_axis_limits (const std::string& axis_type) const; |
|
684 |
6874
|
685 virtual void delete_children (void); |
|
686 |
7222
|
687 Matrix get_children (void) const { return children; } |
|
688 |
|
689 // FIXME -- these functions should be generated automatically by the |
|
690 // genprops.awk script. |
|
691 // |
|
692 // EMIT_BASE_PROPERTIES_GET_FUNCTIONS |
|
693 virtual data_property get_xdata (void) const |
|
694 { |
|
695 error ("get: invalid property \"xdata\""); |
|
696 return data_property (); |
|
697 } |
|
698 |
|
699 virtual data_property get_ydata (void) const |
|
700 { |
|
701 error ("get: invalid property \"ydata\""); |
|
702 return data_property (); |
|
703 } |
|
704 |
|
705 virtual data_property get_zdata (void) const |
|
706 { |
|
707 error ("get: invalid property \"zdata\""); |
|
708 return data_property (); |
|
709 } |
|
710 |
|
711 virtual data_property get_ldata (void) const |
|
712 { |
|
713 error ("get: invalid property \"ldata\""); |
|
714 return data_property (); |
|
715 } |
|
716 |
|
717 virtual data_property get_udata (void) const |
|
718 { |
|
719 error ("get: invalid property \"udata\""); |
|
720 return data_property (); |
|
721 } |
|
722 |
|
723 virtual data_property get_xldata (void) const |
|
724 { |
|
725 error ("get: invalid property \"xldata\""); |
|
726 return data_property (); |
|
727 } |
|
728 |
|
729 virtual data_property get_xudata (void) const |
|
730 { |
|
731 error ("get: invalid property \"xudata\""); |
|
732 return data_property (); |
|
733 } |
|
734 |
|
735 virtual data_property get_cdata (void) const |
|
736 { |
|
737 error ("get: invalid property \"cdata\""); |
|
738 return data_property (); |
|
739 } |
|
740 |
6874
|
741 protected: |
7176
|
742 std::string tag; |
6874
|
743 std::string type; |
|
744 bool __modified__; |
|
745 graphics_handle __myhandle__; |
|
746 graphics_handle parent; |
|
747 Matrix children; |
|
748 }; |
|
749 |
|
750 class base_graphics_object |
|
751 { |
|
752 public: |
|
753 friend class graphics_object; |
|
754 |
|
755 base_graphics_object (void) : count (1) { } |
|
756 |
|
757 base_graphics_object (const base_graphics_object&) { } |
|
758 |
|
759 virtual ~base_graphics_object (void) { } |
|
760 |
|
761 virtual void mark_modified (void) |
|
762 { |
|
763 error ("base_graphics_object::mark_modified: invalid graphics object"); |
|
764 } |
|
765 |
|
766 virtual void override_defaults (base_graphics_object&) |
|
767 { |
|
768 error ("base_graphics_object::override_defaults: invalid graphics object"); |
|
769 } |
|
770 |
|
771 virtual void set_from_list (property_list&) |
|
772 { |
|
773 error ("base_graphics_object::set_from_list: invalid graphics object"); |
|
774 } |
|
775 |
7189
|
776 virtual void set (const caseless_str&, const octave_value&) |
6874
|
777 { |
|
778 error ("base_graphics_object::set: invalid graphics object"); |
|
779 } |
|
780 |
|
781 virtual void set_defaults (const std::string&) |
|
782 { |
|
783 error ("base_graphics_object::set_defaults: invalid graphics object"); |
|
784 } |
|
785 |
|
786 virtual octave_value get (void) const |
|
787 { |
|
788 error ("base_graphics_object::get: invalid graphics object"); |
|
789 return octave_value (); |
|
790 } |
|
791 |
7189
|
792 virtual octave_value get (const caseless_str&) const |
6874
|
793 { |
|
794 error ("base_graphics_object::get: invalid graphics object"); |
|
795 return octave_value (); |
|
796 } |
|
797 |
7189
|
798 virtual octave_value get_default (const caseless_str&) const; |
6874
|
799 |
7189
|
800 virtual octave_value get_factory_default (const caseless_str&) const; |
6874
|
801 |
|
802 virtual octave_value get_defaults (void) const |
|
803 { |
|
804 error ("base_graphics_object::get_defaults: invalid graphics object"); |
|
805 return octave_value (); |
|
806 } |
|
807 |
|
808 virtual octave_value get_factory_defaults (void) const |
|
809 { |
|
810 error ("base_graphics_object::get_factory_defaults: invalid graphics object"); |
|
811 return octave_value (); |
|
812 } |
|
813 |
|
814 virtual graphics_handle get_parent (void) const |
|
815 { |
|
816 error ("base_graphics_object::get_parent: invalid graphics object"); |
|
817 return graphics_handle (); |
|
818 } |
|
819 |
|
820 virtual void remove_child (const graphics_handle&) |
|
821 { |
|
822 error ("base_graphics_object::remove_child: invalid graphics object"); |
|
823 } |
|
824 |
|
825 virtual void adopt (const graphics_handle&) |
|
826 { |
|
827 error ("base_graphics_object::adopt: invalid graphics object"); |
|
828 } |
|
829 |
|
830 virtual void reparent (const graphics_handle&) |
|
831 { |
|
832 error ("base_graphics_object::reparent: invalid graphics object"); |
|
833 } |
|
834 |
|
835 virtual void defaults (void) const |
|
836 { |
|
837 error ("base_graphics_object::default: invalid graphics object"); |
|
838 } |
|
839 |
|
840 virtual base_properties& get_properties (void) |
|
841 { |
|
842 static base_properties properties; |
|
843 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
844 return properties; |
|
845 } |
|
846 |
7222
|
847 virtual const base_properties& get_properties (void) const |
|
848 { |
|
849 static base_properties properties; |
|
850 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
851 return properties; |
|
852 } |
|
853 |
|
854 virtual void update_axis_limits (const std::string&) |
7214
|
855 { |
|
856 error ("base_graphics_object::update_axis_limits: invalid graphics object"); |
|
857 } |
|
858 |
6874
|
859 virtual bool valid_object (void) const { return false; } |
|
860 |
|
861 virtual std::string type (void) const { return "unknown"; } |
|
862 |
|
863 bool isa (const std::string& go_name) const |
|
864 { |
|
865 return type () == go_name; |
|
866 } |
|
867 |
|
868 protected: |
|
869 // A reference count. |
|
870 int count; |
|
871 }; |
|
872 |
|
873 class graphics_object |
|
874 { |
|
875 public: |
|
876 graphics_object (void) : rep (new base_graphics_object ()) { } |
|
877 |
|
878 graphics_object (base_graphics_object *new_rep) |
|
879 : rep (new_rep) { } |
|
880 |
|
881 graphics_object (const graphics_object& obj) |
|
882 { |
|
883 rep = obj.rep; |
|
884 rep->count++; |
|
885 } |
|
886 |
|
887 graphics_object& operator = (const graphics_object& obj) |
|
888 { |
|
889 if (rep != obj.rep) |
|
890 { |
|
891 if (--rep->count == 0) |
|
892 delete rep; |
|
893 |
|
894 rep = obj.rep; |
|
895 rep->count++; |
|
896 } |
|
897 |
|
898 return *this; |
|
899 } |
|
900 |
|
901 ~graphics_object (void) |
|
902 { |
|
903 if (--rep->count == 0) |
|
904 delete rep; |
|
905 } |
|
906 |
|
907 void mark_modified (void) { rep->mark_modified (); } |
|
908 |
|
909 void override_defaults (base_graphics_object& obj) |
|
910 { |
|
911 rep->override_defaults (obj); |
|
912 } |
|
913 |
7214
|
914 void set_from_list (property_list& plist) { rep->set_from_list (plist); } |
6874
|
915 |
7189
|
916 void set (const caseless_str& name, const octave_value& val) |
6874
|
917 { |
|
918 rep->set (name, val); |
|
919 } |
|
920 |
|
921 void set (const octave_value_list& args); |
|
922 |
7214
|
923 void set_defaults (const std::string& mode) { rep->set_defaults (mode); } |
|
924 |
|
925 octave_value get (void) const { return rep->get (); } |
6874
|
926 |
7189
|
927 octave_value get (const caseless_str& name) const |
6874
|
928 { |
|
929 return name.compare ("default") |
|
930 ? get_defaults () |
|
931 : (name.compare ("factory") |
|
932 ? get_factory_defaults () : rep->get (name)); |
|
933 } |
|
934 |
7189
|
935 octave_value get_default (const caseless_str& name) const |
6874
|
936 { |
|
937 return rep->get_default (name); |
|
938 } |
|
939 |
7189
|
940 octave_value get_factory_default (const caseless_str& name) const |
6874
|
941 { |
|
942 return rep->get_factory_default (name); |
|
943 } |
|
944 |
|
945 octave_value get_defaults (void) const { return rep->get_defaults (); } |
|
946 |
|
947 octave_value get_factory_defaults (void) const |
|
948 { |
|
949 return rep->get_factory_defaults (); |
|
950 } |
|
951 |
|
952 graphics_handle get_parent (void) const { return rep->get_parent (); } |
|
953 |
7214
|
954 void remove_child (const graphics_handle& h) { rep->remove_child (h); } |
|
955 |
|
956 void adopt (const graphics_handle& h) { rep->adopt (h); } |
|
957 |
|
958 void reparent (const graphics_handle& h) { rep->reparent (h); } |
6874
|
959 |
|
960 void defaults (void) const { rep->defaults (); } |
|
961 |
|
962 bool isa (const std::string& go_name) const { return rep->isa (go_name); } |
|
963 |
|
964 base_properties& get_properties (void) { return rep->get_properties (); } |
|
965 |
7222
|
966 const base_properties& get_properties (void) const |
|
967 { |
|
968 return rep->get_properties (); |
|
969 } |
|
970 |
7214
|
971 void update_axis_limits (const std::string& axis_type) |
|
972 { |
|
973 rep->update_axis_limits (axis_type); |
|
974 } |
|
975 |
6874
|
976 bool valid_object (void) const { return rep->valid_object (); } |
|
977 |
|
978 operator bool (void) const { return rep->valid_object (); } |
|
979 |
7222
|
980 // FIXME -- these functions should be generated automatically by the |
|
981 // genprops.awk script. |
|
982 // |
|
983 // EMIT_GRAPHICS_OBJECT_GET_FUNCTIONS |
|
984 data_property get_xdata (void) const |
|
985 { |
|
986 const base_properties& props = get_properties (); |
|
987 return props.get_xdata (); |
|
988 } |
|
989 |
|
990 data_property get_ydata (void) const |
|
991 { |
|
992 const base_properties& props = get_properties (); |
|
993 return props.get_ydata (); |
|
994 } |
|
995 |
|
996 data_property get_zdata (void) const |
|
997 { |
|
998 const base_properties& props = get_properties (); |
|
999 return props.get_zdata (); |
|
1000 } |
|
1001 |
|
1002 data_property get_ldata (void) const |
|
1003 { |
|
1004 const base_properties& props = get_properties (); |
|
1005 return props.get_ldata (); |
|
1006 } |
|
1007 |
|
1008 data_property get_udata (void) const |
|
1009 { |
|
1010 const base_properties& props = get_properties (); |
|
1011 return props.get_udata (); |
|
1012 } |
|
1013 |
|
1014 data_property get_xldata (void) const |
|
1015 { |
|
1016 const base_properties& props = get_properties (); |
|
1017 return props.get_xldata (); |
|
1018 } |
|
1019 |
|
1020 data_property get_xudata (void) const |
|
1021 { |
|
1022 const base_properties& props = get_properties (); |
|
1023 return props.get_xudata (); |
|
1024 } |
|
1025 |
|
1026 data_property get_cdata (void) const |
|
1027 { |
|
1028 const base_properties& props = get_properties (); |
|
1029 return props.get_cdata (); |
|
1030 } |
|
1031 |
6874
|
1032 private: |
|
1033 base_graphics_object *rep; |
|
1034 }; |
|
1035 |
|
1036 // --------------------------------------------------------------------- |
|
1037 |
|
1038 class root_figure : public base_graphics_object |
|
1039 { |
|
1040 public: |
|
1041 class properties : public base_properties |
|
1042 { |
|
1043 public: |
|
1044 properties (void) |
|
1045 : base_properties ("root figure", 0, graphics_handle ()), |
|
1046 currentfigure (), |
|
1047 visible ("on") |
|
1048 { } |
|
1049 |
|
1050 ~properties (void) { } |
|
1051 |
7189
|
1052 void set (const caseless_str& name, const octave_value& val); |
6874
|
1053 |
|
1054 octave_value get (void) const; |
|
1055 |
7189
|
1056 octave_value get (const caseless_str& name) const; |
6874
|
1057 |
|
1058 std::string graphics_object_name (void) const { return go_name; } |
|
1059 |
|
1060 // See the genprops.awk script for an explanation of the |
|
1061 // properties declarations. |
|
1062 |
|
1063 BEGIN_PROPERTIES |
|
1064 graphics_handle currentfigure S |
|
1065 octave_value visible |
|
1066 END_PROPERTIES |
|
1067 |
|
1068 static std::string go_name; |
|
1069 }; |
|
1070 |
|
1071 private: |
|
1072 properties xproperties; |
|
1073 |
|
1074 public: |
|
1075 |
|
1076 root_figure (void) : xproperties (), default_properties () { } |
|
1077 |
|
1078 ~root_figure (void) { xproperties.delete_children (); } |
|
1079 |
|
1080 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1081 |
|
1082 void mark_modified (void) { } |
|
1083 |
|
1084 void override_defaults (base_graphics_object& obj) |
|
1085 { |
|
1086 // Now override with our defaults. If the default_properties |
|
1087 // list includes the properties for all defaults (line, |
|
1088 // surface, etc.) then we don't have to know the type of OBJ |
|
1089 // here, we just call its set function and let it decide which |
|
1090 // properties from the list to use. |
|
1091 obj.set_from_list (default_properties); |
|
1092 } |
|
1093 |
|
1094 void set_from_list (property_list& plist) |
|
1095 { |
|
1096 xproperties.set_from_list (*this, plist); |
|
1097 } |
|
1098 |
7189
|
1099 void set (const caseless_str& name, const octave_value& value) |
6874
|
1100 { |
|
1101 if (name.compare ("default", 7)) |
|
1102 // strip "default", pass rest to function that will |
|
1103 // parse the remainder and add the element to the |
|
1104 // default_properties map. |
|
1105 default_properties.set (name.substr (7), value); |
|
1106 else |
|
1107 xproperties.set (name, value); |
|
1108 } |
|
1109 |
|
1110 octave_value get (void) const |
|
1111 { |
|
1112 return xproperties.get (); |
|
1113 } |
|
1114 |
7189
|
1115 octave_value get (const caseless_str& name) const |
6874
|
1116 { |
|
1117 octave_value retval; |
|
1118 |
|
1119 if (name.compare ("default", 7)) |
|
1120 return get_default (name.substr (7)); |
|
1121 else if (name.compare ("factory", 7)) |
|
1122 return get_factory_default (name.substr (7)); |
|
1123 else |
|
1124 retval = xproperties.get (name); |
|
1125 |
|
1126 return retval; |
|
1127 } |
|
1128 |
7189
|
1129 octave_value get_default (const caseless_str& name) const |
6874
|
1130 { |
|
1131 octave_value retval = default_properties.lookup (name); |
|
1132 |
|
1133 if (retval.is_undefined ()) |
|
1134 error ("get: invalid default property `%s'", name.c_str ()); |
|
1135 |
|
1136 return retval; |
|
1137 } |
|
1138 |
7189
|
1139 octave_value get_factory_default (const caseless_str& name) const |
6874
|
1140 { |
|
1141 octave_value retval = factory_properties.lookup (name); |
|
1142 |
|
1143 if (retval.is_undefined ()) |
|
1144 error ("get: invalid factory default property `%s'", name.c_str ()); |
|
1145 |
|
1146 return retval; |
|
1147 } |
|
1148 |
|
1149 octave_value get_defaults (void) const |
|
1150 { |
|
1151 return default_properties.as_struct ("default"); |
|
1152 } |
|
1153 |
|
1154 octave_value get_factory_defaults (void) const |
|
1155 { |
|
1156 return factory_properties.as_struct ("factory"); |
|
1157 } |
|
1158 |
|
1159 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1160 |
|
1161 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1162 |
|
1163 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1164 |
|
1165 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
1166 |
|
1167 base_properties& get_properties (void) { return xproperties; } |
|
1168 |
7222
|
1169 const base_properties& get_properties (void) const { return xproperties; } |
|
1170 |
6890
|
1171 void defaults (void) const |
|
1172 { |
|
1173 gripe_not_implemented ("root_figure::defaults"); |
|
1174 } |
|
1175 |
6874
|
1176 bool valid_object (void) const { return true; } |
|
1177 |
|
1178 private: |
|
1179 property_list default_properties; |
|
1180 |
|
1181 static property_list factory_properties; |
|
1182 |
|
1183 static property_list::plist_map_type init_factory_properties (void); |
|
1184 }; |
|
1185 |
|
1186 // --------------------------------------------------------------------- |
|
1187 |
|
1188 class figure : public base_graphics_object |
|
1189 { |
|
1190 public: |
|
1191 class properties : public base_properties |
|
1192 { |
|
1193 public: |
|
1194 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1195 |
|
1196 ~properties (void) { } |
|
1197 |
7189
|
1198 void set (const caseless_str& name, const octave_value& val); |
6874
|
1199 |
|
1200 octave_value get (void) const; |
|
1201 |
7189
|
1202 octave_value get (const caseless_str& name) const; |
6874
|
1203 |
|
1204 void close (void); |
|
1205 |
|
1206 std::string graphics_object_name (void) const { return go_name; } |
|
1207 |
|
1208 static property_list::pval_map_type factory_defaults (void); |
|
1209 |
|
1210 // See the genprops.awk script for an explanation of the |
|
1211 // properties declarations. |
|
1212 |
|
1213 BEGIN_PROPERTIES |
|
1214 octave_value __plot_stream__ |
7189
|
1215 octave_value __enhanced__ |
6874
|
1216 octave_value nextplot |
|
1217 octave_value closerequestfcn |
|
1218 graphics_handle currentaxes S |
|
1219 colormap_property colormap |
|
1220 octave_value visible S |
|
1221 octave_value paperorientation |
7283
|
1222 color_property color |
6874
|
1223 END_PROPERTIES |
|
1224 |
|
1225 static std::string go_name; |
|
1226 }; |
|
1227 |
|
1228 private: |
|
1229 properties xproperties; |
|
1230 |
|
1231 public: |
|
1232 figure (const graphics_handle& mh, const graphics_handle& p) |
|
1233 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1234 { |
|
1235 xproperties.override_defaults (*this); |
|
1236 } |
|
1237 |
|
1238 ~figure (void) |
|
1239 { |
|
1240 xproperties.delete_children (); |
|
1241 xproperties.close (); |
|
1242 } |
|
1243 |
|
1244 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1245 |
|
1246 void mark_modified (void) { xproperties.mark_modified (); } |
|
1247 |
|
1248 void override_defaults (base_graphics_object& obj) |
|
1249 { |
|
1250 // Allow parent (root figure) to override first (properties knows how |
|
1251 // to find the parent object). |
|
1252 xproperties.override_defaults (obj); |
|
1253 |
|
1254 // Now override with our defaults. If the default_properties |
|
1255 // list includes the properties for all defaults (line, |
|
1256 // surface, etc.) then we don't have to know the type of OBJ |
|
1257 // here, we just call its set function and let it decide which |
|
1258 // properties from the list to use. |
|
1259 obj.set_from_list (default_properties); |
|
1260 } |
|
1261 |
|
1262 void set_from_list (property_list& plist) |
|
1263 { |
|
1264 xproperties.set_from_list (*this, plist); |
|
1265 } |
|
1266 |
7189
|
1267 void set (const caseless_str& name, const octave_value& value) |
6874
|
1268 { |
|
1269 if (name.compare ("default", 7)) |
|
1270 // strip "default", pass rest to function that will |
|
1271 // parse the remainder and add the element to the |
|
1272 // default_properties map. |
|
1273 default_properties.set (name.substr (7), value); |
|
1274 else |
|
1275 xproperties.set (name, value); |
|
1276 } |
|
1277 |
|
1278 octave_value get (void) const |
|
1279 { |
|
1280 return xproperties.get (); |
|
1281 } |
|
1282 |
7189
|
1283 octave_value get (const caseless_str& name) const |
6874
|
1284 { |
|
1285 octave_value retval; |
|
1286 |
|
1287 if (name.compare ("default", 7)) |
|
1288 retval = get_default (name.substr (7)); |
|
1289 else |
|
1290 retval = xproperties.get (name); |
|
1291 |
|
1292 return retval; |
|
1293 } |
|
1294 |
7189
|
1295 octave_value get_default (const caseless_str& name) const; |
6874
|
1296 |
|
1297 octave_value get_defaults (void) const |
|
1298 { |
|
1299 return default_properties.as_struct ("default"); |
|
1300 } |
|
1301 |
|
1302 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1303 |
|
1304 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1305 |
|
1306 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1307 |
|
1308 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
1309 |
|
1310 base_properties& get_properties (void) { return xproperties; } |
|
1311 |
7222
|
1312 const base_properties& get_properties (void) const { return xproperties; } |
|
1313 |
6890
|
1314 void defaults (void) const { gripe_not_implemented ("figure::defaults"); } |
|
1315 |
6874
|
1316 bool valid_object (void) const { return true; } |
|
1317 |
|
1318 private: |
|
1319 property_list default_properties; |
|
1320 }; |
|
1321 |
|
1322 // --------------------------------------------------------------------- |
|
1323 |
|
1324 class axes : public base_graphics_object |
|
1325 { |
|
1326 public: |
|
1327 class properties : public base_properties |
|
1328 { |
|
1329 public: |
|
1330 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1331 |
|
1332 ~properties (void) { } |
|
1333 |
7189
|
1334 void set (const caseless_str& name, const octave_value& val); |
6874
|
1335 |
|
1336 void set_defaults (base_graphics_object& obj, const std::string& mode); |
|
1337 |
|
1338 octave_value get (void) const; |
|
1339 |
7189
|
1340 octave_value get (const caseless_str& name) const; |
6874
|
1341 |
|
1342 void remove_child (const graphics_handle& h); |
|
1343 |
|
1344 void delete_children (void); |
|
1345 |
|
1346 std::string graphics_object_name (void) const { return go_name; } |
|
1347 |
|
1348 static property_list::pval_map_type factory_defaults (void); |
|
1349 |
|
1350 // See the genprops.awk script for an explanation of the |
|
1351 // properties declarations. |
|
1352 |
|
1353 BEGIN_PROPERTIES |
|
1354 octave_value position |
|
1355 mutable graphics_handle title GSO |
|
1356 octave_value box |
|
1357 octave_value key |
|
1358 octave_value keybox |
|
1359 octave_value keypos |
6962
|
1360 octave_value colororder |
6874
|
1361 octave_value dataaspectratio m |
|
1362 octave_value dataaspectratiomode |
7307
|
1363 radio_property layer a |
6874
|
1364 octave_value xlim m |
|
1365 octave_value ylim m |
|
1366 octave_value zlim m |
|
1367 octave_value clim m |
7222
|
1368 radio_property xlimmode al |
|
1369 radio_property ylimmode al |
|
1370 radio_property zlimmode al |
|
1371 radio_property climmode al |
6874
|
1372 mutable graphics_handle xlabel GSO |
|
1373 mutable graphics_handle ylabel GSO |
|
1374 mutable graphics_handle zlabel GSO |
|
1375 octave_value xgrid |
|
1376 octave_value ygrid |
|
1377 octave_value zgrid |
|
1378 octave_value xminorgrid |
|
1379 octave_value yminorgrid |
|
1380 octave_value zminorgrid |
|
1381 octave_value xtick m |
|
1382 octave_value ytick m |
|
1383 octave_value ztick m |
|
1384 octave_value xtickmode |
|
1385 octave_value ytickmode |
|
1386 octave_value ztickmode |
|
1387 octave_value xticklabel m |
|
1388 octave_value yticklabel m |
|
1389 octave_value zticklabel m |
|
1390 octave_value xticklabelmode |
|
1391 octave_value yticklabelmode |
|
1392 octave_value zticklabelmode |
7240
|
1393 color_property color a |
7194
|
1394 color_property xcolor |
|
1395 color_property ycolor |
|
1396 color_property zcolor |
7222
|
1397 radio_property xscale al |
|
1398 radio_property yscale al |
|
1399 radio_property zscale al |
6874
|
1400 octave_value xdir |
|
1401 octave_value ydir |
|
1402 octave_value zdir |
|
1403 octave_value xaxislocation |
|
1404 octave_value yaxislocation |
|
1405 octave_value view |
|
1406 octave_value visible |
|
1407 octave_value nextplot |
|
1408 octave_value outerposition |
7240
|
1409 radio_property activepositionproperty a |
7189
|
1410 radio_property __colorbar__ a |
|
1411 END_PROPERTIES |
6874
|
1412 |
|
1413 static std::string go_name; |
|
1414 }; |
|
1415 |
|
1416 private: |
|
1417 properties xproperties; |
|
1418 |
|
1419 public: |
|
1420 axes (const graphics_handle& mh, const graphics_handle& p) |
|
1421 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1422 { |
|
1423 xproperties.override_defaults (*this); |
|
1424 } |
|
1425 |
|
1426 ~axes (void) { xproperties.delete_children (); } |
|
1427 |
|
1428 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1429 |
|
1430 void mark_modified (void) { xproperties.mark_modified (); } |
|
1431 |
|
1432 void override_defaults (base_graphics_object& obj) |
|
1433 { |
|
1434 // Allow parent (figure) to override first (properties knows how |
|
1435 // to find the parent object). |
|
1436 xproperties.override_defaults (obj); |
|
1437 |
|
1438 // Now override with our defaults. If the default_properties |
|
1439 // list includes the properties for all defaults (line, |
|
1440 // surface, etc.) then we don't have to know the type of OBJ |
|
1441 // here, we just call its set function and let it decide which |
|
1442 // properties from the list to use. |
|
1443 obj.set_from_list (default_properties); |
|
1444 } |
|
1445 |
|
1446 void set_from_list (property_list& plist) |
|
1447 { |
|
1448 xproperties.set_from_list (*this, plist); |
|
1449 } |
|
1450 |
7189
|
1451 void set (const caseless_str& name, const octave_value& value) |
6874
|
1452 { |
|
1453 if (name.compare ("default", 7)) |
|
1454 // strip "default", pass rest to function that will |
|
1455 // parse the remainder and add the element to the |
|
1456 // default_properties map. |
|
1457 default_properties.set (name.substr (7), value); |
|
1458 else |
|
1459 xproperties.set (name, value); |
|
1460 } |
|
1461 |
|
1462 void set_defaults (const std::string& mode) |
|
1463 { |
|
1464 xproperties.set_defaults (*this, mode); |
|
1465 } |
|
1466 |
|
1467 octave_value get (void) const |
|
1468 { |
|
1469 return xproperties.get (); |
|
1470 } |
|
1471 |
7189
|
1472 octave_value get (const caseless_str& name) const |
6874
|
1473 { |
|
1474 octave_value retval; |
|
1475 |
|
1476 // FIXME -- finish this. |
|
1477 if (name.compare ("default", 7)) |
|
1478 retval = get_default (name.substr (7)); |
|
1479 else |
|
1480 retval = xproperties.get (name); |
|
1481 |
|
1482 return retval; |
|
1483 } |
|
1484 |
7189
|
1485 octave_value get_default (const caseless_str& name) const; |
6874
|
1486 |
|
1487 octave_value get_defaults (void) const |
|
1488 { |
|
1489 return default_properties.as_struct ("default"); |
|
1490 } |
|
1491 |
|
1492 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1493 |
|
1494 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1495 |
|
1496 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1497 |
|
1498 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
1499 |
|
1500 base_properties& get_properties (void) { return xproperties; } |
|
1501 |
7222
|
1502 const base_properties& get_properties (void) const { return xproperties; } |
|
1503 |
6890
|
1504 void defaults (void) const { gripe_not_implemented ("axes::defaults"); } |
|
1505 |
7214
|
1506 void update_axis_limits (const std::string& axis_type); |
|
1507 |
6874
|
1508 bool valid_object (void) const { return true; } |
|
1509 |
|
1510 private: |
|
1511 property_list default_properties; |
|
1512 }; |
|
1513 |
|
1514 // --------------------------------------------------------------------- |
|
1515 |
|
1516 class line : public base_graphics_object |
|
1517 { |
|
1518 public: |
|
1519 class properties : public base_properties |
|
1520 { |
|
1521 public: |
|
1522 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1523 |
|
1524 ~properties (void) { } |
|
1525 |
7189
|
1526 void set (const caseless_str& name, const octave_value& val); |
6874
|
1527 |
|
1528 octave_value get (void) const; |
|
1529 |
7189
|
1530 octave_value get (const caseless_str& name) const; |
6874
|
1531 |
|
1532 std::string graphics_object_name (void) const { return go_name; } |
|
1533 |
|
1534 static property_list::pval_map_type factory_defaults (void); |
|
1535 |
|
1536 // See the genprops.awk script for an explanation of the |
|
1537 // properties declarations. |
|
1538 |
|
1539 BEGIN_PROPERTIES |
7214
|
1540 data_property xdata l |
|
1541 data_property ydata l |
|
1542 data_property zdata l |
|
1543 data_property ldata l |
|
1544 data_property udata l |
|
1545 data_property xldata l |
|
1546 data_property xudata l |
6874
|
1547 color_property color |
|
1548 octave_value linestyle |
|
1549 octave_value linewidth |
|
1550 octave_value marker |
|
1551 octave_value markeredgecolor |
|
1552 octave_value markerfacecolor |
|
1553 octave_value markersize |
|
1554 octave_value keylabel |
7189
|
1555 radio_property interpreter a |
6874
|
1556 END_PROPERTIES |
|
1557 |
|
1558 static std::string go_name; |
|
1559 }; |
|
1560 |
|
1561 private: |
|
1562 properties xproperties; |
|
1563 |
|
1564 public: |
|
1565 line (const graphics_handle& mh, const graphics_handle& p) |
|
1566 : base_graphics_object (), xproperties (mh, p) |
|
1567 { |
|
1568 xproperties.override_defaults (*this); |
|
1569 } |
|
1570 |
|
1571 ~line (void) { xproperties.delete_children (); } |
|
1572 |
|
1573 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1574 |
|
1575 void mark_modified (void) { xproperties.mark_modified (); } |
|
1576 |
|
1577 void override_defaults (base_graphics_object& obj) |
|
1578 { |
|
1579 // Allow parent (figure) to override first (properties knows how |
|
1580 // to find the parent object). |
|
1581 xproperties.override_defaults (obj); |
|
1582 } |
|
1583 |
|
1584 void set_from_list (property_list& plist) |
|
1585 { |
|
1586 xproperties.set_from_list (*this, plist); |
|
1587 } |
|
1588 |
7189
|
1589 void set (const caseless_str& name, const octave_value& val) |
6874
|
1590 { |
|
1591 xproperties.set (name, val); |
|
1592 } |
|
1593 |
|
1594 octave_value get (void) const |
|
1595 { |
|
1596 return xproperties.get (); |
|
1597 } |
|
1598 |
7189
|
1599 octave_value get (const caseless_str& name) const |
6874
|
1600 { |
|
1601 return xproperties.get (name); |
|
1602 } |
|
1603 |
|
1604 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1605 |
|
1606 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1607 |
|
1608 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1609 |
|
1610 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1611 |
|
1612 base_properties& get_properties (void) { return xproperties; } |
|
1613 |
7222
|
1614 const base_properties& get_properties (void) const { return xproperties; } |
|
1615 |
6890
|
1616 void defaults (void) const { gripe_not_implemented ("line::defaults"); } |
|
1617 |
6874
|
1618 bool valid_object (void) const { return true; } |
|
1619 }; |
|
1620 |
|
1621 // --------------------------------------------------------------------- |
|
1622 |
|
1623 class text : public base_graphics_object |
|
1624 { |
|
1625 public: |
|
1626 class properties : public base_properties |
|
1627 { |
|
1628 public: |
|
1629 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1630 |
|
1631 ~properties (void) { } |
|
1632 |
7189
|
1633 void set (const caseless_str& name, const octave_value& val); |
6874
|
1634 |
|
1635 octave_value get (void) const; |
|
1636 |
7189
|
1637 octave_value get (const caseless_str& name) const; |
6874
|
1638 |
|
1639 std::string graphics_object_name (void) const { return go_name; } |
|
1640 |
|
1641 static property_list::pval_map_type factory_defaults (void); |
|
1642 |
|
1643 // See the genprops.awk script for an explanation of the |
|
1644 // properties declarations. |
|
1645 |
|
1646 BEGIN_PROPERTIES |
|
1647 octave_value string |
|
1648 octave_value units |
|
1649 octave_value position |
|
1650 octave_value rotation |
|
1651 octave_value horizontalalignment |
6890
|
1652 color_property color |
7162
|
1653 octave_value fontname |
|
1654 octave_value fontsize |
7189
|
1655 radio_property fontangle a |
|
1656 radio_property fontweight a |
|
1657 radio_property interpreter a |
6874
|
1658 END_PROPERTIES |
|
1659 |
|
1660 static std::string go_name; |
|
1661 }; |
|
1662 |
|
1663 private: |
|
1664 properties xproperties; |
|
1665 |
|
1666 public: |
|
1667 text (const graphics_handle& mh, const graphics_handle& p) |
|
1668 : base_graphics_object (), xproperties (mh, p) |
|
1669 { |
|
1670 xproperties.override_defaults (*this); |
|
1671 } |
|
1672 |
|
1673 ~text (void) { xproperties.delete_children (); } |
|
1674 |
|
1675 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1676 |
|
1677 void mark_modified (void) { xproperties.mark_modified (); } |
|
1678 |
|
1679 void override_defaults (base_graphics_object& obj) |
|
1680 { |
|
1681 // Allow parent (figure) to override first (properties knows how |
|
1682 // to find the parent object). |
|
1683 xproperties.override_defaults (obj); |
|
1684 } |
|
1685 |
|
1686 void set_from_list (property_list& plist) |
|
1687 { |
|
1688 xproperties.set_from_list (*this, plist); |
|
1689 } |
|
1690 |
7189
|
1691 void set (const caseless_str& name, const octave_value& val) |
6874
|
1692 { |
|
1693 xproperties.set (name, val); |
|
1694 } |
|
1695 |
|
1696 octave_value get (void) const |
|
1697 { |
|
1698 return xproperties.get (); |
|
1699 } |
|
1700 |
7189
|
1701 octave_value get (const caseless_str& name) const |
6874
|
1702 { |
|
1703 return xproperties.get (name); |
|
1704 } |
|
1705 |
|
1706 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1707 |
|
1708 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1709 |
|
1710 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1711 |
|
1712 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1713 |
|
1714 base_properties& get_properties (void) { return xproperties; } |
|
1715 |
7222
|
1716 const base_properties& get_properties (void) const { return xproperties; } |
|
1717 |
6890
|
1718 void defaults (void) const { gripe_not_implemented ("text::defaults"); } |
|
1719 |
6874
|
1720 bool valid_object (void) const { return true; } |
|
1721 }; |
|
1722 |
|
1723 // --------------------------------------------------------------------- |
|
1724 |
|
1725 class image : public base_graphics_object |
|
1726 { |
|
1727 public: |
|
1728 class properties : public base_properties |
|
1729 { |
|
1730 public: |
|
1731 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1732 |
|
1733 ~properties (void) { } |
|
1734 |
7189
|
1735 void set (const caseless_str& name, const octave_value& val); |
6874
|
1736 |
|
1737 octave_value get (void) const; |
|
1738 |
7189
|
1739 octave_value get (const caseless_str& name) const; |
6874
|
1740 |
|
1741 std::string graphics_object_name (void) const { return go_name; } |
|
1742 |
|
1743 static property_list::pval_map_type factory_defaults (void); |
|
1744 |
|
1745 // See the genprops.awk script for an explanation of the |
|
1746 // properties declarations. |
|
1747 |
|
1748 BEGIN_PROPERTIES |
7214
|
1749 data_property xdata l |
|
1750 data_property ydata l |
|
1751 data_property cdata l |
6874
|
1752 END_PROPERTIES |
|
1753 |
|
1754 static std::string go_name; |
|
1755 }; |
|
1756 |
|
1757 private: |
|
1758 properties xproperties; |
|
1759 |
|
1760 public: |
|
1761 image (const graphics_handle& mh, const graphics_handle& p) |
|
1762 : base_graphics_object (), xproperties (mh, p) |
|
1763 { |
|
1764 xproperties.override_defaults (*this); |
|
1765 } |
|
1766 |
|
1767 ~image (void) { xproperties.delete_children (); } |
|
1768 |
|
1769 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1770 |
|
1771 void mark_modified (void) { xproperties.mark_modified (); } |
|
1772 |
|
1773 void override_defaults (base_graphics_object& obj) |
|
1774 { |
|
1775 // Allow parent (figure) to override first (properties knows how |
|
1776 // to find the parent object). |
|
1777 xproperties.override_defaults (obj); |
|
1778 } |
|
1779 |
|
1780 void set_from_list (property_list& plist) |
|
1781 { |
|
1782 xproperties.set_from_list (*this, plist); |
|
1783 } |
|
1784 |
7189
|
1785 void set (const caseless_str& name, const octave_value& val) |
6874
|
1786 { |
|
1787 xproperties.set (name, val); |
|
1788 } |
|
1789 |
|
1790 octave_value get (void) const |
|
1791 { |
|
1792 return xproperties.get (); |
|
1793 } |
|
1794 |
7189
|
1795 octave_value get (const caseless_str& name) const |
6874
|
1796 { |
|
1797 return xproperties.get (name); |
|
1798 } |
|
1799 |
|
1800 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1801 |
|
1802 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1803 |
|
1804 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1805 |
|
1806 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1807 |
|
1808 base_properties& get_properties (void) { return xproperties; } |
|
1809 |
7222
|
1810 const base_properties& get_properties (void) const { return xproperties; } |
|
1811 |
6890
|
1812 void defaults (void) const { gripe_not_implemented ("image::defaults"); } |
|
1813 |
6874
|
1814 bool valid_object (void) const { return true; } |
|
1815 }; |
|
1816 |
|
1817 // --------------------------------------------------------------------- |
|
1818 |
|
1819 class patch : public base_graphics_object |
|
1820 { |
|
1821 public: |
|
1822 class properties : public base_properties |
|
1823 { |
|
1824 public: |
|
1825 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1826 |
|
1827 ~properties (void) { } |
|
1828 |
7189
|
1829 void set (const caseless_str& name, const octave_value& val); |
6874
|
1830 |
|
1831 octave_value get (void) const; |
|
1832 |
7189
|
1833 octave_value get (const caseless_str& name) const; |
6874
|
1834 |
|
1835 std::string graphics_object_name (void) const { return go_name; } |
|
1836 |
|
1837 static property_list::pval_map_type factory_defaults (void); |
|
1838 |
|
1839 // See the genprops.awk script for an explanation of the |
|
1840 // properties declarations. |
|
1841 |
|
1842 BEGIN_PROPERTIES |
7214
|
1843 data_property xdata l |
|
1844 data_property ydata l |
|
1845 data_property zdata l |
|
1846 data_property cdata l |
7020
|
1847 octave_value faces |
|
1848 octave_value vertices |
6938
|
1849 color_property facecolor a |
6874
|
1850 octave_value facealpha |
6938
|
1851 color_property edgecolor a |
6874
|
1852 octave_value linestyle |
|
1853 octave_value linewidth |
|
1854 octave_value marker |
|
1855 octave_value markeredgecolor |
|
1856 octave_value markerfacecolor |
|
1857 octave_value markersize |
7148
|
1858 octave_value keylabel |
7189
|
1859 radio_property interpreter a |
6874
|
1860 END_PROPERTIES |
|
1861 |
|
1862 static std::string go_name; |
|
1863 }; |
|
1864 |
|
1865 private: |
|
1866 properties xproperties; |
|
1867 |
|
1868 public: |
|
1869 patch (const graphics_handle& mh, const graphics_handle& p) |
|
1870 : base_graphics_object (), xproperties (mh, p) |
|
1871 { |
|
1872 xproperties.override_defaults (*this); |
|
1873 } |
|
1874 |
|
1875 ~patch (void) { xproperties.delete_children (); } |
|
1876 |
|
1877 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1878 |
|
1879 void mark_modified (void) { xproperties.mark_modified (); } |
|
1880 |
|
1881 void override_defaults (base_graphics_object& obj) |
|
1882 { |
|
1883 // Allow parent (figure) to override first (properties knows how |
|
1884 // to find the parent object). |
|
1885 xproperties.override_defaults (obj); |
|
1886 } |
|
1887 |
|
1888 void set_from_list (property_list& plist) |
|
1889 { |
|
1890 xproperties.set_from_list (*this, plist); |
|
1891 } |
|
1892 |
7189
|
1893 void set (const caseless_str& name, const octave_value& val) |
6874
|
1894 { |
|
1895 xproperties.set (name, val); |
|
1896 } |
|
1897 |
|
1898 octave_value get (void) const |
|
1899 { |
|
1900 return xproperties.get (); |
|
1901 } |
|
1902 |
7189
|
1903 octave_value get (const caseless_str& name) const |
6874
|
1904 { |
|
1905 return xproperties.get (name); |
|
1906 } |
|
1907 |
|
1908 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1909 |
|
1910 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1911 |
|
1912 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1913 |
|
1914 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1915 |
|
1916 base_properties& get_properties (void) { return xproperties; } |
|
1917 |
7222
|
1918 const base_properties& get_properties (void) const { return xproperties; } |
|
1919 |
6890
|
1920 void defaults (void) const { gripe_not_implemented ("patch::defaults"); } |
|
1921 |
6874
|
1922 bool valid_object (void) const { return true; } |
|
1923 }; |
|
1924 |
|
1925 // --------------------------------------------------------------------- |
|
1926 |
|
1927 class surface : public base_graphics_object |
|
1928 { |
|
1929 public: |
|
1930 class properties : public base_properties |
|
1931 { |
|
1932 public: |
|
1933 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1934 |
|
1935 ~properties (void) { } |
|
1936 |
7189
|
1937 void set (const caseless_str& name, const octave_value& val); |
6874
|
1938 |
|
1939 octave_value get (void) const; |
|
1940 |
7189
|
1941 octave_value get (const caseless_str& name) const; |
6874
|
1942 |
|
1943 std::string graphics_object_name (void) const { return go_name; } |
|
1944 |
|
1945 static property_list::pval_map_type factory_defaults (void); |
|
1946 |
|
1947 // See the genprops.awk script for an explanation of the |
|
1948 // properties declarations. |
|
1949 |
|
1950 BEGIN_PROPERTIES |
7214
|
1951 data_property xdata l |
|
1952 data_property ydata l |
|
1953 data_property zdata l |
|
1954 data_property cdata l |
7108
|
1955 color_property facecolor a |
|
1956 octave_value facealpha |
|
1957 color_property edgecolor a |
|
1958 octave_value linestyle |
|
1959 octave_value linewidth |
|
1960 octave_value marker |
|
1961 octave_value markeredgecolor |
|
1962 octave_value markerfacecolor |
|
1963 octave_value markersize |
6874
|
1964 octave_value keylabel |
7189
|
1965 radio_property interpreter a |
6874
|
1966 END_PROPERTIES |
|
1967 |
|
1968 static std::string go_name; |
|
1969 }; |
|
1970 |
|
1971 private: |
|
1972 properties xproperties; |
|
1973 |
|
1974 public: |
|
1975 surface (const graphics_handle& mh, const graphics_handle& p) |
|
1976 : base_graphics_object (), xproperties (mh, p) |
|
1977 { |
|
1978 xproperties.override_defaults (*this); |
|
1979 } |
|
1980 |
|
1981 ~surface (void) { xproperties.delete_children (); } |
|
1982 |
|
1983 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1984 |
|
1985 void mark_modified (void) { xproperties.mark_modified (); } |
|
1986 |
|
1987 void override_defaults (base_graphics_object& obj) |
|
1988 { |
|
1989 // Allow parent (figure) to override first (properties knows how |
|
1990 // to find the parent object). |
|
1991 xproperties.override_defaults (obj); |
|
1992 } |
|
1993 |
|
1994 void set_from_list (property_list& plist) |
|
1995 { |
|
1996 xproperties.set_from_list (*this, plist); |
|
1997 } |
|
1998 |
7189
|
1999 void set (const caseless_str& name, const octave_value& val) |
6874
|
2000 { |
|
2001 xproperties.set (name, val); |
|
2002 } |
|
2003 |
|
2004 octave_value get (void) const |
|
2005 { |
|
2006 return xproperties.get (); |
|
2007 } |
|
2008 |
7189
|
2009 octave_value get (const caseless_str& name) const |
6874
|
2010 { |
|
2011 return xproperties.get (name); |
|
2012 } |
|
2013 |
|
2014 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
2015 |
|
2016 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
2017 |
|
2018 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
2019 |
|
2020 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
2021 |
|
2022 base_properties& get_properties (void) { return xproperties; } |
|
2023 |
7222
|
2024 const base_properties& get_properties (void) const { return xproperties; } |
|
2025 |
6890
|
2026 void defaults (void) const { gripe_not_implemented ("surface::defaults"); } |
|
2027 |
6874
|
2028 bool valid_object (void) const { return true; } |
|
2029 }; |
|
2030 |
|
2031 octave_value |
|
2032 get_property_from_handle (double handle, const std::string &property, |
|
2033 const std::string &func); |
|
2034 bool |
|
2035 set_property_in_handle (double handle, const std::string &property, |
|
2036 const octave_value &arg, const std::string &func); |
|
2037 |
|
2038 // --------------------------------------------------------------------- |
|
2039 |
|
2040 class gh_manager |
|
2041 { |
|
2042 protected: |
|
2043 |
|
2044 gh_manager (void); |
|
2045 |
|
2046 public: |
|
2047 |
|
2048 static bool instance_ok (void) |
|
2049 { |
|
2050 bool retval = true; |
|
2051 |
|
2052 if (! instance) |
|
2053 instance = new gh_manager (); |
|
2054 |
|
2055 if (! instance) |
|
2056 { |
|
2057 ::error ("unable to create gh_manager!"); |
|
2058 |
|
2059 retval = false; |
|
2060 } |
|
2061 |
|
2062 return retval; |
|
2063 } |
|
2064 |
|
2065 static void free (const graphics_handle& h) |
|
2066 { |
|
2067 if (instance_ok ()) |
|
2068 instance->do_free (h); |
|
2069 } |
|
2070 |
|
2071 static graphics_handle lookup (double val) |
|
2072 { |
|
2073 return instance_ok () ? instance->do_lookup (val) : graphics_handle (); |
|
2074 } |
|
2075 |
|
2076 static graphics_object get_object (const graphics_handle& h) |
|
2077 { |
|
2078 return instance_ok () ? instance->do_get_object (h) : graphics_object (); |
|
2079 } |
|
2080 |
|
2081 static graphics_handle |
|
2082 make_graphics_handle (const std::string& go_name, |
|
2083 const graphics_handle& parent) |
|
2084 { |
|
2085 return instance_ok () |
|
2086 ? instance->do_make_graphics_handle (go_name, parent) |
|
2087 : graphics_handle (); |
|
2088 } |
|
2089 |
|
2090 static graphics_handle make_figure_handle (double val) |
|
2091 { |
|
2092 return instance_ok () |
|
2093 ? instance->do_make_figure_handle (val) : graphics_handle (); |
|
2094 } |
|
2095 |
|
2096 static void push_figure (const graphics_handle& h) |
|
2097 { |
|
2098 if (instance_ok ()) |
|
2099 instance->do_push_figure (h); |
|
2100 } |
|
2101 |
|
2102 static void pop_figure (const graphics_handle& h) |
|
2103 { |
|
2104 if (instance_ok ()) |
|
2105 instance->do_pop_figure (h); |
|
2106 } |
|
2107 |
|
2108 static graphics_handle current_figure (void) |
|
2109 { |
|
2110 return instance_ok () |
|
2111 ? instance->do_current_figure () : graphics_handle (); |
|
2112 } |
|
2113 |
|
2114 static Matrix handle_list (void) |
|
2115 { |
|
2116 return instance_ok () ? instance->do_handle_list () : Matrix (); |
|
2117 } |
|
2118 |
|
2119 static Matrix figure_handle_list (void) |
|
2120 { |
|
2121 return instance_ok () ? instance->do_figure_handle_list () : Matrix (); |
|
2122 } |
|
2123 |
|
2124 private: |
|
2125 |
|
2126 static gh_manager *instance; |
|
2127 |
|
2128 typedef std::map<graphics_handle, graphics_object>::iterator iterator; |
|
2129 typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator; |
|
2130 |
|
2131 typedef std::set<graphics_handle>::iterator free_list_iterator; |
|
2132 typedef std::set<graphics_handle>::const_iterator const_free_list_iterator; |
|
2133 |
|
2134 typedef std::list<graphics_handle>::iterator figure_list_iterator; |
|
2135 typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator; |
|
2136 |
|
2137 // A map of handles to graphics objects. |
|
2138 std::map<graphics_handle, graphics_object> handle_map; |
|
2139 |
|
2140 // The available graphics handles. |
|
2141 std::set<graphics_handle> handle_free_list; |
|
2142 |
|
2143 // The next handle available if handle_free_list is empty. |
7286
|
2144 double next_handle; |
6874
|
2145 |
|
2146 // The allocated figure handles. Top of the stack is most recently |
|
2147 // created. |
|
2148 std::list<graphics_handle> figure_list; |
|
2149 |
|
2150 graphics_handle get_handle (const std::string& go_name); |
|
2151 |
|
2152 void do_free (const graphics_handle& h); |
|
2153 |
|
2154 graphics_handle do_lookup (double val) |
|
2155 { |
|
2156 iterator p = handle_map.find (val); |
|
2157 |
|
2158 return (p != handle_map.end ()) ? p->first : graphics_handle (); |
|
2159 } |
|
2160 |
|
2161 graphics_object do_get_object (const graphics_handle& h) |
|
2162 { |
|
2163 iterator p = handle_map.find (h); |
|
2164 |
|
2165 return (p != handle_map.end ()) ? p->second : graphics_object (); |
|
2166 } |
|
2167 |
|
2168 graphics_handle do_make_graphics_handle (const std::string& go_name, |
|
2169 const graphics_handle& p); |
|
2170 |
|
2171 graphics_handle do_make_figure_handle (double val); |
|
2172 |
|
2173 Matrix do_handle_list (void) |
|
2174 { |
|
2175 Matrix retval (1, handle_map.size ()); |
|
2176 octave_idx_type i = 0; |
|
2177 for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++) |
7056
|
2178 { |
|
2179 graphics_handle h = p->first; |
|
2180 retval(i++) = h.value (); |
|
2181 } |
6874
|
2182 return retval; |
|
2183 } |
|
2184 |
|
2185 Matrix do_figure_handle_list (void) |
|
2186 { |
|
2187 Matrix retval (1, figure_list.size ()); |
|
2188 octave_idx_type i = 0; |
|
2189 for (const_figure_list_iterator p = figure_list.begin (); |
|
2190 p != figure_list.end (); |
|
2191 p++) |
7056
|
2192 { |
|
2193 graphics_handle h = *p; |
|
2194 retval(i++) = h.value (); |
|
2195 } |
6874
|
2196 return retval; |
|
2197 } |
|
2198 |
|
2199 void do_push_figure (const graphics_handle& h); |
|
2200 |
|
2201 void do_pop_figure (const graphics_handle& h); |
|
2202 |
|
2203 graphics_handle do_current_figure (void) const |
|
2204 { |
|
2205 return figure_list.empty () ? graphics_handle () : figure_list.front (); |
|
2206 } |
|
2207 }; |
|
2208 |
|
2209 |
|
2210 // This function is NOT equivalent to the scripting language function gcf. |
|
2211 graphics_handle gcf (void); |
|
2212 |
|
2213 // This function is NOT equivalent to the scripting language function gca. |
|
2214 graphics_handle gca (void); |
|
2215 |
|
2216 #endif |
|
2217 |
|
2218 /* |
|
2219 ;;; Local Variables: *** |
|
2220 ;;; mode: C++ *** |
|
2221 ;;; End: *** |
|
2222 */ |