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 |
6807
|
248 if (pfx.compare ("image") || pfx.compare ("patch")) |
6705
|
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 |
6807
|
321 if (pfx.compare ("image") || pfx.compare ("patch")) |
6705
|
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 |
6836
|
690 void |
|
691 base_properties::set_parent (const octave_value& val) |
6705
|
692 { |
|
693 double tmp = val.double_value (); |
6406
|
694 |
6705
|
695 graphics_handle new_parent = octave_NaN; |
6406
|
696 |
6705
|
697 if (! error_state) |
|
698 { |
|
699 new_parent = gh_manager::lookup (tmp); |
6406
|
700 |
6705
|
701 if (! xisnan (new_parent)) |
|
702 { |
|
703 graphics_object parent_obj = gh_manager::get_object (parent); |
6406
|
704 |
6705
|
705 parent_obj.remove_child (__myhandle__); |
6406
|
706 |
6705
|
707 parent = new_parent; |
6406
|
708 |
6705
|
709 ::adopt (parent, __myhandle__); |
|
710 } |
|
711 else |
|
712 error ("set: invalid graphics handle (= %g) for parent", tmp); |
|
713 } |
|
714 else |
|
715 error ("set: expecting parent to be a graphics handle"); |
|
716 } |
6432
|
717 |
6705
|
718 void |
6836
|
719 base_properties::mark_modified (void) |
|
720 { |
|
721 __modified__ = true; |
|
722 graphics_object parent_obj = gh_manager::get_object (parent); |
|
723 parent_obj.mark_modified (); |
|
724 } |
|
725 |
|
726 void |
|
727 base_properties::override_defaults (base_graphics_object& obj) |
|
728 { |
|
729 graphics_object parent_obj = gh_manager::get_object (parent); |
|
730 parent_obj.override_defaults (obj); |
|
731 } |
|
732 |
|
733 void |
|
734 base_properties::delete_children (void) |
|
735 { |
|
736 octave_idx_type n = children.numel (); |
|
737 |
|
738 for (octave_idx_type i = 0; i < n; i++) |
|
739 gh_manager::free (children(i)); |
|
740 } |
|
741 |
|
742 void |
6705
|
743 root_figure::root_figure_properties::set (const property_name& name, |
|
744 const octave_value& val) |
|
745 { |
|
746 if (name.compare ("currentfigure")) |
|
747 { |
|
748 octave_value tval = empty_to_nan (val); |
6406
|
749 |
6705
|
750 if (is_handle (tval)) |
|
751 { |
|
752 currentfigure = tval.double_value (); |
6406
|
753 |
6705
|
754 gh_manager::push_figure (currentfigure); |
|
755 } |
|
756 else |
|
757 gripe_set_invalid ("currentfigure"); |
|
758 } |
|
759 else if (name.compare ("children")) |
|
760 children = maybe_set_children (children, val); |
|
761 else if (name.compare ("visible")) |
|
762 visible = val; |
|
763 else |
|
764 warning ("set: invalid property `%s'", name.c_str ()); |
|
765 } |
6406
|
766 |
6705
|
767 octave_value root_figure::root_figure_properties::get (void) const |
|
768 { |
|
769 Octave_map m; |
6406
|
770 |
6705
|
771 m.assign ("type", type); |
|
772 m.assign ("currentfigure", nan_to_empty (currentfigure)); |
|
773 m.assign ("children", children); |
|
774 m.assign ("visible", visible); |
6406
|
775 |
6705
|
776 return m; |
|
777 } |
6406
|
778 |
6705
|
779 octave_value |
|
780 root_figure::root_figure_properties::get (const property_name& name) const |
|
781 { |
|
782 octave_value retval; |
6406
|
783 |
6705
|
784 if (name.compare ("type")) |
|
785 retval = type; |
|
786 else if (name.compare ("currentfigure")) |
|
787 retval = nan_to_empty (currentfigure); |
|
788 else if (name.compare ("children")) |
|
789 retval = children; |
|
790 else if (name.compare ("visible")) |
|
791 retval = visible; |
|
792 else |
|
793 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
794 |
6705
|
795 return retval; |
|
796 } |
6406
|
797 |
|
798 property_list |
|
799 root_figure::factory_properties = root_figure::init_factory_properties (); |
|
800 |
|
801 std::string root_figure::root_figure_properties::go_name ("root figure"); |
|
802 |
|
803 // --------------------------------------------------------------------- |
|
804 |
6705
|
805 figure::figure_properties::figure_properties (const graphics_handle& mh, |
|
806 const graphics_handle& p) |
|
807 : base_properties (go_name, mh, p), |
|
808 __plot_stream__ (Matrix ()), |
|
809 nextplot ("replace"), |
|
810 closerequestfcn (make_fcn_handle ("closereq")), |
|
811 currentaxes (octave_NaN), |
|
812 colormap (), |
|
813 visible ("on"), |
|
814 paperorientation ("portrait") |
|
815 { } |
|
816 |
|
817 void |
|
818 figure::figure_properties::set (const property_name& name, |
|
819 const octave_value& val) |
6406
|
820 { |
6705
|
821 bool modified = true; |
6406
|
822 |
6705
|
823 if (name.compare ("children")) |
|
824 children = maybe_set_children (children, val); |
|
825 else if (name.compare ("__modified__")) |
|
826 { |
|
827 __modified__ = val.bool_value (); |
|
828 modified = false; |
|
829 } |
|
830 else if (name.compare ("__plot_stream__")) |
|
831 __plot_stream__ = val; |
|
832 else if (name.compare ("nextplot")) |
|
833 nextplot = val; |
|
834 else if (name.compare ("closerequestfcn")) |
|
835 closerequestfcn = val; |
|
836 else if (name.compare ("currentaxes")) |
6406
|
837 { |
6705
|
838 octave_value tval = empty_to_nan (val); |
6432
|
839 |
6705
|
840 if (is_handle (tval)) |
|
841 currentaxes = tval.double_value (); |
|
842 else |
|
843 gripe_set_invalid ("currentaxes"); |
|
844 } |
|
845 else if (name.compare ("colormap")) |
|
846 colormap = colormap_property (val); |
|
847 else if (name.compare ("visible")) |
|
848 { |
|
849 std::string s = val.string_value (); |
|
850 |
|
851 if (! error_state) |
6432
|
852 { |
6705
|
853 if (s == "on") |
|
854 xset (0, "currentfigure", __myhandle__); |
6425
|
855 |
6705
|
856 visible = val; |
6425
|
857 } |
6406
|
858 } |
6705
|
859 else if (name.compare ("paperorientation")) |
|
860 paperorientation = val; |
|
861 else |
6406
|
862 { |
6705
|
863 modified = false; |
|
864 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
865 } |
|
866 |
6705
|
867 if (modified) |
|
868 mark_modified (); |
|
869 } |
|
870 |
|
871 octave_value |
|
872 figure::figure_properties::get (void) const |
|
873 { |
|
874 Octave_map m; |
6406
|
875 |
6705
|
876 m.assign ("type", type); |
|
877 m.assign ("parent", parent); |
|
878 m.assign ("children", children); |
|
879 m.assign ("__modified__", __modified__); |
|
880 m.assign ("__plot_stream__", __plot_stream__); |
|
881 m.assign ("nextplot", nextplot); |
|
882 m.assign ("closerequestfcn", closerequestfcn); |
|
883 m.assign ("currentaxes", nan_to_empty (currentaxes)); |
|
884 m.assign ("colormap", colormap); |
|
885 m.assign ("visible", visible); |
|
886 m.assign ("paperorientation", paperorientation); |
|
887 |
|
888 return m; |
|
889 } |
|
890 |
|
891 octave_value |
|
892 figure::figure_properties::get (const property_name& name) const |
|
893 { |
|
894 octave_value retval; |
6406
|
895 |
6705
|
896 if (name.compare ("type")) |
|
897 retval = type; |
|
898 else if (name.compare ("parent")) |
|
899 retval = parent; |
|
900 else if (name.compare ("children")) |
|
901 retval = children; |
|
902 else if (name.compare ("__modified__")) |
|
903 retval = __modified__; |
|
904 else if (name.compare ("__plot_stream__")) |
|
905 retval = __plot_stream__; |
|
906 else if (name.compare ("nextplot")) |
|
907 retval = nextplot; |
|
908 else if (name.compare ("closerequestfcn")) |
|
909 retval = closerequestfcn; |
|
910 else if (name.compare ("currentaxes")) |
|
911 retval = nan_to_empty (currentaxes); |
|
912 else if (name.compare ("colormap")) |
|
913 retval = colormap; |
|
914 else if (name.compare ("visible")) |
|
915 retval = visible; |
|
916 else if (name.compare ("paperorientation")) |
|
917 retval = paperorientation; |
|
918 else |
|
919 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
920 |
6705
|
921 return retval; |
|
922 } |
6406
|
923 |
6836
|
924 void |
|
925 figure::figure_properties::close (void) |
6705
|
926 { |
|
927 if (! __plot_stream__.is_empty ()) |
6406
|
928 { |
6705
|
929 octave_value_list args; |
|
930 args(1) = "\nquit;\n"; |
|
931 args(0) = __plot_stream__; |
|
932 feval ("fputs", args); |
|
933 args.resize (1); |
|
934 feval ("fflush", args); |
|
935 feval ("pclose", args); |
6406
|
936 } |
|
937 |
6705
|
938 gh_manager::pop_figure (__myhandle__); |
6406
|
939 |
6705
|
940 xset (0, "currentfigure", gh_manager::current_figure ()); |
|
941 } |
6432
|
942 |
6836
|
943 property_list::pval_map_type |
|
944 figure::figure_properties::factory_defaults (void) |
6705
|
945 { |
|
946 property_list::pval_map_type m; |
6406
|
947 |
6705
|
948 m["nextplot"] = "replace"; |
|
949 // m["closerequestfcn"] = make_fcn_handle ("closereq"); |
|
950 m["colormap"] = colormap_property (); |
|
951 m["visible"] = "on"; |
|
952 m["paperorientation"] = "portrait"; |
6406
|
953 |
6705
|
954 return m; |
|
955 } |
6406
|
956 |
6836
|
957 octave_value |
|
958 figure::get_default (const property_name& name) const |
|
959 { |
|
960 octave_value retval = default_properties.lookup (name); |
|
961 |
|
962 if (retval.is_undefined ()) |
|
963 { |
|
964 graphics_handle parent = get_parent (); |
|
965 graphics_object parent_obj = gh_manager::get_object (parent); |
|
966 |
|
967 retval = parent_obj.get_default (name); |
|
968 } |
|
969 |
|
970 return retval; |
|
971 } |
|
972 |
6406
|
973 std::string figure::figure_properties::go_name ("figure"); |
|
974 |
|
975 // --------------------------------------------------------------------- |
|
976 |
6705
|
977 axes::axes_properties::axes_properties (const graphics_handle& mh, |
|
978 const graphics_handle& p) |
|
979 : base_properties (go_name, mh, p), |
|
980 position (Matrix ()), |
|
981 title (octave_NaN), |
|
982 box ("on"), |
|
983 key ("off"), |
|
984 keybox ("off"), |
|
985 keypos (1), |
|
986 dataaspectratio (Matrix (1, 3, 1.0)), |
|
987 dataaspectratiomode ("auto"), |
|
988 xlim (), |
|
989 ylim (), |
|
990 zlim (), |
6807
|
991 clim (), |
6705
|
992 xlimmode ("auto"), |
|
993 ylimmode ("auto"), |
|
994 zlimmode ("auto"), |
6807
|
995 climmode ("auto"), |
6705
|
996 xlabel (octave_NaN), |
|
997 ylabel (octave_NaN), |
|
998 zlabel (octave_NaN), |
|
999 xgrid ("off"), |
|
1000 ygrid ("off"), |
|
1001 zgrid ("off"), |
|
1002 xminorgrid ("off"), |
|
1003 yminorgrid ("off"), |
|
1004 zminorgrid ("off"), |
|
1005 xtick (Matrix ()), |
|
1006 ytick (Matrix ()), |
|
1007 ztick (Matrix ()), |
|
1008 xtickmode ("auto"), |
|
1009 ytickmode ("auto"), |
|
1010 ztickmode ("auto"), |
|
1011 xticklabel (""), |
|
1012 yticklabel (""), |
|
1013 zticklabel (""), |
|
1014 xticklabelmode ("auto"), |
|
1015 yticklabelmode ("auto"), |
|
1016 zticklabelmode ("auto"), |
|
1017 xscale ("linear"), |
|
1018 yscale ("linear"), |
|
1019 zscale ("linear"), |
|
1020 xdir ("normal"), |
|
1021 ydir ("normal"), |
|
1022 zdir ("normal"), |
6809
|
1023 xaxislocation ("bottom"), |
|
1024 yaxislocation ("left"), |
6705
|
1025 view (), |
6765
|
1026 visible ("on"), |
6705
|
1027 nextplot ("replace"), |
|
1028 outerposition () |
|
1029 { |
|
1030 Matrix tlim (1, 2, 0.0); |
|
1031 tlim(1) = 1; |
|
1032 xlim = tlim; |
|
1033 ylim = tlim; |
|
1034 zlim = tlim; |
6807
|
1035 Matrix cl (1, 2, 0); |
|
1036 cl(1) = 1; |
|
1037 clim = cl; |
6705
|
1038 |
|
1039 Matrix tview (1, 2, 0.0); |
|
1040 tview(1) = 90; |
|
1041 view = tview; |
|
1042 |
|
1043 Matrix touterposition (1, 4, 0.0); |
|
1044 touterposition(2) = 1; |
|
1045 touterposition(3) = 1; |
|
1046 outerposition = touterposition; |
|
1047 } |
|
1048 |
|
1049 void |
|
1050 axes::axes_properties::set (const property_name& name, const octave_value& val) |
6406
|
1051 { |
6705
|
1052 bool modified = true; |
|
1053 |
|
1054 if (name.compare ("parent")) |
|
1055 set_parent (val); |
|
1056 else if (name.compare ("children")) |
|
1057 children = maybe_set_children (children, val); |
|
1058 else if (name.compare ("__modified__")) |
|
1059 { |
|
1060 __modified__ = val.bool_value (); |
|
1061 modified = false; |
|
1062 } |
|
1063 else if (name.compare ("position")) |
|
1064 position = val; |
|
1065 else if (name.compare ("title")) |
|
1066 { |
|
1067 graphics_handle h = ::reparent (val, "set", "title", |
|
1068 __myhandle__, false); |
|
1069 if (! error_state) |
|
1070 { |
|
1071 if (! xisnan (title)) |
|
1072 gh_manager::free (title); |
|
1073 |
|
1074 title = h; |
|
1075 } |
|
1076 } |
|
1077 else if (name.compare ("box")) |
|
1078 box = val; |
|
1079 else if (name.compare ("key")) |
|
1080 key = val; |
|
1081 else if (name.compare ("keybox")) |
|
1082 keybox = val; |
|
1083 else if (name.compare ("keypos")) |
|
1084 keypos = val; |
|
1085 else if (name.compare ("dataaspectratio")) |
|
1086 { |
|
1087 dataaspectratio = val; |
|
1088 dataaspectratiomode = "manual"; |
|
1089 } |
|
1090 else if (name.compare ("dataaspectratiomode")) |
|
1091 dataaspectratiomode = val; |
|
1092 else if (name.compare ("xlim")) |
|
1093 { |
|
1094 xlim = val; |
|
1095 xlimmode = "manual"; |
|
1096 } |
|
1097 else if (name.compare ("ylim")) |
|
1098 { |
|
1099 ylim = val; |
|
1100 ylimmode = "manual"; |
|
1101 } |
|
1102 else if (name.compare ("zlim")) |
|
1103 { |
|
1104 zlim = val; |
|
1105 zlimmode = "manual"; |
|
1106 } |
6807
|
1107 else if (name.compare ("clim")) |
|
1108 { |
|
1109 clim = val; |
|
1110 climmode = "manual"; |
|
1111 } |
6705
|
1112 else if (name.compare ("xlimmode")) |
|
1113 xlimmode = val; |
|
1114 else if (name.compare ("ylimmode")) |
|
1115 ylimmode = val; |
|
1116 else if (name.compare ("zlimmode")) |
|
1117 zlimmode = val; |
6807
|
1118 else if (name.compare ("climmode")) |
|
1119 climmode = val; |
6705
|
1120 else if (name.compare ("xlabel")) |
|
1121 { |
|
1122 graphics_handle h = ::reparent (val, "set", "xlabel", |
|
1123 __myhandle__, false); |
|
1124 if (! error_state) |
|
1125 { |
|
1126 if (! xisnan (xlabel)) |
|
1127 gh_manager::free (xlabel); |
|
1128 |
|
1129 xlabel = h; |
|
1130 } |
|
1131 } |
|
1132 else if (name.compare ("ylabel")) |
|
1133 { |
|
1134 graphics_handle h = ::reparent (val, "set", "ylabel", |
|
1135 __myhandle__, false); |
|
1136 if (! error_state) |
|
1137 { |
|
1138 if (! xisnan (ylabel)) |
|
1139 gh_manager::free (ylabel); |
|
1140 |
|
1141 ylabel = h; |
|
1142 } |
|
1143 } |
|
1144 else if (name.compare ("zlabel")) |
|
1145 { |
|
1146 graphics_handle h = ::reparent (val, "set", "zlabel", |
|
1147 __myhandle__, false); |
|
1148 if (! error_state) |
|
1149 { |
|
1150 if (! xisnan (zlabel)) |
|
1151 gh_manager::free (zlabel); |
|
1152 |
|
1153 zlabel = h; |
|
1154 } |
|
1155 } |
|
1156 else if (name.compare ("xgrid")) |
|
1157 xgrid = val; |
|
1158 else if (name.compare ("ygrid")) |
|
1159 ygrid = val; |
|
1160 else if (name.compare ("zgrid")) |
|
1161 zgrid = val; |
|
1162 else if (name.compare ("xminorgrid")) |
|
1163 xminorgrid = val; |
|
1164 else if (name.compare ("yminorgrid")) |
|
1165 yminorgrid = val; |
|
1166 else if (name.compare ("zminorgrid")) |
|
1167 zminorgrid = val; |
|
1168 else if (name.compare ("xtick")) |
|
1169 { |
|
1170 xtick = val; |
|
1171 xtickmode = "manual"; |
|
1172 } |
|
1173 else if (name.compare ("ytick")) |
6406
|
1174 { |
6705
|
1175 ytick = val; |
|
1176 ytickmode = "manual"; |
|
1177 } |
|
1178 else if (name.compare ("ztick")) |
|
1179 { |
|
1180 ztick = val; |
|
1181 ztickmode = "manual"; |
|
1182 } |
|
1183 else if (name.compare ("xtickmode")) |
|
1184 xtickmode = val; |
|
1185 else if (name.compare ("ytickmode")) |
|
1186 ytickmode = val; |
|
1187 else if (name.compare ("ztickmode")) |
|
1188 ztickmode = val; |
|
1189 else if (name.compare ("xticklabel")) |
|
1190 { |
|
1191 xticklabel = val; |
|
1192 xticklabelmode = "manual"; |
|
1193 } |
|
1194 else if (name.compare ("yticklabel")) |
|
1195 { |
|
1196 yticklabel = val; |
|
1197 yticklabelmode = "manual"; |
|
1198 } |
|
1199 else if (name.compare ("zticklabel")) |
|
1200 { |
|
1201 zticklabel = val; |
|
1202 zticklabelmode = "manual"; |
|
1203 } |
|
1204 else if (name.compare ("xticklabelmode")) |
|
1205 xticklabelmode = val; |
|
1206 else if (name.compare ("yticklabelmode")) |
|
1207 yticklabelmode = val; |
|
1208 else if (name.compare ("zticklabelmode")) |
|
1209 zticklabelmode = val; |
|
1210 else if (name.compare ("xscale")) |
|
1211 xscale = val; |
|
1212 else if (name.compare ("yscale")) |
|
1213 yscale = val; |
|
1214 else if (name.compare ("zscale")) |
|
1215 zscale = val; |
|
1216 else if (name.compare ("xdir")) |
|
1217 xdir = val; |
|
1218 else if (name.compare ("ydir")) |
|
1219 ydir = val; |
|
1220 else if (name.compare ("zdir")) |
|
1221 zdir = val; |
6809
|
1222 else if (name.compare ("xaxislocation")) |
|
1223 xaxislocation = val; |
|
1224 else if (name.compare ("yaxislocation")) |
|
1225 yaxislocation = val; |
6705
|
1226 else if (name.compare ("view")) |
|
1227 view = val; |
6765
|
1228 else if (name.compare ("visible")) |
|
1229 visible = val; |
6705
|
1230 else if (name.compare ("nextplot")) |
|
1231 nextplot = val; |
|
1232 else if (name.compare ("outerposition")) |
|
1233 outerposition = val; |
|
1234 else |
|
1235 { |
|
1236 modified = false; |
|
1237 warning ("set: invalid property `%s'", name.c_str ()); |
|
1238 } |
6406
|
1239 |
6705
|
1240 if (modified) |
|
1241 mark_modified (); |
|
1242 } |
|
1243 |
|
1244 void |
|
1245 axes::axes_properties::set_defaults (base_graphics_object& obj, |
|
1246 const std::string& mode) |
|
1247 { |
|
1248 position = Matrix (); |
|
1249 title = octave_NaN; |
|
1250 box = "on"; |
|
1251 key = "off"; |
|
1252 keybox = "off"; |
|
1253 keypos = 1; |
|
1254 dataaspectratio = Matrix (1, 3, 1.0); |
|
1255 dataaspectratiomode = "auto"; |
|
1256 |
|
1257 Matrix tlim (1, 2, 0.0); |
|
1258 tlim(1) = 1; |
|
1259 xlim = tlim; |
|
1260 ylim = tlim; |
|
1261 zlim = tlim; |
6807
|
1262 |
|
1263 Matrix cl (1, 2, 0); |
|
1264 cl(1) = 1; |
|
1265 clim = cl; |
|
1266 |
6705
|
1267 xlimmode = "auto"; |
|
1268 ylimmode = "auto"; |
|
1269 zlimmode = "auto"; |
6807
|
1270 climmode = "auto"; |
6705
|
1271 xlabel = octave_NaN; |
|
1272 ylabel = octave_NaN; |
|
1273 zlabel = octave_NaN; |
|
1274 xgrid = "off"; |
|
1275 ygrid = "off"; |
|
1276 zgrid = "off"; |
|
1277 xminorgrid = "off"; |
|
1278 yminorgrid = "off"; |
|
1279 zminorgrid = "off"; |
|
1280 xtick = Matrix (); |
|
1281 ytick = Matrix (); |
|
1282 ztick = Matrix (); |
|
1283 xtickmode = "auto"; |
|
1284 ytickmode = "auto"; |
|
1285 ztickmode = "auto"; |
|
1286 xticklabel = ""; |
|
1287 yticklabel = ""; |
|
1288 zticklabel = ""; |
|
1289 xticklabelmode = "auto"; |
|
1290 yticklabelmode = "auto"; |
|
1291 zticklabelmode = "auto"; |
|
1292 xscale = "linear"; |
|
1293 yscale = "linear"; |
|
1294 zscale = "linear"; |
|
1295 xdir = "normal"; |
|
1296 ydir = "normal"; |
|
1297 zdir = "normal"; |
6809
|
1298 xaxislocation = "left"; |
|
1299 yaxislocation = "bottom"; |
6705
|
1300 |
|
1301 Matrix tview (1, 2, 0.0); |
|
1302 tview(1) = 90; |
|
1303 view = tview; |
|
1304 |
6765
|
1305 visible = "on"; |
6705
|
1306 nextplot = "replace"; |
|
1307 |
|
1308 // FIXME -- this is not quite right; we should preserve |
|
1309 // "position" and "units". |
|
1310 |
|
1311 if (mode != "replace") |
|
1312 { |
6406
|
1313 Matrix touterposition (1, 4, 0.0); |
|
1314 touterposition(2) = 1; |
|
1315 touterposition(3) = 1; |
|
1316 outerposition = touterposition; |
|
1317 } |
|
1318 |
6705
|
1319 delete_children (); |
6406
|
1320 |
6705
|
1321 children = Matrix (); |
6432
|
1322 |
6705
|
1323 override_defaults (obj); |
|
1324 } |
|
1325 |
|
1326 octave_value |
|
1327 axes::axes_properties::get (void) const |
|
1328 { |
|
1329 Octave_map m; |
6406
|
1330 |
6705
|
1331 if (xisnan (title)) |
|
1332 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1333 |
|
1334 if (xisnan (xlabel)) |
|
1335 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
6406
|
1336 |
6705
|
1337 if (xisnan (ylabel)) |
|
1338 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
6406
|
1339 |
6705
|
1340 if (xisnan (zlabel)) |
|
1341 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
6406
|
1342 |
6705
|
1343 m.assign ("type", type); |
|
1344 m.assign ("parent", parent); |
|
1345 m.assign ("children", children); |
|
1346 m.assign ("__modified__", __modified__); |
|
1347 m.assign ("position", position); |
|
1348 m.assign ("title", title); |
|
1349 m.assign ("box", box); |
|
1350 m.assign ("key", key); |
|
1351 m.assign ("keybox", keybox); |
|
1352 m.assign ("keypos", keypos); |
|
1353 m.assign ("dataaspectratio", dataaspectratio); |
|
1354 m.assign ("dataaspectratiomode", dataaspectratiomode); |
|
1355 m.assign ("xlim", xlim); |
|
1356 m.assign ("ylim", ylim); |
|
1357 m.assign ("zlim", zlim); |
6807
|
1358 m.assign ("clim", clim); |
6705
|
1359 m.assign ("xlimmode", xlimmode); |
|
1360 m.assign ("ylimmode", ylimmode); |
|
1361 m.assign ("zlimmode", zlimmode); |
6807
|
1362 m.assign ("climmode", climmode); |
6705
|
1363 m.assign ("xlabel", xlabel); |
|
1364 m.assign ("ylabel", ylabel); |
|
1365 m.assign ("zlabel", zlabel); |
|
1366 m.assign ("xgrid", xgrid); |
|
1367 m.assign ("ygrid", ygrid); |
|
1368 m.assign ("zgrid", zgrid); |
|
1369 m.assign ("xminorgrid", xminorgrid); |
|
1370 m.assign ("yminorgrid", yminorgrid); |
|
1371 m.assign ("zminorgrid", zminorgrid); |
|
1372 m.assign ("xtick", xtick); |
|
1373 m.assign ("ytick", ytick); |
|
1374 m.assign ("ztick", ztick); |
|
1375 m.assign ("xtickmode", xtickmode); |
|
1376 m.assign ("ytickmode", ytickmode); |
|
1377 m.assign ("ztickmode", ztickmode); |
|
1378 m.assign ("xticklabel", xticklabel); |
|
1379 m.assign ("yticklabel", yticklabel); |
|
1380 m.assign ("zticklabel", zticklabel); |
|
1381 m.assign ("xticklabelmode", xticklabelmode); |
|
1382 m.assign ("yticklabelmode", yticklabelmode); |
|
1383 m.assign ("zticklabelmode", zticklabelmode); |
|
1384 m.assign ("xscale", xscale); |
|
1385 m.assign ("yscale", yscale); |
|
1386 m.assign ("zscale", zscale); |
|
1387 m.assign ("xdir", xdir); |
|
1388 m.assign ("ydir", ydir); |
|
1389 m.assign ("zdir", zdir); |
6809
|
1390 m.assign ("xaxislocation", xaxislocation); |
|
1391 m.assign ("yaxislocation", yaxislocation); |
6705
|
1392 m.assign ("view", view); |
6765
|
1393 m.assign ("visible", visible); |
6705
|
1394 m.assign ("nextplot", nextplot); |
|
1395 m.assign ("outerposition", outerposition); |
6432
|
1396 |
6705
|
1397 return m; |
|
1398 } |
6406
|
1399 |
6705
|
1400 octave_value |
|
1401 axes::axes_properties::get (const property_name& name) const |
|
1402 { |
|
1403 octave_value retval; |
6406
|
1404 |
6705
|
1405 if (name.compare ("type")) |
|
1406 retval = type; |
|
1407 else if (name.compare ("parent")) |
|
1408 retval = parent; |
|
1409 else if (name.compare ("children")) |
|
1410 retval = children; |
|
1411 else if (name.compare ("__modified__")) |
|
1412 retval = __modified__; |
|
1413 else if (name.compare ("position")) |
|
1414 retval = position; |
|
1415 else if (name.compare ("title")) |
6406
|
1416 { |
|
1417 if (xisnan (title)) |
|
1418 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1419 |
6705
|
1420 retval = title; |
|
1421 } |
|
1422 else if (name.compare ("box")) |
|
1423 retval = box; |
|
1424 else if (name.compare ("key")) |
|
1425 retval = key; |
|
1426 else if (name.compare ("keybox")) |
|
1427 retval = keybox; |
|
1428 else if (name.compare ("keypos")) |
|
1429 retval = keypos; |
|
1430 else if (name.compare ("dataaspectratio")) |
|
1431 retval = dataaspectratio; |
|
1432 else if (name.compare ("dataaspectratiomode")) |
|
1433 retval = dataaspectratiomode; |
|
1434 else if (name.compare ("xlim")) |
|
1435 retval = xlim; |
|
1436 else if (name.compare ("ylim")) |
|
1437 retval = ylim; |
|
1438 else if (name.compare ("zlim")) |
|
1439 retval = zlim; |
6807
|
1440 else if (name.compare ("clim")) |
|
1441 retval = clim; |
6705
|
1442 else if (name.compare ("xlimmode")) |
|
1443 retval = xlimmode; |
|
1444 else if (name.compare ("ylimmode")) |
|
1445 retval = ylimmode; |
|
1446 else if (name.compare ("zlimmode")) |
|
1447 retval = zlimmode; |
6807
|
1448 else if (name.compare ("climmode")) |
|
1449 retval = climmode; |
6705
|
1450 else if (name.compare ("xlabel")) |
|
1451 { |
6406
|
1452 if (xisnan (xlabel)) |
|
1453 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1454 |
6705
|
1455 retval = xlabel; |
|
1456 } |
|
1457 else if (name.compare ("ylabel")) |
|
1458 { |
6406
|
1459 if (xisnan (ylabel)) |
|
1460 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1461 |
6705
|
1462 retval = ylabel; |
|
1463 } |
|
1464 else if (name.compare ("zlabel")) |
|
1465 { |
6406
|
1466 if (xisnan (zlabel)) |
|
1467 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1468 |
6705
|
1469 retval = zlabel; |
6406
|
1470 } |
6705
|
1471 else if (name.compare ("xgrid")) |
|
1472 retval = xgrid; |
|
1473 else if (name.compare ("ygrid")) |
|
1474 retval = ygrid; |
|
1475 else if (name.compare ("zgrid")) |
|
1476 retval = zgrid; |
|
1477 else if (name.compare ("xminorgrid")) |
|
1478 retval = xminorgrid; |
|
1479 else if (name.compare ("yminorgrid")) |
|
1480 retval = yminorgrid; |
|
1481 else if (name.compare ("zminorgrid")) |
|
1482 retval = zminorgrid; |
|
1483 else if (name.compare ("xtick")) |
|
1484 retval = xtick; |
|
1485 else if (name.compare ("ytick")) |
|
1486 retval = ytick; |
|
1487 else if (name.compare ("ztick")) |
|
1488 retval = ztick; |
|
1489 else if (name.compare ("xtickmode")) |
|
1490 retval = xtickmode; |
|
1491 else if (name.compare ("ytickmode")) |
|
1492 retval = ytickmode; |
|
1493 else if (name.compare ("ztickmode")) |
|
1494 retval = ztickmode; |
|
1495 else if (name.compare ("xticklabel")) |
|
1496 retval = xticklabel; |
|
1497 else if (name.compare ("yticklabel")) |
|
1498 retval = yticklabel; |
|
1499 else if (name.compare ("zticklabel")) |
|
1500 retval = zticklabel; |
|
1501 else if (name.compare ("xticklabelmode")) |
|
1502 retval = xticklabelmode; |
|
1503 else if (name.compare ("yticklabelmode")) |
|
1504 retval = yticklabelmode; |
|
1505 else if (name.compare ("zticklabelmode")) |
|
1506 retval = zticklabelmode; |
|
1507 else if (name.compare ("xscale")) |
|
1508 retval = xscale; |
|
1509 else if (name.compare ("yscale")) |
|
1510 retval = yscale; |
|
1511 else if (name.compare ("zscale")) |
|
1512 retval = zscale; |
|
1513 else if (name.compare ("xdir")) |
|
1514 retval = xdir; |
|
1515 else if (name.compare ("ydir")) |
|
1516 retval = ydir; |
|
1517 else if (name.compare ("zdir")) |
|
1518 retval = zdir; |
6809
|
1519 else if (name.compare ("xaxislocation")) |
|
1520 retval = xaxislocation; |
|
1521 else if (name.compare ("yaxislocation")) |
|
1522 retval = yaxislocation; |
6705
|
1523 else if (name.compare ("view")) |
|
1524 retval = view; |
6765
|
1525 else if (name.compare ("visible")) |
|
1526 retval = visible; |
6705
|
1527 else if (name.compare ("nextplot")) |
|
1528 retval = nextplot; |
|
1529 else if (name.compare ("outerposition")) |
|
1530 retval = outerposition; |
|
1531 else |
|
1532 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1533 |
6705
|
1534 return retval; |
|
1535 } |
6406
|
1536 |
6705
|
1537 void |
|
1538 axes::axes_properties::remove_child (const graphics_handle& h) |
|
1539 { |
|
1540 if (! xisnan (title) && h == title) |
|
1541 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1542 else if (! xisnan (xlabel) && h == xlabel) |
|
1543 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1544 else if (! xisnan (ylabel) && h == ylabel) |
|
1545 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1546 else if (! xisnan (zlabel) && h == zlabel) |
|
1547 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1548 else |
|
1549 base_properties::remove_child (h); |
|
1550 } |
6406
|
1551 |
6705
|
1552 void |
|
1553 axes::axes_properties::delete_children (void) |
|
1554 { |
|
1555 base_properties::delete_children (); |
|
1556 |
|
1557 if (! xisnan (title)) |
|
1558 gh_manager::free (title); |
6406
|
1559 |
6705
|
1560 if (! xisnan (xlabel)) |
|
1561 gh_manager::free (xlabel); |
6406
|
1562 |
6705
|
1563 if (! xisnan (ylabel)) |
|
1564 gh_manager::free (ylabel); |
6406
|
1565 |
6705
|
1566 if (! xisnan (zlabel)) |
|
1567 gh_manager::free (zlabel); |
|
1568 } |
6406
|
1569 |
6836
|
1570 property_list::pval_map_type |
|
1571 axes::axes_properties::factory_defaults (void) |
6705
|
1572 { |
|
1573 property_list::pval_map_type m; |
6406
|
1574 |
6705
|
1575 m["position"] = Matrix (); |
|
1576 m["title"] = octave_NaN; |
|
1577 m["box"] = "on"; |
|
1578 m["key"] = "off"; |
|
1579 m["keybox"] = "off"; |
|
1580 m["keypos"] = 1; |
|
1581 m["dataaspectratio"] = Matrix (1, 3, 1.0); |
|
1582 m["dataaspectratiomode"] = "auto"; |
6406
|
1583 |
6705
|
1584 Matrix tlim (1, 2, 0.0); |
|
1585 tlim(1) = 1; |
6406
|
1586 |
6705
|
1587 m["xlim"] = tlim; |
|
1588 m["ylim"] = tlim; |
|
1589 m["zlim"] = tlim; |
6807
|
1590 |
|
1591 Matrix cl(1, 2, 0); |
|
1592 cl(1) = 1; |
|
1593 |
|
1594 m["clim"] = cl; |
6406
|
1595 |
6705
|
1596 m["xlimmode"] = "auto"; |
|
1597 m["ylimmode"] = "auto"; |
|
1598 m["zlimmode"] = "auto"; |
6807
|
1599 m["climmode"] = "auto"; |
6705
|
1600 m["xlabel"] = octave_NaN; |
|
1601 m["ylabel"] = octave_NaN; |
|
1602 m["zlabel"] = octave_NaN; |
|
1603 m["xgrid"] = "off"; |
|
1604 m["ygrid"] = "off"; |
|
1605 m["zgrid"] = "off"; |
|
1606 m["xminorgrid"] = "off"; |
|
1607 m["yminorgrid"] = "off"; |
|
1608 m["zminorgrid"] = "off"; |
|
1609 m["xtick"] = Matrix (); |
|
1610 m["ytick"] = Matrix (); |
|
1611 m["ztick"] = Matrix (); |
|
1612 m["xtickmode"] = "auto"; |
|
1613 m["ytickmode"] = "auto"; |
|
1614 m["ztickmode"] = "auto"; |
|
1615 m["xticklabel"] = ""; |
|
1616 m["yticklabel"] = ""; |
|
1617 m["zticklabel"] = ""; |
|
1618 m["xticklabelmode"] = "auto"; |
|
1619 m["yticklabelmode"] = "auto"; |
|
1620 m["zticklabelmode"] = "auto"; |
|
1621 m["xscale"] = "linear"; |
|
1622 m["yscale"] = "linear"; |
|
1623 m["zscale"] = "linear"; |
|
1624 m["xdir"] = "normal"; |
|
1625 m["ydir"] = "normal"; |
|
1626 m["zdir"] = "normal"; |
6809
|
1627 m["xaxislocation"] = "bottom"; |
|
1628 m["yaxislocation"] = "left"; |
6406
|
1629 |
6705
|
1630 Matrix tview (1, 2, 0.0); |
|
1631 tview(1) = 90; |
6406
|
1632 |
6705
|
1633 m["view"] = tview; |
6406
|
1634 |
6765
|
1635 m["visible"] = "on"; |
6705
|
1636 m["nextplot"] = "replace"; |
6406
|
1637 |
6705
|
1638 Matrix touterposition (1, 4, 0.0); |
|
1639 touterposition(2) = 1; |
|
1640 touterposition(3) = 1; |
6406
|
1641 |
6705
|
1642 m["outerposition"] = touterposition; |
6406
|
1643 |
6705
|
1644 return m; |
|
1645 } |
6406
|
1646 |
6836
|
1647 octave_value |
|
1648 axes::get_default (const property_name& name) const |
|
1649 { |
|
1650 octave_value retval = default_properties.lookup (name); |
|
1651 |
|
1652 if (retval.is_undefined ()) |
|
1653 { |
|
1654 graphics_handle parent = get_parent (); |
|
1655 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1656 |
|
1657 retval = parent_obj.get_default (name); |
|
1658 } |
|
1659 |
|
1660 return retval; |
|
1661 } |
|
1662 |
6406
|
1663 std::string axes::axes_properties::go_name ("axes"); |
|
1664 |
|
1665 // --------------------------------------------------------------------- |
|
1666 |
|
1667 static Matrix |
|
1668 default_data (void) |
|
1669 { |
|
1670 Matrix retval (1, 2); |
|
1671 |
|
1672 retval(0) = 0; |
|
1673 retval(1) = 1; |
|
1674 |
|
1675 return retval; |
|
1676 } |
|
1677 |
6705
|
1678 line::line_properties::line_properties (const graphics_handle& mh, |
|
1679 const graphics_handle& p) |
|
1680 : base_properties (go_name, mh, p), |
|
1681 xdata (default_data ()), |
|
1682 ydata (default_data ()), |
|
1683 zdata (Matrix ()), |
|
1684 ldata (Matrix ()), |
|
1685 udata (Matrix ()), |
|
1686 xldata (Matrix ()), |
|
1687 xudata (Matrix ()), |
|
1688 color (), |
|
1689 linestyle ("-"), |
|
1690 linewidth (0.5), |
|
1691 marker ("none"), |
|
1692 markeredgecolor ("auto"), |
|
1693 markerfacecolor ("none"), |
|
1694 markersize (1), |
|
1695 keylabel ("") |
|
1696 { } |
|
1697 |
|
1698 void |
|
1699 line::line_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 ("xdata")) |
|
1713 xdata = val; |
|
1714 else if (name.compare ("ydata")) |
|
1715 ydata = val; |
|
1716 else if (name.compare ("zdata")) |
|
1717 zdata = val; |
|
1718 else if (name.compare ("ldata")) |
|
1719 ldata = val; |
|
1720 else if (name.compare ("udata")) |
|
1721 udata = val; |
|
1722 else if (name.compare ("xldata")) |
|
1723 xldata = val; |
|
1724 else if (name.compare ("xudata")) |
|
1725 xudata = val; |
|
1726 else if (name.compare ("color")) |
6790
|
1727 color = val; |
6705
|
1728 else if (name.compare ("linestyle")) |
|
1729 linestyle = val; |
|
1730 else if (name.compare ("linewidth")) |
|
1731 linewidth = val; |
|
1732 else if (name.compare ("marker")) |
|
1733 marker = val; |
|
1734 else if (name.compare ("markeredgecolor")) |
|
1735 markeredgecolor = val; |
|
1736 else if (name.compare ("markerfacecolor")) |
|
1737 markerfacecolor = val; |
|
1738 else if (name.compare ("markersize")) |
|
1739 markersize = val; |
|
1740 else if (name.compare ("keylabel")) |
|
1741 keylabel = val; |
|
1742 else |
6406
|
1743 { |
6705
|
1744 modified = false; |
|
1745 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1746 } |
|
1747 |
6705
|
1748 if (modified) |
|
1749 mark_modified (); |
|
1750 } |
|
1751 |
|
1752 octave_value |
|
1753 line::line_properties::get (void) const |
|
1754 { |
|
1755 Octave_map m; |
6406
|
1756 |
6705
|
1757 m.assign ("type", type); |
|
1758 m.assign ("parent", parent); |
|
1759 m.assign ("children", children); |
|
1760 m.assign ("__modified__", __modified__); |
|
1761 m.assign ("xdata", xdata); |
|
1762 m.assign ("ydata", ydata); |
|
1763 m.assign ("zdata", zdata); |
|
1764 m.assign ("ldata", ldata); |
|
1765 m.assign ("udata", udata); |
|
1766 m.assign ("xldata", xldata); |
|
1767 m.assign ("xudata", xudata); |
|
1768 m.assign ("color", color); |
|
1769 m.assign ("linestyle", linestyle); |
|
1770 m.assign ("linewidth", linewidth); |
|
1771 m.assign ("marker", marker); |
|
1772 m.assign ("markeredgecolor", markeredgecolor); |
|
1773 m.assign ("markerface", markerfacecolor); |
|
1774 m.assign ("markersize", markersize); |
|
1775 m.assign ("keylabel", keylabel); |
6406
|
1776 |
6705
|
1777 return m; |
|
1778 } |
6406
|
1779 |
6705
|
1780 octave_value |
|
1781 line::line_properties::get (const property_name& name) const |
|
1782 { |
|
1783 octave_value retval; |
6406
|
1784 |
6705
|
1785 if (name.compare ("type")) |
|
1786 retval = type; |
|
1787 else if (name.compare ("parent")) |
|
1788 retval = parent; |
|
1789 else if (name.compare ("children")) |
|
1790 retval = children; |
|
1791 else if (name.compare ("__modified__")) |
|
1792 retval = __modified__; |
|
1793 else if (name.compare ("xdata")) |
|
1794 retval = xdata; |
|
1795 else if (name.compare ("ydata")) |
|
1796 retval = ydata; |
|
1797 else if (name.compare ("zdata")) |
|
1798 retval = zdata; |
|
1799 else if (name.compare ("ldata")) |
|
1800 retval = ldata; |
|
1801 else if (name.compare ("udata")) |
|
1802 retval = udata; |
|
1803 else if (name.compare ("xldata")) |
|
1804 retval = xldata; |
|
1805 else if (name.compare ("xudata")) |
|
1806 retval = xudata; |
|
1807 else if (name.compare ("color")) |
|
1808 retval = color; |
|
1809 else if (name.compare ("linestyle")) |
|
1810 retval = linestyle; |
|
1811 else if (name.compare ("linewidth")) |
|
1812 retval = linewidth; |
|
1813 else if (name.compare ("marker")) |
|
1814 retval = marker; |
|
1815 else if (name.compare ("markeredgecolor")) |
|
1816 retval = markeredgecolor; |
|
1817 else if (name.compare ("markerfacecolor")) |
|
1818 retval = markerfacecolor; |
|
1819 else if (name.compare ("markersize")) |
|
1820 retval = markersize; |
|
1821 else if (name.compare ("keylabel")) |
|
1822 retval = keylabel; |
|
1823 else |
|
1824 warning ("get: invalid property `%s'", name.c_str ()); |
6432
|
1825 |
6705
|
1826 return retval; |
|
1827 } |
6406
|
1828 |
6836
|
1829 property_list::pval_map_type |
|
1830 line::line_properties::factory_defaults (void) |
6705
|
1831 { |
|
1832 property_list::pval_map_type m; |
6406
|
1833 |
6705
|
1834 m["xdata"] = default_data (); |
|
1835 m["ydata"] = default_data (); |
|
1836 m["zdata"] = Matrix (); |
|
1837 m["ldata"] = Matrix (); |
|
1838 m["udata"] = Matrix (); |
|
1839 m["xldata"] = Matrix (); |
|
1840 m["xudata"] = Matrix (); |
|
1841 m["color"] = color_property (); |
|
1842 m["linestyle"] = "-"; |
|
1843 m["linewidth"] = 0.5; |
|
1844 m["marker"] = "none"; |
|
1845 m["markeredgecolor"] = "auto"; |
|
1846 m["markerfacecolor"] = "none"; |
|
1847 m["markersize"] = 1; |
|
1848 m["keylabel"] = ""; |
6406
|
1849 |
6705
|
1850 return m; |
|
1851 } |
6406
|
1852 |
|
1853 std::string line::line_properties::go_name ("line"); |
|
1854 |
|
1855 // --------------------------------------------------------------------- |
|
1856 |
6705
|
1857 text::text_properties::text_properties (const graphics_handle& mh, |
|
1858 const graphics_handle& p) |
|
1859 : base_properties (go_name, mh, p), |
|
1860 string (""), |
|
1861 units ("data"), |
|
1862 position (Matrix (1, 3, 0.0)), |
6724
|
1863 rotation (0), |
6829
|
1864 horizontalalignment ("left"), |
|
1865 color (Matrix (1, 3, 1.0)) |
6705
|
1866 { } |
|
1867 |
|
1868 void |
|
1869 text::text_properties::set (const property_name& name, const octave_value& val) |
6406
|
1870 { |
6705
|
1871 bool modified = true; |
6432
|
1872 |
6705
|
1873 if (name.compare ("parent")) |
|
1874 set_parent (val); |
|
1875 else if (name.compare ("children")) |
|
1876 children = maybe_set_children (children, val); |
|
1877 else if (name.compare ("__modified__")) |
|
1878 { |
|
1879 __modified__ = val.bool_value (); |
|
1880 modified = false; |
6406
|
1881 } |
6705
|
1882 else if (name.compare ("string")) |
|
1883 string = val; |
|
1884 else if (name.compare ("units")) |
|
1885 units = val; |
|
1886 else if (name.compare ("position")) |
|
1887 position = val; |
6724
|
1888 else if (name.compare ("rotation")) |
|
1889 rotation = val; |
6705
|
1890 else if (name.compare ("horizontalalignment")) |
|
1891 horizontalalignment = val; |
6829
|
1892 else if (name.compare ("color")) |
|
1893 color = val; |
6705
|
1894 else |
6406
|
1895 { |
6705
|
1896 modified = false; |
|
1897 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
1898 } |
|
1899 |
6705
|
1900 if (modified) |
|
1901 mark_modified (); |
|
1902 } |
6406
|
1903 |
6705
|
1904 octave_value |
|
1905 text::text_properties::get (void) const |
|
1906 { |
|
1907 Octave_map m; |
6406
|
1908 |
6705
|
1909 m.assign ("type", type); |
|
1910 m.assign ("parent", parent); |
|
1911 m.assign ("children", children); |
|
1912 m.assign ("__modified__", __modified__); |
|
1913 m.assign ("string", string); |
|
1914 m.assign ("units", units); |
|
1915 m.assign ("position", position); |
6724
|
1916 m.assign ("rotation", rotation); |
6705
|
1917 m.assign ("horizontalalignment", horizontalalignment); |
6829
|
1918 m.assign ("color", color); |
6406
|
1919 |
6705
|
1920 return m; |
|
1921 } |
6406
|
1922 |
6705
|
1923 octave_value |
|
1924 text::text_properties::get (const property_name& name) const |
|
1925 { |
|
1926 octave_value retval; |
6406
|
1927 |
6705
|
1928 if (name.compare ("type")) |
|
1929 retval = type; |
|
1930 else if (name.compare ("parent")) |
|
1931 retval = parent; |
|
1932 else if (name.compare ("children")) |
|
1933 retval = children; |
|
1934 else if (name.compare ("__modified__")) |
|
1935 retval = __modified__; |
|
1936 else if (name.compare ("string")) |
|
1937 retval = string; |
|
1938 else if (name.compare ("units")) |
|
1939 retval = units; |
|
1940 else if (name.compare ("position")) |
|
1941 retval = position; |
6724
|
1942 else if (name.compare ("rotation")) |
|
1943 retval = rotation; |
6705
|
1944 else if (name.compare ("horizontalalignment")) |
|
1945 retval = horizontalalignment; |
6829
|
1946 else if (name.compare ("color")) |
|
1947 retval = color; |
6705
|
1948 else |
|
1949 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
1950 |
6705
|
1951 return retval; |
|
1952 } |
6406
|
1953 |
6705
|
1954 property_list::pval_map_type |
|
1955 text::text_properties::factory_defaults (void) |
|
1956 { |
|
1957 property_list::pval_map_type m; |
6406
|
1958 |
6705
|
1959 m["string"] = ""; |
|
1960 m["units"] = "data"; |
|
1961 m["position"] = Matrix (1, 3, 0.0); |
6724
|
1962 m["rotation"] = 0; |
6705
|
1963 m["horizontalalignment"] = "left"; |
6829
|
1964 m["color"] = Matrix (1, 3, 1.0); |
6406
|
1965 |
6705
|
1966 return m; |
|
1967 } |
6406
|
1968 |
|
1969 std::string text::text_properties::go_name ("text"); |
|
1970 |
|
1971 // --------------------------------------------------------------------- |
|
1972 |
6705
|
1973 image::image_properties::image_properties (const graphics_handle& mh, |
|
1974 const graphics_handle& p) |
|
1975 : base_properties (go_name, mh, p), |
|
1976 cdata (Matrix ()), |
|
1977 xdata (Matrix ()), |
|
1978 ydata (Matrix ()) |
|
1979 { } |
|
1980 |
|
1981 void |
|
1982 image::image_properties::set (const property_name& name, |
|
1983 const octave_value& val) |
6406
|
1984 { |
6705
|
1985 bool modified = true; |
6432
|
1986 |
6705
|
1987 if (name.compare ("parent")) |
|
1988 set_parent (val); |
|
1989 else if (name.compare ("children")) |
|
1990 children = maybe_set_children (children, val); |
|
1991 else if (name.compare ("__modified__")) |
|
1992 { |
|
1993 __modified__ = val.bool_value (); |
|
1994 modified = false; |
6406
|
1995 } |
6705
|
1996 else if (name.compare ("cdata")) |
|
1997 cdata = val; |
|
1998 else if (name.compare ("xdata")) |
|
1999 xdata = val; |
|
2000 else if (name.compare ("ydata")) |
|
2001 ydata = val; |
|
2002 else |
6406
|
2003 { |
6705
|
2004 modified = false; |
|
2005 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
2006 } |
|
2007 |
6705
|
2008 if (modified) |
|
2009 mark_modified (); |
|
2010 } |
6406
|
2011 |
6705
|
2012 octave_value |
|
2013 image::image_properties::get (void) const |
|
2014 { |
|
2015 Octave_map m; |
6406
|
2016 |
6705
|
2017 m.assign ("type", type); |
|
2018 m.assign ("parent", parent); |
|
2019 m.assign ("children", children); |
|
2020 m.assign ("__modified__", __modified__); |
|
2021 m.assign ("cdata", cdata); |
|
2022 m.assign ("xdata", xdata); |
|
2023 m.assign ("ydata", ydata); |
6406
|
2024 |
6705
|
2025 return m; |
|
2026 } |
6406
|
2027 |
6705
|
2028 octave_value |
|
2029 image::image_properties::get (const property_name& name) const |
|
2030 { |
|
2031 octave_value retval; |
6406
|
2032 |
6705
|
2033 if (name.compare ("type")) |
|
2034 retval = type; |
|
2035 else if (name.compare ("parent")) |
|
2036 retval = parent; |
|
2037 else if (name.compare ("children")) |
|
2038 retval = children; |
|
2039 else if (name.compare ("__modified__")) |
|
2040 retval = __modified__; |
|
2041 else if (name.compare ("cdata")) |
|
2042 retval = cdata; |
|
2043 else if (name.compare ("xdata")) |
|
2044 retval = xdata; |
|
2045 else if (name.compare ("ydata")) |
|
2046 retval = ydata; |
|
2047 else |
|
2048 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
2049 |
6705
|
2050 return retval; |
|
2051 } |
6406
|
2052 |
6836
|
2053 property_list::pval_map_type |
|
2054 image::image_properties::factory_defaults (void) |
6705
|
2055 { |
|
2056 property_list::pval_map_type m; |
6406
|
2057 |
6705
|
2058 m["cdata"] = Matrix (); |
|
2059 m["xdata"] = Matrix (); |
|
2060 m["ydata"] = Matrix (); |
6406
|
2061 |
6705
|
2062 return m; |
|
2063 } |
6406
|
2064 |
|
2065 std::string image::image_properties::go_name ("image"); |
|
2066 |
|
2067 // --------------------------------------------------------------------- |
|
2068 |
6807
|
2069 patch::patch_properties::patch_properties (const graphics_handle& mh, |
|
2070 const graphics_handle& p) |
|
2071 : base_properties (go_name, mh, p), |
|
2072 cdata (Matrix ()), |
|
2073 xdata (Matrix ()), |
|
2074 ydata (Matrix ()), |
|
2075 zdata (Matrix ()), |
|
2076 facecolor (radio_values("{flat}|none|interp")), |
|
2077 facealpha (1.0), |
|
2078 edgecolor (color_values(0, 0, 0), radio_values("flat|none|interp")), |
|
2079 linestyle ("-"), |
|
2080 linewidth (0.5), |
|
2081 marker ("none"), |
|
2082 markeredgecolor ("auto"), |
|
2083 markerfacecolor ("none"), |
|
2084 markersize (1) |
|
2085 { } |
|
2086 |
|
2087 void |
|
2088 patch::patch_properties::set (const property_name& name, |
|
2089 const octave_value& val) |
|
2090 { |
|
2091 bool modified = true; |
|
2092 |
|
2093 if (name.compare ("parent")) |
|
2094 set_parent (val); |
|
2095 else if (name.compare ("children")) |
|
2096 children = maybe_set_children (children, val); |
|
2097 else if (name.compare ("__modified__")) |
|
2098 { |
|
2099 __modified__ = val.bool_value (); |
|
2100 modified = false; |
|
2101 } |
|
2102 else if (name.compare ("cdata")) |
|
2103 cdata = val; |
|
2104 else if (name.compare ("xdata")) |
|
2105 xdata = val; |
|
2106 else if (name.compare ("ydata")) |
|
2107 ydata = val; |
|
2108 else if (name.compare ("zdata")) |
|
2109 zdata = val; |
|
2110 else if (name.compare ("facecolor")) |
|
2111 facecolor = val; |
|
2112 else if (name.compare ("facealpha")) |
|
2113 facealpha = val; |
|
2114 else if (name.compare ("edgecolor")) |
|
2115 edgecolor = val; |
|
2116 else if (name.compare ("linestyle")) |
|
2117 linestyle = val; |
|
2118 else if (name.compare ("linewidth")) |
|
2119 linewidth = val; |
|
2120 else if (name.compare ("marker")) |
|
2121 marker = val; |
|
2122 else if (name.compare ("markeredgecolor")) |
|
2123 markeredgecolor = val; |
|
2124 else if (name.compare ("markerfacecolor")) |
|
2125 markerfacecolor = val; |
|
2126 else if (name.compare ("markersize")) |
|
2127 markersize = val; |
|
2128 |
|
2129 else |
|
2130 { |
|
2131 modified = false; |
|
2132 warning ("set: invalid property `%s'", name.c_str ()); |
|
2133 } |
|
2134 |
|
2135 if (modified) |
|
2136 mark_modified (); |
|
2137 } |
|
2138 |
|
2139 octave_value |
|
2140 patch::patch_properties::get (void) const |
|
2141 { |
|
2142 Octave_map m; |
|
2143 |
|
2144 m.assign ("type", type); |
|
2145 m.assign ("parent", parent); |
|
2146 m.assign ("children", children); |
|
2147 m.assign ("__modified__", __modified__); |
|
2148 m.assign ("cdata", cdata); |
|
2149 m.assign ("xdata", xdata); |
|
2150 m.assign ("ydata", ydata); |
|
2151 m.assign ("zdata", zdata); |
|
2152 m.assign ("facecolor", facecolor); |
|
2153 m.assign ("facealpha", facealpha); |
|
2154 m.assign ("edgecolor", edgecolor); |
|
2155 m.assign ("linestyle", linestyle); |
|
2156 m.assign ("linewidth", linewidth); |
|
2157 m.assign ("marker", marker); |
|
2158 m.assign ("markeredgecolor", markeredgecolor); |
|
2159 m.assign ("markerface", markerfacecolor); |
|
2160 m.assign ("markersize", markersize); |
|
2161 |
|
2162 return m; |
|
2163 } |
|
2164 |
|
2165 octave_value |
|
2166 patch::patch_properties::get (const property_name& name) const |
|
2167 { |
|
2168 octave_value retval; |
|
2169 |
|
2170 if (name.compare ("type")) |
|
2171 retval = type; |
|
2172 else if (name.compare ("parent")) |
|
2173 retval = parent; |
|
2174 else if (name.compare ("children")) |
|
2175 retval = children; |
|
2176 else if (name.compare ("__modified__")) |
|
2177 retval = __modified__; |
|
2178 else if (name.compare ("cdata")) |
|
2179 retval = cdata; |
|
2180 else if (name.compare ("xdata")) |
|
2181 retval = xdata; |
|
2182 else if (name.compare ("ydata")) |
|
2183 retval = ydata; |
|
2184 else if (name.compare ("zdata")) |
|
2185 retval = zdata; |
|
2186 else if (name.compare ("facecolor")) |
|
2187 retval = facecolor; |
|
2188 else if (name.compare ("facealpha")) |
|
2189 retval = facecolor; |
|
2190 else if (name.compare ("egdecolor")) |
|
2191 retval = edgecolor; |
|
2192 else if (name.compare ("linestyle")) |
|
2193 retval = linestyle; |
|
2194 else if (name.compare ("linewidth")) |
|
2195 retval = linewidth; |
|
2196 else if (name.compare ("marker")) |
|
2197 retval = marker; |
|
2198 else if (name.compare ("markeredgecolor")) |
|
2199 retval = markeredgecolor; |
|
2200 else if (name.compare ("markerfacecolor")) |
|
2201 retval = markerfacecolor; |
|
2202 else if (name.compare ("markersize")) |
|
2203 retval = markersize; |
|
2204 else |
|
2205 warning ("get: invalid property `%s'", name.c_str ()); |
|
2206 |
|
2207 return retval; |
|
2208 } |
|
2209 |
6836
|
2210 property_list::pval_map_type |
|
2211 patch::patch_properties::factory_defaults (void) |
6807
|
2212 { |
|
2213 property_list::pval_map_type m; |
|
2214 |
|
2215 m["cdata"] = Matrix (); |
|
2216 m["xdata"] = Matrix (); |
|
2217 m["ydata"] = Matrix (); |
|
2218 m["zdata"] = Matrix (); |
|
2219 m["facecolor"] = color_property(); |
|
2220 m["facealpha"] = 1.0; |
|
2221 m["edgecolor"] = color_property("black"); |
|
2222 m["linestyle"] = "-"; |
|
2223 m["linewidth"] = 0.5; |
|
2224 m["marker"] = "none"; |
|
2225 m["markeredgecolor"] = "auto"; |
|
2226 m["markerfacecolor"] = "none"; |
|
2227 m["markersize"] = 1; |
|
2228 |
|
2229 |
|
2230 return m; |
|
2231 } |
|
2232 |
|
2233 std::string patch::patch_properties::go_name ("patch"); |
|
2234 |
|
2235 // --------------------------------------------------------------------- |
|
2236 |
6705
|
2237 surface::surface_properties::surface_properties (const graphics_handle& mh, |
|
2238 const graphics_handle& p) |
|
2239 : base_properties (go_name, mh, p), |
|
2240 xdata (Matrix ()), |
|
2241 ydata (Matrix ()), |
|
2242 zdata (Matrix ()), |
|
2243 keylabel ("") |
|
2244 { } |
|
2245 |
|
2246 void |
|
2247 surface::surface_properties::set (const property_name& name, |
|
2248 const octave_value& val) |
6406
|
2249 { |
6705
|
2250 bool modified = true; |
6432
|
2251 |
6705
|
2252 if (name.compare ("parent")) |
|
2253 set_parent (val); |
|
2254 else if (name.compare ("children")) |
|
2255 children = maybe_set_children (children, val); |
|
2256 else if (name.compare ("__modified__")) |
|
2257 { |
|
2258 __modified__ = val.bool_value (); |
|
2259 modified = false; |
6406
|
2260 } |
6705
|
2261 else if (name.compare ("xdata")) |
|
2262 xdata = val; |
|
2263 else if (name.compare ("ydata")) |
|
2264 ydata = val; |
|
2265 else if (name.compare ("zdata")) |
|
2266 zdata = val; |
|
2267 else if (name.compare ("keylabel")) |
|
2268 keylabel = val; |
|
2269 else |
6406
|
2270 { |
6705
|
2271 modified = false; |
|
2272 warning ("set: invalid property `%s'", name.c_str ()); |
6406
|
2273 } |
|
2274 |
6705
|
2275 if (modified) |
|
2276 mark_modified (); |
|
2277 } |
6406
|
2278 |
6705
|
2279 octave_value |
|
2280 surface::surface_properties::get (void) const |
|
2281 { |
|
2282 Octave_map m; |
6406
|
2283 |
6705
|
2284 m.assign ("type", type); |
|
2285 m.assign ("parent", parent); |
|
2286 m.assign ("children", children); |
|
2287 m.assign ("__modified__", __modified__); |
|
2288 m.assign ("xdata", xdata); |
|
2289 m.assign ("ydata", ydata); |
|
2290 m.assign ("zdata", zdata); |
|
2291 m.assign ("keylabel", keylabel); |
6406
|
2292 |
6705
|
2293 return m; |
|
2294 } |
6406
|
2295 |
6705
|
2296 octave_value |
|
2297 surface::surface_properties::get (const property_name& name) const |
|
2298 { |
|
2299 octave_value retval; |
6406
|
2300 |
6705
|
2301 if (name.compare ("type")) |
|
2302 retval = type; |
|
2303 else if (name.compare ("parent")) |
|
2304 retval = parent; |
|
2305 else if (name.compare ("children")) |
|
2306 retval = children; |
|
2307 else if (name.compare ("__modified__")) |
|
2308 retval = __modified__; |
|
2309 else if (name.compare ("xdata")) |
|
2310 retval = xdata; |
|
2311 else if (name.compare ("ydata")) |
|
2312 retval = ydata; |
|
2313 else if (name.compare ("zdata")) |
|
2314 retval = zdata; |
|
2315 else if (name.compare ("keylabel")) |
|
2316 retval = keylabel; |
|
2317 else |
|
2318 warning ("get: invalid property `%s'", name.c_str ()); |
6406
|
2319 |
6705
|
2320 return retval; |
|
2321 } |
6406
|
2322 |
6705
|
2323 property_list::pval_map_type |
|
2324 surface::surface_properties::factory_defaults (void) |
|
2325 { |
|
2326 property_list::pval_map_type m; |
6406
|
2327 |
6705
|
2328 m["xdata"] = Matrix (); |
|
2329 m["ydata"] = Matrix (); |
|
2330 m["zdata"] = Matrix (); |
|
2331 m["keylabel"] = ""; |
6406
|
2332 |
6705
|
2333 return m; |
|
2334 } |
6406
|
2335 |
|
2336 std::string surface::surface_properties::go_name ("surface"); |
|
2337 |
|
2338 // --------------------------------------------------------------------- |
|
2339 |
|
2340 octave_value |
|
2341 base_graphics_object::get_default (const property_name& name) const |
|
2342 { |
|
2343 graphics_handle parent = get_parent (); |
|
2344 graphics_object parent_obj = gh_manager::get_object (parent); |
|
2345 |
|
2346 return parent_obj.get_default (type () + name); |
|
2347 } |
|
2348 |
|
2349 octave_value |
|
2350 base_graphics_object::get_factory_default (const property_name& name) const |
|
2351 { |
|
2352 graphics_object parent_obj = gh_manager::get_object (0); |
|
2353 |
|
2354 return parent_obj.get_factory_default (type () + name); |
|
2355 } |
|
2356 |
|
2357 gh_manager::gh_manager (void) |
|
2358 : handle_map (), handle_free_list (), next_handle (-1) |
|
2359 { |
|
2360 handle_map[0] = graphics_object (new root_figure ()); |
|
2361 } |
|
2362 |
|
2363 graphics_handle |
|
2364 gh_manager::do_make_graphics_handle (const std::string& go_name, |
|
2365 const graphics_handle& p) |
|
2366 { |
|
2367 graphics_handle h = get_handle (go_name); |
|
2368 |
|
2369 base_graphics_object *go = 0; |
|
2370 |
|
2371 if (go_name == "figure") |
|
2372 go = new figure (h, p); |
|
2373 else if (go_name == "axes") |
|
2374 go = new axes (h, p); |
|
2375 else if (go_name == "line") |
|
2376 go = new line (h, p); |
|
2377 else if (go_name == "text") |
|
2378 go = new text (h, p); |
|
2379 else if (go_name == "image") |
|
2380 go = new image (h, p); |
6807
|
2381 else if (go_name == "patch") |
|
2382 go = new patch (h, p); |
6406
|
2383 else if (go_name == "surface") |
|
2384 go = new surface (h, p); |
|
2385 if (go) |
|
2386 handle_map[h] = graphics_object (go); |
|
2387 else |
|
2388 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
|
2389 go_name.c_str ()); |
|
2390 |
|
2391 return h; |
|
2392 } |
|
2393 |
|
2394 graphics_handle |
|
2395 gh_manager::do_make_figure_handle (double val) |
|
2396 { |
|
2397 graphics_handle h = val; |
|
2398 |
|
2399 handle_map[h] = graphics_object (new figure (h, 0)); |
|
2400 |
|
2401 return h; |
|
2402 } |
|
2403 |
|
2404 void |
|
2405 gh_manager::do_push_figure (const graphics_handle& h) |
|
2406 { |
|
2407 do_pop_figure (h); |
|
2408 |
|
2409 figure_list.push_front (h); |
|
2410 } |
|
2411 |
|
2412 void |
|
2413 gh_manager::do_pop_figure (const graphics_handle& h) |
|
2414 { |
|
2415 for (figure_list_iterator p = figure_list.begin (); |
|
2416 p != figure_list.end (); |
|
2417 p++) |
|
2418 { |
|
2419 if (*p == h) |
|
2420 { |
|
2421 figure_list.erase (p); |
|
2422 break; |
|
2423 } |
|
2424 } |
|
2425 } |
|
2426 |
|
2427 property_list::plist_map_type |
|
2428 root_figure::init_factory_properties (void) |
|
2429 { |
|
2430 property_list::plist_map_type plist_map; |
|
2431 |
|
2432 plist_map["figure"] = figure::figure_properties::factory_defaults (); |
|
2433 plist_map["axes"] = axes::axes_properties::factory_defaults (); |
|
2434 plist_map["line"] = line::line_properties::factory_defaults (); |
|
2435 plist_map["text"] = text::text_properties::factory_defaults (); |
|
2436 plist_map["image"] = image::image_properties::factory_defaults (); |
6807
|
2437 plist_map["patch"] = patch::patch_properties::factory_defaults (); |
6406
|
2438 plist_map["surface"] = surface::surface_properties::factory_defaults (); |
|
2439 |
|
2440 return plist_map; |
|
2441 } |
|
2442 |
|
2443 // --------------------------------------------------------------------- |
|
2444 |
|
2445 DEFUN (ishandle, args, , |
|
2446 "-*- texinfo -*-\n\ |
6678
|
2447 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406
|
2448 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
|
2449 @end deftypefn") |
|
2450 { |
|
2451 octave_value retval; |
|
2452 |
|
2453 if (args.length () == 1) |
|
2454 retval = is_handle (args(0)); |
|
2455 else |
|
2456 print_usage (); |
|
2457 |
|
2458 return retval; |
|
2459 } |
|
2460 |
|
2461 DEFUN (set, args, , |
|
2462 "-*- texinfo -*-\n\ |
6678
|
2463 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6732
|
2464 Set the named property value or vector @var{p} to the value @var{v}\n\ |
|
2465 in the graphics handle @var{h}.\n\ |
6406
|
2466 @end deftypefn") |
|
2467 { |
|
2468 octave_value retval; |
|
2469 |
|
2470 int nargin = args.length (); |
|
2471 |
|
2472 if (nargin > 0) |
|
2473 { |
6732
|
2474 ColumnVector hcv (args(0).vector_value ()); |
6406
|
2475 |
|
2476 if (! error_state) |
6732
|
2477 { |
6733
|
2478 bool request_drawnow = false; |
|
2479 |
6732
|
2480 for (octave_idx_type n = 0; n < hcv.length (); n++) |
|
2481 { |
|
2482 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
2483 |
6732
|
2484 if (obj) |
|
2485 { |
|
2486 obj.set (args.splice (0, 1)); |
6406
|
2487 |
6733
|
2488 request_drawnow = true; |
6732
|
2489 } |
|
2490 else |
6733
|
2491 { |
|
2492 error ("set: invalid handle (= %g)", hcv(n)); |
|
2493 break; |
|
2494 } |
6732
|
2495 } |
6733
|
2496 |
|
2497 if (! error_state && request_drawnow) |
|
2498 feval ("__request_drawnow__"); |
6732
|
2499 } |
6406
|
2500 else |
6732
|
2501 error ("set: expecting graphics handle as first argument"); |
6406
|
2502 } |
|
2503 else |
|
2504 print_usage (); |
|
2505 |
|
2506 return retval; |
|
2507 } |
|
2508 |
|
2509 DEFUN (get, args, , |
|
2510 "-*- texinfo -*-\n\ |
6678
|
2511 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406
|
2512 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
|
2513 If @var{p} is omitted, return the complete property list for @var{h}.\n\ |
6732
|
2514 If @var{h} is a vector, return a cell array including the property\n\ |
|
2515 values or lists respectively.\n\ |
6406
|
2516 @end deftypefn") |
|
2517 { |
|
2518 octave_value retval; |
6732
|
2519 octave_value_list vlist; |
6406
|
2520 |
|
2521 int nargin = args.length (); |
|
2522 |
|
2523 if (nargin == 1 || nargin == 2) |
|
2524 { |
6732
|
2525 ColumnVector hcv (args(0).vector_value ()); |
6406
|
2526 |
|
2527 if (! error_state) |
6732
|
2528 { |
6733
|
2529 octave_idx_type len = hcv.length (); |
|
2530 |
|
2531 vlist.resize (len); |
|
2532 |
|
2533 for (octave_idx_type n = 0; n < len; n++) |
6732
|
2534 { |
|
2535 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
2536 |
6732
|
2537 if (obj) |
|
2538 { |
|
2539 if (nargin == 1) |
|
2540 vlist(n) = obj.get (); |
|
2541 else |
|
2542 { |
|
2543 property_name property = args(1).string_value (); |
6406
|
2544 |
6732
|
2545 if (! error_state) |
|
2546 vlist(n) = obj.get (property); |
|
2547 else |
6733
|
2548 { |
|
2549 error ("get: expecting property name as second argument"); |
|
2550 break; |
|
2551 } |
6732
|
2552 } |
|
2553 } |
|
2554 else |
6733
|
2555 { |
|
2556 error ("get: invalid handle (= %g)", hcv(n)); |
|
2557 break; |
|
2558 } |
6732
|
2559 } |
|
2560 } |
6406
|
2561 else |
6732
|
2562 error ("get: expecting graphics handle as first argument"); |
6406
|
2563 } |
|
2564 else |
|
2565 print_usage (); |
|
2566 |
6733
|
2567 if (! error_state) |
6732
|
2568 { |
6733
|
2569 octave_idx_type len = vlist.length (); |
|
2570 |
|
2571 if (len > 1) |
|
2572 retval = Cell (vlist); |
|
2573 else if (len == 1) |
|
2574 retval = vlist(0); |
6732
|
2575 } |
|
2576 |
6406
|
2577 return retval; |
|
2578 } |
|
2579 |
|
2580 static octave_value |
|
2581 make_graphics_object (const std::string& go_name, |
6732
|
2582 const octave_value_list& args) |
6406
|
2583 { |
|
2584 octave_value retval; |
|
2585 |
|
2586 double val = args(0).double_value (); |
|
2587 |
|
2588 if (! error_state) |
|
2589 { |
|
2590 graphics_handle parent = gh_manager::lookup (val); |
|
2591 |
|
2592 if (! xisnan (parent)) |
|
2593 { |
|
2594 graphics_handle h |
|
2595 = gh_manager::make_graphics_handle (go_name, parent); |
|
2596 |
|
2597 if (! error_state) |
|
2598 { |
|
2599 adopt (parent, h); |
|
2600 |
|
2601 xset (h, args.splice (0, 1)); |
|
2602 |
|
2603 retval = h; |
|
2604 } |
|
2605 else |
|
2606 error ("__go%s__: unable to create graphics handle", |
|
2607 go_name.c_str ()); |
|
2608 } |
|
2609 else |
|
2610 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2611 } |
|
2612 else |
|
2613 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2614 |
|
2615 return retval; |
|
2616 } |
|
2617 |
|
2618 DEFUN (__go_figure__, args, , |
|
2619 "-*- texinfo -*-\n\ |
|
2620 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ |
|
2621 Create a figure graphics object.\n\ |
|
2622 @end deftypefn") |
|
2623 { |
|
2624 octave_value retval; |
|
2625 |
|
2626 if (args.length () > 0) |
|
2627 { |
|
2628 double val = args(0).double_value (); |
|
2629 |
|
2630 if (! error_state) |
|
2631 { |
|
2632 if (is_figure (val)) |
|
2633 { |
|
2634 graphics_handle h = gh_manager::lookup (val); |
|
2635 |
|
2636 xset (h, args.splice (0, 1)); |
|
2637 |
|
2638 retval = h; |
|
2639 } |
|
2640 else |
|
2641 { |
|
2642 graphics_handle h = octave_NaN; |
|
2643 |
|
2644 if (xisnan (val)) |
|
2645 h = gh_manager::make_graphics_handle ("figure", 0); |
|
2646 else if (val > 0 && D_NINT (val) == val) |
|
2647 h = gh_manager::make_figure_handle (val); |
|
2648 else |
|
2649 error ("__go_figure__: invalid figure number"); |
|
2650 |
|
2651 if (! (error_state || xisnan (h))) |
|
2652 { |
|
2653 adopt (0, h); |
|
2654 |
|
2655 xset (h, args.splice (0, 1)); |
|
2656 |
|
2657 retval = h; |
|
2658 } |
|
2659 else |
|
2660 error ("__go_figure__: failed to create figure handle"); |
|
2661 } |
|
2662 } |
|
2663 else |
|
2664 error ("__go_figure__: expecting figure number to be double value"); |
|
2665 } |
|
2666 else |
|
2667 print_usage (); |
|
2668 |
|
2669 return retval; |
|
2670 } |
|
2671 |
|
2672 #define GO_BODY(TYPE) \ |
|
2673 octave_value retval; \ |
|
2674 \ |
|
2675 if (args.length () > 0) \ |
|
2676 retval = make_graphics_object (#TYPE, args); \ |
|
2677 else \ |
|
2678 print_usage (); \ |
|
2679 \ |
|
2680 return retval |
|
2681 |
|
2682 DEFUN (__go_axes__, args, , |
|
2683 "-*- texinfo -*-\n\ |
|
2684 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ |
|
2685 Create an axes graphics object.\n\ |
|
2686 @end deftypefn") |
|
2687 { |
|
2688 GO_BODY (axes); |
|
2689 } |
|
2690 |
|
2691 DEFUN (__go_line__, args, , |
|
2692 "-*- texinfo -*-\n\ |
|
2693 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ |
|
2694 Create a line graphics object.\n\ |
|
2695 @end deftypefn") |
|
2696 { |
|
2697 GO_BODY (line); |
|
2698 } |
|
2699 |
|
2700 DEFUN (__go_text__, args, , |
|
2701 "-*- texinfo -*-\n\ |
|
2702 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ |
|
2703 Create a text graphics object.\n\ |
|
2704 @end deftypefn") |
|
2705 { |
|
2706 GO_BODY (text); |
|
2707 } |
|
2708 |
|
2709 DEFUN (__go_image__, args, , |
|
2710 "-*- texinfo -*-\n\ |
|
2711 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ |
|
2712 Create an image graphics object.\n\ |
|
2713 @end deftypefn") |
|
2714 { |
|
2715 GO_BODY (image); |
|
2716 } |
|
2717 |
|
2718 DEFUN (__go_surface__, args, , |
|
2719 "-*- texinfo -*-\n\ |
|
2720 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ |
|
2721 Create a surface graphics object.\n\ |
|
2722 @end deftypefn") |
|
2723 { |
|
2724 GO_BODY (surface); |
|
2725 } |
|
2726 |
6807
|
2727 DEFUN (__go_patch__, args, , |
|
2728 "-*- texinfo -*-\n\ |
|
2729 @deftypefn {Built-in Function} {} __go_patch__ (@var{parent})\n\ |
|
2730 Create a patch graphics object.\n\ |
|
2731 @end deftypefn") |
|
2732 { |
|
2733 GO_BODY (patch); |
|
2734 } |
|
2735 |
6406
|
2736 DEFUN (__go_delete__, args, , |
|
2737 "-*- texinfo -*-\n\ |
|
2738 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ |
|
2739 @end deftypefn") |
|
2740 { |
|
2741 octave_value_list retval; |
|
2742 |
|
2743 if (args.length () == 1) |
|
2744 { |
|
2745 graphics_handle h = octave_NaN; |
|
2746 |
|
2747 double val = args(0).double_value (); |
|
2748 |
|
2749 if (! error_state) |
|
2750 { |
|
2751 h = gh_manager::lookup (val); |
|
2752 |
|
2753 if (! xisnan (h)) |
|
2754 { |
|
2755 graphics_object obj = gh_manager::get_object (h); |
|
2756 |
|
2757 graphics_handle parent_h = obj.get_parent (); |
|
2758 |
|
2759 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
2760 |
|
2761 parent_obj.remove_child (h); |
|
2762 |
|
2763 gh_manager::free (h); |
|
2764 } |
|
2765 else |
|
2766 error ("delete: invalid graphics object (= %g)", val); |
|
2767 } |
|
2768 else |
|
2769 error ("delete: invalid graphics object"); |
|
2770 } |
|
2771 else |
|
2772 print_usage (); |
|
2773 |
|
2774 return retval; |
|
2775 } |
|
2776 |
|
2777 DEFUN (__go_axes_init__, args, , |
|
2778 "-*- texinfo -*-\n\ |
|
2779 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ |
|
2780 Initialize axes object.\n\ |
|
2781 @end deftypefn") |
|
2782 { |
|
2783 octave_value retval; |
|
2784 |
|
2785 int nargin = args.length (); |
|
2786 |
|
2787 std::string mode = ""; |
|
2788 |
|
2789 if (nargin == 2) |
|
2790 { |
|
2791 mode = args(1).string_value (); |
|
2792 |
|
2793 if (error_state) |
|
2794 return retval; |
|
2795 } |
|
2796 |
|
2797 if (nargin == 1 || nargin == 2) |
|
2798 { |
|
2799 graphics_handle h = octave_NaN; |
|
2800 |
|
2801 double val = args(0).double_value (); |
|
2802 |
|
2803 if (! error_state) |
|
2804 { |
|
2805 h = gh_manager::lookup (val); |
|
2806 |
|
2807 if (! xisnan (h)) |
|
2808 { |
|
2809 graphics_object obj = gh_manager::get_object (h); |
|
2810 |
|
2811 obj.set_defaults (mode); |
|
2812 } |
|
2813 else |
|
2814 error ("__go_axes_init__: invalid graphics object (= %g)", val); |
|
2815 } |
|
2816 else |
|
2817 error ("__go_axes_init__: invalid graphics object"); |
|
2818 } |
|
2819 else |
|
2820 print_usage (); |
|
2821 |
|
2822 return retval; |
|
2823 } |
|
2824 |
|
2825 DEFUN (__go_handles__, , , |
|
2826 "-*- texinfo -*-\n\ |
|
2827 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ |
|
2828 Return current list of function handles.\n\ |
|
2829 @end deftypefn") |
|
2830 { |
6425
|
2831 return octave_value (gh_manager::handle_list ()); |
|
2832 } |
|
2833 |
|
2834 DEFUN (__go_figure_handles__, , , |
|
2835 "-*- texinfo -*-\n\ |
|
2836 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ |
|
2837 Return current list of function handles.\n\ |
|
2838 @end deftypefn") |
|
2839 { |
|
2840 return octave_value (gh_manager::figure_handle_list ()); |
6406
|
2841 } |
|
2842 |
6595
|
2843 octave_value |
|
2844 get_property_from_handle (double handle, const std::string &property, |
|
2845 const std::string &func) |
|
2846 { |
|
2847 graphics_object obj = gh_manager::get_object (handle); |
|
2848 octave_value retval; |
|
2849 |
|
2850 if (obj) |
|
2851 { |
|
2852 property_name p = std::string (property); |
|
2853 retval = obj.get (p); |
|
2854 } |
|
2855 else |
|
2856 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2857 |
|
2858 return retval; |
|
2859 } |
|
2860 |
|
2861 bool |
|
2862 set_property_in_handle (double handle, const std::string &property, |
|
2863 const octave_value &arg, const std::string &func) |
|
2864 { |
|
2865 graphics_object obj = gh_manager::get_object (handle); |
|
2866 int ret = false; |
|
2867 |
|
2868 if (obj) |
|
2869 { |
|
2870 property_name p = std::string (property); |
|
2871 obj.set (p, arg); |
|
2872 if (!error_state) |
|
2873 ret = true; |
|
2874 } |
|
2875 else |
|
2876 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2877 |
|
2878 return ret; |
|
2879 } |
|
2880 |
6841
|
2881 DEFUN (doit, args, , "") |
|
2882 { |
|
2883 octave_value retval; |
|
2884 |
|
2885 if (args.length () == 1) |
|
2886 { |
|
2887 graphics_handle h = octave_NaN; |
|
2888 |
|
2889 double val = args(0).double_value (); |
|
2890 |
|
2891 if (! error_state) |
|
2892 { |
|
2893 h = gh_manager::lookup (val); |
|
2894 |
|
2895 if (! xisnan (h)) |
|
2896 { |
|
2897 graphics_object obj = gh_manager::get_object (h); |
|
2898 |
|
2899 if (obj.isa ("line")) |
|
2900 { |
|
2901 line::line_properties& lp |
|
2902 = dynamic_cast<line::line_properties&> (obj.get_properties ()); |
|
2903 retval = lp.get_xdata (); |
|
2904 Matrix m (1, 5); |
|
2905 m(0) = 0; |
|
2906 m(1) = 1; |
|
2907 m(2) = 2; |
|
2908 m(3) = 3; |
|
2909 m(4) = 4; |
|
2910 lp.set_xdata (m); |
|
2911 m(0) = 0; |
|
2912 m(1) = 1; |
|
2913 m(2) = 0.2; |
|
2914 m(3) = 0.8; |
|
2915 m(4) = 0.4; |
|
2916 lp.set_ydata (m); |
|
2917 |
|
2918 feval ("__request_drawnow__"); |
|
2919 } |
|
2920 else |
|
2921 error ("doit: looking for line"); |
|
2922 } |
|
2923 else |
|
2924 error ("doit: invalid graphics object (= %g)", val); |
|
2925 } |
|
2926 else |
|
2927 error ("doit: invalid graphics object"); |
|
2928 } |
|
2929 else |
|
2930 print_usage (); |
|
2931 |
|
2932 return retval; |
|
2933 } |
|
2934 |
6406
|
2935 /* |
|
2936 ;;; Local Variables: *** |
|
2937 ;;; mode: C++ *** |
|
2938 ;;; End: *** |
|
2939 */ |