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)), |
6724
|
1709 rotation (0), |
6705
|
1710 horizontalalignment ("left") |
|
1711 { } |
|
1712 |
|
1713 void |
|
1714 text::text_properties::set (const property_name& name, const octave_value& val) |
6406
|
1715 { |
6705
|
1716 bool modified = true; |
6432
|
1717 |
6705
|
1718 if (name.compare ("parent")) |
|
1719 set_parent (val); |
|
1720 else if (name.compare ("children")) |
|
1721 children = maybe_set_children (children, val); |
|
1722 else if (name.compare ("__modified__")) |
|
1723 { |
|
1724 __modified__ = val.bool_value (); |
|
1725 modified = false; |
6406
|
1726 } |
6705
|
1727 else if (name.compare ("string")) |
|
1728 string = val; |
|
1729 else if (name.compare ("units")) |
|
1730 units = val; |
|
1731 else if (name.compare ("position")) |
|
1732 position = val; |
6724
|
1733 else if (name.compare ("rotation")) |
|
1734 rotation = val; |
6705
|
1735 else if (name.compare ("horizontalalignment")) |
|
1736 horizontalalignment = val; |
|
1737 else |
6406
|
1738 { |
6705
|
1739 modified = false; |
|
1740 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1741 } |
|
1742 |
6705
|
1743 if (modified) |
|
1744 mark_modified (); |
|
1745 } |
6406
|
1746 |
6705
|
1747 octave_value |
|
1748 text::text_properties::get (void) const |
|
1749 { |
|
1750 Octave_map m; |
6406
|
1751 |
6705
|
1752 m.assign ("type", type); |
|
1753 m.assign ("parent", parent); |
|
1754 m.assign ("children", children); |
|
1755 m.assign ("__modified__", __modified__); |
|
1756 m.assign ("string", string); |
|
1757 m.assign ("units", units); |
|
1758 m.assign ("position", position); |
6724
|
1759 m.assign ("rotation", rotation); |
6705
|
1760 m.assign ("horizontalalignment", horizontalalignment); |
6406
|
1761 |
6705
|
1762 return m; |
|
1763 } |
6406
|
1764 |
6705
|
1765 octave_value |
|
1766 text::text_properties::get (const property_name& name) const |
|
1767 { |
|
1768 octave_value retval; |
6406
|
1769 |
6705
|
1770 if (name.compare ("type")) |
|
1771 retval = type; |
|
1772 else if (name.compare ("parent")) |
|
1773 retval = parent; |
|
1774 else if (name.compare ("children")) |
|
1775 retval = children; |
|
1776 else if (name.compare ("__modified__")) |
|
1777 retval = __modified__; |
|
1778 else if (name.compare ("string")) |
|
1779 retval = string; |
|
1780 else if (name.compare ("units")) |
|
1781 retval = units; |
|
1782 else if (name.compare ("position")) |
|
1783 retval = position; |
6724
|
1784 else if (name.compare ("rotation")) |
|
1785 retval = rotation; |
6705
|
1786 else if (name.compare ("horizontalalignment")) |
|
1787 retval = horizontalalignment; |
|
1788 else |
|
1789 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1790 |
6705
|
1791 return retval; |
|
1792 } |
6406
|
1793 |
6705
|
1794 property_list::pval_map_type |
|
1795 text::text_properties::factory_defaults (void) |
|
1796 { |
|
1797 property_list::pval_map_type m; |
6406
|
1798 |
6705
|
1799 m["string"] = ""; |
|
1800 m["units"] = "data"; |
|
1801 m["position"] = Matrix (1, 3, 0.0); |
6724
|
1802 m["rotation"] = 0; |
6705
|
1803 m["horizontalalignment"] = "left"; |
6406
|
1804 |
6705
|
1805 return m; |
|
1806 } |
6406
|
1807 |
|
1808 std::string text::text_properties::go_name ("text"); |
|
1809 |
|
1810 // --------------------------------------------------------------------- |
|
1811 |
6705
|
1812 image::image_properties::image_properties (const graphics_handle& mh, |
|
1813 const graphics_handle& p) |
|
1814 : base_properties (go_name, mh, p), |
|
1815 cdata (Matrix ()), |
|
1816 xdata (Matrix ()), |
|
1817 ydata (Matrix ()) |
|
1818 { } |
|
1819 |
|
1820 void |
|
1821 image::image_properties::set (const property_name& name, |
|
1822 const octave_value& val) |
6406
|
1823 { |
6705
|
1824 bool modified = true; |
6432
|
1825 |
6705
|
1826 if (name.compare ("parent")) |
|
1827 set_parent (val); |
|
1828 else if (name.compare ("children")) |
|
1829 children = maybe_set_children (children, val); |
|
1830 else if (name.compare ("__modified__")) |
|
1831 { |
|
1832 __modified__ = val.bool_value (); |
|
1833 modified = false; |
6406
|
1834 } |
6705
|
1835 else if (name.compare ("cdata")) |
|
1836 cdata = val; |
|
1837 else if (name.compare ("xdata")) |
|
1838 xdata = val; |
|
1839 else if (name.compare ("ydata")) |
|
1840 ydata = val; |
|
1841 else |
6406
|
1842 { |
6705
|
1843 modified = false; |
|
1844 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1845 } |
|
1846 |
6705
|
1847 if (modified) |
|
1848 mark_modified (); |
|
1849 } |
6406
|
1850 |
6705
|
1851 octave_value |
|
1852 image::image_properties::get (void) const |
|
1853 { |
|
1854 Octave_map m; |
6406
|
1855 |
6705
|
1856 m.assign ("type", type); |
|
1857 m.assign ("parent", parent); |
|
1858 m.assign ("children", children); |
|
1859 m.assign ("__modified__", __modified__); |
|
1860 m.assign ("cdata", cdata); |
|
1861 m.assign ("xdata", xdata); |
|
1862 m.assign ("ydata", ydata); |
6406
|
1863 |
6705
|
1864 return m; |
|
1865 } |
6406
|
1866 |
6705
|
1867 octave_value |
|
1868 image::image_properties::get (const property_name& name) const |
|
1869 { |
|
1870 octave_value retval; |
6406
|
1871 |
6705
|
1872 if (name.compare ("type")) |
|
1873 retval = type; |
|
1874 else if (name.compare ("parent")) |
|
1875 retval = parent; |
|
1876 else if (name.compare ("children")) |
|
1877 retval = children; |
|
1878 else if (name.compare ("__modified__")) |
|
1879 retval = __modified__; |
|
1880 else if (name.compare ("cdata")) |
|
1881 retval = cdata; |
|
1882 else if (name.compare ("xdata")) |
|
1883 retval = xdata; |
|
1884 else if (name.compare ("ydata")) |
|
1885 retval = ydata; |
|
1886 else |
|
1887 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1888 |
6705
|
1889 return retval; |
|
1890 } |
6406
|
1891 |
6705
|
1892 property_list::pval_map_type image::image_properties::factory_defaults (void) |
|
1893 { |
|
1894 property_list::pval_map_type m; |
6406
|
1895 |
6705
|
1896 m["cdata"] = Matrix (); |
|
1897 m["xdata"] = Matrix (); |
|
1898 m["ydata"] = Matrix (); |
6406
|
1899 |
6705
|
1900 return m; |
|
1901 } |
6406
|
1902 |
|
1903 std::string image::image_properties::go_name ("image"); |
|
1904 |
|
1905 // --------------------------------------------------------------------- |
|
1906 |
6705
|
1907 surface::surface_properties::surface_properties (const graphics_handle& mh, |
|
1908 const graphics_handle& p) |
|
1909 : base_properties (go_name, mh, p), |
|
1910 xdata (Matrix ()), |
|
1911 ydata (Matrix ()), |
|
1912 zdata (Matrix ()), |
|
1913 keylabel ("") |
|
1914 { } |
|
1915 |
|
1916 void |
|
1917 surface::surface_properties::set (const property_name& name, |
|
1918 const octave_value& val) |
6406
|
1919 { |
6705
|
1920 bool modified = true; |
6432
|
1921 |
6705
|
1922 if (name.compare ("parent")) |
|
1923 set_parent (val); |
|
1924 else if (name.compare ("children")) |
|
1925 children = maybe_set_children (children, val); |
|
1926 else if (name.compare ("__modified__")) |
|
1927 { |
|
1928 __modified__ = val.bool_value (); |
|
1929 modified = false; |
6406
|
1930 } |
6705
|
1931 else if (name.compare ("xdata")) |
|
1932 xdata = val; |
|
1933 else if (name.compare ("ydata")) |
|
1934 ydata = val; |
|
1935 else if (name.compare ("zdata")) |
|
1936 zdata = val; |
|
1937 else if (name.compare ("keylabel")) |
|
1938 keylabel = val; |
|
1939 else |
6406
|
1940 { |
6705
|
1941 modified = false; |
|
1942 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1943 } |
|
1944 |
6705
|
1945 if (modified) |
|
1946 mark_modified (); |
|
1947 } |
6406
|
1948 |
6705
|
1949 octave_value |
|
1950 surface::surface_properties::get (void) const |
|
1951 { |
|
1952 Octave_map m; |
6406
|
1953 |
6705
|
1954 m.assign ("type", type); |
|
1955 m.assign ("parent", parent); |
|
1956 m.assign ("children", children); |
|
1957 m.assign ("__modified__", __modified__); |
|
1958 m.assign ("xdata", xdata); |
|
1959 m.assign ("ydata", ydata); |
|
1960 m.assign ("zdata", zdata); |
|
1961 m.assign ("keylabel", keylabel); |
6406
|
1962 |
6705
|
1963 return m; |
|
1964 } |
6406
|
1965 |
6705
|
1966 octave_value |
|
1967 surface::surface_properties::get (const property_name& name) const |
|
1968 { |
|
1969 octave_value retval; |
6406
|
1970 |
6705
|
1971 if (name.compare ("type")) |
|
1972 retval = type; |
|
1973 else if (name.compare ("parent")) |
|
1974 retval = parent; |
|
1975 else if (name.compare ("children")) |
|
1976 retval = children; |
|
1977 else if (name.compare ("__modified__")) |
|
1978 retval = __modified__; |
|
1979 else if (name.compare ("xdata")) |
|
1980 retval = xdata; |
|
1981 else if (name.compare ("ydata")) |
|
1982 retval = ydata; |
|
1983 else if (name.compare ("zdata")) |
|
1984 retval = zdata; |
|
1985 else if (name.compare ("keylabel")) |
|
1986 retval = keylabel; |
|
1987 else |
|
1988 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1989 |
6705
|
1990 return retval; |
|
1991 } |
6406
|
1992 |
6705
|
1993 property_list::pval_map_type |
|
1994 surface::surface_properties::factory_defaults (void) |
|
1995 { |
|
1996 property_list::pval_map_type m; |
6406
|
1997 |
6705
|
1998 m["xdata"] = Matrix (); |
|
1999 m["ydata"] = Matrix (); |
|
2000 m["zdata"] = Matrix (); |
|
2001 m["keylabel"] = ""; |
6406
|
2002 |
6705
|
2003 return m; |
|
2004 } |
6406
|
2005 |
|
2006 std::string surface::surface_properties::go_name ("surface"); |
|
2007 |
|
2008 // --------------------------------------------------------------------- |
|
2009 |
|
2010 octave_value |
|
2011 base_graphics_object::get_default (const property_name& name) const |
|
2012 { |
|
2013 graphics_handle parent = get_parent (); |
|
2014 graphics_object parent_obj = gh_manager::get_object (parent); |
|
2015 |
|
2016 return parent_obj.get_default (type () + name); |
|
2017 } |
|
2018 |
|
2019 octave_value |
|
2020 base_graphics_object::get_factory_default (const property_name& name) const |
|
2021 { |
|
2022 graphics_object parent_obj = gh_manager::get_object (0); |
|
2023 |
|
2024 return parent_obj.get_factory_default (type () + name); |
|
2025 } |
|
2026 |
|
2027 gh_manager::gh_manager (void) |
|
2028 : handle_map (), handle_free_list (), next_handle (-1) |
|
2029 { |
|
2030 handle_map[0] = graphics_object (new root_figure ()); |
|
2031 } |
|
2032 |
|
2033 graphics_handle |
|
2034 gh_manager::do_make_graphics_handle (const std::string& go_name, |
|
2035 const graphics_handle& p) |
|
2036 { |
|
2037 graphics_handle h = get_handle (go_name); |
|
2038 |
|
2039 base_graphics_object *go = 0; |
|
2040 |
|
2041 if (go_name == "figure") |
|
2042 go = new figure (h, p); |
|
2043 else if (go_name == "axes") |
|
2044 go = new axes (h, p); |
|
2045 else if (go_name == "line") |
|
2046 go = new line (h, p); |
|
2047 else if (go_name == "text") |
|
2048 go = new text (h, p); |
|
2049 else if (go_name == "image") |
|
2050 go = new image (h, p); |
|
2051 else if (go_name == "surface") |
|
2052 go = new surface (h, p); |
|
2053 |
|
2054 if (go) |
|
2055 handle_map[h] = graphics_object (go); |
|
2056 else |
|
2057 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
|
2058 go_name.c_str ()); |
|
2059 |
|
2060 return h; |
|
2061 } |
|
2062 |
|
2063 graphics_handle |
|
2064 gh_manager::do_make_figure_handle (double val) |
|
2065 { |
|
2066 graphics_handle h = val; |
|
2067 |
|
2068 handle_map[h] = graphics_object (new figure (h, 0)); |
|
2069 |
|
2070 return h; |
|
2071 } |
|
2072 |
|
2073 void |
|
2074 gh_manager::do_push_figure (const graphics_handle& h) |
|
2075 { |
|
2076 do_pop_figure (h); |
|
2077 |
|
2078 figure_list.push_front (h); |
|
2079 } |
|
2080 |
|
2081 void |
|
2082 gh_manager::do_pop_figure (const graphics_handle& h) |
|
2083 { |
|
2084 for (figure_list_iterator p = figure_list.begin (); |
|
2085 p != figure_list.end (); |
|
2086 p++) |
|
2087 { |
|
2088 if (*p == h) |
|
2089 { |
|
2090 figure_list.erase (p); |
|
2091 break; |
|
2092 } |
|
2093 } |
|
2094 } |
|
2095 |
|
2096 property_list::plist_map_type |
|
2097 root_figure::init_factory_properties (void) |
|
2098 { |
|
2099 property_list::plist_map_type plist_map; |
|
2100 |
|
2101 plist_map["figure"] = figure::figure_properties::factory_defaults (); |
|
2102 plist_map["axes"] = axes::axes_properties::factory_defaults (); |
|
2103 plist_map["line"] = line::line_properties::factory_defaults (); |
|
2104 plist_map["text"] = text::text_properties::factory_defaults (); |
|
2105 plist_map["image"] = image::image_properties::factory_defaults (); |
|
2106 plist_map["surface"] = surface::surface_properties::factory_defaults (); |
|
2107 |
|
2108 return plist_map; |
|
2109 } |
|
2110 |
|
2111 // --------------------------------------------------------------------- |
|
2112 |
|
2113 DEFUN (ishandle, args, , |
|
2114 "-*- texinfo -*-\n\ |
6678
|
2115 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406
|
2116 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
|
2117 @end deftypefn") |
|
2118 { |
|
2119 octave_value retval; |
|
2120 |
|
2121 if (args.length () == 1) |
|
2122 retval = is_handle (args(0)); |
|
2123 else |
|
2124 print_usage (); |
|
2125 |
|
2126 return retval; |
|
2127 } |
|
2128 |
|
2129 DEFUN (set, args, , |
|
2130 "-*- texinfo -*-\n\ |
6678
|
2131 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6406
|
2132 Set the named property @var{p} to the value @var{v} in the graphics\n\ |
|
2133 handle @var{h}.\n\ |
|
2134 @end deftypefn") |
|
2135 { |
|
2136 octave_value retval; |
|
2137 |
|
2138 int nargin = args.length (); |
|
2139 |
|
2140 if (nargin > 0) |
|
2141 { |
|
2142 double handle = args(0).double_value (); |
|
2143 |
|
2144 if (! error_state) |
|
2145 { |
|
2146 graphics_object obj = gh_manager::get_object (handle); |
|
2147 |
|
2148 if (obj) |
|
2149 { |
|
2150 obj.set (args.splice (0, 1)); |
|
2151 |
|
2152 feval ("__request_drawnow__"); |
|
2153 } |
|
2154 else |
|
2155 error ("set: invalid handle (= %g)", handle); |
|
2156 } |
|
2157 else |
|
2158 error ("set: expecting graphics handle as first argument"); |
|
2159 } |
|
2160 else |
|
2161 print_usage (); |
|
2162 |
|
2163 return retval; |
|
2164 } |
|
2165 |
|
2166 DEFUN (get, args, , |
|
2167 "-*- texinfo -*-\n\ |
6678
|
2168 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406
|
2169 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
|
2170 If @var{p} is omitted, return the complete property list for @var{h}.\n\ |
|
2171 @end deftypefn") |
|
2172 { |
|
2173 octave_value retval; |
|
2174 |
|
2175 int nargin = args.length (); |
|
2176 |
|
2177 if (nargin == 1 || nargin == 2) |
|
2178 { |
|
2179 double handle = args(0).double_value (); |
|
2180 |
|
2181 if (! error_state) |
|
2182 { |
|
2183 graphics_object obj = gh_manager::get_object (handle); |
|
2184 |
|
2185 if (obj) |
|
2186 { |
|
2187 if (nargin == 1) |
|
2188 retval = obj.get (); |
|
2189 else |
|
2190 { |
|
2191 property_name property = args(1).string_value (); |
|
2192 |
|
2193 if (! error_state) |
|
2194 retval = obj.get (property); |
|
2195 else |
|
2196 error ("get: expecting property name as second argument"); |
|
2197 } |
|
2198 } |
|
2199 else |
|
2200 error ("get: invalid handle (= %g)", handle); |
|
2201 } |
|
2202 else |
|
2203 error ("get: expecting graphics handle as first argument"); |
|
2204 } |
|
2205 else |
|
2206 print_usage (); |
|
2207 |
|
2208 return retval; |
|
2209 } |
|
2210 |
|
2211 static octave_value |
|
2212 make_graphics_object (const std::string& go_name, |
|
2213 const octave_value_list& args) |
|
2214 { |
|
2215 octave_value retval; |
|
2216 |
|
2217 double val = args(0).double_value (); |
|
2218 |
|
2219 if (! error_state) |
|
2220 { |
|
2221 graphics_handle parent = gh_manager::lookup (val); |
|
2222 |
|
2223 if (! xisnan (parent)) |
|
2224 { |
|
2225 graphics_handle h |
|
2226 = gh_manager::make_graphics_handle (go_name, parent); |
|
2227 |
|
2228 if (! error_state) |
|
2229 { |
|
2230 adopt (parent, h); |
|
2231 |
|
2232 xset (h, args.splice (0, 1)); |
|
2233 |
|
2234 retval = h; |
|
2235 } |
|
2236 else |
|
2237 error ("__go%s__: unable to create graphics handle", |
|
2238 go_name.c_str ()); |
|
2239 } |
|
2240 else |
|
2241 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2242 } |
|
2243 else |
|
2244 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2245 |
|
2246 return retval; |
|
2247 } |
|
2248 |
|
2249 DEFUN (__go_figure__, args, , |
|
2250 "-*- texinfo -*-\n\ |
|
2251 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ |
|
2252 Create a figure graphics object.\n\ |
|
2253 @end deftypefn") |
|
2254 { |
|
2255 octave_value retval; |
|
2256 |
|
2257 if (args.length () > 0) |
|
2258 { |
|
2259 double val = args(0).double_value (); |
|
2260 |
|
2261 if (! error_state) |
|
2262 { |
|
2263 if (is_figure (val)) |
|
2264 { |
|
2265 graphics_handle h = gh_manager::lookup (val); |
|
2266 |
|
2267 xset (h, args.splice (0, 1)); |
|
2268 |
|
2269 retval = h; |
|
2270 } |
|
2271 else |
|
2272 { |
|
2273 graphics_handle h = octave_NaN; |
|
2274 |
|
2275 if (xisnan (val)) |
|
2276 h = gh_manager::make_graphics_handle ("figure", 0); |
|
2277 else if (val > 0 && D_NINT (val) == val) |
|
2278 h = gh_manager::make_figure_handle (val); |
|
2279 else |
|
2280 error ("__go_figure__: invalid figure number"); |
|
2281 |
|
2282 if (! (error_state || xisnan (h))) |
|
2283 { |
|
2284 adopt (0, h); |
|
2285 |
|
2286 xset (h, args.splice (0, 1)); |
|
2287 |
|
2288 retval = h; |
|
2289 } |
|
2290 else |
|
2291 error ("__go_figure__: failed to create figure handle"); |
|
2292 } |
|
2293 } |
|
2294 else |
|
2295 error ("__go_figure__: expecting figure number to be double value"); |
|
2296 } |
|
2297 else |
|
2298 print_usage (); |
|
2299 |
|
2300 return retval; |
|
2301 } |
|
2302 |
|
2303 #define GO_BODY(TYPE) \ |
|
2304 octave_value retval; \ |
|
2305 \ |
|
2306 if (args.length () > 0) \ |
|
2307 retval = make_graphics_object (#TYPE, args); \ |
|
2308 else \ |
|
2309 print_usage (); \ |
|
2310 \ |
|
2311 return retval |
|
2312 |
|
2313 DEFUN (__go_axes__, args, , |
|
2314 "-*- texinfo -*-\n\ |
|
2315 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ |
|
2316 Create an axes graphics object.\n\ |
|
2317 @end deftypefn") |
|
2318 { |
|
2319 GO_BODY (axes); |
|
2320 } |
|
2321 |
|
2322 DEFUN (__go_line__, args, , |
|
2323 "-*- texinfo -*-\n\ |
|
2324 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ |
|
2325 Create a line graphics object.\n\ |
|
2326 @end deftypefn") |
|
2327 { |
|
2328 GO_BODY (line); |
|
2329 } |
|
2330 |
|
2331 DEFUN (__go_text__, args, , |
|
2332 "-*- texinfo -*-\n\ |
|
2333 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ |
|
2334 Create a text graphics object.\n\ |
|
2335 @end deftypefn") |
|
2336 { |
|
2337 GO_BODY (text); |
|
2338 } |
|
2339 |
|
2340 DEFUN (__go_image__, args, , |
|
2341 "-*- texinfo -*-\n\ |
|
2342 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ |
|
2343 Create an image graphics object.\n\ |
|
2344 @end deftypefn") |
|
2345 { |
|
2346 GO_BODY (image); |
|
2347 } |
|
2348 |
|
2349 DEFUN (__go_surface__, args, , |
|
2350 "-*- texinfo -*-\n\ |
|
2351 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ |
|
2352 Create a surface graphics object.\n\ |
|
2353 @end deftypefn") |
|
2354 { |
|
2355 GO_BODY (surface); |
|
2356 } |
|
2357 |
|
2358 DEFUN (__go_delete__, args, , |
|
2359 "-*- texinfo -*-\n\ |
|
2360 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ |
|
2361 @end deftypefn") |
|
2362 { |
|
2363 octave_value_list retval; |
|
2364 |
|
2365 if (args.length () == 1) |
|
2366 { |
|
2367 graphics_handle h = octave_NaN; |
|
2368 |
|
2369 double val = args(0).double_value (); |
|
2370 |
|
2371 if (! error_state) |
|
2372 { |
|
2373 h = gh_manager::lookup (val); |
|
2374 |
|
2375 if (! xisnan (h)) |
|
2376 { |
|
2377 graphics_object obj = gh_manager::get_object (h); |
|
2378 |
|
2379 graphics_handle parent_h = obj.get_parent (); |
|
2380 |
|
2381 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
2382 |
|
2383 parent_obj.remove_child (h); |
|
2384 |
|
2385 gh_manager::free (h); |
|
2386 } |
|
2387 else |
|
2388 error ("delete: invalid graphics object (= %g)", val); |
|
2389 } |
|
2390 else |
|
2391 error ("delete: invalid graphics object"); |
|
2392 } |
|
2393 else |
|
2394 print_usage (); |
|
2395 |
|
2396 return retval; |
|
2397 } |
|
2398 |
|
2399 DEFUN (__go_axes_init__, args, , |
|
2400 "-*- texinfo -*-\n\ |
|
2401 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ |
|
2402 Initialize axes object.\n\ |
|
2403 @end deftypefn") |
|
2404 { |
|
2405 octave_value retval; |
|
2406 |
|
2407 int nargin = args.length (); |
|
2408 |
|
2409 std::string mode = ""; |
|
2410 |
|
2411 if (nargin == 2) |
|
2412 { |
|
2413 mode = args(1).string_value (); |
|
2414 |
|
2415 if (error_state) |
|
2416 return retval; |
|
2417 } |
|
2418 |
|
2419 if (nargin == 1 || nargin == 2) |
|
2420 { |
|
2421 graphics_handle h = octave_NaN; |
|
2422 |
|
2423 double val = args(0).double_value (); |
|
2424 |
|
2425 if (! error_state) |
|
2426 { |
|
2427 h = gh_manager::lookup (val); |
|
2428 |
|
2429 if (! xisnan (h)) |
|
2430 { |
|
2431 graphics_object obj = gh_manager::get_object (h); |
|
2432 |
|
2433 obj.set_defaults (mode); |
|
2434 } |
|
2435 else |
|
2436 error ("__go_axes_init__: invalid graphics object (= %g)", val); |
|
2437 } |
|
2438 else |
|
2439 error ("__go_axes_init__: invalid graphics object"); |
|
2440 } |
|
2441 else |
|
2442 print_usage (); |
|
2443 |
|
2444 return retval; |
|
2445 } |
|
2446 |
|
2447 DEFUN (__go_handles__, , , |
|
2448 "-*- texinfo -*-\n\ |
|
2449 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ |
|
2450 Return current list of function handles.\n\ |
|
2451 @end deftypefn") |
|
2452 { |
6425
|
2453 return octave_value (gh_manager::handle_list ()); |
|
2454 } |
|
2455 |
|
2456 DEFUN (__go_figure_handles__, , , |
|
2457 "-*- texinfo -*-\n\ |
|
2458 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ |
|
2459 Return current list of function handles.\n\ |
|
2460 @end deftypefn") |
|
2461 { |
|
2462 return octave_value (gh_manager::figure_handle_list ()); |
6406
|
2463 } |
|
2464 |
6595
|
2465 octave_value |
|
2466 get_property_from_handle (double handle, const std::string &property, |
|
2467 const std::string &func) |
|
2468 { |
|
2469 graphics_object obj = gh_manager::get_object (handle); |
|
2470 octave_value retval; |
|
2471 |
|
2472 if (obj) |
|
2473 { |
|
2474 property_name p = std::string (property); |
|
2475 retval = obj.get (p); |
|
2476 } |
|
2477 else |
|
2478 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2479 |
|
2480 return retval; |
|
2481 } |
|
2482 |
|
2483 bool |
|
2484 set_property_in_handle (double handle, const std::string &property, |
|
2485 const octave_value &arg, const std::string &func) |
|
2486 { |
|
2487 graphics_object obj = gh_manager::get_object (handle); |
|
2488 int ret = false; |
|
2489 |
|
2490 if (obj) |
|
2491 { |
|
2492 property_name p = std::string (property); |
|
2493 obj.set (p, arg); |
|
2494 if (!error_state) |
|
2495 ret = true; |
|
2496 } |
|
2497 else |
|
2498 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2499 |
|
2500 return ret; |
|
2501 } |
|
2502 |
6406
|
2503 /* |
|
2504 ;;; Local Variables: *** |
|
2505 ;;; mode: C++ *** |
|
2506 ;;; End: *** |
|
2507 */ |