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