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; |
7366
|
832 else if (name.compare ("busyaction")) |
|
833 retval = get_busyaction (); |
|
834 else if (name.compare ("buttondownfcn")) |
|
835 retval = get_buttondownfcn (); |
|
836 else if (name.compare ("clipping")) |
|
837 retval = get_clipping (); |
|
838 else if (name.compare ("createfcn")) |
|
839 retval = get_createfcn (); |
|
840 else if (name.compare ("deletefcn")) |
|
841 retval = get_deletefcn (); |
|
842 else if (name.compare ("handlevisibility")) |
|
843 retval = get_handlevisibility (); |
|
844 else if (name.compare ("hittest")) |
|
845 retval = get_hittest (); |
|
846 else if (name.compare ("interruptible")) |
|
847 retval = get_interruptible (); |
|
848 else if (name.compare ("selected")) |
|
849 retval = get_selected (); |
|
850 else if (name.compare ("selectionhighlight")) |
|
851 retval = get_selectionhighlight (); |
|
852 else if (name.compare ("uicontextmenu")) |
|
853 retval = get_uicontextmenu (); |
|
854 else if (name.compare ("userdata")) |
|
855 retval = get_userdata (); |
|
856 else if (name.compare ("visible")) |
|
857 retval = get_visible (); |
7363
|
858 else |
|
859 { |
|
860 std::map<caseless_str, property>::const_iterator it = all_props.find (name); |
|
861 |
|
862 if (it != all_props.end ()) |
|
863 retval = it->second.get (); |
|
864 else |
|
865 error ("get: unknown property \"%s\"", name.c_str ()); |
|
866 } |
|
867 |
|
868 return retval; |
|
869 } |
|
870 |
|
871 octave_value |
|
872 base_properties::get (void) const |
|
873 { |
|
874 Octave_map m; |
|
875 |
|
876 for (std::map<caseless_str, property>::const_iterator it = all_props.begin (); |
|
877 it != all_props.end (); ++it) |
|
878 m.assign (it->second.get_name (), it->second.get ()); |
|
879 |
|
880 m.assign ("tag", get_tag ()); |
|
881 m.assign ("type", get_type ()); |
|
882 m.assign ("__modified__", is_modified ()); |
|
883 m.assign ("parent", get_parent ().as_octave_value ()); |
|
884 m.assign ("children", children); |
7366
|
885 m.assign ("busyaction", get_busyaction ()); |
|
886 m.assign ("buttondownfcn", get_buttondownfcn ()); |
|
887 m.assign ("clipping", get_clipping ()); |
|
888 m.assign ("createfcn", get_createfcn ()); |
|
889 m.assign ("deletefcn", get_deletefcn ()); |
|
890 m.assign ("handlevisibility", get_handlevisibility ()); |
|
891 m.assign ("hittest", get_hittest ()); |
|
892 m.assign ("interruptible", get_interruptible ()); |
|
893 m.assign ("selected", get_selected ()); |
|
894 m.assign ("selectionhighlight", get_selectionhighlight ()); |
|
895 m.assign ("uicontextmenu", get_uicontextmenu ()); |
|
896 m.assign ("userdata", get_userdata ()); |
|
897 m.assign ("visible", get_visible ()); |
7363
|
898 |
|
899 return m; |
|
900 } |
|
901 |
|
902 void |
|
903 base_properties::set (const caseless_str& name, const octave_value& val) |
|
904 { |
|
905 if (name.compare ("tag")) |
|
906 set_tag (val); |
|
907 else if (name.compare ("__modified__")) |
|
908 __modified__ = val; |
|
909 else if (name.compare ("parent")) |
|
910 set_parent (val); |
|
911 else if (name.compare ("children")) |
|
912 maybe_set_children (children, val); |
7366
|
913 else if (name.compare ("busyaction")) |
|
914 set_busyaction (val); |
|
915 else if (name.compare ("buttondownfcn")) |
|
916 set_buttondownfcn (val); |
|
917 else if (name.compare ("clipping")) |
|
918 set_clipping (val); |
|
919 else if (name.compare ("createfcn")) |
|
920 set_createfcn (val); |
|
921 else if (name.compare ("deletefcn")) |
|
922 set_deletefcn (val); |
|
923 else if (name.compare ("handlevisibility")) |
|
924 set_handlevisibility (val); |
|
925 else if (name.compare ("hittest")) |
|
926 set_hittest (val); |
|
927 else if (name.compare ("interruptible")) |
|
928 set_interruptible (val); |
|
929 else if (name.compare ("selected")) |
|
930 set_selected (val); |
|
931 else if (name.compare ("selectionhighlight")) |
|
932 set_selectionhighlight (val); |
|
933 else if (name.compare ("uicontextmenu")) |
|
934 set_uicontextmenu (val); |
|
935 else if (name.compare ("userdata")) |
|
936 set_userdata (val); |
|
937 else if (name.compare ("visible")) |
|
938 set_visible (val); |
7363
|
939 else |
|
940 { |
|
941 std::map<caseless_str, property>::iterator it = all_props.find (name); |
|
942 |
|
943 if (it != all_props.end ()) |
|
944 it->second.set (val); |
|
945 else |
|
946 error ("set: unknown property \"%s\"", name.c_str ()); |
|
947 } |
|
948 |
|
949 if (! error_state && ! name.compare ("__modified__")) |
|
950 mark_modified (); |
|
951 } |
|
952 |
|
953 property |
|
954 base_properties::get_property (const caseless_str& name) const |
|
955 { |
|
956 std::map<caseless_str, property>::const_iterator it = all_props.find (name); |
|
957 |
|
958 if (it == all_props.end ()) |
|
959 return property (); |
|
960 else |
|
961 return it->second; |
|
962 } |
|
963 |
6705
|
964 void |
|
965 base_properties::remove_child (const graphics_handle& h) |
6406
|
966 { |
6705
|
967 octave_idx_type k = -1; |
|
968 octave_idx_type n = children.numel (); |
|
969 for (octave_idx_type i = 0; i < n; i++) |
6406
|
970 { |
6874
|
971 if (h.value () == children(i)) |
6406
|
972 { |
6705
|
973 k = i; |
|
974 break; |
6406
|
975 } |
|
976 } |
|
977 |
6705
|
978 if (k >= 0) |
6406
|
979 { |
6705
|
980 Matrix new_kids (1, n-1); |
|
981 octave_idx_type j = 0; |
|
982 for (octave_idx_type i = 0; i < n; i++) |
|
983 { |
|
984 if (i != k) |
|
985 new_kids(j++) = children(i); |
|
986 } |
|
987 children = new_kids; |
6406
|
988 } |
6705
|
989 } |
6406
|
990 |
6836
|
991 void |
|
992 base_properties::set_parent (const octave_value& val) |
6705
|
993 { |
|
994 double tmp = val.double_value (); |
6406
|
995 |
6705
|
996 graphics_handle new_parent = octave_NaN; |
6406
|
997 |
6705
|
998 if (! error_state) |
|
999 { |
|
1000 new_parent = gh_manager::lookup (tmp); |
6406
|
1001 |
7056
|
1002 if (new_parent.ok ()) |
6705
|
1003 { |
7363
|
1004 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
6406
|
1005 |
6705
|
1006 parent_obj.remove_child (__myhandle__); |
6406
|
1007 |
7363
|
1008 parent = new_parent.as_octave_value (); |
6406
|
1009 |
7363
|
1010 ::adopt (parent.handle_value (), __myhandle__); |
6705
|
1011 } |
|
1012 else |
|
1013 error ("set: invalid graphics handle (= %g) for parent", tmp); |
|
1014 } |
|
1015 else |
|
1016 error ("set: expecting parent to be a graphics handle"); |
|
1017 } |
6432
|
1018 |
6705
|
1019 void |
6836
|
1020 base_properties::mark_modified (void) |
|
1021 { |
7363
|
1022 __modified__ = "on"; |
|
1023 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
6836
|
1024 parent_obj.mark_modified (); |
|
1025 } |
|
1026 |
|
1027 void |
|
1028 base_properties::override_defaults (base_graphics_object& obj) |
|
1029 { |
7363
|
1030 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
6836
|
1031 parent_obj.override_defaults (obj); |
|
1032 } |
|
1033 |
|
1034 void |
7214
|
1035 base_properties::update_axis_limits (const std::string& axis_type) const |
|
1036 { |
7363
|
1037 graphics_handle h = (get_type () == "axes") ? __myhandle__ : get_parent (); |
7214
|
1038 |
|
1039 graphics_object obj = gh_manager::get_object (h); |
|
1040 |
|
1041 if (obj.isa ("axes")) |
|
1042 obj.update_axis_limits (axis_type); |
|
1043 } |
|
1044 |
|
1045 void |
6836
|
1046 base_properties::delete_children (void) |
|
1047 { |
|
1048 octave_idx_type n = children.numel (); |
|
1049 |
|
1050 for (octave_idx_type i = 0; i < n; i++) |
|
1051 gh_manager::free (children(i)); |
|
1052 } |
|
1053 |
7363
|
1054 // --------------------------------------------------------------------- |
|
1055 |
|
1056 #include "graphics-props.cc" |
|
1057 |
|
1058 // --------------------------------------------------------------------- |
|
1059 |
6836
|
1060 void |
7363
|
1061 root_figure::properties::set_currentfigure (const octave_value& v) |
6874
|
1062 { |
7363
|
1063 graphics_handle val (v.double_value ()); |
|
1064 |
6874
|
1065 if (error_state) |
|
1066 return; |
|
1067 |
7059
|
1068 if (xisnan (val.value ()) || is_handle (val)) |
6874
|
1069 { |
|
1070 currentfigure = val; |
|
1071 |
7363
|
1072 gh_manager::push_figure (val); |
6874
|
1073 } |
|
1074 else |
|
1075 gripe_set_invalid ("currentfigure"); |
|
1076 } |
|
1077 |
6406
|
1078 property_list |
|
1079 root_figure::factory_properties = root_figure::init_factory_properties (); |
|
1080 |
|
1081 // --------------------------------------------------------------------- |
|
1082 |
7363
|
1083 void |
|
1084 figure::properties::set_currentaxes (const octave_value& v) |
|
1085 { |
|
1086 graphics_handle val (v.double_value ()); |
6705
|
1087 |
6874
|
1088 if (error_state) |
|
1089 return; |
|
1090 |
7070
|
1091 if (xisnan (val.value ()) || is_handle (val)) |
6874
|
1092 currentaxes = val; |
|
1093 else |
|
1094 gripe_set_invalid ("currentaxes"); |
|
1095 } |
|
1096 |
|
1097 void |
|
1098 figure::properties::set_visible (const octave_value& val) |
|
1099 { |
|
1100 std::string s = val.string_value (); |
|
1101 |
|
1102 if (! error_state) |
|
1103 { |
|
1104 if (s == "on") |
|
1105 xset (0, "currentfigure", __myhandle__.value ()); |
|
1106 |
|
1107 visible = val; |
|
1108 } |
|
1109 } |
|
1110 |
|
1111 void |
6844
|
1112 figure::properties::close (void) |
6705
|
1113 { |
7363
|
1114 if (! get___plot_stream__ ().is_empty ()) |
6406
|
1115 { |
6705
|
1116 octave_value_list args; |
|
1117 args(1) = "\nquit;\n"; |
7363
|
1118 args(0) = get___plot_stream__ (); |
6705
|
1119 feval ("fputs", args); |
|
1120 args.resize (1); |
|
1121 feval ("fflush", args); |
|
1122 feval ("pclose", args); |
6406
|
1123 } |
|
1124 |
6705
|
1125 gh_manager::pop_figure (__myhandle__); |
6406
|
1126 |
6874
|
1127 graphics_handle cf = gh_manager::current_figure (); |
|
1128 |
|
1129 xset (0, "currentfigure", cf.value ()); |
6705
|
1130 } |
6432
|
1131 |
6836
|
1132 octave_value |
7189
|
1133 figure::get_default (const caseless_str& name) const |
6836
|
1134 { |
|
1135 octave_value retval = default_properties.lookup (name); |
|
1136 |
|
1137 if (retval.is_undefined ()) |
|
1138 { |
|
1139 graphics_handle parent = get_parent (); |
|
1140 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1141 |
|
1142 retval = parent_obj.get_default (name); |
|
1143 } |
|
1144 |
|
1145 return retval; |
|
1146 } |
|
1147 |
6406
|
1148 // --------------------------------------------------------------------- |
|
1149 |
7363
|
1150 void |
|
1151 axes::properties::set_title (const octave_value& v) |
6962
|
1152 { |
7363
|
1153 graphics_handle val = ::reparent (v, "set", "title", __myhandle__, false); |
6962
|
1154 |
6874
|
1155 if (! error_state) |
|
1156 { |
7363
|
1157 gh_manager::free (title.handle_value ()); |
6874
|
1158 title = val; |
|
1159 } |
|
1160 } |
|
1161 |
|
1162 void |
7363
|
1163 axes::properties::set_xlabel (const octave_value& v) |
6874
|
1164 { |
7363
|
1165 graphics_handle val = ::reparent (v, "set", "xlabel", __myhandle__, false); |
6874
|
1166 |
|
1167 if (! error_state) |
|
1168 { |
7363
|
1169 gh_manager::free (xlabel.handle_value ()); |
6874
|
1170 xlabel = val; |
|
1171 } |
|
1172 } |
|
1173 |
|
1174 void |
7363
|
1175 axes::properties::set_ylabel (const octave_value& v) |
6874
|
1176 { |
7363
|
1177 graphics_handle val = ::reparent (v, "set", "ylabel", __myhandle__, false); |
6874
|
1178 |
|
1179 if (! error_state) |
|
1180 { |
7363
|
1181 gh_manager::free (ylabel.handle_value ()); |
6874
|
1182 ylabel = val; |
|
1183 } |
|
1184 } |
|
1185 |
|
1186 void |
7363
|
1187 axes::properties::set_zlabel (const octave_value& v) |
6874
|
1188 { |
7363
|
1189 graphics_handle val = ::reparent (v, "set", "zlabel", __myhandle__, false); |
6874
|
1190 |
|
1191 if (! error_state) |
|
1192 { |
7363
|
1193 gh_manager::free (zlabel.handle_value ()); |
6874
|
1194 zlabel = val; |
|
1195 } |
|
1196 } |
|
1197 |
|
1198 void |
6844
|
1199 axes::properties::set_defaults (base_graphics_object& obj, |
6890
|
1200 const std::string& mode) |
6705
|
1201 { |
|
1202 position = Matrix (); |
7363
|
1203 title = graphics_handle (); |
6705
|
1204 box = "on"; |
|
1205 key = "off"; |
|
1206 keybox = "off"; |
7363
|
1207 keypos = 1.0; |
6962
|
1208 colororder = default_colororder (); |
6705
|
1209 dataaspectratio = Matrix (1, 3, 1.0); |
|
1210 dataaspectratiomode = "auto"; |
7363
|
1211 layer = "bottom"; |
6705
|
1212 |
|
1213 Matrix tlim (1, 2, 0.0); |
|
1214 tlim(1) = 1; |
|
1215 xlim = tlim; |
|
1216 ylim = tlim; |
|
1217 zlim = tlim; |
6807
|
1218 |
|
1219 Matrix cl (1, 2, 0); |
|
1220 cl(1) = 1; |
|
1221 clim = cl; |
|
1222 |
7363
|
1223 xlimmode = "auto"; |
|
1224 ylimmode = "auto"; |
|
1225 zlimmode = "auto"; |
|
1226 climmode = "auto"; |
|
1227 xlabel = graphics_handle (); |
|
1228 ylabel = graphics_handle (); |
|
1229 zlabel = graphics_handle (); |
6705
|
1230 xgrid = "off"; |
|
1231 ygrid = "off"; |
|
1232 zgrid = "off"; |
|
1233 xminorgrid = "off"; |
|
1234 yminorgrid = "off"; |
|
1235 zminorgrid = "off"; |
|
1236 xtick = Matrix (); |
|
1237 ytick = Matrix (); |
|
1238 ztick = Matrix (); |
|
1239 xtickmode = "auto"; |
|
1240 ytickmode = "auto"; |
|
1241 ztickmode = "auto"; |
|
1242 xticklabel = ""; |
|
1243 yticklabel = ""; |
|
1244 zticklabel = ""; |
|
1245 xticklabelmode = "auto"; |
|
1246 yticklabelmode = "auto"; |
|
1247 zticklabelmode = "auto"; |
7364
|
1248 color = color_values (0, 0, 0); |
|
1249 xcolor = color_values ("black"); |
|
1250 ycolor = color_values ("black"); |
|
1251 zcolor = color_values ("black"); |
7363
|
1252 xscale = "linear"; |
|
1253 yscale = "linear"; |
|
1254 zscale = "linear"; |
6705
|
1255 xdir = "normal"; |
|
1256 ydir = "normal"; |
|
1257 zdir = "normal"; |
7363
|
1258 yaxislocation = "left"; |
|
1259 xaxislocation = "bottom"; |
6705
|
1260 |
|
1261 Matrix tview (1, 2, 0.0); |
|
1262 tview(1) = 90; |
|
1263 view = tview; |
|
1264 |
6765
|
1265 visible = "on"; |
6705
|
1266 nextplot = "replace"; |
|
1267 |
|
1268 // FIXME -- this is not quite right; we should preserve |
|
1269 // "position" and "units". |
|
1270 |
|
1271 if (mode != "replace") |
|
1272 { |
6406
|
1273 Matrix touterposition (1, 4, 0.0); |
|
1274 touterposition(2) = 1; |
|
1275 touterposition(3) = 1; |
|
1276 outerposition = touterposition; |
|
1277 } |
|
1278 |
7363
|
1279 activepositionproperty = "outerposition"; |
|
1280 __colorbar__ = "none"; |
7189
|
1281 |
6705
|
1282 delete_children (); |
6406
|
1283 |
6705
|
1284 children = Matrix (); |
6432
|
1285 |
6705
|
1286 override_defaults (obj); |
|
1287 } |
|
1288 |
6874
|
1289 graphics_handle |
|
1290 axes::properties::get_title (void) const |
|
1291 { |
7363
|
1292 if (! title.handle_value ().ok ()) |
6874
|
1293 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1294 |
7363
|
1295 return title.handle_value (); |
6874
|
1296 } |
|
1297 |
|
1298 graphics_handle |
|
1299 axes::properties::get_xlabel (void) const |
|
1300 { |
7363
|
1301 if (! xlabel.handle_value ().ok ()) |
6874
|
1302 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1303 |
7363
|
1304 return xlabel.handle_value (); |
6874
|
1305 } |
|
1306 |
|
1307 graphics_handle |
|
1308 axes::properties::get_ylabel (void) const |
|
1309 { |
7363
|
1310 if (! ylabel.handle_value ().ok ()) |
6874
|
1311 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1312 |
7363
|
1313 return ylabel.handle_value (); |
6874
|
1314 } |
|
1315 |
|
1316 graphics_handle |
|
1317 axes::properties::get_zlabel (void) const |
|
1318 { |
7363
|
1319 if (! zlabel.handle_value ().ok ()) |
6874
|
1320 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1321 |
7363
|
1322 return zlabel.handle_value (); |
6705
|
1323 } |
6406
|
1324 |
6705
|
1325 void |
6844
|
1326 axes::properties::remove_child (const graphics_handle& h) |
6705
|
1327 { |
7363
|
1328 if (title.handle_value ().ok () && h == title.handle_value ()) |
6705
|
1329 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1330 else if (xlabel.handle_value ().ok () && h == xlabel.handle_value ()) |
6705
|
1331 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1332 else if (ylabel.handle_value ().ok () && h == ylabel.handle_value ()) |
6705
|
1333 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1334 else if (zlabel.handle_value ().ok () && h == zlabel.handle_value ()) |
6705
|
1335 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1336 else |
|
1337 base_properties::remove_child (h); |
|
1338 } |
6406
|
1339 |
6705
|
1340 void |
6844
|
1341 axes::properties::delete_children (void) |
6705
|
1342 { |
|
1343 base_properties::delete_children (); |
|
1344 |
7363
|
1345 gh_manager::free (title.handle_value ()); |
|
1346 gh_manager::free (xlabel.handle_value ()); |
|
1347 gh_manager::free (ylabel.handle_value ()); |
|
1348 gh_manager::free (zlabel.handle_value ()); |
6705
|
1349 } |
6406
|
1350 |
6836
|
1351 octave_value |
7189
|
1352 axes::get_default (const caseless_str& name) const |
6836
|
1353 { |
|
1354 octave_value retval = default_properties.lookup (name); |
|
1355 |
|
1356 if (retval.is_undefined ()) |
|
1357 { |
|
1358 graphics_handle parent = get_parent (); |
|
1359 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1360 |
|
1361 retval = parent_obj.get_default (name); |
|
1362 } |
|
1363 |
|
1364 return retval; |
|
1365 } |
|
1366 |
7222
|
1367 static void |
|
1368 check_limit_vals (double& min_val, double& max_val, double& min_pos, |
|
1369 const data_property& data) |
|
1370 { |
7267
|
1371 double val = data.min_val (); |
|
1372 if (! (xisinf (val) || xisnan (val)) && val < min_val) |
|
1373 min_val = val; |
|
1374 val = data.max_val (); |
|
1375 if (! (xisinf (val) || xisnan (val)) && val > max_val) |
|
1376 max_val = val; |
|
1377 val = data.min_pos (); |
|
1378 if (! (xisinf (val) || xisnan (val)) && val > 0 && val < min_pos) |
|
1379 min_pos = val; |
7222
|
1380 } |
|
1381 |
|
1382 // Attempt to make "nice" limits from the actual max and min of the |
|
1383 // data. For log plots, we will also use the smallest strictly positive |
|
1384 // value. |
|
1385 |
|
1386 static Matrix |
|
1387 get_axis_limits (double xmin, double xmax, double min_pos, bool logscale) |
|
1388 { |
|
1389 Matrix retval; |
|
1390 |
|
1391 double min_val = xmin; |
|
1392 double max_val = xmax; |
|
1393 |
|
1394 if (! (xisinf (min_val) || xisinf (max_val))) |
|
1395 { |
|
1396 if (logscale) |
|
1397 { |
|
1398 if (xisinf (min_pos)) |
|
1399 { |
|
1400 // warning ("axis: logscale with no positive values to plot"); |
|
1401 return retval; |
|
1402 } |
|
1403 |
|
1404 if (min_val <= 0) |
|
1405 { |
|
1406 warning ("axis: omitting nonpositive data in log plot"); |
|
1407 min_val = min_pos; |
|
1408 } |
|
1409 // FIXME -- maybe this test should also be relative? |
|
1410 if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) |
|
1411 { |
|
1412 min_val *= 0.9; |
|
1413 max_val *= 1.1; |
|
1414 } |
|
1415 min_val = pow (10, floor (log10 (min_val))); |
|
1416 max_val = pow (10, ceil (log10 (max_val))); |
|
1417 } |
|
1418 else |
|
1419 { |
|
1420 if (min_val == 0 && max_val == 0) |
|
1421 { |
|
1422 min_val = -1; |
|
1423 max_val = 1; |
|
1424 } |
|
1425 // FIXME -- maybe this test should also be relative? |
|
1426 else if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) |
|
1427 { |
|
1428 min_val -= 0.1 * std::abs (min_val); |
|
1429 max_val += 0.1 * std::abs (max_val); |
|
1430 } |
|
1431 // FIXME -- to do a better job, we should consider the tic spacing. |
|
1432 double scale = pow (10, floor (log10 (max_val - min_val) - 1)); |
|
1433 min_val = scale * floor (min_val / scale); |
|
1434 max_val = scale * ceil (max_val / scale); |
|
1435 } |
|
1436 } |
|
1437 |
|
1438 retval.resize (1, 2); |
|
1439 |
|
1440 retval(0) = min_val; |
|
1441 retval(1) = max_val; |
|
1442 |
|
1443 return retval; |
|
1444 } |
|
1445 |
|
1446 static bool updating_axis_limits = false; |
|
1447 |
7214
|
1448 void |
7222
|
1449 axes::update_axis_limits (const std::string& axis_type) |
7214
|
1450 { |
7222
|
1451 if (updating_axis_limits) |
|
1452 return; |
|
1453 |
|
1454 Matrix kids = xproperties.get_children (); |
|
1455 |
|
1456 octave_idx_type n = kids.numel (); |
|
1457 |
|
1458 double min_val = octave_Inf; |
|
1459 double max_val = -octave_Inf; |
|
1460 double min_pos = octave_Inf; |
|
1461 |
|
1462 char update_type = 0; |
|
1463 |
|
1464 Matrix limits; |
|
1465 |
|
1466 if (axis_type == "xdata" || axis_type == "xscale" |
|
1467 || axis_type == "xldata" || axis_type == "xudata" |
|
1468 || axis_type == "xlimmode") |
|
1469 { |
7363
|
1470 if (xproperties.xlimmode_is ("auto")) |
7222
|
1471 { |
|
1472 for (octave_idx_type i = 0; i < n; i++) |
|
1473 { |
|
1474 graphics_object obj = gh_manager::get_object (kids(i)); |
|
1475 |
|
1476 if (obj.isa ("line") || obj.isa ("image") |
|
1477 || obj.isa ("patch") || obj.isa ("surface")) |
|
1478 { |
7363
|
1479 data_property xdata = obj.get_xdata_property (); |
7222
|
1480 |
|
1481 check_limit_vals (min_val, max_val, min_pos, xdata); |
|
1482 |
|
1483 if (obj.isa ("line")) |
|
1484 { |
7363
|
1485 data_property xldata = obj.get_xldata_property (); |
|
1486 data_property xudata = obj.get_xudata_property (); |
7222
|
1487 |
|
1488 check_limit_vals (min_val, max_val, min_pos, xldata); |
|
1489 check_limit_vals (min_val, max_val, min_pos, xudata); |
|
1490 } |
|
1491 } |
|
1492 } |
|
1493 |
|
1494 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
1495 xproperties.xscale_is ("log")); |
7222
|
1496 |
|
1497 update_type = 'x'; |
|
1498 } |
|
1499 } |
|
1500 else if (axis_type == "ydata" || axis_type == "yscale" |
|
1501 || axis_type == "ldata" || axis_type == "udata" |
|
1502 || axis_type == "ylimmode") |
|
1503 { |
7363
|
1504 if (xproperties.ylimmode_is ("auto")) |
7222
|
1505 { |
|
1506 for (octave_idx_type i = 0; i < n; i++) |
|
1507 { |
|
1508 graphics_object obj = gh_manager::get_object (kids(i)); |
|
1509 |
|
1510 if (obj.isa ("line") || obj.isa ("image") |
|
1511 || obj.isa ("patch") || obj.isa ("surface")) |
|
1512 { |
7363
|
1513 data_property ydata = obj.get_ydata_property (); |
7222
|
1514 |
|
1515 check_limit_vals (min_val, max_val, min_pos, ydata); |
|
1516 |
|
1517 if (obj.isa ("line")) |
|
1518 { |
7363
|
1519 data_property ldata = obj.get_ldata_property (); |
|
1520 data_property udata = obj.get_udata_property (); |
7222
|
1521 |
|
1522 check_limit_vals (min_val, max_val, min_pos, ldata); |
|
1523 check_limit_vals (min_val, max_val, min_pos, udata); |
|
1524 } |
|
1525 } |
|
1526 } |
|
1527 |
|
1528 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
1529 xproperties.yscale_is ("log")); |
7222
|
1530 |
|
1531 update_type = 'y'; |
|
1532 } |
|
1533 } |
|
1534 else if (axis_type == "zdata" || axis_type == "zscale" |
|
1535 || axis_type == "zlimmode") |
|
1536 { |
7363
|
1537 if (xproperties.zlimmode_is ("auto")) |
7222
|
1538 { |
|
1539 for (octave_idx_type i = 0; i < n; i++) |
|
1540 { |
|
1541 graphics_object obj = gh_manager::get_object (kids(i)); |
|
1542 |
|
1543 if (obj.isa ("line") || obj.isa ("patch") || obj.isa ("surface")) |
|
1544 { |
7363
|
1545 data_property zdata = obj.get_zdata_property (); |
7222
|
1546 |
|
1547 check_limit_vals (min_val, max_val, min_pos, zdata); |
|
1548 } |
|
1549 } |
|
1550 |
|
1551 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
1552 xproperties.zscale_is ("log")); |
7222
|
1553 |
|
1554 update_type = 'z'; |
|
1555 } |
|
1556 } |
|
1557 else if (axis_type == "cdata" || axis_type == "climmode") |
|
1558 { |
7363
|
1559 if (xproperties.climmode_is ("auto")) |
7222
|
1560 { |
|
1561 for (octave_idx_type i = 0; i < n; i++) |
|
1562 { |
|
1563 graphics_object obj = gh_manager::get_object (kids(i)); |
|
1564 |
|
1565 if (obj.isa ("image") || obj.isa ("patch") || obj.isa ("surface")) |
|
1566 { |
7363
|
1567 data_property cdata = obj.get_cdata_property (); |
7222
|
1568 |
|
1569 check_limit_vals (min_val, max_val, min_pos, cdata); |
|
1570 } |
|
1571 } |
|
1572 |
|
1573 if (min_val == max_val) |
|
1574 max_val = min_val + 1; |
|
1575 |
|
1576 limits.resize (1, 2); |
|
1577 |
|
1578 limits(0) = min_val; |
|
1579 limits(1) = max_val; |
|
1580 |
|
1581 update_type = 'c'; |
|
1582 } |
|
1583 |
|
1584 } |
|
1585 |
|
1586 unwind_protect_bool (updating_axis_limits); |
|
1587 updating_axis_limits = true; |
|
1588 |
|
1589 switch (update_type) |
|
1590 { |
|
1591 case 'x': |
|
1592 xproperties.set_xlim (limits); |
|
1593 xproperties.set_xlimmode ("auto"); |
|
1594 break; |
|
1595 |
|
1596 case 'y': |
|
1597 xproperties.set_ylim (limits); |
|
1598 xproperties.set_ylimmode ("auto"); |
|
1599 break; |
|
1600 |
|
1601 case 'z': |
|
1602 xproperties.set_zlim (limits); |
|
1603 xproperties.set_zlimmode ("auto"); |
|
1604 break; |
|
1605 |
|
1606 case 'c': |
|
1607 xproperties.set_clim (limits); |
|
1608 xproperties.set_climmode ("auto"); |
|
1609 break; |
|
1610 |
|
1611 default: |
|
1612 break; |
|
1613 } |
|
1614 |
|
1615 unwind_protect::run (); |
7214
|
1616 } |
|
1617 |
7363
|
1618 // --------------------------------------------------------------------- |
|
1619 |
|
1620 // Note: "line" code is entirely auto-generated |
6406
|
1621 |
|
1622 // --------------------------------------------------------------------- |
|
1623 |
7363
|
1624 // Note: "text" code is entirely auto-generated |
6406
|
1625 |
|
1626 // --------------------------------------------------------------------- |
|
1627 |
7363
|
1628 // Note: "image" code is entirely auto-generated |
6406
|
1629 |
|
1630 // --------------------------------------------------------------------- |
|
1631 |
7363
|
1632 // Note: "patch" code is entirely auto-generated |
6807
|
1633 |
|
1634 // --------------------------------------------------------------------- |
|
1635 |
7363
|
1636 // Note: "surface" code is entirely auto-generated |
6406
|
1637 |
|
1638 // --------------------------------------------------------------------- |
|
1639 |
|
1640 octave_value |
7189
|
1641 base_graphics_object::get_default (const caseless_str& name) const |
6406
|
1642 { |
|
1643 graphics_handle parent = get_parent (); |
|
1644 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1645 |
|
1646 return parent_obj.get_default (type () + name); |
|
1647 } |
|
1648 |
|
1649 octave_value |
7189
|
1650 base_graphics_object::get_factory_default (const caseless_str& name) const |
6406
|
1651 { |
|
1652 graphics_object parent_obj = gh_manager::get_object (0); |
|
1653 |
|
1654 return parent_obj.get_factory_default (type () + name); |
|
1655 } |
|
1656 |
7286
|
1657 // We use a random value for the handle to avoid issues with plots and |
|
1658 // scalar values for the first argument. |
6406
|
1659 gh_manager::gh_manager (void) |
7286
|
1660 : handle_map (), handle_free_list (), |
|
1661 next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) |
6406
|
1662 { |
|
1663 handle_map[0] = graphics_object (new root_figure ()); |
|
1664 } |
|
1665 |
|
1666 graphics_handle |
|
1667 gh_manager::do_make_graphics_handle (const std::string& go_name, |
|
1668 const graphics_handle& p) |
|
1669 { |
|
1670 graphics_handle h = get_handle (go_name); |
|
1671 |
|
1672 base_graphics_object *go = 0; |
|
1673 |
|
1674 if (go_name == "figure") |
|
1675 go = new figure (h, p); |
|
1676 else if (go_name == "axes") |
|
1677 go = new axes (h, p); |
|
1678 else if (go_name == "line") |
|
1679 go = new line (h, p); |
|
1680 else if (go_name == "text") |
|
1681 go = new text (h, p); |
|
1682 else if (go_name == "image") |
|
1683 go = new image (h, p); |
6807
|
1684 else if (go_name == "patch") |
|
1685 go = new patch (h, p); |
6406
|
1686 else if (go_name == "surface") |
|
1687 go = new surface (h, p); |
|
1688 if (go) |
|
1689 handle_map[h] = graphics_object (go); |
|
1690 else |
|
1691 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
|
1692 go_name.c_str ()); |
|
1693 |
|
1694 return h; |
|
1695 } |
|
1696 |
|
1697 graphics_handle |
|
1698 gh_manager::do_make_figure_handle (double val) |
|
1699 { |
|
1700 graphics_handle h = val; |
|
1701 |
|
1702 handle_map[h] = graphics_object (new figure (h, 0)); |
|
1703 |
|
1704 return h; |
|
1705 } |
|
1706 |
|
1707 void |
|
1708 gh_manager::do_push_figure (const graphics_handle& h) |
|
1709 { |
|
1710 do_pop_figure (h); |
|
1711 |
|
1712 figure_list.push_front (h); |
|
1713 } |
|
1714 |
|
1715 void |
|
1716 gh_manager::do_pop_figure (const graphics_handle& h) |
|
1717 { |
|
1718 for (figure_list_iterator p = figure_list.begin (); |
|
1719 p != figure_list.end (); |
|
1720 p++) |
|
1721 { |
|
1722 if (*p == h) |
|
1723 { |
|
1724 figure_list.erase (p); |
|
1725 break; |
|
1726 } |
|
1727 } |
|
1728 } |
|
1729 |
|
1730 property_list::plist_map_type |
|
1731 root_figure::init_factory_properties (void) |
|
1732 { |
|
1733 property_list::plist_map_type plist_map; |
|
1734 |
6844
|
1735 plist_map["figure"] = figure::properties::factory_defaults (); |
|
1736 plist_map["axes"] = axes::properties::factory_defaults (); |
|
1737 plist_map["line"] = line::properties::factory_defaults (); |
|
1738 plist_map["text"] = text::properties::factory_defaults (); |
|
1739 plist_map["image"] = image::properties::factory_defaults (); |
|
1740 plist_map["patch"] = patch::properties::factory_defaults (); |
|
1741 plist_map["surface"] = surface::properties::factory_defaults (); |
6406
|
1742 |
|
1743 return plist_map; |
|
1744 } |
|
1745 |
|
1746 // --------------------------------------------------------------------- |
|
1747 |
|
1748 DEFUN (ishandle, args, , |
|
1749 "-*- texinfo -*-\n\ |
6678
|
1750 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406
|
1751 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
|
1752 @end deftypefn") |
|
1753 { |
|
1754 octave_value retval; |
|
1755 |
|
1756 if (args.length () == 1) |
|
1757 retval = is_handle (args(0)); |
|
1758 else |
|
1759 print_usage (); |
|
1760 |
|
1761 return retval; |
|
1762 } |
|
1763 |
|
1764 DEFUN (set, args, , |
|
1765 "-*- texinfo -*-\n\ |
6678
|
1766 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6732
|
1767 Set the named property value or vector @var{p} to the value @var{v}\n\ |
6894
|
1768 for the graphics handle @var{h}.\n\ |
6406
|
1769 @end deftypefn") |
|
1770 { |
|
1771 octave_value retval; |
|
1772 |
|
1773 int nargin = args.length (); |
|
1774 |
|
1775 if (nargin > 0) |
|
1776 { |
6732
|
1777 ColumnVector hcv (args(0).vector_value ()); |
6406
|
1778 |
|
1779 if (! error_state) |
6732
|
1780 { |
6733
|
1781 bool request_drawnow = false; |
|
1782 |
6732
|
1783 for (octave_idx_type n = 0; n < hcv.length (); n++) |
|
1784 { |
|
1785 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
1786 |
6732
|
1787 if (obj) |
|
1788 { |
|
1789 obj.set (args.splice (0, 1)); |
6406
|
1790 |
6733
|
1791 request_drawnow = true; |
6732
|
1792 } |
|
1793 else |
6733
|
1794 { |
|
1795 error ("set: invalid handle (= %g)", hcv(n)); |
|
1796 break; |
|
1797 } |
6732
|
1798 } |
6733
|
1799 |
|
1800 if (! error_state && request_drawnow) |
|
1801 feval ("__request_drawnow__"); |
6732
|
1802 } |
6406
|
1803 else |
6732
|
1804 error ("set: expecting graphics handle as first argument"); |
6406
|
1805 } |
|
1806 else |
|
1807 print_usage (); |
|
1808 |
|
1809 return retval; |
|
1810 } |
|
1811 |
|
1812 DEFUN (get, args, , |
|
1813 "-*- texinfo -*-\n\ |
6678
|
1814 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406
|
1815 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
|
1816 If @var{p} is omitted, return the complete property list for @var{h}.\n\ |
6732
|
1817 If @var{h} is a vector, return a cell array including the property\n\ |
|
1818 values or lists respectively.\n\ |
6406
|
1819 @end deftypefn") |
|
1820 { |
|
1821 octave_value retval; |
6732
|
1822 octave_value_list vlist; |
6406
|
1823 |
|
1824 int nargin = args.length (); |
|
1825 |
|
1826 if (nargin == 1 || nargin == 2) |
|
1827 { |
6732
|
1828 ColumnVector hcv (args(0).vector_value ()); |
6406
|
1829 |
|
1830 if (! error_state) |
6732
|
1831 { |
6733
|
1832 octave_idx_type len = hcv.length (); |
|
1833 |
|
1834 vlist.resize (len); |
|
1835 |
|
1836 for (octave_idx_type n = 0; n < len; n++) |
6732
|
1837 { |
|
1838 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
1839 |
6732
|
1840 if (obj) |
|
1841 { |
|
1842 if (nargin == 1) |
|
1843 vlist(n) = obj.get (); |
|
1844 else |
|
1845 { |
7189
|
1846 caseless_str property = args(1).string_value (); |
6406
|
1847 |
6732
|
1848 if (! error_state) |
|
1849 vlist(n) = obj.get (property); |
|
1850 else |
6733
|
1851 { |
|
1852 error ("get: expecting property name as second argument"); |
|
1853 break; |
|
1854 } |
6732
|
1855 } |
|
1856 } |
|
1857 else |
6733
|
1858 { |
|
1859 error ("get: invalid handle (= %g)", hcv(n)); |
|
1860 break; |
|
1861 } |
6732
|
1862 } |
|
1863 } |
6406
|
1864 else |
6732
|
1865 error ("get: expecting graphics handle as first argument"); |
6406
|
1866 } |
|
1867 else |
|
1868 print_usage (); |
|
1869 |
6733
|
1870 if (! error_state) |
6732
|
1871 { |
6733
|
1872 octave_idx_type len = vlist.length (); |
|
1873 |
|
1874 if (len > 1) |
|
1875 retval = Cell (vlist); |
|
1876 else if (len == 1) |
|
1877 retval = vlist(0); |
6732
|
1878 } |
|
1879 |
6406
|
1880 return retval; |
|
1881 } |
|
1882 |
|
1883 static octave_value |
|
1884 make_graphics_object (const std::string& go_name, |
6874
|
1885 const octave_value_list& args) |
6406
|
1886 { |
|
1887 octave_value retval; |
|
1888 |
|
1889 double val = args(0).double_value (); |
|
1890 |
|
1891 if (! error_state) |
|
1892 { |
|
1893 graphics_handle parent = gh_manager::lookup (val); |
|
1894 |
7056
|
1895 if (parent.ok ()) |
6406
|
1896 { |
|
1897 graphics_handle h |
|
1898 = gh_manager::make_graphics_handle (go_name, parent); |
|
1899 |
|
1900 if (! error_state) |
|
1901 { |
|
1902 adopt (parent, h); |
|
1903 |
|
1904 xset (h, args.splice (0, 1)); |
|
1905 |
6874
|
1906 retval = h.value (); |
7296
|
1907 |
|
1908 if (! error_state) |
|
1909 feval ("__request_drawnow__"); |
6406
|
1910 } |
|
1911 else |
|
1912 error ("__go%s__: unable to create graphics handle", |
|
1913 go_name.c_str ()); |
|
1914 } |
|
1915 else |
|
1916 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
1917 } |
|
1918 else |
|
1919 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
1920 |
|
1921 return retval; |
|
1922 } |
|
1923 |
|
1924 DEFUN (__go_figure__, args, , |
|
1925 "-*- texinfo -*-\n\ |
|
1926 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ |
6945
|
1927 Undocumented internal function.\n\ |
6406
|
1928 @end deftypefn") |
|
1929 { |
|
1930 octave_value retval; |
|
1931 |
|
1932 if (args.length () > 0) |
|
1933 { |
|
1934 double val = args(0).double_value (); |
|
1935 |
|
1936 if (! error_state) |
|
1937 { |
|
1938 if (is_figure (val)) |
|
1939 { |
|
1940 graphics_handle h = gh_manager::lookup (val); |
|
1941 |
|
1942 xset (h, args.splice (0, 1)); |
|
1943 |
6874
|
1944 retval = h.value (); |
6406
|
1945 } |
|
1946 else |
|
1947 { |
|
1948 graphics_handle h = octave_NaN; |
|
1949 |
|
1950 if (xisnan (val)) |
|
1951 h = gh_manager::make_graphics_handle ("figure", 0); |
|
1952 else if (val > 0 && D_NINT (val) == val) |
|
1953 h = gh_manager::make_figure_handle (val); |
|
1954 else |
|
1955 error ("__go_figure__: invalid figure number"); |
|
1956 |
7056
|
1957 if (! error_state && h.ok ()) |
6406
|
1958 { |
|
1959 adopt (0, h); |
|
1960 |
|
1961 xset (h, args.splice (0, 1)); |
|
1962 |
6874
|
1963 retval = h.value (); |
6406
|
1964 } |
|
1965 else |
|
1966 error ("__go_figure__: failed to create figure handle"); |
|
1967 } |
|
1968 } |
|
1969 else |
|
1970 error ("__go_figure__: expecting figure number to be double value"); |
|
1971 } |
|
1972 else |
|
1973 print_usage (); |
|
1974 |
|
1975 return retval; |
|
1976 } |
|
1977 |
|
1978 #define GO_BODY(TYPE) \ |
|
1979 octave_value retval; \ |
|
1980 \ |
|
1981 if (args.length () > 0) \ |
|
1982 retval = make_graphics_object (#TYPE, args); \ |
|
1983 else \ |
|
1984 print_usage (); \ |
|
1985 \ |
|
1986 return retval |
|
1987 |
|
1988 DEFUN (__go_axes__, args, , |
|
1989 "-*- texinfo -*-\n\ |
|
1990 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ |
6945
|
1991 Undocumented internal function.\n\ |
6406
|
1992 @end deftypefn") |
|
1993 { |
|
1994 GO_BODY (axes); |
|
1995 } |
|
1996 |
|
1997 DEFUN (__go_line__, args, , |
|
1998 "-*- texinfo -*-\n\ |
|
1999 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ |
6945
|
2000 Undocumented internal function.\n\ |
6406
|
2001 @end deftypefn") |
|
2002 { |
|
2003 GO_BODY (line); |
|
2004 } |
|
2005 |
|
2006 DEFUN (__go_text__, args, , |
|
2007 "-*- texinfo -*-\n\ |
|
2008 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ |
6945
|
2009 Undocumented internal function.\n\ |
6406
|
2010 @end deftypefn") |
|
2011 { |
|
2012 GO_BODY (text); |
|
2013 } |
|
2014 |
|
2015 DEFUN (__go_image__, args, , |
|
2016 "-*- texinfo -*-\n\ |
|
2017 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ |
6945
|
2018 Undocumented internal function.\n\ |
6406
|
2019 @end deftypefn") |
|
2020 { |
|
2021 GO_BODY (image); |
|
2022 } |
|
2023 |
|
2024 DEFUN (__go_surface__, args, , |
|
2025 "-*- texinfo -*-\n\ |
|
2026 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ |
6945
|
2027 Undocumented internal function.\n\ |
6406
|
2028 @end deftypefn") |
|
2029 { |
|
2030 GO_BODY (surface); |
|
2031 } |
|
2032 |
6807
|
2033 DEFUN (__go_patch__, args, , |
|
2034 "-*- texinfo -*-\n\ |
|
2035 @deftypefn {Built-in Function} {} __go_patch__ (@var{parent})\n\ |
6945
|
2036 Undocumented internal function.\n\ |
6807
|
2037 @end deftypefn") |
|
2038 { |
|
2039 GO_BODY (patch); |
|
2040 } |
|
2041 |
6406
|
2042 DEFUN (__go_delete__, args, , |
|
2043 "-*- texinfo -*-\n\ |
|
2044 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ |
6945
|
2045 Undocumented internal function.\n\ |
6406
|
2046 @end deftypefn") |
|
2047 { |
|
2048 octave_value_list retval; |
|
2049 |
|
2050 if (args.length () == 1) |
|
2051 { |
|
2052 graphics_handle h = octave_NaN; |
|
2053 |
|
2054 double val = args(0).double_value (); |
|
2055 |
|
2056 if (! error_state) |
|
2057 { |
|
2058 h = gh_manager::lookup (val); |
|
2059 |
7056
|
2060 if (h.ok ()) |
6406
|
2061 { |
|
2062 graphics_object obj = gh_manager::get_object (h); |
|
2063 |
|
2064 graphics_handle parent_h = obj.get_parent (); |
|
2065 |
|
2066 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
2067 |
|
2068 parent_obj.remove_child (h); |
|
2069 |
|
2070 gh_manager::free (h); |
|
2071 } |
|
2072 else |
|
2073 error ("delete: invalid graphics object (= %g)", val); |
|
2074 } |
|
2075 else |
|
2076 error ("delete: invalid graphics object"); |
|
2077 } |
|
2078 else |
|
2079 print_usage (); |
|
2080 |
|
2081 return retval; |
|
2082 } |
|
2083 |
|
2084 DEFUN (__go_axes_init__, args, , |
|
2085 "-*- texinfo -*-\n\ |
|
2086 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ |
6945
|
2087 Undocumented internal function.\n\ |
6406
|
2088 @end deftypefn") |
|
2089 { |
|
2090 octave_value retval; |
|
2091 |
|
2092 int nargin = args.length (); |
|
2093 |
|
2094 std::string mode = ""; |
|
2095 |
|
2096 if (nargin == 2) |
|
2097 { |
|
2098 mode = args(1).string_value (); |
|
2099 |
|
2100 if (error_state) |
|
2101 return retval; |
|
2102 } |
|
2103 |
|
2104 if (nargin == 1 || nargin == 2) |
|
2105 { |
|
2106 graphics_handle h = octave_NaN; |
|
2107 |
|
2108 double val = args(0).double_value (); |
|
2109 |
|
2110 if (! error_state) |
|
2111 { |
|
2112 h = gh_manager::lookup (val); |
|
2113 |
7056
|
2114 if (h.ok ()) |
6406
|
2115 { |
|
2116 graphics_object obj = gh_manager::get_object (h); |
|
2117 |
|
2118 obj.set_defaults (mode); |
|
2119 } |
|
2120 else |
|
2121 error ("__go_axes_init__: invalid graphics object (= %g)", val); |
|
2122 } |
|
2123 else |
|
2124 error ("__go_axes_init__: invalid graphics object"); |
|
2125 } |
|
2126 else |
|
2127 print_usage (); |
|
2128 |
|
2129 return retval; |
|
2130 } |
|
2131 |
|
2132 DEFUN (__go_handles__, , , |
|
2133 "-*- texinfo -*-\n\ |
|
2134 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ |
6945
|
2135 Undocumented internal function.\n\ |
6406
|
2136 @end deftypefn") |
|
2137 { |
6425
|
2138 return octave_value (gh_manager::handle_list ()); |
|
2139 } |
|
2140 |
|
2141 DEFUN (__go_figure_handles__, , , |
|
2142 "-*- texinfo -*-\n\ |
|
2143 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ |
6945
|
2144 Undocumented internal function.\n\ |
6425
|
2145 @end deftypefn") |
|
2146 { |
|
2147 return octave_value (gh_manager::figure_handle_list ()); |
6406
|
2148 } |
|
2149 |
6595
|
2150 octave_value |
|
2151 get_property_from_handle (double handle, const std::string &property, |
|
2152 const std::string &func) |
|
2153 { |
|
2154 graphics_object obj = gh_manager::get_object (handle); |
|
2155 octave_value retval; |
|
2156 |
|
2157 if (obj) |
|
2158 { |
7189
|
2159 caseless_str p = std::string (property); |
6595
|
2160 retval = obj.get (p); |
|
2161 } |
|
2162 else |
|
2163 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2164 |
|
2165 return retval; |
|
2166 } |
|
2167 |
|
2168 bool |
|
2169 set_property_in_handle (double handle, const std::string &property, |
|
2170 const octave_value &arg, const std::string &func) |
|
2171 { |
|
2172 graphics_object obj = gh_manager::get_object (handle); |
|
2173 int ret = false; |
|
2174 |
|
2175 if (obj) |
|
2176 { |
7189
|
2177 caseless_str p = std::string (property); |
6595
|
2178 obj.set (p, arg); |
|
2179 if (!error_state) |
|
2180 ret = true; |
|
2181 } |
|
2182 else |
|
2183 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
2184 |
|
2185 return ret; |
|
2186 } |
|
2187 |
6406
|
2188 /* |
|
2189 ;;; Local Variables: *** |
|
2190 ;;; mode: C++ *** |
|
2191 ;;; End: *** |
|
2192 */ |