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