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