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> |
7286
|
29 #include <cstdlib> |
6406
|
30 |
|
31 #include <algorithm> |
|
32 #include <list> |
|
33 #include <map> |
|
34 #include <set> |
|
35 #include <string> |
|
36 |
6705
|
37 #include "defun.h" |
|
38 #include "error.h" |
6595
|
39 #include "graphics.h" |
6705
|
40 #include "ov.h" |
|
41 #include "oct-obj.h" |
|
42 #include "oct-map.h" |
|
43 #include "ov-fcn-handle.h" |
|
44 #include "parse.h" |
7222
|
45 #include "unwind-prot.h" |
6595
|
46 |
6406
|
47 static void |
|
48 gripe_set_invalid (const std::string& pname) |
|
49 { |
|
50 error ("set: invalid value for %s property", pname.c_str ()); |
|
51 } |
|
52 |
7363
|
53 static Matrix |
|
54 jet_colormap (void) |
|
55 { |
|
56 Matrix cmap (64, 3, 0.0); |
|
57 |
|
58 for (octave_idx_type i = 0; i < 64; i++) |
|
59 { |
|
60 // This is the jet colormap. It would be nice to be able |
|
61 // to feval the jet function but since there is a static |
|
62 // property object that includes a colormap_property |
|
63 // object, we need to initialize this before main is even |
|
64 // called, so calling an interpreted function is not |
|
65 // possible. |
|
66 |
|
67 double x = i / 63.0; |
|
68 |
|
69 if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
70 cmap(i,0) = 4.0 * x - 3.0/2.0; |
|
71 else if (x >= 5.0/8.0 && x < 7.0/8.0) |
|
72 cmap(i,0) = 1.0; |
|
73 else if (x >= 7.0/8.0) |
|
74 cmap(i,0) = -4.0 * x + 9.0/2.0; |
|
75 |
|
76 if (x >= 1.0/8.0 && x < 3.0/8.0) |
|
77 cmap(i,1) = 4.0 * x - 1.0/2.0; |
|
78 else if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
79 cmap(i,1) = 1.0; |
|
80 else if (x >= 5.0/8.0 && x < 7.0/8.0) |
|
81 cmap(i,1) = -4.0 * x + 7.0/2.0; |
|
82 |
|
83 if (x < 1.0/8.0) |
|
84 cmap(i,2) = 4.0 * x + 1.0/2.0; |
|
85 else if (x >= 1.0/8.0 && x < 3.0/8.0) |
|
86 cmap(i,2) = 1.0; |
|
87 else if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
88 cmap(i,2) = -4.0 * x + 5.0/2.0; |
|
89 } |
|
90 |
|
91 return cmap; |
|
92 } |
|
93 |
|
94 static Matrix |
|
95 default_colororder (void) |
|
96 { |
|
97 Matrix retval (7, 3, 0.0); |
|
98 |
|
99 retval(0,2) = 1.0; |
|
100 |
|
101 retval(1,1) = 0.5; |
|
102 |
|
103 retval(2,0) = 1.0; |
|
104 |
|
105 retval(3,1) = 0.75; |
|
106 retval(3,2) = 0.75; |
|
107 |
|
108 retval(4,0) = 0.75; |
|
109 retval(4,2) = 0.75; |
|
110 |
|
111 retval(5,0) = 0.75; |
|
112 retval(5,1) = 0.75; |
|
113 |
|
114 retval(6,0) = 0.25; |
|
115 retval(6,1) = 0.25; |
|
116 retval(6,2) = 0.25; |
|
117 |
|
118 return retval; |
|
119 } |
|
120 |
|
121 static Matrix |
|
122 default_lim (void) |
|
123 { |
|
124 Matrix m (1, 2, 0); |
|
125 m(1) = 1; |
|
126 return m; |
|
127 } |
|
128 |
|
129 static Matrix |
|
130 default_data (void) |
|
131 { |
|
132 Matrix retval (1, 2); |
|
133 |
|
134 retval(0) = 0; |
|
135 retval(1) = 1; |
|
136 |
|
137 return retval; |
|
138 } |
|
139 |
6406
|
140 // --------------------------------------------------------------------- |
|
141 |
6705
|
142 radio_values::radio_values (const std::string& opt_string) |
6406
|
143 { |
6705
|
144 size_t beg = 0; |
|
145 size_t len = opt_string.length (); |
|
146 bool done = len == 0; |
6681
|
147 |
6705
|
148 while (! done) |
|
149 { |
|
150 size_t end = opt_string.find ('|', beg); |
6681
|
151 |
6705
|
152 if (end == std::string::npos) |
|
153 { |
|
154 end = len; |
|
155 done = true; |
|
156 } |
6681
|
157 |
6705
|
158 std::string t = opt_string.substr (beg, end-beg); |
6681
|
159 |
6705
|
160 // Might want more error checking here... |
|
161 if (t[0] == '{') |
|
162 { |
|
163 t = t.substr (1, t.length () - 2); |
|
164 default_val = t; |
|
165 } |
|
166 else if (beg == 0) // ensure default value |
|
167 default_val = t; |
6681
|
168 |
6705
|
169 possible_vals.insert (t); |
6681
|
170 |
6705
|
171 beg = end + 1; |
|
172 } |
|
173 } |
6681
|
174 |
6705
|
175 bool |
6761
|
176 color_values::str2rgb (std::string str) |
6681
|
177 { |
6705
|
178 double tmp_rgb[3] = {0, 0, 0}; |
|
179 bool retval = true; |
6761
|
180 unsigned int len = str.length(); |
6681
|
181 |
6925
|
182 std::transform (str.begin (), str.end (), str.begin (), tolower); |
|
183 |
6761
|
184 if (str.compare(0, len, "blue", 0, len) == 0) |
|
185 tmp_rgb[2] = 1; |
6925
|
186 else if (str.compare(0, len, "black", 0, len) == 0 || |
|
187 str.compare(0, len, "k", 0, len) == 0) |
6761
|
188 tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 0; |
|
189 else if (str.compare(0, len, "red", 0, len) == 0) |
|
190 tmp_rgb[0] = 1; |
|
191 else if (str.compare(0, len, "green", 0, len) == 0) |
|
192 tmp_rgb[1] = 1; |
|
193 else if (str.compare(0, len, "yellow", 0, len) == 0) |
|
194 tmp_rgb[0] = tmp_rgb[1] = 1; |
|
195 else if (str.compare(0, len, "magenta", 0, len) == 0) |
|
196 tmp_rgb[0] = tmp_rgb[2] = 1; |
|
197 else if (str.compare(0, len, "cyan", 0, len) == 0) |
|
198 tmp_rgb[1] = tmp_rgb[2] = 1; |
6925
|
199 else if (str.compare(0, len, "white", 0, len) == 0 || |
|
200 str.compare(0, len, "w", 0, len) == 0) |
6761
|
201 tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 1; |
|
202 else |
|
203 retval = false; |
6406
|
204 |
6705
|
205 if (retval) |
|
206 { |
|
207 for (int i = 0; i < 3; i++) |
7363
|
208 xrgb(i) = tmp_rgb[i]; |
6705
|
209 } |
6563
|
210 |
6705
|
211 return retval; |
|
212 } |
6681
|
213 |
7363
|
214 void |
|
215 color_property::set (const octave_value& val) |
6790
|
216 { |
|
217 if (val.is_string ()) |
|
218 { |
|
219 std::string s = val.string_value (); |
|
220 |
|
221 if (! s.empty ()) |
|
222 { |
6898
|
223 if (radio_val.contains (s)) |
6790
|
224 { |
|
225 current_val = s; |
|
226 current_type = radio_t; |
|
227 } |
|
228 else |
|
229 { |
|
230 color_values col (s); |
|
231 if (! error_state) |
|
232 { |
|
233 color_val = col; |
|
234 current_type = color_t; |
|
235 } |
|
236 else |
7363
|
237 error ("invalid value for color property \"%s\" (value = %s)", |
|
238 get_name ().c_str (), s.c_str ()); |
6790
|
239 } |
|
240 } |
|
241 else |
7363
|
242 error ("invalid value for color property \"%s\"", |
|
243 get_name ().c_str ()); |
6790
|
244 } |
|
245 else if (val.is_real_matrix ()) |
|
246 { |
|
247 Matrix m = val.matrix_value (); |
|
248 |
|
249 if (m.numel () == 3) |
|
250 { |
|
251 color_values col (m (0), m (1), m(2)); |
|
252 if (! error_state) |
|
253 { |
|
254 color_val = col; |
|
255 current_type = color_t; |
|
256 } |
|
257 } |
|
258 else |
7363
|
259 error ("invalid value for color property \"%s\"", |
|
260 get_name ().c_str ()); |
6790
|
261 } |
|
262 else |
7363
|
263 error ("invalid value for color property \"%s\"", |
|
264 get_name ().c_str ()); |
6790
|
265 } |
|
266 |
7363
|
267 bool |
|
268 array_property::validate (const octave_value& v) |
|
269 { |
7364
|
270 bool xok = false; |
7363
|
271 |
|
272 // FIXME: should we always support []? |
|
273 if (v.is_empty () && v.is_double_type ()) |
|
274 return true; |
|
275 |
|
276 // check value type |
|
277 if (type_constraints.size () > 0) |
|
278 { |
|
279 for (std::list<std::string>::const_iterator it = type_constraints.begin (); |
7364
|
280 ! xok && it != type_constraints.end (); ++it) |
7363
|
281 if ((*it) == v.type_name ()) |
7364
|
282 xok = true; |
7363
|
283 } |
|
284 else |
7364
|
285 xok = v.is_double_type (); |
7363
|
286 |
7364
|
287 if (xok) |
7363
|
288 { |
|
289 dim_vector vdims = v.dims (); |
|
290 int vlen = vdims.length (); |
|
291 |
7364
|
292 xok = false; |
7363
|
293 |
|
294 // check value size |
|
295 if (size_constraints.size () > 0) |
|
296 for (std::list<dim_vector>::const_iterator it = size_constraints.begin (); |
7364
|
297 ! xok && it != size_constraints.end (); ++it) |
7363
|
298 { |
|
299 dim_vector itdims = (*it); |
|
300 |
|
301 if (itdims.length () == vlen) |
|
302 { |
7364
|
303 xok = true; |
7363
|
304 |
7364
|
305 for (int i = 0; xok && i < vlen; i++) |
7363
|
306 if (itdims(i) >= 0 && itdims(i) != vdims(i)) |
7364
|
307 xok = false; |
7363
|
308 } |
|
309 } |
|
310 else |
|
311 return true; |
|
312 } |
|
313 |
7364
|
314 return xok; |
7363
|
315 } |
|
316 |
|
317 void |
|
318 handle_property::set (const octave_value& v) |
|
319 { |
|
320 double dv = v.double_value (); |
|
321 |
|
322 if (! error_state) |
|
323 { |
|
324 graphics_handle gh = gh_manager::lookup (dv); |
|
325 |
|
326 if (xisnan (gh.value ()) || gh.ok ()) |
|
327 current_val = gh; |
|
328 else |
|
329 error ("set: invalid graphics handle (= %g) for property \"%s\"", |
|
330 dv, get_name ().c_str ()); |
|
331 } |
|
332 else |
|
333 error ("set: invalid graphics handle for property \"%s\"", |
|
334 get_name ().c_str ()); |
|
335 } |
|
336 |
|
337 bool |
7364
|
338 callback_property::validate (const octave_value&) const |
7363
|
339 { |
|
340 // FIXME: implement this |
|
341 return true; |
|
342 } |
|
343 |
|
344 void |
|
345 callback_property::execute (void) |
|
346 { |
|
347 // FIXME: define correct signature and implement this |
|
348 } |
|
349 |
|
350 // --------------------------------------------------------------------- |
6681
|
351 |
6705
|
352 void |
7189
|
353 property_list::set (const caseless_str& name, const octave_value& val) |
6681
|
354 { |
6705
|
355 size_t offset = 0; |
6681
|
356 |
6705
|
357 size_t len = name.length (); |
6681
|
358 |
6705
|
359 if (len > 4) |
|
360 { |
7189
|
361 caseless_str pfx = name.substr (0, 4); |
6681
|
362 |
6705
|
363 if (pfx.compare ("axes") || pfx.compare ("line") |
|
364 || pfx.compare ("text")) |
|
365 offset = 4; |
|
366 else if (len > 5) |
|
367 { |
|
368 pfx = name.substr (0, 5); |
6681
|
369 |
6807
|
370 if (pfx.compare ("image") || pfx.compare ("patch")) |
6705
|
371 offset = 5; |
|
372 else if (len > 6) |
|
373 { |
|
374 pfx = name.substr (0, 6); |
6681
|
375 |
6705
|
376 if (pfx.compare ("figure")) |
|
377 offset = 6; |
|
378 else if (len > 7) |
|
379 { |
|
380 pfx = name.substr (0, 7); |
6681
|
381 |
6705
|
382 if (pfx.compare ("surface")) |
|
383 offset = 7; |
|
384 } |
|
385 } |
|
386 } |
6681
|
387 |
6705
|
388 if (offset > 0) |
|
389 { |
|
390 // FIXME -- should we validate property names and values here? |
6406
|
391 |
6705
|
392 std::string pname = name.substr (offset); |
6406
|
393 |
6705
|
394 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
|
395 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); |
6406
|
396 |
6705
|
397 bool remove = false; |
|
398 if (val.is_string ()) |
|
399 { |
7189
|
400 caseless_str tval = val.string_value (); |
6406
|
401 |
6705
|
402 remove = tval.compare ("remove"); |
|
403 } |
6406
|
404 |
6705
|
405 pval_map_type& pval_map = plist_map[pfx]; |
6406
|
406 |
6705
|
407 if (remove) |
|
408 { |
|
409 pval_map_iterator p = pval_map.find (pname); |
6406
|
410 |
6705
|
411 if (p != pval_map.end ()) |
|
412 pval_map.erase (p); |
|
413 } |
|
414 else |
|
415 pval_map[pname] = val; |
|
416 } |
|
417 } |
6406
|
418 |
6705
|
419 if (offset == 0) |
|
420 error ("invalid default property specification"); |
|
421 } |
6406
|
422 |
6705
|
423 octave_value |
7189
|
424 property_list::lookup (const caseless_str& name) const |
6705
|
425 { |
|
426 octave_value retval; |
6406
|
427 |
6705
|
428 size_t offset = 0; |
6406
|
429 |
6705
|
430 size_t len = name.length (); |
6406
|
431 |
6705
|
432 if (len > 4) |
|
433 { |
7189
|
434 caseless_str pfx = name.substr (0, 4); |
6406
|
435 |
6705
|
436 if (pfx.compare ("axes") || pfx.compare ("line") |
|
437 || pfx.compare ("text")) |
|
438 offset = 4; |
|
439 else if (len > 5) |
|
440 { |
|
441 pfx = name.substr (0, 5); |
6406
|
442 |
6807
|
443 if (pfx.compare ("image") || pfx.compare ("patch")) |
6705
|
444 offset = 5; |
|
445 else if (len > 6) |
|
446 { |
|
447 pfx = name.substr (0, 6); |
6406
|
448 |
6705
|
449 if (pfx.compare ("figure")) |
|
450 offset = 6; |
|
451 else if (len > 7) |
|
452 { |
|
453 pfx = name.substr (0, 7); |
6406
|
454 |
6705
|
455 if (pfx.compare ("surface")) |
|
456 offset = 7; |
|
457 } |
|
458 } |
|
459 } |
6406
|
460 |
6705
|
461 if (offset > 0) |
|
462 { |
|
463 std::string pname = name.substr (offset); |
6406
|
464 |
6705
|
465 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
|
466 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); |
6406
|
467 |
6705
|
468 plist_map_const_iterator p = find (pfx); |
6432
|
469 |
6705
|
470 if (p != end ()) |
|
471 { |
|
472 const pval_map_type& pval_map = p->second; |
6406
|
473 |
6705
|
474 pval_map_const_iterator q = pval_map.find (pname); |
6406
|
475 |
6705
|
476 if (q != pval_map.end ()) |
|
477 retval = q->second; |
|
478 } |
|
479 } |
|
480 } |
6406
|
481 |
6705
|
482 return retval; |
|
483 } |
6406
|
484 |
6705
|
485 Octave_map |
|
486 property_list::as_struct (const std::string& prefix_arg) const |
|
487 { |
|
488 Octave_map m; |
6406
|
489 |
6705
|
490 for (plist_map_const_iterator p = begin (); p != end (); p++) |
|
491 { |
|
492 std::string prefix = prefix_arg + p->first; |
6406
|
493 |
6705
|
494 const pval_map_type pval_map = p->second; |
6406
|
495 |
6705
|
496 for (pval_map_const_iterator q = pval_map.begin (); |
|
497 q != pval_map.end (); |
|
498 q++) |
|
499 m.assign (prefix + q->first, q->second); |
|
500 } |
6406
|
501 |
6705
|
502 return m; |
|
503 } |
6432
|
504 |
6874
|
505 graphics_handle::graphics_handle (const octave_value& a) |
|
506 : val (octave_NaN) |
|
507 { |
|
508 if (a.is_empty ()) |
|
509 /* do nothing */; |
|
510 else |
|
511 { |
|
512 double tval = a.double_value (); |
|
513 |
|
514 if (! error_state) |
|
515 val = tval; |
|
516 else |
|
517 error ("invalid graphics handle"); |
|
518 } |
|
519 } |
|
520 |
6705
|
521 void |
|
522 graphics_object::set (const octave_value_list& args) |
|
523 { |
|
524 int nargin = args.length (); |
6406
|
525 |
6705
|
526 if (nargin == 0) |
|
527 rep->defaults (); |
|
528 else if (nargin % 2 == 0) |
|
529 { |
|
530 for (int i = 0; i < nargin; i += 2) |
|
531 { |
7189
|
532 caseless_str name = args(i).string_value (); |
6406
|
533 |
6705
|
534 if (! error_state) |
|
535 { |
|
536 octave_value val = args(i+1); |
6406
|
537 |
6705
|
538 if (val.is_string ()) |
|
539 { |
7189
|
540 caseless_str tval = val.string_value (); |
6406
|
541 |
6705
|
542 if (tval.compare ("default")) |
|
543 val = get_default (name); |
|
544 else if (tval.compare ("factory")) |
|
545 val = get_factory_default (name); |
|
546 } |
6406
|
547 |
6705
|
548 if (error_state) |
|
549 break; |
6406
|
550 |
6705
|
551 rep->set (name, val); |
|
552 } |
|
553 else |
|
554 error ("set: expecting argument %d to be a property name", i); |
|
555 } |
|
556 } |
|
557 else |
|
558 error ("set: invalid number of arguments"); |
|
559 } |
6406
|
560 |
|
561 |
6705
|
562 graphics_handle |
|
563 gh_manager::get_handle (const std::string& go_name) |
|
564 { |
|
565 graphics_handle retval; |
6406
|
566 |
6705
|
567 if (go_name == "figure") |
|
568 { |
|
569 // We always want the lowest unused figure number. |
6406
|
570 |
6705
|
571 retval = 1; |
6425
|
572 |
6705
|
573 while (handle_map.find (retval) != handle_map.end ()) |
|
574 retval++; |
|
575 } |
|
576 else |
|
577 { |
|
578 free_list_iterator p = handle_free_list.begin (); |
6406
|
579 |
6705
|
580 if (p != handle_free_list.end ()) |
|
581 { |
|
582 retval = *p; |
|
583 handle_free_list.erase (p); |
|
584 } |
|
585 else |
7286
|
586 { |
|
587 static double maxrand = RAND_MAX + 2.0; |
|
588 |
|
589 retval = graphics_handle (next_handle); |
|
590 |
7304
|
591 next_handle = ceil (next_handle) - 1.0 - (rand () + 1.0) / maxrand; |
7286
|
592 } |
6705
|
593 } |
6406
|
594 |
6705
|
595 return retval; |
|
596 } |
6406
|
597 |
6705
|
598 void |
|
599 gh_manager::do_free (const graphics_handle& h) |
|
600 { |
7056
|
601 if (h.ok ()) |
6705
|
602 { |
6874
|
603 if (h.value () != 0) |
6705
|
604 { |
6874
|
605 iterator p = handle_map.find (h); |
|
606 |
|
607 if (p != handle_map.end ()) |
|
608 { |
|
609 handle_map.erase (p); |
|
610 |
|
611 if (h.value () < 0) |
|
612 handle_free_list.insert (h); |
|
613 } |
|
614 else |
|
615 error ("graphics_handle::free: invalid object %g", h.value ()); |
6705
|
616 } |
|
617 else |
6874
|
618 error ("graphics_handle::free: can't delete root figure"); |
6705
|
619 } |
|
620 } |
6406
|
621 |
|
622 gh_manager *gh_manager::instance = 0; |
|
623 |
|
624 static void |
7189
|
625 xset (const graphics_handle& h, const caseless_str& name, |
6406
|
626 const octave_value& val) |
|
627 { |
|
628 graphics_object obj = gh_manager::get_object (h); |
|
629 obj.set (name, val); |
|
630 } |
|
631 |
|
632 static void |
|
633 xset (const graphics_handle& h, const octave_value_list& args) |
|
634 { |
|
635 if (args.length () > 0) |
|
636 { |
|
637 graphics_object obj = gh_manager::get_object (h); |
|
638 obj.set (args); |
|
639 } |
|
640 } |
|
641 |
|
642 |
|
643 static octave_value |
7189
|
644 xget (const graphics_handle& h, const caseless_str& name) |
6406
|
645 { |
|
646 graphics_object obj = gh_manager::get_object (h); |
|
647 return obj.get (name); |
|
648 } |
|
649 |
|
650 static graphics_handle |
|
651 reparent (const octave_value& ov, const std::string& who, |
|
652 const std::string& property, const graphics_handle& new_parent, |
|
653 bool adopt = true) |
|
654 { |
|
655 graphics_handle h = octave_NaN; |
|
656 |
|
657 double val = ov.double_value (); |
|
658 |
|
659 if (! error_state) |
|
660 { |
|
661 h = gh_manager::lookup (val); |
|
662 |
7056
|
663 if (h.ok ()) |
6406
|
664 { |
|
665 graphics_object obj = gh_manager::get_object (h); |
|
666 |
|
667 graphics_handle parent_h = obj.get_parent (); |
|
668 |
|
669 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
670 |
|
671 parent_obj.remove_child (h); |
|
672 |
|
673 if (adopt) |
6874
|
674 obj.set ("parent", new_parent.value ()); |
6406
|
675 else |
|
676 obj.reparent (new_parent); |
|
677 } |
|
678 else |
|
679 error ("%s: invalid graphics handle (= %g) for %s", |
|
680 who.c_str (), val, property.c_str ()); |
|
681 } |
|
682 else |
|
683 error ("%s: expecting %s to be a graphics handle", |
|
684 who.c_str (), property.c_str ()); |
|
685 |
|
686 return h; |
|
687 } |
|
688 |
|
689 // This function is NOT equivalent to the scripting language function gcf. |
|
690 graphics_handle |
|
691 gcf (void) |
|
692 { |
|
693 octave_value val = xget (0, "currentfigure"); |
|
694 |
|
695 return val.is_empty () ? octave_NaN : val.double_value (); |
|
696 } |
|
697 |
|
698 // This function is NOT equivalent to the scripting language function gca. |
|
699 graphics_handle |
|
700 gca (void) |
|
701 { |
|
702 octave_value val = xget (gcf (), "currentaxes"); |
|
703 |
|
704 return val.is_empty () ? octave_NaN : val.double_value (); |
|
705 } |
|
706 |
|
707 static void |
|
708 adopt (const graphics_handle& p, const graphics_handle& h) |
|
709 { |
|
710 graphics_object parent_obj = gh_manager::get_object (p); |
|
711 |
|
712 parent_obj.adopt (h); |
|
713 } |
|
714 |
|
715 static bool |
7056
|
716 is_handle (const graphics_handle& h) |
|
717 { |
|
718 return h.ok (); |
|
719 } |
|
720 |
|
721 static bool |
6406
|
722 is_handle (double val) |
|
723 { |
6874
|
724 graphics_handle h = gh_manager::lookup (val); |
|
725 |
|
726 return h.ok (); |
6406
|
727 } |
|
728 |
|
729 static bool |
|
730 is_handle (const octave_value& val) |
|
731 { |
7142
|
732 return val.is_real_scalar () && is_handle (val.double_value ()); |
6406
|
733 } |
|
734 |
|
735 static bool |
|
736 is_figure (double val) |
|
737 { |
|
738 graphics_object obj = gh_manager::get_object (val); |
|
739 |
|
740 return obj && obj.isa ("figure"); |
|
741 } |
|
742 |
|
743 // --------------------------------------------------------------------- |
|
744 |
|
745 static int |
|
746 compare (const void *a_arg, const void *b_arg) |
|
747 { |
|
748 double a = *(static_cast<const double *> (a_arg)); |
|
749 double b = *(static_cast<const double *> (b_arg)); |
|
750 |
|
751 return a > b ? 1 : (a < b) ? -1 : 0; |
|
752 } |
|
753 |
|
754 static Matrix |
|
755 maybe_set_children (const Matrix& kids, const octave_value& val) |
|
756 { |
|
757 const Matrix new_kids = val.matrix_value (); |
|
758 |
|
759 bool ok = true; |
|
760 |
|
761 if (! error_state) |
|
762 { |
|
763 if (kids.numel () == new_kids.numel ()) |
|
764 { |
|
765 Matrix t1 = kids; |
|
766 Matrix t2 = new_kids; |
|
767 |
|
768 t1.qsort (compare); |
|
769 t2.qsort (compare); |
|
770 |
|
771 if (t1 != t2) |
|
772 ok = false; |
|
773 } else |
|
774 ok = false; |
|
775 |
|
776 if (! ok) |
|
777 error ("set: new children must be a permutation of existing children"); |
|
778 } |
|
779 else |
|
780 { |
|
781 ok = false; |
|
782 error ("set: expecting children to be array of graphics handles"); |
|
783 } |
|
784 |
|
785 return ok ? new_kids : kids; |
|
786 } |
|
787 |
6705
|
788 void |
|
789 base_properties::set_from_list (base_graphics_object& obj, |
|
790 property_list& defaults) |
6406
|
791 { |
6705
|
792 std::string go_name = graphics_object_name (); |
6406
|
793 |
6705
|
794 property_list::plist_map_const_iterator p = defaults.find (go_name); |
6406
|
795 |
6705
|
796 if (p != defaults.end ()) |
|
797 { |
|
798 const property_list::pval_map_type pval_map = p->second; |
6406
|
799 |
6705
|
800 for (property_list::pval_map_const_iterator q = pval_map.begin (); |
|
801 q != pval_map.end (); |
|
802 q++) |
|
803 { |
|
804 std::string pname = q->first; |
6406
|
805 |
6705
|
806 obj.set (pname, q->second); |
6406
|
807 |
6705
|
808 if (error_state) |
|
809 { |
|
810 error ("error setting default property %s", pname.c_str ()); |
|
811 break; |
|
812 } |
|
813 } |
|
814 } |
|
815 } |
6406
|
816 |
7363
|
817 octave_value |
|
818 base_properties::get (const caseless_str& name) const |
|
819 { |
|
820 octave_value retval; |
|
821 |
|
822 if (name.compare ("tag")) |
|
823 retval = get_tag (); |
|
824 else if (name.compare ("type")) |
|
825 retval = get_type (); |
|
826 else if (name.compare ("__modified__")) |
|
827 retval = is_modified (); |
|
828 else if (name.compare ("parent")) |
|
829 retval = get_parent ().as_octave_value (); |
|
830 else if (name.compare ("children")) |
|
831 retval = children; |
|
832 else |
|
833 { |
|
834 std::map<caseless_str, property>::const_iterator it = all_props.find (name); |
|
835 |
|
836 if (it != all_props.end ()) |
|
837 retval = it->second.get (); |
|
838 else |
|
839 error ("get: unknown property \"%s\"", name.c_str ()); |
|
840 } |
|
841 |
|
842 return retval; |
|
843 } |
|
844 |
|
845 octave_value |
|
846 base_properties::get (void) const |
|
847 { |
|
848 Octave_map m; |
|
849 |
|
850 for (std::map<caseless_str, property>::const_iterator it = all_props.begin (); |
|
851 it != all_props.end (); ++it) |
|
852 m.assign (it->second.get_name (), it->second.get ()); |
|
853 |
|
854 m.assign ("tag", get_tag ()); |
|
855 m.assign ("type", get_type ()); |
|
856 m.assign ("__modified__", is_modified ()); |
|
857 m.assign ("parent", get_parent ().as_octave_value ()); |
|
858 m.assign ("children", children); |
|
859 |
|
860 return m; |
|
861 } |
|
862 |
|
863 void |
|
864 base_properties::set (const caseless_str& name, const octave_value& val) |
|
865 { |
|
866 if (name.compare ("tag")) |
|
867 set_tag (val); |
|
868 else if (name.compare ("__modified__")) |
|
869 __modified__ = val; |
|
870 else if (name.compare ("parent")) |
|
871 set_parent (val); |
|
872 else if (name.compare ("children")) |
|
873 maybe_set_children (children, val); |
|
874 else |
|
875 { |
|
876 std::map<caseless_str, property>::iterator it = all_props.find (name); |
|
877 |
|
878 if (it != all_props.end ()) |
|
879 it->second.set (val); |
|
880 else |
|
881 error ("set: unknown property \"%s\"", name.c_str ()); |
|
882 } |
|
883 |
|
884 if (! error_state && ! name.compare ("__modified__")) |
|
885 mark_modified (); |
|
886 } |
|
887 |
|
888 property |
|
889 base_properties::get_property (const caseless_str& name) const |
|
890 { |
|
891 std::map<caseless_str, property>::const_iterator it = all_props.find (name); |
|
892 |
|
893 if (it == all_props.end ()) |
|
894 return property (); |
|
895 else |
|
896 return it->second; |
|
897 } |
|
898 |
6705
|
899 void |
|
900 base_properties::remove_child (const graphics_handle& h) |
6406
|
901 { |
6705
|
902 octave_idx_type k = -1; |
|
903 octave_idx_type n = children.numel (); |
|
904 for (octave_idx_type i = 0; i < n; i++) |
6406
|
905 { |
6874
|
906 if (h.value () == children(i)) |
6406
|
907 { |
6705
|
908 k = i; |
|
909 break; |
6406
|
910 } |
|
911 } |
|
912 |
6705
|
913 if (k >= 0) |
6406
|
914 { |
6705
|
915 Matrix new_kids (1, n-1); |
|
916 octave_idx_type j = 0; |
|
917 for (octave_idx_type i = 0; i < n; i++) |
|
918 { |
|
919 if (i != k) |
|
920 new_kids(j++) = children(i); |
|
921 } |
|
922 children = new_kids; |
6406
|
923 } |
6705
|
924 } |
6406
|
925 |
6836
|
926 void |
|
927 base_properties::set_parent (const octave_value& val) |
6705
|
928 { |
|
929 double tmp = val.double_value (); |
6406
|
930 |
6705
|
931 graphics_handle new_parent = octave_NaN; |
6406
|
932 |
6705
|
933 if (! error_state) |
|
934 { |
|
935 new_parent = gh_manager::lookup (tmp); |
6406
|
936 |
7056
|
937 if (new_parent.ok ()) |
6705
|
938 { |
7363
|
939 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
6406
|
940 |
6705
|
941 parent_obj.remove_child (__myhandle__); |
6406
|
942 |
7363
|
943 parent = new_parent.as_octave_value (); |
6406
|
944 |
7363
|
945 ::adopt (parent.handle_value (), __myhandle__); |
6705
|
946 } |
|
947 else |
|
948 error ("set: invalid graphics handle (= %g) for parent", tmp); |
|
949 } |
|
950 else |
|
951 error ("set: expecting parent to be a graphics handle"); |
|
952 } |
6432
|
953 |
6705
|
954 void |
6836
|
955 base_properties::mark_modified (void) |
|
956 { |
7363
|
957 __modified__ = "on"; |
|
958 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
6836
|
959 parent_obj.mark_modified (); |
|
960 } |
|
961 |
|
962 void |
|
963 base_properties::override_defaults (base_graphics_object& obj) |
|
964 { |
7363
|
965 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
6836
|
966 parent_obj.override_defaults (obj); |
|
967 } |
|
968 |
|
969 void |
7214
|
970 base_properties::update_axis_limits (const std::string& axis_type) const |
|
971 { |
7363
|
972 graphics_handle h = (get_type () == "axes") ? __myhandle__ : get_parent (); |
7214
|
973 |
|
974 graphics_object obj = gh_manager::get_object (h); |
|
975 |
|
976 if (obj.isa ("axes")) |
|
977 obj.update_axis_limits (axis_type); |
|
978 } |
|
979 |
|
980 void |
6836
|
981 base_properties::delete_children (void) |
|
982 { |
|
983 octave_idx_type n = children.numel (); |
|
984 |
|
985 for (octave_idx_type i = 0; i < n; i++) |
|
986 gh_manager::free (children(i)); |
|
987 } |
|
988 |
7363
|
989 // --------------------------------------------------------------------- |
|
990 |
|
991 #include "graphics-props.cc" |
|
992 |
|
993 // --------------------------------------------------------------------- |
|
994 |
6836
|
995 void |
7363
|
996 root_figure::properties::set_currentfigure (const octave_value& v) |
6874
|
997 { |
7363
|
998 graphics_handle val (v.double_value ()); |
|
999 |
6874
|
1000 if (error_state) |
|
1001 return; |
|
1002 |
7059
|
1003 if (xisnan (val.value ()) || is_handle (val)) |
6874
|
1004 { |
|
1005 currentfigure = val; |
|
1006 |
7363
|
1007 gh_manager::push_figure (val); |
6874
|
1008 } |
|
1009 else |
|
1010 gripe_set_invalid ("currentfigure"); |
|
1011 } |
|
1012 |
6406
|
1013 property_list |
|
1014 root_figure::factory_properties = root_figure::init_factory_properties (); |
|
1015 |
|
1016 // --------------------------------------------------------------------- |
|
1017 |
7363
|
1018 void |
|
1019 figure::properties::set_currentaxes (const octave_value& v) |
|
1020 { |
|
1021 graphics_handle val (v.double_value ()); |
6705
|
1022 |
6874
|
1023 if (error_state) |
|
1024 return; |
|
1025 |
7070
|
1026 if (xisnan (val.value ()) || is_handle (val)) |
6874
|
1027 currentaxes = val; |
|
1028 else |
|
1029 gripe_set_invalid ("currentaxes"); |
|
1030 } |
|
1031 |
|
1032 void |
|
1033 figure::properties::set_visible (const octave_value& val) |
|
1034 { |
|
1035 std::string s = val.string_value (); |
|
1036 |
|
1037 if (! error_state) |
|
1038 { |
|
1039 if (s == "on") |
|
1040 xset (0, "currentfigure", __myhandle__.value ()); |
|
1041 |
|
1042 visible = val; |
|
1043 } |
|
1044 } |
|
1045 |
|
1046 void |
6844
|
1047 figure::properties::close (void) |
6705
|
1048 { |
7363
|
1049 if (! get___plot_stream__ ().is_empty ()) |
6406
|
1050 { |
6705
|
1051 octave_value_list args; |
|
1052 args(1) = "\nquit;\n"; |
7363
|
1053 args(0) = get___plot_stream__ (); |
6705
|
1054 feval ("fputs", args); |
|
1055 args.resize (1); |
|
1056 feval ("fflush", args); |
|
1057 feval ("pclose", args); |
6406
|
1058 } |
|
1059 |
6705
|
1060 gh_manager::pop_figure (__myhandle__); |
6406
|
1061 |
6874
|
1062 graphics_handle cf = gh_manager::current_figure (); |
|
1063 |
|
1064 xset (0, "currentfigure", cf.value ()); |
6705
|
1065 } |
6432
|
1066 |
6836
|
1067 octave_value |
7189
|
1068 figure::get_default (const caseless_str& name) const |
6836
|
1069 { |
|
1070 octave_value retval = default_properties.lookup (name); |
|
1071 |
|
1072 if (retval.is_undefined ()) |
|
1073 { |
|
1074 graphics_handle parent = get_parent (); |
|
1075 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1076 |
|
1077 retval = parent_obj.get_default (name); |
|
1078 } |
|
1079 |
|
1080 return retval; |
|
1081 } |
|
1082 |
6406
|
1083 // --------------------------------------------------------------------- |
|
1084 |
7363
|
1085 void |
|
1086 axes::properties::set_title (const octave_value& v) |
6962
|
1087 { |
7363
|
1088 graphics_handle val = ::reparent (v, "set", "title", __myhandle__, false); |
6962
|
1089 |
6874
|
1090 if (! error_state) |
|
1091 { |
7363
|
1092 gh_manager::free (title.handle_value ()); |
6874
|
1093 title = val; |
|
1094 } |
|
1095 } |
|
1096 |
|
1097 void |
7363
|
1098 axes::properties::set_xlabel (const octave_value& v) |
6874
|
1099 { |
7363
|
1100 graphics_handle val = ::reparent (v, "set", "xlabel", __myhandle__, false); |
6874
|
1101 |
|
1102 if (! error_state) |
|
1103 { |
7363
|
1104 gh_manager::free (xlabel.handle_value ()); |
6874
|
1105 xlabel = val; |
|
1106 } |
|
1107 } |
|
1108 |
|
1109 void |
7363
|
1110 axes::properties::set_ylabel (const octave_value& v) |
6874
|
1111 { |
7363
|
1112 graphics_handle val = ::reparent (v, "set", "ylabel", __myhandle__, false); |
6874
|
1113 |
|
1114 if (! error_state) |
|
1115 { |
7363
|
1116 gh_manager::free (ylabel.handle_value ()); |
6874
|
1117 ylabel = val; |
|
1118 } |
|
1119 } |
|
1120 |
|
1121 void |
7363
|
1122 axes::properties::set_zlabel (const octave_value& v) |
6874
|
1123 { |
7363
|
1124 graphics_handle val = ::reparent (v, "set", "zlabel", __myhandle__, false); |
6874
|
1125 |
|
1126 if (! error_state) |
|
1127 { |
7363
|
1128 gh_manager::free (zlabel.handle_value ()); |
6874
|
1129 zlabel = val; |
|
1130 } |
|
1131 } |
|
1132 |
|
1133 void |
6844
|
1134 axes::properties::set_defaults (base_graphics_object& obj, |
6890
|
1135 const std::string& mode) |
6705
|
1136 { |
|
1137 position = Matrix (); |
7363
|
1138 title = graphics_handle (); |
6705
|
1139 box = "on"; |
|
1140 key = "off"; |
|
1141 keybox = "off"; |
7363
|
1142 keypos = 1.0; |
6962
|
1143 colororder = default_colororder (); |
6705
|
1144 dataaspectratio = Matrix (1, 3, 1.0); |
|
1145 dataaspectratiomode = "auto"; |
7363
|
1146 layer = "bottom"; |
6705
|
1147 |
|
1148 Matrix tlim (1, 2, 0.0); |
|
1149 tlim(1) = 1; |
|
1150 xlim = tlim; |
|
1151 ylim = tlim; |
|
1152 zlim = tlim; |
6807
|
1153 |
|
1154 Matrix cl (1, 2, 0); |
|
1155 cl(1) = 1; |
|
1156 clim = cl; |
|
1157 |
7363
|
1158 xlimmode = "auto"; |
|
1159 ylimmode = "auto"; |
|
1160 zlimmode = "auto"; |
|
1161 climmode = "auto"; |
|
1162 xlabel = graphics_handle (); |
|
1163 ylabel = graphics_handle (); |
|
1164 zlabel = graphics_handle (); |
6705
|
1165 xgrid = "off"; |
|
1166 ygrid = "off"; |
|
1167 zgrid = "off"; |
|
1168 xminorgrid = "off"; |
|
1169 yminorgrid = "off"; |
|
1170 zminorgrid = "off"; |
|
1171 xtick = Matrix (); |
|
1172 ytick = Matrix (); |
|
1173 ztick = Matrix (); |
|
1174 xtickmode = "auto"; |
|
1175 ytickmode = "auto"; |
|
1176 ztickmode = "auto"; |
|
1177 xticklabel = ""; |
|
1178 yticklabel = ""; |
|
1179 zticklabel = ""; |
|
1180 xticklabelmode = "auto"; |
|
1181 yticklabelmode = "auto"; |
|
1182 zticklabelmode = "auto"; |
7364
|
1183 color = color_values (0, 0, 0); |
|
1184 xcolor = color_values ("black"); |
|
1185 ycolor = color_values ("black"); |
|
1186 zcolor = color_values ("black"); |
7363
|
1187 xscale = "linear"; |
|
1188 yscale = "linear"; |
|
1189 zscale = "linear"; |
6705
|
1190 xdir = "normal"; |
|
1191 ydir = "normal"; |
|
1192 zdir = "normal"; |
7363
|
1193 yaxislocation = "left"; |
|
1194 xaxislocation = "bottom"; |
6705
|
1195 |
|
1196 Matrix tview (1, 2, 0.0); |
|
1197 tview(1) = 90; |
|
1198 view = tview; |
|
1199 |
6765
|
1200 visible = "on"; |
6705
|
1201 nextplot = "replace"; |
|
1202 |
|
1203 // FIXME -- this is not quite right; we should preserve |
|
1204 // "position" and "units". |
|
1205 |
|
1206 if (mode != "replace") |
|
1207 { |
6406
|
1208 Matrix touterposition (1, 4, 0.0); |
|
1209 touterposition(2) = 1; |
|
1210 touterposition(3) = 1; |
|
1211 outerposition = touterposition; |
|
1212 } |
|
1213 |
7363
|
1214 activepositionproperty = "outerposition"; |
|
1215 __colorbar__ = "none"; |
7189
|
1216 |
6705
|
1217 delete_children (); |
6406
|
1218 |
6705
|
1219 children = Matrix (); |
6432
|
1220 |
6705
|
1221 override_defaults (obj); |
|
1222 } |
|
1223 |
6874
|
1224 graphics_handle |
|
1225 axes::properties::get_title (void) const |
|
1226 { |
7363
|
1227 if (! title.handle_value ().ok ()) |
6874
|
1228 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1229 |
7363
|
1230 return title.handle_value (); |
6874
|
1231 } |
|
1232 |
|
1233 graphics_handle |
|
1234 axes::properties::get_xlabel (void) const |
|
1235 { |
7363
|
1236 if (! xlabel.handle_value ().ok ()) |
6874
|
1237 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1238 |
7363
|
1239 return xlabel.handle_value (); |
6874
|
1240 } |
|
1241 |
|
1242 graphics_handle |
|
1243 axes::properties::get_ylabel (void) const |
|
1244 { |
7363
|
1245 if (! ylabel.handle_value ().ok ()) |
6874
|
1246 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1247 |
7363
|
1248 return ylabel.handle_value (); |
6874
|
1249 } |
|
1250 |
|
1251 graphics_handle |
|
1252 axes::properties::get_zlabel (void) const |
|
1253 { |
7363
|
1254 if (! zlabel.handle_value ().ok ()) |
6874
|
1255 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1256 |
7363
|
1257 return zlabel.handle_value (); |
6705
|
1258 } |
6406
|
1259 |
6705
|
1260 void |
6844
|
1261 axes::properties::remove_child (const graphics_handle& h) |
6705
|
1262 { |
7363
|
1263 if (title.handle_value ().ok () && h == title.handle_value ()) |
6705
|
1264 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1265 else if (xlabel.handle_value ().ok () && h == xlabel.handle_value ()) |
6705
|
1266 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1267 else if (ylabel.handle_value ().ok () && h == ylabel.handle_value ()) |
6705
|
1268 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1269 else if (zlabel.handle_value ().ok () && h == zlabel.handle_value ()) |
6705
|
1270 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1271 else |
|
1272 base_properties::remove_child (h); |
|
1273 } |
6406
|
1274 |
6705
|
1275 void |
6844
|
1276 axes::properties::delete_children (void) |
6705
|
1277 { |
|
1278 base_properties::delete_children (); |
|
1279 |
7363
|
1280 gh_manager::free (title.handle_value ()); |
|
1281 gh_manager::free (xlabel.handle_value ()); |
|
1282 gh_manager::free (ylabel.handle_value ()); |
|
1283 gh_manager::free (zlabel.handle_value ()); |
6705
|
1284 } |
6406
|
1285 |
6836
|
1286 octave_value |
7189
|
1287 axes::get_default (const caseless_str& name) const |
6836
|
1288 { |
|
1289 octave_value retval = default_properties.lookup (name); |
|
1290 |
|
1291 if (retval.is_undefined ()) |
|
1292 { |
|
1293 graphics_handle parent = get_parent (); |
|
1294 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1295 |
|
1296 retval = parent_obj.get_default (name); |
|
1297 } |
|
1298 |
|
1299 return retval; |
|
1300 } |
|
1301 |
7222
|
1302 static void |
|
1303 check_limit_vals (double& min_val, double& max_val, double& min_pos, |
|
1304 const data_property& data) |
|
1305 { |
7267
|
1306 double val = data.min_val (); |
|
1307 if (! (xisinf (val) || xisnan (val)) && val < min_val) |
|
1308 min_val = val; |
|
1309 val = data.max_val (); |
|
1310 if (! (xisinf (val) || xisnan (val)) && val > max_val) |
|
1311 max_val = val; |
|
1312 val = data.min_pos (); |
|
1313 if (! (xisinf (val) || xisnan (val)) && val > 0 && val < min_pos) |
|
1314 min_pos = val; |
7222
|
1315 } |
|
1316 |
|
1317 // Attempt to make "nice" limits from the actual max and min of the |
|
1318 // data. For log plots, we will also use the smallest strictly positive |
|
1319 // value. |
|
1320 |
|
1321 static Matrix |
|
1322 get_axis_limits (double xmin, double xmax, double min_pos, bool logscale) |
|
1323 { |
|
1324 Matrix retval; |
|
1325 |
|
1326 double min_val = xmin; |
|
1327 double max_val = xmax; |
|
1328 |
|
1329 if (! (xisinf (min_val) || xisinf (max_val))) |
|
1330 { |
|
1331 if (logscale) |
|
1332 { |
|
1333 if (xisinf (min_pos)) |
|
1334 { |
|
1335 // warning ("axis: logscale with no positive values to plot"); |
|
1336 return retval; |
|
1337 } |
|
1338 |
|
1339 if (min_val <= 0) |
|
1340 { |
|
1341 warning ("axis: omitting nonpositive data in log plot"); |
|
1342 min_val = min_pos; |
|
1343 } |
|
1344 // FIXME -- maybe this test should also be relative? |
|
1345 if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) |
|
1346 { |
|
1347 min_val *= 0.9; |
|
1348 max_val *= 1.1; |
|
1349 } |
|
1350 min_val = pow (10, floor (log10 (min_val))); |
|
1351 max_val = pow (10, ceil (log10 (max_val))); |
|
1352 } |
|
1353 else |
|
1354 { |
|
1355 if (min_val == 0 && max_val == 0) |
|
1356 { |
|
1357 min_val = -1; |
|
1358 max_val = 1; |
|
1359 } |
|
1360 // FIXME -- maybe this test should also be relative? |
|
1361 else if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) |
|
1362 { |
|
1363 min_val -= 0.1 * std::abs (min_val); |
|
1364 max_val += 0.1 * std::abs (max_val); |
|
1365 } |
|
1366 // FIXME -- to do a better job, we should consider the tic spacing. |
|
1367 double scale = pow (10, floor (log10 (max_val - min_val) - 1)); |
|
1368 min_val = scale * floor (min_val / scale); |
|
1369 max_val = scale * ceil (max_val / scale); |
|
1370 } |
|
1371 } |
|
1372 |
|
1373 retval.resize (1, 2); |
|
1374 |
|
1375 retval(0) = min_val; |
|
1376 retval(1) = max_val; |
|
1377 |
|
1378 return retval; |
|
1379 } |
|
1380 |
|
1381 static bool updating_axis_limits = false; |
|
1382 |
7214
|
1383 void |
7222
|
1384 axes::update_axis_limits (const std::string& axis_type) |
7214
|
1385 { |
7222
|
1386 if (updating_axis_limits) |
|
1387 return; |
|
1388 |
|
1389 Matrix kids = xproperties.get_children (); |
|
1390 |
|
1391 octave_idx_type n = kids.numel (); |
|
1392 |
|
1393 double min_val = octave_Inf; |
|
1394 double max_val = -octave_Inf; |
|
1395 double min_pos = octave_Inf; |
|
1396 |
|
1397 char update_type = 0; |
|
1398 |
|
1399 Matrix limits; |
|
1400 |
|
1401 if (axis_type == "xdata" || axis_type == "xscale" |
|
1402 || axis_type == "xldata" || axis_type == "xudata" |
|
1403 || axis_type == "xlimmode") |
|
1404 { |
7363
|
1405 if (xproperties.xlimmode_is ("auto")) |
7222
|
1406 { |
|
1407 for (octave_idx_type i = 0; i < n; i++) |
|
1408 { |
|
1409 graphics_object obj = gh_manager::get_object (kids(i)); |
|
1410 |
|
1411 if (obj.isa ("line") || obj.isa ("image") |
|
1412 || obj.isa ("patch") || obj.isa ("surface")) |
|
1413 { |
7363
|
1414 data_property xdata = obj.get_xdata_property (); |
7222
|
1415 |
|
1416 check_limit_vals (min_val, max_val, min_pos, xdata); |
|
1417 |
|
1418 if (obj.isa ("line")) |
|
1419 { |
7363
|
1420 data_property xldata = obj.get_xldata_property (); |
|
1421 data_property xudata = obj.get_xudata_property (); |
7222
|
1422 |
|
1423 check_limit_vals (min_val, max_val, min_pos, xldata); |
|
1424 check_limit_vals (min_val, max_val, min_pos, xudata); |
|
1425 } |
|
1426 } |
|
1427 } |
|
1428 |
|
1429 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
1430 xproperties.xscale_is ("log")); |
7222
|
1431 |
|
1432 update_type = 'x'; |
|
1433 } |
|
1434 } |
|
1435 else if (axis_type == "ydata" || axis_type == "yscale" |
|
1436 || axis_type == "ldata" || axis_type == "udata" |
|
1437 || axis_type == "ylimmode") |
|
1438 { |
7363
|
1439 if (xproperties.ylimmode_is ("auto")) |
7222
|
1440 { |
|
1441 for (octave_idx_type i = 0; i < n; i++) |
|
1442 { |
|
1443 graphics_object obj = gh_manager::get_object (kids(i)); |
|
1444 |
|
1445 if (obj.isa ("line") || obj.isa ("image") |
|
1446 || obj.isa ("patch") || obj.isa ("surface")) |
|
1447 { |
7363
|
1448 data_property ydata = obj.get_ydata_property (); |
7222
|
1449 |
|
1450 check_limit_vals (min_val, max_val, min_pos, ydata); |
|
1451 |
|
1452 if (obj.isa ("line")) |
|
1453 { |
7363
|
1454 data_property ldata = obj.get_ldata_property (); |
|
1455 data_property udata = obj.get_udata_property (); |
7222
|
1456 |
|
1457 check_limit_vals (min_val, max_val, min_pos, ldata); |
|
1458 check_limit_vals (min_val, max_val, min_pos, udata); |
|
1459 } |
|
1460 } |
|
1461 } |
|
1462 |
|
1463 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
1464 xproperties.yscale_is ("log")); |
7222
|
1465 |
|
1466 update_type = 'y'; |
|
1467 } |
|
1468 } |
|
1469 else if (axis_type == "zdata" || axis_type == "zscale" |
|
1470 || axis_type == "zlimmode") |
|
1471 { |
7363
|
1472 if (xproperties.zlimmode_is ("auto")) |
7222
|
1473 { |
|
1474 for (octave_idx_type i = 0; i < n; i++) |
|
1475 { |
|
1476 graphics_object obj = gh_manager::get_object (kids(i)); |
|
1477 |
|
1478 if (obj.isa ("line") || obj.isa ("patch") || obj.isa ("surface")) |
|
1479 { |
7363
|
1480 data_property zdata = obj.get_zdata_property (); |
7222
|
1481 |
|
1482 check_limit_vals (min_val, max_val, min_pos, zdata); |
|
1483 } |
|
1484 } |
|
1485 |
|
1486 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
1487 xproperties.zscale_is ("log")); |
7222
|
1488 |
|
1489 update_type = 'z'; |
|
1490 } |
|
1491 } |
|
1492 else if (axis_type == "cdata" || axis_type == "climmode") |
|
1493 { |
7363
|
1494 if (xproperties.climmode_is ("auto")) |
7222
|
1495 { |
|
1496 for (octave_idx_type i = 0; i < n; i++) |
|
1497 { |
|
1498 graphics_object obj = gh_manager::get_object (kids(i)); |
|
1499 |
|
1500 if (obj.isa ("image") || obj.isa ("patch") || obj.isa ("surface")) |
|
1501 { |
7363
|
1502 data_property cdata = obj.get_cdata_property (); |
7222
|
1503 |
|
1504 check_limit_vals (min_val, max_val, min_pos, cdata); |
|
1505 } |
|
1506 } |
|
1507 |
|
1508 if (min_val == max_val) |
|
1509 max_val = min_val + 1; |
|
1510 |
|
1511 limits.resize (1, 2); |
|
1512 |
|
1513 limits(0) = min_val; |
|
1514 limits(1) = max_val; |
|
1515 |
|
1516 update_type = 'c'; |
|
1517 } |
|
1518 |
|
1519 } |
|
1520 |
|
1521 unwind_protect_bool (updating_axis_limits); |
|
1522 updating_axis_limits = true; |
|
1523 |
|
1524 switch (update_type) |
|
1525 { |
|
1526 case 'x': |
|
1527 xproperties.set_xlim (limits); |
|
1528 xproperties.set_xlimmode ("auto"); |
|
1529 break; |
|
1530 |
|
1531 case 'y': |
|
1532 xproperties.set_ylim (limits); |
|
1533 xproperties.set_ylimmode ("auto"); |
|
1534 break; |
|
1535 |
|
1536 case 'z': |
|
1537 xproperties.set_zlim (limits); |
|
1538 xproperties.set_zlimmode ("auto"); |
|
1539 break; |
|
1540 |
|
1541 case 'c': |
|
1542 xproperties.set_clim (limits); |
|
1543 xproperties.set_climmode ("auto"); |
|
1544 break; |
|
1545 |
|
1546 default: |
|
1547 break; |
|
1548 } |
|
1549 |
|
1550 unwind_protect::run (); |
7214
|
1551 } |
|
1552 |
7363
|
1553 // --------------------------------------------------------------------- |
|
1554 |
|
1555 // Note: "line" code is entirely auto-generated |
6406
|
1556 |
|
1557 // --------------------------------------------------------------------- |
|
1558 |
7363
|
1559 // Note: "text" code is entirely auto-generated |
6406
|
1560 |
|
1561 // --------------------------------------------------------------------- |
|
1562 |
7363
|
1563 // Note: "image" code is entirely auto-generated |
6406
|
1564 |
|
1565 // --------------------------------------------------------------------- |
|
1566 |
7363
|
1567 // Note: "patch" code is entirely auto-generated |
6807
|
1568 |
|
1569 // --------------------------------------------------------------------- |
|
1570 |
7363
|
1571 // Note: "surface" code is entirely auto-generated |
6406
|
1572 |
|
1573 // --------------------------------------------------------------------- |
|
1574 |
|
1575 octave_value |
7189
|
1576 base_graphics_object::get_default (const caseless_str& name) const |
6406
|
1577 { |
|
1578 graphics_handle parent = get_parent (); |
|
1579 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1580 |
|
1581 return parent_obj.get_default (type () + name); |
|
1582 } |
|
1583 |
|
1584 octave_value |
7189
|
1585 base_graphics_object::get_factory_default (const caseless_str& name) const |
6406
|
1586 { |
|
1587 graphics_object parent_obj = gh_manager::get_object (0); |
|
1588 |
|
1589 return parent_obj.get_factory_default (type () + name); |
|
1590 } |
|
1591 |
7286
|
1592 // We use a random value for the handle to avoid issues with plots and |
|
1593 // scalar values for the first argument. |
6406
|
1594 gh_manager::gh_manager (void) |
7286
|
1595 : handle_map (), handle_free_list (), |
|
1596 next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) |
6406
|
1597 { |
|
1598 handle_map[0] = graphics_object (new root_figure ()); |
|
1599 } |
|
1600 |
|
1601 graphics_handle |
|
1602 gh_manager::do_make_graphics_handle (const std::string& go_name, |
|
1603 const graphics_handle& p) |
|
1604 { |
|
1605 graphics_handle h = get_handle (go_name); |
|
1606 |
|
1607 base_graphics_object *go = 0; |
|
1608 |
|
1609 if (go_name == "figure") |
|
1610 go = new figure (h, p); |
|
1611 else if (go_name == "axes") |
|
1612 go = new axes (h, p); |
|
1613 else if (go_name == "line") |
|
1614 go = new line (h, p); |
|
1615 else if (go_name == "text") |
|
1616 go = new text (h, p); |
|
1617 else if (go_name == "image") |
|
1618 go = new image (h, p); |
6807
|
1619 else if (go_name == "patch") |
|
1620 go = new patch (h, p); |
6406
|
1621 else if (go_name == "surface") |
|
1622 go = new surface (h, p); |
|
1623 if (go) |
|
1624 handle_map[h] = graphics_object (go); |
|
1625 else |
|
1626 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
|
1627 go_name.c_str ()); |
|
1628 |
|
1629 return h; |
|
1630 } |
|
1631 |
|
1632 graphics_handle |
|
1633 gh_manager::do_make_figure_handle (double val) |
|
1634 { |
|
1635 graphics_handle h = val; |
|
1636 |
|
1637 handle_map[h] = graphics_object (new figure (h, 0)); |
|
1638 |
|
1639 return h; |
|
1640 } |
|
1641 |
|
1642 void |
|
1643 gh_manager::do_push_figure (const graphics_handle& h) |
|
1644 { |
|
1645 do_pop_figure (h); |
|
1646 |
|
1647 figure_list.push_front (h); |
|
1648 } |
|
1649 |
|
1650 void |
|
1651 gh_manager::do_pop_figure (const graphics_handle& h) |
|
1652 { |
|
1653 for (figure_list_iterator p = figure_list.begin (); |
|
1654 p != figure_list.end (); |
|
1655 p++) |
|
1656 { |
|
1657 if (*p == h) |
|
1658 { |
|
1659 figure_list.erase (p); |
|
1660 break; |
|
1661 } |
|
1662 } |
|
1663 } |
|
1664 |
|
1665 property_list::plist_map_type |
|
1666 root_figure::init_factory_properties (void) |
|
1667 { |
|
1668 property_list::plist_map_type plist_map; |
|
1669 |
6844
|
1670 plist_map["figure"] = figure::properties::factory_defaults (); |
|
1671 plist_map["axes"] = axes::properties::factory_defaults (); |
|
1672 plist_map["line"] = line::properties::factory_defaults (); |
|
1673 plist_map["text"] = text::properties::factory_defaults (); |
|
1674 plist_map["image"] = image::properties::factory_defaults (); |
|
1675 plist_map["patch"] = patch::properties::factory_defaults (); |
|
1676 plist_map["surface"] = surface::properties::factory_defaults (); |
6406
|
1677 |
|
1678 return plist_map; |
|
1679 } |
|
1680 |
|
1681 // --------------------------------------------------------------------- |
|
1682 |
|
1683 DEFUN (ishandle, args, , |
|
1684 "-*- texinfo -*-\n\ |
6678
|
1685 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406
|
1686 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
|
1687 @end deftypefn") |
|
1688 { |
|
1689 octave_value retval; |
|
1690 |
|
1691 if (args.length () == 1) |
|
1692 retval = is_handle (args(0)); |
|
1693 else |
|
1694 print_usage (); |
|
1695 |
|
1696 return retval; |
|
1697 } |
|
1698 |
|
1699 DEFUN (set, args, , |
|
1700 "-*- texinfo -*-\n\ |
6678
|
1701 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6732
|
1702 Set the named property value or vector @var{p} to the value @var{v}\n\ |
6894
|
1703 for the graphics handle @var{h}.\n\ |
6406
|
1704 @end deftypefn") |
|
1705 { |
|
1706 octave_value retval; |
|
1707 |
|
1708 int nargin = args.length (); |
|
1709 |
|
1710 if (nargin > 0) |
|
1711 { |
6732
|
1712 ColumnVector hcv (args(0).vector_value ()); |
6406
|
1713 |
|
1714 if (! error_state) |
6732
|
1715 { |
6733
|
1716 bool request_drawnow = false; |
|
1717 |
6732
|
1718 for (octave_idx_type n = 0; n < hcv.length (); n++) |
|
1719 { |
|
1720 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
1721 |
6732
|
1722 if (obj) |
|
1723 { |
|
1724 obj.set (args.splice (0, 1)); |
6406
|
1725 |
6733
|
1726 request_drawnow = true; |
6732
|
1727 } |
|
1728 else |
6733
|
1729 { |
|
1730 error ("set: invalid handle (= %g)", hcv(n)); |
|
1731 break; |
|
1732 } |
6732
|
1733 } |
6733
|
1734 |
|
1735 if (! error_state && request_drawnow) |
|
1736 feval ("__request_drawnow__"); |
6732
|
1737 } |
6406
|
1738 else |
6732
|
1739 error ("set: expecting graphics handle as first argument"); |
6406
|
1740 } |
|
1741 else |
|
1742 print_usage (); |
|
1743 |
|
1744 return retval; |
|
1745 } |
|
1746 |
|
1747 DEFUN (get, args, , |
|
1748 "-*- texinfo -*-\n\ |
6678
|
1749 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406
|
1750 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
|
1751 If @var{p} is omitted, return the complete property list for @var{h}.\n\ |
6732
|
1752 If @var{h} is a vector, return a cell array including the property\n\ |
|
1753 values or lists respectively.\n\ |
6406
|
1754 @end deftypefn") |
|
1755 { |
|
1756 octave_value retval; |
6732
|
1757 octave_value_list vlist; |
6406
|
1758 |
|
1759 int nargin = args.length (); |
|
1760 |
|
1761 if (nargin == 1 || nargin == 2) |
|
1762 { |
6732
|
1763 ColumnVector hcv (args(0).vector_value ()); |
6406
|
1764 |
|
1765 if (! error_state) |
6732
|
1766 { |
6733
|
1767 octave_idx_type len = hcv.length (); |
|
1768 |
|
1769 vlist.resize (len); |
|
1770 |
|
1771 for (octave_idx_type n = 0; n < len; n++) |
6732
|
1772 { |
|
1773 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
1774 |
6732
|
1775 if (obj) |
|
1776 { |
|
1777 if (nargin == 1) |
|
1778 vlist(n) = obj.get (); |
|
1779 else |
|
1780 { |
7189
|
1781 caseless_str property = args(1).string_value (); |
6406
|
1782 |
6732
|
1783 if (! error_state) |
|
1784 vlist(n) = obj.get (property); |
|
1785 else |
6733
|
1786 { |
|
1787 error ("get: expecting property name as second argument"); |
|
1788 break; |
|
1789 } |
6732
|
1790 } |
|
1791 } |
|
1792 else |
6733
|
1793 { |
|
1794 error ("get: invalid handle (= %g)", hcv(n)); |
|
1795 break; |
|
1796 } |
6732
|
1797 } |
|
1798 } |
6406
|
1799 else |
6732
|
1800 error ("get: expecting graphics handle as first argument"); |
6406
|
1801 } |
|
1802 else |
|
1803 print_usage (); |
|
1804 |
6733
|
1805 if (! error_state) |
6732
|
1806 { |
6733
|
1807 octave_idx_type len = vlist.length (); |
|
1808 |
|
1809 if (len > 1) |
|
1810 retval = Cell (vlist); |
|
1811 else if (len == 1) |
|
1812 retval = vlist(0); |
6732
|
1813 } |
|
1814 |
6406
|
1815 return retval; |
|
1816 } |
|
1817 |
|
1818 static octave_value |
|
1819 make_graphics_object (const std::string& go_name, |
6874
|
1820 const octave_value_list& args) |
6406
|
1821 { |
|
1822 octave_value retval; |
|
1823 |
|
1824 double val = args(0).double_value (); |
|
1825 |
|
1826 if (! error_state) |
|
1827 { |
|
1828 graphics_handle parent = gh_manager::lookup (val); |
|
1829 |
7056
|
1830 if (parent.ok ()) |
6406
|
1831 { |
|
1832 graphics_handle h |
|
1833 = gh_manager::make_graphics_handle (go_name, parent); |
|
1834 |
|
1835 if (! error_state) |
|
1836 { |
|
1837 adopt (parent, h); |
|
1838 |
|
1839 xset (h, args.splice (0, 1)); |
|
1840 |
6874
|
1841 retval = h.value (); |
7296
|
1842 |
|
1843 if (! error_state) |
|
1844 feval ("__request_drawnow__"); |
6406
|
1845 } |
|
1846 else |
|
1847 error ("__go%s__: unable to create graphics handle", |
|
1848 go_name.c_str ()); |
|
1849 } |
|
1850 else |
|
1851 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
1852 } |
|
1853 else |
|
1854 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
1855 |
|
1856 return retval; |
|
1857 } |
|
1858 |
|
1859 DEFUN (__go_figure__, args, , |
|
1860 "-*- texinfo -*-\n\ |
|
1861 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ |
6945
|
1862 Undocumented internal function.\n\ |
6406
|
1863 @end deftypefn") |
|
1864 { |
|
1865 octave_value retval; |
|
1866 |
|
1867 if (args.length () > 0) |
|
1868 { |
|
1869 double val = args(0).double_value (); |
|
1870 |
|
1871 if (! error_state) |
|
1872 { |
|
1873 if (is_figure (val)) |
|
1874 { |
|
1875 graphics_handle h = gh_manager::lookup (val); |
|
1876 |
|
1877 xset (h, args.splice (0, 1)); |
|
1878 |
6874
|
1879 retval = h.value (); |
6406
|
1880 } |
|
1881 else |
|
1882 { |
|
1883 graphics_handle h = octave_NaN; |
|
1884 |
|
1885 if (xisnan (val)) |
|
1886 h = gh_manager::make_graphics_handle ("figure", 0); |
|
1887 else if (val > 0 && D_NINT (val) == val) |
|
1888 h = gh_manager::make_figure_handle (val); |
|
1889 else |
|
1890 error ("__go_figure__: invalid figure number"); |
|
1891 |
7056
|
1892 if (! error_state && h.ok ()) |
6406
|
1893 { |
|
1894 adopt (0, h); |
|
1895 |
|
1896 xset (h, args.splice (0, 1)); |
|
1897 |
6874
|
1898 retval = h.value (); |
6406
|
1899 } |
|
1900 else |
|
1901 error ("__go_figure__: failed to create figure handle"); |
|
1902 } |
|
1903 } |
|
1904 else |
|
1905 error ("__go_figure__: expecting figure number to be double value"); |
|
1906 } |
|
1907 else |
|
1908 print_usage (); |
|
1909 |
|
1910 return retval; |
|
1911 } |
|
1912 |
|
1913 #define GO_BODY(TYPE) \ |
|
1914 octave_value retval; \ |
|
1915 \ |
|
1916 if (args.length () > 0) \ |
|
1917 retval = make_graphics_object (#TYPE, args); \ |
|
1918 else \ |
|
1919 print_usage (); \ |
|
1920 \ |
|
1921 return retval |
|
1922 |
|
1923 DEFUN (__go_axes__, args, , |
|
1924 "-*- texinfo -*-\n\ |
|
1925 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ |
6945
|
1926 Undocumented internal function.\n\ |
6406
|
1927 @end deftypefn") |
|
1928 { |
|
1929 GO_BODY (axes); |
|
1930 } |
|
1931 |
|
1932 DEFUN (__go_line__, args, , |
|
1933 "-*- texinfo -*-\n\ |
|
1934 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ |
6945
|
1935 Undocumented internal function.\n\ |
6406
|
1936 @end deftypefn") |
|
1937 { |
|
1938 GO_BODY (line); |
|
1939 } |
|
1940 |
|
1941 DEFUN (__go_text__, args, , |
|
1942 "-*- texinfo -*-\n\ |
|
1943 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ |
6945
|
1944 Undocumented internal function.\n\ |
6406
|
1945 @end deftypefn") |
|
1946 { |
|
1947 GO_BODY (text); |
|
1948 } |
|
1949 |
|
1950 DEFUN (__go_image__, args, , |
|
1951 "-*- texinfo -*-\n\ |
|
1952 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ |
6945
|
1953 Undocumented internal function.\n\ |
6406
|
1954 @end deftypefn") |
|
1955 { |
|
1956 GO_BODY (image); |
|
1957 } |
|
1958 |
|
1959 DEFUN (__go_surface__, args, , |
|
1960 "-*- texinfo -*-\n\ |
|
1961 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ |
6945
|
1962 Undocumented internal function.\n\ |
6406
|
1963 @end deftypefn") |
|
1964 { |
|
1965 GO_BODY (surface); |
|
1966 } |
|
1967 |
6807
|
1968 DEFUN (__go_patch__, args, , |
|
1969 "-*- texinfo -*-\n\ |
|
1970 @deftypefn {Built-in Function} {} __go_patch__ (@var{parent})\n\ |
6945
|
1971 Undocumented internal function.\n\ |
6807
|
1972 @end deftypefn") |
|
1973 { |
|
1974 GO_BODY (patch); |
|
1975 } |
|
1976 |
6406
|
1977 DEFUN (__go_delete__, args, , |
|
1978 "-*- texinfo -*-\n\ |
|
1979 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ |
6945
|
1980 Undocumented internal function.\n\ |
6406
|
1981 @end deftypefn") |
|
1982 { |
|
1983 octave_value_list retval; |
|
1984 |
|
1985 if (args.length () == 1) |
|
1986 { |
|
1987 graphics_handle h = octave_NaN; |
|
1988 |
|
1989 double val = args(0).double_value (); |
|
1990 |
|
1991 if (! error_state) |
|
1992 { |
|
1993 h = gh_manager::lookup (val); |
|
1994 |
7056
|
1995 if (h.ok ()) |
6406
|
1996 { |
|
1997 graphics_object obj = gh_manager::get_object (h); |
|
1998 |
|
1999 graphics_handle parent_h = obj.get_parent (); |
|
2000 |
|
2001 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
2002 |
|
2003 parent_obj.remove_child (h); |
|
2004 |
|
2005 gh_manager::free (h); |
|
2006 } |
|
2007 else |
|
2008 error ("delete: invalid graphics object (= %g)", val); |
|
2009 } |
|
2010 else |
|
2011 error ("delete: invalid graphics object"); |
|
2012 } |
|
2013 else |
|
2014 print_usage (); |
|
2015 |
|
2016 return retval; |
|
2017 } |
|
2018 |
|
2019 DEFUN (__go_axes_init__, args, , |
|
2020 "-*- texinfo -*-\n\ |
|
2021 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ |
6945
|
2022 Undocumented internal function.\n\ |
6406
|
2023 @end deftypefn") |
|
2024 { |
|
2025 octave_value retval; |
|
2026 |
|
2027 int nargin = args.length (); |
|
2028 |
|
2029 std::string mode = ""; |
|
2030 |
|
2031 if (nargin == 2) |
|
2032 { |
|
2033 mode = args(1).string_value (); |
|
2034 |
|
2035 if (error_state) |
|
2036 return retval; |
|
2037 } |
|
2038 |
|
2039 if (nargin == 1 || nargin == 2) |
|
2040 { |
|
2041 graphics_handle h = octave_NaN; |
|
2042 |
|
2043 double val = args(0).double_value (); |
|
2044 |
|
2045 if (! error_state) |
|
2046 { |
|
2047 h = gh_manager::lookup (val); |
|
2048 |
7056
|
2049 if (h.ok ()) |
6406
|
2050 { |
|
2051 graphics_object obj = gh_manager::get_object (h); |
|
2052 |
|
2053 obj.set_defaults (mode); |
|
2054 } |
|
2055 else |
|
2056 error ("__go_axes_init__: invalid graphics object (= %g)", val); |
|
2057 } |
|
2058 else |
|
2059 error ("__go_axes_init__: invalid graphics object"); |
|
2060 } |
|
2061 else |
|
2062 print_usage (); |
|
2063 |
|
2064 return retval; |
|
2065 } |
|
2066 |
|
2067 DEFUN (__go_handles__, , , |
|
2068 "-*- texinfo -*-\n\ |
|
2069 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ |
6945
|
2070 Undocumented internal function.\n\ |
6406
|
2071 @end deftypefn") |
|
2072 { |
6425
|
2073 return octave_value (gh_manager::handle_list ()); |
|
2074 } |
|
2075 |
|
2076 DEFUN (__go_figure_handles__, , , |
|
2077 "-*- texinfo -*-\n\ |
|
2078 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ |
6945
|
2079 Undocumented internal function.\n\ |
6425
|
2080 @end deftypefn") |
|
2081 { |
|
2082 return octave_value (gh_manager::figure_handle_list ()); |
6406
|
2083 } |
|
2084 |
6595
|
2085 octave_value |
|
2086 get_property_from_handle (double handle, const std::string &property, |
|
2087 const std::string &func) |
|
2088 { |
|
2089 graphics_object obj = gh_manager::get_object (handle); |
|
2090 octave_value retval; |
|
2091 |
|
2092 if (obj) |
|
2093 { |
7189
|
2094 caseless_str p = std::string (property); |
6595
|
2095 retval = obj.get (p); |
|
2096 } |
|
2097 else |
|
2098 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2099 |
|
2100 return retval; |
|
2101 } |
|
2102 |
|
2103 bool |
|
2104 set_property_in_handle (double handle, const std::string &property, |
|
2105 const octave_value &arg, const std::string &func) |
|
2106 { |
|
2107 graphics_object obj = gh_manager::get_object (handle); |
|
2108 int ret = false; |
|
2109 |
|
2110 if (obj) |
|
2111 { |
7189
|
2112 caseless_str p = std::string (property); |
6595
|
2113 obj.set (p, arg); |
|
2114 if (!error_state) |
|
2115 ret = true; |
|
2116 } |
|
2117 else |
|
2118 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2119 |
|
2120 return ret; |
|
2121 } |
|
2122 |
6406
|
2123 /* |
|
2124 ;;; Local Variables: *** |
|
2125 ;;; mode: C++ *** |
|
2126 ;;; End: *** |
|
2127 */ |