6406
|
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 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <cctype> |
|
29 |
|
30 #include <algorithm> |
|
31 #include <list> |
|
32 #include <map> |
|
33 #include <set> |
|
34 #include <string> |
|
35 |
|
36 #include <defun.h> |
|
37 #include <ov.h> |
|
38 #include <oct-obj.h> |
|
39 #include <oct-map.h> |
|
40 #include <ov-fcn-handle.h> |
|
41 #include <parse.h> |
|
42 |
|
43 static void |
|
44 gripe_set_invalid (const std::string& pname) |
|
45 { |
|
46 error ("set: invalid value for %s property", pname.c_str ()); |
|
47 } |
|
48 |
|
49 static octave_value |
|
50 nan_to_empty (double val) |
|
51 { |
|
52 return xisnan (val) ? octave_value (Matrix ()) : octave_value (val); |
|
53 } |
|
54 |
|
55 static octave_value |
|
56 empty_to_nan (const octave_value& val) |
|
57 { |
|
58 return val.is_empty () ? octave_value (octave_NaN) : val; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------- |
|
62 |
|
63 class color_property |
|
64 { |
|
65 public: |
|
66 color_property (double r = 0, double g = 0, double b = 1) |
|
67 : red (r), green (g), blue (b) |
|
68 { |
|
69 validate (); |
|
70 } |
|
71 |
|
72 color_property (const octave_value& val) |
|
73 : red (), green (), blue () |
|
74 { |
|
75 // FIXME -- need some error checking here. |
|
76 |
|
77 Matrix m = val.matrix_value (); |
|
78 |
|
79 if (! error_state && m.numel () == 3) |
|
80 { |
|
81 red = m(0); |
|
82 green = m(1); |
|
83 blue = m(2); |
|
84 |
|
85 validate (); |
|
86 } |
|
87 else |
|
88 error ("invalid RGB color specification"); |
|
89 } |
|
90 |
|
91 void validate (void) const |
|
92 { |
|
93 if (red < 0 || red > 1 || green < 0 || green > 1 || blue < 0 || blue > 1) |
|
94 error ("invalid RGB color specification"); |
|
95 } |
|
96 |
|
97 operator octave_value (void) const |
|
98 { |
|
99 Matrix retval (1, 3); |
|
100 |
|
101 retval(0) = red; |
|
102 retval(1) = green; |
|
103 retval(2) = blue; |
|
104 |
|
105 return retval; |
|
106 } |
|
107 |
|
108 private: |
|
109 double red; |
|
110 double green; |
|
111 double blue; |
|
112 }; |
|
113 |
|
114 class colormap_property |
|
115 { |
|
116 public: |
|
117 colormap_property (const Matrix& m = Matrix ()) |
|
118 : cmap (m) |
|
119 { |
|
120 if (cmap.is_empty ()) |
|
121 { |
|
122 cmap = Matrix (64, 3); |
|
123 |
|
124 for (octave_idx_type i = 0; i < 64; i++) |
|
125 cmap(i,0) = cmap(i,1) = cmap(i,2) = i / 64.0; |
|
126 } |
|
127 |
|
128 validate (); |
|
129 } |
|
130 |
|
131 colormap_property (const octave_value& val) |
|
132 { |
|
133 cmap = val.matrix_value (); |
|
134 |
|
135 validate (); |
|
136 } |
|
137 |
|
138 void validate (void) const |
|
139 { |
|
140 if (error_state || cmap.columns () != 3) |
|
141 error ("invalid colormap specification"); |
|
142 } |
|
143 |
|
144 operator octave_value (void) const { return cmap; } |
|
145 |
|
146 private: |
|
147 Matrix cmap; |
|
148 }; |
|
149 |
|
150 // --------------------------------------------------------------------- |
|
151 |
|
152 class property_name : public std::string |
|
153 { |
|
154 public: |
|
155 typedef std::string::iterator iterator; |
|
156 typedef std::string::const_iterator const_iterator; |
|
157 |
|
158 property_name (void) : std::string () { } |
|
159 property_name (const std::string& s) : std::string (s) { } |
|
160 property_name (const char *s) : std::string (s) { } |
|
161 |
|
162 property_name (const property_name& name) : std::string (name) { } |
|
163 |
|
164 property_name& operator = (const property_name& pname) |
|
165 { |
|
166 std::string::operator = (pname); |
|
167 return *this; |
|
168 } |
|
169 |
|
170 operator std::string (void) const { return *this; } |
|
171 |
|
172 // Case-insensitive comparison. |
|
173 bool compare (const std::string& s, size_t limit = NPOS) const |
|
174 { |
|
175 const_iterator p1 = begin (); |
|
176 const_iterator p2 = s.begin (); |
|
177 |
|
178 size_t k = 0; |
|
179 |
|
180 while (p1 != end () && p2 != s.end () && k++ < limit) |
|
181 { |
|
182 if (std::tolower (*p1) != std::tolower (*p2)) |
|
183 return false; |
|
184 |
|
185 *p1++; |
|
186 *p2++; |
|
187 } |
|
188 |
|
189 return (limit == NPOS) ? size () == s.size () : k == limit; |
|
190 } |
|
191 }; |
|
192 |
|
193 // --------------------------------------------------------------------- |
|
194 |
|
195 class property_list |
|
196 { |
|
197 public: |
|
198 typedef std::map<std::string, octave_value> pval_map_type; |
|
199 typedef std::map<std::string, pval_map_type> plist_map_type; |
|
200 |
|
201 typedef pval_map_type::iterator pval_map_iterator; |
|
202 typedef pval_map_type::const_iterator pval_map_const_iterator; |
|
203 |
|
204 typedef plist_map_type::iterator plist_map_iterator; |
|
205 typedef plist_map_type::const_iterator plist_map_const_iterator; |
|
206 |
|
207 property_list (const plist_map_type& m = plist_map_type ()) |
|
208 : plist_map (m) { } |
|
209 |
|
210 ~property_list (void) { } |
|
211 |
|
212 void set (const property_name& name, const octave_value& val) |
|
213 { |
|
214 size_t offset = 0; |
|
215 |
|
216 size_t len = name.length (); |
|
217 |
|
218 if (len > 4) |
|
219 { |
|
220 property_name pfx = name.substr (0, 4); |
|
221 |
|
222 if (pfx.compare ("axes") || pfx.compare ("line") |
|
223 || pfx.compare ("text")) |
|
224 offset = 4; |
|
225 else if (len > 5) |
|
226 { |
|
227 pfx = name.substr (0, 5); |
|
228 |
|
229 if (pfx.compare ("image")) |
|
230 offset = 5; |
|
231 else if (len > 6) |
|
232 { |
|
233 pfx = name.substr (0, 6); |
|
234 |
|
235 if (pfx.compare ("figure")) |
|
236 offset = 6; |
|
237 else if (len > 7) |
|
238 { |
|
239 pfx = name.substr (0, 7); |
|
240 |
|
241 if (pfx.compare ("surface")) |
|
242 offset = 7; |
|
243 } |
|
244 } |
|
245 } |
|
246 |
|
247 if (offset > 0) |
|
248 { |
|
249 // FIXME -- should we validate property names and values here? |
|
250 |
|
251 std::string pname = name.substr (offset); |
|
252 |
|
253 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
|
254 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); |
|
255 |
|
256 bool remove = false; |
|
257 if (val.is_string ()) |
|
258 { |
|
259 property_name tval = val.string_value (); |
|
260 |
|
261 remove = tval.compare ("remove"); |
|
262 } |
|
263 |
|
264 pval_map_type& pval_map = plist_map[pfx]; |
|
265 |
|
266 if (remove) |
|
267 { |
|
268 pval_map_iterator p = pval_map.find (pname); |
|
269 |
|
270 if (p != pval_map.end ()) |
|
271 pval_map.erase (p); |
|
272 } |
|
273 else |
|
274 pval_map[pname] = val; |
|
275 } |
|
276 } |
|
277 |
|
278 if (offset == 0) |
|
279 error ("invalid default property specification"); |
|
280 } |
|
281 |
|
282 octave_value lookup (const property_name& name) const |
|
283 { |
|
284 octave_value retval; |
|
285 |
|
286 size_t offset = 0; |
|
287 |
|
288 size_t len = name.length (); |
|
289 |
|
290 if (len > 4) |
|
291 { |
|
292 property_name pfx = name.substr (0, 4); |
|
293 |
|
294 if (pfx.compare ("axes") || pfx.compare ("line") |
|
295 || pfx.compare ("text")) |
|
296 offset = 4; |
|
297 else if (len > 5) |
|
298 { |
|
299 pfx = name.substr (0, 5); |
|
300 |
|
301 if (pfx.compare ("image")) |
|
302 offset = 5; |
|
303 else if (len > 6) |
|
304 { |
|
305 pfx = name.substr (0, 6); |
|
306 |
|
307 if (pfx.compare ("figure")) |
|
308 offset = 6; |
|
309 else if (len > 7) |
|
310 { |
|
311 pfx = name.substr (0, 7); |
|
312 |
|
313 if (pfx.compare ("surface")) |
|
314 offset = 7; |
|
315 } |
|
316 } |
|
317 } |
|
318 |
|
319 if (offset > 0) |
|
320 { |
|
321 std::string pname = name.substr (offset); |
|
322 |
|
323 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
|
324 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); |
|
325 |
|
326 plist_map_const_iterator p = find (pfx); |
|
327 |
|
328 if (p != end ()) |
|
329 { |
|
330 const pval_map_type& pval_map = p->second; |
|
331 |
|
332 pval_map_const_iterator q = pval_map.find (pname); |
|
333 |
|
334 if (q != pval_map.end ()) |
|
335 retval = q->second; |
|
336 } |
|
337 } |
|
338 } |
|
339 |
|
340 return retval; |
|
341 } |
|
342 |
|
343 plist_map_iterator begin (void) { return plist_map.begin (); } |
|
344 plist_map_const_iterator begin (void) const { return plist_map.begin (); } |
|
345 |
|
346 plist_map_iterator end (void) { return plist_map.end (); } |
|
347 plist_map_const_iterator end (void) const { return plist_map.end (); } |
|
348 |
|
349 plist_map_iterator find (const std::string& go_name) |
|
350 { |
|
351 return plist_map.find (go_name); |
|
352 } |
|
353 |
|
354 plist_map_const_iterator find (const std::string& go_name) const |
|
355 { |
|
356 return plist_map.find (go_name); |
|
357 } |
|
358 |
|
359 Octave_map as_struct (const std::string& prefix_arg) const |
|
360 { |
|
361 Octave_map m; |
|
362 |
|
363 for (plist_map_const_iterator p = begin (); p != end (); p++) |
|
364 { |
|
365 std::string prefix = prefix_arg + p->first; |
|
366 |
|
367 const pval_map_type pval_map = p->second; |
|
368 |
|
369 for (pval_map_const_iterator q = pval_map.begin (); |
|
370 q != pval_map.end (); |
|
371 q++) |
|
372 m.assign (prefix + q->first, q->second); |
|
373 } |
|
374 |
|
375 return m; |
|
376 } |
|
377 |
|
378 private: |
|
379 plist_map_type plist_map; |
|
380 }; |
|
381 |
|
382 // --------------------------------------------------------------------- |
|
383 |
|
384 typedef double graphics_handle; |
|
385 |
|
386 // --------------------------------------------------------------------- |
|
387 |
|
388 class base_graphics_object |
|
389 { |
|
390 public: |
|
391 friend class graphics_object; |
|
392 |
|
393 base_graphics_object (void) : count (1) { } |
|
394 |
|
395 base_graphics_object (const base_graphics_object&) { } |
|
396 |
|
397 virtual ~base_graphics_object (void) { } |
|
398 |
|
399 virtual void override_defaults (base_graphics_object&) |
|
400 { |
|
401 error ("base_graphics_object::override_defaults: invalid graphics object"); |
|
402 } |
|
403 |
|
404 virtual void set_from_list (property_list&) |
|
405 { |
|
406 error ("base_graphics_object::set_from_list: invalid graphics object"); |
|
407 } |
|
408 |
|
409 virtual void set (const property_name&, const octave_value&) |
|
410 { |
|
411 error ("base_graphics_object::set: invalid graphics object"); |
|
412 } |
|
413 |
|
414 virtual void set_defaults (const std::string&) |
|
415 { |
|
416 error ("base_graphics_object::set_defaults: invalid graphics object"); |
|
417 } |
|
418 |
|
419 virtual octave_value get (void) const |
|
420 { |
|
421 error ("base_graphics_object::get: invalid graphics object"); |
|
422 return octave_value (); |
|
423 } |
|
424 |
|
425 virtual octave_value get (const property_name&) const |
|
426 { |
|
427 error ("base_graphics_object::get: invalid graphics object"); |
|
428 return octave_value (); |
|
429 } |
|
430 |
|
431 virtual octave_value get_default (const property_name&) const; |
|
432 |
|
433 virtual octave_value get_factory_default (const property_name&) const; |
|
434 |
|
435 virtual octave_value get_defaults (void) const |
|
436 { |
|
437 error ("base_graphics_object::get_defaults: invalid graphics object"); |
|
438 return octave_value (); |
|
439 } |
|
440 |
|
441 virtual octave_value get_factory_defaults (void) const |
|
442 { |
|
443 error ("base_graphics_object::get_factory_defaults: invalid graphics object"); |
|
444 return octave_value (); |
|
445 } |
|
446 |
|
447 virtual graphics_handle get_parent (void) const |
|
448 { |
|
449 error ("base_graphics_object::get_parent: invalid graphics object"); |
|
450 return octave_NaN; |
|
451 } |
|
452 |
|
453 virtual void remove_child (const graphics_handle&) |
|
454 { |
|
455 error ("base_graphics_object::remove_child: invalid graphics object"); |
|
456 } |
|
457 |
|
458 virtual void adopt (const graphics_handle&) |
|
459 { |
|
460 error ("base_graphics_object::adopt: invalid graphics object"); |
|
461 } |
|
462 |
|
463 virtual void reparent (const graphics_handle&) |
|
464 { |
|
465 error ("base_graphics_object::reparent: invalid graphics object"); |
|
466 } |
|
467 |
|
468 virtual void defaults (void) const |
|
469 { |
|
470 error ("base_graphics_object::default: invalid graphics object"); |
|
471 } |
|
472 |
|
473 virtual bool valid_object (void) const { return false; } |
|
474 |
|
475 virtual std::string type (void) const { return "unknown"; } |
|
476 |
|
477 bool isa (const std::string& go_name) const |
|
478 { |
|
479 return type () == go_name; |
|
480 } |
|
481 |
|
482 protected: |
|
483 // A reference count. |
|
484 int count; |
|
485 }; |
|
486 |
|
487 class graphics_object |
|
488 { |
|
489 public: |
|
490 graphics_object (void) : rep (new base_graphics_object ()) { } |
|
491 |
|
492 graphics_object (base_graphics_object *new_rep) |
|
493 : rep (new_rep) { } |
|
494 |
|
495 graphics_object (const graphics_object& obj) |
|
496 { |
|
497 rep = obj.rep; |
|
498 rep->count++; |
|
499 } |
|
500 |
|
501 graphics_object& operator = (const graphics_object& obj) |
|
502 { |
|
503 if (rep != obj.rep) |
|
504 { |
|
505 if (--rep->count == 0) |
|
506 delete rep; |
|
507 |
|
508 rep = obj.rep; |
|
509 rep->count++; |
|
510 } |
|
511 |
|
512 return *this; |
|
513 } |
|
514 |
|
515 ~graphics_object (void) |
|
516 { |
|
517 if (--rep->count == 0) |
|
518 delete rep; |
|
519 } |
|
520 |
|
521 void override_defaults (base_graphics_object& obj) |
|
522 { |
|
523 rep->override_defaults (obj); |
|
524 } |
|
525 |
|
526 void set_from_list (property_list& plist) |
|
527 { |
|
528 rep->set_from_list (plist); |
|
529 } |
|
530 |
|
531 void set (const property_name& name, const octave_value& val) |
|
532 { |
|
533 rep->set (name, val); |
|
534 } |
|
535 |
|
536 void set (const octave_value_list& args) |
|
537 { |
|
538 int nargin = args.length (); |
|
539 |
|
540 if (nargin == 0) |
|
541 rep->defaults (); |
|
542 else if (nargin % 2 == 0) |
|
543 { |
|
544 for (int i = 0; i < nargin; i += 2) |
|
545 { |
|
546 property_name name = args(i).string_value (); |
|
547 |
|
548 if (! error_state) |
|
549 { |
|
550 octave_value val = args(i+1); |
|
551 |
|
552 if (val.is_string ()) |
|
553 { |
|
554 property_name tval = val.string_value (); |
|
555 |
|
556 if (tval.compare ("default")) |
|
557 val = get_default (name); |
|
558 else if (tval.compare ("factory")) |
|
559 val = get_factory_default (name); |
|
560 } |
|
561 |
|
562 if (error_state) |
|
563 break; |
|
564 |
|
565 rep->set (name, val); |
|
566 } |
|
567 else |
|
568 error ("set: expecting argument %d to be a property name", i); |
|
569 } |
|
570 } |
|
571 else |
|
572 error ("set: invalid number of arguments"); |
|
573 } |
|
574 |
|
575 void set_defaults (const std::string& mode) |
|
576 { |
|
577 rep->set_defaults (mode); |
|
578 } |
|
579 |
|
580 octave_value get (void) const |
|
581 { |
|
582 return rep->get (); |
|
583 } |
|
584 |
|
585 octave_value get (const property_name& name) const |
|
586 { |
|
587 return name.compare ("default") |
|
588 ? get_defaults () |
|
589 : (name.compare ("factory") |
|
590 ? get_factory_defaults () : rep->get (name)); |
|
591 } |
|
592 |
|
593 octave_value get_default (const property_name& name) const |
|
594 { |
|
595 return rep->get_default (name); |
|
596 } |
|
597 |
|
598 octave_value get_factory_default (const property_name& name) const |
|
599 { |
|
600 return rep->get_factory_default (name); |
|
601 } |
|
602 |
|
603 octave_value get_defaults (void) const { return rep->get_defaults (); } |
|
604 |
|
605 octave_value get_factory_defaults (void) const |
|
606 { |
|
607 return rep->get_factory_defaults (); |
|
608 } |
|
609 |
|
610 graphics_handle get_parent (void) const { return rep->get_parent (); } |
|
611 |
|
612 void remove_child (const graphics_handle& h) { return rep->remove_child (h); } |
|
613 |
|
614 void adopt (const graphics_handle& h) { return rep->adopt (h); } |
|
615 |
|
616 void reparent (const graphics_handle& h) { return rep->reparent (h); } |
|
617 |
|
618 void defaults (void) const { rep->defaults (); } |
|
619 |
|
620 bool isa (const std::string& go_name) const { return rep->isa (go_name); } |
|
621 |
|
622 bool valid_object (void) const { return rep->valid_object (); } |
|
623 |
|
624 operator bool (void) const { return rep->valid_object (); } |
|
625 |
|
626 private: |
|
627 base_graphics_object *rep; |
|
628 }; |
|
629 |
|
630 // --------------------------------------------------------------------- |
|
631 |
|
632 class gh_manager |
|
633 { |
|
634 protected: |
|
635 |
|
636 gh_manager (void); |
|
637 |
|
638 public: |
|
639 |
|
640 static bool instance_ok (void) |
|
641 { |
|
642 bool retval = true; |
|
643 |
|
644 if (! instance) |
|
645 instance = new gh_manager (); |
|
646 |
|
647 if (! instance) |
|
648 { |
|
649 ::error ("unable to create gh_manager!"); |
|
650 |
|
651 retval = false; |
|
652 } |
|
653 |
|
654 return retval; |
|
655 } |
|
656 |
|
657 static void free (const graphics_handle& h) |
|
658 { |
|
659 if (instance_ok ()) |
|
660 instance->do_free (h); |
|
661 } |
|
662 |
|
663 static graphics_handle lookup (double val) |
|
664 { |
|
665 return instance_ok () ? instance->do_lookup (val) : graphics_handle (); |
|
666 } |
|
667 |
|
668 static graphics_object get_object (const graphics_handle& h) |
|
669 { |
|
670 return instance_ok () ? instance->do_get_object (h) : graphics_object (); |
|
671 } |
|
672 |
|
673 static graphics_handle |
|
674 make_graphics_handle (const std::string& go_name, |
|
675 const graphics_handle& parent) |
|
676 { |
|
677 return instance_ok () |
|
678 ? instance->do_make_graphics_handle (go_name, parent) : octave_NaN; |
|
679 } |
|
680 |
|
681 static graphics_handle make_figure_handle (double val) |
|
682 { |
|
683 return instance_ok () |
|
684 ? instance->do_make_figure_handle (val) : octave_NaN; |
|
685 } |
|
686 |
|
687 static void push_figure (const graphics_handle& h) |
|
688 { |
|
689 if (instance_ok ()) |
|
690 instance->do_push_figure (h); |
|
691 } |
|
692 |
|
693 static void pop_figure (const graphics_handle& h) |
|
694 { |
|
695 if (instance_ok ()) |
|
696 instance->do_pop_figure (h); |
|
697 } |
|
698 |
|
699 static graphics_handle current_figure (void) |
|
700 { |
|
701 return instance_ok () ? instance->do_current_figure () : octave_NaN; |
|
702 } |
|
703 |
6425
|
704 static Matrix handle_list (void) |
6406
|
705 { |
6425
|
706 return instance_ok () ? instance->do_handle_list () : Matrix (); |
|
707 } |
|
708 |
|
709 static Matrix figure_handle_list (void) |
|
710 { |
|
711 return instance_ok () ? instance->do_figure_handle_list () : Matrix (); |
6406
|
712 } |
|
713 |
|
714 private: |
|
715 |
|
716 static gh_manager *instance; |
|
717 |
|
718 typedef std::map<graphics_handle, graphics_object>::iterator iterator; |
|
719 typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator; |
|
720 |
|
721 typedef std::set<graphics_handle>::iterator free_list_iterator; |
|
722 typedef std::set<graphics_handle>::const_iterator const_free_list_iterator; |
|
723 |
|
724 typedef std::list<graphics_handle>::iterator figure_list_iterator; |
|
725 typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator; |
|
726 |
|
727 // A map of handles to graphics objects. |
|
728 std::map<graphics_handle, graphics_object> handle_map; |
|
729 |
|
730 // The available graphics handles. |
|
731 std::set<graphics_handle> handle_free_list; |
|
732 |
|
733 // The next handle available if handle_free_list is empty. |
|
734 graphics_handle next_handle; |
|
735 |
|
736 // The allocated figure handles. Top of the stack is most recently |
|
737 // created. |
|
738 std::list<graphics_handle> figure_list; |
|
739 |
|
740 graphics_handle get_handle (const std::string& go_name) |
|
741 { |
|
742 graphics_handle retval; |
|
743 |
|
744 if (go_name == "figure") |
|
745 { |
|
746 // We always want the lowest unused figure number. |
|
747 |
|
748 retval = 1; |
|
749 |
|
750 while (handle_map.find (retval) != handle_map.end ()) |
|
751 retval++; |
|
752 } |
|
753 else |
|
754 { |
|
755 free_list_iterator p = handle_free_list.begin (); |
|
756 |
|
757 if (p != handle_free_list.end ()) |
|
758 { |
|
759 retval = *p; |
|
760 handle_free_list.erase (p); |
|
761 } |
|
762 else |
|
763 retval = next_handle--; |
|
764 } |
|
765 |
|
766 return retval; |
|
767 } |
|
768 |
|
769 void do_free (const graphics_handle& h) |
|
770 { |
|
771 if (h != 0) |
|
772 { |
|
773 iterator p = handle_map.find (h); |
|
774 |
|
775 if (p != handle_map.end ()) |
|
776 { |
|
777 handle_map.erase (p); |
|
778 |
|
779 if (h < 0) |
|
780 handle_free_list.insert (h); |
|
781 } |
|
782 else |
|
783 error ("graphics_handle::free: invalid object %g", h); |
|
784 } |
|
785 else |
|
786 error ("graphics_handle::free: can't delete root figure"); |
|
787 } |
|
788 |
|
789 graphics_handle do_lookup (double val) |
|
790 { |
|
791 iterator p = handle_map.find (val); |
|
792 |
|
793 return (p != handle_map.end ()) ? p->first : octave_NaN; |
|
794 } |
|
795 |
|
796 graphics_object do_get_object (const graphics_handle& h) |
|
797 { |
|
798 iterator p = handle_map.find (h); |
|
799 |
|
800 return (p != handle_map.end ()) ? p->second : graphics_object (); |
|
801 } |
|
802 |
|
803 graphics_handle do_make_graphics_handle (const std::string& go_name, |
|
804 const graphics_handle& p); |
|
805 |
|
806 graphics_handle do_make_figure_handle (double val); |
|
807 |
6425
|
808 Matrix do_handle_list (void) |
6406
|
809 { |
|
810 Matrix retval (1, handle_map.size ()); |
|
811 octave_idx_type i = 0; |
|
812 for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++) |
|
813 retval(i++) = p->first; |
|
814 return retval; |
|
815 } |
|
816 |
6425
|
817 Matrix do_figure_handle_list (void) |
|
818 { |
|
819 Matrix retval (1, figure_list.size ()); |
|
820 octave_idx_type i = 0; |
|
821 for (const_figure_list_iterator p = figure_list.begin (); |
|
822 p != figure_list.end (); |
|
823 p++) |
|
824 retval(i++) = *p; |
|
825 return retval; |
|
826 } |
|
827 |
6406
|
828 void do_push_figure (const graphics_handle& h); |
|
829 |
|
830 void do_pop_figure (const graphics_handle& h); |
|
831 |
|
832 graphics_handle do_current_figure (void) const |
|
833 { |
|
834 return figure_list.empty () ? octave_NaN : figure_list.front (); |
|
835 } |
|
836 }; |
|
837 |
|
838 gh_manager *gh_manager::instance = 0; |
|
839 |
|
840 // --------------------------------------------------------------------- |
|
841 |
|
842 static void |
|
843 xset (const graphics_handle& h, const property_name& name, |
|
844 const octave_value& val) |
|
845 { |
|
846 graphics_object obj = gh_manager::get_object (h); |
|
847 obj.set (name, val); |
|
848 } |
|
849 |
|
850 static void |
|
851 xset (const graphics_handle& h, const octave_value_list& args) |
|
852 { |
|
853 if (args.length () > 0) |
|
854 { |
|
855 graphics_object obj = gh_manager::get_object (h); |
|
856 obj.set (args); |
|
857 } |
|
858 } |
|
859 |
|
860 |
|
861 static octave_value |
|
862 xget (const graphics_handle& h, const property_name& name) |
|
863 { |
|
864 graphics_object obj = gh_manager::get_object (h); |
|
865 return obj.get (name); |
|
866 } |
|
867 |
|
868 static graphics_handle |
|
869 reparent (const octave_value& ov, const std::string& who, |
|
870 const std::string& property, const graphics_handle& new_parent, |
|
871 bool adopt = true) |
|
872 { |
|
873 graphics_handle h = octave_NaN; |
|
874 |
|
875 double val = ov.double_value (); |
|
876 |
|
877 if (! error_state) |
|
878 { |
|
879 h = gh_manager::lookup (val); |
|
880 |
|
881 if (! xisnan (h)) |
|
882 { |
|
883 graphics_object obj = gh_manager::get_object (h); |
|
884 |
|
885 graphics_handle parent_h = obj.get_parent (); |
|
886 |
|
887 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
888 |
|
889 parent_obj.remove_child (h); |
|
890 |
|
891 if (adopt) |
|
892 obj.set ("parent", new_parent); |
|
893 else |
|
894 obj.reparent (new_parent); |
|
895 } |
|
896 else |
|
897 error ("%s: invalid graphics handle (= %g) for %s", |
|
898 who.c_str (), val, property.c_str ()); |
|
899 } |
|
900 else |
|
901 error ("%s: expecting %s to be a graphics handle", |
|
902 who.c_str (), property.c_str ()); |
|
903 |
|
904 return h; |
|
905 } |
|
906 |
|
907 // This function is NOT equivalent to the scripting language function gcf. |
|
908 graphics_handle |
|
909 gcf (void) |
|
910 { |
|
911 octave_value val = xget (0, "currentfigure"); |
|
912 |
|
913 return val.is_empty () ? octave_NaN : val.double_value (); |
|
914 } |
|
915 |
|
916 // This function is NOT equivalent to the scripting language function gca. |
|
917 graphics_handle |
|
918 gca (void) |
|
919 { |
|
920 octave_value val = xget (gcf (), "currentaxes"); |
|
921 |
|
922 return val.is_empty () ? octave_NaN : val.double_value (); |
|
923 } |
|
924 |
|
925 static void |
|
926 adopt (const graphics_handle& p, const graphics_handle& h) |
|
927 { |
|
928 graphics_object parent_obj = gh_manager::get_object (p); |
|
929 |
|
930 parent_obj.adopt (h); |
|
931 } |
|
932 |
|
933 static bool |
|
934 is_handle (double val) |
|
935 { |
|
936 return ! xisnan (gh_manager::lookup (val)); |
|
937 } |
|
938 |
|
939 static bool |
|
940 is_handle (const octave_value& val) |
|
941 { |
|
942 return val.is_real_type () && is_handle (val.double_value ()); |
|
943 } |
|
944 |
|
945 static bool |
|
946 is_figure (double val) |
|
947 { |
|
948 graphics_object obj = gh_manager::get_object (val); |
|
949 |
|
950 return obj && obj.isa ("figure"); |
|
951 } |
|
952 |
|
953 // --------------------------------------------------------------------- |
|
954 |
|
955 static int |
|
956 compare (const void *a_arg, const void *b_arg) |
|
957 { |
|
958 double a = *(static_cast<const double *> (a_arg)); |
|
959 double b = *(static_cast<const double *> (b_arg)); |
|
960 |
|
961 return a > b ? 1 : (a < b) ? -1 : 0; |
|
962 } |
|
963 |
|
964 static Matrix |
|
965 maybe_set_children (const Matrix& kids, const octave_value& val) |
|
966 { |
|
967 const Matrix new_kids = val.matrix_value (); |
|
968 |
|
969 bool ok = true; |
|
970 |
|
971 if (! error_state) |
|
972 { |
|
973 if (kids.numel () == new_kids.numel ()) |
|
974 { |
|
975 Matrix t1 = kids; |
|
976 Matrix t2 = new_kids; |
|
977 |
|
978 t1.qsort (compare); |
|
979 t2.qsort (compare); |
|
980 |
|
981 if (t1 != t2) |
|
982 ok = false; |
|
983 } else |
|
984 ok = false; |
|
985 |
|
986 if (! ok) |
|
987 error ("set: new children must be a permutation of existing children"); |
|
988 } |
|
989 else |
|
990 { |
|
991 ok = false; |
|
992 error ("set: expecting children to be array of graphics handles"); |
|
993 } |
|
994 |
|
995 return ok ? new_kids : kids; |
|
996 } |
|
997 |
|
998 class base_properties |
|
999 { |
|
1000 public: |
|
1001 base_properties (const std::string& t = "unknown", |
|
1002 const graphics_handle& mh = octave_NaN, |
|
1003 const graphics_handle& p = octave_NaN) |
|
1004 : type (t), __myhandle__ (mh), parent (p), children () { } |
|
1005 |
|
1006 virtual ~base_properties (void) { } |
|
1007 |
|
1008 virtual std::string graphics_object_name (void) const = 0; |
|
1009 |
|
1010 void override_defaults (base_graphics_object& obj) |
|
1011 { |
|
1012 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1013 parent_obj.override_defaults (obj); |
|
1014 } |
|
1015 |
|
1016 // Look through DEFAULTS for properties with given CLASS_NAME, and |
|
1017 // apply them to the current object with set (virtual method). |
|
1018 |
|
1019 void set_from_list (base_graphics_object& obj, property_list& defaults) |
|
1020 { |
|
1021 std::string go_name = graphics_object_name (); |
|
1022 |
|
1023 property_list::plist_map_const_iterator p = defaults.find (go_name); |
|
1024 |
|
1025 if (p != defaults.end ()) |
|
1026 { |
|
1027 const property_list::pval_map_type pval_map = p->second; |
|
1028 |
|
1029 for (property_list::pval_map_const_iterator q = pval_map.begin (); |
|
1030 q != pval_map.end (); |
|
1031 q++) |
|
1032 { |
|
1033 std::string pname = q->first; |
|
1034 |
|
1035 obj.set (pname, q->second); |
|
1036 |
|
1037 if (error_state) |
|
1038 { |
|
1039 error ("error setting default property %s", pname.c_str ()); |
|
1040 break; |
|
1041 } |
|
1042 } |
|
1043 } |
|
1044 } |
|
1045 |
|
1046 virtual void set (const property_name& name, const octave_value& val) = 0; |
|
1047 |
|
1048 graphics_handle get_parent (void) const { return parent; } |
|
1049 |
|
1050 void remove_child (const graphics_handle& h) |
|
1051 { |
|
1052 octave_idx_type k = -1; |
|
1053 octave_idx_type n = children.numel (); |
|
1054 for (octave_idx_type i = 0; i < n; i++) |
|
1055 { |
|
1056 if (h == children(i)) |
|
1057 { |
|
1058 k = i; |
|
1059 break; |
|
1060 } |
|
1061 } |
|
1062 |
|
1063 if (k >= 0) |
|
1064 { |
|
1065 Matrix new_kids (1, n-1); |
|
1066 octave_idx_type j = 0; |
|
1067 for (octave_idx_type i = 0; i < n; i++) |
|
1068 { |
|
1069 if (i != k) |
|
1070 new_kids(j++) = children(i); |
|
1071 } |
|
1072 children = new_kids; |
|
1073 } |
|
1074 } |
|
1075 |
|
1076 void adopt (const graphics_handle& h) |
|
1077 { |
|
1078 octave_idx_type n = children.numel (); |
|
1079 children.resize (1, n+1); |
|
1080 children(n) = h; |
|
1081 } |
|
1082 |
|
1083 void set_parent (const octave_value& val) |
|
1084 { |
|
1085 double tmp = val.double_value (); |
|
1086 |
|
1087 graphics_handle new_parent = octave_NaN; |
|
1088 |
|
1089 if (! error_state) |
|
1090 { |
|
1091 new_parent = gh_manager::lookup (tmp); |
|
1092 |
|
1093 if (! xisnan (new_parent)) |
|
1094 { |
|
1095 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1096 |
|
1097 parent_obj.remove_child (__myhandle__); |
|
1098 |
|
1099 parent = new_parent; |
|
1100 |
|
1101 ::adopt (parent, __myhandle__); |
|
1102 } |
|
1103 else |
|
1104 error ("set: invalid graphics handle (= %g) for parent", tmp); |
|
1105 } |
|
1106 else |
|
1107 error ("set: expecting parent to be a graphics handle"); |
|
1108 } |
|
1109 |
|
1110 void reparent (const graphics_handle& new_parent) { parent = new_parent; } |
|
1111 |
|
1112 virtual void delete_children (void) |
|
1113 { |
|
1114 octave_idx_type n = children.numel (); |
|
1115 |
|
1116 for (octave_idx_type i = 0; i < n; i++) |
|
1117 gh_manager::free (children(i)); |
|
1118 } |
|
1119 |
|
1120 protected: |
|
1121 std::string type; |
|
1122 graphics_handle __myhandle__; |
|
1123 graphics_handle parent; |
|
1124 Matrix children; |
|
1125 }; |
|
1126 |
|
1127 // --------------------------------------------------------------------- |
|
1128 |
|
1129 class root_figure : public base_graphics_object |
|
1130 { |
|
1131 public: |
|
1132 class root_figure_properties : public base_properties |
|
1133 { |
|
1134 public: |
|
1135 root_figure_properties (void) |
|
1136 : base_properties ("root figure", 0, octave_NaN), |
|
1137 currentfigure (octave_NaN), |
|
1138 visible ("on") |
|
1139 { } |
|
1140 |
|
1141 ~root_figure_properties (void) { } |
|
1142 |
|
1143 void set (const property_name& name, const octave_value& val) |
|
1144 { |
|
1145 if (name.compare ("currentfigure")) |
|
1146 { |
|
1147 octave_value tval = empty_to_nan (val); |
|
1148 |
|
1149 if (is_handle (tval)) |
|
1150 { |
|
1151 currentfigure = tval.double_value (); |
|
1152 |
|
1153 gh_manager::push_figure (currentfigure); |
|
1154 } |
|
1155 else |
|
1156 gripe_set_invalid ("currentfigure"); |
|
1157 } |
|
1158 else if (name.compare ("children")) |
|
1159 children = maybe_set_children (children, val); |
|
1160 else if (name.compare ("visible")) |
|
1161 visible = val; |
|
1162 else |
|
1163 warning ("set: invalid property `%s'", name.c_str ()); |
|
1164 } |
|
1165 |
|
1166 octave_value get (void) const |
|
1167 { |
|
1168 Octave_map m; |
|
1169 |
|
1170 m.assign ("type", type); |
|
1171 m.assign ("currentfigure", nan_to_empty (currentfigure)); |
|
1172 m.assign ("children", children); |
|
1173 m.assign ("visible", visible); |
|
1174 |
|
1175 return m; |
|
1176 } |
|
1177 |
|
1178 octave_value get (const property_name& name) const |
|
1179 { |
|
1180 octave_value retval; |
|
1181 |
|
1182 if (name.compare ("type")) |
|
1183 retval = type; |
|
1184 else if (name.compare ("currentfigure")) |
|
1185 retval = nan_to_empty (currentfigure); |
|
1186 else if (name.compare ("children")) |
|
1187 retval = children; |
|
1188 else if (name.compare ("visible")) |
|
1189 retval = visible; |
|
1190 else |
|
1191 warning ("get: invalid property `%s'", name.c_str ()); |
|
1192 |
|
1193 return retval; |
|
1194 } |
|
1195 |
|
1196 std::string graphics_object_name (void) const { return go_name; } |
|
1197 |
|
1198 private: |
|
1199 graphics_handle currentfigure; |
|
1200 octave_value visible; |
|
1201 |
|
1202 static std::string go_name; |
|
1203 }; |
|
1204 |
|
1205 root_figure_properties properties; |
|
1206 |
|
1207 public: |
|
1208 |
|
1209 root_figure (void) : properties (), default_properties () { } |
|
1210 |
|
1211 ~root_figure (void) { properties.delete_children (); } |
|
1212 |
|
1213 std::string type (void) const { return properties.graphics_object_name (); } |
|
1214 |
|
1215 void override_defaults (base_graphics_object& obj) |
|
1216 { |
|
1217 // Now override with our defaults. If the default_properties |
|
1218 // list includes the properties for all defaults (line, |
|
1219 // surface, etc.) then we don't have to know the type of OBJ |
|
1220 // here, we just call its set function and let it decide which |
|
1221 // properties from the list to use. |
|
1222 obj.set_from_list (default_properties); |
|
1223 } |
|
1224 |
|
1225 void set_from_list (property_list& plist) |
|
1226 { |
|
1227 properties.set_from_list (*this, plist); |
|
1228 } |
|
1229 |
|
1230 void set (const property_name& name, const octave_value& value) |
|
1231 { |
|
1232 if (name.compare ("default", 7)) |
|
1233 // strip "default", pass rest to function that will |
|
1234 // parse the remainder and add the element to the |
|
1235 // default_properties map. |
|
1236 default_properties.set (name.substr (7), value); |
|
1237 else |
|
1238 properties.set (name, value); |
|
1239 } |
|
1240 |
|
1241 octave_value get (void) const |
|
1242 { |
|
1243 return properties.get (); |
|
1244 } |
|
1245 |
|
1246 octave_value get (const property_name& name) const |
|
1247 { |
|
1248 octave_value retval; |
|
1249 |
|
1250 if (name.compare ("default", 7)) |
|
1251 return get_default (name.substr (7)); |
|
1252 else if (name.compare ("factory", 7)) |
|
1253 return get_factory_default (name.substr (7)); |
|
1254 else |
|
1255 retval = properties.get (name); |
|
1256 |
|
1257 return retval; |
|
1258 } |
|
1259 |
|
1260 octave_value get_default (const property_name& name) const |
|
1261 { |
|
1262 octave_value retval = default_properties.lookup (name); |
|
1263 |
|
1264 if (retval.is_undefined ()) |
|
1265 error ("get: invalid default property `%s'", name.c_str ()); |
|
1266 |
|
1267 return retval; |
|
1268 } |
|
1269 |
|
1270 octave_value get_factory_default (const property_name& name) const |
|
1271 { |
|
1272 octave_value retval = factory_properties.lookup (name); |
|
1273 |
|
1274 if (retval.is_undefined ()) |
|
1275 error ("get: invalid factory default property `%s'", name.c_str ()); |
|
1276 |
|
1277 return retval; |
|
1278 } |
|
1279 |
|
1280 octave_value get_defaults (void) const |
|
1281 { |
|
1282 return default_properties.as_struct ("default"); |
|
1283 } |
|
1284 |
|
1285 octave_value get_factory_defaults (void) const |
|
1286 { |
|
1287 return factory_properties.as_struct ("factory"); |
|
1288 } |
|
1289 |
|
1290 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
1291 |
|
1292 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
1293 |
|
1294 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
1295 |
|
1296 void reparent (const graphics_handle& np) { properties.reparent (np); } |
|
1297 |
|
1298 bool valid_object (void) const { return true; } |
|
1299 |
|
1300 private: |
|
1301 property_list default_properties; |
|
1302 |
|
1303 static property_list factory_properties; |
|
1304 |
|
1305 static property_list::plist_map_type init_factory_properties (void); |
|
1306 }; |
|
1307 |
|
1308 property_list |
|
1309 root_figure::factory_properties = root_figure::init_factory_properties (); |
|
1310 |
|
1311 std::string root_figure::root_figure_properties::go_name ("root figure"); |
|
1312 |
|
1313 // --------------------------------------------------------------------- |
|
1314 |
|
1315 class figure : public base_graphics_object |
|
1316 { |
|
1317 public: |
|
1318 class figure_properties : public base_properties |
|
1319 { |
|
1320 public: |
|
1321 figure_properties (const graphics_handle& mh, const graphics_handle& p) |
|
1322 : base_properties (go_name, mh, p), |
|
1323 __plot_stream__ (Matrix ()), |
|
1324 nextplot ("replace"), |
|
1325 closerequestfcn (make_fcn_handle ("closereq")), |
|
1326 currentaxes (octave_NaN), |
|
1327 colormap (), |
|
1328 visible ("on"), |
|
1329 paperorientation ("portrait") |
|
1330 { } |
|
1331 |
|
1332 ~figure_properties (void) { } |
|
1333 |
|
1334 void set (const property_name& name, const octave_value& val) |
|
1335 { |
|
1336 if (name.compare ("children")) |
|
1337 children = maybe_set_children (children, val); |
|
1338 else if (name.compare ("__plot_stream__")) |
|
1339 __plot_stream__ = val; |
|
1340 else if (name.compare ("nextplot")) |
|
1341 nextplot = val; |
|
1342 else if (name.compare ("closerequestfcn")) |
|
1343 closerequestfcn = val; |
|
1344 else if (name.compare ("currentaxes")) |
|
1345 { |
|
1346 octave_value tval = empty_to_nan (val); |
|
1347 |
|
1348 if (is_handle (tval)) |
|
1349 currentaxes = tval.double_value (); |
|
1350 else |
|
1351 gripe_set_invalid ("currentaxes"); |
|
1352 } |
|
1353 else if (name.compare ("colormap")) |
|
1354 colormap = colormap_property (val); |
|
1355 else if (name.compare ("visible")) |
6425
|
1356 { |
|
1357 std::string s = val.string_value (); |
|
1358 |
|
1359 if (! error_state) |
|
1360 { |
|
1361 if (s == "on") |
|
1362 xset (0, "currentfigure", __myhandle__); |
|
1363 |
|
1364 visible = val; |
|
1365 } |
|
1366 } |
6406
|
1367 else if (name.compare ("paperorientation")) |
|
1368 paperorientation = val; |
|
1369 else |
|
1370 warning ("set: invalid property `%s'", name.c_str ()); |
|
1371 } |
|
1372 |
|
1373 octave_value get (void) const |
|
1374 { |
|
1375 Octave_map m; |
|
1376 |
|
1377 m.assign ("type", type); |
|
1378 m.assign ("parent", parent); |
|
1379 m.assign ("children", children); |
|
1380 m.assign ("__plot_stream__", __plot_stream__); |
|
1381 m.assign ("nextplot", nextplot); |
|
1382 m.assign ("closerequestfcn", closerequestfcn); |
|
1383 m.assign ("currentaxes", nan_to_empty (currentaxes)); |
|
1384 m.assign ("colormap", colormap); |
|
1385 m.assign ("visible", visible); |
|
1386 m.assign ("paperorientation", paperorientation); |
|
1387 |
|
1388 return m; |
|
1389 } |
|
1390 |
|
1391 octave_value get (const property_name& name) const |
|
1392 { |
|
1393 octave_value retval; |
|
1394 |
|
1395 if (name.compare ("type")) |
|
1396 retval = type; |
|
1397 else if (name.compare ("parent")) |
|
1398 retval = parent; |
|
1399 else if (name.compare ("children")) |
|
1400 retval = children; |
|
1401 else if (name.compare ("__plot_stream__")) |
|
1402 retval = __plot_stream__; |
|
1403 else if (name.compare ("nextplot")) |
|
1404 retval = nextplot; |
|
1405 else if (name.compare ("closerequestfcn")) |
|
1406 retval = closerequestfcn; |
|
1407 else if (name.compare ("currentaxes")) |
|
1408 retval = nan_to_empty (currentaxes); |
|
1409 else if (name.compare ("colormap")) |
|
1410 retval = colormap; |
|
1411 else if (name.compare ("visible")) |
|
1412 retval = visible; |
|
1413 else if (name.compare ("paperorientation")) |
|
1414 retval = paperorientation; |
|
1415 else |
|
1416 warning ("get: invalid property `%s'", name.c_str ()); |
|
1417 |
|
1418 return retval; |
|
1419 } |
|
1420 |
|
1421 void close (void) |
|
1422 { |
|
1423 if (! __plot_stream__.is_empty ()) |
|
1424 { |
|
1425 octave_value_list args; |
|
1426 args(1) = "\nquit;\n"; |
|
1427 args(0) = __plot_stream__; |
|
1428 feval ("fputs", args); |
|
1429 args.resize (1); |
|
1430 feval ("fflush", args); |
|
1431 feval ("pclose", args); |
|
1432 } |
|
1433 |
|
1434 gh_manager::pop_figure (__myhandle__); |
|
1435 |
|
1436 xset (0, "currentfigure", gh_manager::current_figure ()); |
|
1437 } |
|
1438 |
|
1439 std::string graphics_object_name (void) const { return go_name; } |
|
1440 |
|
1441 static property_list::pval_map_type factory_defaults (void) |
|
1442 { |
|
1443 property_list::pval_map_type m; |
|
1444 |
|
1445 m["nextplot"] = "replace"; |
|
1446 // m["closerequestfcn"] = make_fcn_handle ("closereq"); |
|
1447 m["colormap"] = colormap_property (); |
|
1448 m["visible"] = "on"; |
|
1449 m["paperorientation"] = "portrait"; |
|
1450 |
|
1451 return m; |
|
1452 } |
|
1453 |
|
1454 private: |
|
1455 octave_value __plot_stream__; |
|
1456 octave_value nextplot; |
|
1457 octave_value closerequestfcn; |
|
1458 graphics_handle currentaxes; |
|
1459 colormap_property colormap; |
|
1460 octave_value visible; |
|
1461 octave_value paperorientation; |
|
1462 |
|
1463 static std::string go_name; |
|
1464 }; |
|
1465 |
|
1466 figure_properties properties; |
|
1467 |
|
1468 public: |
|
1469 figure (const graphics_handle& mh, const graphics_handle& p) |
|
1470 : base_graphics_object (), properties (mh, p), default_properties () |
|
1471 { |
|
1472 properties.override_defaults (*this); |
|
1473 } |
|
1474 |
|
1475 ~figure (void) |
|
1476 { |
|
1477 properties.delete_children (); |
|
1478 properties.close (); |
|
1479 } |
|
1480 |
|
1481 std::string type (void) const { return properties.graphics_object_name (); } |
|
1482 |
|
1483 void override_defaults (base_graphics_object& obj) |
|
1484 { |
|
1485 // Allow parent (root figure) to override first (properties knows how |
|
1486 // to find the parent object). |
|
1487 properties.override_defaults (obj); |
|
1488 |
|
1489 // Now override with our defaults. If the default_properties |
|
1490 // list includes the properties for all defaults (line, |
|
1491 // surface, etc.) then we don't have to know the type of OBJ |
|
1492 // here, we just call its set function and let it decide which |
|
1493 // properties from the list to use. |
|
1494 obj.set_from_list (default_properties); |
|
1495 } |
|
1496 |
|
1497 void set_from_list (property_list& plist) |
|
1498 { |
|
1499 properties.set_from_list (*this, plist); |
|
1500 } |
|
1501 |
|
1502 void set (const property_name& name, const octave_value& value) |
|
1503 { |
|
1504 if (name.compare ("default", 7)) |
|
1505 // strip "default", pass rest to function that will |
|
1506 // parse the remainder and add the element to the |
|
1507 // default_properties map. |
|
1508 default_properties.set (name.substr (7), value); |
|
1509 else |
|
1510 properties.set (name, value); |
|
1511 } |
|
1512 |
|
1513 octave_value get (void) const |
|
1514 { |
|
1515 return properties.get (); |
|
1516 } |
|
1517 |
|
1518 octave_value get (const property_name& name) const |
|
1519 { |
|
1520 octave_value retval; |
|
1521 |
|
1522 if (name.compare ("default", 7)) |
|
1523 retval = get_default (name.substr (7)); |
|
1524 else |
|
1525 retval = properties.get (name); |
|
1526 |
|
1527 return retval; |
|
1528 } |
|
1529 |
|
1530 octave_value get_default (const property_name& name) const |
|
1531 { |
|
1532 octave_value retval = default_properties.lookup (name); |
|
1533 |
|
1534 if (retval.is_undefined ()) |
|
1535 { |
|
1536 graphics_handle parent = get_parent (); |
|
1537 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1538 |
|
1539 retval = parent_obj.get_default (name); |
|
1540 } |
|
1541 |
|
1542 return retval; |
|
1543 } |
|
1544 |
|
1545 octave_value get_defaults (void) const |
|
1546 { |
|
1547 return default_properties.as_struct ("default"); |
|
1548 } |
|
1549 |
|
1550 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
1551 |
|
1552 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
1553 |
|
1554 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
1555 |
|
1556 void reparent (const graphics_handle& np) { properties.reparent (np); } |
|
1557 |
|
1558 bool valid_object (void) const { return true; } |
|
1559 |
|
1560 private: |
|
1561 property_list default_properties; |
|
1562 }; |
|
1563 |
|
1564 std::string figure::figure_properties::go_name ("figure"); |
|
1565 |
|
1566 // --------------------------------------------------------------------- |
|
1567 |
|
1568 class axes : public base_graphics_object |
|
1569 { |
|
1570 public: |
|
1571 class axes_properties : public base_properties |
|
1572 { |
|
1573 public: |
|
1574 axes_properties (const graphics_handle& mh, const graphics_handle& p) |
|
1575 : base_properties (go_name, mh, p), |
|
1576 position (Matrix ()), |
|
1577 title (octave_NaN), |
|
1578 box ("on"), |
|
1579 key ("off"), |
|
1580 keybox ("off"), |
|
1581 keypos (1), |
|
1582 dataaspectratio (Matrix (1, 3, 1.0)), |
|
1583 dataaspectratiomode ("auto"), |
|
1584 xlim (), |
|
1585 ylim (), |
|
1586 zlim (), |
|
1587 xlimmode ("auto"), |
|
1588 ylimmode ("auto"), |
|
1589 zlimmode ("auto"), |
|
1590 xlabel (octave_NaN), |
|
1591 ylabel (octave_NaN), |
|
1592 zlabel (octave_NaN), |
|
1593 xgrid ("off"), |
|
1594 ygrid ("off"), |
|
1595 zgrid ("off"), |
|
1596 xminorgrid ("off"), |
|
1597 yminorgrid ("off"), |
|
1598 zminorgrid ("off"), |
|
1599 xtick (Matrix ()), |
|
1600 ytick (Matrix ()), |
|
1601 ztick (Matrix ()), |
|
1602 xtickmode ("auto"), |
|
1603 ytickmode ("auto"), |
|
1604 ztickmode ("auto"), |
|
1605 xticklabel (""), |
|
1606 yticklabel (""), |
|
1607 zticklabel (""), |
|
1608 xticklabelmode ("auto"), |
|
1609 yticklabelmode ("auto"), |
|
1610 zticklabelmode ("auto"), |
|
1611 xscale ("linear"), |
|
1612 yscale ("linear"), |
|
1613 zscale ("linear"), |
|
1614 xdir ("normal"), |
|
1615 ydir ("normal"), |
|
1616 zdir ("normal"), |
|
1617 view (), |
|
1618 nextplot ("replace"), |
|
1619 outerposition () |
|
1620 { |
|
1621 Matrix tlim (1, 2, 0.0); |
|
1622 tlim(1) = 1; |
|
1623 xlim = tlim; |
|
1624 ylim = tlim; |
|
1625 zlim = tlim; |
|
1626 |
|
1627 Matrix tview (1, 2, 0.0); |
|
1628 tview(1) = 90; |
|
1629 view = tview; |
|
1630 |
|
1631 Matrix touterposition (1, 4, 0.0); |
|
1632 touterposition(2) = 1; |
|
1633 touterposition(3) = 1; |
|
1634 outerposition = touterposition; |
|
1635 } |
|
1636 |
|
1637 ~axes_properties (void) { } |
|
1638 |
|
1639 void set (const property_name& name, const octave_value& val) |
|
1640 { |
|
1641 if (name.compare ("parent")) |
|
1642 set_parent (val); |
|
1643 else if (name.compare ("children")) |
|
1644 children = maybe_set_children (children, val); |
|
1645 else if (name.compare ("position")) |
|
1646 position = val; |
|
1647 else if (name.compare ("title")) |
|
1648 { |
|
1649 graphics_handle h = ::reparent (val, "set", "title", |
|
1650 __myhandle__, false); |
|
1651 if (! error_state) |
|
1652 { |
|
1653 if (! xisnan (title)) |
|
1654 gh_manager::free (title); |
|
1655 |
|
1656 title = h; |
|
1657 } |
|
1658 } |
|
1659 else if (name.compare ("box")) |
|
1660 box = val; |
|
1661 else if (name.compare ("key")) |
|
1662 key = val; |
|
1663 else if (name.compare ("keybox")) |
|
1664 keybox = val; |
|
1665 else if (name.compare ("keypos")) |
|
1666 keypos = val; |
|
1667 else if (name.compare ("dataaspectratio")) |
|
1668 { |
|
1669 dataaspectratio = val; |
|
1670 dataaspectratiomode = "manual"; |
|
1671 } |
|
1672 else if (name.compare ("dataaspectratiomode")) |
|
1673 dataaspectratiomode = val; |
|
1674 else if (name.compare ("xlim")) |
|
1675 { |
|
1676 xlim = val; |
|
1677 xlimmode = "manual"; |
|
1678 } |
|
1679 else if (name.compare ("ylim")) |
|
1680 { |
|
1681 ylim = val; |
|
1682 ylimmode = "manual"; |
|
1683 } |
|
1684 else if (name.compare ("zlim")) |
|
1685 { |
|
1686 zlim = val; |
|
1687 zlimmode = "manual"; |
|
1688 } |
|
1689 else if (name.compare ("xlimmode")) |
|
1690 xlimmode = val; |
|
1691 else if (name.compare ("ylimmode")) |
|
1692 ylimmode = val; |
|
1693 else if (name.compare ("zlimmode")) |
|
1694 zlimmode = val; |
|
1695 else if (name.compare ("xlabel")) |
|
1696 { |
|
1697 graphics_handle h = ::reparent (val, "set", "xlabel", |
|
1698 __myhandle__, false); |
|
1699 if (! error_state) |
|
1700 { |
|
1701 if (! xisnan (xlabel)) |
|
1702 gh_manager::free (xlabel); |
|
1703 |
|
1704 xlabel = h; |
|
1705 } |
|
1706 } |
|
1707 else if (name.compare ("ylabel")) |
|
1708 { |
|
1709 graphics_handle h = ::reparent (val, "set", "ylabel", |
|
1710 __myhandle__, false); |
|
1711 if (! error_state) |
|
1712 { |
|
1713 if (! xisnan (ylabel)) |
|
1714 gh_manager::free (ylabel); |
|
1715 |
|
1716 ylabel = h; |
|
1717 } |
|
1718 } |
|
1719 else if (name.compare ("zlabel")) |
|
1720 { |
|
1721 graphics_handle h = ::reparent (val, "set", "zlabel", |
|
1722 __myhandle__, false); |
|
1723 if (! error_state) |
|
1724 { |
|
1725 if (! xisnan (zlabel)) |
|
1726 gh_manager::free (zlabel); |
|
1727 |
|
1728 zlabel = h; |
|
1729 } |
|
1730 } |
|
1731 else if (name.compare ("xgrid")) |
|
1732 xgrid = val; |
|
1733 else if (name.compare ("ygrid")) |
|
1734 ygrid = val; |
|
1735 else if (name.compare ("zgrid")) |
|
1736 zgrid = val; |
|
1737 else if (name.compare ("xminorgrid")) |
|
1738 xminorgrid = val; |
|
1739 else if (name.compare ("yminorgrid")) |
|
1740 yminorgrid = val; |
|
1741 else if (name.compare ("zminorgrid")) |
|
1742 zminorgrid = val; |
|
1743 else if (name.compare ("xtick")) |
|
1744 { |
|
1745 xtick = val; |
|
1746 xtickmode = "manual"; |
|
1747 } |
|
1748 else if (name.compare ("ytick")) |
|
1749 { |
|
1750 ytick = val; |
|
1751 ytickmode = "manual"; |
|
1752 } |
|
1753 else if (name.compare ("ztick")) |
|
1754 { |
|
1755 ztick = val; |
|
1756 ztickmode = "manual"; |
|
1757 } |
|
1758 else if (name.compare ("xtickmode")) |
|
1759 xtickmode = val; |
|
1760 else if (name.compare ("ytickmode")) |
|
1761 ytickmode = val; |
|
1762 else if (name.compare ("ztickmode")) |
|
1763 ztickmode = val; |
|
1764 else if (name.compare ("xticklabel")) |
|
1765 { |
|
1766 xticklabel = val; |
|
1767 xticklabelmode = "manual"; |
|
1768 } |
|
1769 else if (name.compare ("yticklabel")) |
|
1770 { |
|
1771 yticklabel = val; |
|
1772 yticklabelmode = "manual"; |
|
1773 } |
|
1774 else if (name.compare ("zticklabel")) |
|
1775 { |
|
1776 zticklabel = val; |
|
1777 zticklabelmode = "manual"; |
|
1778 } |
|
1779 else if (name.compare ("xticklabelmode")) |
|
1780 xticklabelmode = val; |
|
1781 else if (name.compare ("yticklabelmode")) |
|
1782 yticklabelmode = val; |
|
1783 else if (name.compare ("zticklabelmode")) |
|
1784 zticklabelmode = val; |
|
1785 else if (name.compare ("xscale")) |
|
1786 xscale = val; |
|
1787 else if (name.compare ("yscale")) |
|
1788 yscale = val; |
|
1789 else if (name.compare ("zscale")) |
|
1790 zscale = val; |
|
1791 else if (name.compare ("xdir")) |
|
1792 xdir = val; |
|
1793 else if (name.compare ("ydir")) |
|
1794 ydir = val; |
|
1795 else if (name.compare ("zdir")) |
|
1796 zdir = val; |
|
1797 else if (name.compare ("view")) |
|
1798 view = val; |
|
1799 else if (name.compare ("nextplot")) |
|
1800 nextplot = val; |
|
1801 else if (name.compare ("outerposition")) |
|
1802 outerposition = val; |
|
1803 else |
|
1804 warning ("set: invalid property `%s'", name.c_str ()); |
|
1805 } |
|
1806 |
|
1807 void set_defaults (base_graphics_object& obj, const std::string& mode) |
|
1808 { |
|
1809 position = Matrix (); |
|
1810 title = octave_NaN; |
|
1811 box = "on"; |
|
1812 key = "off"; |
|
1813 keybox = "off"; |
|
1814 keypos = 1; |
|
1815 dataaspectratio = Matrix (1, 3, 1.0); |
|
1816 dataaspectratiomode = "auto"; |
|
1817 |
|
1818 Matrix tlim (1, 2, 0.0); |
|
1819 tlim(1) = 1; |
|
1820 xlim = tlim; |
|
1821 ylim = tlim; |
|
1822 zlim = tlim; |
|
1823 |
|
1824 xlimmode = "auto"; |
|
1825 ylimmode = "auto"; |
|
1826 zlimmode = "auto"; |
|
1827 xlabel = octave_NaN; |
|
1828 ylabel = octave_NaN; |
|
1829 zlabel = octave_NaN; |
|
1830 xgrid = "off"; |
|
1831 ygrid = "off"; |
|
1832 zgrid = "off"; |
|
1833 xminorgrid = "off"; |
|
1834 yminorgrid = "off"; |
|
1835 zminorgrid = "off"; |
|
1836 xtick = Matrix (); |
|
1837 ytick = Matrix (); |
|
1838 ztick = Matrix (); |
|
1839 xtickmode = "auto"; |
|
1840 ytickmode = "auto"; |
|
1841 ztickmode = "auto"; |
|
1842 xticklabel = ""; |
|
1843 yticklabel = ""; |
|
1844 zticklabel = ""; |
|
1845 xticklabelmode = "auto"; |
|
1846 yticklabelmode = "auto"; |
|
1847 zticklabelmode = "auto"; |
|
1848 xscale = "linear"; |
|
1849 yscale = "linear"; |
|
1850 zscale = "linear"; |
|
1851 xdir = "normal"; |
|
1852 ydir = "normal"; |
|
1853 zdir = "normal"; |
|
1854 |
|
1855 Matrix tview (1, 2, 0.0); |
|
1856 tview(1) = 90; |
|
1857 view = tview; |
|
1858 |
|
1859 nextplot = "replace"; |
|
1860 |
|
1861 // FIXME -- this is not quite right; we should preserve |
|
1862 // "position" and "units". |
|
1863 |
6424
|
1864 if (mode != "replace") |
6406
|
1865 { |
|
1866 Matrix touterposition (1, 4, 0.0); |
|
1867 touterposition(2) = 1; |
|
1868 touterposition(3) = 1; |
|
1869 outerposition = touterposition; |
|
1870 } |
|
1871 |
|
1872 delete_children (); |
|
1873 |
|
1874 children = Matrix (); |
|
1875 |
|
1876 override_defaults (obj); |
|
1877 } |
|
1878 |
|
1879 octave_value get (void) const |
|
1880 { |
|
1881 Octave_map m; |
|
1882 |
|
1883 if (xisnan (title)) |
|
1884 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1885 |
|
1886 if (xisnan (xlabel)) |
|
1887 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1888 |
|
1889 if (xisnan (ylabel)) |
|
1890 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1891 |
|
1892 if (xisnan (zlabel)) |
|
1893 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1894 |
|
1895 m.assign ("type", type); |
|
1896 m.assign ("parent", parent); |
|
1897 m.assign ("children", children); |
|
1898 m.assign ("position", position); |
|
1899 m.assign ("title", title); |
|
1900 m.assign ("box", box); |
|
1901 m.assign ("key", key); |
|
1902 m.assign ("keybox", keybox); |
|
1903 m.assign ("keypos", keypos); |
|
1904 m.assign ("dataaspectratio", dataaspectratio); |
|
1905 m.assign ("dataaspectratiomode", dataaspectratiomode); |
|
1906 m.assign ("xlim", xlim); |
|
1907 m.assign ("ylim", ylim); |
|
1908 m.assign ("zlim", zlim); |
|
1909 m.assign ("xlimmode", xlimmode); |
|
1910 m.assign ("ylimmode", ylimmode); |
|
1911 m.assign ("zlimmode", zlimmode); |
|
1912 m.assign ("xlabel", xlabel); |
|
1913 m.assign ("ylabel", ylabel); |
|
1914 m.assign ("zlabel", zlabel); |
|
1915 m.assign ("xgrid", xgrid); |
|
1916 m.assign ("ygrid", ygrid); |
|
1917 m.assign ("zgrid", zgrid); |
|
1918 m.assign ("xminorgrid", xminorgrid); |
|
1919 m.assign ("yminorgrid", yminorgrid); |
|
1920 m.assign ("zminorgrid", zminorgrid); |
|
1921 m.assign ("xtick", xtick); |
|
1922 m.assign ("ytick", ytick); |
|
1923 m.assign ("ztick", ztick); |
|
1924 m.assign ("xtickmode", xtickmode); |
|
1925 m.assign ("ytickmode", ytickmode); |
|
1926 m.assign ("ztickmode", ztickmode); |
|
1927 m.assign ("xticklabel", xticklabel); |
|
1928 m.assign ("yticklabel", yticklabel); |
|
1929 m.assign ("zticklabel", zticklabel); |
|
1930 m.assign ("xticklabelmode", xticklabelmode); |
|
1931 m.assign ("yticklabelmode", yticklabelmode); |
|
1932 m.assign ("zticklabelmode", zticklabelmode); |
|
1933 m.assign ("xscale", xscale); |
|
1934 m.assign ("yscale", yscale); |
|
1935 m.assign ("zscale", zscale); |
|
1936 m.assign ("xdir", xdir); |
|
1937 m.assign ("ydir", ydir); |
|
1938 m.assign ("zdir", zdir); |
|
1939 m.assign ("view", view); |
|
1940 m.assign ("nextplot", nextplot); |
|
1941 m.assign ("outerposition", outerposition); |
|
1942 |
|
1943 return m; |
|
1944 } |
|
1945 |
|
1946 octave_value get (const property_name& name) const |
|
1947 { |
|
1948 octave_value retval; |
|
1949 |
|
1950 if (name.compare ("type")) |
|
1951 retval = type; |
|
1952 else if (name.compare ("parent")) |
|
1953 retval = parent; |
|
1954 else if (name.compare ("children")) |
|
1955 retval = children; |
|
1956 else if (name.compare ("position")) |
|
1957 retval = position; |
|
1958 else if (name.compare ("title")) |
|
1959 { |
|
1960 if (xisnan (title)) |
|
1961 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1962 |
|
1963 retval = title; |
|
1964 } |
|
1965 else if (name.compare ("box")) |
|
1966 retval = box; |
|
1967 else if (name.compare ("key")) |
|
1968 retval = key; |
|
1969 else if (name.compare ("keybox")) |
|
1970 retval = keybox; |
|
1971 else if (name.compare ("keypos")) |
|
1972 retval = keypos; |
|
1973 else if (name.compare ("dataaspectratio")) |
|
1974 retval = dataaspectratio; |
|
1975 else if (name.compare ("dataaspectratiomode")) |
|
1976 retval = dataaspectratiomode; |
|
1977 else if (name.compare ("xlim")) |
|
1978 retval = xlim; |
|
1979 else if (name.compare ("ylim")) |
|
1980 retval = ylim; |
|
1981 else if (name.compare ("zlim")) |
|
1982 retval = zlim; |
|
1983 else if (name.compare ("xlimmode")) |
|
1984 retval = xlimmode; |
|
1985 else if (name.compare ("ylimmode")) |
|
1986 retval = ylimmode; |
|
1987 else if (name.compare ("zlimmode")) |
|
1988 retval = zlimmode; |
|
1989 else if (name.compare ("xlabel")) |
|
1990 { |
|
1991 if (xisnan (xlabel)) |
|
1992 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1993 |
|
1994 retval = xlabel; |
|
1995 } |
|
1996 else if (name.compare ("ylabel")) |
|
1997 { |
|
1998 if (xisnan (ylabel)) |
|
1999 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
2000 |
|
2001 retval = ylabel; |
|
2002 } |
|
2003 else if (name.compare ("zlabel")) |
|
2004 { |
|
2005 if (xisnan (zlabel)) |
|
2006 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
2007 |
|
2008 retval = zlabel; |
|
2009 } |
|
2010 else if (name.compare ("xgrid")) |
|
2011 retval = xgrid; |
|
2012 else if (name.compare ("ygrid")) |
|
2013 retval = ygrid; |
|
2014 else if (name.compare ("zgrid")) |
|
2015 retval = zgrid; |
|
2016 else if (name.compare ("xminorgrid")) |
|
2017 retval = xminorgrid; |
|
2018 else if (name.compare ("yminorgrid")) |
|
2019 retval = yminorgrid; |
|
2020 else if (name.compare ("zminorgrid")) |
|
2021 retval = zminorgrid; |
|
2022 else if (name.compare ("xtick")) |
|
2023 retval = xtick; |
|
2024 else if (name.compare ("ytick")) |
|
2025 retval = ytick; |
|
2026 else if (name.compare ("ztick")) |
|
2027 retval = ztick; |
|
2028 else if (name.compare ("xtickmode")) |
|
2029 retval = xtickmode; |
|
2030 else if (name.compare ("ytickmode")) |
|
2031 retval = ytickmode; |
|
2032 else if (name.compare ("ztickmode")) |
|
2033 retval = ztickmode; |
|
2034 else if (name.compare ("xticklabel")) |
|
2035 retval = xticklabel; |
|
2036 else if (name.compare ("yticklabel")) |
|
2037 retval = yticklabel; |
|
2038 else if (name.compare ("zticklabel")) |
|
2039 retval = zticklabel; |
|
2040 else if (name.compare ("xticklabelmode")) |
|
2041 retval = xticklabelmode; |
|
2042 else if (name.compare ("yticklabelmode")) |
|
2043 retval = yticklabelmode; |
|
2044 else if (name.compare ("zticklabelmode")) |
|
2045 retval = zticklabelmode; |
|
2046 else if (name.compare ("xscale")) |
|
2047 retval = xscale; |
|
2048 else if (name.compare ("yscale")) |
|
2049 retval = yscale; |
|
2050 else if (name.compare ("zscale")) |
|
2051 retval = zscale; |
|
2052 else if (name.compare ("xdir")) |
|
2053 retval = xdir; |
|
2054 else if (name.compare ("ydir")) |
|
2055 retval = ydir; |
|
2056 else if (name.compare ("zdir")) |
|
2057 retval = zdir; |
|
2058 else if (name.compare ("view")) |
|
2059 retval = view; |
|
2060 else if (name.compare ("nextplot")) |
|
2061 retval = nextplot; |
|
2062 else if (name.compare ("outerposition")) |
|
2063 retval = outerposition; |
|
2064 else |
|
2065 warning ("get: invalid property `%s'", name.c_str ()); |
|
2066 |
|
2067 return retval; |
|
2068 } |
|
2069 |
|
2070 void remove_child (const graphics_handle& h) |
|
2071 { |
|
2072 if (! xisnan (title) && h == title) |
|
2073 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
2074 else if (! xisnan (xlabel) && h == xlabel) |
|
2075 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
2076 else if (! xisnan (ylabel) && h == ylabel) |
|
2077 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
2078 else if (! xisnan (zlabel) && h == zlabel) |
|
2079 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
2080 else |
|
2081 base_properties::remove_child (h); |
|
2082 } |
|
2083 |
|
2084 void delete_children (void) |
|
2085 { |
|
2086 base_properties::delete_children (); |
|
2087 |
|
2088 if (! xisnan (title)) |
|
2089 gh_manager::free (title); |
|
2090 |
|
2091 if (! xisnan (xlabel)) |
|
2092 gh_manager::free (xlabel); |
|
2093 |
|
2094 if (! xisnan (ylabel)) |
|
2095 gh_manager::free (ylabel); |
|
2096 |
|
2097 if (! xisnan (zlabel)) |
|
2098 gh_manager::free (zlabel); |
|
2099 } |
|
2100 |
|
2101 std::string graphics_object_name (void) const { return go_name; } |
|
2102 |
|
2103 static property_list::pval_map_type factory_defaults (void) |
|
2104 { |
|
2105 property_list::pval_map_type m; |
|
2106 |
|
2107 m["position"] = Matrix (); |
|
2108 m["title"] = octave_NaN; |
|
2109 m["box"] = "on"; |
|
2110 m["key"] = "off"; |
|
2111 m["keybox"] = "off"; |
|
2112 m["keypos"] = 1; |
|
2113 m["dataaspectratio"] = Matrix (1, 3, 1.0); |
|
2114 m["dataaspectratiomode"] = "auto"; |
|
2115 |
|
2116 Matrix tlim (1, 2, 0.0); |
|
2117 tlim(1) = 1; |
|
2118 |
|
2119 m["xlim"] = tlim; |
|
2120 m["ylim"] = tlim; |
|
2121 m["zlim"] = tlim; |
|
2122 |
|
2123 m["xlimmode"] = "auto"; |
|
2124 m["ylimmode"] = "auto"; |
|
2125 m["zlimmode"] = "auto"; |
|
2126 m["xlabel"] = octave_NaN; |
|
2127 m["ylabel"] = octave_NaN; |
|
2128 m["zlabel"] = octave_NaN; |
|
2129 m["xgrid"] = "off"; |
|
2130 m["ygrid"] = "off"; |
|
2131 m["zgrid"] = "off"; |
|
2132 m["xminorgrid"] = "off"; |
|
2133 m["yminorgrid"] = "off"; |
|
2134 m["zminorgrid"] = "off"; |
|
2135 m["xtick"] = Matrix (); |
|
2136 m["ytick"] = Matrix (); |
|
2137 m["ztick"] = Matrix (); |
|
2138 m["xtickmode"] = "auto"; |
|
2139 m["ytickmode"] = "auto"; |
|
2140 m["ztickmode"] = "auto"; |
|
2141 m["xticklabel"] = ""; |
|
2142 m["yticklabel"] = ""; |
|
2143 m["zticklabel"] = ""; |
|
2144 m["xticklabelmode"] = "auto"; |
|
2145 m["yticklabelmode"] = "auto"; |
|
2146 m["zticklabelmode"] = "auto"; |
|
2147 m["xscale"] = "linear"; |
|
2148 m["yscale"] = "linear"; |
|
2149 m["zscale"] = "linear"; |
|
2150 m["xdir"] = "normal"; |
|
2151 m["ydir"] = "normal"; |
|
2152 m["zdir"] = "normal"; |
|
2153 |
|
2154 Matrix tview (1, 2, 0.0); |
|
2155 tview(1) = 90; |
|
2156 |
|
2157 m["view"] = tview; |
|
2158 |
|
2159 m["nextplot"] = "replace"; |
|
2160 |
|
2161 Matrix touterposition (1, 4, 0.0); |
|
2162 touterposition(2) = 1; |
|
2163 touterposition(3) = 1; |
|
2164 |
|
2165 m["outerposition"] = touterposition; |
|
2166 |
|
2167 return m; |
|
2168 } |
|
2169 |
|
2170 private: |
|
2171 octave_value position; |
|
2172 mutable graphics_handle title; |
|
2173 octave_value box; |
|
2174 octave_value key; |
|
2175 octave_value keybox; |
|
2176 octave_value keypos; |
|
2177 octave_value dataaspectratio; |
|
2178 octave_value dataaspectratiomode; |
|
2179 octave_value xlim; |
|
2180 octave_value ylim; |
|
2181 octave_value zlim; |
|
2182 octave_value xlimmode; |
|
2183 octave_value ylimmode; |
|
2184 octave_value zlimmode; |
|
2185 mutable graphics_handle xlabel; |
|
2186 mutable graphics_handle ylabel; |
|
2187 mutable graphics_handle zlabel; |
|
2188 octave_value xgrid; |
|
2189 octave_value ygrid; |
|
2190 octave_value zgrid; |
|
2191 octave_value xminorgrid; |
|
2192 octave_value yminorgrid; |
|
2193 octave_value zminorgrid; |
|
2194 octave_value xtick; |
|
2195 octave_value ytick; |
|
2196 octave_value ztick; |
|
2197 octave_value xtickmode; |
|
2198 octave_value ytickmode; |
|
2199 octave_value ztickmode; |
|
2200 octave_value xticklabel; |
|
2201 octave_value yticklabel; |
|
2202 octave_value zticklabel; |
|
2203 octave_value xticklabelmode; |
|
2204 octave_value yticklabelmode; |
|
2205 octave_value zticklabelmode; |
|
2206 octave_value xscale; |
|
2207 octave_value yscale; |
|
2208 octave_value zscale; |
|
2209 octave_value xdir; |
|
2210 octave_value ydir; |
|
2211 octave_value zdir; |
|
2212 octave_value view; |
|
2213 octave_value nextplot; |
|
2214 octave_value outerposition; |
|
2215 |
|
2216 static std::string go_name; |
|
2217 }; |
|
2218 |
|
2219 axes_properties properties; |
|
2220 |
|
2221 public: |
|
2222 axes (const graphics_handle& mh, const graphics_handle& p) |
|
2223 : base_graphics_object (), properties (mh, p), default_properties () |
|
2224 { |
|
2225 properties.override_defaults (*this); |
|
2226 } |
|
2227 |
|
2228 ~axes (void) { properties.delete_children (); } |
|
2229 |
|
2230 std::string type (void) const { return properties.graphics_object_name (); } |
|
2231 |
|
2232 void override_defaults (base_graphics_object& obj) |
|
2233 { |
|
2234 // Allow parent (figure) to override first (properties knows how |
|
2235 // to find the parent object). |
|
2236 properties.override_defaults (obj); |
|
2237 |
|
2238 // Now override with our defaults. If the default_properties |
|
2239 // list includes the properties for all defaults (line, |
|
2240 // surface, etc.) then we don't have to know the type of OBJ |
|
2241 // here, we just call its set function and let it decide which |
|
2242 // properties from the list to use. |
|
2243 obj.set_from_list (default_properties); |
|
2244 } |
|
2245 |
|
2246 void set_from_list (property_list& plist) |
|
2247 { |
|
2248 properties.set_from_list (*this, plist); |
|
2249 } |
|
2250 |
|
2251 void set (const property_name& name, const octave_value& value) |
|
2252 { |
|
2253 if (name.compare ("default", 7)) |
|
2254 // strip "default", pass rest to function that will |
|
2255 // parse the remainder and add the element to the |
|
2256 // default_properties map. |
|
2257 default_properties.set (name.substr (7), value); |
|
2258 else |
|
2259 properties.set (name, value); |
|
2260 } |
|
2261 |
|
2262 void set_defaults (const std::string& mode) |
|
2263 { |
|
2264 properties.set_defaults (*this, mode); |
|
2265 } |
|
2266 |
|
2267 octave_value get (void) const |
|
2268 { |
|
2269 return properties.get (); |
|
2270 } |
|
2271 |
|
2272 octave_value get (const property_name& name) const |
|
2273 { |
|
2274 octave_value retval; |
|
2275 |
|
2276 // FIXME -- finish this. |
|
2277 if (name.compare ("default", 7)) |
|
2278 retval = get_default (name.substr (7)); |
|
2279 else |
|
2280 retval = properties.get (name); |
|
2281 |
|
2282 return retval; |
|
2283 } |
|
2284 |
|
2285 octave_value get_default (const property_name& name) const |
|
2286 { |
|
2287 octave_value retval = default_properties.lookup (name); |
|
2288 |
|
2289 if (retval.is_undefined ()) |
|
2290 { |
|
2291 graphics_handle parent = get_parent (); |
|
2292 graphics_object parent_obj = gh_manager::get_object (parent); |
|
2293 |
|
2294 retval = parent_obj.get_default (name); |
|
2295 } |
|
2296 |
|
2297 return retval; |
|
2298 } |
|
2299 |
|
2300 octave_value get_defaults (void) const |
|
2301 { |
|
2302 return default_properties.as_struct ("default"); |
|
2303 } |
|
2304 |
|
2305 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
2306 |
|
2307 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
2308 |
|
2309 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
2310 |
|
2311 void reparent (const graphics_handle& np) { properties.reparent (np); } |
|
2312 |
|
2313 bool valid_object (void) const { return true; } |
|
2314 |
|
2315 private: |
|
2316 property_list default_properties; |
|
2317 }; |
|
2318 |
|
2319 std::string axes::axes_properties::go_name ("axes"); |
|
2320 |
|
2321 // --------------------------------------------------------------------- |
|
2322 |
|
2323 static Matrix |
|
2324 default_data (void) |
|
2325 { |
|
2326 Matrix retval (1, 2); |
|
2327 |
|
2328 retval(0) = 0; |
|
2329 retval(1) = 1; |
|
2330 |
|
2331 return retval; |
|
2332 } |
|
2333 |
|
2334 class line : public base_graphics_object |
|
2335 { |
|
2336 public: |
|
2337 class line_properties : public base_properties |
|
2338 { |
|
2339 public: |
|
2340 line_properties (const graphics_handle& mh, const graphics_handle& p) |
|
2341 : base_properties (go_name, mh, p), |
|
2342 xdata (default_data ()), |
|
2343 ydata (default_data ()), |
|
2344 zdata (Matrix ()), |
|
2345 ldata (Matrix ()), |
|
2346 udata (Matrix ()), |
|
2347 xldata (Matrix ()), |
|
2348 xudata (Matrix ()), |
|
2349 color (), |
|
2350 linestyle ("-"), |
|
2351 linewidth (0.5), |
|
2352 marker ("none"), |
|
2353 markersize (1), |
|
2354 keylabel ("") { } |
|
2355 |
|
2356 ~line_properties (void) { } |
|
2357 |
|
2358 void set (const property_name& name, const octave_value& val) |
|
2359 { |
|
2360 if (name.compare ("parent")) |
|
2361 set_parent (val); |
|
2362 else if (name.compare ("children")) |
|
2363 children = maybe_set_children (children, val); |
|
2364 else if (name.compare ("xdata")) |
|
2365 xdata = val; |
|
2366 else if (name.compare ("ydata")) |
|
2367 ydata = val; |
|
2368 else if (name.compare ("zdata")) |
|
2369 zdata = val; |
|
2370 else if (name.compare ("ldata")) |
|
2371 ldata = val; |
|
2372 else if (name.compare ("udata")) |
|
2373 udata = val; |
|
2374 else if (name.compare ("xldata")) |
|
2375 xldata = val; |
|
2376 else if (name.compare ("xudata")) |
|
2377 xudata = val; |
|
2378 else if (name.compare ("color")) |
|
2379 color = color_property (val); |
|
2380 else if (name.compare ("linestyle")) |
|
2381 linestyle = val; |
|
2382 else if (name.compare ("linewidth")) |
|
2383 linewidth = val; |
|
2384 else if (name.compare ("marker")) |
|
2385 marker = val; |
|
2386 else if (name.compare ("markersize")) |
|
2387 markersize = val; |
|
2388 else if (name.compare ("keylabel")) |
|
2389 keylabel = val; |
|
2390 else |
|
2391 warning ("set: invalid property `%s'", name.c_str ()); |
|
2392 } |
|
2393 |
|
2394 octave_value get (void) const |
|
2395 { |
|
2396 Octave_map m; |
|
2397 |
|
2398 m.assign ("type", type); |
|
2399 m.assign ("parent", parent); |
|
2400 m.assign ("children", children); |
|
2401 m.assign ("xdata", xdata); |
|
2402 m.assign ("ydata", ydata); |
|
2403 m.assign ("zdata", zdata); |
|
2404 m.assign ("ldata", ldata); |
|
2405 m.assign ("udata", udata); |
|
2406 m.assign ("xldata", xldata); |
|
2407 m.assign ("xudata", xudata); |
|
2408 m.assign ("color", color); |
|
2409 m.assign ("linestyle", linestyle); |
|
2410 m.assign ("linewidth", linewidth); |
|
2411 m.assign ("marker", marker); |
|
2412 m.assign ("markersize", markersize); |
|
2413 m.assign ("keylabel", keylabel); |
|
2414 |
|
2415 return m; |
|
2416 } |
|
2417 |
|
2418 octave_value get (const property_name& name) const |
|
2419 { |
|
2420 octave_value retval; |
|
2421 |
|
2422 if (name.compare ("type")) |
|
2423 retval = type; |
|
2424 else if (name.compare ("parent")) |
|
2425 retval = parent; |
|
2426 else if (name.compare ("children")) |
|
2427 retval = children; |
|
2428 else if (name.compare ("xdata")) |
|
2429 retval = xdata; |
|
2430 else if (name.compare ("ydata")) |
|
2431 retval = ydata; |
|
2432 else if (name.compare ("zdata")) |
|
2433 retval = zdata; |
|
2434 else if (name.compare ("ldata")) |
|
2435 retval = ldata; |
|
2436 else if (name.compare ("udata")) |
|
2437 retval = udata; |
|
2438 else if (name.compare ("xldata")) |
|
2439 retval = xldata; |
|
2440 else if (name.compare ("xudata")) |
|
2441 retval = xudata; |
|
2442 else if (name.compare ("color")) |
|
2443 retval = color; |
|
2444 else if (name.compare ("linestyle")) |
|
2445 retval = linestyle; |
|
2446 else if (name.compare ("linewidth")) |
|
2447 retval = linewidth; |
|
2448 else if (name.compare ("marker")) |
|
2449 retval = marker; |
|
2450 else if (name.compare ("markersize")) |
|
2451 retval = markersize; |
|
2452 else if (name.compare ("keylabel")) |
|
2453 retval = keylabel; |
|
2454 else |
|
2455 warning ("get: invalid property `%s'", name.c_str ()); |
|
2456 |
|
2457 return retval; |
|
2458 } |
|
2459 |
|
2460 std::string graphics_object_name (void) const { return go_name; } |
|
2461 |
|
2462 static property_list::pval_map_type factory_defaults (void) |
|
2463 { |
|
2464 property_list::pval_map_type m; |
|
2465 |
|
2466 m["xdata"] = default_data (); |
|
2467 m["ydata"] = default_data (); |
|
2468 m["zdata"] = Matrix (); |
|
2469 m["ldata"] = Matrix (); |
|
2470 m["udata"] = Matrix (); |
|
2471 m["xldata"] = Matrix (); |
|
2472 m["xudata"] = Matrix (); |
|
2473 m["color"] = color_property (); |
|
2474 m["linestyle"] = "-"; |
|
2475 m["linewidth"] = 0.5; |
|
2476 m["marker"] = "none"; |
|
2477 m["markersize"] = 1; |
|
2478 m["keylabel"] = ""; |
|
2479 |
|
2480 return m; |
|
2481 } |
|
2482 |
|
2483 private: |
|
2484 octave_value xdata; |
|
2485 octave_value ydata; |
|
2486 octave_value zdata; |
|
2487 octave_value ldata; |
|
2488 octave_value udata; |
|
2489 octave_value xldata; |
|
2490 octave_value xudata; |
|
2491 color_property color; |
|
2492 octave_value linestyle; |
|
2493 octave_value linewidth; |
|
2494 octave_value marker; |
|
2495 octave_value markersize; |
|
2496 octave_value keylabel; |
|
2497 |
|
2498 static std::string go_name; |
|
2499 }; |
|
2500 |
|
2501 line_properties properties; |
|
2502 |
|
2503 public: |
|
2504 line (const graphics_handle& mh, const graphics_handle& p) |
|
2505 : base_graphics_object (), properties (mh, p) |
|
2506 { |
|
2507 properties.override_defaults (*this); |
|
2508 } |
|
2509 |
|
2510 ~line (void) { properties.delete_children (); } |
|
2511 |
|
2512 std::string type (void) const { return properties.graphics_object_name (); } |
|
2513 |
|
2514 void override_defaults (base_graphics_object& obj) |
|
2515 { |
|
2516 // Allow parent (figure) to override first (properties knows how |
|
2517 // to find the parent object). |
|
2518 properties.override_defaults (obj); |
|
2519 } |
|
2520 |
|
2521 void set_from_list (property_list& plist) |
|
2522 { |
|
2523 properties.set_from_list (*this, plist); |
|
2524 } |
|
2525 |
|
2526 void set (const property_name& name, const octave_value& val) |
|
2527 { |
|
2528 properties.set (name, val); |
|
2529 } |
|
2530 |
|
2531 octave_value get (void) const |
|
2532 { |
|
2533 return properties.get (); |
|
2534 } |
|
2535 |
|
2536 octave_value get (const property_name& name) const |
|
2537 { |
|
2538 return properties.get (name); |
|
2539 } |
|
2540 |
|
2541 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
2542 |
|
2543 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
2544 |
|
2545 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
2546 |
|
2547 void reparent (const graphics_handle& h) { properties.reparent (h); } |
|
2548 |
|
2549 bool valid_object (void) const { return true; } |
|
2550 }; |
|
2551 |
|
2552 std::string line::line_properties::go_name ("line"); |
|
2553 |
|
2554 // --------------------------------------------------------------------- |
|
2555 |
|
2556 class text : public base_graphics_object |
|
2557 { |
|
2558 public: |
|
2559 class text_properties : public base_properties |
|
2560 { |
|
2561 public: |
|
2562 text_properties (const graphics_handle& mh, const graphics_handle& p) |
|
2563 : base_properties (go_name, mh, p), |
|
2564 string (""), |
|
2565 units ("data"), |
|
2566 position (Matrix (1, 3, 0.0)), |
|
2567 horizontalalignment ("left") |
|
2568 { } |
|
2569 |
|
2570 ~text_properties (void) { } |
|
2571 |
|
2572 void set (const property_name& name, const octave_value& val) |
|
2573 { |
|
2574 if (name.compare ("parent")) |
|
2575 set_parent (val); |
|
2576 else if (name.compare ("children")) |
|
2577 children = maybe_set_children (children, val); |
|
2578 else if (name.compare ("string")) |
|
2579 string = val; |
|
2580 else if (name.compare ("units")) |
|
2581 units = val; |
|
2582 else if (name.compare ("position")) |
|
2583 position = val; |
|
2584 else if (name.compare ("horizontalalignment")) |
|
2585 horizontalalignment = val; |
|
2586 else |
|
2587 warning ("set: invalid property `%s'", name.c_str ()); |
|
2588 } |
|
2589 |
|
2590 octave_value get (void) const |
|
2591 { |
|
2592 Octave_map m; |
|
2593 |
|
2594 m.assign ("type", type); |
|
2595 m.assign ("parent", parent); |
|
2596 m.assign ("children", children); |
|
2597 m.assign ("string", string); |
|
2598 m.assign ("units", units); |
|
2599 m.assign ("position", position); |
|
2600 m.assign ("horizontalalignment", horizontalalignment); |
|
2601 |
|
2602 return m; |
|
2603 } |
|
2604 |
|
2605 octave_value get (const property_name& name) const |
|
2606 { |
|
2607 octave_value retval; |
|
2608 |
|
2609 if (name.compare ("type")) |
|
2610 retval = type; |
|
2611 else if (name.compare ("parent")) |
|
2612 retval = parent; |
|
2613 else if (name.compare ("children")) |
|
2614 retval = children; |
|
2615 else if (name.compare ("string")) |
|
2616 retval = string; |
|
2617 else if (name.compare ("units")) |
|
2618 retval = units; |
|
2619 else if (name.compare ("position")) |
|
2620 retval = position; |
|
2621 else if (name.compare ("horizontalalignment")) |
|
2622 retval = horizontalalignment; |
|
2623 else |
|
2624 warning ("get: invalid property `%s'", name.c_str ()); |
|
2625 |
|
2626 return retval; |
|
2627 } |
|
2628 |
|
2629 std::string graphics_object_name (void) const { return go_name; } |
|
2630 |
|
2631 static property_list::pval_map_type factory_defaults (void) |
|
2632 { |
|
2633 property_list::pval_map_type m; |
|
2634 |
|
2635 m["string"] = ""; |
|
2636 m["units"] = "data"; |
|
2637 m["position"] = Matrix (1, 3, 0.0); |
|
2638 m["horizontalalignment"] = "left"; |
|
2639 |
|
2640 return m; |
|
2641 } |
|
2642 |
|
2643 private: |
|
2644 octave_value string; |
|
2645 octave_value units; |
|
2646 octave_value position; |
|
2647 octave_value horizontalalignment; |
|
2648 |
|
2649 static std::string go_name; |
|
2650 }; |
|
2651 |
|
2652 text_properties properties; |
|
2653 |
|
2654 public: |
|
2655 text (const graphics_handle& mh, const graphics_handle& p) |
|
2656 : base_graphics_object (), properties (mh, p) |
|
2657 { |
|
2658 properties.override_defaults (*this); |
|
2659 } |
|
2660 |
|
2661 ~text (void) { properties.delete_children (); } |
|
2662 |
|
2663 std::string type (void) const { return properties.graphics_object_name (); } |
|
2664 |
|
2665 void override_defaults (base_graphics_object& obj) |
|
2666 { |
|
2667 // Allow parent (figure) to override first (properties knows how |
|
2668 // to find the parent object). |
|
2669 properties.override_defaults (obj); |
|
2670 } |
|
2671 |
|
2672 void set_from_list (property_list& plist) |
|
2673 { |
|
2674 properties.set_from_list (*this, plist); |
|
2675 } |
|
2676 |
|
2677 void set (const property_name& name, const octave_value& val) |
|
2678 { |
|
2679 properties.set (name, val); |
|
2680 } |
|
2681 |
|
2682 octave_value get (void) const |
|
2683 { |
|
2684 return properties.get (); |
|
2685 } |
|
2686 |
|
2687 octave_value get (const property_name& name) const |
|
2688 { |
|
2689 return properties.get (name); |
|
2690 } |
|
2691 |
|
2692 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
2693 |
|
2694 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
2695 |
|
2696 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
2697 |
|
2698 void reparent (const graphics_handle& h) { properties.reparent (h); } |
|
2699 |
|
2700 bool valid_object (void) const { return true; } |
|
2701 }; |
|
2702 |
|
2703 std::string text::text_properties::go_name ("text"); |
|
2704 |
|
2705 // --------------------------------------------------------------------- |
|
2706 |
|
2707 class image : public base_graphics_object |
|
2708 { |
|
2709 public: |
|
2710 class image_properties : public base_properties |
|
2711 { |
|
2712 public: |
|
2713 image_properties (const graphics_handle& mh, const graphics_handle& p) |
|
2714 : base_properties (go_name, mh, p), |
|
2715 cdata (Matrix ()), |
|
2716 xdata (Matrix ()), |
|
2717 ydata (Matrix ()) |
|
2718 { } |
|
2719 |
|
2720 ~image_properties (void) { } |
|
2721 |
|
2722 void set (const property_name& name, const octave_value& val) |
|
2723 { |
|
2724 if (name.compare ("parent")) |
|
2725 set_parent (val); |
|
2726 else if (name.compare ("children")) |
|
2727 children = maybe_set_children (children, val); |
|
2728 else if (name.compare ("cdata")) |
|
2729 cdata = val; |
|
2730 else if (name.compare ("xdata")) |
|
2731 xdata = val; |
|
2732 else if (name.compare ("ydata")) |
|
2733 ydata = val; |
|
2734 else |
|
2735 warning ("set: invalid property `%s'", name.c_str ()); |
|
2736 } |
|
2737 |
|
2738 octave_value get (void) const |
|
2739 { |
|
2740 Octave_map m; |
|
2741 |
|
2742 m.assign ("type", type); |
|
2743 m.assign ("parent", parent); |
|
2744 m.assign ("children", children); |
|
2745 m.assign ("cdata", cdata); |
|
2746 m.assign ("xdata", xdata); |
|
2747 m.assign ("ydata", ydata); |
|
2748 |
|
2749 return m; |
|
2750 } |
|
2751 |
|
2752 octave_value get (const property_name& name) const |
|
2753 { |
|
2754 octave_value retval; |
|
2755 |
|
2756 if (name.compare ("type")) |
|
2757 retval = type; |
|
2758 else if (name.compare ("parent")) |
|
2759 retval = parent; |
|
2760 else if (name.compare ("children")) |
|
2761 retval = children; |
|
2762 else if (name.compare ("cdata")) |
|
2763 retval = cdata; |
|
2764 else if (name.compare ("xdata")) |
|
2765 retval = xdata; |
|
2766 else if (name.compare ("ydata")) |
|
2767 retval = ydata; |
|
2768 else |
|
2769 warning ("get: invalid property `%s'", name.c_str ()); |
|
2770 |
|
2771 return retval; |
|
2772 } |
|
2773 |
|
2774 std::string graphics_object_name (void) const { return go_name; } |
|
2775 |
|
2776 static property_list::pval_map_type factory_defaults (void) |
|
2777 { |
|
2778 property_list::pval_map_type m; |
|
2779 |
|
2780 m["cdata"] = Matrix (); |
|
2781 m["xdata"] = Matrix (); |
|
2782 m["ydata"] = Matrix (); |
|
2783 |
|
2784 return m; |
|
2785 } |
|
2786 |
|
2787 private: |
|
2788 octave_value cdata; |
|
2789 octave_value xdata; |
|
2790 octave_value ydata; |
|
2791 |
|
2792 static std::string go_name; |
|
2793 }; |
|
2794 |
|
2795 image_properties properties; |
|
2796 |
|
2797 public: |
|
2798 image (const graphics_handle& mh, const graphics_handle& p) |
|
2799 : base_graphics_object (), properties (mh, p) |
|
2800 { |
|
2801 properties.override_defaults (*this); |
|
2802 } |
|
2803 |
|
2804 ~image (void) { properties.delete_children (); } |
|
2805 |
|
2806 std::string type (void) const { return properties.graphics_object_name (); } |
|
2807 |
|
2808 void override_defaults (base_graphics_object& obj) |
|
2809 { |
|
2810 // Allow parent (figure) to override first (properties knows how |
|
2811 // to find the parent object). |
|
2812 properties.override_defaults (obj); |
|
2813 } |
|
2814 |
|
2815 void set_from_list (property_list& plist) |
|
2816 { |
|
2817 properties.set_from_list (*this, plist); |
|
2818 } |
|
2819 |
|
2820 void set (const property_name& name, const octave_value& val) |
|
2821 { |
|
2822 properties.set (name, val); |
|
2823 } |
|
2824 |
|
2825 octave_value get (void) const |
|
2826 { |
|
2827 return properties.get (); |
|
2828 } |
|
2829 |
|
2830 octave_value get (const property_name& name) const |
|
2831 { |
|
2832 return properties.get (name); |
|
2833 } |
|
2834 |
|
2835 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
2836 |
|
2837 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
2838 |
|
2839 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
2840 |
|
2841 void reparent (const graphics_handle& h) { properties.reparent (h); } |
|
2842 |
|
2843 bool valid_object (void) const { return true; } |
|
2844 }; |
|
2845 |
|
2846 std::string image::image_properties::go_name ("image"); |
|
2847 |
|
2848 // --------------------------------------------------------------------- |
|
2849 |
|
2850 class surface : public base_graphics_object |
|
2851 { |
|
2852 public: |
|
2853 class surface_properties : public base_properties |
|
2854 { |
|
2855 public: |
|
2856 surface_properties (const graphics_handle& mh, const graphics_handle& p) |
|
2857 : base_properties (go_name, mh, p), |
|
2858 xdata (Matrix ()), |
|
2859 ydata (Matrix ()), |
|
2860 zdata (Matrix ()), |
|
2861 keylabel ("") |
|
2862 { } |
|
2863 |
|
2864 ~surface_properties (void) { } |
|
2865 |
|
2866 void set (const property_name& name, const octave_value& val) |
|
2867 { |
|
2868 if (name.compare ("parent")) |
|
2869 set_parent (val); |
|
2870 else if (name.compare ("children")) |
|
2871 children = maybe_set_children (children, val); |
|
2872 else if (name.compare ("xdata")) |
|
2873 xdata = val; |
|
2874 else if (name.compare ("ydata")) |
|
2875 ydata = val; |
|
2876 else if (name.compare ("zdata")) |
|
2877 zdata = val; |
|
2878 else if (name.compare ("keylabel")) |
|
2879 keylabel = val; |
|
2880 else |
|
2881 warning ("set: invalid property `%s'", name.c_str ()); |
|
2882 } |
|
2883 |
|
2884 octave_value get (void) const |
|
2885 { |
|
2886 Octave_map m; |
|
2887 |
|
2888 m.assign ("type", type); |
|
2889 m.assign ("parent", parent); |
|
2890 m.assign ("children", children); |
|
2891 m.assign ("xdata", xdata); |
|
2892 m.assign ("ydata", ydata); |
|
2893 m.assign ("zdata", zdata); |
|
2894 m.assign ("keylabel", keylabel); |
|
2895 |
|
2896 return m; |
|
2897 } |
|
2898 |
|
2899 octave_value get (const property_name& name) const |
|
2900 { |
|
2901 octave_value retval; |
|
2902 |
|
2903 if (name.compare ("type")) |
|
2904 retval = type; |
|
2905 else if (name.compare ("parent")) |
|
2906 retval = parent; |
|
2907 else if (name.compare ("children")) |
|
2908 retval = children; |
|
2909 else if (name.compare ("xdata")) |
|
2910 retval = xdata; |
|
2911 else if (name.compare ("ydata")) |
|
2912 retval = ydata; |
|
2913 else if (name.compare ("zdata")) |
|
2914 retval = zdata; |
|
2915 else if (name.compare ("keylabel")) |
|
2916 retval = keylabel; |
|
2917 else |
|
2918 warning ("get: invalid property `%s'", name.c_str ()); |
|
2919 |
|
2920 return retval; |
|
2921 } |
|
2922 |
|
2923 std::string graphics_object_name (void) const { return go_name; } |
|
2924 |
|
2925 static property_list::pval_map_type factory_defaults (void) |
|
2926 { |
|
2927 property_list::pval_map_type m; |
|
2928 |
|
2929 m["xdata"] = Matrix (); |
|
2930 m["ydata"] = Matrix (); |
|
2931 m["zdata"] = Matrix (); |
|
2932 m["keylabel"] = ""; |
|
2933 |
|
2934 return m; |
|
2935 } |
|
2936 |
|
2937 private: |
|
2938 octave_value xdata; |
|
2939 octave_value ydata; |
|
2940 octave_value zdata; |
|
2941 octave_value keylabel; |
|
2942 |
|
2943 static std::string go_name; |
|
2944 }; |
|
2945 |
|
2946 surface_properties properties; |
|
2947 |
|
2948 public: |
|
2949 surface (const graphics_handle& mh, const graphics_handle& p) |
|
2950 : base_graphics_object (), properties (mh, p) |
|
2951 { |
|
2952 properties.override_defaults (*this); |
|
2953 } |
|
2954 |
|
2955 ~surface (void) { properties.delete_children (); } |
|
2956 |
|
2957 std::string type (void) const { return properties.graphics_object_name (); } |
|
2958 |
|
2959 void override_defaults (base_graphics_object& obj) |
|
2960 { |
|
2961 // Allow parent (figure) to override first (properties knows how |
|
2962 // to find the parent object). |
|
2963 properties.override_defaults (obj); |
|
2964 } |
|
2965 |
|
2966 void set_from_list (property_list& plist) |
|
2967 { |
|
2968 properties.set_from_list (*this, plist); |
|
2969 } |
|
2970 |
|
2971 void set (const property_name& name, const octave_value& val) |
|
2972 { |
|
2973 properties.set (name, val); |
|
2974 } |
|
2975 |
|
2976 octave_value get (void) const |
|
2977 { |
|
2978 return properties.get (); |
|
2979 } |
|
2980 |
|
2981 octave_value get (const property_name& name) const |
|
2982 { |
|
2983 return properties.get (name); |
|
2984 } |
|
2985 |
|
2986 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
2987 |
|
2988 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
2989 |
|
2990 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
2991 |
|
2992 void reparent (const graphics_handle& h) { properties.reparent (h); } |
|
2993 |
|
2994 bool valid_object (void) const { return true; } |
|
2995 }; |
|
2996 |
|
2997 std::string surface::surface_properties::go_name ("surface"); |
|
2998 |
|
2999 // --------------------------------------------------------------------- |
|
3000 |
|
3001 octave_value |
|
3002 base_graphics_object::get_default (const property_name& name) const |
|
3003 { |
|
3004 graphics_handle parent = get_parent (); |
|
3005 graphics_object parent_obj = gh_manager::get_object (parent); |
|
3006 |
|
3007 return parent_obj.get_default (type () + name); |
|
3008 } |
|
3009 |
|
3010 octave_value |
|
3011 base_graphics_object::get_factory_default (const property_name& name) const |
|
3012 { |
|
3013 graphics_object parent_obj = gh_manager::get_object (0); |
|
3014 |
|
3015 return parent_obj.get_factory_default (type () + name); |
|
3016 } |
|
3017 |
|
3018 gh_manager::gh_manager (void) |
|
3019 : handle_map (), handle_free_list (), next_handle (-1) |
|
3020 { |
|
3021 handle_map[0] = graphics_object (new root_figure ()); |
|
3022 } |
|
3023 |
|
3024 graphics_handle |
|
3025 gh_manager::do_make_graphics_handle (const std::string& go_name, |
|
3026 const graphics_handle& p) |
|
3027 { |
|
3028 graphics_handle h = get_handle (go_name); |
|
3029 |
|
3030 base_graphics_object *go = 0; |
|
3031 |
|
3032 if (go_name == "figure") |
|
3033 go = new figure (h, p); |
|
3034 else if (go_name == "axes") |
|
3035 go = new axes (h, p); |
|
3036 else if (go_name == "line") |
|
3037 go = new line (h, p); |
|
3038 else if (go_name == "text") |
|
3039 go = new text (h, p); |
|
3040 else if (go_name == "image") |
|
3041 go = new image (h, p); |
|
3042 else if (go_name == "surface") |
|
3043 go = new surface (h, p); |
|
3044 |
|
3045 if (go) |
|
3046 handle_map[h] = graphics_object (go); |
|
3047 else |
|
3048 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
|
3049 go_name.c_str ()); |
|
3050 |
|
3051 return h; |
|
3052 } |
|
3053 |
|
3054 graphics_handle |
|
3055 gh_manager::do_make_figure_handle (double val) |
|
3056 { |
|
3057 graphics_handle h = val; |
|
3058 |
|
3059 handle_map[h] = graphics_object (new figure (h, 0)); |
|
3060 |
|
3061 return h; |
|
3062 } |
|
3063 |
|
3064 void |
|
3065 gh_manager::do_push_figure (const graphics_handle& h) |
|
3066 { |
|
3067 do_pop_figure (h); |
|
3068 |
|
3069 figure_list.push_front (h); |
|
3070 } |
|
3071 |
|
3072 void |
|
3073 gh_manager::do_pop_figure (const graphics_handle& h) |
|
3074 { |
|
3075 for (figure_list_iterator p = figure_list.begin (); |
|
3076 p != figure_list.end (); |
|
3077 p++) |
|
3078 { |
|
3079 if (*p == h) |
|
3080 { |
|
3081 figure_list.erase (p); |
|
3082 break; |
|
3083 } |
|
3084 } |
|
3085 } |
|
3086 |
|
3087 property_list::plist_map_type |
|
3088 root_figure::init_factory_properties (void) |
|
3089 { |
|
3090 property_list::plist_map_type plist_map; |
|
3091 |
|
3092 plist_map["figure"] = figure::figure_properties::factory_defaults (); |
|
3093 plist_map["axes"] = axes::axes_properties::factory_defaults (); |
|
3094 plist_map["line"] = line::line_properties::factory_defaults (); |
|
3095 plist_map["text"] = text::text_properties::factory_defaults (); |
|
3096 plist_map["image"] = image::image_properties::factory_defaults (); |
|
3097 plist_map["surface"] = surface::surface_properties::factory_defaults (); |
|
3098 |
|
3099 return plist_map; |
|
3100 } |
|
3101 |
|
3102 // --------------------------------------------------------------------- |
|
3103 |
|
3104 DEFUN (ishandle, args, , |
|
3105 "-*- texinfo -*-\n\ |
|
3106 @deftypefn {Function File} {} ishandle (@var{h})\n\ |
|
3107 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
|
3108 @end deftypefn") |
|
3109 { |
|
3110 octave_value retval; |
|
3111 |
|
3112 if (args.length () == 1) |
|
3113 retval = is_handle (args(0)); |
|
3114 else |
|
3115 print_usage (); |
|
3116 |
|
3117 return retval; |
|
3118 } |
|
3119 |
|
3120 DEFUN (set, args, , |
|
3121 "-*- texinfo -*-\n\ |
|
3122 @deftypefn {Function File} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
|
3123 Set the named property @var{p} to the value @var{v} in the graphics\n\ |
|
3124 handle @var{h}.\n\ |
|
3125 @end deftypefn") |
|
3126 { |
|
3127 octave_value retval; |
|
3128 |
|
3129 int nargin = args.length (); |
|
3130 |
|
3131 if (nargin > 0) |
|
3132 { |
|
3133 double handle = args(0).double_value (); |
|
3134 |
|
3135 if (! error_state) |
|
3136 { |
|
3137 graphics_object obj = gh_manager::get_object (handle); |
|
3138 |
|
3139 if (obj) |
|
3140 { |
|
3141 obj.set (args.splice (0, 1)); |
|
3142 |
|
3143 feval ("__request_drawnow__"); |
|
3144 } |
|
3145 else |
|
3146 error ("set: invalid handle (= %g)", handle); |
|
3147 } |
|
3148 else |
|
3149 error ("set: expecting graphics handle as first argument"); |
|
3150 } |
|
3151 else |
|
3152 print_usage (); |
|
3153 |
|
3154 return retval; |
|
3155 } |
|
3156 |
|
3157 DEFUN (get, args, , |
|
3158 "-*- texinfo -*-\n\ |
|
3159 @deftypefn {Function File} {} get (@var{h}, @var{p})\n\ |
|
3160 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
|
3161 If @var{p} is omitted, return the complete property list for @var{h}.\n\ |
|
3162 @end deftypefn") |
|
3163 { |
|
3164 octave_value retval; |
|
3165 |
|
3166 int nargin = args.length (); |
|
3167 |
|
3168 if (nargin == 1 || nargin == 2) |
|
3169 { |
|
3170 double handle = args(0).double_value (); |
|
3171 |
|
3172 if (! error_state) |
|
3173 { |
|
3174 graphics_object obj = gh_manager::get_object (handle); |
|
3175 |
|
3176 if (obj) |
|
3177 { |
|
3178 if (nargin == 1) |
|
3179 retval = obj.get (); |
|
3180 else |
|
3181 { |
|
3182 property_name property = args(1).string_value (); |
|
3183 |
|
3184 if (! error_state) |
|
3185 retval = obj.get (property); |
|
3186 else |
|
3187 error ("get: expecting property name as second argument"); |
|
3188 } |
|
3189 } |
|
3190 else |
|
3191 error ("get: invalid handle (= %g)", handle); |
|
3192 } |
|
3193 else |
|
3194 error ("get: expecting graphics handle as first argument"); |
|
3195 } |
|
3196 else |
|
3197 print_usage (); |
|
3198 |
|
3199 return retval; |
|
3200 } |
|
3201 |
|
3202 static octave_value |
|
3203 make_graphics_object (const std::string& go_name, |
|
3204 const octave_value_list& args) |
|
3205 { |
|
3206 octave_value retval; |
|
3207 |
|
3208 double val = args(0).double_value (); |
|
3209 |
|
3210 if (! error_state) |
|
3211 { |
|
3212 graphics_handle parent = gh_manager::lookup (val); |
|
3213 |
|
3214 if (! xisnan (parent)) |
|
3215 { |
|
3216 graphics_handle h |
|
3217 = gh_manager::make_graphics_handle (go_name, parent); |
|
3218 |
|
3219 if (! error_state) |
|
3220 { |
|
3221 adopt (parent, h); |
|
3222 |
|
3223 xset (h, args.splice (0, 1)); |
|
3224 |
|
3225 retval = h; |
|
3226 } |
|
3227 else |
|
3228 error ("__go%s__: unable to create graphics handle", |
|
3229 go_name.c_str ()); |
|
3230 } |
|
3231 else |
|
3232 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
3233 } |
|
3234 else |
|
3235 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
3236 |
|
3237 return retval; |
|
3238 } |
|
3239 |
|
3240 DEFUN (__go_figure__, args, , |
|
3241 "-*- texinfo -*-\n\ |
|
3242 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ |
|
3243 Create a figure graphics object.\n\ |
|
3244 @end deftypefn") |
|
3245 { |
|
3246 octave_value retval; |
|
3247 |
|
3248 if (args.length () > 0) |
|
3249 { |
|
3250 double val = args(0).double_value (); |
|
3251 |
|
3252 if (! error_state) |
|
3253 { |
|
3254 if (is_figure (val)) |
|
3255 { |
|
3256 graphics_handle h = gh_manager::lookup (val); |
|
3257 |
|
3258 xset (h, args.splice (0, 1)); |
|
3259 |
|
3260 retval = h; |
|
3261 } |
|
3262 else |
|
3263 { |
|
3264 graphics_handle h = octave_NaN; |
|
3265 |
|
3266 if (xisnan (val)) |
|
3267 h = gh_manager::make_graphics_handle ("figure", 0); |
|
3268 else if (val > 0 && D_NINT (val) == val) |
|
3269 h = gh_manager::make_figure_handle (val); |
|
3270 else |
|
3271 error ("__go_figure__: invalid figure number"); |
|
3272 |
|
3273 if (! (error_state || xisnan (h))) |
|
3274 { |
|
3275 adopt (0, h); |
|
3276 |
|
3277 xset (h, args.splice (0, 1)); |
|
3278 |
|
3279 retval = h; |
|
3280 } |
|
3281 else |
|
3282 error ("__go_figure__: failed to create figure handle"); |
|
3283 } |
|
3284 } |
|
3285 else |
|
3286 error ("__go_figure__: expecting figure number to be double value"); |
|
3287 } |
|
3288 else |
|
3289 print_usage (); |
|
3290 |
|
3291 return retval; |
|
3292 } |
|
3293 |
|
3294 #define GO_BODY(TYPE) \ |
|
3295 octave_value retval; \ |
|
3296 \ |
|
3297 if (args.length () > 0) \ |
|
3298 retval = make_graphics_object (#TYPE, args); \ |
|
3299 else \ |
|
3300 print_usage (); \ |
|
3301 \ |
|
3302 return retval |
|
3303 |
|
3304 DEFUN (__go_axes__, args, , |
|
3305 "-*- texinfo -*-\n\ |
|
3306 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ |
|
3307 Create an axes graphics object.\n\ |
|
3308 @end deftypefn") |
|
3309 { |
|
3310 GO_BODY (axes); |
|
3311 } |
|
3312 |
|
3313 DEFUN (__go_line__, args, , |
|
3314 "-*- texinfo -*-\n\ |
|
3315 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ |
|
3316 Create a line graphics object.\n\ |
|
3317 @end deftypefn") |
|
3318 { |
|
3319 GO_BODY (line); |
|
3320 } |
|
3321 |
|
3322 DEFUN (__go_text__, args, , |
|
3323 "-*- texinfo -*-\n\ |
|
3324 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ |
|
3325 Create a text graphics object.\n\ |
|
3326 @end deftypefn") |
|
3327 { |
|
3328 GO_BODY (text); |
|
3329 } |
|
3330 |
|
3331 DEFUN (__go_image__, args, , |
|
3332 "-*- texinfo -*-\n\ |
|
3333 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ |
|
3334 Create an image graphics object.\n\ |
|
3335 @end deftypefn") |
|
3336 { |
|
3337 GO_BODY (image); |
|
3338 } |
|
3339 |
|
3340 DEFUN (__go_surface__, args, , |
|
3341 "-*- texinfo -*-\n\ |
|
3342 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ |
|
3343 Create a surface graphics object.\n\ |
|
3344 @end deftypefn") |
|
3345 { |
|
3346 GO_BODY (surface); |
|
3347 } |
|
3348 |
|
3349 DEFUN (__go_delete__, args, , |
|
3350 "-*- texinfo -*-\n\ |
|
3351 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ |
|
3352 @end deftypefn") |
|
3353 { |
|
3354 octave_value_list retval; |
|
3355 |
|
3356 if (args.length () == 1) |
|
3357 { |
|
3358 graphics_handle h = octave_NaN; |
|
3359 |
|
3360 double val = args(0).double_value (); |
|
3361 |
|
3362 if (! error_state) |
|
3363 { |
|
3364 h = gh_manager::lookup (val); |
|
3365 |
|
3366 if (! xisnan (h)) |
|
3367 { |
|
3368 graphics_object obj = gh_manager::get_object (h); |
|
3369 |
|
3370 graphics_handle parent_h = obj.get_parent (); |
|
3371 |
|
3372 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
3373 |
|
3374 parent_obj.remove_child (h); |
|
3375 |
|
3376 gh_manager::free (h); |
|
3377 } |
|
3378 else |
|
3379 error ("delete: invalid graphics object (= %g)", val); |
|
3380 } |
|
3381 else |
|
3382 error ("delete: invalid graphics object"); |
|
3383 } |
|
3384 else |
|
3385 print_usage (); |
|
3386 |
|
3387 return retval; |
|
3388 } |
|
3389 |
|
3390 DEFUN (__go_axes_init__, args, , |
|
3391 "-*- texinfo -*-\n\ |
|
3392 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ |
|
3393 Initialize axes object.\n\ |
|
3394 @end deftypefn") |
|
3395 { |
|
3396 octave_value retval; |
|
3397 |
|
3398 int nargin = args.length (); |
|
3399 |
|
3400 std::string mode = ""; |
|
3401 |
|
3402 if (nargin == 2) |
|
3403 { |
|
3404 mode = args(1).string_value (); |
|
3405 |
|
3406 if (error_state) |
|
3407 return retval; |
|
3408 } |
|
3409 |
|
3410 if (nargin == 1 || nargin == 2) |
|
3411 { |
|
3412 graphics_handle h = octave_NaN; |
|
3413 |
|
3414 double val = args(0).double_value (); |
|
3415 |
|
3416 if (! error_state) |
|
3417 { |
|
3418 h = gh_manager::lookup (val); |
|
3419 |
|
3420 if (! xisnan (h)) |
|
3421 { |
|
3422 graphics_object obj = gh_manager::get_object (h); |
|
3423 |
|
3424 obj.set_defaults (mode); |
|
3425 } |
|
3426 else |
|
3427 error ("__go_axes_init__: invalid graphics object (= %g)", val); |
|
3428 } |
|
3429 else |
|
3430 error ("__go_axes_init__: invalid graphics object"); |
|
3431 } |
|
3432 else |
|
3433 print_usage (); |
|
3434 |
|
3435 return retval; |
|
3436 } |
|
3437 |
|
3438 DEFUN (__go_handles__, , , |
|
3439 "-*- texinfo -*-\n\ |
|
3440 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ |
|
3441 Return current list of function handles.\n\ |
|
3442 @end deftypefn") |
|
3443 { |
6425
|
3444 return octave_value (gh_manager::handle_list ()); |
|
3445 } |
|
3446 |
|
3447 DEFUN (__go_figure_handles__, , , |
|
3448 "-*- texinfo -*-\n\ |
|
3449 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ |
|
3450 Return current list of function handles.\n\ |
|
3451 @end deftypefn") |
|
3452 { |
|
3453 return octave_value (gh_manager::figure_handle_list ()); |
6406
|
3454 } |
|
3455 |
|
3456 /* |
|
3457 ;;; Local Variables: *** |
|
3458 ;;; mode: C++ *** |
|
3459 ;;; End: *** |
|
3460 */ |