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