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