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