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 (), |
|
924 nextplot ("replace"), |
|
925 outerposition () |
|
926 { |
|
927 Matrix tlim (1, 2, 0.0); |
|
928 tlim(1) = 1; |
|
929 xlim = tlim; |
|
930 ylim = tlim; |
|
931 zlim = tlim; |
|
932 |
|
933 Matrix tview (1, 2, 0.0); |
|
934 tview(1) = 90; |
|
935 view = tview; |
|
936 |
|
937 Matrix touterposition (1, 4, 0.0); |
|
938 touterposition(2) = 1; |
|
939 touterposition(3) = 1; |
|
940 outerposition = touterposition; |
|
941 } |
|
942 |
|
943 void |
|
944 axes::axes_properties::set (const property_name& name, const octave_value& val) |
6406
|
945 { |
6705
|
946 bool modified = true; |
|
947 |
|
948 if (name.compare ("parent")) |
|
949 set_parent (val); |
|
950 else if (name.compare ("children")) |
|
951 children = maybe_set_children (children, val); |
|
952 else if (name.compare ("__modified__")) |
|
953 { |
|
954 __modified__ = val.bool_value (); |
|
955 modified = false; |
|
956 } |
|
957 else if (name.compare ("position")) |
|
958 position = val; |
|
959 else if (name.compare ("title")) |
|
960 { |
|
961 graphics_handle h = ::reparent (val, "set", "title", |
|
962 __myhandle__, false); |
|
963 if (! error_state) |
|
964 { |
|
965 if (! xisnan (title)) |
|
966 gh_manager::free (title); |
|
967 |
|
968 title = h; |
|
969 } |
|
970 } |
|
971 else if (name.compare ("box")) |
|
972 box = val; |
|
973 else if (name.compare ("key")) |
|
974 key = val; |
|
975 else if (name.compare ("keybox")) |
|
976 keybox = val; |
|
977 else if (name.compare ("keypos")) |
|
978 keypos = val; |
|
979 else if (name.compare ("dataaspectratio")) |
|
980 { |
|
981 dataaspectratio = val; |
|
982 dataaspectratiomode = "manual"; |
|
983 } |
|
984 else if (name.compare ("dataaspectratiomode")) |
|
985 dataaspectratiomode = val; |
|
986 else if (name.compare ("xlim")) |
|
987 { |
|
988 xlim = val; |
|
989 xlimmode = "manual"; |
|
990 } |
|
991 else if (name.compare ("ylim")) |
|
992 { |
|
993 ylim = val; |
|
994 ylimmode = "manual"; |
|
995 } |
|
996 else if (name.compare ("zlim")) |
|
997 { |
|
998 zlim = val; |
|
999 zlimmode = "manual"; |
|
1000 } |
|
1001 else if (name.compare ("xlimmode")) |
|
1002 xlimmode = val; |
|
1003 else if (name.compare ("ylimmode")) |
|
1004 ylimmode = val; |
|
1005 else if (name.compare ("zlimmode")) |
|
1006 zlimmode = val; |
|
1007 else if (name.compare ("xlabel")) |
|
1008 { |
|
1009 graphics_handle h = ::reparent (val, "set", "xlabel", |
|
1010 __myhandle__, false); |
|
1011 if (! error_state) |
|
1012 { |
|
1013 if (! xisnan (xlabel)) |
|
1014 gh_manager::free (xlabel); |
|
1015 |
|
1016 xlabel = h; |
|
1017 } |
|
1018 } |
|
1019 else if (name.compare ("ylabel")) |
|
1020 { |
|
1021 graphics_handle h = ::reparent (val, "set", "ylabel", |
|
1022 __myhandle__, false); |
|
1023 if (! error_state) |
|
1024 { |
|
1025 if (! xisnan (ylabel)) |
|
1026 gh_manager::free (ylabel); |
|
1027 |
|
1028 ylabel = h; |
|
1029 } |
|
1030 } |
|
1031 else if (name.compare ("zlabel")) |
|
1032 { |
|
1033 graphics_handle h = ::reparent (val, "set", "zlabel", |
|
1034 __myhandle__, false); |
|
1035 if (! error_state) |
|
1036 { |
|
1037 if (! xisnan (zlabel)) |
|
1038 gh_manager::free (zlabel); |
|
1039 |
|
1040 zlabel = h; |
|
1041 } |
|
1042 } |
|
1043 else if (name.compare ("xgrid")) |
|
1044 xgrid = val; |
|
1045 else if (name.compare ("ygrid")) |
|
1046 ygrid = val; |
|
1047 else if (name.compare ("zgrid")) |
|
1048 zgrid = val; |
|
1049 else if (name.compare ("xminorgrid")) |
|
1050 xminorgrid = val; |
|
1051 else if (name.compare ("yminorgrid")) |
|
1052 yminorgrid = val; |
|
1053 else if (name.compare ("zminorgrid")) |
|
1054 zminorgrid = val; |
|
1055 else if (name.compare ("xtick")) |
|
1056 { |
|
1057 xtick = val; |
|
1058 xtickmode = "manual"; |
|
1059 } |
|
1060 else if (name.compare ("ytick")) |
6406
|
1061 { |
6705
|
1062 ytick = val; |
|
1063 ytickmode = "manual"; |
|
1064 } |
|
1065 else if (name.compare ("ztick")) |
|
1066 { |
|
1067 ztick = val; |
|
1068 ztickmode = "manual"; |
|
1069 } |
|
1070 else if (name.compare ("xtickmode")) |
|
1071 xtickmode = val; |
|
1072 else if (name.compare ("ytickmode")) |
|
1073 ytickmode = val; |
|
1074 else if (name.compare ("ztickmode")) |
|
1075 ztickmode = val; |
|
1076 else if (name.compare ("xticklabel")) |
|
1077 { |
|
1078 xticklabel = val; |
|
1079 xticklabelmode = "manual"; |
|
1080 } |
|
1081 else if (name.compare ("yticklabel")) |
|
1082 { |
|
1083 yticklabel = val; |
|
1084 yticklabelmode = "manual"; |
|
1085 } |
|
1086 else if (name.compare ("zticklabel")) |
|
1087 { |
|
1088 zticklabel = val; |
|
1089 zticklabelmode = "manual"; |
|
1090 } |
|
1091 else if (name.compare ("xticklabelmode")) |
|
1092 xticklabelmode = val; |
|
1093 else if (name.compare ("yticklabelmode")) |
|
1094 yticklabelmode = val; |
|
1095 else if (name.compare ("zticklabelmode")) |
|
1096 zticklabelmode = val; |
|
1097 else if (name.compare ("xscale")) |
|
1098 xscale = val; |
|
1099 else if (name.compare ("yscale")) |
|
1100 yscale = val; |
|
1101 else if (name.compare ("zscale")) |
|
1102 zscale = val; |
|
1103 else if (name.compare ("xdir")) |
|
1104 xdir = val; |
|
1105 else if (name.compare ("ydir")) |
|
1106 ydir = val; |
|
1107 else if (name.compare ("zdir")) |
|
1108 zdir = val; |
|
1109 else if (name.compare ("view")) |
|
1110 view = val; |
|
1111 else if (name.compare ("nextplot")) |
|
1112 nextplot = val; |
|
1113 else if (name.compare ("outerposition")) |
|
1114 outerposition = val; |
|
1115 else |
|
1116 { |
|
1117 modified = false; |
|
1118 warning ("set: invalid property `%s'", name.c_str ()); |
|
1119 } |
6406
|
1120 |
6705
|
1121 if (modified) |
|
1122 mark_modified (); |
|
1123 } |
|
1124 |
|
1125 void |
|
1126 axes::axes_properties::set_defaults (base_graphics_object& obj, |
|
1127 const std::string& mode) |
|
1128 { |
|
1129 position = Matrix (); |
|
1130 title = octave_NaN; |
|
1131 box = "on"; |
|
1132 key = "off"; |
|
1133 keybox = "off"; |
|
1134 keypos = 1; |
|
1135 dataaspectratio = Matrix (1, 3, 1.0); |
|
1136 dataaspectratiomode = "auto"; |
|
1137 |
|
1138 Matrix tlim (1, 2, 0.0); |
|
1139 tlim(1) = 1; |
|
1140 xlim = tlim; |
|
1141 ylim = tlim; |
|
1142 zlim = tlim; |
6406
|
1143 |
6705
|
1144 xlimmode = "auto"; |
|
1145 ylimmode = "auto"; |
|
1146 zlimmode = "auto"; |
|
1147 xlabel = octave_NaN; |
|
1148 ylabel = octave_NaN; |
|
1149 zlabel = octave_NaN; |
|
1150 xgrid = "off"; |
|
1151 ygrid = "off"; |
|
1152 zgrid = "off"; |
|
1153 xminorgrid = "off"; |
|
1154 yminorgrid = "off"; |
|
1155 zminorgrid = "off"; |
|
1156 xtick = Matrix (); |
|
1157 ytick = Matrix (); |
|
1158 ztick = Matrix (); |
|
1159 xtickmode = "auto"; |
|
1160 ytickmode = "auto"; |
|
1161 ztickmode = "auto"; |
|
1162 xticklabel = ""; |
|
1163 yticklabel = ""; |
|
1164 zticklabel = ""; |
|
1165 xticklabelmode = "auto"; |
|
1166 yticklabelmode = "auto"; |
|
1167 zticklabelmode = "auto"; |
|
1168 xscale = "linear"; |
|
1169 yscale = "linear"; |
|
1170 zscale = "linear"; |
|
1171 xdir = "normal"; |
|
1172 ydir = "normal"; |
|
1173 zdir = "normal"; |
|
1174 |
|
1175 Matrix tview (1, 2, 0.0); |
|
1176 tview(1) = 90; |
|
1177 view = tview; |
|
1178 |
|
1179 nextplot = "replace"; |
|
1180 |
|
1181 // FIXME -- this is not quite right; we should preserve |
|
1182 // "position" and "units". |
|
1183 |
|
1184 if (mode != "replace") |
|
1185 { |
6406
|
1186 Matrix touterposition (1, 4, 0.0); |
|
1187 touterposition(2) = 1; |
|
1188 touterposition(3) = 1; |
|
1189 outerposition = touterposition; |
|
1190 } |
|
1191 |
6705
|
1192 delete_children (); |
6406
|
1193 |
6705
|
1194 children = Matrix (); |
6432
|
1195 |
6705
|
1196 override_defaults (obj); |
|
1197 } |
|
1198 |
|
1199 octave_value |
|
1200 axes::axes_properties::get (void) const |
|
1201 { |
|
1202 Octave_map m; |
6406
|
1203 |
6705
|
1204 if (xisnan (title)) |
|
1205 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1206 |
|
1207 if (xisnan (xlabel)) |
|
1208 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
6406
|
1209 |
6705
|
1210 if (xisnan (ylabel)) |
|
1211 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
6406
|
1212 |
6705
|
1213 if (xisnan (zlabel)) |
|
1214 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
6406
|
1215 |
6705
|
1216 m.assign ("type", type); |
|
1217 m.assign ("parent", parent); |
|
1218 m.assign ("children", children); |
|
1219 m.assign ("__modified__", __modified__); |
|
1220 m.assign ("position", position); |
|
1221 m.assign ("title", title); |
|
1222 m.assign ("box", box); |
|
1223 m.assign ("key", key); |
|
1224 m.assign ("keybox", keybox); |
|
1225 m.assign ("keypos", keypos); |
|
1226 m.assign ("dataaspectratio", dataaspectratio); |
|
1227 m.assign ("dataaspectratiomode", dataaspectratiomode); |
|
1228 m.assign ("xlim", xlim); |
|
1229 m.assign ("ylim", ylim); |
|
1230 m.assign ("zlim", zlim); |
|
1231 m.assign ("xlimmode", xlimmode); |
|
1232 m.assign ("ylimmode", ylimmode); |
|
1233 m.assign ("zlimmode", zlimmode); |
|
1234 m.assign ("xlabel", xlabel); |
|
1235 m.assign ("ylabel", ylabel); |
|
1236 m.assign ("zlabel", zlabel); |
|
1237 m.assign ("xgrid", xgrid); |
|
1238 m.assign ("ygrid", ygrid); |
|
1239 m.assign ("zgrid", zgrid); |
|
1240 m.assign ("xminorgrid", xminorgrid); |
|
1241 m.assign ("yminorgrid", yminorgrid); |
|
1242 m.assign ("zminorgrid", zminorgrid); |
|
1243 m.assign ("xtick", xtick); |
|
1244 m.assign ("ytick", ytick); |
|
1245 m.assign ("ztick", ztick); |
|
1246 m.assign ("xtickmode", xtickmode); |
|
1247 m.assign ("ytickmode", ytickmode); |
|
1248 m.assign ("ztickmode", ztickmode); |
|
1249 m.assign ("xticklabel", xticklabel); |
|
1250 m.assign ("yticklabel", yticklabel); |
|
1251 m.assign ("zticklabel", zticklabel); |
|
1252 m.assign ("xticklabelmode", xticklabelmode); |
|
1253 m.assign ("yticklabelmode", yticklabelmode); |
|
1254 m.assign ("zticklabelmode", zticklabelmode); |
|
1255 m.assign ("xscale", xscale); |
|
1256 m.assign ("yscale", yscale); |
|
1257 m.assign ("zscale", zscale); |
|
1258 m.assign ("xdir", xdir); |
|
1259 m.assign ("ydir", ydir); |
|
1260 m.assign ("zdir", zdir); |
|
1261 m.assign ("view", view); |
|
1262 m.assign ("nextplot", nextplot); |
|
1263 m.assign ("outerposition", outerposition); |
6432
|
1264 |
6705
|
1265 return m; |
|
1266 } |
6406
|
1267 |
6705
|
1268 octave_value |
|
1269 axes::axes_properties::get (const property_name& name) const |
|
1270 { |
|
1271 octave_value retval; |
6406
|
1272 |
6705
|
1273 if (name.compare ("type")) |
|
1274 retval = type; |
|
1275 else if (name.compare ("parent")) |
|
1276 retval = parent; |
|
1277 else if (name.compare ("children")) |
|
1278 retval = children; |
|
1279 else if (name.compare ("__modified__")) |
|
1280 retval = __modified__; |
|
1281 else if (name.compare ("position")) |
|
1282 retval = position; |
|
1283 else if (name.compare ("title")) |
6406
|
1284 { |
|
1285 if (xisnan (title)) |
|
1286 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1287 |
6705
|
1288 retval = title; |
|
1289 } |
|
1290 else if (name.compare ("box")) |
|
1291 retval = box; |
|
1292 else if (name.compare ("key")) |
|
1293 retval = key; |
|
1294 else if (name.compare ("keybox")) |
|
1295 retval = keybox; |
|
1296 else if (name.compare ("keypos")) |
|
1297 retval = keypos; |
|
1298 else if (name.compare ("dataaspectratio")) |
|
1299 retval = dataaspectratio; |
|
1300 else if (name.compare ("dataaspectratiomode")) |
|
1301 retval = dataaspectratiomode; |
|
1302 else if (name.compare ("xlim")) |
|
1303 retval = xlim; |
|
1304 else if (name.compare ("ylim")) |
|
1305 retval = ylim; |
|
1306 else if (name.compare ("zlim")) |
|
1307 retval = zlim; |
|
1308 else if (name.compare ("xlimmode")) |
|
1309 retval = xlimmode; |
|
1310 else if (name.compare ("ylimmode")) |
|
1311 retval = ylimmode; |
|
1312 else if (name.compare ("zlimmode")) |
|
1313 retval = zlimmode; |
|
1314 else if (name.compare ("xlabel")) |
|
1315 { |
6406
|
1316 if (xisnan (xlabel)) |
|
1317 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1318 |
6705
|
1319 retval = xlabel; |
|
1320 } |
|
1321 else if (name.compare ("ylabel")) |
|
1322 { |
6406
|
1323 if (xisnan (ylabel)) |
|
1324 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1325 |
6705
|
1326 retval = ylabel; |
|
1327 } |
|
1328 else if (name.compare ("zlabel")) |
|
1329 { |
6406
|
1330 if (xisnan (zlabel)) |
|
1331 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1332 |
6705
|
1333 retval = zlabel; |
6406
|
1334 } |
6705
|
1335 else if (name.compare ("xgrid")) |
|
1336 retval = xgrid; |
|
1337 else if (name.compare ("ygrid")) |
|
1338 retval = ygrid; |
|
1339 else if (name.compare ("zgrid")) |
|
1340 retval = zgrid; |
|
1341 else if (name.compare ("xminorgrid")) |
|
1342 retval = xminorgrid; |
|
1343 else if (name.compare ("yminorgrid")) |
|
1344 retval = yminorgrid; |
|
1345 else if (name.compare ("zminorgrid")) |
|
1346 retval = zminorgrid; |
|
1347 else if (name.compare ("xtick")) |
|
1348 retval = xtick; |
|
1349 else if (name.compare ("ytick")) |
|
1350 retval = ytick; |
|
1351 else if (name.compare ("ztick")) |
|
1352 retval = ztick; |
|
1353 else if (name.compare ("xtickmode")) |
|
1354 retval = xtickmode; |
|
1355 else if (name.compare ("ytickmode")) |
|
1356 retval = ytickmode; |
|
1357 else if (name.compare ("ztickmode")) |
|
1358 retval = ztickmode; |
|
1359 else if (name.compare ("xticklabel")) |
|
1360 retval = xticklabel; |
|
1361 else if (name.compare ("yticklabel")) |
|
1362 retval = yticklabel; |
|
1363 else if (name.compare ("zticklabel")) |
|
1364 retval = zticklabel; |
|
1365 else if (name.compare ("xticklabelmode")) |
|
1366 retval = xticklabelmode; |
|
1367 else if (name.compare ("yticklabelmode")) |
|
1368 retval = yticklabelmode; |
|
1369 else if (name.compare ("zticklabelmode")) |
|
1370 retval = zticklabelmode; |
|
1371 else if (name.compare ("xscale")) |
|
1372 retval = xscale; |
|
1373 else if (name.compare ("yscale")) |
|
1374 retval = yscale; |
|
1375 else if (name.compare ("zscale")) |
|
1376 retval = zscale; |
|
1377 else if (name.compare ("xdir")) |
|
1378 retval = xdir; |
|
1379 else if (name.compare ("ydir")) |
|
1380 retval = ydir; |
|
1381 else if (name.compare ("zdir")) |
|
1382 retval = zdir; |
|
1383 else if (name.compare ("view")) |
|
1384 retval = view; |
|
1385 else if (name.compare ("nextplot")) |
|
1386 retval = nextplot; |
|
1387 else if (name.compare ("outerposition")) |
|
1388 retval = outerposition; |
|
1389 else |
|
1390 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1391 |
6705
|
1392 return retval; |
|
1393 } |
6406
|
1394 |
6705
|
1395 void |
|
1396 axes::axes_properties::remove_child (const graphics_handle& h) |
|
1397 { |
|
1398 if (! xisnan (title) && h == title) |
|
1399 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1400 else if (! xisnan (xlabel) && h == xlabel) |
|
1401 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1402 else if (! xisnan (ylabel) && h == ylabel) |
|
1403 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1404 else if (! xisnan (zlabel) && h == zlabel) |
|
1405 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1406 else |
|
1407 base_properties::remove_child (h); |
|
1408 } |
6406
|
1409 |
6705
|
1410 void |
|
1411 axes::axes_properties::delete_children (void) |
|
1412 { |
|
1413 base_properties::delete_children (); |
|
1414 |
|
1415 if (! xisnan (title)) |
|
1416 gh_manager::free (title); |
6406
|
1417 |
6705
|
1418 if (! xisnan (xlabel)) |
|
1419 gh_manager::free (xlabel); |
6406
|
1420 |
6705
|
1421 if (! xisnan (ylabel)) |
|
1422 gh_manager::free (ylabel); |
6406
|
1423 |
6705
|
1424 if (! xisnan (zlabel)) |
|
1425 gh_manager::free (zlabel); |
|
1426 } |
6406
|
1427 |
6705
|
1428 property_list::pval_map_type axes::axes_properties::factory_defaults (void) |
|
1429 { |
|
1430 property_list::pval_map_type m; |
6406
|
1431 |
6705
|
1432 m["position"] = Matrix (); |
|
1433 m["title"] = octave_NaN; |
|
1434 m["box"] = "on"; |
|
1435 m["key"] = "off"; |
|
1436 m["keybox"] = "off"; |
|
1437 m["keypos"] = 1; |
|
1438 m["dataaspectratio"] = Matrix (1, 3, 1.0); |
|
1439 m["dataaspectratiomode"] = "auto"; |
6406
|
1440 |
6705
|
1441 Matrix tlim (1, 2, 0.0); |
|
1442 tlim(1) = 1; |
6406
|
1443 |
6705
|
1444 m["xlim"] = tlim; |
|
1445 m["ylim"] = tlim; |
|
1446 m["zlim"] = tlim; |
6406
|
1447 |
6705
|
1448 m["xlimmode"] = "auto"; |
|
1449 m["ylimmode"] = "auto"; |
|
1450 m["zlimmode"] = "auto"; |
|
1451 m["xlabel"] = octave_NaN; |
|
1452 m["ylabel"] = octave_NaN; |
|
1453 m["zlabel"] = octave_NaN; |
|
1454 m["xgrid"] = "off"; |
|
1455 m["ygrid"] = "off"; |
|
1456 m["zgrid"] = "off"; |
|
1457 m["xminorgrid"] = "off"; |
|
1458 m["yminorgrid"] = "off"; |
|
1459 m["zminorgrid"] = "off"; |
|
1460 m["xtick"] = Matrix (); |
|
1461 m["ytick"] = Matrix (); |
|
1462 m["ztick"] = Matrix (); |
|
1463 m["xtickmode"] = "auto"; |
|
1464 m["ytickmode"] = "auto"; |
|
1465 m["ztickmode"] = "auto"; |
|
1466 m["xticklabel"] = ""; |
|
1467 m["yticklabel"] = ""; |
|
1468 m["zticklabel"] = ""; |
|
1469 m["xticklabelmode"] = "auto"; |
|
1470 m["yticklabelmode"] = "auto"; |
|
1471 m["zticklabelmode"] = "auto"; |
|
1472 m["xscale"] = "linear"; |
|
1473 m["yscale"] = "linear"; |
|
1474 m["zscale"] = "linear"; |
|
1475 m["xdir"] = "normal"; |
|
1476 m["ydir"] = "normal"; |
|
1477 m["zdir"] = "normal"; |
6406
|
1478 |
6705
|
1479 Matrix tview (1, 2, 0.0); |
|
1480 tview(1) = 90; |
6406
|
1481 |
6705
|
1482 m["view"] = tview; |
6406
|
1483 |
6705
|
1484 m["nextplot"] = "replace"; |
6406
|
1485 |
6705
|
1486 Matrix touterposition (1, 4, 0.0); |
|
1487 touterposition(2) = 1; |
|
1488 touterposition(3) = 1; |
6406
|
1489 |
6705
|
1490 m["outerposition"] = touterposition; |
6406
|
1491 |
6705
|
1492 return m; |
|
1493 } |
6406
|
1494 |
|
1495 std::string axes::axes_properties::go_name ("axes"); |
|
1496 |
|
1497 // --------------------------------------------------------------------- |
|
1498 |
|
1499 static Matrix |
|
1500 default_data (void) |
|
1501 { |
|
1502 Matrix retval (1, 2); |
|
1503 |
|
1504 retval(0) = 0; |
|
1505 retval(1) = 1; |
|
1506 |
|
1507 return retval; |
|
1508 } |
|
1509 |
6705
|
1510 line::line_properties::line_properties (const graphics_handle& mh, |
|
1511 const graphics_handle& p) |
|
1512 : base_properties (go_name, mh, p), |
|
1513 xdata (default_data ()), |
|
1514 ydata (default_data ()), |
|
1515 zdata (Matrix ()), |
|
1516 ldata (Matrix ()), |
|
1517 udata (Matrix ()), |
|
1518 xldata (Matrix ()), |
|
1519 xudata (Matrix ()), |
|
1520 color (), |
|
1521 linestyle ("-"), |
|
1522 linewidth (0.5), |
|
1523 marker ("none"), |
|
1524 markeredgecolor ("auto"), |
|
1525 markerfacecolor ("none"), |
|
1526 markersize (1), |
|
1527 keylabel ("") |
|
1528 { } |
|
1529 |
|
1530 void |
|
1531 line::line_properties::set (const property_name& name, const octave_value& val) |
6406
|
1532 { |
6705
|
1533 bool modified = true; |
6432
|
1534 |
6705
|
1535 if (name.compare ("parent")) |
|
1536 set_parent (val); |
|
1537 else if (name.compare ("children")) |
|
1538 children = maybe_set_children (children, val); |
|
1539 else if (name.compare ("__modified__")) |
|
1540 { |
|
1541 __modified__ = val.bool_value (); |
|
1542 modified = false; |
6406
|
1543 } |
6705
|
1544 else if (name.compare ("xdata")) |
|
1545 xdata = val; |
|
1546 else if (name.compare ("ydata")) |
|
1547 ydata = val; |
|
1548 else if (name.compare ("zdata")) |
|
1549 zdata = val; |
|
1550 else if (name.compare ("ldata")) |
|
1551 ldata = val; |
|
1552 else if (name.compare ("udata")) |
|
1553 udata = val; |
|
1554 else if (name.compare ("xldata")) |
|
1555 xldata = val; |
|
1556 else if (name.compare ("xudata")) |
|
1557 xudata = val; |
|
1558 else if (name.compare ("color")) |
|
1559 color = color_property (val); |
|
1560 else if (name.compare ("linestyle")) |
|
1561 linestyle = val; |
|
1562 else if (name.compare ("linewidth")) |
|
1563 linewidth = val; |
|
1564 else if (name.compare ("marker")) |
|
1565 marker = val; |
|
1566 else if (name.compare ("markeredgecolor")) |
|
1567 markeredgecolor = val; |
|
1568 else if (name.compare ("markerfacecolor")) |
|
1569 markerfacecolor = val; |
|
1570 else if (name.compare ("markersize")) |
|
1571 markersize = val; |
|
1572 else if (name.compare ("keylabel")) |
|
1573 keylabel = val; |
|
1574 else |
6406
|
1575 { |
6705
|
1576 modified = false; |
|
1577 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1578 } |
|
1579 |
6705
|
1580 if (modified) |
|
1581 mark_modified (); |
|
1582 } |
|
1583 |
|
1584 octave_value |
|
1585 line::line_properties::get (void) const |
|
1586 { |
|
1587 Octave_map m; |
6406
|
1588 |
6705
|
1589 m.assign ("type", type); |
|
1590 m.assign ("parent", parent); |
|
1591 m.assign ("children", children); |
|
1592 m.assign ("__modified__", __modified__); |
|
1593 m.assign ("xdata", xdata); |
|
1594 m.assign ("ydata", ydata); |
|
1595 m.assign ("zdata", zdata); |
|
1596 m.assign ("ldata", ldata); |
|
1597 m.assign ("udata", udata); |
|
1598 m.assign ("xldata", xldata); |
|
1599 m.assign ("xudata", xudata); |
|
1600 m.assign ("color", color); |
|
1601 m.assign ("linestyle", linestyle); |
|
1602 m.assign ("linewidth", linewidth); |
|
1603 m.assign ("marker", marker); |
|
1604 m.assign ("markeredgecolor", markeredgecolor); |
|
1605 m.assign ("markerface", markerfacecolor); |
|
1606 m.assign ("markersize", markersize); |
|
1607 m.assign ("keylabel", keylabel); |
6406
|
1608 |
6705
|
1609 return m; |
|
1610 } |
6406
|
1611 |
6705
|
1612 octave_value |
|
1613 line::line_properties::get (const property_name& name) const |
|
1614 { |
|
1615 octave_value retval; |
6406
|
1616 |
6705
|
1617 if (name.compare ("type")) |
|
1618 retval = type; |
|
1619 else if (name.compare ("parent")) |
|
1620 retval = parent; |
|
1621 else if (name.compare ("children")) |
|
1622 retval = children; |
|
1623 else if (name.compare ("__modified__")) |
|
1624 retval = __modified__; |
|
1625 else if (name.compare ("xdata")) |
|
1626 retval = xdata; |
|
1627 else if (name.compare ("ydata")) |
|
1628 retval = ydata; |
|
1629 else if (name.compare ("zdata")) |
|
1630 retval = zdata; |
|
1631 else if (name.compare ("ldata")) |
|
1632 retval = ldata; |
|
1633 else if (name.compare ("udata")) |
|
1634 retval = udata; |
|
1635 else if (name.compare ("xldata")) |
|
1636 retval = xldata; |
|
1637 else if (name.compare ("xudata")) |
|
1638 retval = xudata; |
|
1639 else if (name.compare ("color")) |
|
1640 retval = color; |
|
1641 else if (name.compare ("linestyle")) |
|
1642 retval = linestyle; |
|
1643 else if (name.compare ("linewidth")) |
|
1644 retval = linewidth; |
|
1645 else if (name.compare ("marker")) |
|
1646 retval = marker; |
|
1647 else if (name.compare ("markeredgecolor")) |
|
1648 retval = markeredgecolor; |
|
1649 else if (name.compare ("markerfacecolor")) |
|
1650 retval = markerfacecolor; |
|
1651 else if (name.compare ("markersize")) |
|
1652 retval = markersize; |
|
1653 else if (name.compare ("keylabel")) |
|
1654 retval = keylabel; |
|
1655 else |
|
1656 warning ("get: invalid property `%s'", name.c_str ()); |
6432
|
1657 |
6705
|
1658 return retval; |
|
1659 } |
6406
|
1660 |
6705
|
1661 property_list::pval_map_type line::line_properties::factory_defaults (void) |
|
1662 { |
|
1663 property_list::pval_map_type m; |
6406
|
1664 |
6705
|
1665 m["xdata"] = default_data (); |
|
1666 m["ydata"] = default_data (); |
|
1667 m["zdata"] = Matrix (); |
|
1668 m["ldata"] = Matrix (); |
|
1669 m["udata"] = Matrix (); |
|
1670 m["xldata"] = Matrix (); |
|
1671 m["xudata"] = Matrix (); |
|
1672 m["color"] = color_property (); |
|
1673 m["linestyle"] = "-"; |
|
1674 m["linewidth"] = 0.5; |
|
1675 m["marker"] = "none"; |
|
1676 m["markeredgecolor"] = "auto"; |
|
1677 m["markerfacecolor"] = "none"; |
|
1678 m["markersize"] = 1; |
|
1679 m["keylabel"] = ""; |
6406
|
1680 |
6705
|
1681 return m; |
|
1682 } |
6406
|
1683 |
|
1684 std::string line::line_properties::go_name ("line"); |
|
1685 |
|
1686 // --------------------------------------------------------------------- |
|
1687 |
6705
|
1688 text::text_properties::text_properties (const graphics_handle& mh, |
|
1689 const graphics_handle& p) |
|
1690 : base_properties (go_name, mh, p), |
|
1691 string (""), |
|
1692 units ("data"), |
|
1693 position (Matrix (1, 3, 0.0)), |
6724
|
1694 rotation (0), |
6705
|
1695 horizontalalignment ("left") |
|
1696 { } |
|
1697 |
|
1698 void |
|
1699 text::text_properties::set (const property_name& name, const octave_value& val) |
6406
|
1700 { |
6705
|
1701 bool modified = true; |
6432
|
1702 |
6705
|
1703 if (name.compare ("parent")) |
|
1704 set_parent (val); |
|
1705 else if (name.compare ("children")) |
|
1706 children = maybe_set_children (children, val); |
|
1707 else if (name.compare ("__modified__")) |
|
1708 { |
|
1709 __modified__ = val.bool_value (); |
|
1710 modified = false; |
6406
|
1711 } |
6705
|
1712 else if (name.compare ("string")) |
|
1713 string = val; |
|
1714 else if (name.compare ("units")) |
|
1715 units = val; |
|
1716 else if (name.compare ("position")) |
|
1717 position = val; |
6724
|
1718 else if (name.compare ("rotation")) |
|
1719 rotation = val; |
6705
|
1720 else if (name.compare ("horizontalalignment")) |
|
1721 horizontalalignment = val; |
|
1722 else |
6406
|
1723 { |
6705
|
1724 modified = false; |
|
1725 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1726 } |
|
1727 |
6705
|
1728 if (modified) |
|
1729 mark_modified (); |
|
1730 } |
6406
|
1731 |
6705
|
1732 octave_value |
|
1733 text::text_properties::get (void) const |
|
1734 { |
|
1735 Octave_map m; |
6406
|
1736 |
6705
|
1737 m.assign ("type", type); |
|
1738 m.assign ("parent", parent); |
|
1739 m.assign ("children", children); |
|
1740 m.assign ("__modified__", __modified__); |
|
1741 m.assign ("string", string); |
|
1742 m.assign ("units", units); |
|
1743 m.assign ("position", position); |
6724
|
1744 m.assign ("rotation", rotation); |
6705
|
1745 m.assign ("horizontalalignment", horizontalalignment); |
6406
|
1746 |
6705
|
1747 return m; |
|
1748 } |
6406
|
1749 |
6705
|
1750 octave_value |
|
1751 text::text_properties::get (const property_name& name) const |
|
1752 { |
|
1753 octave_value retval; |
6406
|
1754 |
6705
|
1755 if (name.compare ("type")) |
|
1756 retval = type; |
|
1757 else if (name.compare ("parent")) |
|
1758 retval = parent; |
|
1759 else if (name.compare ("children")) |
|
1760 retval = children; |
|
1761 else if (name.compare ("__modified__")) |
|
1762 retval = __modified__; |
|
1763 else if (name.compare ("string")) |
|
1764 retval = string; |
|
1765 else if (name.compare ("units")) |
|
1766 retval = units; |
|
1767 else if (name.compare ("position")) |
|
1768 retval = position; |
6724
|
1769 else if (name.compare ("rotation")) |
|
1770 retval = rotation; |
6705
|
1771 else if (name.compare ("horizontalalignment")) |
|
1772 retval = horizontalalignment; |
|
1773 else |
|
1774 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1775 |
6705
|
1776 return retval; |
|
1777 } |
6406
|
1778 |
6705
|
1779 property_list::pval_map_type |
|
1780 text::text_properties::factory_defaults (void) |
|
1781 { |
|
1782 property_list::pval_map_type m; |
6406
|
1783 |
6705
|
1784 m["string"] = ""; |
|
1785 m["units"] = "data"; |
|
1786 m["position"] = Matrix (1, 3, 0.0); |
6724
|
1787 m["rotation"] = 0; |
6705
|
1788 m["horizontalalignment"] = "left"; |
6406
|
1789 |
6705
|
1790 return m; |
|
1791 } |
6406
|
1792 |
|
1793 std::string text::text_properties::go_name ("text"); |
|
1794 |
|
1795 // --------------------------------------------------------------------- |
|
1796 |
6705
|
1797 image::image_properties::image_properties (const graphics_handle& mh, |
|
1798 const graphics_handle& p) |
|
1799 : base_properties (go_name, mh, p), |
|
1800 cdata (Matrix ()), |
|
1801 xdata (Matrix ()), |
|
1802 ydata (Matrix ()) |
|
1803 { } |
|
1804 |
|
1805 void |
|
1806 image::image_properties::set (const property_name& name, |
|
1807 const octave_value& val) |
6406
|
1808 { |
6705
|
1809 bool modified = true; |
6432
|
1810 |
6705
|
1811 if (name.compare ("parent")) |
|
1812 set_parent (val); |
|
1813 else if (name.compare ("children")) |
|
1814 children = maybe_set_children (children, val); |
|
1815 else if (name.compare ("__modified__")) |
|
1816 { |
|
1817 __modified__ = val.bool_value (); |
|
1818 modified = false; |
6406
|
1819 } |
6705
|
1820 else if (name.compare ("cdata")) |
|
1821 cdata = val; |
|
1822 else if (name.compare ("xdata")) |
|
1823 xdata = val; |
|
1824 else if (name.compare ("ydata")) |
|
1825 ydata = val; |
|
1826 else |
6406
|
1827 { |
6705
|
1828 modified = false; |
|
1829 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1830 } |
|
1831 |
6705
|
1832 if (modified) |
|
1833 mark_modified (); |
|
1834 } |
6406
|
1835 |
6705
|
1836 octave_value |
|
1837 image::image_properties::get (void) const |
|
1838 { |
|
1839 Octave_map m; |
6406
|
1840 |
6705
|
1841 m.assign ("type", type); |
|
1842 m.assign ("parent", parent); |
|
1843 m.assign ("children", children); |
|
1844 m.assign ("__modified__", __modified__); |
|
1845 m.assign ("cdata", cdata); |
|
1846 m.assign ("xdata", xdata); |
|
1847 m.assign ("ydata", ydata); |
6406
|
1848 |
6705
|
1849 return m; |
|
1850 } |
6406
|
1851 |
6705
|
1852 octave_value |
|
1853 image::image_properties::get (const property_name& name) const |
|
1854 { |
|
1855 octave_value retval; |
6406
|
1856 |
6705
|
1857 if (name.compare ("type")) |
|
1858 retval = type; |
|
1859 else if (name.compare ("parent")) |
|
1860 retval = parent; |
|
1861 else if (name.compare ("children")) |
|
1862 retval = children; |
|
1863 else if (name.compare ("__modified__")) |
|
1864 retval = __modified__; |
|
1865 else if (name.compare ("cdata")) |
|
1866 retval = cdata; |
|
1867 else if (name.compare ("xdata")) |
|
1868 retval = xdata; |
|
1869 else if (name.compare ("ydata")) |
|
1870 retval = ydata; |
|
1871 else |
|
1872 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1873 |
6705
|
1874 return retval; |
|
1875 } |
6406
|
1876 |
6705
|
1877 property_list::pval_map_type image::image_properties::factory_defaults (void) |
|
1878 { |
|
1879 property_list::pval_map_type m; |
6406
|
1880 |
6705
|
1881 m["cdata"] = Matrix (); |
|
1882 m["xdata"] = Matrix (); |
|
1883 m["ydata"] = Matrix (); |
6406
|
1884 |
6705
|
1885 return m; |
|
1886 } |
6406
|
1887 |
|
1888 std::string image::image_properties::go_name ("image"); |
|
1889 |
|
1890 // --------------------------------------------------------------------- |
|
1891 |
6705
|
1892 surface::surface_properties::surface_properties (const graphics_handle& mh, |
|
1893 const graphics_handle& p) |
|
1894 : base_properties (go_name, mh, p), |
|
1895 xdata (Matrix ()), |
|
1896 ydata (Matrix ()), |
|
1897 zdata (Matrix ()), |
|
1898 keylabel ("") |
|
1899 { } |
|
1900 |
|
1901 void |
|
1902 surface::surface_properties::set (const property_name& name, |
|
1903 const octave_value& val) |
6406
|
1904 { |
6705
|
1905 bool modified = true; |
6432
|
1906 |
6705
|
1907 if (name.compare ("parent")) |
|
1908 set_parent (val); |
|
1909 else if (name.compare ("children")) |
|
1910 children = maybe_set_children (children, val); |
|
1911 else if (name.compare ("__modified__")) |
|
1912 { |
|
1913 __modified__ = val.bool_value (); |
|
1914 modified = false; |
6406
|
1915 } |
6705
|
1916 else if (name.compare ("xdata")) |
|
1917 xdata = val; |
|
1918 else if (name.compare ("ydata")) |
|
1919 ydata = val; |
|
1920 else if (name.compare ("zdata")) |
|
1921 zdata = val; |
|
1922 else if (name.compare ("keylabel")) |
|
1923 keylabel = val; |
|
1924 else |
6406
|
1925 { |
6705
|
1926 modified = false; |
|
1927 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1928 } |
|
1929 |
6705
|
1930 if (modified) |
|
1931 mark_modified (); |
|
1932 } |
6406
|
1933 |
6705
|
1934 octave_value |
|
1935 surface::surface_properties::get (void) const |
|
1936 { |
|
1937 Octave_map m; |
6406
|
1938 |
6705
|
1939 m.assign ("type", type); |
|
1940 m.assign ("parent", parent); |
|
1941 m.assign ("children", children); |
|
1942 m.assign ("__modified__", __modified__); |
|
1943 m.assign ("xdata", xdata); |
|
1944 m.assign ("ydata", ydata); |
|
1945 m.assign ("zdata", zdata); |
|
1946 m.assign ("keylabel", keylabel); |
6406
|
1947 |
6705
|
1948 return m; |
|
1949 } |
6406
|
1950 |
6705
|
1951 octave_value |
|
1952 surface::surface_properties::get (const property_name& name) const |
|
1953 { |
|
1954 octave_value retval; |
6406
|
1955 |
6705
|
1956 if (name.compare ("type")) |
|
1957 retval = type; |
|
1958 else if (name.compare ("parent")) |
|
1959 retval = parent; |
|
1960 else if (name.compare ("children")) |
|
1961 retval = children; |
|
1962 else if (name.compare ("__modified__")) |
|
1963 retval = __modified__; |
|
1964 else if (name.compare ("xdata")) |
|
1965 retval = xdata; |
|
1966 else if (name.compare ("ydata")) |
|
1967 retval = ydata; |
|
1968 else if (name.compare ("zdata")) |
|
1969 retval = zdata; |
|
1970 else if (name.compare ("keylabel")) |
|
1971 retval = keylabel; |
|
1972 else |
|
1973 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1974 |
6705
|
1975 return retval; |
|
1976 } |
6406
|
1977 |
6705
|
1978 property_list::pval_map_type |
|
1979 surface::surface_properties::factory_defaults (void) |
|
1980 { |
|
1981 property_list::pval_map_type m; |
6406
|
1982 |
6705
|
1983 m["xdata"] = Matrix (); |
|
1984 m["ydata"] = Matrix (); |
|
1985 m["zdata"] = Matrix (); |
|
1986 m["keylabel"] = ""; |
6406
|
1987 |
6705
|
1988 return m; |
|
1989 } |
6406
|
1990 |
|
1991 std::string surface::surface_properties::go_name ("surface"); |
|
1992 |
|
1993 // --------------------------------------------------------------------- |
|
1994 |
|
1995 octave_value |
|
1996 base_graphics_object::get_default (const property_name& name) const |
|
1997 { |
|
1998 graphics_handle parent = get_parent (); |
|
1999 graphics_object parent_obj = gh_manager::get_object (parent); |
|
2000 |
|
2001 return parent_obj.get_default (type () + name); |
|
2002 } |
|
2003 |
|
2004 octave_value |
|
2005 base_graphics_object::get_factory_default (const property_name& name) const |
|
2006 { |
|
2007 graphics_object parent_obj = gh_manager::get_object (0); |
|
2008 |
|
2009 return parent_obj.get_factory_default (type () + name); |
|
2010 } |
|
2011 |
|
2012 gh_manager::gh_manager (void) |
|
2013 : handle_map (), handle_free_list (), next_handle (-1) |
|
2014 { |
|
2015 handle_map[0] = graphics_object (new root_figure ()); |
|
2016 } |
|
2017 |
|
2018 graphics_handle |
|
2019 gh_manager::do_make_graphics_handle (const std::string& go_name, |
|
2020 const graphics_handle& p) |
|
2021 { |
|
2022 graphics_handle h = get_handle (go_name); |
|
2023 |
|
2024 base_graphics_object *go = 0; |
|
2025 |
|
2026 if (go_name == "figure") |
|
2027 go = new figure (h, p); |
|
2028 else if (go_name == "axes") |
|
2029 go = new axes (h, p); |
|
2030 else if (go_name == "line") |
|
2031 go = new line (h, p); |
|
2032 else if (go_name == "text") |
|
2033 go = new text (h, p); |
|
2034 else if (go_name == "image") |
|
2035 go = new image (h, p); |
|
2036 else if (go_name == "surface") |
|
2037 go = new surface (h, p); |
|
2038 |
|
2039 if (go) |
|
2040 handle_map[h] = graphics_object (go); |
|
2041 else |
|
2042 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
|
2043 go_name.c_str ()); |
|
2044 |
|
2045 return h; |
|
2046 } |
|
2047 |
|
2048 graphics_handle |
|
2049 gh_manager::do_make_figure_handle (double val) |
|
2050 { |
|
2051 graphics_handle h = val; |
|
2052 |
|
2053 handle_map[h] = graphics_object (new figure (h, 0)); |
|
2054 |
|
2055 return h; |
|
2056 } |
|
2057 |
|
2058 void |
|
2059 gh_manager::do_push_figure (const graphics_handle& h) |
|
2060 { |
|
2061 do_pop_figure (h); |
|
2062 |
|
2063 figure_list.push_front (h); |
|
2064 } |
|
2065 |
|
2066 void |
|
2067 gh_manager::do_pop_figure (const graphics_handle& h) |
|
2068 { |
|
2069 for (figure_list_iterator p = figure_list.begin (); |
|
2070 p != figure_list.end (); |
|
2071 p++) |
|
2072 { |
|
2073 if (*p == h) |
|
2074 { |
|
2075 figure_list.erase (p); |
|
2076 break; |
|
2077 } |
|
2078 } |
|
2079 } |
|
2080 |
|
2081 property_list::plist_map_type |
|
2082 root_figure::init_factory_properties (void) |
|
2083 { |
|
2084 property_list::plist_map_type plist_map; |
|
2085 |
|
2086 plist_map["figure"] = figure::figure_properties::factory_defaults (); |
|
2087 plist_map["axes"] = axes::axes_properties::factory_defaults (); |
|
2088 plist_map["line"] = line::line_properties::factory_defaults (); |
|
2089 plist_map["text"] = text::text_properties::factory_defaults (); |
|
2090 plist_map["image"] = image::image_properties::factory_defaults (); |
|
2091 plist_map["surface"] = surface::surface_properties::factory_defaults (); |
|
2092 |
|
2093 return plist_map; |
|
2094 } |
|
2095 |
|
2096 // --------------------------------------------------------------------- |
|
2097 |
|
2098 DEFUN (ishandle, args, , |
|
2099 "-*- texinfo -*-\n\ |
6678
|
2100 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406
|
2101 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
|
2102 @end deftypefn") |
|
2103 { |
|
2104 octave_value retval; |
|
2105 |
|
2106 if (args.length () == 1) |
|
2107 retval = is_handle (args(0)); |
|
2108 else |
|
2109 print_usage (); |
|
2110 |
|
2111 return retval; |
|
2112 } |
|
2113 |
|
2114 DEFUN (set, args, , |
|
2115 "-*- texinfo -*-\n\ |
6678
|
2116 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6732
|
2117 Set the named property value or vector @var{p} to the value @var{v}\n\ |
|
2118 in the graphics handle @var{h}.\n\ |
6406
|
2119 @end deftypefn") |
|
2120 { |
|
2121 octave_value retval; |
|
2122 |
|
2123 int nargin = args.length (); |
|
2124 |
|
2125 if (nargin > 0) |
|
2126 { |
6732
|
2127 ColumnVector hcv (args(0).vector_value ()); |
6406
|
2128 |
|
2129 if (! error_state) |
6732
|
2130 { |
6733
|
2131 bool request_drawnow = false; |
|
2132 |
6732
|
2133 for (octave_idx_type n = 0; n < hcv.length (); n++) |
|
2134 { |
|
2135 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
2136 |
6732
|
2137 if (obj) |
|
2138 { |
|
2139 obj.set (args.splice (0, 1)); |
6406
|
2140 |
6733
|
2141 request_drawnow = true; |
6732
|
2142 } |
|
2143 else |
6733
|
2144 { |
|
2145 error ("set: invalid handle (= %g)", hcv(n)); |
|
2146 break; |
|
2147 } |
6732
|
2148 } |
6733
|
2149 |
|
2150 if (! error_state && request_drawnow) |
|
2151 feval ("__request_drawnow__"); |
6732
|
2152 } |
6406
|
2153 else |
6732
|
2154 error ("set: expecting graphics handle as first argument"); |
6406
|
2155 } |
|
2156 else |
|
2157 print_usage (); |
|
2158 |
|
2159 return retval; |
|
2160 } |
|
2161 |
|
2162 DEFUN (get, args, , |
|
2163 "-*- texinfo -*-\n\ |
6678
|
2164 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406
|
2165 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
|
2166 If @var{p} is omitted, return the complete property list for @var{h}.\n\ |
6732
|
2167 If @var{h} is a vector, return a cell array including the property\n\ |
|
2168 values or lists respectively.\n\ |
6406
|
2169 @end deftypefn") |
|
2170 { |
|
2171 octave_value retval; |
6732
|
2172 octave_value_list vlist; |
6406
|
2173 |
|
2174 int nargin = args.length (); |
|
2175 |
|
2176 if (nargin == 1 || nargin == 2) |
|
2177 { |
6732
|
2178 ColumnVector hcv (args(0).vector_value ()); |
6406
|
2179 |
|
2180 if (! error_state) |
6732
|
2181 { |
6733
|
2182 octave_idx_type len = hcv.length (); |
|
2183 |
|
2184 vlist.resize (len); |
|
2185 |
|
2186 for (octave_idx_type n = 0; n < len; n++) |
6732
|
2187 { |
|
2188 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
2189 |
6732
|
2190 if (obj) |
|
2191 { |
|
2192 if (nargin == 1) |
|
2193 vlist(n) = obj.get (); |
|
2194 else |
|
2195 { |
|
2196 property_name property = args(1).string_value (); |
6406
|
2197 |
6732
|
2198 if (! error_state) |
|
2199 vlist(n) = obj.get (property); |
|
2200 else |
6733
|
2201 { |
|
2202 error ("get: expecting property name as second argument"); |
|
2203 break; |
|
2204 } |
6732
|
2205 } |
|
2206 } |
|
2207 else |
6733
|
2208 { |
|
2209 error ("get: invalid handle (= %g)", hcv(n)); |
|
2210 break; |
|
2211 } |
6732
|
2212 } |
|
2213 } |
6406
|
2214 else |
6732
|
2215 error ("get: expecting graphics handle as first argument"); |
6406
|
2216 } |
|
2217 else |
|
2218 print_usage (); |
|
2219 |
6733
|
2220 if (! error_state) |
6732
|
2221 { |
6733
|
2222 octave_idx_type len = vlist.length (); |
|
2223 |
|
2224 if (len > 1) |
|
2225 retval = Cell (vlist); |
|
2226 else if (len == 1) |
|
2227 retval = vlist(0); |
6732
|
2228 } |
|
2229 |
6406
|
2230 return retval; |
|
2231 } |
|
2232 |
|
2233 static octave_value |
|
2234 make_graphics_object (const std::string& go_name, |
6732
|
2235 const octave_value_list& args) |
6406
|
2236 { |
|
2237 octave_value retval; |
|
2238 |
|
2239 double val = args(0).double_value (); |
|
2240 |
|
2241 if (! error_state) |
|
2242 { |
|
2243 graphics_handle parent = gh_manager::lookup (val); |
|
2244 |
|
2245 if (! xisnan (parent)) |
|
2246 { |
|
2247 graphics_handle h |
|
2248 = gh_manager::make_graphics_handle (go_name, parent); |
|
2249 |
|
2250 if (! error_state) |
|
2251 { |
|
2252 adopt (parent, h); |
|
2253 |
|
2254 xset (h, args.splice (0, 1)); |
|
2255 |
|
2256 retval = h; |
|
2257 } |
|
2258 else |
|
2259 error ("__go%s__: unable to create graphics handle", |
|
2260 go_name.c_str ()); |
|
2261 } |
|
2262 else |
|
2263 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2264 } |
|
2265 else |
|
2266 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2267 |
|
2268 return retval; |
|
2269 } |
|
2270 |
|
2271 DEFUN (__go_figure__, args, , |
|
2272 "-*- texinfo -*-\n\ |
|
2273 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ |
|
2274 Create a figure graphics object.\n\ |
|
2275 @end deftypefn") |
|
2276 { |
|
2277 octave_value retval; |
|
2278 |
|
2279 if (args.length () > 0) |
|
2280 { |
|
2281 double val = args(0).double_value (); |
|
2282 |
|
2283 if (! error_state) |
|
2284 { |
|
2285 if (is_figure (val)) |
|
2286 { |
|
2287 graphics_handle h = gh_manager::lookup (val); |
|
2288 |
|
2289 xset (h, args.splice (0, 1)); |
|
2290 |
|
2291 retval = h; |
|
2292 } |
|
2293 else |
|
2294 { |
|
2295 graphics_handle h = octave_NaN; |
|
2296 |
|
2297 if (xisnan (val)) |
|
2298 h = gh_manager::make_graphics_handle ("figure", 0); |
|
2299 else if (val > 0 && D_NINT (val) == val) |
|
2300 h = gh_manager::make_figure_handle (val); |
|
2301 else |
|
2302 error ("__go_figure__: invalid figure number"); |
|
2303 |
|
2304 if (! (error_state || xisnan (h))) |
|
2305 { |
|
2306 adopt (0, h); |
|
2307 |
|
2308 xset (h, args.splice (0, 1)); |
|
2309 |
|
2310 retval = h; |
|
2311 } |
|
2312 else |
|
2313 error ("__go_figure__: failed to create figure handle"); |
|
2314 } |
|
2315 } |
|
2316 else |
|
2317 error ("__go_figure__: expecting figure number to be double value"); |
|
2318 } |
|
2319 else |
|
2320 print_usage (); |
|
2321 |
|
2322 return retval; |
|
2323 } |
|
2324 |
|
2325 #define GO_BODY(TYPE) \ |
|
2326 octave_value retval; \ |
|
2327 \ |
|
2328 if (args.length () > 0) \ |
|
2329 retval = make_graphics_object (#TYPE, args); \ |
|
2330 else \ |
|
2331 print_usage (); \ |
|
2332 \ |
|
2333 return retval |
|
2334 |
|
2335 DEFUN (__go_axes__, args, , |
|
2336 "-*- texinfo -*-\n\ |
|
2337 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ |
|
2338 Create an axes graphics object.\n\ |
|
2339 @end deftypefn") |
|
2340 { |
|
2341 GO_BODY (axes); |
|
2342 } |
|
2343 |
|
2344 DEFUN (__go_line__, args, , |
|
2345 "-*- texinfo -*-\n\ |
|
2346 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ |
|
2347 Create a line graphics object.\n\ |
|
2348 @end deftypefn") |
|
2349 { |
|
2350 GO_BODY (line); |
|
2351 } |
|
2352 |
|
2353 DEFUN (__go_text__, args, , |
|
2354 "-*- texinfo -*-\n\ |
|
2355 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ |
|
2356 Create a text graphics object.\n\ |
|
2357 @end deftypefn") |
|
2358 { |
|
2359 GO_BODY (text); |
|
2360 } |
|
2361 |
|
2362 DEFUN (__go_image__, args, , |
|
2363 "-*- texinfo -*-\n\ |
|
2364 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ |
|
2365 Create an image graphics object.\n\ |
|
2366 @end deftypefn") |
|
2367 { |
|
2368 GO_BODY (image); |
|
2369 } |
|
2370 |
|
2371 DEFUN (__go_surface__, args, , |
|
2372 "-*- texinfo -*-\n\ |
|
2373 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ |
|
2374 Create a surface graphics object.\n\ |
|
2375 @end deftypefn") |
|
2376 { |
|
2377 GO_BODY (surface); |
|
2378 } |
|
2379 |
|
2380 DEFUN (__go_delete__, args, , |
|
2381 "-*- texinfo -*-\n\ |
|
2382 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ |
|
2383 @end deftypefn") |
|
2384 { |
|
2385 octave_value_list retval; |
|
2386 |
|
2387 if (args.length () == 1) |
|
2388 { |
|
2389 graphics_handle h = octave_NaN; |
|
2390 |
|
2391 double val = args(0).double_value (); |
|
2392 |
|
2393 if (! error_state) |
|
2394 { |
|
2395 h = gh_manager::lookup (val); |
|
2396 |
|
2397 if (! xisnan (h)) |
|
2398 { |
|
2399 graphics_object obj = gh_manager::get_object (h); |
|
2400 |
|
2401 graphics_handle parent_h = obj.get_parent (); |
|
2402 |
|
2403 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
2404 |
|
2405 parent_obj.remove_child (h); |
|
2406 |
|
2407 gh_manager::free (h); |
|
2408 } |
|
2409 else |
|
2410 error ("delete: invalid graphics object (= %g)", val); |
|
2411 } |
|
2412 else |
|
2413 error ("delete: invalid graphics object"); |
|
2414 } |
|
2415 else |
|
2416 print_usage (); |
|
2417 |
|
2418 return retval; |
|
2419 } |
|
2420 |
|
2421 DEFUN (__go_axes_init__, args, , |
|
2422 "-*- texinfo -*-\n\ |
|
2423 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ |
|
2424 Initialize axes object.\n\ |
|
2425 @end deftypefn") |
|
2426 { |
|
2427 octave_value retval; |
|
2428 |
|
2429 int nargin = args.length (); |
|
2430 |
|
2431 std::string mode = ""; |
|
2432 |
|
2433 if (nargin == 2) |
|
2434 { |
|
2435 mode = args(1).string_value (); |
|
2436 |
|
2437 if (error_state) |
|
2438 return retval; |
|
2439 } |
|
2440 |
|
2441 if (nargin == 1 || nargin == 2) |
|
2442 { |
|
2443 graphics_handle h = octave_NaN; |
|
2444 |
|
2445 double val = args(0).double_value (); |
|
2446 |
|
2447 if (! error_state) |
|
2448 { |
|
2449 h = gh_manager::lookup (val); |
|
2450 |
|
2451 if (! xisnan (h)) |
|
2452 { |
|
2453 graphics_object obj = gh_manager::get_object (h); |
|
2454 |
|
2455 obj.set_defaults (mode); |
|
2456 } |
|
2457 else |
|
2458 error ("__go_axes_init__: invalid graphics object (= %g)", val); |
|
2459 } |
|
2460 else |
|
2461 error ("__go_axes_init__: invalid graphics object"); |
|
2462 } |
|
2463 else |
|
2464 print_usage (); |
|
2465 |
|
2466 return retval; |
|
2467 } |
|
2468 |
|
2469 DEFUN (__go_handles__, , , |
|
2470 "-*- texinfo -*-\n\ |
|
2471 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ |
|
2472 Return current list of function handles.\n\ |
|
2473 @end deftypefn") |
|
2474 { |
6425
|
2475 return octave_value (gh_manager::handle_list ()); |
|
2476 } |
|
2477 |
|
2478 DEFUN (__go_figure_handles__, , , |
|
2479 "-*- texinfo -*-\n\ |
|
2480 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ |
|
2481 Return current list of function handles.\n\ |
|
2482 @end deftypefn") |
|
2483 { |
|
2484 return octave_value (gh_manager::figure_handle_list ()); |
6406
|
2485 } |
|
2486 |
6595
|
2487 octave_value |
|
2488 get_property_from_handle (double handle, const std::string &property, |
|
2489 const std::string &func) |
|
2490 { |
|
2491 graphics_object obj = gh_manager::get_object (handle); |
|
2492 octave_value retval; |
|
2493 |
|
2494 if (obj) |
|
2495 { |
|
2496 property_name p = std::string (property); |
|
2497 retval = obj.get (p); |
|
2498 } |
|
2499 else |
|
2500 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2501 |
|
2502 return retval; |
|
2503 } |
|
2504 |
|
2505 bool |
|
2506 set_property_in_handle (double handle, const std::string &property, |
|
2507 const octave_value &arg, const std::string &func) |
|
2508 { |
|
2509 graphics_object obj = gh_manager::get_object (handle); |
|
2510 int ret = false; |
|
2511 |
|
2512 if (obj) |
|
2513 { |
|
2514 property_name p = std::string (property); |
|
2515 obj.set (p, arg); |
|
2516 if (!error_state) |
|
2517 ret = true; |
|
2518 } |
|
2519 else |
|
2520 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2521 |
|
2522 return ret; |
|
2523 } |
|
2524 |
6406
|
2525 /* |
|
2526 ;;; Local Variables: *** |
|
2527 ;;; mode: C++ *** |
|
2528 ;;; End: *** |
|
2529 */ |