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