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