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