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