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