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"), |
6509
|
2407 markeredgecolor ("auto"), |
|
2408 markerfacecolor ("none"), |
6406
|
2409 markersize (1), |
|
2410 keylabel ("") { } |
|
2411 |
|
2412 ~line_properties (void) { } |
|
2413 |
|
2414 void set (const property_name& name, const octave_value& val) |
|
2415 { |
6432
|
2416 bool modified = true; |
|
2417 |
6406
|
2418 if (name.compare ("parent")) |
|
2419 set_parent (val); |
|
2420 else if (name.compare ("children")) |
|
2421 children = maybe_set_children (children, val); |
6432
|
2422 else if (name.compare ("__modified__")) |
|
2423 { |
|
2424 __modified__ = val.bool_value (); |
|
2425 modified = false; |
|
2426 } |
6406
|
2427 else if (name.compare ("xdata")) |
|
2428 xdata = val; |
|
2429 else if (name.compare ("ydata")) |
|
2430 ydata = val; |
|
2431 else if (name.compare ("zdata")) |
|
2432 zdata = val; |
|
2433 else if (name.compare ("ldata")) |
|
2434 ldata = val; |
|
2435 else if (name.compare ("udata")) |
|
2436 udata = val; |
|
2437 else if (name.compare ("xldata")) |
|
2438 xldata = val; |
|
2439 else if (name.compare ("xudata")) |
|
2440 xudata = val; |
|
2441 else if (name.compare ("color")) |
|
2442 color = color_property (val); |
|
2443 else if (name.compare ("linestyle")) |
|
2444 linestyle = val; |
|
2445 else if (name.compare ("linewidth")) |
|
2446 linewidth = val; |
|
2447 else if (name.compare ("marker")) |
|
2448 marker = val; |
6509
|
2449 else if (name.compare ("markeredgecolor")) |
|
2450 markeredgecolor = val; |
|
2451 else if (name.compare ("markerfacecolor")) |
|
2452 markerfacecolor = val; |
6406
|
2453 else if (name.compare ("markersize")) |
|
2454 markersize = val; |
|
2455 else if (name.compare ("keylabel")) |
|
2456 keylabel = val; |
|
2457 else |
6432
|
2458 { |
|
2459 modified = false; |
|
2460 warning ("set: invalid property `%s'", name.c_str ()); |
|
2461 } |
|
2462 |
|
2463 if (modified) |
|
2464 mark_modified (); |
6406
|
2465 } |
|
2466 |
|
2467 octave_value get (void) const |
|
2468 { |
|
2469 Octave_map m; |
|
2470 |
|
2471 m.assign ("type", type); |
|
2472 m.assign ("parent", parent); |
|
2473 m.assign ("children", children); |
6432
|
2474 m.assign ("__modified__", __modified__); |
6406
|
2475 m.assign ("xdata", xdata); |
|
2476 m.assign ("ydata", ydata); |
|
2477 m.assign ("zdata", zdata); |
|
2478 m.assign ("ldata", ldata); |
|
2479 m.assign ("udata", udata); |
|
2480 m.assign ("xldata", xldata); |
|
2481 m.assign ("xudata", xudata); |
|
2482 m.assign ("color", color); |
|
2483 m.assign ("linestyle", linestyle); |
|
2484 m.assign ("linewidth", linewidth); |
|
2485 m.assign ("marker", marker); |
6509
|
2486 m.assign ("markeredgecolor", markeredgecolor); |
|
2487 m.assign ("markerface", markerfacecolor); |
6406
|
2488 m.assign ("markersize", markersize); |
|
2489 m.assign ("keylabel", keylabel); |
|
2490 |
|
2491 return m; |
|
2492 } |
|
2493 |
|
2494 octave_value get (const property_name& name) const |
|
2495 { |
|
2496 octave_value retval; |
|
2497 |
|
2498 if (name.compare ("type")) |
|
2499 retval = type; |
|
2500 else if (name.compare ("parent")) |
|
2501 retval = parent; |
|
2502 else if (name.compare ("children")) |
|
2503 retval = children; |
6432
|
2504 else if (name.compare ("__modified__")) |
|
2505 retval = __modified__; |
6406
|
2506 else if (name.compare ("xdata")) |
|
2507 retval = xdata; |
|
2508 else if (name.compare ("ydata")) |
|
2509 retval = ydata; |
|
2510 else if (name.compare ("zdata")) |
|
2511 retval = zdata; |
|
2512 else if (name.compare ("ldata")) |
|
2513 retval = ldata; |
|
2514 else if (name.compare ("udata")) |
|
2515 retval = udata; |
|
2516 else if (name.compare ("xldata")) |
|
2517 retval = xldata; |
|
2518 else if (name.compare ("xudata")) |
|
2519 retval = xudata; |
|
2520 else if (name.compare ("color")) |
|
2521 retval = color; |
|
2522 else if (name.compare ("linestyle")) |
|
2523 retval = linestyle; |
|
2524 else if (name.compare ("linewidth")) |
|
2525 retval = linewidth; |
|
2526 else if (name.compare ("marker")) |
|
2527 retval = marker; |
6509
|
2528 else if (name.compare ("markeredgecolor")) |
|
2529 retval = markeredgecolor; |
|
2530 else if (name.compare ("markerfacecolor")) |
|
2531 retval = markerfacecolor; |
6406
|
2532 else if (name.compare ("markersize")) |
|
2533 retval = markersize; |
|
2534 else if (name.compare ("keylabel")) |
|
2535 retval = keylabel; |
|
2536 else |
|
2537 warning ("get: invalid property `%s'", name.c_str ()); |
|
2538 |
|
2539 return retval; |
|
2540 } |
|
2541 |
|
2542 std::string graphics_object_name (void) const { return go_name; } |
|
2543 |
|
2544 static property_list::pval_map_type factory_defaults (void) |
|
2545 { |
|
2546 property_list::pval_map_type m; |
|
2547 |
|
2548 m["xdata"] = default_data (); |
|
2549 m["ydata"] = default_data (); |
|
2550 m["zdata"] = Matrix (); |
|
2551 m["ldata"] = Matrix (); |
|
2552 m["udata"] = Matrix (); |
|
2553 m["xldata"] = Matrix (); |
|
2554 m["xudata"] = Matrix (); |
|
2555 m["color"] = color_property (); |
|
2556 m["linestyle"] = "-"; |
|
2557 m["linewidth"] = 0.5; |
|
2558 m["marker"] = "none"; |
6509
|
2559 m["markeredgecolor"] = "auto"; |
|
2560 m["markerfacecolor"] = "none"; |
6406
|
2561 m["markersize"] = 1; |
|
2562 m["keylabel"] = ""; |
|
2563 |
|
2564 return m; |
|
2565 } |
|
2566 |
|
2567 private: |
|
2568 octave_value xdata; |
|
2569 octave_value ydata; |
|
2570 octave_value zdata; |
|
2571 octave_value ldata; |
|
2572 octave_value udata; |
|
2573 octave_value xldata; |
|
2574 octave_value xudata; |
|
2575 color_property color; |
|
2576 octave_value linestyle; |
|
2577 octave_value linewidth; |
|
2578 octave_value marker; |
6509
|
2579 octave_value markeredgecolor; |
|
2580 octave_value markerfacecolor; |
6406
|
2581 octave_value markersize; |
|
2582 octave_value keylabel; |
|
2583 |
|
2584 static std::string go_name; |
|
2585 }; |
|
2586 |
|
2587 line_properties properties; |
|
2588 |
|
2589 public: |
|
2590 line (const graphics_handle& mh, const graphics_handle& p) |
|
2591 : base_graphics_object (), properties (mh, p) |
|
2592 { |
|
2593 properties.override_defaults (*this); |
|
2594 } |
|
2595 |
|
2596 ~line (void) { properties.delete_children (); } |
|
2597 |
|
2598 std::string type (void) const { return properties.graphics_object_name (); } |
|
2599 |
6432
|
2600 void mark_modified (void) { properties.mark_modified (); } |
|
2601 |
6406
|
2602 void override_defaults (base_graphics_object& obj) |
|
2603 { |
|
2604 // Allow parent (figure) to override first (properties knows how |
|
2605 // to find the parent object). |
|
2606 properties.override_defaults (obj); |
|
2607 } |
|
2608 |
|
2609 void set_from_list (property_list& plist) |
|
2610 { |
|
2611 properties.set_from_list (*this, plist); |
|
2612 } |
|
2613 |
|
2614 void set (const property_name& name, const octave_value& val) |
|
2615 { |
|
2616 properties.set (name, val); |
|
2617 } |
|
2618 |
|
2619 octave_value get (void) const |
|
2620 { |
|
2621 return properties.get (); |
|
2622 } |
|
2623 |
|
2624 octave_value get (const property_name& name) const |
|
2625 { |
|
2626 return properties.get (name); |
|
2627 } |
|
2628 |
|
2629 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
2630 |
|
2631 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
2632 |
|
2633 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
2634 |
|
2635 void reparent (const graphics_handle& h) { properties.reparent (h); } |
|
2636 |
|
2637 bool valid_object (void) const { return true; } |
|
2638 }; |
|
2639 |
|
2640 std::string line::line_properties::go_name ("line"); |
|
2641 |
|
2642 // --------------------------------------------------------------------- |
|
2643 |
|
2644 class text : public base_graphics_object |
|
2645 { |
|
2646 public: |
|
2647 class text_properties : public base_properties |
|
2648 { |
|
2649 public: |
|
2650 text_properties (const graphics_handle& mh, const graphics_handle& p) |
|
2651 : base_properties (go_name, mh, p), |
|
2652 string (""), |
|
2653 units ("data"), |
|
2654 position (Matrix (1, 3, 0.0)), |
|
2655 horizontalalignment ("left") |
|
2656 { } |
|
2657 |
|
2658 ~text_properties (void) { } |
|
2659 |
|
2660 void set (const property_name& name, const octave_value& val) |
|
2661 { |
6432
|
2662 bool modified = true; |
|
2663 |
6406
|
2664 if (name.compare ("parent")) |
|
2665 set_parent (val); |
|
2666 else if (name.compare ("children")) |
|
2667 children = maybe_set_children (children, val); |
6432
|
2668 else if (name.compare ("__modified__")) |
|
2669 { |
|
2670 __modified__ = val.bool_value (); |
|
2671 modified = false; |
|
2672 } |
6406
|
2673 else if (name.compare ("string")) |
|
2674 string = val; |
|
2675 else if (name.compare ("units")) |
|
2676 units = val; |
|
2677 else if (name.compare ("position")) |
|
2678 position = val; |
|
2679 else if (name.compare ("horizontalalignment")) |
|
2680 horizontalalignment = val; |
|
2681 else |
6432
|
2682 { |
|
2683 modified = false; |
|
2684 warning ("set: invalid property `%s'", name.c_str ()); |
|
2685 } |
|
2686 |
|
2687 if (modified) |
|
2688 mark_modified (); |
6406
|
2689 } |
|
2690 |
|
2691 octave_value get (void) const |
|
2692 { |
|
2693 Octave_map m; |
|
2694 |
|
2695 m.assign ("type", type); |
|
2696 m.assign ("parent", parent); |
|
2697 m.assign ("children", children); |
6432
|
2698 m.assign ("__modified__", __modified__); |
6406
|
2699 m.assign ("string", string); |
|
2700 m.assign ("units", units); |
|
2701 m.assign ("position", position); |
|
2702 m.assign ("horizontalalignment", horizontalalignment); |
|
2703 |
|
2704 return m; |
|
2705 } |
|
2706 |
|
2707 octave_value get (const property_name& name) const |
|
2708 { |
|
2709 octave_value retval; |
|
2710 |
|
2711 if (name.compare ("type")) |
|
2712 retval = type; |
|
2713 else if (name.compare ("parent")) |
|
2714 retval = parent; |
|
2715 else if (name.compare ("children")) |
|
2716 retval = children; |
6432
|
2717 else if (name.compare ("__modified__")) |
|
2718 retval = __modified__; |
6406
|
2719 else if (name.compare ("string")) |
|
2720 retval = string; |
|
2721 else if (name.compare ("units")) |
|
2722 retval = units; |
|
2723 else if (name.compare ("position")) |
|
2724 retval = position; |
|
2725 else if (name.compare ("horizontalalignment")) |
|
2726 retval = horizontalalignment; |
|
2727 else |
|
2728 warning ("get: invalid property `%s'", name.c_str ()); |
|
2729 |
|
2730 return retval; |
|
2731 } |
|
2732 |
|
2733 std::string graphics_object_name (void) const { return go_name; } |
|
2734 |
|
2735 static property_list::pval_map_type factory_defaults (void) |
|
2736 { |
|
2737 property_list::pval_map_type m; |
|
2738 |
|
2739 m["string"] = ""; |
|
2740 m["units"] = "data"; |
|
2741 m["position"] = Matrix (1, 3, 0.0); |
|
2742 m["horizontalalignment"] = "left"; |
|
2743 |
|
2744 return m; |
|
2745 } |
|
2746 |
|
2747 private: |
|
2748 octave_value string; |
|
2749 octave_value units; |
|
2750 octave_value position; |
|
2751 octave_value horizontalalignment; |
|
2752 |
|
2753 static std::string go_name; |
|
2754 }; |
|
2755 |
|
2756 text_properties properties; |
|
2757 |
|
2758 public: |
|
2759 text (const graphics_handle& mh, const graphics_handle& p) |
|
2760 : base_graphics_object (), properties (mh, p) |
|
2761 { |
|
2762 properties.override_defaults (*this); |
|
2763 } |
|
2764 |
|
2765 ~text (void) { properties.delete_children (); } |
|
2766 |
|
2767 std::string type (void) const { return properties.graphics_object_name (); } |
|
2768 |
6432
|
2769 void mark_modified (void) { properties.mark_modified (); } |
|
2770 |
6406
|
2771 void override_defaults (base_graphics_object& obj) |
|
2772 { |
|
2773 // Allow parent (figure) to override first (properties knows how |
|
2774 // to find the parent object). |
|
2775 properties.override_defaults (obj); |
|
2776 } |
|
2777 |
|
2778 void set_from_list (property_list& plist) |
|
2779 { |
|
2780 properties.set_from_list (*this, plist); |
|
2781 } |
|
2782 |
|
2783 void set (const property_name& name, const octave_value& val) |
|
2784 { |
|
2785 properties.set (name, val); |
|
2786 } |
|
2787 |
|
2788 octave_value get (void) const |
|
2789 { |
|
2790 return properties.get (); |
|
2791 } |
|
2792 |
|
2793 octave_value get (const property_name& name) const |
|
2794 { |
|
2795 return properties.get (name); |
|
2796 } |
|
2797 |
|
2798 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
2799 |
|
2800 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
2801 |
|
2802 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
2803 |
|
2804 void reparent (const graphics_handle& h) { properties.reparent (h); } |
|
2805 |
|
2806 bool valid_object (void) const { return true; } |
|
2807 }; |
|
2808 |
|
2809 std::string text::text_properties::go_name ("text"); |
|
2810 |
|
2811 // --------------------------------------------------------------------- |
|
2812 |
|
2813 class image : public base_graphics_object |
|
2814 { |
|
2815 public: |
|
2816 class image_properties : public base_properties |
|
2817 { |
|
2818 public: |
|
2819 image_properties (const graphics_handle& mh, const graphics_handle& p) |
|
2820 : base_properties (go_name, mh, p), |
|
2821 cdata (Matrix ()), |
|
2822 xdata (Matrix ()), |
|
2823 ydata (Matrix ()) |
|
2824 { } |
|
2825 |
|
2826 ~image_properties (void) { } |
|
2827 |
|
2828 void set (const property_name& name, const octave_value& val) |
|
2829 { |
6432
|
2830 bool modified = true; |
|
2831 |
6406
|
2832 if (name.compare ("parent")) |
|
2833 set_parent (val); |
|
2834 else if (name.compare ("children")) |
|
2835 children = maybe_set_children (children, val); |
6432
|
2836 else if (name.compare ("__modified__")) |
|
2837 { |
|
2838 __modified__ = val.bool_value (); |
|
2839 modified = false; |
|
2840 } |
6406
|
2841 else if (name.compare ("cdata")) |
|
2842 cdata = val; |
|
2843 else if (name.compare ("xdata")) |
|
2844 xdata = val; |
|
2845 else if (name.compare ("ydata")) |
|
2846 ydata = val; |
|
2847 else |
6432
|
2848 { |
|
2849 modified = false; |
|
2850 warning ("set: invalid property `%s'", name.c_str ()); |
|
2851 } |
|
2852 |
|
2853 if (modified) |
|
2854 mark_modified (); |
6406
|
2855 } |
|
2856 |
|
2857 octave_value get (void) const |
|
2858 { |
|
2859 Octave_map m; |
|
2860 |
|
2861 m.assign ("type", type); |
|
2862 m.assign ("parent", parent); |
|
2863 m.assign ("children", children); |
6432
|
2864 m.assign ("__modified__", __modified__); |
6406
|
2865 m.assign ("cdata", cdata); |
|
2866 m.assign ("xdata", xdata); |
|
2867 m.assign ("ydata", ydata); |
|
2868 |
|
2869 return m; |
|
2870 } |
|
2871 |
|
2872 octave_value get (const property_name& name) const |
|
2873 { |
|
2874 octave_value retval; |
|
2875 |
|
2876 if (name.compare ("type")) |
|
2877 retval = type; |
|
2878 else if (name.compare ("parent")) |
|
2879 retval = parent; |
|
2880 else if (name.compare ("children")) |
|
2881 retval = children; |
6432
|
2882 else if (name.compare ("__modified__")) |
|
2883 retval = __modified__; |
6406
|
2884 else if (name.compare ("cdata")) |
|
2885 retval = cdata; |
|
2886 else if (name.compare ("xdata")) |
|
2887 retval = xdata; |
|
2888 else if (name.compare ("ydata")) |
|
2889 retval = ydata; |
|
2890 else |
|
2891 warning ("get: invalid property `%s'", name.c_str ()); |
|
2892 |
|
2893 return retval; |
|
2894 } |
|
2895 |
|
2896 std::string graphics_object_name (void) const { return go_name; } |
|
2897 |
|
2898 static property_list::pval_map_type factory_defaults (void) |
|
2899 { |
|
2900 property_list::pval_map_type m; |
|
2901 |
|
2902 m["cdata"] = Matrix (); |
|
2903 m["xdata"] = Matrix (); |
|
2904 m["ydata"] = Matrix (); |
|
2905 |
|
2906 return m; |
|
2907 } |
|
2908 |
|
2909 private: |
|
2910 octave_value cdata; |
|
2911 octave_value xdata; |
|
2912 octave_value ydata; |
|
2913 |
|
2914 static std::string go_name; |
|
2915 }; |
|
2916 |
|
2917 image_properties properties; |
|
2918 |
|
2919 public: |
|
2920 image (const graphics_handle& mh, const graphics_handle& p) |
|
2921 : base_graphics_object (), properties (mh, p) |
|
2922 { |
|
2923 properties.override_defaults (*this); |
|
2924 } |
|
2925 |
|
2926 ~image (void) { properties.delete_children (); } |
|
2927 |
|
2928 std::string type (void) const { return properties.graphics_object_name (); } |
|
2929 |
6432
|
2930 void mark_modified (void) { properties.mark_modified (); } |
|
2931 |
6406
|
2932 void override_defaults (base_graphics_object& obj) |
|
2933 { |
|
2934 // Allow parent (figure) to override first (properties knows how |
|
2935 // to find the parent object). |
|
2936 properties.override_defaults (obj); |
|
2937 } |
|
2938 |
|
2939 void set_from_list (property_list& plist) |
|
2940 { |
|
2941 properties.set_from_list (*this, plist); |
|
2942 } |
|
2943 |
|
2944 void set (const property_name& name, const octave_value& val) |
|
2945 { |
|
2946 properties.set (name, val); |
|
2947 } |
|
2948 |
|
2949 octave_value get (void) const |
|
2950 { |
|
2951 return properties.get (); |
|
2952 } |
|
2953 |
|
2954 octave_value get (const property_name& name) const |
|
2955 { |
|
2956 return properties.get (name); |
|
2957 } |
|
2958 |
|
2959 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
2960 |
|
2961 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
2962 |
|
2963 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
2964 |
|
2965 void reparent (const graphics_handle& h) { properties.reparent (h); } |
|
2966 |
|
2967 bool valid_object (void) const { return true; } |
|
2968 }; |
|
2969 |
|
2970 std::string image::image_properties::go_name ("image"); |
|
2971 |
|
2972 // --------------------------------------------------------------------- |
|
2973 |
|
2974 class surface : public base_graphics_object |
|
2975 { |
|
2976 public: |
|
2977 class surface_properties : public base_properties |
|
2978 { |
|
2979 public: |
|
2980 surface_properties (const graphics_handle& mh, const graphics_handle& p) |
|
2981 : base_properties (go_name, mh, p), |
|
2982 xdata (Matrix ()), |
|
2983 ydata (Matrix ()), |
|
2984 zdata (Matrix ()), |
|
2985 keylabel ("") |
|
2986 { } |
|
2987 |
|
2988 ~surface_properties (void) { } |
|
2989 |
|
2990 void set (const property_name& name, const octave_value& val) |
|
2991 { |
6432
|
2992 bool modified = true; |
|
2993 |
6406
|
2994 if (name.compare ("parent")) |
|
2995 set_parent (val); |
|
2996 else if (name.compare ("children")) |
|
2997 children = maybe_set_children (children, val); |
6432
|
2998 else if (name.compare ("__modified__")) |
|
2999 { |
|
3000 __modified__ = val.bool_value (); |
|
3001 modified = false; |
|
3002 } |
6406
|
3003 else if (name.compare ("xdata")) |
|
3004 xdata = val; |
|
3005 else if (name.compare ("ydata")) |
|
3006 ydata = val; |
|
3007 else if (name.compare ("zdata")) |
|
3008 zdata = val; |
|
3009 else if (name.compare ("keylabel")) |
|
3010 keylabel = val; |
|
3011 else |
6432
|
3012 { |
|
3013 modified = false; |
|
3014 warning ("set: invalid property `%s'", name.c_str ()); |
|
3015 } |
|
3016 |
|
3017 if (modified) |
|
3018 mark_modified (); |
6406
|
3019 } |
|
3020 |
|
3021 octave_value get (void) const |
|
3022 { |
|
3023 Octave_map m; |
|
3024 |
|
3025 m.assign ("type", type); |
|
3026 m.assign ("parent", parent); |
|
3027 m.assign ("children", children); |
6432
|
3028 m.assign ("__modified__", __modified__); |
6406
|
3029 m.assign ("xdata", xdata); |
|
3030 m.assign ("ydata", ydata); |
|
3031 m.assign ("zdata", zdata); |
|
3032 m.assign ("keylabel", keylabel); |
|
3033 |
|
3034 return m; |
|
3035 } |
|
3036 |
|
3037 octave_value get (const property_name& name) const |
|
3038 { |
|
3039 octave_value retval; |
|
3040 |
|
3041 if (name.compare ("type")) |
|
3042 retval = type; |
|
3043 else if (name.compare ("parent")) |
|
3044 retval = parent; |
|
3045 else if (name.compare ("children")) |
|
3046 retval = children; |
6432
|
3047 else if (name.compare ("__modified__")) |
|
3048 retval = __modified__; |
6406
|
3049 else if (name.compare ("xdata")) |
|
3050 retval = xdata; |
|
3051 else if (name.compare ("ydata")) |
|
3052 retval = ydata; |
|
3053 else if (name.compare ("zdata")) |
|
3054 retval = zdata; |
|
3055 else if (name.compare ("keylabel")) |
|
3056 retval = keylabel; |
|
3057 else |
|
3058 warning ("get: invalid property `%s'", name.c_str ()); |
|
3059 |
|
3060 return retval; |
|
3061 } |
|
3062 |
|
3063 std::string graphics_object_name (void) const { return go_name; } |
|
3064 |
|
3065 static property_list::pval_map_type factory_defaults (void) |
|
3066 { |
|
3067 property_list::pval_map_type m; |
|
3068 |
|
3069 m["xdata"] = Matrix (); |
|
3070 m["ydata"] = Matrix (); |
|
3071 m["zdata"] = Matrix (); |
|
3072 m["keylabel"] = ""; |
|
3073 |
|
3074 return m; |
|
3075 } |
|
3076 |
|
3077 private: |
|
3078 octave_value xdata; |
|
3079 octave_value ydata; |
|
3080 octave_value zdata; |
|
3081 octave_value keylabel; |
|
3082 |
|
3083 static std::string go_name; |
|
3084 }; |
|
3085 |
|
3086 surface_properties properties; |
|
3087 |
|
3088 public: |
|
3089 surface (const graphics_handle& mh, const graphics_handle& p) |
|
3090 : base_graphics_object (), properties (mh, p) |
|
3091 { |
|
3092 properties.override_defaults (*this); |
|
3093 } |
|
3094 |
|
3095 ~surface (void) { properties.delete_children (); } |
|
3096 |
|
3097 std::string type (void) const { return properties.graphics_object_name (); } |
|
3098 |
6432
|
3099 void mark_modified (void) { properties.mark_modified (); } |
|
3100 |
6406
|
3101 void override_defaults (base_graphics_object& obj) |
|
3102 { |
|
3103 // Allow parent (figure) to override first (properties knows how |
|
3104 // to find the parent object). |
|
3105 properties.override_defaults (obj); |
|
3106 } |
|
3107 |
|
3108 void set_from_list (property_list& plist) |
|
3109 { |
|
3110 properties.set_from_list (*this, plist); |
|
3111 } |
|
3112 |
|
3113 void set (const property_name& name, const octave_value& val) |
|
3114 { |
|
3115 properties.set (name, val); |
|
3116 } |
|
3117 |
|
3118 octave_value get (void) const |
|
3119 { |
|
3120 return properties.get (); |
|
3121 } |
|
3122 |
|
3123 octave_value get (const property_name& name) const |
|
3124 { |
|
3125 return properties.get (name); |
|
3126 } |
|
3127 |
|
3128 graphics_handle get_parent (void) const { return properties.get_parent (); } |
|
3129 |
|
3130 void remove_child (const graphics_handle& h) { properties.remove_child (h); } |
|
3131 |
|
3132 void adopt (const graphics_handle& h) { properties.adopt (h); } |
|
3133 |
|
3134 void reparent (const graphics_handle& h) { properties.reparent (h); } |
|
3135 |
|
3136 bool valid_object (void) const { return true; } |
|
3137 }; |
|
3138 |
|
3139 std::string surface::surface_properties::go_name ("surface"); |
|
3140 |
|
3141 // --------------------------------------------------------------------- |
|
3142 |
|
3143 octave_value |
|
3144 base_graphics_object::get_default (const property_name& name) const |
|
3145 { |
|
3146 graphics_handle parent = get_parent (); |
|
3147 graphics_object parent_obj = gh_manager::get_object (parent); |
|
3148 |
|
3149 return parent_obj.get_default (type () + name); |
|
3150 } |
|
3151 |
|
3152 octave_value |
|
3153 base_graphics_object::get_factory_default (const property_name& name) const |
|
3154 { |
|
3155 graphics_object parent_obj = gh_manager::get_object (0); |
|
3156 |
|
3157 return parent_obj.get_factory_default (type () + name); |
|
3158 } |
|
3159 |
|
3160 gh_manager::gh_manager (void) |
|
3161 : handle_map (), handle_free_list (), next_handle (-1) |
|
3162 { |
|
3163 handle_map[0] = graphics_object (new root_figure ()); |
|
3164 } |
|
3165 |
|
3166 graphics_handle |
|
3167 gh_manager::do_make_graphics_handle (const std::string& go_name, |
|
3168 const graphics_handle& p) |
|
3169 { |
|
3170 graphics_handle h = get_handle (go_name); |
|
3171 |
|
3172 base_graphics_object *go = 0; |
|
3173 |
|
3174 if (go_name == "figure") |
|
3175 go = new figure (h, p); |
|
3176 else if (go_name == "axes") |
|
3177 go = new axes (h, p); |
|
3178 else if (go_name == "line") |
|
3179 go = new line (h, p); |
|
3180 else if (go_name == "text") |
|
3181 go = new text (h, p); |
|
3182 else if (go_name == "image") |
|
3183 go = new image (h, p); |
|
3184 else if (go_name == "surface") |
|
3185 go = new surface (h, p); |
|
3186 |
|
3187 if (go) |
|
3188 handle_map[h] = graphics_object (go); |
|
3189 else |
|
3190 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
|
3191 go_name.c_str ()); |
|
3192 |
|
3193 return h; |
|
3194 } |
|
3195 |
|
3196 graphics_handle |
|
3197 gh_manager::do_make_figure_handle (double val) |
|
3198 { |
|
3199 graphics_handle h = val; |
|
3200 |
|
3201 handle_map[h] = graphics_object (new figure (h, 0)); |
|
3202 |
|
3203 return h; |
|
3204 } |
|
3205 |
|
3206 void |
|
3207 gh_manager::do_push_figure (const graphics_handle& h) |
|
3208 { |
|
3209 do_pop_figure (h); |
|
3210 |
|
3211 figure_list.push_front (h); |
|
3212 } |
|
3213 |
|
3214 void |
|
3215 gh_manager::do_pop_figure (const graphics_handle& h) |
|
3216 { |
|
3217 for (figure_list_iterator p = figure_list.begin (); |
|
3218 p != figure_list.end (); |
|
3219 p++) |
|
3220 { |
|
3221 if (*p == h) |
|
3222 { |
|
3223 figure_list.erase (p); |
|
3224 break; |
|
3225 } |
|
3226 } |
|
3227 } |
|
3228 |
|
3229 property_list::plist_map_type |
|
3230 root_figure::init_factory_properties (void) |
|
3231 { |
|
3232 property_list::plist_map_type plist_map; |
|
3233 |
|
3234 plist_map["figure"] = figure::figure_properties::factory_defaults (); |
|
3235 plist_map["axes"] = axes::axes_properties::factory_defaults (); |
|
3236 plist_map["line"] = line::line_properties::factory_defaults (); |
|
3237 plist_map["text"] = text::text_properties::factory_defaults (); |
|
3238 plist_map["image"] = image::image_properties::factory_defaults (); |
|
3239 plist_map["surface"] = surface::surface_properties::factory_defaults (); |
|
3240 |
|
3241 return plist_map; |
|
3242 } |
|
3243 |
|
3244 // --------------------------------------------------------------------- |
|
3245 |
|
3246 DEFUN (ishandle, args, , |
|
3247 "-*- texinfo -*-\n\ |
|
3248 @deftypefn {Function File} {} ishandle (@var{h})\n\ |
|
3249 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
|
3250 @end deftypefn") |
|
3251 { |
|
3252 octave_value retval; |
|
3253 |
|
3254 if (args.length () == 1) |
|
3255 retval = is_handle (args(0)); |
|
3256 else |
|
3257 print_usage (); |
|
3258 |
|
3259 return retval; |
|
3260 } |
|
3261 |
|
3262 DEFUN (set, args, , |
|
3263 "-*- texinfo -*-\n\ |
|
3264 @deftypefn {Function File} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
|
3265 Set the named property @var{p} to the value @var{v} in the graphics\n\ |
|
3266 handle @var{h}.\n\ |
|
3267 @end deftypefn") |
|
3268 { |
|
3269 octave_value retval; |
|
3270 |
|
3271 int nargin = args.length (); |
|
3272 |
|
3273 if (nargin > 0) |
|
3274 { |
|
3275 double handle = args(0).double_value (); |
|
3276 |
|
3277 if (! error_state) |
|
3278 { |
|
3279 graphics_object obj = gh_manager::get_object (handle); |
|
3280 |
|
3281 if (obj) |
|
3282 { |
|
3283 obj.set (args.splice (0, 1)); |
|
3284 |
|
3285 feval ("__request_drawnow__"); |
|
3286 } |
|
3287 else |
|
3288 error ("set: invalid handle (= %g)", handle); |
|
3289 } |
|
3290 else |
|
3291 error ("set: expecting graphics handle as first argument"); |
|
3292 } |
|
3293 else |
|
3294 print_usage (); |
|
3295 |
|
3296 return retval; |
|
3297 } |
|
3298 |
|
3299 DEFUN (get, args, , |
|
3300 "-*- texinfo -*-\n\ |
|
3301 @deftypefn {Function File} {} get (@var{h}, @var{p})\n\ |
|
3302 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
|
3303 If @var{p} is omitted, return the complete property list for @var{h}.\n\ |
|
3304 @end deftypefn") |
|
3305 { |
|
3306 octave_value retval; |
|
3307 |
|
3308 int nargin = args.length (); |
|
3309 |
|
3310 if (nargin == 1 || nargin == 2) |
|
3311 { |
|
3312 double handle = args(0).double_value (); |
|
3313 |
|
3314 if (! error_state) |
|
3315 { |
|
3316 graphics_object obj = gh_manager::get_object (handle); |
|
3317 |
|
3318 if (obj) |
|
3319 { |
|
3320 if (nargin == 1) |
|
3321 retval = obj.get (); |
|
3322 else |
|
3323 { |
|
3324 property_name property = args(1).string_value (); |
|
3325 |
|
3326 if (! error_state) |
|
3327 retval = obj.get (property); |
|
3328 else |
|
3329 error ("get: expecting property name as second argument"); |
|
3330 } |
|
3331 } |
|
3332 else |
|
3333 error ("get: invalid handle (= %g)", handle); |
|
3334 } |
|
3335 else |
|
3336 error ("get: expecting graphics handle as first argument"); |
|
3337 } |
|
3338 else |
|
3339 print_usage (); |
|
3340 |
|
3341 return retval; |
|
3342 } |
|
3343 |
|
3344 static octave_value |
|
3345 make_graphics_object (const std::string& go_name, |
|
3346 const octave_value_list& args) |
|
3347 { |
|
3348 octave_value retval; |
|
3349 |
|
3350 double val = args(0).double_value (); |
|
3351 |
|
3352 if (! error_state) |
|
3353 { |
|
3354 graphics_handle parent = gh_manager::lookup (val); |
|
3355 |
|
3356 if (! xisnan (parent)) |
|
3357 { |
|
3358 graphics_handle h |
|
3359 = gh_manager::make_graphics_handle (go_name, parent); |
|
3360 |
|
3361 if (! error_state) |
|
3362 { |
|
3363 adopt (parent, h); |
|
3364 |
|
3365 xset (h, args.splice (0, 1)); |
|
3366 |
|
3367 retval = h; |
|
3368 } |
|
3369 else |
|
3370 error ("__go%s__: unable to create graphics handle", |
|
3371 go_name.c_str ()); |
|
3372 } |
|
3373 else |
|
3374 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
3375 } |
|
3376 else |
|
3377 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
3378 |
|
3379 return retval; |
|
3380 } |
|
3381 |
|
3382 DEFUN (__go_figure__, args, , |
|
3383 "-*- texinfo -*-\n\ |
|
3384 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ |
|
3385 Create a figure graphics object.\n\ |
|
3386 @end deftypefn") |
|
3387 { |
|
3388 octave_value retval; |
|
3389 |
|
3390 if (args.length () > 0) |
|
3391 { |
|
3392 double val = args(0).double_value (); |
|
3393 |
|
3394 if (! error_state) |
|
3395 { |
|
3396 if (is_figure (val)) |
|
3397 { |
|
3398 graphics_handle h = gh_manager::lookup (val); |
|
3399 |
|
3400 xset (h, args.splice (0, 1)); |
|
3401 |
|
3402 retval = h; |
|
3403 } |
|
3404 else |
|
3405 { |
|
3406 graphics_handle h = octave_NaN; |
|
3407 |
|
3408 if (xisnan (val)) |
|
3409 h = gh_manager::make_graphics_handle ("figure", 0); |
|
3410 else if (val > 0 && D_NINT (val) == val) |
|
3411 h = gh_manager::make_figure_handle (val); |
|
3412 else |
|
3413 error ("__go_figure__: invalid figure number"); |
|
3414 |
|
3415 if (! (error_state || xisnan (h))) |
|
3416 { |
|
3417 adopt (0, h); |
|
3418 |
|
3419 xset (h, args.splice (0, 1)); |
|
3420 |
|
3421 retval = h; |
|
3422 } |
|
3423 else |
|
3424 error ("__go_figure__: failed to create figure handle"); |
|
3425 } |
|
3426 } |
|
3427 else |
|
3428 error ("__go_figure__: expecting figure number to be double value"); |
|
3429 } |
|
3430 else |
|
3431 print_usage (); |
|
3432 |
|
3433 return retval; |
|
3434 } |
|
3435 |
|
3436 #define GO_BODY(TYPE) \ |
|
3437 octave_value retval; \ |
|
3438 \ |
|
3439 if (args.length () > 0) \ |
|
3440 retval = make_graphics_object (#TYPE, args); \ |
|
3441 else \ |
|
3442 print_usage (); \ |
|
3443 \ |
|
3444 return retval |
|
3445 |
|
3446 DEFUN (__go_axes__, args, , |
|
3447 "-*- texinfo -*-\n\ |
|
3448 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ |
|
3449 Create an axes graphics object.\n\ |
|
3450 @end deftypefn") |
|
3451 { |
|
3452 GO_BODY (axes); |
|
3453 } |
|
3454 |
|
3455 DEFUN (__go_line__, args, , |
|
3456 "-*- texinfo -*-\n\ |
|
3457 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ |
|
3458 Create a line graphics object.\n\ |
|
3459 @end deftypefn") |
|
3460 { |
|
3461 GO_BODY (line); |
|
3462 } |
|
3463 |
|
3464 DEFUN (__go_text__, args, , |
|
3465 "-*- texinfo -*-\n\ |
|
3466 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ |
|
3467 Create a text graphics object.\n\ |
|
3468 @end deftypefn") |
|
3469 { |
|
3470 GO_BODY (text); |
|
3471 } |
|
3472 |
|
3473 DEFUN (__go_image__, args, , |
|
3474 "-*- texinfo -*-\n\ |
|
3475 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ |
|
3476 Create an image graphics object.\n\ |
|
3477 @end deftypefn") |
|
3478 { |
|
3479 GO_BODY (image); |
|
3480 } |
|
3481 |
|
3482 DEFUN (__go_surface__, args, , |
|
3483 "-*- texinfo -*-\n\ |
|
3484 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ |
|
3485 Create a surface graphics object.\n\ |
|
3486 @end deftypefn") |
|
3487 { |
|
3488 GO_BODY (surface); |
|
3489 } |
|
3490 |
|
3491 DEFUN (__go_delete__, args, , |
|
3492 "-*- texinfo -*-\n\ |
|
3493 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ |
|
3494 @end deftypefn") |
|
3495 { |
|
3496 octave_value_list retval; |
|
3497 |
|
3498 if (args.length () == 1) |
|
3499 { |
|
3500 graphics_handle h = octave_NaN; |
|
3501 |
|
3502 double val = args(0).double_value (); |
|
3503 |
|
3504 if (! error_state) |
|
3505 { |
|
3506 h = gh_manager::lookup (val); |
|
3507 |
|
3508 if (! xisnan (h)) |
|
3509 { |
|
3510 graphics_object obj = gh_manager::get_object (h); |
|
3511 |
|
3512 graphics_handle parent_h = obj.get_parent (); |
|
3513 |
|
3514 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
3515 |
|
3516 parent_obj.remove_child (h); |
|
3517 |
|
3518 gh_manager::free (h); |
|
3519 } |
|
3520 else |
|
3521 error ("delete: invalid graphics object (= %g)", val); |
|
3522 } |
|
3523 else |
|
3524 error ("delete: invalid graphics object"); |
|
3525 } |
|
3526 else |
|
3527 print_usage (); |
|
3528 |
|
3529 return retval; |
|
3530 } |
|
3531 |
|
3532 DEFUN (__go_axes_init__, args, , |
|
3533 "-*- texinfo -*-\n\ |
|
3534 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ |
|
3535 Initialize axes object.\n\ |
|
3536 @end deftypefn") |
|
3537 { |
|
3538 octave_value retval; |
|
3539 |
|
3540 int nargin = args.length (); |
|
3541 |
|
3542 std::string mode = ""; |
|
3543 |
|
3544 if (nargin == 2) |
|
3545 { |
|
3546 mode = args(1).string_value (); |
|
3547 |
|
3548 if (error_state) |
|
3549 return retval; |
|
3550 } |
|
3551 |
|
3552 if (nargin == 1 || nargin == 2) |
|
3553 { |
|
3554 graphics_handle h = octave_NaN; |
|
3555 |
|
3556 double val = args(0).double_value (); |
|
3557 |
|
3558 if (! error_state) |
|
3559 { |
|
3560 h = gh_manager::lookup (val); |
|
3561 |
|
3562 if (! xisnan (h)) |
|
3563 { |
|
3564 graphics_object obj = gh_manager::get_object (h); |
|
3565 |
|
3566 obj.set_defaults (mode); |
|
3567 } |
|
3568 else |
|
3569 error ("__go_axes_init__: invalid graphics object (= %g)", val); |
|
3570 } |
|
3571 else |
|
3572 error ("__go_axes_init__: invalid graphics object"); |
|
3573 } |
|
3574 else |
|
3575 print_usage (); |
|
3576 |
|
3577 return retval; |
|
3578 } |
|
3579 |
|
3580 DEFUN (__go_handles__, , , |
|
3581 "-*- texinfo -*-\n\ |
|
3582 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ |
|
3583 Return current list of function handles.\n\ |
|
3584 @end deftypefn") |
|
3585 { |
6425
|
3586 return octave_value (gh_manager::handle_list ()); |
|
3587 } |
|
3588 |
|
3589 DEFUN (__go_figure_handles__, , , |
|
3590 "-*- texinfo -*-\n\ |
|
3591 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ |
|
3592 Return current list of function handles.\n\ |
|
3593 @end deftypefn") |
|
3594 { |
|
3595 return octave_value (gh_manager::figure_handle_list ()); |
6406
|
3596 } |
|
3597 |
|
3598 /* |
|
3599 ;;; Local Variables: *** |
|
3600 ;;; mode: C++ *** |
|
3601 ;;; End: *** |
|
3602 */ |