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 |
|
1222 END_PROPERTIES |
|
1223 |
|
1224 static std::string go_name; |
|
1225 }; |
|
1226 |
|
1227 private: |
|
1228 properties xproperties; |
|
1229 |
|
1230 public: |
|
1231 figure (const graphics_handle& mh, const graphics_handle& p) |
|
1232 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1233 { |
|
1234 xproperties.override_defaults (*this); |
|
1235 } |
|
1236 |
|
1237 ~figure (void) |
|
1238 { |
|
1239 xproperties.delete_children (); |
|
1240 xproperties.close (); |
|
1241 } |
|
1242 |
|
1243 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1244 |
|
1245 void mark_modified (void) { xproperties.mark_modified (); } |
|
1246 |
|
1247 void override_defaults (base_graphics_object& obj) |
|
1248 { |
|
1249 // Allow parent (root figure) to override first (properties knows how |
|
1250 // to find the parent object). |
|
1251 xproperties.override_defaults (obj); |
|
1252 |
|
1253 // Now override with our defaults. If the default_properties |
|
1254 // list includes the properties for all defaults (line, |
|
1255 // surface, etc.) then we don't have to know the type of OBJ |
|
1256 // here, we just call its set function and let it decide which |
|
1257 // properties from the list to use. |
|
1258 obj.set_from_list (default_properties); |
|
1259 } |
|
1260 |
|
1261 void set_from_list (property_list& plist) |
|
1262 { |
|
1263 xproperties.set_from_list (*this, plist); |
|
1264 } |
|
1265 |
7189
|
1266 void set (const caseless_str& name, const octave_value& value) |
6874
|
1267 { |
|
1268 if (name.compare ("default", 7)) |
|
1269 // strip "default", pass rest to function that will |
|
1270 // parse the remainder and add the element to the |
|
1271 // default_properties map. |
|
1272 default_properties.set (name.substr (7), value); |
|
1273 else |
|
1274 xproperties.set (name, value); |
|
1275 } |
|
1276 |
|
1277 octave_value get (void) const |
|
1278 { |
|
1279 return xproperties.get (); |
|
1280 } |
|
1281 |
7189
|
1282 octave_value get (const caseless_str& name) const |
6874
|
1283 { |
|
1284 octave_value retval; |
|
1285 |
|
1286 if (name.compare ("default", 7)) |
|
1287 retval = get_default (name.substr (7)); |
|
1288 else |
|
1289 retval = xproperties.get (name); |
|
1290 |
|
1291 return retval; |
|
1292 } |
|
1293 |
7189
|
1294 octave_value get_default (const caseless_str& name) const; |
6874
|
1295 |
|
1296 octave_value get_defaults (void) const |
|
1297 { |
|
1298 return default_properties.as_struct ("default"); |
|
1299 } |
|
1300 |
|
1301 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1302 |
|
1303 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1304 |
|
1305 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1306 |
|
1307 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
1308 |
|
1309 base_properties& get_properties (void) { return xproperties; } |
|
1310 |
7222
|
1311 const base_properties& get_properties (void) const { return xproperties; } |
|
1312 |
6890
|
1313 void defaults (void) const { gripe_not_implemented ("figure::defaults"); } |
|
1314 |
6874
|
1315 bool valid_object (void) const { return true; } |
|
1316 |
|
1317 private: |
|
1318 property_list default_properties; |
|
1319 }; |
|
1320 |
|
1321 // --------------------------------------------------------------------- |
|
1322 |
|
1323 class axes : public base_graphics_object |
|
1324 { |
|
1325 public: |
|
1326 class properties : public base_properties |
|
1327 { |
|
1328 public: |
|
1329 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1330 |
|
1331 ~properties (void) { } |
|
1332 |
7189
|
1333 void set (const caseless_str& name, const octave_value& val); |
6874
|
1334 |
|
1335 void set_defaults (base_graphics_object& obj, const std::string& mode); |
|
1336 |
|
1337 octave_value get (void) const; |
|
1338 |
7189
|
1339 octave_value get (const caseless_str& name) const; |
6874
|
1340 |
|
1341 void remove_child (const graphics_handle& h); |
|
1342 |
|
1343 void delete_children (void); |
|
1344 |
|
1345 std::string graphics_object_name (void) const { return go_name; } |
|
1346 |
|
1347 static property_list::pval_map_type factory_defaults (void); |
|
1348 |
|
1349 // See the genprops.awk script for an explanation of the |
|
1350 // properties declarations. |
|
1351 |
|
1352 BEGIN_PROPERTIES |
|
1353 octave_value position |
|
1354 mutable graphics_handle title GSO |
|
1355 octave_value box |
|
1356 octave_value key |
|
1357 octave_value keybox |
|
1358 octave_value keypos |
6962
|
1359 octave_value colororder |
6874
|
1360 octave_value dataaspectratio m |
|
1361 octave_value dataaspectratiomode |
|
1362 octave_value xlim m |
|
1363 octave_value ylim m |
|
1364 octave_value zlim m |
|
1365 octave_value clim m |
7222
|
1366 radio_property xlimmode al |
|
1367 radio_property ylimmode al |
|
1368 radio_property zlimmode al |
|
1369 radio_property climmode al |
6874
|
1370 mutable graphics_handle xlabel GSO |
|
1371 mutable graphics_handle ylabel GSO |
|
1372 mutable graphics_handle zlabel GSO |
|
1373 octave_value xgrid |
|
1374 octave_value ygrid |
|
1375 octave_value zgrid |
|
1376 octave_value xminorgrid |
|
1377 octave_value yminorgrid |
|
1378 octave_value zminorgrid |
|
1379 octave_value xtick m |
|
1380 octave_value ytick m |
|
1381 octave_value ztick m |
|
1382 octave_value xtickmode |
|
1383 octave_value ytickmode |
|
1384 octave_value ztickmode |
|
1385 octave_value xticklabel m |
|
1386 octave_value yticklabel m |
|
1387 octave_value zticklabel m |
|
1388 octave_value xticklabelmode |
|
1389 octave_value yticklabelmode |
|
1390 octave_value zticklabelmode |
7240
|
1391 color_property color a |
7194
|
1392 color_property xcolor |
|
1393 color_property ycolor |
|
1394 color_property zcolor |
7222
|
1395 radio_property xscale al |
|
1396 radio_property yscale al |
|
1397 radio_property zscale al |
6874
|
1398 octave_value xdir |
|
1399 octave_value ydir |
|
1400 octave_value zdir |
|
1401 octave_value xaxislocation |
|
1402 octave_value yaxislocation |
|
1403 octave_value view |
|
1404 octave_value visible |
|
1405 octave_value nextplot |
|
1406 octave_value outerposition |
7240
|
1407 radio_property activepositionproperty a |
7189
|
1408 radio_property __colorbar__ a |
|
1409 END_PROPERTIES |
6874
|
1410 |
|
1411 static std::string go_name; |
|
1412 }; |
|
1413 |
|
1414 private: |
|
1415 properties xproperties; |
|
1416 |
|
1417 public: |
|
1418 axes (const graphics_handle& mh, const graphics_handle& p) |
|
1419 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1420 { |
|
1421 xproperties.override_defaults (*this); |
|
1422 } |
|
1423 |
|
1424 ~axes (void) { xproperties.delete_children (); } |
|
1425 |
|
1426 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1427 |
|
1428 void mark_modified (void) { xproperties.mark_modified (); } |
|
1429 |
|
1430 void override_defaults (base_graphics_object& obj) |
|
1431 { |
|
1432 // Allow parent (figure) to override first (properties knows how |
|
1433 // to find the parent object). |
|
1434 xproperties.override_defaults (obj); |
|
1435 |
|
1436 // Now override with our defaults. If the default_properties |
|
1437 // list includes the properties for all defaults (line, |
|
1438 // surface, etc.) then we don't have to know the type of OBJ |
|
1439 // here, we just call its set function and let it decide which |
|
1440 // properties from the list to use. |
|
1441 obj.set_from_list (default_properties); |
|
1442 } |
|
1443 |
|
1444 void set_from_list (property_list& plist) |
|
1445 { |
|
1446 xproperties.set_from_list (*this, plist); |
|
1447 } |
|
1448 |
7189
|
1449 void set (const caseless_str& name, const octave_value& value) |
6874
|
1450 { |
|
1451 if (name.compare ("default", 7)) |
|
1452 // strip "default", pass rest to function that will |
|
1453 // parse the remainder and add the element to the |
|
1454 // default_properties map. |
|
1455 default_properties.set (name.substr (7), value); |
|
1456 else |
|
1457 xproperties.set (name, value); |
|
1458 } |
|
1459 |
|
1460 void set_defaults (const std::string& mode) |
|
1461 { |
|
1462 xproperties.set_defaults (*this, mode); |
|
1463 } |
|
1464 |
|
1465 octave_value get (void) const |
|
1466 { |
|
1467 return xproperties.get (); |
|
1468 } |
|
1469 |
7189
|
1470 octave_value get (const caseless_str& name) const |
6874
|
1471 { |
|
1472 octave_value retval; |
|
1473 |
|
1474 // FIXME -- finish this. |
|
1475 if (name.compare ("default", 7)) |
|
1476 retval = get_default (name.substr (7)); |
|
1477 else |
|
1478 retval = xproperties.get (name); |
|
1479 |
|
1480 return retval; |
|
1481 } |
|
1482 |
7189
|
1483 octave_value get_default (const caseless_str& name) const; |
6874
|
1484 |
|
1485 octave_value get_defaults (void) const |
|
1486 { |
|
1487 return default_properties.as_struct ("default"); |
|
1488 } |
|
1489 |
|
1490 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1491 |
|
1492 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1493 |
|
1494 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1495 |
|
1496 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
1497 |
|
1498 base_properties& get_properties (void) { return xproperties; } |
|
1499 |
7222
|
1500 const base_properties& get_properties (void) const { return xproperties; } |
|
1501 |
6890
|
1502 void defaults (void) const { gripe_not_implemented ("axes::defaults"); } |
|
1503 |
7214
|
1504 void update_axis_limits (const std::string& axis_type); |
|
1505 |
6874
|
1506 bool valid_object (void) const { return true; } |
|
1507 |
|
1508 private: |
|
1509 property_list default_properties; |
|
1510 }; |
|
1511 |
|
1512 // --------------------------------------------------------------------- |
|
1513 |
|
1514 class line : public base_graphics_object |
|
1515 { |
|
1516 public: |
|
1517 class properties : public base_properties |
|
1518 { |
|
1519 public: |
|
1520 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1521 |
|
1522 ~properties (void) { } |
|
1523 |
7189
|
1524 void set (const caseless_str& name, const octave_value& val); |
6874
|
1525 |
|
1526 octave_value get (void) const; |
|
1527 |
7189
|
1528 octave_value get (const caseless_str& name) const; |
6874
|
1529 |
|
1530 std::string graphics_object_name (void) const { return go_name; } |
|
1531 |
|
1532 static property_list::pval_map_type factory_defaults (void); |
|
1533 |
|
1534 // See the genprops.awk script for an explanation of the |
|
1535 // properties declarations. |
|
1536 |
|
1537 BEGIN_PROPERTIES |
7214
|
1538 data_property xdata l |
|
1539 data_property ydata l |
|
1540 data_property zdata l |
|
1541 data_property ldata l |
|
1542 data_property udata l |
|
1543 data_property xldata l |
|
1544 data_property xudata l |
6874
|
1545 color_property color |
|
1546 octave_value linestyle |
|
1547 octave_value linewidth |
|
1548 octave_value marker |
|
1549 octave_value markeredgecolor |
|
1550 octave_value markerfacecolor |
|
1551 octave_value markersize |
|
1552 octave_value keylabel |
7189
|
1553 radio_property interpreter a |
6874
|
1554 END_PROPERTIES |
|
1555 |
|
1556 static std::string go_name; |
|
1557 }; |
|
1558 |
|
1559 private: |
|
1560 properties xproperties; |
|
1561 |
|
1562 public: |
|
1563 line (const graphics_handle& mh, const graphics_handle& p) |
|
1564 : base_graphics_object (), xproperties (mh, p) |
|
1565 { |
|
1566 xproperties.override_defaults (*this); |
|
1567 } |
|
1568 |
|
1569 ~line (void) { xproperties.delete_children (); } |
|
1570 |
|
1571 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1572 |
|
1573 void mark_modified (void) { xproperties.mark_modified (); } |
|
1574 |
|
1575 void override_defaults (base_graphics_object& obj) |
|
1576 { |
|
1577 // Allow parent (figure) to override first (properties knows how |
|
1578 // to find the parent object). |
|
1579 xproperties.override_defaults (obj); |
|
1580 } |
|
1581 |
|
1582 void set_from_list (property_list& plist) |
|
1583 { |
|
1584 xproperties.set_from_list (*this, plist); |
|
1585 } |
|
1586 |
7189
|
1587 void set (const caseless_str& name, const octave_value& val) |
6874
|
1588 { |
|
1589 xproperties.set (name, val); |
|
1590 } |
|
1591 |
|
1592 octave_value get (void) const |
|
1593 { |
|
1594 return xproperties.get (); |
|
1595 } |
|
1596 |
7189
|
1597 octave_value get (const caseless_str& name) const |
6874
|
1598 { |
|
1599 return xproperties.get (name); |
|
1600 } |
|
1601 |
|
1602 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1603 |
|
1604 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1605 |
|
1606 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1607 |
|
1608 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1609 |
|
1610 base_properties& get_properties (void) { return xproperties; } |
|
1611 |
7222
|
1612 const base_properties& get_properties (void) const { return xproperties; } |
|
1613 |
6890
|
1614 void defaults (void) const { gripe_not_implemented ("line::defaults"); } |
|
1615 |
6874
|
1616 bool valid_object (void) const { return true; } |
|
1617 }; |
|
1618 |
|
1619 // --------------------------------------------------------------------- |
|
1620 |
|
1621 class text : public base_graphics_object |
|
1622 { |
|
1623 public: |
|
1624 class properties : public base_properties |
|
1625 { |
|
1626 public: |
|
1627 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1628 |
|
1629 ~properties (void) { } |
|
1630 |
7189
|
1631 void set (const caseless_str& name, const octave_value& val); |
6874
|
1632 |
|
1633 octave_value get (void) const; |
|
1634 |
7189
|
1635 octave_value get (const caseless_str& name) const; |
6874
|
1636 |
|
1637 std::string graphics_object_name (void) const { return go_name; } |
|
1638 |
|
1639 static property_list::pval_map_type factory_defaults (void); |
|
1640 |
|
1641 // See the genprops.awk script for an explanation of the |
|
1642 // properties declarations. |
|
1643 |
|
1644 BEGIN_PROPERTIES |
|
1645 octave_value string |
|
1646 octave_value units |
|
1647 octave_value position |
|
1648 octave_value rotation |
|
1649 octave_value horizontalalignment |
6890
|
1650 color_property color |
7162
|
1651 octave_value fontname |
|
1652 octave_value fontsize |
7189
|
1653 radio_property fontangle a |
|
1654 radio_property fontweight a |
|
1655 radio_property interpreter a |
6874
|
1656 END_PROPERTIES |
|
1657 |
|
1658 static std::string go_name; |
|
1659 }; |
|
1660 |
|
1661 private: |
|
1662 properties xproperties; |
|
1663 |
|
1664 public: |
|
1665 text (const graphics_handle& mh, const graphics_handle& p) |
|
1666 : base_graphics_object (), xproperties (mh, p) |
|
1667 { |
|
1668 xproperties.override_defaults (*this); |
|
1669 } |
|
1670 |
|
1671 ~text (void) { xproperties.delete_children (); } |
|
1672 |
|
1673 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1674 |
|
1675 void mark_modified (void) { xproperties.mark_modified (); } |
|
1676 |
|
1677 void override_defaults (base_graphics_object& obj) |
|
1678 { |
|
1679 // Allow parent (figure) to override first (properties knows how |
|
1680 // to find the parent object). |
|
1681 xproperties.override_defaults (obj); |
|
1682 } |
|
1683 |
|
1684 void set_from_list (property_list& plist) |
|
1685 { |
|
1686 xproperties.set_from_list (*this, plist); |
|
1687 } |
|
1688 |
7189
|
1689 void set (const caseless_str& name, const octave_value& val) |
6874
|
1690 { |
|
1691 xproperties.set (name, val); |
|
1692 } |
|
1693 |
|
1694 octave_value get (void) const |
|
1695 { |
|
1696 return xproperties.get (); |
|
1697 } |
|
1698 |
7189
|
1699 octave_value get (const caseless_str& name) const |
6874
|
1700 { |
|
1701 return xproperties.get (name); |
|
1702 } |
|
1703 |
|
1704 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1705 |
|
1706 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1707 |
|
1708 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1709 |
|
1710 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1711 |
|
1712 base_properties& get_properties (void) { return xproperties; } |
|
1713 |
7222
|
1714 const base_properties& get_properties (void) const { return xproperties; } |
|
1715 |
6890
|
1716 void defaults (void) const { gripe_not_implemented ("text::defaults"); } |
|
1717 |
6874
|
1718 bool valid_object (void) const { return true; } |
|
1719 }; |
|
1720 |
|
1721 // --------------------------------------------------------------------- |
|
1722 |
|
1723 class image : public base_graphics_object |
|
1724 { |
|
1725 public: |
|
1726 class properties : public base_properties |
|
1727 { |
|
1728 public: |
|
1729 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1730 |
|
1731 ~properties (void) { } |
|
1732 |
7189
|
1733 void set (const caseless_str& name, const octave_value& val); |
6874
|
1734 |
|
1735 octave_value get (void) const; |
|
1736 |
7189
|
1737 octave_value get (const caseless_str& name) const; |
6874
|
1738 |
|
1739 std::string graphics_object_name (void) const { return go_name; } |
|
1740 |
|
1741 static property_list::pval_map_type factory_defaults (void); |
|
1742 |
|
1743 // See the genprops.awk script for an explanation of the |
|
1744 // properties declarations. |
|
1745 |
|
1746 BEGIN_PROPERTIES |
7214
|
1747 data_property xdata l |
|
1748 data_property ydata l |
|
1749 data_property cdata l |
6874
|
1750 END_PROPERTIES |
|
1751 |
|
1752 static std::string go_name; |
|
1753 }; |
|
1754 |
|
1755 private: |
|
1756 properties xproperties; |
|
1757 |
|
1758 public: |
|
1759 image (const graphics_handle& mh, const graphics_handle& p) |
|
1760 : base_graphics_object (), xproperties (mh, p) |
|
1761 { |
|
1762 xproperties.override_defaults (*this); |
|
1763 } |
|
1764 |
|
1765 ~image (void) { xproperties.delete_children (); } |
|
1766 |
|
1767 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1768 |
|
1769 void mark_modified (void) { xproperties.mark_modified (); } |
|
1770 |
|
1771 void override_defaults (base_graphics_object& obj) |
|
1772 { |
|
1773 // Allow parent (figure) to override first (properties knows how |
|
1774 // to find the parent object). |
|
1775 xproperties.override_defaults (obj); |
|
1776 } |
|
1777 |
|
1778 void set_from_list (property_list& plist) |
|
1779 { |
|
1780 xproperties.set_from_list (*this, plist); |
|
1781 } |
|
1782 |
7189
|
1783 void set (const caseless_str& name, const octave_value& val) |
6874
|
1784 { |
|
1785 xproperties.set (name, val); |
|
1786 } |
|
1787 |
|
1788 octave_value get (void) const |
|
1789 { |
|
1790 return xproperties.get (); |
|
1791 } |
|
1792 |
7189
|
1793 octave_value get (const caseless_str& name) const |
6874
|
1794 { |
|
1795 return xproperties.get (name); |
|
1796 } |
|
1797 |
|
1798 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1799 |
|
1800 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1801 |
|
1802 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1803 |
|
1804 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1805 |
|
1806 base_properties& get_properties (void) { return xproperties; } |
|
1807 |
7222
|
1808 const base_properties& get_properties (void) const { return xproperties; } |
|
1809 |
6890
|
1810 void defaults (void) const { gripe_not_implemented ("image::defaults"); } |
|
1811 |
6874
|
1812 bool valid_object (void) const { return true; } |
|
1813 }; |
|
1814 |
|
1815 // --------------------------------------------------------------------- |
|
1816 |
|
1817 class patch : public base_graphics_object |
|
1818 { |
|
1819 public: |
|
1820 class properties : public base_properties |
|
1821 { |
|
1822 public: |
|
1823 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1824 |
|
1825 ~properties (void) { } |
|
1826 |
7189
|
1827 void set (const caseless_str& name, const octave_value& val); |
6874
|
1828 |
|
1829 octave_value get (void) const; |
|
1830 |
7189
|
1831 octave_value get (const caseless_str& name) const; |
6874
|
1832 |
|
1833 std::string graphics_object_name (void) const { return go_name; } |
|
1834 |
|
1835 static property_list::pval_map_type factory_defaults (void); |
|
1836 |
|
1837 // See the genprops.awk script for an explanation of the |
|
1838 // properties declarations. |
|
1839 |
|
1840 BEGIN_PROPERTIES |
7214
|
1841 data_property xdata l |
|
1842 data_property ydata l |
|
1843 data_property zdata l |
|
1844 data_property cdata l |
7020
|
1845 octave_value faces |
|
1846 octave_value vertices |
6938
|
1847 color_property facecolor a |
6874
|
1848 octave_value facealpha |
6938
|
1849 color_property edgecolor a |
6874
|
1850 octave_value linestyle |
|
1851 octave_value linewidth |
|
1852 octave_value marker |
|
1853 octave_value markeredgecolor |
|
1854 octave_value markerfacecolor |
|
1855 octave_value markersize |
7148
|
1856 octave_value keylabel |
7189
|
1857 radio_property interpreter a |
6874
|
1858 END_PROPERTIES |
|
1859 |
|
1860 static std::string go_name; |
|
1861 }; |
|
1862 |
|
1863 private: |
|
1864 properties xproperties; |
|
1865 |
|
1866 public: |
|
1867 patch (const graphics_handle& mh, const graphics_handle& p) |
|
1868 : base_graphics_object (), xproperties (mh, p) |
|
1869 { |
|
1870 xproperties.override_defaults (*this); |
|
1871 } |
|
1872 |
|
1873 ~patch (void) { xproperties.delete_children (); } |
|
1874 |
|
1875 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1876 |
|
1877 void mark_modified (void) { xproperties.mark_modified (); } |
|
1878 |
|
1879 void override_defaults (base_graphics_object& obj) |
|
1880 { |
|
1881 // Allow parent (figure) to override first (properties knows how |
|
1882 // to find the parent object). |
|
1883 xproperties.override_defaults (obj); |
|
1884 } |
|
1885 |
|
1886 void set_from_list (property_list& plist) |
|
1887 { |
|
1888 xproperties.set_from_list (*this, plist); |
|
1889 } |
|
1890 |
7189
|
1891 void set (const caseless_str& name, const octave_value& val) |
6874
|
1892 { |
|
1893 xproperties.set (name, val); |
|
1894 } |
|
1895 |
|
1896 octave_value get (void) const |
|
1897 { |
|
1898 return xproperties.get (); |
|
1899 } |
|
1900 |
7189
|
1901 octave_value get (const caseless_str& name) const |
6874
|
1902 { |
|
1903 return xproperties.get (name); |
|
1904 } |
|
1905 |
|
1906 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1907 |
|
1908 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1909 |
|
1910 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1911 |
|
1912 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1913 |
|
1914 base_properties& get_properties (void) { return xproperties; } |
|
1915 |
7222
|
1916 const base_properties& get_properties (void) const { return xproperties; } |
|
1917 |
6890
|
1918 void defaults (void) const { gripe_not_implemented ("patch::defaults"); } |
|
1919 |
6874
|
1920 bool valid_object (void) const { return true; } |
|
1921 }; |
|
1922 |
|
1923 // --------------------------------------------------------------------- |
|
1924 |
|
1925 class surface : public base_graphics_object |
|
1926 { |
|
1927 public: |
|
1928 class properties : public base_properties |
|
1929 { |
|
1930 public: |
|
1931 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1932 |
|
1933 ~properties (void) { } |
|
1934 |
7189
|
1935 void set (const caseless_str& name, const octave_value& val); |
6874
|
1936 |
|
1937 octave_value get (void) const; |
|
1938 |
7189
|
1939 octave_value get (const caseless_str& name) const; |
6874
|
1940 |
|
1941 std::string graphics_object_name (void) const { return go_name; } |
|
1942 |
|
1943 static property_list::pval_map_type factory_defaults (void); |
|
1944 |
|
1945 // See the genprops.awk script for an explanation of the |
|
1946 // properties declarations. |
|
1947 |
|
1948 BEGIN_PROPERTIES |
7214
|
1949 data_property xdata l |
|
1950 data_property ydata l |
|
1951 data_property zdata l |
|
1952 data_property cdata l |
7108
|
1953 color_property facecolor a |
|
1954 octave_value facealpha |
|
1955 color_property edgecolor a |
|
1956 octave_value linestyle |
|
1957 octave_value linewidth |
|
1958 octave_value marker |
|
1959 octave_value markeredgecolor |
|
1960 octave_value markerfacecolor |
|
1961 octave_value markersize |
6874
|
1962 octave_value keylabel |
7189
|
1963 radio_property interpreter a |
6874
|
1964 END_PROPERTIES |
|
1965 |
|
1966 static std::string go_name; |
|
1967 }; |
|
1968 |
|
1969 private: |
|
1970 properties xproperties; |
|
1971 |
|
1972 public: |
|
1973 surface (const graphics_handle& mh, const graphics_handle& p) |
|
1974 : base_graphics_object (), xproperties (mh, p) |
|
1975 { |
|
1976 xproperties.override_defaults (*this); |
|
1977 } |
|
1978 |
|
1979 ~surface (void) { xproperties.delete_children (); } |
|
1980 |
|
1981 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1982 |
|
1983 void mark_modified (void) { xproperties.mark_modified (); } |
|
1984 |
|
1985 void override_defaults (base_graphics_object& obj) |
|
1986 { |
|
1987 // Allow parent (figure) to override first (properties knows how |
|
1988 // to find the parent object). |
|
1989 xproperties.override_defaults (obj); |
|
1990 } |
|
1991 |
|
1992 void set_from_list (property_list& plist) |
|
1993 { |
|
1994 xproperties.set_from_list (*this, plist); |
|
1995 } |
|
1996 |
7189
|
1997 void set (const caseless_str& name, const octave_value& val) |
6874
|
1998 { |
|
1999 xproperties.set (name, val); |
|
2000 } |
|
2001 |
|
2002 octave_value get (void) const |
|
2003 { |
|
2004 return xproperties.get (); |
|
2005 } |
|
2006 |
7189
|
2007 octave_value get (const caseless_str& name) const |
6874
|
2008 { |
|
2009 return xproperties.get (name); |
|
2010 } |
|
2011 |
|
2012 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
2013 |
|
2014 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
2015 |
|
2016 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
2017 |
|
2018 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
2019 |
|
2020 base_properties& get_properties (void) { return xproperties; } |
|
2021 |
7222
|
2022 const base_properties& get_properties (void) const { return xproperties; } |
|
2023 |
6890
|
2024 void defaults (void) const { gripe_not_implemented ("surface::defaults"); } |
|
2025 |
6874
|
2026 bool valid_object (void) const { return true; } |
|
2027 }; |
|
2028 |
|
2029 octave_value |
|
2030 get_property_from_handle (double handle, const std::string &property, |
|
2031 const std::string &func); |
|
2032 bool |
|
2033 set_property_in_handle (double handle, const std::string &property, |
|
2034 const octave_value &arg, const std::string &func); |
|
2035 |
|
2036 // --------------------------------------------------------------------- |
|
2037 |
|
2038 class gh_manager |
|
2039 { |
|
2040 protected: |
|
2041 |
|
2042 gh_manager (void); |
|
2043 |
|
2044 public: |
|
2045 |
|
2046 static bool instance_ok (void) |
|
2047 { |
|
2048 bool retval = true; |
|
2049 |
|
2050 if (! instance) |
|
2051 instance = new gh_manager (); |
|
2052 |
|
2053 if (! instance) |
|
2054 { |
|
2055 ::error ("unable to create gh_manager!"); |
|
2056 |
|
2057 retval = false; |
|
2058 } |
|
2059 |
|
2060 return retval; |
|
2061 } |
|
2062 |
|
2063 static void free (const graphics_handle& h) |
|
2064 { |
|
2065 if (instance_ok ()) |
|
2066 instance->do_free (h); |
|
2067 } |
|
2068 |
|
2069 static graphics_handle lookup (double val) |
|
2070 { |
|
2071 return instance_ok () ? instance->do_lookup (val) : graphics_handle (); |
|
2072 } |
|
2073 |
|
2074 static graphics_object get_object (const graphics_handle& h) |
|
2075 { |
|
2076 return instance_ok () ? instance->do_get_object (h) : graphics_object (); |
|
2077 } |
|
2078 |
|
2079 static graphics_handle |
|
2080 make_graphics_handle (const std::string& go_name, |
|
2081 const graphics_handle& parent) |
|
2082 { |
|
2083 return instance_ok () |
|
2084 ? instance->do_make_graphics_handle (go_name, parent) |
|
2085 : graphics_handle (); |
|
2086 } |
|
2087 |
|
2088 static graphics_handle make_figure_handle (double val) |
|
2089 { |
|
2090 return instance_ok () |
|
2091 ? instance->do_make_figure_handle (val) : graphics_handle (); |
|
2092 } |
|
2093 |
|
2094 static void push_figure (const graphics_handle& h) |
|
2095 { |
|
2096 if (instance_ok ()) |
|
2097 instance->do_push_figure (h); |
|
2098 } |
|
2099 |
|
2100 static void pop_figure (const graphics_handle& h) |
|
2101 { |
|
2102 if (instance_ok ()) |
|
2103 instance->do_pop_figure (h); |
|
2104 } |
|
2105 |
|
2106 static graphics_handle current_figure (void) |
|
2107 { |
|
2108 return instance_ok () |
|
2109 ? instance->do_current_figure () : graphics_handle (); |
|
2110 } |
|
2111 |
|
2112 static Matrix handle_list (void) |
|
2113 { |
|
2114 return instance_ok () ? instance->do_handle_list () : Matrix (); |
|
2115 } |
|
2116 |
|
2117 static Matrix figure_handle_list (void) |
|
2118 { |
|
2119 return instance_ok () ? instance->do_figure_handle_list () : Matrix (); |
|
2120 } |
|
2121 |
|
2122 private: |
|
2123 |
|
2124 static gh_manager *instance; |
|
2125 |
|
2126 typedef std::map<graphics_handle, graphics_object>::iterator iterator; |
|
2127 typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator; |
|
2128 |
|
2129 typedef std::set<graphics_handle>::iterator free_list_iterator; |
|
2130 typedef std::set<graphics_handle>::const_iterator const_free_list_iterator; |
|
2131 |
|
2132 typedef std::list<graphics_handle>::iterator figure_list_iterator; |
|
2133 typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator; |
|
2134 |
|
2135 // A map of handles to graphics objects. |
|
2136 std::map<graphics_handle, graphics_object> handle_map; |
|
2137 |
|
2138 // The available graphics handles. |
|
2139 std::set<graphics_handle> handle_free_list; |
|
2140 |
|
2141 // The next handle available if handle_free_list is empty. |
|
2142 graphics_handle next_handle; |
|
2143 |
|
2144 // The allocated figure handles. Top of the stack is most recently |
|
2145 // created. |
|
2146 std::list<graphics_handle> figure_list; |
|
2147 |
|
2148 graphics_handle get_handle (const std::string& go_name); |
|
2149 |
|
2150 void do_free (const graphics_handle& h); |
|
2151 |
|
2152 graphics_handle do_lookup (double val) |
|
2153 { |
|
2154 iterator p = handle_map.find (val); |
|
2155 |
|
2156 return (p != handle_map.end ()) ? p->first : graphics_handle (); |
|
2157 } |
|
2158 |
|
2159 graphics_object do_get_object (const graphics_handle& h) |
|
2160 { |
|
2161 iterator p = handle_map.find (h); |
|
2162 |
|
2163 return (p != handle_map.end ()) ? p->second : graphics_object (); |
|
2164 } |
|
2165 |
|
2166 graphics_handle do_make_graphics_handle (const std::string& go_name, |
|
2167 const graphics_handle& p); |
|
2168 |
|
2169 graphics_handle do_make_figure_handle (double val); |
|
2170 |
|
2171 Matrix do_handle_list (void) |
|
2172 { |
|
2173 Matrix retval (1, handle_map.size ()); |
|
2174 octave_idx_type i = 0; |
|
2175 for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++) |
7056
|
2176 { |
|
2177 graphics_handle h = p->first; |
|
2178 retval(i++) = h.value (); |
|
2179 } |
6874
|
2180 return retval; |
|
2181 } |
|
2182 |
|
2183 Matrix do_figure_handle_list (void) |
|
2184 { |
|
2185 Matrix retval (1, figure_list.size ()); |
|
2186 octave_idx_type i = 0; |
|
2187 for (const_figure_list_iterator p = figure_list.begin (); |
|
2188 p != figure_list.end (); |
|
2189 p++) |
7056
|
2190 { |
|
2191 graphics_handle h = *p; |
|
2192 retval(i++) = h.value (); |
|
2193 } |
6874
|
2194 return retval; |
|
2195 } |
|
2196 |
|
2197 void do_push_figure (const graphics_handle& h); |
|
2198 |
|
2199 void do_pop_figure (const graphics_handle& h); |
|
2200 |
|
2201 graphics_handle do_current_figure (void) const |
|
2202 { |
|
2203 return figure_list.empty () ? graphics_handle () : figure_list.front (); |
|
2204 } |
|
2205 }; |
|
2206 |
|
2207 |
|
2208 // This function is NOT equivalent to the scripting language function gcf. |
|
2209 graphics_handle gcf (void); |
|
2210 |
|
2211 // This function is NOT equivalent to the scripting language function gca. |
|
2212 graphics_handle gca (void); |
|
2213 |
|
2214 #endif |
|
2215 |
|
2216 /* |
|
2217 ;;; Local Variables: *** |
|
2218 ;;; mode: C++ *** |
|
2219 ;;; End: *** |
|
2220 */ |