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