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