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 |
6705
|
36 #include "defun.h" |
|
37 #include "error.h" |
6595
|
38 #include "graphics.h" |
6705
|
39 #include "ov.h" |
|
40 #include "oct-obj.h" |
|
41 #include "oct-map.h" |
|
42 #include "ov-fcn-handle.h" |
|
43 #include "parse.h" |
6595
|
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 |
6705
|
65 radio_values::radio_values (const std::string& opt_string) |
6406
|
66 { |
6705
|
67 size_t beg = 0; |
|
68 size_t len = opt_string.length (); |
|
69 bool done = len == 0; |
6681
|
70 |
6705
|
71 while (! done) |
|
72 { |
|
73 size_t end = opt_string.find ('|', beg); |
6681
|
74 |
6705
|
75 if (end == std::string::npos) |
|
76 { |
|
77 end = len; |
|
78 done = true; |
|
79 } |
6681
|
80 |
6705
|
81 std::string t = opt_string.substr (beg, end-beg); |
6681
|
82 |
6705
|
83 // Might want more error checking here... |
|
84 if (t[0] == '{') |
|
85 { |
|
86 t = t.substr (1, t.length () - 2); |
|
87 default_val = t; |
|
88 } |
|
89 else if (beg == 0) // ensure default value |
|
90 default_val = t; |
6681
|
91 |
6705
|
92 possible_vals.insert (t); |
6681
|
93 |
6705
|
94 beg = end + 1; |
|
95 } |
|
96 } |
6681
|
97 |
6705
|
98 bool |
|
99 color_values::c2rgb (char c) |
6681
|
100 { |
6705
|
101 double tmp_rgb[3] = {0, 0, 0}; |
|
102 bool retval = true; |
6681
|
103 |
6705
|
104 switch(c) |
|
105 { |
|
106 case 'r': |
|
107 tmp_rgb[0] = 1; |
|
108 break; |
6681
|
109 |
6705
|
110 case 'g': |
|
111 tmp_rgb[1] = 1; |
|
112 break; |
|
113 |
|
114 case 'b': |
|
115 tmp_rgb[2] = 1; |
|
116 break; |
6681
|
117 |
6705
|
118 case 'c': |
|
119 tmp_rgb[1] = tmp_rgb[2] = 1; |
|
120 break; |
6681
|
121 |
6705
|
122 case 'm': |
|
123 tmp_rgb[0] = tmp_rgb[2] = 1; |
|
124 break; |
6681
|
125 |
6705
|
126 case 'y': |
|
127 tmp_rgb[0] = tmp_rgb[1] = 1; |
|
128 break; |
6681
|
129 |
6705
|
130 case 'w': |
|
131 tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 1; |
|
132 break; |
6563
|
133 |
6705
|
134 default: |
|
135 retval = false; |
|
136 } |
6406
|
137 |
6705
|
138 if (retval) |
|
139 { |
|
140 for (int i = 0; i < 3; i++) |
|
141 xrgb[i] = tmp_rgb[i]; |
|
142 } |
6563
|
143 |
6705
|
144 return retval; |
|
145 } |
6681
|
146 |
|
147 |
6705
|
148 color_property::color_property (const octave_value& val) |
|
149 : radio_val (), current_val () |
|
150 { |
|
151 // FIXME -- need some error checking here. |
6681
|
152 |
6705
|
153 if (val.is_string ()) |
|
154 { |
|
155 std::string s = val.string_value (); |
6681
|
156 |
6705
|
157 if (! s.empty ()) |
|
158 { |
|
159 color_values col (s[0]); |
|
160 if (! error_state) |
|
161 { |
|
162 color_val = col; |
|
163 current_type = color_t; |
|
164 } |
|
165 } |
|
166 else |
|
167 error ("invalid color specification"); |
|
168 } |
|
169 else if (val.is_real_matrix ()) |
|
170 { |
|
171 Matrix m = val.matrix_value (); |
6563
|
172 |
6705
|
173 if (m.numel () == 3) |
|
174 { |
|
175 color_values col (m (0), m (1), m(2)); |
|
176 if (! error_state) |
|
177 { |
|
178 color_val = col; |
|
179 current_type = color_t; |
|
180 } |
|
181 } |
|
182 else |
|
183 error ("invalid color specification"); |
|
184 } |
|
185 else |
|
186 error ("invalid color specification"); |
|
187 } |
6406
|
188 |
6681
|
189 |
6705
|
190 void |
|
191 property_list::set (const property_name& name, const octave_value& val) |
6681
|
192 { |
6705
|
193 size_t offset = 0; |
6681
|
194 |
6705
|
195 size_t len = name.length (); |
6681
|
196 |
6705
|
197 if (len > 4) |
|
198 { |
|
199 property_name pfx = name.substr (0, 4); |
6681
|
200 |
6705
|
201 if (pfx.compare ("axes") || pfx.compare ("line") |
|
202 || pfx.compare ("text")) |
|
203 offset = 4; |
|
204 else if (len > 5) |
|
205 { |
|
206 pfx = name.substr (0, 5); |
6681
|
207 |
6705
|
208 if (pfx.compare ("image")) |
|
209 offset = 5; |
|
210 else if (len > 6) |
|
211 { |
|
212 pfx = name.substr (0, 6); |
6681
|
213 |
6705
|
214 if (pfx.compare ("figure")) |
|
215 offset = 6; |
|
216 else if (len > 7) |
|
217 { |
|
218 pfx = name.substr (0, 7); |
6681
|
219 |
6705
|
220 if (pfx.compare ("surface")) |
|
221 offset = 7; |
|
222 } |
|
223 } |
|
224 } |
6681
|
225 |
6705
|
226 if (offset > 0) |
|
227 { |
|
228 // FIXME -- should we validate property names and values here? |
6406
|
229 |
6705
|
230 std::string pname = name.substr (offset); |
6406
|
231 |
6705
|
232 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
|
233 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); |
6406
|
234 |
6705
|
235 bool remove = false; |
|
236 if (val.is_string ()) |
|
237 { |
|
238 property_name tval = val.string_value (); |
6406
|
239 |
6705
|
240 remove = tval.compare ("remove"); |
|
241 } |
6406
|
242 |
6705
|
243 pval_map_type& pval_map = plist_map[pfx]; |
6406
|
244 |
6705
|
245 if (remove) |
|
246 { |
|
247 pval_map_iterator p = pval_map.find (pname); |
6406
|
248 |
6705
|
249 if (p != pval_map.end ()) |
|
250 pval_map.erase (p); |
|
251 } |
|
252 else |
|
253 pval_map[pname] = val; |
|
254 } |
|
255 } |
6406
|
256 |
6705
|
257 if (offset == 0) |
|
258 error ("invalid default property specification"); |
|
259 } |
6406
|
260 |
6705
|
261 octave_value |
|
262 property_list::lookup (const property_name& name) const |
|
263 { |
|
264 octave_value retval; |
6406
|
265 |
6705
|
266 size_t offset = 0; |
6406
|
267 |
6705
|
268 size_t len = name.length (); |
6406
|
269 |
6705
|
270 if (len > 4) |
|
271 { |
|
272 property_name pfx = name.substr (0, 4); |
6406
|
273 |
6705
|
274 if (pfx.compare ("axes") || pfx.compare ("line") |
|
275 || pfx.compare ("text")) |
|
276 offset = 4; |
|
277 else if (len > 5) |
|
278 { |
|
279 pfx = name.substr (0, 5); |
6406
|
280 |
6705
|
281 if (pfx.compare ("image")) |
|
282 offset = 5; |
|
283 else if (len > 6) |
|
284 { |
|
285 pfx = name.substr (0, 6); |
6406
|
286 |
6705
|
287 if (pfx.compare ("figure")) |
|
288 offset = 6; |
|
289 else if (len > 7) |
|
290 { |
|
291 pfx = name.substr (0, 7); |
6406
|
292 |
6705
|
293 if (pfx.compare ("surface")) |
|
294 offset = 7; |
|
295 } |
|
296 } |
|
297 } |
6406
|
298 |
6705
|
299 if (offset > 0) |
|
300 { |
|
301 std::string pname = name.substr (offset); |
6406
|
302 |
6705
|
303 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
|
304 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); |
6406
|
305 |
6705
|
306 plist_map_const_iterator p = find (pfx); |
6432
|
307 |
6705
|
308 if (p != end ()) |
|
309 { |
|
310 const pval_map_type& pval_map = p->second; |
6406
|
311 |
6705
|
312 pval_map_const_iterator q = pval_map.find (pname); |
6406
|
313 |
6705
|
314 if (q != pval_map.end ()) |
|
315 retval = q->second; |
|
316 } |
|
317 } |
|
318 } |
6406
|
319 |
6705
|
320 return retval; |
|
321 } |
6406
|
322 |
6705
|
323 Octave_map |
|
324 property_list::as_struct (const std::string& prefix_arg) const |
|
325 { |
|
326 Octave_map m; |
6406
|
327 |
6705
|
328 for (plist_map_const_iterator p = begin (); p != end (); p++) |
|
329 { |
|
330 std::string prefix = prefix_arg + p->first; |
6406
|
331 |
6705
|
332 const pval_map_type pval_map = p->second; |
6406
|
333 |
6705
|
334 for (pval_map_const_iterator q = pval_map.begin (); |
|
335 q != pval_map.end (); |
|
336 q++) |
|
337 m.assign (prefix + q->first, q->second); |
|
338 } |
6406
|
339 |
6705
|
340 return m; |
|
341 } |
6432
|
342 |
6705
|
343 void |
|
344 graphics_object::set (const octave_value_list& args) |
|
345 { |
|
346 int nargin = args.length (); |
6406
|
347 |
6705
|
348 if (nargin == 0) |
|
349 rep->defaults (); |
|
350 else if (nargin % 2 == 0) |
|
351 { |
|
352 for (int i = 0; i < nargin; i += 2) |
|
353 { |
|
354 property_name name = args(i).string_value (); |
6406
|
355 |
6705
|
356 if (! error_state) |
|
357 { |
|
358 octave_value val = args(i+1); |
6406
|
359 |
6705
|
360 if (val.is_string ()) |
|
361 { |
|
362 property_name tval = val.string_value (); |
6406
|
363 |
6705
|
364 if (tval.compare ("default")) |
|
365 val = get_default (name); |
|
366 else if (tval.compare ("factory")) |
|
367 val = get_factory_default (name); |
|
368 } |
6406
|
369 |
6705
|
370 if (error_state) |
|
371 break; |
6406
|
372 |
6705
|
373 rep->set (name, val); |
|
374 } |
|
375 else |
|
376 error ("set: expecting argument %d to be a property name", i); |
|
377 } |
|
378 } |
|
379 else |
|
380 error ("set: invalid number of arguments"); |
|
381 } |
6406
|
382 |
|
383 |
6705
|
384 graphics_handle |
|
385 gh_manager::get_handle (const std::string& go_name) |
|
386 { |
|
387 graphics_handle retval; |
6406
|
388 |
6705
|
389 if (go_name == "figure") |
|
390 { |
|
391 // We always want the lowest unused figure number. |
6406
|
392 |
6705
|
393 retval = 1; |
6425
|
394 |
6705
|
395 while (handle_map.find (retval) != handle_map.end ()) |
|
396 retval++; |
|
397 } |
|
398 else |
|
399 { |
|
400 free_list_iterator p = handle_free_list.begin (); |
6406
|
401 |
6705
|
402 if (p != handle_free_list.end ()) |
|
403 { |
|
404 retval = *p; |
|
405 handle_free_list.erase (p); |
|
406 } |
|
407 else |
|
408 retval = next_handle--; |
|
409 } |
6406
|
410 |
6705
|
411 return retval; |
|
412 } |
6406
|
413 |
6705
|
414 void |
|
415 gh_manager::do_free (const graphics_handle& h) |
|
416 { |
|
417 if (h != 0) |
|
418 { |
|
419 iterator p = handle_map.find (h); |
6406
|
420 |
6705
|
421 if (p != handle_map.end ()) |
|
422 { |
|
423 handle_map.erase (p); |
6406
|
424 |
6705
|
425 if (h < 0) |
|
426 handle_free_list.insert (h); |
|
427 } |
|
428 else |
|
429 error ("graphics_handle::free: invalid object %g", h); |
|
430 } |
|
431 else |
|
432 error ("graphics_handle::free: can't delete root figure"); |
|
433 } |
6406
|
434 |
|
435 |
|
436 gh_manager *gh_manager::instance = 0; |
|
437 |
|
438 static void |
|
439 xset (const graphics_handle& h, const property_name& name, |
|
440 const octave_value& val) |
|
441 { |
|
442 graphics_object obj = gh_manager::get_object (h); |
|
443 obj.set (name, val); |
|
444 } |
|
445 |
|
446 static void |
|
447 xset (const graphics_handle& h, const octave_value_list& args) |
|
448 { |
|
449 if (args.length () > 0) |
|
450 { |
|
451 graphics_object obj = gh_manager::get_object (h); |
|
452 obj.set (args); |
|
453 } |
|
454 } |
|
455 |
|
456 |
|
457 static octave_value |
|
458 xget (const graphics_handle& h, const property_name& name) |
|
459 { |
|
460 graphics_object obj = gh_manager::get_object (h); |
|
461 return obj.get (name); |
|
462 } |
|
463 |
|
464 static graphics_handle |
|
465 reparent (const octave_value& ov, const std::string& who, |
|
466 const std::string& property, const graphics_handle& new_parent, |
|
467 bool adopt = true) |
|
468 { |
|
469 graphics_handle h = octave_NaN; |
|
470 |
|
471 double val = ov.double_value (); |
|
472 |
|
473 if (! error_state) |
|
474 { |
|
475 h = gh_manager::lookup (val); |
|
476 |
|
477 if (! xisnan (h)) |
|
478 { |
|
479 graphics_object obj = gh_manager::get_object (h); |
|
480 |
|
481 graphics_handle parent_h = obj.get_parent (); |
|
482 |
|
483 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
484 |
|
485 parent_obj.remove_child (h); |
|
486 |
|
487 if (adopt) |
|
488 obj.set ("parent", new_parent); |
|
489 else |
|
490 obj.reparent (new_parent); |
|
491 } |
|
492 else |
|
493 error ("%s: invalid graphics handle (= %g) for %s", |
|
494 who.c_str (), val, property.c_str ()); |
|
495 } |
|
496 else |
|
497 error ("%s: expecting %s to be a graphics handle", |
|
498 who.c_str (), property.c_str ()); |
|
499 |
|
500 return h; |
|
501 } |
|
502 |
|
503 // This function is NOT equivalent to the scripting language function gcf. |
|
504 graphics_handle |
|
505 gcf (void) |
|
506 { |
|
507 octave_value val = xget (0, "currentfigure"); |
|
508 |
|
509 return val.is_empty () ? octave_NaN : val.double_value (); |
|
510 } |
|
511 |
|
512 // This function is NOT equivalent to the scripting language function gca. |
|
513 graphics_handle |
|
514 gca (void) |
|
515 { |
|
516 octave_value val = xget (gcf (), "currentaxes"); |
|
517 |
|
518 return val.is_empty () ? octave_NaN : val.double_value (); |
|
519 } |
|
520 |
|
521 static void |
|
522 adopt (const graphics_handle& p, const graphics_handle& h) |
|
523 { |
|
524 graphics_object parent_obj = gh_manager::get_object (p); |
|
525 |
|
526 parent_obj.adopt (h); |
|
527 } |
|
528 |
|
529 static bool |
|
530 is_handle (double val) |
|
531 { |
|
532 return ! xisnan (gh_manager::lookup (val)); |
|
533 } |
|
534 |
|
535 static bool |
|
536 is_handle (const octave_value& val) |
|
537 { |
|
538 return val.is_real_type () && is_handle (val.double_value ()); |
|
539 } |
|
540 |
|
541 static bool |
|
542 is_figure (double val) |
|
543 { |
|
544 graphics_object obj = gh_manager::get_object (val); |
|
545 |
|
546 return obj && obj.isa ("figure"); |
|
547 } |
|
548 |
|
549 // --------------------------------------------------------------------- |
|
550 |
|
551 static int |
|
552 compare (const void *a_arg, const void *b_arg) |
|
553 { |
|
554 double a = *(static_cast<const double *> (a_arg)); |
|
555 double b = *(static_cast<const double *> (b_arg)); |
|
556 |
|
557 return a > b ? 1 : (a < b) ? -1 : 0; |
|
558 } |
|
559 |
|
560 static Matrix |
|
561 maybe_set_children (const Matrix& kids, const octave_value& val) |
|
562 { |
|
563 const Matrix new_kids = val.matrix_value (); |
|
564 |
|
565 bool ok = true; |
|
566 |
|
567 if (! error_state) |
|
568 { |
|
569 if (kids.numel () == new_kids.numel ()) |
|
570 { |
|
571 Matrix t1 = kids; |
|
572 Matrix t2 = new_kids; |
|
573 |
|
574 t1.qsort (compare); |
|
575 t2.qsort (compare); |
|
576 |
|
577 if (t1 != t2) |
|
578 ok = false; |
|
579 } else |
|
580 ok = false; |
|
581 |
|
582 if (! ok) |
|
583 error ("set: new children must be a permutation of existing children"); |
|
584 } |
|
585 else |
|
586 { |
|
587 ok = false; |
|
588 error ("set: expecting children to be array of graphics handles"); |
|
589 } |
|
590 |
|
591 return ok ? new_kids : kids; |
|
592 } |
|
593 |
6705
|
594 void |
|
595 base_properties::set_from_list (base_graphics_object& obj, |
|
596 property_list& defaults) |
6406
|
597 { |
6705
|
598 std::string go_name = graphics_object_name (); |
6406
|
599 |
6705
|
600 property_list::plist_map_const_iterator p = defaults.find (go_name); |
6406
|
601 |
6705
|
602 if (p != defaults.end ()) |
|
603 { |
|
604 const property_list::pval_map_type pval_map = p->second; |
6406
|
605 |
6705
|
606 for (property_list::pval_map_const_iterator q = pval_map.begin (); |
|
607 q != pval_map.end (); |
|
608 q++) |
|
609 { |
|
610 std::string pname = q->first; |
6406
|
611 |
6705
|
612 obj.set (pname, q->second); |
6406
|
613 |
6705
|
614 if (error_state) |
|
615 { |
|
616 error ("error setting default property %s", pname.c_str ()); |
|
617 break; |
|
618 } |
|
619 } |
|
620 } |
|
621 } |
6406
|
622 |
6705
|
623 void |
|
624 base_properties::remove_child (const graphics_handle& h) |
6406
|
625 { |
6705
|
626 octave_idx_type k = -1; |
|
627 octave_idx_type n = children.numel (); |
|
628 for (octave_idx_type i = 0; i < n; i++) |
6406
|
629 { |
6705
|
630 if (h == children(i)) |
6406
|
631 { |
6705
|
632 k = i; |
|
633 break; |
6406
|
634 } |
|
635 } |
|
636 |
6705
|
637 if (k >= 0) |
6406
|
638 { |
6705
|
639 Matrix new_kids (1, n-1); |
|
640 octave_idx_type j = 0; |
|
641 for (octave_idx_type i = 0; i < n; i++) |
|
642 { |
|
643 if (i != k) |
|
644 new_kids(j++) = children(i); |
|
645 } |
|
646 children = new_kids; |
6406
|
647 } |
6705
|
648 } |
6406
|
649 |
6705
|
650 void base_properties::set_parent (const octave_value& val) |
|
651 { |
|
652 double tmp = val.double_value (); |
6406
|
653 |
6705
|
654 graphics_handle new_parent = octave_NaN; |
6406
|
655 |
6705
|
656 if (! error_state) |
|
657 { |
|
658 new_parent = gh_manager::lookup (tmp); |
6406
|
659 |
6705
|
660 if (! xisnan (new_parent)) |
|
661 { |
|
662 graphics_object parent_obj = gh_manager::get_object (parent); |
6406
|
663 |
6705
|
664 parent_obj.remove_child (__myhandle__); |
6406
|
665 |
6705
|
666 parent = new_parent; |
6406
|
667 |
6705
|
668 ::adopt (parent, __myhandle__); |
|
669 } |
|
670 else |
|
671 error ("set: invalid graphics handle (= %g) for parent", tmp); |
|
672 } |
|
673 else |
|
674 error ("set: expecting parent to be a graphics handle"); |
|
675 } |
6432
|
676 |
6705
|
677 void |
|
678 root_figure::root_figure_properties::set (const property_name& name, |
|
679 const octave_value& val) |
|
680 { |
|
681 if (name.compare ("currentfigure")) |
|
682 { |
|
683 octave_value tval = empty_to_nan (val); |
6406
|
684 |
6705
|
685 if (is_handle (tval)) |
|
686 { |
|
687 currentfigure = tval.double_value (); |
6406
|
688 |
6705
|
689 gh_manager::push_figure (currentfigure); |
|
690 } |
|
691 else |
|
692 gripe_set_invalid ("currentfigure"); |
|
693 } |
|
694 else if (name.compare ("children")) |
|
695 children = maybe_set_children (children, val); |
|
696 else if (name.compare ("visible")) |
|
697 visible = val; |
|
698 else |
|
699 warning ("set: invalid property `%s'", name.c_str ()); |
|
700 } |
6406
|
701 |
6705
|
702 octave_value root_figure::root_figure_properties::get (void) const |
|
703 { |
|
704 Octave_map m; |
6406
|
705 |
6705
|
706 m.assign ("type", type); |
|
707 m.assign ("currentfigure", nan_to_empty (currentfigure)); |
|
708 m.assign ("children", children); |
|
709 m.assign ("visible", visible); |
6406
|
710 |
6705
|
711 return m; |
|
712 } |
6406
|
713 |
6705
|
714 octave_value |
|
715 root_figure::root_figure_properties::get (const property_name& name) const |
|
716 { |
|
717 octave_value retval; |
6406
|
718 |
6705
|
719 if (name.compare ("type")) |
|
720 retval = type; |
|
721 else if (name.compare ("currentfigure")) |
|
722 retval = nan_to_empty (currentfigure); |
|
723 else if (name.compare ("children")) |
|
724 retval = children; |
|
725 else if (name.compare ("visible")) |
|
726 retval = visible; |
|
727 else |
|
728 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
729 |
6705
|
730 return retval; |
|
731 } |
6406
|
732 |
|
733 property_list |
|
734 root_figure::factory_properties = root_figure::init_factory_properties (); |
|
735 |
|
736 std::string root_figure::root_figure_properties::go_name ("root figure"); |
|
737 |
|
738 // --------------------------------------------------------------------- |
|
739 |
6705
|
740 figure::figure_properties::figure_properties (const graphics_handle& mh, |
|
741 const graphics_handle& p) |
|
742 : base_properties (go_name, mh, p), |
|
743 __plot_stream__ (Matrix ()), |
|
744 nextplot ("replace"), |
|
745 closerequestfcn (make_fcn_handle ("closereq")), |
|
746 currentaxes (octave_NaN), |
|
747 colormap (), |
|
748 visible ("on"), |
|
749 paperorientation ("portrait") |
|
750 { } |
|
751 |
|
752 void |
|
753 figure::figure_properties::set (const property_name& name, |
|
754 const octave_value& val) |
6406
|
755 { |
6705
|
756 bool modified = true; |
6406
|
757 |
6705
|
758 if (name.compare ("children")) |
|
759 children = maybe_set_children (children, val); |
|
760 else if (name.compare ("__modified__")) |
|
761 { |
|
762 __modified__ = val.bool_value (); |
|
763 modified = false; |
|
764 } |
|
765 else if (name.compare ("__plot_stream__")) |
|
766 __plot_stream__ = val; |
|
767 else if (name.compare ("nextplot")) |
|
768 nextplot = val; |
|
769 else if (name.compare ("closerequestfcn")) |
|
770 closerequestfcn = val; |
|
771 else if (name.compare ("currentaxes")) |
6406
|
772 { |
6705
|
773 octave_value tval = empty_to_nan (val); |
6432
|
774 |
6705
|
775 if (is_handle (tval)) |
|
776 currentaxes = tval.double_value (); |
|
777 else |
|
778 gripe_set_invalid ("currentaxes"); |
|
779 } |
|
780 else if (name.compare ("colormap")) |
|
781 colormap = colormap_property (val); |
|
782 else if (name.compare ("visible")) |
|
783 { |
|
784 std::string s = val.string_value (); |
|
785 |
|
786 if (! error_state) |
6432
|
787 { |
6705
|
788 if (s == "on") |
|
789 xset (0, "currentfigure", __myhandle__); |
6425
|
790 |
6705
|
791 visible = val; |
6425
|
792 } |
6406
|
793 } |
6705
|
794 else if (name.compare ("paperorientation")) |
|
795 paperorientation = val; |
|
796 else |
6406
|
797 { |
6705
|
798 modified = false; |
|
799 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
800 } |
|
801 |
6705
|
802 if (modified) |
|
803 mark_modified (); |
|
804 } |
|
805 |
|
806 octave_value |
|
807 figure::figure_properties::get (void) const |
|
808 { |
|
809 Octave_map m; |
6406
|
810 |
6705
|
811 m.assign ("type", type); |
|
812 m.assign ("parent", parent); |
|
813 m.assign ("children", children); |
|
814 m.assign ("__modified__", __modified__); |
|
815 m.assign ("__plot_stream__", __plot_stream__); |
|
816 m.assign ("nextplot", nextplot); |
|
817 m.assign ("closerequestfcn", closerequestfcn); |
|
818 m.assign ("currentaxes", nan_to_empty (currentaxes)); |
|
819 m.assign ("colormap", colormap); |
|
820 m.assign ("visible", visible); |
|
821 m.assign ("paperorientation", paperorientation); |
|
822 |
|
823 return m; |
|
824 } |
|
825 |
|
826 octave_value |
|
827 figure::figure_properties::get (const property_name& name) const |
|
828 { |
|
829 octave_value retval; |
6406
|
830 |
6705
|
831 if (name.compare ("type")) |
|
832 retval = type; |
|
833 else if (name.compare ("parent")) |
|
834 retval = parent; |
|
835 else if (name.compare ("children")) |
|
836 retval = children; |
|
837 else if (name.compare ("__modified__")) |
|
838 retval = __modified__; |
|
839 else if (name.compare ("__plot_stream__")) |
|
840 retval = __plot_stream__; |
|
841 else if (name.compare ("nextplot")) |
|
842 retval = nextplot; |
|
843 else if (name.compare ("closerequestfcn")) |
|
844 retval = closerequestfcn; |
|
845 else if (name.compare ("currentaxes")) |
|
846 retval = nan_to_empty (currentaxes); |
|
847 else if (name.compare ("colormap")) |
|
848 retval = colormap; |
|
849 else if (name.compare ("visible")) |
|
850 retval = visible; |
|
851 else if (name.compare ("paperorientation")) |
|
852 retval = paperorientation; |
|
853 else |
|
854 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
855 |
6705
|
856 return retval; |
|
857 } |
6406
|
858 |
6705
|
859 void figure::figure_properties::close (void) |
|
860 { |
|
861 if (! __plot_stream__.is_empty ()) |
6406
|
862 { |
6705
|
863 octave_value_list args; |
|
864 args(1) = "\nquit;\n"; |
|
865 args(0) = __plot_stream__; |
|
866 feval ("fputs", args); |
|
867 args.resize (1); |
|
868 feval ("fflush", args); |
|
869 feval ("pclose", args); |
6406
|
870 } |
|
871 |
6705
|
872 gh_manager::pop_figure (__myhandle__); |
6406
|
873 |
6705
|
874 xset (0, "currentfigure", gh_manager::current_figure ()); |
|
875 } |
6432
|
876 |
6705
|
877 property_list::pval_map_type figure::figure_properties::factory_defaults (void) |
|
878 { |
|
879 property_list::pval_map_type m; |
6406
|
880 |
6705
|
881 m["nextplot"] = "replace"; |
|
882 // m["closerequestfcn"] = make_fcn_handle ("closereq"); |
|
883 m["colormap"] = colormap_property (); |
|
884 m["visible"] = "on"; |
|
885 m["paperorientation"] = "portrait"; |
6406
|
886 |
6705
|
887 return m; |
|
888 } |
6406
|
889 |
|
890 std::string figure::figure_properties::go_name ("figure"); |
|
891 |
|
892 // --------------------------------------------------------------------- |
|
893 |
6705
|
894 axes::axes_properties::axes_properties (const graphics_handle& mh, |
|
895 const graphics_handle& p) |
|
896 : base_properties (go_name, mh, p), |
|
897 position (Matrix ()), |
|
898 title (octave_NaN), |
|
899 box ("on"), |
|
900 key ("off"), |
|
901 keybox ("off"), |
|
902 keypos (1), |
|
903 dataaspectratio (Matrix (1, 3, 1.0)), |
|
904 dataaspectratiomode ("auto"), |
|
905 xlim (), |
|
906 ylim (), |
|
907 zlim (), |
|
908 xlimmode ("auto"), |
|
909 ylimmode ("auto"), |
|
910 zlimmode ("auto"), |
|
911 xlabel (octave_NaN), |
|
912 ylabel (octave_NaN), |
|
913 zlabel (octave_NaN), |
|
914 xgrid ("off"), |
|
915 ygrid ("off"), |
|
916 zgrid ("off"), |
|
917 xminorgrid ("off"), |
|
918 yminorgrid ("off"), |
|
919 zminorgrid ("off"), |
|
920 xtick (Matrix ()), |
|
921 ytick (Matrix ()), |
|
922 ztick (Matrix ()), |
|
923 xtickmode ("auto"), |
|
924 ytickmode ("auto"), |
|
925 ztickmode ("auto"), |
|
926 xticklabel (""), |
|
927 yticklabel (""), |
|
928 zticklabel (""), |
|
929 xticklabelmode ("auto"), |
|
930 yticklabelmode ("auto"), |
|
931 zticklabelmode ("auto"), |
|
932 xscale ("linear"), |
|
933 yscale ("linear"), |
|
934 zscale ("linear"), |
|
935 xdir ("normal"), |
|
936 ydir ("normal"), |
|
937 zdir ("normal"), |
|
938 view (), |
|
939 nextplot ("replace"), |
|
940 outerposition () |
|
941 { |
|
942 Matrix tlim (1, 2, 0.0); |
|
943 tlim(1) = 1; |
|
944 xlim = tlim; |
|
945 ylim = tlim; |
|
946 zlim = tlim; |
|
947 |
|
948 Matrix tview (1, 2, 0.0); |
|
949 tview(1) = 90; |
|
950 view = tview; |
|
951 |
|
952 Matrix touterposition (1, 4, 0.0); |
|
953 touterposition(2) = 1; |
|
954 touterposition(3) = 1; |
|
955 outerposition = touterposition; |
|
956 } |
|
957 |
|
958 void |
|
959 axes::axes_properties::set (const property_name& name, const octave_value& val) |
6406
|
960 { |
6705
|
961 bool modified = true; |
|
962 |
|
963 if (name.compare ("parent")) |
|
964 set_parent (val); |
|
965 else if (name.compare ("children")) |
|
966 children = maybe_set_children (children, val); |
|
967 else if (name.compare ("__modified__")) |
|
968 { |
|
969 __modified__ = val.bool_value (); |
|
970 modified = false; |
|
971 } |
|
972 else if (name.compare ("position")) |
|
973 position = val; |
|
974 else if (name.compare ("title")) |
|
975 { |
|
976 graphics_handle h = ::reparent (val, "set", "title", |
|
977 __myhandle__, false); |
|
978 if (! error_state) |
|
979 { |
|
980 if (! xisnan (title)) |
|
981 gh_manager::free (title); |
|
982 |
|
983 title = h; |
|
984 } |
|
985 } |
|
986 else if (name.compare ("box")) |
|
987 box = val; |
|
988 else if (name.compare ("key")) |
|
989 key = val; |
|
990 else if (name.compare ("keybox")) |
|
991 keybox = val; |
|
992 else if (name.compare ("keypos")) |
|
993 keypos = val; |
|
994 else if (name.compare ("dataaspectratio")) |
|
995 { |
|
996 dataaspectratio = val; |
|
997 dataaspectratiomode = "manual"; |
|
998 } |
|
999 else if (name.compare ("dataaspectratiomode")) |
|
1000 dataaspectratiomode = val; |
|
1001 else if (name.compare ("xlim")) |
|
1002 { |
|
1003 xlim = val; |
|
1004 xlimmode = "manual"; |
|
1005 } |
|
1006 else if (name.compare ("ylim")) |
|
1007 { |
|
1008 ylim = val; |
|
1009 ylimmode = "manual"; |
|
1010 } |
|
1011 else if (name.compare ("zlim")) |
|
1012 { |
|
1013 zlim = val; |
|
1014 zlimmode = "manual"; |
|
1015 } |
|
1016 else if (name.compare ("xlimmode")) |
|
1017 xlimmode = val; |
|
1018 else if (name.compare ("ylimmode")) |
|
1019 ylimmode = val; |
|
1020 else if (name.compare ("zlimmode")) |
|
1021 zlimmode = val; |
|
1022 else if (name.compare ("xlabel")) |
|
1023 { |
|
1024 graphics_handle h = ::reparent (val, "set", "xlabel", |
|
1025 __myhandle__, false); |
|
1026 if (! error_state) |
|
1027 { |
|
1028 if (! xisnan (xlabel)) |
|
1029 gh_manager::free (xlabel); |
|
1030 |
|
1031 xlabel = h; |
|
1032 } |
|
1033 } |
|
1034 else if (name.compare ("ylabel")) |
|
1035 { |
|
1036 graphics_handle h = ::reparent (val, "set", "ylabel", |
|
1037 __myhandle__, false); |
|
1038 if (! error_state) |
|
1039 { |
|
1040 if (! xisnan (ylabel)) |
|
1041 gh_manager::free (ylabel); |
|
1042 |
|
1043 ylabel = h; |
|
1044 } |
|
1045 } |
|
1046 else if (name.compare ("zlabel")) |
|
1047 { |
|
1048 graphics_handle h = ::reparent (val, "set", "zlabel", |
|
1049 __myhandle__, false); |
|
1050 if (! error_state) |
|
1051 { |
|
1052 if (! xisnan (zlabel)) |
|
1053 gh_manager::free (zlabel); |
|
1054 |
|
1055 zlabel = h; |
|
1056 } |
|
1057 } |
|
1058 else if (name.compare ("xgrid")) |
|
1059 xgrid = val; |
|
1060 else if (name.compare ("ygrid")) |
|
1061 ygrid = val; |
|
1062 else if (name.compare ("zgrid")) |
|
1063 zgrid = val; |
|
1064 else if (name.compare ("xminorgrid")) |
|
1065 xminorgrid = val; |
|
1066 else if (name.compare ("yminorgrid")) |
|
1067 yminorgrid = val; |
|
1068 else if (name.compare ("zminorgrid")) |
|
1069 zminorgrid = val; |
|
1070 else if (name.compare ("xtick")) |
|
1071 { |
|
1072 xtick = val; |
|
1073 xtickmode = "manual"; |
|
1074 } |
|
1075 else if (name.compare ("ytick")) |
6406
|
1076 { |
6705
|
1077 ytick = val; |
|
1078 ytickmode = "manual"; |
|
1079 } |
|
1080 else if (name.compare ("ztick")) |
|
1081 { |
|
1082 ztick = val; |
|
1083 ztickmode = "manual"; |
|
1084 } |
|
1085 else if (name.compare ("xtickmode")) |
|
1086 xtickmode = val; |
|
1087 else if (name.compare ("ytickmode")) |
|
1088 ytickmode = val; |
|
1089 else if (name.compare ("ztickmode")) |
|
1090 ztickmode = val; |
|
1091 else if (name.compare ("xticklabel")) |
|
1092 { |
|
1093 xticklabel = val; |
|
1094 xticklabelmode = "manual"; |
|
1095 } |
|
1096 else if (name.compare ("yticklabel")) |
|
1097 { |
|
1098 yticklabel = val; |
|
1099 yticklabelmode = "manual"; |
|
1100 } |
|
1101 else if (name.compare ("zticklabel")) |
|
1102 { |
|
1103 zticklabel = val; |
|
1104 zticklabelmode = "manual"; |
|
1105 } |
|
1106 else if (name.compare ("xticklabelmode")) |
|
1107 xticklabelmode = val; |
|
1108 else if (name.compare ("yticklabelmode")) |
|
1109 yticklabelmode = val; |
|
1110 else if (name.compare ("zticklabelmode")) |
|
1111 zticklabelmode = val; |
|
1112 else if (name.compare ("xscale")) |
|
1113 xscale = val; |
|
1114 else if (name.compare ("yscale")) |
|
1115 yscale = val; |
|
1116 else if (name.compare ("zscale")) |
|
1117 zscale = val; |
|
1118 else if (name.compare ("xdir")) |
|
1119 xdir = val; |
|
1120 else if (name.compare ("ydir")) |
|
1121 ydir = val; |
|
1122 else if (name.compare ("zdir")) |
|
1123 zdir = val; |
|
1124 else if (name.compare ("view")) |
|
1125 view = val; |
|
1126 else if (name.compare ("nextplot")) |
|
1127 nextplot = val; |
|
1128 else if (name.compare ("outerposition")) |
|
1129 outerposition = val; |
|
1130 else |
|
1131 { |
|
1132 modified = false; |
|
1133 warning ("set: invalid property `%s'", name.c_str ()); |
|
1134 } |
6406
|
1135 |
6705
|
1136 if (modified) |
|
1137 mark_modified (); |
|
1138 } |
|
1139 |
|
1140 void |
|
1141 axes::axes_properties::set_defaults (base_graphics_object& obj, |
|
1142 const std::string& mode) |
|
1143 { |
|
1144 position = Matrix (); |
|
1145 title = octave_NaN; |
|
1146 box = "on"; |
|
1147 key = "off"; |
|
1148 keybox = "off"; |
|
1149 keypos = 1; |
|
1150 dataaspectratio = Matrix (1, 3, 1.0); |
|
1151 dataaspectratiomode = "auto"; |
|
1152 |
|
1153 Matrix tlim (1, 2, 0.0); |
|
1154 tlim(1) = 1; |
|
1155 xlim = tlim; |
|
1156 ylim = tlim; |
|
1157 zlim = tlim; |
6406
|
1158 |
6705
|
1159 xlimmode = "auto"; |
|
1160 ylimmode = "auto"; |
|
1161 zlimmode = "auto"; |
|
1162 xlabel = octave_NaN; |
|
1163 ylabel = octave_NaN; |
|
1164 zlabel = octave_NaN; |
|
1165 xgrid = "off"; |
|
1166 ygrid = "off"; |
|
1167 zgrid = "off"; |
|
1168 xminorgrid = "off"; |
|
1169 yminorgrid = "off"; |
|
1170 zminorgrid = "off"; |
|
1171 xtick = Matrix (); |
|
1172 ytick = Matrix (); |
|
1173 ztick = Matrix (); |
|
1174 xtickmode = "auto"; |
|
1175 ytickmode = "auto"; |
|
1176 ztickmode = "auto"; |
|
1177 xticklabel = ""; |
|
1178 yticklabel = ""; |
|
1179 zticklabel = ""; |
|
1180 xticklabelmode = "auto"; |
|
1181 yticklabelmode = "auto"; |
|
1182 zticklabelmode = "auto"; |
|
1183 xscale = "linear"; |
|
1184 yscale = "linear"; |
|
1185 zscale = "linear"; |
|
1186 xdir = "normal"; |
|
1187 ydir = "normal"; |
|
1188 zdir = "normal"; |
|
1189 |
|
1190 Matrix tview (1, 2, 0.0); |
|
1191 tview(1) = 90; |
|
1192 view = tview; |
|
1193 |
|
1194 nextplot = "replace"; |
|
1195 |
|
1196 // FIXME -- this is not quite right; we should preserve |
|
1197 // "position" and "units". |
|
1198 |
|
1199 if (mode != "replace") |
|
1200 { |
6406
|
1201 Matrix touterposition (1, 4, 0.0); |
|
1202 touterposition(2) = 1; |
|
1203 touterposition(3) = 1; |
|
1204 outerposition = touterposition; |
|
1205 } |
|
1206 |
6705
|
1207 delete_children (); |
6406
|
1208 |
6705
|
1209 children = Matrix (); |
6432
|
1210 |
6705
|
1211 override_defaults (obj); |
|
1212 } |
|
1213 |
|
1214 octave_value |
|
1215 axes::axes_properties::get (void) const |
|
1216 { |
|
1217 Octave_map m; |
6406
|
1218 |
6705
|
1219 if (xisnan (title)) |
|
1220 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1221 |
|
1222 if (xisnan (xlabel)) |
|
1223 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
6406
|
1224 |
6705
|
1225 if (xisnan (ylabel)) |
|
1226 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
6406
|
1227 |
6705
|
1228 if (xisnan (zlabel)) |
|
1229 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
6406
|
1230 |
6705
|
1231 m.assign ("type", type); |
|
1232 m.assign ("parent", parent); |
|
1233 m.assign ("children", children); |
|
1234 m.assign ("__modified__", __modified__); |
|
1235 m.assign ("position", position); |
|
1236 m.assign ("title", title); |
|
1237 m.assign ("box", box); |
|
1238 m.assign ("key", key); |
|
1239 m.assign ("keybox", keybox); |
|
1240 m.assign ("keypos", keypos); |
|
1241 m.assign ("dataaspectratio", dataaspectratio); |
|
1242 m.assign ("dataaspectratiomode", dataaspectratiomode); |
|
1243 m.assign ("xlim", xlim); |
|
1244 m.assign ("ylim", ylim); |
|
1245 m.assign ("zlim", zlim); |
|
1246 m.assign ("xlimmode", xlimmode); |
|
1247 m.assign ("ylimmode", ylimmode); |
|
1248 m.assign ("zlimmode", zlimmode); |
|
1249 m.assign ("xlabel", xlabel); |
|
1250 m.assign ("ylabel", ylabel); |
|
1251 m.assign ("zlabel", zlabel); |
|
1252 m.assign ("xgrid", xgrid); |
|
1253 m.assign ("ygrid", ygrid); |
|
1254 m.assign ("zgrid", zgrid); |
|
1255 m.assign ("xminorgrid", xminorgrid); |
|
1256 m.assign ("yminorgrid", yminorgrid); |
|
1257 m.assign ("zminorgrid", zminorgrid); |
|
1258 m.assign ("xtick", xtick); |
|
1259 m.assign ("ytick", ytick); |
|
1260 m.assign ("ztick", ztick); |
|
1261 m.assign ("xtickmode", xtickmode); |
|
1262 m.assign ("ytickmode", ytickmode); |
|
1263 m.assign ("ztickmode", ztickmode); |
|
1264 m.assign ("xticklabel", xticklabel); |
|
1265 m.assign ("yticklabel", yticklabel); |
|
1266 m.assign ("zticklabel", zticklabel); |
|
1267 m.assign ("xticklabelmode", xticklabelmode); |
|
1268 m.assign ("yticklabelmode", yticklabelmode); |
|
1269 m.assign ("zticklabelmode", zticklabelmode); |
|
1270 m.assign ("xscale", xscale); |
|
1271 m.assign ("yscale", yscale); |
|
1272 m.assign ("zscale", zscale); |
|
1273 m.assign ("xdir", xdir); |
|
1274 m.assign ("ydir", ydir); |
|
1275 m.assign ("zdir", zdir); |
|
1276 m.assign ("view", view); |
|
1277 m.assign ("nextplot", nextplot); |
|
1278 m.assign ("outerposition", outerposition); |
6432
|
1279 |
6705
|
1280 return m; |
|
1281 } |
6406
|
1282 |
6705
|
1283 octave_value |
|
1284 axes::axes_properties::get (const property_name& name) const |
|
1285 { |
|
1286 octave_value retval; |
6406
|
1287 |
6705
|
1288 if (name.compare ("type")) |
|
1289 retval = type; |
|
1290 else if (name.compare ("parent")) |
|
1291 retval = parent; |
|
1292 else if (name.compare ("children")) |
|
1293 retval = children; |
|
1294 else if (name.compare ("__modified__")) |
|
1295 retval = __modified__; |
|
1296 else if (name.compare ("position")) |
|
1297 retval = position; |
|
1298 else if (name.compare ("title")) |
6406
|
1299 { |
|
1300 if (xisnan (title)) |
|
1301 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1302 |
6705
|
1303 retval = title; |
|
1304 } |
|
1305 else if (name.compare ("box")) |
|
1306 retval = box; |
|
1307 else if (name.compare ("key")) |
|
1308 retval = key; |
|
1309 else if (name.compare ("keybox")) |
|
1310 retval = keybox; |
|
1311 else if (name.compare ("keypos")) |
|
1312 retval = keypos; |
|
1313 else if (name.compare ("dataaspectratio")) |
|
1314 retval = dataaspectratio; |
|
1315 else if (name.compare ("dataaspectratiomode")) |
|
1316 retval = dataaspectratiomode; |
|
1317 else if (name.compare ("xlim")) |
|
1318 retval = xlim; |
|
1319 else if (name.compare ("ylim")) |
|
1320 retval = ylim; |
|
1321 else if (name.compare ("zlim")) |
|
1322 retval = zlim; |
|
1323 else if (name.compare ("xlimmode")) |
|
1324 retval = xlimmode; |
|
1325 else if (name.compare ("ylimmode")) |
|
1326 retval = ylimmode; |
|
1327 else if (name.compare ("zlimmode")) |
|
1328 retval = zlimmode; |
|
1329 else if (name.compare ("xlabel")) |
|
1330 { |
6406
|
1331 if (xisnan (xlabel)) |
|
1332 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1333 |
6705
|
1334 retval = xlabel; |
|
1335 } |
|
1336 else if (name.compare ("ylabel")) |
|
1337 { |
6406
|
1338 if (xisnan (ylabel)) |
|
1339 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1340 |
6705
|
1341 retval = ylabel; |
|
1342 } |
|
1343 else if (name.compare ("zlabel")) |
|
1344 { |
6406
|
1345 if (xisnan (zlabel)) |
|
1346 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1347 |
6705
|
1348 retval = zlabel; |
6406
|
1349 } |
6705
|
1350 else if (name.compare ("xgrid")) |
|
1351 retval = xgrid; |
|
1352 else if (name.compare ("ygrid")) |
|
1353 retval = ygrid; |
|
1354 else if (name.compare ("zgrid")) |
|
1355 retval = zgrid; |
|
1356 else if (name.compare ("xminorgrid")) |
|
1357 retval = xminorgrid; |
|
1358 else if (name.compare ("yminorgrid")) |
|
1359 retval = yminorgrid; |
|
1360 else if (name.compare ("zminorgrid")) |
|
1361 retval = zminorgrid; |
|
1362 else if (name.compare ("xtick")) |
|
1363 retval = xtick; |
|
1364 else if (name.compare ("ytick")) |
|
1365 retval = ytick; |
|
1366 else if (name.compare ("ztick")) |
|
1367 retval = ztick; |
|
1368 else if (name.compare ("xtickmode")) |
|
1369 retval = xtickmode; |
|
1370 else if (name.compare ("ytickmode")) |
|
1371 retval = ytickmode; |
|
1372 else if (name.compare ("ztickmode")) |
|
1373 retval = ztickmode; |
|
1374 else if (name.compare ("xticklabel")) |
|
1375 retval = xticklabel; |
|
1376 else if (name.compare ("yticklabel")) |
|
1377 retval = yticklabel; |
|
1378 else if (name.compare ("zticklabel")) |
|
1379 retval = zticklabel; |
|
1380 else if (name.compare ("xticklabelmode")) |
|
1381 retval = xticklabelmode; |
|
1382 else if (name.compare ("yticklabelmode")) |
|
1383 retval = yticklabelmode; |
|
1384 else if (name.compare ("zticklabelmode")) |
|
1385 retval = zticklabelmode; |
|
1386 else if (name.compare ("xscale")) |
|
1387 retval = xscale; |
|
1388 else if (name.compare ("yscale")) |
|
1389 retval = yscale; |
|
1390 else if (name.compare ("zscale")) |
|
1391 retval = zscale; |
|
1392 else if (name.compare ("xdir")) |
|
1393 retval = xdir; |
|
1394 else if (name.compare ("ydir")) |
|
1395 retval = ydir; |
|
1396 else if (name.compare ("zdir")) |
|
1397 retval = zdir; |
|
1398 else if (name.compare ("view")) |
|
1399 retval = view; |
|
1400 else if (name.compare ("nextplot")) |
|
1401 retval = nextplot; |
|
1402 else if (name.compare ("outerposition")) |
|
1403 retval = outerposition; |
|
1404 else |
|
1405 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1406 |
6705
|
1407 return retval; |
|
1408 } |
6406
|
1409 |
6705
|
1410 void |
|
1411 axes::axes_properties::remove_child (const graphics_handle& h) |
|
1412 { |
|
1413 if (! xisnan (title) && h == title) |
|
1414 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1415 else if (! xisnan (xlabel) && h == xlabel) |
|
1416 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1417 else if (! xisnan (ylabel) && h == ylabel) |
|
1418 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1419 else if (! xisnan (zlabel) && h == zlabel) |
|
1420 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1421 else |
|
1422 base_properties::remove_child (h); |
|
1423 } |
6406
|
1424 |
6705
|
1425 void |
|
1426 axes::axes_properties::delete_children (void) |
|
1427 { |
|
1428 base_properties::delete_children (); |
|
1429 |
|
1430 if (! xisnan (title)) |
|
1431 gh_manager::free (title); |
6406
|
1432 |
6705
|
1433 if (! xisnan (xlabel)) |
|
1434 gh_manager::free (xlabel); |
6406
|
1435 |
6705
|
1436 if (! xisnan (ylabel)) |
|
1437 gh_manager::free (ylabel); |
6406
|
1438 |
6705
|
1439 if (! xisnan (zlabel)) |
|
1440 gh_manager::free (zlabel); |
|
1441 } |
6406
|
1442 |
6705
|
1443 property_list::pval_map_type axes::axes_properties::factory_defaults (void) |
|
1444 { |
|
1445 property_list::pval_map_type m; |
6406
|
1446 |
6705
|
1447 m["position"] = Matrix (); |
|
1448 m["title"] = octave_NaN; |
|
1449 m["box"] = "on"; |
|
1450 m["key"] = "off"; |
|
1451 m["keybox"] = "off"; |
|
1452 m["keypos"] = 1; |
|
1453 m["dataaspectratio"] = Matrix (1, 3, 1.0); |
|
1454 m["dataaspectratiomode"] = "auto"; |
6406
|
1455 |
6705
|
1456 Matrix tlim (1, 2, 0.0); |
|
1457 tlim(1) = 1; |
6406
|
1458 |
6705
|
1459 m["xlim"] = tlim; |
|
1460 m["ylim"] = tlim; |
|
1461 m["zlim"] = tlim; |
6406
|
1462 |
6705
|
1463 m["xlimmode"] = "auto"; |
|
1464 m["ylimmode"] = "auto"; |
|
1465 m["zlimmode"] = "auto"; |
|
1466 m["xlabel"] = octave_NaN; |
|
1467 m["ylabel"] = octave_NaN; |
|
1468 m["zlabel"] = octave_NaN; |
|
1469 m["xgrid"] = "off"; |
|
1470 m["ygrid"] = "off"; |
|
1471 m["zgrid"] = "off"; |
|
1472 m["xminorgrid"] = "off"; |
|
1473 m["yminorgrid"] = "off"; |
|
1474 m["zminorgrid"] = "off"; |
|
1475 m["xtick"] = Matrix (); |
|
1476 m["ytick"] = Matrix (); |
|
1477 m["ztick"] = Matrix (); |
|
1478 m["xtickmode"] = "auto"; |
|
1479 m["ytickmode"] = "auto"; |
|
1480 m["ztickmode"] = "auto"; |
|
1481 m["xticklabel"] = ""; |
|
1482 m["yticklabel"] = ""; |
|
1483 m["zticklabel"] = ""; |
|
1484 m["xticklabelmode"] = "auto"; |
|
1485 m["yticklabelmode"] = "auto"; |
|
1486 m["zticklabelmode"] = "auto"; |
|
1487 m["xscale"] = "linear"; |
|
1488 m["yscale"] = "linear"; |
|
1489 m["zscale"] = "linear"; |
|
1490 m["xdir"] = "normal"; |
|
1491 m["ydir"] = "normal"; |
|
1492 m["zdir"] = "normal"; |
6406
|
1493 |
6705
|
1494 Matrix tview (1, 2, 0.0); |
|
1495 tview(1) = 90; |
6406
|
1496 |
6705
|
1497 m["view"] = tview; |
6406
|
1498 |
6705
|
1499 m["nextplot"] = "replace"; |
6406
|
1500 |
6705
|
1501 Matrix touterposition (1, 4, 0.0); |
|
1502 touterposition(2) = 1; |
|
1503 touterposition(3) = 1; |
6406
|
1504 |
6705
|
1505 m["outerposition"] = touterposition; |
6406
|
1506 |
6705
|
1507 return m; |
|
1508 } |
6406
|
1509 |
|
1510 std::string axes::axes_properties::go_name ("axes"); |
|
1511 |
|
1512 // --------------------------------------------------------------------- |
|
1513 |
|
1514 static Matrix |
|
1515 default_data (void) |
|
1516 { |
|
1517 Matrix retval (1, 2); |
|
1518 |
|
1519 retval(0) = 0; |
|
1520 retval(1) = 1; |
|
1521 |
|
1522 return retval; |
|
1523 } |
|
1524 |
6705
|
1525 line::line_properties::line_properties (const graphics_handle& mh, |
|
1526 const graphics_handle& p) |
|
1527 : base_properties (go_name, mh, p), |
|
1528 xdata (default_data ()), |
|
1529 ydata (default_data ()), |
|
1530 zdata (Matrix ()), |
|
1531 ldata (Matrix ()), |
|
1532 udata (Matrix ()), |
|
1533 xldata (Matrix ()), |
|
1534 xudata (Matrix ()), |
|
1535 color (), |
|
1536 linestyle ("-"), |
|
1537 linewidth (0.5), |
|
1538 marker ("none"), |
|
1539 markeredgecolor ("auto"), |
|
1540 markerfacecolor ("none"), |
|
1541 markersize (1), |
|
1542 keylabel ("") |
|
1543 { } |
|
1544 |
|
1545 void |
|
1546 line::line_properties::set (const property_name& name, const octave_value& val) |
6406
|
1547 { |
6705
|
1548 bool modified = true; |
6432
|
1549 |
6705
|
1550 if (name.compare ("parent")) |
|
1551 set_parent (val); |
|
1552 else if (name.compare ("children")) |
|
1553 children = maybe_set_children (children, val); |
|
1554 else if (name.compare ("__modified__")) |
|
1555 { |
|
1556 __modified__ = val.bool_value (); |
|
1557 modified = false; |
6406
|
1558 } |
6705
|
1559 else if (name.compare ("xdata")) |
|
1560 xdata = val; |
|
1561 else if (name.compare ("ydata")) |
|
1562 ydata = val; |
|
1563 else if (name.compare ("zdata")) |
|
1564 zdata = val; |
|
1565 else if (name.compare ("ldata")) |
|
1566 ldata = val; |
|
1567 else if (name.compare ("udata")) |
|
1568 udata = val; |
|
1569 else if (name.compare ("xldata")) |
|
1570 xldata = val; |
|
1571 else if (name.compare ("xudata")) |
|
1572 xudata = val; |
|
1573 else if (name.compare ("color")) |
|
1574 color = color_property (val); |
|
1575 else if (name.compare ("linestyle")) |
|
1576 linestyle = val; |
|
1577 else if (name.compare ("linewidth")) |
|
1578 linewidth = val; |
|
1579 else if (name.compare ("marker")) |
|
1580 marker = val; |
|
1581 else if (name.compare ("markeredgecolor")) |
|
1582 markeredgecolor = val; |
|
1583 else if (name.compare ("markerfacecolor")) |
|
1584 markerfacecolor = val; |
|
1585 else if (name.compare ("markersize")) |
|
1586 markersize = val; |
|
1587 else if (name.compare ("keylabel")) |
|
1588 keylabel = val; |
|
1589 else |
6406
|
1590 { |
6705
|
1591 modified = false; |
|
1592 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1593 } |
|
1594 |
6705
|
1595 if (modified) |
|
1596 mark_modified (); |
|
1597 } |
|
1598 |
|
1599 octave_value |
|
1600 line::line_properties::get (void) const |
|
1601 { |
|
1602 Octave_map m; |
6406
|
1603 |
6705
|
1604 m.assign ("type", type); |
|
1605 m.assign ("parent", parent); |
|
1606 m.assign ("children", children); |
|
1607 m.assign ("__modified__", __modified__); |
|
1608 m.assign ("xdata", xdata); |
|
1609 m.assign ("ydata", ydata); |
|
1610 m.assign ("zdata", zdata); |
|
1611 m.assign ("ldata", ldata); |
|
1612 m.assign ("udata", udata); |
|
1613 m.assign ("xldata", xldata); |
|
1614 m.assign ("xudata", xudata); |
|
1615 m.assign ("color", color); |
|
1616 m.assign ("linestyle", linestyle); |
|
1617 m.assign ("linewidth", linewidth); |
|
1618 m.assign ("marker", marker); |
|
1619 m.assign ("markeredgecolor", markeredgecolor); |
|
1620 m.assign ("markerface", markerfacecolor); |
|
1621 m.assign ("markersize", markersize); |
|
1622 m.assign ("keylabel", keylabel); |
6406
|
1623 |
6705
|
1624 return m; |
|
1625 } |
6406
|
1626 |
6705
|
1627 octave_value |
|
1628 line::line_properties::get (const property_name& name) const |
|
1629 { |
|
1630 octave_value retval; |
6406
|
1631 |
6705
|
1632 if (name.compare ("type")) |
|
1633 retval = type; |
|
1634 else if (name.compare ("parent")) |
|
1635 retval = parent; |
|
1636 else if (name.compare ("children")) |
|
1637 retval = children; |
|
1638 else if (name.compare ("__modified__")) |
|
1639 retval = __modified__; |
|
1640 else if (name.compare ("xdata")) |
|
1641 retval = xdata; |
|
1642 else if (name.compare ("ydata")) |
|
1643 retval = ydata; |
|
1644 else if (name.compare ("zdata")) |
|
1645 retval = zdata; |
|
1646 else if (name.compare ("ldata")) |
|
1647 retval = ldata; |
|
1648 else if (name.compare ("udata")) |
|
1649 retval = udata; |
|
1650 else if (name.compare ("xldata")) |
|
1651 retval = xldata; |
|
1652 else if (name.compare ("xudata")) |
|
1653 retval = xudata; |
|
1654 else if (name.compare ("color")) |
|
1655 retval = color; |
|
1656 else if (name.compare ("linestyle")) |
|
1657 retval = linestyle; |
|
1658 else if (name.compare ("linewidth")) |
|
1659 retval = linewidth; |
|
1660 else if (name.compare ("marker")) |
|
1661 retval = marker; |
|
1662 else if (name.compare ("markeredgecolor")) |
|
1663 retval = markeredgecolor; |
|
1664 else if (name.compare ("markerfacecolor")) |
|
1665 retval = markerfacecolor; |
|
1666 else if (name.compare ("markersize")) |
|
1667 retval = markersize; |
|
1668 else if (name.compare ("keylabel")) |
|
1669 retval = keylabel; |
|
1670 else |
|
1671 warning ("get: invalid property `%s'", name.c_str ()); |
6432
|
1672 |
6705
|
1673 return retval; |
|
1674 } |
6406
|
1675 |
6705
|
1676 property_list::pval_map_type line::line_properties::factory_defaults (void) |
|
1677 { |
|
1678 property_list::pval_map_type m; |
6406
|
1679 |
6705
|
1680 m["xdata"] = default_data (); |
|
1681 m["ydata"] = default_data (); |
|
1682 m["zdata"] = Matrix (); |
|
1683 m["ldata"] = Matrix (); |
|
1684 m["udata"] = Matrix (); |
|
1685 m["xldata"] = Matrix (); |
|
1686 m["xudata"] = Matrix (); |
|
1687 m["color"] = color_property (); |
|
1688 m["linestyle"] = "-"; |
|
1689 m["linewidth"] = 0.5; |
|
1690 m["marker"] = "none"; |
|
1691 m["markeredgecolor"] = "auto"; |
|
1692 m["markerfacecolor"] = "none"; |
|
1693 m["markersize"] = 1; |
|
1694 m["keylabel"] = ""; |
6406
|
1695 |
6705
|
1696 return m; |
|
1697 } |
6406
|
1698 |
|
1699 std::string line::line_properties::go_name ("line"); |
|
1700 |
|
1701 // --------------------------------------------------------------------- |
|
1702 |
6705
|
1703 text::text_properties::text_properties (const graphics_handle& mh, |
|
1704 const graphics_handle& p) |
|
1705 : base_properties (go_name, mh, p), |
|
1706 string (""), |
|
1707 units ("data"), |
|
1708 position (Matrix (1, 3, 0.0)), |
|
1709 horizontalalignment ("left") |
|
1710 { } |
|
1711 |
|
1712 void |
|
1713 text::text_properties::set (const property_name& name, const octave_value& val) |
6406
|
1714 { |
6705
|
1715 bool modified = true; |
6432
|
1716 |
6705
|
1717 if (name.compare ("parent")) |
|
1718 set_parent (val); |
|
1719 else if (name.compare ("children")) |
|
1720 children = maybe_set_children (children, val); |
|
1721 else if (name.compare ("__modified__")) |
|
1722 { |
|
1723 __modified__ = val.bool_value (); |
|
1724 modified = false; |
6406
|
1725 } |
6705
|
1726 else if (name.compare ("string")) |
|
1727 string = val; |
|
1728 else if (name.compare ("units")) |
|
1729 units = val; |
|
1730 else if (name.compare ("position")) |
|
1731 position = val; |
|
1732 else if (name.compare ("horizontalalignment")) |
|
1733 horizontalalignment = val; |
|
1734 else |
6406
|
1735 { |
6705
|
1736 modified = false; |
|
1737 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1738 } |
|
1739 |
6705
|
1740 if (modified) |
|
1741 mark_modified (); |
|
1742 } |
6406
|
1743 |
6705
|
1744 octave_value |
|
1745 text::text_properties::get (void) const |
|
1746 { |
|
1747 Octave_map m; |
6406
|
1748 |
6705
|
1749 m.assign ("type", type); |
|
1750 m.assign ("parent", parent); |
|
1751 m.assign ("children", children); |
|
1752 m.assign ("__modified__", __modified__); |
|
1753 m.assign ("string", string); |
|
1754 m.assign ("units", units); |
|
1755 m.assign ("position", position); |
|
1756 m.assign ("horizontalalignment", horizontalalignment); |
6406
|
1757 |
6705
|
1758 return m; |
|
1759 } |
6406
|
1760 |
6705
|
1761 octave_value |
|
1762 text::text_properties::get (const property_name& name) const |
|
1763 { |
|
1764 octave_value retval; |
6406
|
1765 |
6705
|
1766 if (name.compare ("type")) |
|
1767 retval = type; |
|
1768 else if (name.compare ("parent")) |
|
1769 retval = parent; |
|
1770 else if (name.compare ("children")) |
|
1771 retval = children; |
|
1772 else if (name.compare ("__modified__")) |
|
1773 retval = __modified__; |
|
1774 else if (name.compare ("string")) |
|
1775 retval = string; |
|
1776 else if (name.compare ("units")) |
|
1777 retval = units; |
|
1778 else if (name.compare ("position")) |
|
1779 retval = position; |
|
1780 else if (name.compare ("horizontalalignment")) |
|
1781 retval = horizontalalignment; |
|
1782 else |
|
1783 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1784 |
6705
|
1785 return retval; |
|
1786 } |
6406
|
1787 |
6705
|
1788 property_list::pval_map_type |
|
1789 text::text_properties::factory_defaults (void) |
|
1790 { |
|
1791 property_list::pval_map_type m; |
6406
|
1792 |
6705
|
1793 m["string"] = ""; |
|
1794 m["units"] = "data"; |
|
1795 m["position"] = Matrix (1, 3, 0.0); |
|
1796 m["horizontalalignment"] = "left"; |
6406
|
1797 |
6705
|
1798 return m; |
|
1799 } |
6406
|
1800 |
|
1801 std::string text::text_properties::go_name ("text"); |
|
1802 |
|
1803 // --------------------------------------------------------------------- |
|
1804 |
6705
|
1805 image::image_properties::image_properties (const graphics_handle& mh, |
|
1806 const graphics_handle& p) |
|
1807 : base_properties (go_name, mh, p), |
|
1808 cdata (Matrix ()), |
|
1809 xdata (Matrix ()), |
|
1810 ydata (Matrix ()) |
|
1811 { } |
|
1812 |
|
1813 void |
|
1814 image::image_properties::set (const property_name& name, |
|
1815 const octave_value& val) |
6406
|
1816 { |
6705
|
1817 bool modified = true; |
6432
|
1818 |
6705
|
1819 if (name.compare ("parent")) |
|
1820 set_parent (val); |
|
1821 else if (name.compare ("children")) |
|
1822 children = maybe_set_children (children, val); |
|
1823 else if (name.compare ("__modified__")) |
|
1824 { |
|
1825 __modified__ = val.bool_value (); |
|
1826 modified = false; |
6406
|
1827 } |
6705
|
1828 else if (name.compare ("cdata")) |
|
1829 cdata = val; |
|
1830 else if (name.compare ("xdata")) |
|
1831 xdata = val; |
|
1832 else if (name.compare ("ydata")) |
|
1833 ydata = val; |
|
1834 else |
6406
|
1835 { |
6705
|
1836 modified = false; |
|
1837 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1838 } |
|
1839 |
6705
|
1840 if (modified) |
|
1841 mark_modified (); |
|
1842 } |
6406
|
1843 |
6705
|
1844 octave_value |
|
1845 image::image_properties::get (void) const |
|
1846 { |
|
1847 Octave_map m; |
6406
|
1848 |
6705
|
1849 m.assign ("type", type); |
|
1850 m.assign ("parent", parent); |
|
1851 m.assign ("children", children); |
|
1852 m.assign ("__modified__", __modified__); |
|
1853 m.assign ("cdata", cdata); |
|
1854 m.assign ("xdata", xdata); |
|
1855 m.assign ("ydata", ydata); |
6406
|
1856 |
6705
|
1857 return m; |
|
1858 } |
6406
|
1859 |
6705
|
1860 octave_value |
|
1861 image::image_properties::get (const property_name& name) const |
|
1862 { |
|
1863 octave_value retval; |
6406
|
1864 |
6705
|
1865 if (name.compare ("type")) |
|
1866 retval = type; |
|
1867 else if (name.compare ("parent")) |
|
1868 retval = parent; |
|
1869 else if (name.compare ("children")) |
|
1870 retval = children; |
|
1871 else if (name.compare ("__modified__")) |
|
1872 retval = __modified__; |
|
1873 else if (name.compare ("cdata")) |
|
1874 retval = cdata; |
|
1875 else if (name.compare ("xdata")) |
|
1876 retval = xdata; |
|
1877 else if (name.compare ("ydata")) |
|
1878 retval = ydata; |
|
1879 else |
|
1880 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1881 |
6705
|
1882 return retval; |
|
1883 } |
6406
|
1884 |
6705
|
1885 property_list::pval_map_type image::image_properties::factory_defaults (void) |
|
1886 { |
|
1887 property_list::pval_map_type m; |
6406
|
1888 |
6705
|
1889 m["cdata"] = Matrix (); |
|
1890 m["xdata"] = Matrix (); |
|
1891 m["ydata"] = Matrix (); |
6406
|
1892 |
6705
|
1893 return m; |
|
1894 } |
6406
|
1895 |
|
1896 std::string image::image_properties::go_name ("image"); |
|
1897 |
|
1898 // --------------------------------------------------------------------- |
|
1899 |
6705
|
1900 surface::surface_properties::surface_properties (const graphics_handle& mh, |
|
1901 const graphics_handle& p) |
|
1902 : base_properties (go_name, mh, p), |
|
1903 xdata (Matrix ()), |
|
1904 ydata (Matrix ()), |
|
1905 zdata (Matrix ()), |
|
1906 keylabel ("") |
|
1907 { } |
|
1908 |
|
1909 void |
|
1910 surface::surface_properties::set (const property_name& name, |
|
1911 const octave_value& val) |
6406
|
1912 { |
6705
|
1913 bool modified = true; |
6432
|
1914 |
6705
|
1915 if (name.compare ("parent")) |
|
1916 set_parent (val); |
|
1917 else if (name.compare ("children")) |
|
1918 children = maybe_set_children (children, val); |
|
1919 else if (name.compare ("__modified__")) |
|
1920 { |
|
1921 __modified__ = val.bool_value (); |
|
1922 modified = false; |
6406
|
1923 } |
6705
|
1924 else if (name.compare ("xdata")) |
|
1925 xdata = val; |
|
1926 else if (name.compare ("ydata")) |
|
1927 ydata = val; |
|
1928 else if (name.compare ("zdata")) |
|
1929 zdata = val; |
|
1930 else if (name.compare ("keylabel")) |
|
1931 keylabel = val; |
|
1932 else |
6406
|
1933 { |
6705
|
1934 modified = false; |
|
1935 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1936 } |
|
1937 |
6705
|
1938 if (modified) |
|
1939 mark_modified (); |
|
1940 } |
6406
|
1941 |
6705
|
1942 octave_value |
|
1943 surface::surface_properties::get (void) const |
|
1944 { |
|
1945 Octave_map m; |
6406
|
1946 |
6705
|
1947 m.assign ("type", type); |
|
1948 m.assign ("parent", parent); |
|
1949 m.assign ("children", children); |
|
1950 m.assign ("__modified__", __modified__); |
|
1951 m.assign ("xdata", xdata); |
|
1952 m.assign ("ydata", ydata); |
|
1953 m.assign ("zdata", zdata); |
|
1954 m.assign ("keylabel", keylabel); |
6406
|
1955 |
6705
|
1956 return m; |
|
1957 } |
6406
|
1958 |
6705
|
1959 octave_value |
|
1960 surface::surface_properties::get (const property_name& name) const |
|
1961 { |
|
1962 octave_value retval; |
6406
|
1963 |
6705
|
1964 if (name.compare ("type")) |
|
1965 retval = type; |
|
1966 else if (name.compare ("parent")) |
|
1967 retval = parent; |
|
1968 else if (name.compare ("children")) |
|
1969 retval = children; |
|
1970 else if (name.compare ("__modified__")) |
|
1971 retval = __modified__; |
|
1972 else if (name.compare ("xdata")) |
|
1973 retval = xdata; |
|
1974 else if (name.compare ("ydata")) |
|
1975 retval = ydata; |
|
1976 else if (name.compare ("zdata")) |
|
1977 retval = zdata; |
|
1978 else if (name.compare ("keylabel")) |
|
1979 retval = keylabel; |
|
1980 else |
|
1981 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1982 |
6705
|
1983 return retval; |
|
1984 } |
6406
|
1985 |
6705
|
1986 property_list::pval_map_type |
|
1987 surface::surface_properties::factory_defaults (void) |
|
1988 { |
|
1989 property_list::pval_map_type m; |
6406
|
1990 |
6705
|
1991 m["xdata"] = Matrix (); |
|
1992 m["ydata"] = Matrix (); |
|
1993 m["zdata"] = Matrix (); |
|
1994 m["keylabel"] = ""; |
6406
|
1995 |
6705
|
1996 return m; |
|
1997 } |
6406
|
1998 |
|
1999 std::string surface::surface_properties::go_name ("surface"); |
|
2000 |
|
2001 // --------------------------------------------------------------------- |
|
2002 |
|
2003 octave_value |
|
2004 base_graphics_object::get_default (const property_name& name) const |
|
2005 { |
|
2006 graphics_handle parent = get_parent (); |
|
2007 graphics_object parent_obj = gh_manager::get_object (parent); |
|
2008 |
|
2009 return parent_obj.get_default (type () + name); |
|
2010 } |
|
2011 |
|
2012 octave_value |
|
2013 base_graphics_object::get_factory_default (const property_name& name) const |
|
2014 { |
|
2015 graphics_object parent_obj = gh_manager::get_object (0); |
|
2016 |
|
2017 return parent_obj.get_factory_default (type () + name); |
|
2018 } |
|
2019 |
|
2020 gh_manager::gh_manager (void) |
|
2021 : handle_map (), handle_free_list (), next_handle (-1) |
|
2022 { |
|
2023 handle_map[0] = graphics_object (new root_figure ()); |
|
2024 } |
|
2025 |
|
2026 graphics_handle |
|
2027 gh_manager::do_make_graphics_handle (const std::string& go_name, |
|
2028 const graphics_handle& p) |
|
2029 { |
|
2030 graphics_handle h = get_handle (go_name); |
|
2031 |
|
2032 base_graphics_object *go = 0; |
|
2033 |
|
2034 if (go_name == "figure") |
|
2035 go = new figure (h, p); |
|
2036 else if (go_name == "axes") |
|
2037 go = new axes (h, p); |
|
2038 else if (go_name == "line") |
|
2039 go = new line (h, p); |
|
2040 else if (go_name == "text") |
|
2041 go = new text (h, p); |
|
2042 else if (go_name == "image") |
|
2043 go = new image (h, p); |
|
2044 else if (go_name == "surface") |
|
2045 go = new surface (h, p); |
|
2046 |
|
2047 if (go) |
|
2048 handle_map[h] = graphics_object (go); |
|
2049 else |
|
2050 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
|
2051 go_name.c_str ()); |
|
2052 |
|
2053 return h; |
|
2054 } |
|
2055 |
|
2056 graphics_handle |
|
2057 gh_manager::do_make_figure_handle (double val) |
|
2058 { |
|
2059 graphics_handle h = val; |
|
2060 |
|
2061 handle_map[h] = graphics_object (new figure (h, 0)); |
|
2062 |
|
2063 return h; |
|
2064 } |
|
2065 |
|
2066 void |
|
2067 gh_manager::do_push_figure (const graphics_handle& h) |
|
2068 { |
|
2069 do_pop_figure (h); |
|
2070 |
|
2071 figure_list.push_front (h); |
|
2072 } |
|
2073 |
|
2074 void |
|
2075 gh_manager::do_pop_figure (const graphics_handle& h) |
|
2076 { |
|
2077 for (figure_list_iterator p = figure_list.begin (); |
|
2078 p != figure_list.end (); |
|
2079 p++) |
|
2080 { |
|
2081 if (*p == h) |
|
2082 { |
|
2083 figure_list.erase (p); |
|
2084 break; |
|
2085 } |
|
2086 } |
|
2087 } |
|
2088 |
|
2089 property_list::plist_map_type |
|
2090 root_figure::init_factory_properties (void) |
|
2091 { |
|
2092 property_list::plist_map_type plist_map; |
|
2093 |
|
2094 plist_map["figure"] = figure::figure_properties::factory_defaults (); |
|
2095 plist_map["axes"] = axes::axes_properties::factory_defaults (); |
|
2096 plist_map["line"] = line::line_properties::factory_defaults (); |
|
2097 plist_map["text"] = text::text_properties::factory_defaults (); |
|
2098 plist_map["image"] = image::image_properties::factory_defaults (); |
|
2099 plist_map["surface"] = surface::surface_properties::factory_defaults (); |
|
2100 |
|
2101 return plist_map; |
|
2102 } |
|
2103 |
|
2104 // --------------------------------------------------------------------- |
|
2105 |
|
2106 DEFUN (ishandle, args, , |
|
2107 "-*- texinfo -*-\n\ |
6678
|
2108 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406
|
2109 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
|
2110 @end deftypefn") |
|
2111 { |
|
2112 octave_value retval; |
|
2113 |
|
2114 if (args.length () == 1) |
|
2115 retval = is_handle (args(0)); |
|
2116 else |
|
2117 print_usage (); |
|
2118 |
|
2119 return retval; |
|
2120 } |
|
2121 |
|
2122 DEFUN (set, args, , |
|
2123 "-*- texinfo -*-\n\ |
6678
|
2124 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6406
|
2125 Set the named property @var{p} to the value @var{v} in the graphics\n\ |
|
2126 handle @var{h}.\n\ |
|
2127 @end deftypefn") |
|
2128 { |
|
2129 octave_value retval; |
|
2130 |
|
2131 int nargin = args.length (); |
|
2132 |
|
2133 if (nargin > 0) |
|
2134 { |
|
2135 double handle = args(0).double_value (); |
|
2136 |
|
2137 if (! error_state) |
|
2138 { |
|
2139 graphics_object obj = gh_manager::get_object (handle); |
|
2140 |
|
2141 if (obj) |
|
2142 { |
|
2143 obj.set (args.splice (0, 1)); |
|
2144 |
|
2145 feval ("__request_drawnow__"); |
|
2146 } |
|
2147 else |
|
2148 error ("set: invalid handle (= %g)", handle); |
|
2149 } |
|
2150 else |
|
2151 error ("set: expecting graphics handle as first argument"); |
|
2152 } |
|
2153 else |
|
2154 print_usage (); |
|
2155 |
|
2156 return retval; |
|
2157 } |
|
2158 |
|
2159 DEFUN (get, args, , |
|
2160 "-*- texinfo -*-\n\ |
6678
|
2161 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406
|
2162 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
|
2163 If @var{p} is omitted, return the complete property list for @var{h}.\n\ |
|
2164 @end deftypefn") |
|
2165 { |
|
2166 octave_value retval; |
|
2167 |
|
2168 int nargin = args.length (); |
|
2169 |
|
2170 if (nargin == 1 || nargin == 2) |
|
2171 { |
|
2172 double handle = args(0).double_value (); |
|
2173 |
|
2174 if (! error_state) |
|
2175 { |
|
2176 graphics_object obj = gh_manager::get_object (handle); |
|
2177 |
|
2178 if (obj) |
|
2179 { |
|
2180 if (nargin == 1) |
|
2181 retval = obj.get (); |
|
2182 else |
|
2183 { |
|
2184 property_name property = args(1).string_value (); |
|
2185 |
|
2186 if (! error_state) |
|
2187 retval = obj.get (property); |
|
2188 else |
|
2189 error ("get: expecting property name as second argument"); |
|
2190 } |
|
2191 } |
|
2192 else |
|
2193 error ("get: invalid handle (= %g)", handle); |
|
2194 } |
|
2195 else |
|
2196 error ("get: expecting graphics handle as first argument"); |
|
2197 } |
|
2198 else |
|
2199 print_usage (); |
|
2200 |
|
2201 return retval; |
|
2202 } |
|
2203 |
|
2204 static octave_value |
|
2205 make_graphics_object (const std::string& go_name, |
|
2206 const octave_value_list& args) |
|
2207 { |
|
2208 octave_value retval; |
|
2209 |
|
2210 double val = args(0).double_value (); |
|
2211 |
|
2212 if (! error_state) |
|
2213 { |
|
2214 graphics_handle parent = gh_manager::lookup (val); |
|
2215 |
|
2216 if (! xisnan (parent)) |
|
2217 { |
|
2218 graphics_handle h |
|
2219 = gh_manager::make_graphics_handle (go_name, parent); |
|
2220 |
|
2221 if (! error_state) |
|
2222 { |
|
2223 adopt (parent, h); |
|
2224 |
|
2225 xset (h, args.splice (0, 1)); |
|
2226 |
|
2227 retval = h; |
|
2228 } |
|
2229 else |
|
2230 error ("__go%s__: unable to create graphics handle", |
|
2231 go_name.c_str ()); |
|
2232 } |
|
2233 else |
|
2234 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2235 } |
|
2236 else |
|
2237 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2238 |
|
2239 return retval; |
|
2240 } |
|
2241 |
|
2242 DEFUN (__go_figure__, args, , |
|
2243 "-*- texinfo -*-\n\ |
|
2244 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ |
|
2245 Create a figure graphics object.\n\ |
|
2246 @end deftypefn") |
|
2247 { |
|
2248 octave_value retval; |
|
2249 |
|
2250 if (args.length () > 0) |
|
2251 { |
|
2252 double val = args(0).double_value (); |
|
2253 |
|
2254 if (! error_state) |
|
2255 { |
|
2256 if (is_figure (val)) |
|
2257 { |
|
2258 graphics_handle h = gh_manager::lookup (val); |
|
2259 |
|
2260 xset (h, args.splice (0, 1)); |
|
2261 |
|
2262 retval = h; |
|
2263 } |
|
2264 else |
|
2265 { |
|
2266 graphics_handle h = octave_NaN; |
|
2267 |
|
2268 if (xisnan (val)) |
|
2269 h = gh_manager::make_graphics_handle ("figure", 0); |
|
2270 else if (val > 0 && D_NINT (val) == val) |
|
2271 h = gh_manager::make_figure_handle (val); |
|
2272 else |
|
2273 error ("__go_figure__: invalid figure number"); |
|
2274 |
|
2275 if (! (error_state || xisnan (h))) |
|
2276 { |
|
2277 adopt (0, h); |
|
2278 |
|
2279 xset (h, args.splice (0, 1)); |
|
2280 |
|
2281 retval = h; |
|
2282 } |
|
2283 else |
|
2284 error ("__go_figure__: failed to create figure handle"); |
|
2285 } |
|
2286 } |
|
2287 else |
|
2288 error ("__go_figure__: expecting figure number to be double value"); |
|
2289 } |
|
2290 else |
|
2291 print_usage (); |
|
2292 |
|
2293 return retval; |
|
2294 } |
|
2295 |
|
2296 #define GO_BODY(TYPE) \ |
|
2297 octave_value retval; \ |
|
2298 \ |
|
2299 if (args.length () > 0) \ |
|
2300 retval = make_graphics_object (#TYPE, args); \ |
|
2301 else \ |
|
2302 print_usage (); \ |
|
2303 \ |
|
2304 return retval |
|
2305 |
|
2306 DEFUN (__go_axes__, args, , |
|
2307 "-*- texinfo -*-\n\ |
|
2308 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ |
|
2309 Create an axes graphics object.\n\ |
|
2310 @end deftypefn") |
|
2311 { |
|
2312 GO_BODY (axes); |
|
2313 } |
|
2314 |
|
2315 DEFUN (__go_line__, args, , |
|
2316 "-*- texinfo -*-\n\ |
|
2317 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ |
|
2318 Create a line graphics object.\n\ |
|
2319 @end deftypefn") |
|
2320 { |
|
2321 GO_BODY (line); |
|
2322 } |
|
2323 |
|
2324 DEFUN (__go_text__, args, , |
|
2325 "-*- texinfo -*-\n\ |
|
2326 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ |
|
2327 Create a text graphics object.\n\ |
|
2328 @end deftypefn") |
|
2329 { |
|
2330 GO_BODY (text); |
|
2331 } |
|
2332 |
|
2333 DEFUN (__go_image__, args, , |
|
2334 "-*- texinfo -*-\n\ |
|
2335 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ |
|
2336 Create an image graphics object.\n\ |
|
2337 @end deftypefn") |
|
2338 { |
|
2339 GO_BODY (image); |
|
2340 } |
|
2341 |
|
2342 DEFUN (__go_surface__, args, , |
|
2343 "-*- texinfo -*-\n\ |
|
2344 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ |
|
2345 Create a surface graphics object.\n\ |
|
2346 @end deftypefn") |
|
2347 { |
|
2348 GO_BODY (surface); |
|
2349 } |
|
2350 |
|
2351 DEFUN (__go_delete__, args, , |
|
2352 "-*- texinfo -*-\n\ |
|
2353 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ |
|
2354 @end deftypefn") |
|
2355 { |
|
2356 octave_value_list retval; |
|
2357 |
|
2358 if (args.length () == 1) |
|
2359 { |
|
2360 graphics_handle h = octave_NaN; |
|
2361 |
|
2362 double val = args(0).double_value (); |
|
2363 |
|
2364 if (! error_state) |
|
2365 { |
|
2366 h = gh_manager::lookup (val); |
|
2367 |
|
2368 if (! xisnan (h)) |
|
2369 { |
|
2370 graphics_object obj = gh_manager::get_object (h); |
|
2371 |
|
2372 graphics_handle parent_h = obj.get_parent (); |
|
2373 |
|
2374 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
2375 |
|
2376 parent_obj.remove_child (h); |
|
2377 |
|
2378 gh_manager::free (h); |
|
2379 } |
|
2380 else |
|
2381 error ("delete: invalid graphics object (= %g)", val); |
|
2382 } |
|
2383 else |
|
2384 error ("delete: invalid graphics object"); |
|
2385 } |
|
2386 else |
|
2387 print_usage (); |
|
2388 |
|
2389 return retval; |
|
2390 } |
|
2391 |
|
2392 DEFUN (__go_axes_init__, args, , |
|
2393 "-*- texinfo -*-\n\ |
|
2394 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ |
|
2395 Initialize axes object.\n\ |
|
2396 @end deftypefn") |
|
2397 { |
|
2398 octave_value retval; |
|
2399 |
|
2400 int nargin = args.length (); |
|
2401 |
|
2402 std::string mode = ""; |
|
2403 |
|
2404 if (nargin == 2) |
|
2405 { |
|
2406 mode = args(1).string_value (); |
|
2407 |
|
2408 if (error_state) |
|
2409 return retval; |
|
2410 } |
|
2411 |
|
2412 if (nargin == 1 || nargin == 2) |
|
2413 { |
|
2414 graphics_handle h = octave_NaN; |
|
2415 |
|
2416 double val = args(0).double_value (); |
|
2417 |
|
2418 if (! error_state) |
|
2419 { |
|
2420 h = gh_manager::lookup (val); |
|
2421 |
|
2422 if (! xisnan (h)) |
|
2423 { |
|
2424 graphics_object obj = gh_manager::get_object (h); |
|
2425 |
|
2426 obj.set_defaults (mode); |
|
2427 } |
|
2428 else |
|
2429 error ("__go_axes_init__: invalid graphics object (= %g)", val); |
|
2430 } |
|
2431 else |
|
2432 error ("__go_axes_init__: invalid graphics object"); |
|
2433 } |
|
2434 else |
|
2435 print_usage (); |
|
2436 |
|
2437 return retval; |
|
2438 } |
|
2439 |
|
2440 DEFUN (__go_handles__, , , |
|
2441 "-*- texinfo -*-\n\ |
|
2442 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ |
|
2443 Return current list of function handles.\n\ |
|
2444 @end deftypefn") |
|
2445 { |
6425
|
2446 return octave_value (gh_manager::handle_list ()); |
|
2447 } |
|
2448 |
|
2449 DEFUN (__go_figure_handles__, , , |
|
2450 "-*- texinfo -*-\n\ |
|
2451 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ |
|
2452 Return current list of function handles.\n\ |
|
2453 @end deftypefn") |
|
2454 { |
|
2455 return octave_value (gh_manager::figure_handle_list ()); |
6406
|
2456 } |
|
2457 |
6595
|
2458 octave_value |
|
2459 get_property_from_handle (double handle, const std::string &property, |
|
2460 const std::string &func) |
|
2461 { |
|
2462 graphics_object obj = gh_manager::get_object (handle); |
|
2463 octave_value retval; |
|
2464 |
|
2465 if (obj) |
|
2466 { |
|
2467 property_name p = std::string (property); |
|
2468 retval = obj.get (p); |
|
2469 } |
|
2470 else |
|
2471 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2472 |
|
2473 return retval; |
|
2474 } |
|
2475 |
|
2476 bool |
|
2477 set_property_in_handle (double handle, const std::string &property, |
|
2478 const octave_value &arg, const std::string &func) |
|
2479 { |
|
2480 graphics_object obj = gh_manager::get_object (handle); |
|
2481 int ret = false; |
|
2482 |
|
2483 if (obj) |
|
2484 { |
|
2485 property_name p = std::string (property); |
|
2486 obj.set (p, arg); |
|
2487 if (!error_state) |
|
2488 ret = true; |
|
2489 } |
|
2490 else |
|
2491 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2492 |
|
2493 return ret; |
|
2494 } |
|
2495 |
6406
|
2496 /* |
|
2497 ;;; Local Variables: *** |
|
2498 ;;; mode: C++ *** |
|
2499 ;;; End: *** |
|
2500 */ |