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