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