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