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