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 |
7409
|
37 #include "file-ops.h" |
|
38 #include "file-stat.h" |
|
39 |
6705
|
40 #include "defun.h" |
|
41 #include "error.h" |
6595
|
42 #include "graphics.h" |
7409
|
43 #include "input.h" |
6705
|
44 #include "ov.h" |
|
45 #include "oct-obj.h" |
|
46 #include "oct-map.h" |
|
47 #include "ov-fcn-handle.h" |
|
48 #include "parse.h" |
7409
|
49 #include "toplev.h" |
7222
|
50 #include "unwind-prot.h" |
6595
|
51 |
6406
|
52 static void |
|
53 gripe_set_invalid (const std::string& pname) |
|
54 { |
|
55 error ("set: invalid value for %s property", pname.c_str ()); |
|
56 } |
|
57 |
7363
|
58 static Matrix |
|
59 jet_colormap (void) |
|
60 { |
|
61 Matrix cmap (64, 3, 0.0); |
|
62 |
|
63 for (octave_idx_type i = 0; i < 64; i++) |
|
64 { |
|
65 // This is the jet colormap. It would be nice to be able |
|
66 // to feval the jet function but since there is a static |
|
67 // property object that includes a colormap_property |
|
68 // object, we need to initialize this before main is even |
|
69 // called, so calling an interpreted function is not |
|
70 // possible. |
|
71 |
|
72 double x = i / 63.0; |
|
73 |
|
74 if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
75 cmap(i,0) = 4.0 * x - 3.0/2.0; |
|
76 else if (x >= 5.0/8.0 && x < 7.0/8.0) |
|
77 cmap(i,0) = 1.0; |
|
78 else if (x >= 7.0/8.0) |
|
79 cmap(i,0) = -4.0 * x + 9.0/2.0; |
|
80 |
|
81 if (x >= 1.0/8.0 && x < 3.0/8.0) |
|
82 cmap(i,1) = 4.0 * x - 1.0/2.0; |
|
83 else if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
84 cmap(i,1) = 1.0; |
|
85 else if (x >= 5.0/8.0 && x < 7.0/8.0) |
|
86 cmap(i,1) = -4.0 * x + 7.0/2.0; |
|
87 |
|
88 if (x < 1.0/8.0) |
|
89 cmap(i,2) = 4.0 * x + 1.0/2.0; |
|
90 else if (x >= 1.0/8.0 && x < 3.0/8.0) |
|
91 cmap(i,2) = 1.0; |
|
92 else if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
93 cmap(i,2) = -4.0 * x + 5.0/2.0; |
|
94 } |
|
95 |
|
96 return cmap; |
|
97 } |
|
98 |
|
99 static Matrix |
|
100 default_colororder (void) |
|
101 { |
|
102 Matrix retval (7, 3, 0.0); |
|
103 |
|
104 retval(0,2) = 1.0; |
|
105 |
|
106 retval(1,1) = 0.5; |
|
107 |
|
108 retval(2,0) = 1.0; |
|
109 |
|
110 retval(3,1) = 0.75; |
|
111 retval(3,2) = 0.75; |
|
112 |
|
113 retval(4,0) = 0.75; |
|
114 retval(4,2) = 0.75; |
|
115 |
|
116 retval(5,0) = 0.75; |
|
117 retval(5,1) = 0.75; |
|
118 |
|
119 retval(6,0) = 0.25; |
|
120 retval(6,1) = 0.25; |
|
121 retval(6,2) = 0.25; |
|
122 |
|
123 return retval; |
|
124 } |
|
125 |
|
126 static Matrix |
|
127 default_lim (void) |
|
128 { |
|
129 Matrix m (1, 2, 0); |
|
130 m(1) = 1; |
|
131 return m; |
|
132 } |
|
133 |
|
134 static Matrix |
|
135 default_data (void) |
|
136 { |
|
137 Matrix retval (1, 2); |
|
138 |
|
139 retval(0) = 0; |
|
140 retval(1) = 1; |
|
141 |
|
142 return retval; |
|
143 } |
|
144 |
7427
|
145 static Matrix |
|
146 default_axes_position (void) |
|
147 { |
|
148 Matrix m (1, 4, 0.0); |
|
149 m(0) = 0.13; |
|
150 m(1) = 0.11; |
|
151 m(2) = 0.775; |
|
152 m(3) = 0.815; |
|
153 return m; |
|
154 } |
|
155 |
|
156 static Matrix |
|
157 default_axes_outerposition (void) |
|
158 { |
|
159 Matrix m (1, 4, 0.0); |
|
160 m(2) = m(3) = 1.0; |
|
161 return m; |
|
162 } |
|
163 |
7445
|
164 static Matrix |
|
165 default_figure_position (void) |
|
166 { |
|
167 Matrix m (1, 4, 0.0); |
|
168 m(0) = 300; |
|
169 m(1) = 200; |
|
170 m(2) = 560; |
|
171 m(3) = 420; |
|
172 return m; |
|
173 } |
|
174 |
7367
|
175 // NOTE: "cb" is passed by value, because "function_value" method |
|
176 // is non-const; passing "cb" by const-reference is not |
|
177 // possible |
|
178 |
|
179 static void |
|
180 execute_callback (octave_value cb, const graphics_handle& h, |
|
181 const octave_value& data) |
|
182 { |
|
183 octave_value_list args; |
|
184 octave_function *fcn = 0; |
|
185 |
|
186 args(0) = h.as_octave_value (); |
|
187 args(1) = data; |
|
188 |
|
189 BEGIN_INTERRUPT_WITH_EXCEPTIONS; |
|
190 |
|
191 if (cb.is_function_handle ()) |
|
192 fcn = cb.function_value (); |
|
193 else if (cb.is_string ()) |
|
194 { |
|
195 std::string s = cb.string_value (); |
|
196 octave_value f = symbol_table::find_function (s); |
|
197 int status; |
|
198 |
|
199 if (f.is_defined ()) |
|
200 fcn = f.function_value (); |
|
201 else |
|
202 { |
|
203 eval_string (s, false, status); |
|
204 return; |
|
205 } |
|
206 } |
|
207 else if (cb.is_cell () && cb.length () > 0 |
|
208 && (cb.rows () == 1 || cb.columns () == 1) |
|
209 && cb.cell_value ()(0).is_function_handle ()) |
|
210 { |
|
211 Cell c = cb.cell_value (); |
|
212 |
|
213 fcn = c(0).function_value (); |
|
214 if (! error_state) |
|
215 { |
|
216 for (int i = 0; i < c.length () ; i++) |
|
217 args(2+i) = c(i); |
|
218 } |
|
219 } |
|
220 else |
7373
|
221 { |
|
222 std::string nm = cb.class_name (); |
|
223 error ("trying to execute non-executable object (class = %s)", |
|
224 nm.c_str ()); |
|
225 } |
7367
|
226 |
|
227 if (! error_state) |
|
228 feval (fcn, args); |
|
229 |
|
230 END_INTERRUPT_WITH_EXCEPTIONS; |
|
231 } |
|
232 |
7427
|
233 static Matrix |
|
234 convert_position (const Matrix& pos, const caseless_str& from_units, |
|
235 const caseless_str& to_units, |
|
236 const Matrix& parent_dim = Matrix (1, 2, 0.0), |
|
237 const graphics_backend& backend = graphics_backend ()) |
|
238 { |
|
239 Matrix retval (1, 4); |
|
240 double res = 0; |
|
241 |
|
242 if (from_units.compare ("pixels")) |
|
243 retval = pos; |
|
244 else if (from_units.compare ("normalized")) |
|
245 { |
|
246 retval(0) = pos(0) * parent_dim(0) + 1; |
|
247 retval(1) = pos(1) * parent_dim(1) + 1; |
|
248 retval(2) = pos(2) * parent_dim(0); |
|
249 retval(3) = pos(3) * parent_dim(1); |
|
250 } |
|
251 else if (from_units.compare ("characters")) |
|
252 { |
|
253 // FIXME: implement this |
|
254 } |
|
255 else |
|
256 { |
|
257 res = backend.get_screen_resolution (); |
|
258 |
|
259 double f = 0.0; |
|
260 |
|
261 if (from_units.compare ("points")) |
|
262 f = res / 72.0; |
|
263 else if (from_units.compare ("inches")) |
|
264 f = res; |
|
265 else if (from_units.compare ("centimeters")) |
|
266 f = res / 2.54; |
|
267 |
|
268 if (f > 0) |
|
269 { |
|
270 retval(0) = pos(0) * f + 1; |
|
271 retval(1) = pos(1) * f + 1; |
|
272 retval(2) = pos(2) * f; |
|
273 retval(3) = pos(3) * f; |
|
274 } |
|
275 } |
|
276 |
|
277 if (! to_units.compare ("pixels")) |
|
278 { |
|
279 if (to_units.compare ("normalized")) |
|
280 { |
|
281 retval(0) = (retval(0) - 1) / parent_dim(0); |
|
282 retval(1) = (retval(1) - 1) / parent_dim(1); |
|
283 retval(2) /= parent_dim(0); |
|
284 retval(3) /= parent_dim(1); |
|
285 } |
|
286 else if (to_units.compare ("characters")) |
|
287 { |
|
288 // FIXME: implement this |
|
289 } |
|
290 else |
|
291 { |
|
292 if (res <= 0) |
|
293 res = backend.get_screen_resolution (); |
|
294 |
|
295 double f = 0.0; |
|
296 |
|
297 if (to_units.compare ("points")) |
|
298 f = res / 72.0; |
|
299 else if (to_units.compare ("inches")) |
|
300 f = res; |
|
301 else if (to_units.compare ("centimeters")) |
|
302 f = res / 2.54; |
|
303 |
|
304 if (f > 0) |
|
305 { |
|
306 retval(0) = (retval(0) - 1) / f; |
|
307 retval(1) = (retval(1) - 1) / f; |
|
308 retval(2) /= f; |
|
309 retval(3) /= f; |
|
310 } |
|
311 } |
|
312 } |
|
313 |
|
314 return retval; |
|
315 } |
|
316 |
6406
|
317 // --------------------------------------------------------------------- |
|
318 |
6705
|
319 radio_values::radio_values (const std::string& opt_string) |
6406
|
320 { |
6705
|
321 size_t beg = 0; |
|
322 size_t len = opt_string.length (); |
|
323 bool done = len == 0; |
6681
|
324 |
6705
|
325 while (! done) |
|
326 { |
|
327 size_t end = opt_string.find ('|', beg); |
6681
|
328 |
6705
|
329 if (end == std::string::npos) |
|
330 { |
|
331 end = len; |
|
332 done = true; |
|
333 } |
6681
|
334 |
6705
|
335 std::string t = opt_string.substr (beg, end-beg); |
6681
|
336 |
6705
|
337 // Might want more error checking here... |
|
338 if (t[0] == '{') |
|
339 { |
|
340 t = t.substr (1, t.length () - 2); |
|
341 default_val = t; |
|
342 } |
|
343 else if (beg == 0) // ensure default value |
|
344 default_val = t; |
6681
|
345 |
6705
|
346 possible_vals.insert (t); |
6681
|
347 |
6705
|
348 beg = end + 1; |
|
349 } |
|
350 } |
6681
|
351 |
6705
|
352 bool |
6761
|
353 color_values::str2rgb (std::string str) |
6681
|
354 { |
6705
|
355 double tmp_rgb[3] = {0, 0, 0}; |
|
356 bool retval = true; |
6761
|
357 unsigned int len = str.length(); |
6681
|
358 |
6925
|
359 std::transform (str.begin (), str.end (), str.begin (), tolower); |
|
360 |
6761
|
361 if (str.compare(0, len, "blue", 0, len) == 0) |
|
362 tmp_rgb[2] = 1; |
6925
|
363 else if (str.compare(0, len, "black", 0, len) == 0 || |
|
364 str.compare(0, len, "k", 0, len) == 0) |
6761
|
365 tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 0; |
|
366 else if (str.compare(0, len, "red", 0, len) == 0) |
|
367 tmp_rgb[0] = 1; |
|
368 else if (str.compare(0, len, "green", 0, len) == 0) |
|
369 tmp_rgb[1] = 1; |
|
370 else if (str.compare(0, len, "yellow", 0, len) == 0) |
|
371 tmp_rgb[0] = tmp_rgb[1] = 1; |
|
372 else if (str.compare(0, len, "magenta", 0, len) == 0) |
|
373 tmp_rgb[0] = tmp_rgb[2] = 1; |
|
374 else if (str.compare(0, len, "cyan", 0, len) == 0) |
|
375 tmp_rgb[1] = tmp_rgb[2] = 1; |
6925
|
376 else if (str.compare(0, len, "white", 0, len) == 0 || |
|
377 str.compare(0, len, "w", 0, len) == 0) |
6761
|
378 tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 1; |
|
379 else |
|
380 retval = false; |
6406
|
381 |
6705
|
382 if (retval) |
|
383 { |
|
384 for (int i = 0; i < 3; i++) |
7363
|
385 xrgb(i) = tmp_rgb[i]; |
6705
|
386 } |
6563
|
387 |
6705
|
388 return retval; |
|
389 } |
6681
|
390 |
7363
|
391 void |
|
392 color_property::set (const octave_value& val) |
6790
|
393 { |
|
394 if (val.is_string ()) |
|
395 { |
|
396 std::string s = val.string_value (); |
|
397 |
|
398 if (! s.empty ()) |
|
399 { |
6898
|
400 if (radio_val.contains (s)) |
6790
|
401 { |
|
402 current_val = s; |
|
403 current_type = radio_t; |
|
404 } |
|
405 else |
|
406 { |
|
407 color_values col (s); |
|
408 if (! error_state) |
|
409 { |
|
410 color_val = col; |
|
411 current_type = color_t; |
|
412 } |
|
413 else |
7363
|
414 error ("invalid value for color property \"%s\" (value = %s)", |
|
415 get_name ().c_str (), s.c_str ()); |
6790
|
416 } |
|
417 } |
|
418 else |
7363
|
419 error ("invalid value for color property \"%s\"", |
|
420 get_name ().c_str ()); |
6790
|
421 } |
|
422 else if (val.is_real_matrix ()) |
|
423 { |
|
424 Matrix m = val.matrix_value (); |
|
425 |
|
426 if (m.numel () == 3) |
|
427 { |
|
428 color_values col (m (0), m (1), m(2)); |
|
429 if (! error_state) |
|
430 { |
|
431 color_val = col; |
|
432 current_type = color_t; |
|
433 } |
|
434 } |
|
435 else |
7363
|
436 error ("invalid value for color property \"%s\"", |
|
437 get_name ().c_str ()); |
6790
|
438 } |
|
439 else |
7363
|
440 error ("invalid value for color property \"%s\"", |
|
441 get_name ().c_str ()); |
6790
|
442 } |
|
443 |
7363
|
444 bool |
|
445 array_property::validate (const octave_value& v) |
|
446 { |
7364
|
447 bool xok = false; |
7363
|
448 |
|
449 // FIXME: should we always support []? |
|
450 if (v.is_empty () && v.is_double_type ()) |
|
451 return true; |
|
452 |
|
453 // check value type |
|
454 if (type_constraints.size () > 0) |
|
455 { |
|
456 for (std::list<std::string>::const_iterator it = type_constraints.begin (); |
7364
|
457 ! xok && it != type_constraints.end (); ++it) |
7363
|
458 if ((*it) == v.type_name ()) |
7364
|
459 xok = true; |
7363
|
460 } |
|
461 else |
7364
|
462 xok = v.is_double_type (); |
7363
|
463 |
7364
|
464 if (xok) |
7363
|
465 { |
|
466 dim_vector vdims = v.dims (); |
|
467 int vlen = vdims.length (); |
|
468 |
7364
|
469 xok = false; |
7363
|
470 |
|
471 // check value size |
|
472 if (size_constraints.size () > 0) |
|
473 for (std::list<dim_vector>::const_iterator it = size_constraints.begin (); |
7364
|
474 ! xok && it != size_constraints.end (); ++it) |
7363
|
475 { |
|
476 dim_vector itdims = (*it); |
|
477 |
|
478 if (itdims.length () == vlen) |
|
479 { |
7364
|
480 xok = true; |
7363
|
481 |
7364
|
482 for (int i = 0; xok && i < vlen; i++) |
7363
|
483 if (itdims(i) >= 0 && itdims(i) != vdims(i)) |
7364
|
484 xok = false; |
7363
|
485 } |
|
486 } |
|
487 else |
|
488 return true; |
|
489 } |
|
490 |
7364
|
491 return xok; |
7363
|
492 } |
|
493 |
|
494 void |
|
495 handle_property::set (const octave_value& v) |
|
496 { |
|
497 double dv = v.double_value (); |
|
498 |
|
499 if (! error_state) |
|
500 { |
|
501 graphics_handle gh = gh_manager::lookup (dv); |
|
502 |
|
503 if (xisnan (gh.value ()) || gh.ok ()) |
|
504 current_val = gh; |
|
505 else |
|
506 error ("set: invalid graphics handle (= %g) for property \"%s\"", |
|
507 dv, get_name ().c_str ()); |
|
508 } |
|
509 else |
|
510 error ("set: invalid graphics handle for property \"%s\"", |
|
511 get_name ().c_str ()); |
|
512 } |
|
513 |
|
514 bool |
7367
|
515 callback_property::validate (const octave_value& v) const |
7363
|
516 { |
7367
|
517 // case 1: function handle |
|
518 // case 2: cell array with first element being a function handle |
|
519 // case 3: string corresponding to known function name |
|
520 // case 4: evaluatable string |
|
521 // case 5: empty matrix |
|
522 |
|
523 if (v.is_function_handle ()) |
|
524 return true; |
|
525 else if (v.is_string ()) |
|
526 // complete validation will be done at execution-time |
|
527 return true; |
|
528 else if (v.is_cell () && v.length () > 0 |
|
529 && (v.rows() == 1 || v.columns () == 1) |
|
530 && v.cell_value ()(0).is_function_handle ()) |
|
531 return true; |
|
532 else if (v.is_empty ()) |
|
533 return true; |
|
534 |
|
535 return false; |
7363
|
536 } |
|
537 |
|
538 void |
7367
|
539 callback_property::execute (const octave_value& data) const |
7363
|
540 { |
7367
|
541 if (callback.is_defined () && ! callback.is_empty ()) |
|
542 execute_callback (callback, get_parent (), data); |
7363
|
543 } |
|
544 |
|
545 // --------------------------------------------------------------------- |
6681
|
546 |
6705
|
547 void |
7189
|
548 property_list::set (const caseless_str& name, const octave_value& val) |
6681
|
549 { |
6705
|
550 size_t offset = 0; |
6681
|
551 |
6705
|
552 size_t len = name.length (); |
6681
|
553 |
6705
|
554 if (len > 4) |
|
555 { |
7189
|
556 caseless_str pfx = name.substr (0, 4); |
6681
|
557 |
6705
|
558 if (pfx.compare ("axes") || pfx.compare ("line") |
|
559 || pfx.compare ("text")) |
|
560 offset = 4; |
|
561 else if (len > 5) |
|
562 { |
|
563 pfx = name.substr (0, 5); |
6681
|
564 |
6807
|
565 if (pfx.compare ("image") || pfx.compare ("patch")) |
6705
|
566 offset = 5; |
|
567 else if (len > 6) |
|
568 { |
|
569 pfx = name.substr (0, 6); |
6681
|
570 |
6705
|
571 if (pfx.compare ("figure")) |
|
572 offset = 6; |
|
573 else if (len > 7) |
|
574 { |
|
575 pfx = name.substr (0, 7); |
6681
|
576 |
6705
|
577 if (pfx.compare ("surface")) |
|
578 offset = 7; |
|
579 } |
|
580 } |
|
581 } |
6681
|
582 |
6705
|
583 if (offset > 0) |
|
584 { |
|
585 // FIXME -- should we validate property names and values here? |
6406
|
586 |
6705
|
587 std::string pname = name.substr (offset); |
6406
|
588 |
6705
|
589 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
|
590 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); |
6406
|
591 |
6705
|
592 bool remove = false; |
|
593 if (val.is_string ()) |
|
594 { |
7189
|
595 caseless_str tval = val.string_value (); |
6406
|
596 |
6705
|
597 remove = tval.compare ("remove"); |
|
598 } |
6406
|
599 |
6705
|
600 pval_map_type& pval_map = plist_map[pfx]; |
6406
|
601 |
6705
|
602 if (remove) |
|
603 { |
|
604 pval_map_iterator p = pval_map.find (pname); |
6406
|
605 |
6705
|
606 if (p != pval_map.end ()) |
|
607 pval_map.erase (p); |
|
608 } |
|
609 else |
|
610 pval_map[pname] = val; |
|
611 } |
|
612 } |
6406
|
613 |
6705
|
614 if (offset == 0) |
|
615 error ("invalid default property specification"); |
|
616 } |
6406
|
617 |
6705
|
618 octave_value |
7189
|
619 property_list::lookup (const caseless_str& name) const |
6705
|
620 { |
|
621 octave_value retval; |
6406
|
622 |
6705
|
623 size_t offset = 0; |
6406
|
624 |
6705
|
625 size_t len = name.length (); |
6406
|
626 |
6705
|
627 if (len > 4) |
|
628 { |
7189
|
629 caseless_str pfx = name.substr (0, 4); |
6406
|
630 |
6705
|
631 if (pfx.compare ("axes") || pfx.compare ("line") |
|
632 || pfx.compare ("text")) |
|
633 offset = 4; |
|
634 else if (len > 5) |
|
635 { |
|
636 pfx = name.substr (0, 5); |
6406
|
637 |
6807
|
638 if (pfx.compare ("image") || pfx.compare ("patch")) |
6705
|
639 offset = 5; |
|
640 else if (len > 6) |
|
641 { |
|
642 pfx = name.substr (0, 6); |
6406
|
643 |
6705
|
644 if (pfx.compare ("figure")) |
|
645 offset = 6; |
|
646 else if (len > 7) |
|
647 { |
|
648 pfx = name.substr (0, 7); |
6406
|
649 |
6705
|
650 if (pfx.compare ("surface")) |
|
651 offset = 7; |
|
652 } |
|
653 } |
|
654 } |
6406
|
655 |
6705
|
656 if (offset > 0) |
|
657 { |
|
658 std::string pname = name.substr (offset); |
6406
|
659 |
6705
|
660 std::transform (pfx.begin (), pfx.end (), pfx.begin (), tolower); |
|
661 std::transform (pname.begin (), pname.end (), pname.begin (), tolower); |
6406
|
662 |
6705
|
663 plist_map_const_iterator p = find (pfx); |
6432
|
664 |
6705
|
665 if (p != end ()) |
|
666 { |
|
667 const pval_map_type& pval_map = p->second; |
6406
|
668 |
6705
|
669 pval_map_const_iterator q = pval_map.find (pname); |
6406
|
670 |
6705
|
671 if (q != pval_map.end ()) |
|
672 retval = q->second; |
|
673 } |
|
674 } |
|
675 } |
6406
|
676 |
6705
|
677 return retval; |
|
678 } |
6406
|
679 |
6705
|
680 Octave_map |
|
681 property_list::as_struct (const std::string& prefix_arg) const |
|
682 { |
|
683 Octave_map m; |
6406
|
684 |
6705
|
685 for (plist_map_const_iterator p = begin (); p != end (); p++) |
|
686 { |
|
687 std::string prefix = prefix_arg + p->first; |
6406
|
688 |
6705
|
689 const pval_map_type pval_map = p->second; |
6406
|
690 |
6705
|
691 for (pval_map_const_iterator q = pval_map.begin (); |
|
692 q != pval_map.end (); |
|
693 q++) |
|
694 m.assign (prefix + q->first, q->second); |
|
695 } |
6406
|
696 |
6705
|
697 return m; |
|
698 } |
6432
|
699 |
6874
|
700 graphics_handle::graphics_handle (const octave_value& a) |
|
701 : val (octave_NaN) |
|
702 { |
|
703 if (a.is_empty ()) |
|
704 /* do nothing */; |
|
705 else |
|
706 { |
|
707 double tval = a.double_value (); |
|
708 |
|
709 if (! error_state) |
|
710 val = tval; |
|
711 else |
|
712 error ("invalid graphics handle"); |
|
713 } |
|
714 } |
|
715 |
6705
|
716 void |
|
717 graphics_object::set (const octave_value_list& args) |
|
718 { |
|
719 int nargin = args.length (); |
6406
|
720 |
6705
|
721 if (nargin == 0) |
|
722 rep->defaults (); |
|
723 else if (nargin % 2 == 0) |
|
724 { |
|
725 for (int i = 0; i < nargin; i += 2) |
|
726 { |
7189
|
727 caseless_str name = args(i).string_value (); |
6406
|
728 |
6705
|
729 if (! error_state) |
|
730 { |
|
731 octave_value val = args(i+1); |
6406
|
732 |
6705
|
733 if (val.is_string ()) |
|
734 { |
7189
|
735 caseless_str tval = val.string_value (); |
6406
|
736 |
6705
|
737 if (tval.compare ("default")) |
|
738 val = get_default (name); |
|
739 else if (tval.compare ("factory")) |
|
740 val = get_factory_default (name); |
|
741 } |
6406
|
742 |
6705
|
743 if (error_state) |
|
744 break; |
6406
|
745 |
6705
|
746 rep->set (name, val); |
|
747 } |
|
748 else |
|
749 error ("set: expecting argument %d to be a property name", i); |
|
750 } |
|
751 } |
|
752 else |
|
753 error ("set: invalid number of arguments"); |
|
754 } |
6406
|
755 |
|
756 |
6705
|
757 graphics_handle |
|
758 gh_manager::get_handle (const std::string& go_name) |
|
759 { |
|
760 graphics_handle retval; |
6406
|
761 |
6705
|
762 if (go_name == "figure") |
|
763 { |
|
764 // We always want the lowest unused figure number. |
6406
|
765 |
6705
|
766 retval = 1; |
6425
|
767 |
6705
|
768 while (handle_map.find (retval) != handle_map.end ()) |
|
769 retval++; |
|
770 } |
|
771 else |
|
772 { |
|
773 free_list_iterator p = handle_free_list.begin (); |
6406
|
774 |
6705
|
775 if (p != handle_free_list.end ()) |
|
776 { |
|
777 retval = *p; |
|
778 handle_free_list.erase (p); |
|
779 } |
|
780 else |
7286
|
781 { |
|
782 static double maxrand = RAND_MAX + 2.0; |
|
783 |
|
784 retval = graphics_handle (next_handle); |
|
785 |
7304
|
786 next_handle = ceil (next_handle) - 1.0 - (rand () + 1.0) / maxrand; |
7286
|
787 } |
6705
|
788 } |
6406
|
789 |
6705
|
790 return retval; |
|
791 } |
6406
|
792 |
6705
|
793 void |
|
794 gh_manager::do_free (const graphics_handle& h) |
|
795 { |
7056
|
796 if (h.ok ()) |
6705
|
797 { |
6874
|
798 if (h.value () != 0) |
6705
|
799 { |
6874
|
800 iterator p = handle_map.find (h); |
|
801 |
|
802 if (p != handle_map.end ()) |
|
803 { |
7403
|
804 p->second.get_properties ().set_beingdeleted (true); |
|
805 p->second.get_properties ().execute_deletefcn (); |
7367
|
806 |
6874
|
807 handle_map.erase (p); |
|
808 |
|
809 if (h.value () < 0) |
|
810 handle_free_list.insert (h); |
|
811 } |
|
812 else |
|
813 error ("graphics_handle::free: invalid object %g", h.value ()); |
6705
|
814 } |
|
815 else |
6874
|
816 error ("graphics_handle::free: can't delete root figure"); |
6705
|
817 } |
|
818 } |
6406
|
819 |
|
820 gh_manager *gh_manager::instance = 0; |
|
821 |
|
822 static void |
7189
|
823 xset (const graphics_handle& h, const caseless_str& name, |
6406
|
824 const octave_value& val) |
|
825 { |
|
826 graphics_object obj = gh_manager::get_object (h); |
|
827 obj.set (name, val); |
|
828 } |
|
829 |
|
830 static void |
|
831 xset (const graphics_handle& h, const octave_value_list& args) |
|
832 { |
|
833 if (args.length () > 0) |
|
834 { |
|
835 graphics_object obj = gh_manager::get_object (h); |
|
836 obj.set (args); |
|
837 } |
|
838 } |
|
839 |
|
840 |
|
841 static octave_value |
7189
|
842 xget (const graphics_handle& h, const caseless_str& name) |
6406
|
843 { |
|
844 graphics_object obj = gh_manager::get_object (h); |
|
845 return obj.get (name); |
|
846 } |
|
847 |
|
848 static graphics_handle |
|
849 reparent (const octave_value& ov, const std::string& who, |
|
850 const std::string& property, const graphics_handle& new_parent, |
|
851 bool adopt = true) |
|
852 { |
|
853 graphics_handle h = octave_NaN; |
|
854 |
|
855 double val = ov.double_value (); |
|
856 |
|
857 if (! error_state) |
|
858 { |
|
859 h = gh_manager::lookup (val); |
|
860 |
7056
|
861 if (h.ok ()) |
6406
|
862 { |
|
863 graphics_object obj = gh_manager::get_object (h); |
|
864 |
|
865 graphics_handle parent_h = obj.get_parent (); |
|
866 |
|
867 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
868 |
|
869 parent_obj.remove_child (h); |
|
870 |
|
871 if (adopt) |
6874
|
872 obj.set ("parent", new_parent.value ()); |
6406
|
873 else |
|
874 obj.reparent (new_parent); |
|
875 } |
|
876 else |
|
877 error ("%s: invalid graphics handle (= %g) for %s", |
|
878 who.c_str (), val, property.c_str ()); |
|
879 } |
|
880 else |
|
881 error ("%s: expecting %s to be a graphics handle", |
|
882 who.c_str (), property.c_str ()); |
|
883 |
|
884 return h; |
|
885 } |
|
886 |
|
887 // This function is NOT equivalent to the scripting language function gcf. |
|
888 graphics_handle |
|
889 gcf (void) |
|
890 { |
|
891 octave_value val = xget (0, "currentfigure"); |
|
892 |
|
893 return val.is_empty () ? octave_NaN : val.double_value (); |
|
894 } |
|
895 |
|
896 // This function is NOT equivalent to the scripting language function gca. |
|
897 graphics_handle |
|
898 gca (void) |
|
899 { |
|
900 octave_value val = xget (gcf (), "currentaxes"); |
|
901 |
|
902 return val.is_empty () ? octave_NaN : val.double_value (); |
|
903 } |
|
904 |
|
905 static void |
|
906 adopt (const graphics_handle& p, const graphics_handle& h) |
|
907 { |
|
908 graphics_object parent_obj = gh_manager::get_object (p); |
|
909 |
|
910 parent_obj.adopt (h); |
|
911 } |
|
912 |
|
913 static bool |
7056
|
914 is_handle (const graphics_handle& h) |
|
915 { |
|
916 return h.ok (); |
|
917 } |
|
918 |
|
919 static bool |
6406
|
920 is_handle (double val) |
|
921 { |
6874
|
922 graphics_handle h = gh_manager::lookup (val); |
|
923 |
|
924 return h.ok (); |
6406
|
925 } |
|
926 |
|
927 static bool |
|
928 is_handle (const octave_value& val) |
|
929 { |
7142
|
930 return val.is_real_scalar () && is_handle (val.double_value ()); |
6406
|
931 } |
|
932 |
|
933 static bool |
|
934 is_figure (double val) |
|
935 { |
|
936 graphics_object obj = gh_manager::get_object (val); |
|
937 |
|
938 return obj && obj.isa ("figure"); |
|
939 } |
|
940 |
7370
|
941 static void |
|
942 xcreatefcn (const graphics_handle& h) |
|
943 { |
|
944 graphics_object obj = gh_manager::get_object (h); |
|
945 obj.get_properties ().execute_createfcn (); |
|
946 } |
|
947 |
6406
|
948 // --------------------------------------------------------------------- |
|
949 |
|
950 static int |
|
951 compare (const void *a_arg, const void *b_arg) |
|
952 { |
|
953 double a = *(static_cast<const double *> (a_arg)); |
|
954 double b = *(static_cast<const double *> (b_arg)); |
|
955 |
|
956 return a > b ? 1 : (a < b) ? -1 : 0; |
|
957 } |
|
958 |
|
959 static Matrix |
|
960 maybe_set_children (const Matrix& kids, const octave_value& val) |
|
961 { |
|
962 const Matrix new_kids = val.matrix_value (); |
|
963 |
|
964 bool ok = true; |
|
965 |
|
966 if (! error_state) |
|
967 { |
|
968 if (kids.numel () == new_kids.numel ()) |
|
969 { |
|
970 Matrix t1 = kids; |
|
971 Matrix t2 = new_kids; |
|
972 |
|
973 t1.qsort (compare); |
|
974 t2.qsort (compare); |
|
975 |
|
976 if (t1 != t2) |
|
977 ok = false; |
|
978 } else |
|
979 ok = false; |
|
980 |
|
981 if (! ok) |
|
982 error ("set: new children must be a permutation of existing children"); |
|
983 } |
|
984 else |
|
985 { |
|
986 ok = false; |
|
987 error ("set: expecting children to be array of graphics handles"); |
|
988 } |
|
989 |
|
990 return ok ? new_kids : kids; |
|
991 } |
|
992 |
6705
|
993 void |
|
994 base_properties::set_from_list (base_graphics_object& obj, |
|
995 property_list& defaults) |
6406
|
996 { |
6705
|
997 std::string go_name = graphics_object_name (); |
6406
|
998 |
6705
|
999 property_list::plist_map_const_iterator p = defaults.find (go_name); |
6406
|
1000 |
6705
|
1001 if (p != defaults.end ()) |
|
1002 { |
|
1003 const property_list::pval_map_type pval_map = p->second; |
6406
|
1004 |
6705
|
1005 for (property_list::pval_map_const_iterator q = pval_map.begin (); |
|
1006 q != pval_map.end (); |
|
1007 q++) |
|
1008 { |
|
1009 std::string pname = q->first; |
6406
|
1010 |
6705
|
1011 obj.set (pname, q->second); |
6406
|
1012 |
6705
|
1013 if (error_state) |
|
1014 { |
|
1015 error ("error setting default property %s", pname.c_str ()); |
|
1016 break; |
|
1017 } |
|
1018 } |
|
1019 } |
|
1020 } |
6406
|
1021 |
7363
|
1022 octave_value |
|
1023 base_properties::get (const caseless_str& name) const |
|
1024 { |
|
1025 octave_value retval; |
|
1026 |
|
1027 if (name.compare ("tag")) |
|
1028 retval = get_tag (); |
|
1029 else if (name.compare ("type")) |
|
1030 retval = get_type (); |
|
1031 else if (name.compare ("__modified__")) |
|
1032 retval = is_modified (); |
|
1033 else if (name.compare ("parent")) |
|
1034 retval = get_parent ().as_octave_value (); |
|
1035 else if (name.compare ("children")) |
|
1036 retval = children; |
7366
|
1037 else if (name.compare ("busyaction")) |
|
1038 retval = get_busyaction (); |
|
1039 else if (name.compare ("buttondownfcn")) |
|
1040 retval = get_buttondownfcn (); |
|
1041 else if (name.compare ("clipping")) |
|
1042 retval = get_clipping (); |
|
1043 else if (name.compare ("createfcn")) |
|
1044 retval = get_createfcn (); |
|
1045 else if (name.compare ("deletefcn")) |
|
1046 retval = get_deletefcn (); |
|
1047 else if (name.compare ("handlevisibility")) |
|
1048 retval = get_handlevisibility (); |
|
1049 else if (name.compare ("hittest")) |
|
1050 retval = get_hittest (); |
|
1051 else if (name.compare ("interruptible")) |
|
1052 retval = get_interruptible (); |
|
1053 else if (name.compare ("selected")) |
|
1054 retval = get_selected (); |
|
1055 else if (name.compare ("selectionhighlight")) |
|
1056 retval = get_selectionhighlight (); |
|
1057 else if (name.compare ("uicontextmenu")) |
|
1058 retval = get_uicontextmenu (); |
|
1059 else if (name.compare ("userdata")) |
|
1060 retval = get_userdata (); |
|
1061 else if (name.compare ("visible")) |
|
1062 retval = get_visible (); |
7403
|
1063 else if (name.compare ("beingdeleted")) |
|
1064 retval = get_beingdeleted (); |
7363
|
1065 else |
|
1066 { |
|
1067 std::map<caseless_str, property>::const_iterator it = all_props.find (name); |
|
1068 |
|
1069 if (it != all_props.end ()) |
|
1070 retval = it->second.get (); |
|
1071 else |
|
1072 error ("get: unknown property \"%s\"", name.c_str ()); |
|
1073 } |
|
1074 |
|
1075 return retval; |
|
1076 } |
|
1077 |
|
1078 octave_value |
7379
|
1079 base_properties::get (bool all) const |
7363
|
1080 { |
|
1081 Octave_map m; |
|
1082 |
|
1083 for (std::map<caseless_str, property>::const_iterator it = all_props.begin (); |
|
1084 it != all_props.end (); ++it) |
7379
|
1085 if (all || ! it->second.is_hidden ()) |
|
1086 m.assign (it->second.get_name (), it->second.get ()); |
7363
|
1087 |
|
1088 m.assign ("tag", get_tag ()); |
|
1089 m.assign ("type", get_type ()); |
7379
|
1090 if (all) |
|
1091 m.assign ("__modified__", is_modified ()); |
7363
|
1092 m.assign ("parent", get_parent ().as_octave_value ()); |
|
1093 m.assign ("children", children); |
7366
|
1094 m.assign ("busyaction", get_busyaction ()); |
|
1095 m.assign ("buttondownfcn", get_buttondownfcn ()); |
|
1096 m.assign ("clipping", get_clipping ()); |
|
1097 m.assign ("createfcn", get_createfcn ()); |
|
1098 m.assign ("deletefcn", get_deletefcn ()); |
|
1099 m.assign ("handlevisibility", get_handlevisibility ()); |
|
1100 m.assign ("hittest", get_hittest ()); |
|
1101 m.assign ("interruptible", get_interruptible ()); |
|
1102 m.assign ("selected", get_selected ()); |
|
1103 m.assign ("selectionhighlight", get_selectionhighlight ()); |
|
1104 m.assign ("uicontextmenu", get_uicontextmenu ()); |
|
1105 m.assign ("userdata", get_userdata ()); |
|
1106 m.assign ("visible", get_visible ()); |
7403
|
1107 m.assign ("beingdeleted", get_beingdeleted ()); |
7363
|
1108 |
|
1109 return m; |
|
1110 } |
|
1111 |
|
1112 void |
|
1113 base_properties::set (const caseless_str& name, const octave_value& val) |
|
1114 { |
|
1115 if (name.compare ("tag")) |
|
1116 set_tag (val); |
|
1117 else if (name.compare ("__modified__")) |
|
1118 __modified__ = val; |
|
1119 else if (name.compare ("parent")) |
|
1120 set_parent (val); |
|
1121 else if (name.compare ("children")) |
|
1122 maybe_set_children (children, val); |
7366
|
1123 else if (name.compare ("busyaction")) |
|
1124 set_busyaction (val); |
|
1125 else if (name.compare ("buttondownfcn")) |
|
1126 set_buttondownfcn (val); |
|
1127 else if (name.compare ("clipping")) |
|
1128 set_clipping (val); |
|
1129 else if (name.compare ("createfcn")) |
|
1130 set_createfcn (val); |
|
1131 else if (name.compare ("deletefcn")) |
|
1132 set_deletefcn (val); |
|
1133 else if (name.compare ("handlevisibility")) |
|
1134 set_handlevisibility (val); |
|
1135 else if (name.compare ("hittest")) |
|
1136 set_hittest (val); |
|
1137 else if (name.compare ("interruptible")) |
|
1138 set_interruptible (val); |
|
1139 else if (name.compare ("selected")) |
|
1140 set_selected (val); |
|
1141 else if (name.compare ("selectionhighlight")) |
|
1142 set_selectionhighlight (val); |
|
1143 else if (name.compare ("uicontextmenu")) |
|
1144 set_uicontextmenu (val); |
|
1145 else if (name.compare ("userdata")) |
|
1146 set_userdata (val); |
|
1147 else if (name.compare ("visible")) |
|
1148 set_visible (val); |
7363
|
1149 else |
|
1150 { |
|
1151 std::map<caseless_str, property>::iterator it = all_props.find (name); |
|
1152 |
|
1153 if (it != all_props.end ()) |
|
1154 it->second.set (val); |
|
1155 else |
|
1156 error ("set: unknown property \"%s\"", name.c_str ()); |
|
1157 } |
|
1158 |
|
1159 if (! error_state && ! name.compare ("__modified__")) |
|
1160 mark_modified (); |
|
1161 } |
|
1162 |
|
1163 property |
|
1164 base_properties::get_property (const caseless_str& name) const |
|
1165 { |
|
1166 std::map<caseless_str, property>::const_iterator it = all_props.find (name); |
|
1167 |
|
1168 if (it == all_props.end ()) |
|
1169 return property (); |
|
1170 else |
|
1171 return it->second; |
|
1172 } |
|
1173 |
6705
|
1174 void |
|
1175 base_properties::remove_child (const graphics_handle& h) |
6406
|
1176 { |
6705
|
1177 octave_idx_type k = -1; |
|
1178 octave_idx_type n = children.numel (); |
|
1179 for (octave_idx_type i = 0; i < n; i++) |
6406
|
1180 { |
6874
|
1181 if (h.value () == children(i)) |
6406
|
1182 { |
6705
|
1183 k = i; |
|
1184 break; |
6406
|
1185 } |
|
1186 } |
|
1187 |
6705
|
1188 if (k >= 0) |
6406
|
1189 { |
6705
|
1190 Matrix new_kids (1, n-1); |
|
1191 octave_idx_type j = 0; |
|
1192 for (octave_idx_type i = 0; i < n; i++) |
|
1193 { |
|
1194 if (i != k) |
|
1195 new_kids(j++) = children(i); |
|
1196 } |
|
1197 children = new_kids; |
7378
|
1198 mark_modified (); |
6406
|
1199 } |
6705
|
1200 } |
6406
|
1201 |
6836
|
1202 void |
|
1203 base_properties::set_parent (const octave_value& val) |
6705
|
1204 { |
|
1205 double tmp = val.double_value (); |
6406
|
1206 |
6705
|
1207 graphics_handle new_parent = octave_NaN; |
6406
|
1208 |
6705
|
1209 if (! error_state) |
|
1210 { |
|
1211 new_parent = gh_manager::lookup (tmp); |
6406
|
1212 |
7056
|
1213 if (new_parent.ok ()) |
6705
|
1214 { |
7363
|
1215 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
6406
|
1216 |
6705
|
1217 parent_obj.remove_child (__myhandle__); |
6406
|
1218 |
7363
|
1219 parent = new_parent.as_octave_value (); |
6406
|
1220 |
7363
|
1221 ::adopt (parent.handle_value (), __myhandle__); |
6705
|
1222 } |
|
1223 else |
|
1224 error ("set: invalid graphics handle (= %g) for parent", tmp); |
|
1225 } |
|
1226 else |
|
1227 error ("set: expecting parent to be a graphics handle"); |
|
1228 } |
6432
|
1229 |
6705
|
1230 void |
6836
|
1231 base_properties::mark_modified (void) |
|
1232 { |
7363
|
1233 __modified__ = "on"; |
|
1234 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
7379
|
1235 if (parent_obj) |
|
1236 parent_obj.mark_modified (); |
6836
|
1237 } |
|
1238 |
|
1239 void |
|
1240 base_properties::override_defaults (base_graphics_object& obj) |
|
1241 { |
7363
|
1242 graphics_object parent_obj = gh_manager::get_object (get_parent ()); |
6836
|
1243 parent_obj.override_defaults (obj); |
|
1244 } |
|
1245 |
|
1246 void |
7214
|
1247 base_properties::update_axis_limits (const std::string& axis_type) const |
|
1248 { |
7363
|
1249 graphics_handle h = (get_type () == "axes") ? __myhandle__ : get_parent (); |
7214
|
1250 |
|
1251 graphics_object obj = gh_manager::get_object (h); |
|
1252 |
|
1253 if (obj.isa ("axes")) |
|
1254 obj.update_axis_limits (axis_type); |
|
1255 } |
|
1256 |
|
1257 void |
6836
|
1258 base_properties::delete_children (void) |
|
1259 { |
|
1260 octave_idx_type n = children.numel (); |
|
1261 |
|
1262 for (octave_idx_type i = 0; i < n; i++) |
|
1263 gh_manager::free (children(i)); |
|
1264 } |
|
1265 |
7419
|
1266 graphics_backend |
|
1267 base_properties::get_backend (void) const |
|
1268 { |
|
1269 graphics_object go = gh_manager::get_object (get_parent ()); |
|
1270 |
|
1271 if (go) |
|
1272 return go.get_backend (); |
|
1273 else |
|
1274 return graphics_backend (); |
|
1275 } |
|
1276 |
7363
|
1277 // --------------------------------------------------------------------- |
|
1278 |
7408
|
1279 class gnuplot_backend : public base_graphics_backend |
|
1280 { |
|
1281 public: |
|
1282 gnuplot_backend (void) |
|
1283 : base_graphics_backend ("gnuplot") { } |
|
1284 |
|
1285 ~gnuplot_backend (void) { } |
|
1286 |
|
1287 bool is_valid (void) const { return true; } |
|
1288 |
|
1289 void close_figure (const octave_value& pstream) const |
|
1290 { |
|
1291 if (! pstream.is_empty()) |
|
1292 { |
|
1293 octave_value_list args; |
|
1294 args(1) = "\nquit;\n"; |
|
1295 args(0) = pstream; |
|
1296 feval ("fputs", args); |
|
1297 args.resize (1); |
|
1298 feval ("fflush", args); |
|
1299 feval ("pclose", args); |
|
1300 } |
|
1301 } |
|
1302 |
|
1303 void redraw_figure (const graphics_handle& fh) const |
|
1304 { |
|
1305 octave_value_list args; |
|
1306 args(0) = fh.as_octave_value (); |
|
1307 feval ("gnuplot_drawnow", args); |
|
1308 } |
|
1309 |
|
1310 void print_figure (const graphics_handle& fh, const std::string& term, |
|
1311 const std::string& file, bool mono, |
|
1312 const std::string& debug_file) const |
|
1313 { |
|
1314 octave_value_list args; |
|
1315 if (! debug_file.empty ()) |
|
1316 args(4) = debug_file; |
7409
|
1317 args(3) = mono; |
|
1318 args(2) = file; |
|
1319 args(1) = term; |
|
1320 args(0) = fh.as_octave_value (); |
7408
|
1321 feval ("gnuplot_drawnow", args); |
|
1322 } |
|
1323 |
7409
|
1324 Matrix get_canvas_size (const graphics_handle&) const |
7427
|
1325 { |
|
1326 Matrix sz (1, 2, 0.0); |
|
1327 return sz; |
|
1328 } |
|
1329 |
|
1330 double get_screen_resolution (void) const |
|
1331 { return 72.0; } |
7445
|
1332 |
|
1333 Matrix get_screen_size (void) const |
|
1334 { return Matrix (1, 2, 0.0); } |
7408
|
1335 }; |
|
1336 |
|
1337 graphics_backend |
|
1338 graphics_backend::default_backend (void) |
|
1339 { |
|
1340 if (available_backends.size () == 0) |
|
1341 register_backend (new gnuplot_backend ()); |
|
1342 |
|
1343 return available_backends["gnuplot"]; |
|
1344 } |
|
1345 |
|
1346 std::map<std::string, graphics_backend> graphics_backend::available_backends; |
|
1347 |
|
1348 // --------------------------------------------------------------------- |
|
1349 |
7363
|
1350 #include "graphics-props.cc" |
|
1351 |
|
1352 // --------------------------------------------------------------------- |
|
1353 |
6836
|
1354 void |
7363
|
1355 root_figure::properties::set_currentfigure (const octave_value& v) |
6874
|
1356 { |
7378
|
1357 graphics_handle val (v); |
7363
|
1358 |
6874
|
1359 if (error_state) |
|
1360 return; |
|
1361 |
7059
|
1362 if (xisnan (val.value ()) || is_handle (val)) |
6874
|
1363 { |
|
1364 currentfigure = val; |
|
1365 |
7363
|
1366 gh_manager::push_figure (val); |
6874
|
1367 } |
|
1368 else |
|
1369 gripe_set_invalid ("currentfigure"); |
|
1370 } |
|
1371 |
6406
|
1372 property_list |
|
1373 root_figure::factory_properties = root_figure::init_factory_properties (); |
|
1374 |
|
1375 // --------------------------------------------------------------------- |
|
1376 |
7363
|
1377 void |
|
1378 figure::properties::set_currentaxes (const octave_value& v) |
|
1379 { |
7378
|
1380 graphics_handle val (v); |
6705
|
1381 |
6874
|
1382 if (error_state) |
|
1383 return; |
|
1384 |
7070
|
1385 if (xisnan (val.value ()) || is_handle (val)) |
6874
|
1386 currentaxes = val; |
|
1387 else |
|
1388 gripe_set_invalid ("currentaxes"); |
|
1389 } |
|
1390 |
|
1391 void |
|
1392 figure::properties::set_visible (const octave_value& val) |
|
1393 { |
|
1394 std::string s = val.string_value (); |
|
1395 |
|
1396 if (! error_state) |
|
1397 { |
|
1398 if (s == "on") |
|
1399 xset (0, "currentfigure", __myhandle__.value ()); |
|
1400 |
|
1401 visible = val; |
|
1402 } |
|
1403 } |
|
1404 |
|
1405 void |
7408
|
1406 figure::properties::close (bool pop) |
6705
|
1407 { |
7408
|
1408 if (backend) |
|
1409 backend.close_figure (get___plot_stream__ ()); |
|
1410 |
|
1411 if (pop) |
6406
|
1412 { |
7408
|
1413 gh_manager::pop_figure (__myhandle__); |
|
1414 |
|
1415 graphics_handle cf = gh_manager::current_figure (); |
|
1416 |
|
1417 xset (0, "currentfigure", cf.value ()); |
6406
|
1418 } |
6705
|
1419 } |
6432
|
1420 |
7445
|
1421 Matrix |
|
1422 figure::properties::get_boundingbox (void) const |
|
1423 { |
|
1424 graphics_backend b = get_backend (); |
|
1425 // FIXME: screen size should be obtained from root object |
|
1426 Matrix screen_size = b.get_screen_size (); |
|
1427 Matrix pos; |
|
1428 |
|
1429 pos = convert_position (get_position ().matrix_value (), get_units (), |
|
1430 "pixels", screen_size, b); |
|
1431 |
|
1432 pos(0)--; |
|
1433 pos(1)--; |
|
1434 |
|
1435 return pos; |
|
1436 } |
|
1437 |
6836
|
1438 octave_value |
7189
|
1439 figure::get_default (const caseless_str& name) const |
6836
|
1440 { |
|
1441 octave_value retval = default_properties.lookup (name); |
|
1442 |
|
1443 if (retval.is_undefined ()) |
|
1444 { |
|
1445 graphics_handle parent = get_parent (); |
|
1446 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1447 |
|
1448 retval = parent_obj.get_default (name); |
|
1449 } |
|
1450 |
|
1451 return retval; |
|
1452 } |
|
1453 |
6406
|
1454 // --------------------------------------------------------------------- |
|
1455 |
7363
|
1456 void |
|
1457 axes::properties::set_title (const octave_value& v) |
6962
|
1458 { |
7363
|
1459 graphics_handle val = ::reparent (v, "set", "title", __myhandle__, false); |
6962
|
1460 |
6874
|
1461 if (! error_state) |
|
1462 { |
7363
|
1463 gh_manager::free (title.handle_value ()); |
6874
|
1464 title = val; |
|
1465 } |
|
1466 } |
|
1467 |
|
1468 void |
7363
|
1469 axes::properties::set_xlabel (const octave_value& v) |
6874
|
1470 { |
7363
|
1471 graphics_handle val = ::reparent (v, "set", "xlabel", __myhandle__, false); |
6874
|
1472 |
|
1473 if (! error_state) |
|
1474 { |
7363
|
1475 gh_manager::free (xlabel.handle_value ()); |
6874
|
1476 xlabel = val; |
|
1477 } |
|
1478 } |
|
1479 |
|
1480 void |
7363
|
1481 axes::properties::set_ylabel (const octave_value& v) |
6874
|
1482 { |
7363
|
1483 graphics_handle val = ::reparent (v, "set", "ylabel", __myhandle__, false); |
6874
|
1484 |
|
1485 if (! error_state) |
|
1486 { |
7363
|
1487 gh_manager::free (ylabel.handle_value ()); |
6874
|
1488 ylabel = val; |
|
1489 } |
|
1490 } |
|
1491 |
|
1492 void |
7363
|
1493 axes::properties::set_zlabel (const octave_value& v) |
6874
|
1494 { |
7363
|
1495 graphics_handle val = ::reparent (v, "set", "zlabel", __myhandle__, false); |
6874
|
1496 |
|
1497 if (! error_state) |
|
1498 { |
7363
|
1499 gh_manager::free (zlabel.handle_value ()); |
6874
|
1500 zlabel = val; |
|
1501 } |
|
1502 } |
|
1503 |
|
1504 void |
6844
|
1505 axes::properties::set_defaults (base_graphics_object& obj, |
6890
|
1506 const std::string& mode) |
6705
|
1507 { |
7427
|
1508 position = default_axes_position (); |
7363
|
1509 title = graphics_handle (); |
6705
|
1510 box = "on"; |
|
1511 key = "off"; |
|
1512 keybox = "off"; |
7363
|
1513 keypos = 1.0; |
6962
|
1514 colororder = default_colororder (); |
6705
|
1515 dataaspectratio = Matrix (1, 3, 1.0); |
|
1516 dataaspectratiomode = "auto"; |
7363
|
1517 layer = "bottom"; |
6705
|
1518 |
|
1519 Matrix tlim (1, 2, 0.0); |
|
1520 tlim(1) = 1; |
|
1521 xlim = tlim; |
|
1522 ylim = tlim; |
|
1523 zlim = tlim; |
6807
|
1524 |
|
1525 Matrix cl (1, 2, 0); |
|
1526 cl(1) = 1; |
|
1527 clim = cl; |
|
1528 |
7363
|
1529 xlimmode = "auto"; |
|
1530 ylimmode = "auto"; |
|
1531 zlimmode = "auto"; |
|
1532 climmode = "auto"; |
|
1533 xlabel = graphics_handle (); |
|
1534 ylabel = graphics_handle (); |
|
1535 zlabel = graphics_handle (); |
6705
|
1536 xgrid = "off"; |
|
1537 ygrid = "off"; |
|
1538 zgrid = "off"; |
|
1539 xminorgrid = "off"; |
|
1540 yminorgrid = "off"; |
|
1541 zminorgrid = "off"; |
|
1542 xtick = Matrix (); |
|
1543 ytick = Matrix (); |
|
1544 ztick = Matrix (); |
|
1545 xtickmode = "auto"; |
|
1546 ytickmode = "auto"; |
|
1547 ztickmode = "auto"; |
|
1548 xticklabel = ""; |
|
1549 yticklabel = ""; |
|
1550 zticklabel = ""; |
|
1551 xticklabelmode = "auto"; |
|
1552 yticklabelmode = "auto"; |
|
1553 zticklabelmode = "auto"; |
7364
|
1554 color = color_values (0, 0, 0); |
|
1555 xcolor = color_values ("black"); |
|
1556 ycolor = color_values ("black"); |
|
1557 zcolor = color_values ("black"); |
7363
|
1558 xscale = "linear"; |
|
1559 yscale = "linear"; |
|
1560 zscale = "linear"; |
6705
|
1561 xdir = "normal"; |
|
1562 ydir = "normal"; |
|
1563 zdir = "normal"; |
7363
|
1564 yaxislocation = "left"; |
|
1565 xaxislocation = "bottom"; |
6705
|
1566 |
7427
|
1567 // Note: camera properties will be set through update_transform |
|
1568 camerapositionmode = "auto"; |
|
1569 cameratargetmode = "auto"; |
|
1570 cameraupvectormode = "auto"; |
|
1571 cameraviewanglemode = "auto"; |
|
1572 plotboxaspectratio = Matrix (1, 3, 1.0); |
|
1573 drawmode = "normal"; |
|
1574 fontangle = "normal"; |
|
1575 fontname = "Helvetica"; |
|
1576 fontsize = 12; |
|
1577 fontunits = "points"; |
|
1578 fontweight = "normal"; |
|
1579 gridlinestyle = "-"; |
|
1580 linestyleorder = "-"; |
|
1581 linewidth = 0.5; |
|
1582 minorgridlinestyle = "-"; |
|
1583 // Note: plotboxaspectratio will be set through update_aspectratiors |
|
1584 plotboxaspectratiomode = "auto"; |
|
1585 projection = "orthographic"; |
|
1586 tickdir = "in"; |
|
1587 tickdirmode = "auto"; |
|
1588 ticklength = Matrix (1, 2, 0.1); |
|
1589 tightinset = Matrix (1, 4, 0.0); |
|
1590 |
|
1591 sx = "linear"; |
|
1592 sy = "linear"; |
|
1593 sz = "linear"; |
|
1594 |
6705
|
1595 Matrix tview (1, 2, 0.0); |
|
1596 tview(1) = 90; |
|
1597 view = tview; |
|
1598 |
6765
|
1599 visible = "on"; |
6705
|
1600 nextplot = "replace"; |
|
1601 |
|
1602 // FIXME -- this is not quite right; we should preserve |
|
1603 // "position" and "units". |
|
1604 |
|
1605 if (mode != "replace") |
|
1606 { |
6406
|
1607 Matrix touterposition (1, 4, 0.0); |
|
1608 touterposition(2) = 1; |
|
1609 touterposition(3) = 1; |
|
1610 outerposition = touterposition; |
|
1611 } |
|
1612 |
7363
|
1613 activepositionproperty = "outerposition"; |
|
1614 __colorbar__ = "none"; |
7189
|
1615 |
6705
|
1616 delete_children (); |
6406
|
1617 |
6705
|
1618 children = Matrix (); |
6432
|
1619 |
7427
|
1620 update_transform (); |
|
1621 |
6705
|
1622 override_defaults (obj); |
|
1623 } |
|
1624 |
6874
|
1625 graphics_handle |
|
1626 axes::properties::get_title (void) const |
|
1627 { |
7363
|
1628 if (! title.handle_value ().ok ()) |
6874
|
1629 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1630 |
7363
|
1631 return title.handle_value (); |
6874
|
1632 } |
|
1633 |
|
1634 graphics_handle |
|
1635 axes::properties::get_xlabel (void) const |
|
1636 { |
7363
|
1637 if (! xlabel.handle_value ().ok ()) |
6874
|
1638 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1639 |
7363
|
1640 return xlabel.handle_value (); |
6874
|
1641 } |
|
1642 |
|
1643 graphics_handle |
|
1644 axes::properties::get_ylabel (void) const |
|
1645 { |
7363
|
1646 if (! ylabel.handle_value ().ok ()) |
6874
|
1647 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1648 |
7363
|
1649 return ylabel.handle_value (); |
6874
|
1650 } |
|
1651 |
|
1652 graphics_handle |
|
1653 axes::properties::get_zlabel (void) const |
|
1654 { |
7363
|
1655 if (! zlabel.handle_value ().ok ()) |
6874
|
1656 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1657 |
7363
|
1658 return zlabel.handle_value (); |
6705
|
1659 } |
6406
|
1660 |
6705
|
1661 void |
6844
|
1662 axes::properties::remove_child (const graphics_handle& h) |
6705
|
1663 { |
7363
|
1664 if (title.handle_value ().ok () && h == title.handle_value ()) |
6705
|
1665 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1666 else if (xlabel.handle_value ().ok () && h == xlabel.handle_value ()) |
6705
|
1667 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1668 else if (ylabel.handle_value ().ok () && h == ylabel.handle_value ()) |
6705
|
1669 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1670 else if (zlabel.handle_value ().ok () && h == zlabel.handle_value ()) |
6705
|
1671 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1672 else |
|
1673 base_properties::remove_child (h); |
|
1674 } |
6406
|
1675 |
6705
|
1676 void |
6844
|
1677 axes::properties::delete_children (void) |
6705
|
1678 { |
|
1679 base_properties::delete_children (); |
|
1680 |
7363
|
1681 gh_manager::free (title.handle_value ()); |
|
1682 gh_manager::free (xlabel.handle_value ()); |
|
1683 gh_manager::free (ylabel.handle_value ()); |
|
1684 gh_manager::free (zlabel.handle_value ()); |
6705
|
1685 } |
6406
|
1686 |
7427
|
1687 inline Matrix |
|
1688 xform_matrix (void) |
|
1689 { |
|
1690 Matrix m (4, 4, 0.0); |
|
1691 for (int i = 0; i < 4; i++) |
|
1692 m(i,i) = 1; |
|
1693 return m; |
|
1694 } |
|
1695 |
|
1696 inline ColumnVector |
|
1697 xform_vector (void) |
|
1698 { |
|
1699 ColumnVector v (4, 0.0); |
|
1700 v(3) = 1; |
|
1701 return v; |
|
1702 } |
|
1703 |
|
1704 inline ColumnVector |
|
1705 xform_vector (double x, double y, double z) |
|
1706 { |
|
1707 ColumnVector v (4, 1.0); |
|
1708 v(0) = x; v(1) = y; v(2) = z; |
|
1709 return v; |
|
1710 } |
|
1711 |
|
1712 inline ColumnVector |
|
1713 transform (const Matrix& m, double x, double y, double z) |
|
1714 { |
|
1715 return (m * xform_vector (x, y, z)); |
|
1716 } |
|
1717 |
|
1718 inline Matrix |
|
1719 xform_scale (double x, double y, double z) |
|
1720 { |
|
1721 Matrix m (4, 4, 0.0); |
|
1722 m(0,0) = x; m(1,1) = y; m(2,2) = z; m(3,3) = 1; |
|
1723 return m; |
|
1724 } |
|
1725 |
|
1726 inline Matrix |
|
1727 xform_translate (double x, double y, double z) |
|
1728 { |
|
1729 Matrix m = xform_matrix (); |
|
1730 m(0,3) = x; m(1,3) = y; m(2,3) = z; m(3,3) = 1; |
|
1731 return m; |
|
1732 } |
|
1733 |
|
1734 inline void |
|
1735 scale (Matrix& m, double x, double y, double z) |
|
1736 { |
|
1737 m = m * xform_scale (x, y, z); |
|
1738 } |
|
1739 |
|
1740 inline void |
|
1741 translate (Matrix& m, double x, double y, double z) |
|
1742 { |
|
1743 m = m * xform_translate (x, y, z); |
|
1744 } |
|
1745 |
|
1746 inline void |
|
1747 xform (ColumnVector& v, const Matrix& m) |
|
1748 { |
|
1749 v = m*v; |
|
1750 } |
|
1751 |
|
1752 inline void |
|
1753 scale (ColumnVector& v, double x, double y, double z) |
|
1754 { |
|
1755 v(0) *= x; |
|
1756 v(1) *= y; |
|
1757 v(2) *= z; |
|
1758 } |
|
1759 |
|
1760 inline void |
|
1761 translate (ColumnVector& v, double x, double y, double z) |
|
1762 { |
|
1763 v(0) += x; |
|
1764 v(1) += y; |
|
1765 v(2) += z; |
|
1766 } |
|
1767 |
|
1768 inline void |
|
1769 normalize (ColumnVector& v) |
|
1770 { |
|
1771 double fact = 1.0/sqrt(v(0)*v(0)+v(1)*v(1)+v(2)*v(2)); |
|
1772 scale (v, fact, fact, fact); |
|
1773 } |
|
1774 |
|
1775 inline double |
|
1776 dot (const ColumnVector& v1, const ColumnVector& v2) |
|
1777 { |
|
1778 return (v1(0)*v2(0)+v1(1)*v2(1)+v1(2)*v2(2)); |
|
1779 } |
|
1780 |
|
1781 inline double |
|
1782 norm (const ColumnVector& v) |
|
1783 { |
|
1784 return sqrt (dot (v, v)); |
|
1785 } |
|
1786 |
|
1787 inline ColumnVector |
|
1788 cross (const ColumnVector& v1, const ColumnVector& v2) |
|
1789 { |
|
1790 ColumnVector r = xform_vector (); |
|
1791 r(0) = v1(1)*v2(2)-v1(2)*v2(1); |
|
1792 r(1) = v1(2)*v2(0)-v1(0)*v2(2); |
|
1793 r(2) = v1(0)*v2(1)-v1(1)*v2(0); |
|
1794 return r; |
|
1795 } |
|
1796 |
|
1797 inline Matrix |
|
1798 unit_cube (void) |
|
1799 { |
|
1800 static double data[32] = { |
|
1801 0,0,0,1, |
|
1802 1,0,0,1, |
|
1803 0,1,0,1, |
|
1804 0,0,1,1, |
|
1805 1,1,0,1, |
|
1806 1,0,1,1, |
|
1807 0,1,1,1, |
|
1808 1,1,1,1}; |
|
1809 Matrix m (4, 8); |
|
1810 memcpy (m.fortran_vec (), data, sizeof(double)*32); |
|
1811 return m; |
|
1812 } |
|
1813 |
|
1814 inline ColumnVector |
|
1815 cam2xform (const Array<double>& m) |
|
1816 { |
|
1817 ColumnVector retval (4, 1.0); |
|
1818 memcpy (retval.fortran_vec (), m.fortran_vec (), sizeof(double)*3); |
|
1819 return retval; |
|
1820 } |
|
1821 |
|
1822 inline RowVector |
|
1823 xform2cam (const ColumnVector& v) |
|
1824 { |
|
1825 return v.extract_n (0, 3).transpose (); |
|
1826 } |
|
1827 |
|
1828 void |
|
1829 axes::properties::update_camera (void) |
|
1830 { |
|
1831 double xd = (xdir_is ("normal") ? 1 : -1); |
|
1832 double yd = (ydir_is ("normal") ? 1 : -1); |
|
1833 double zd = (zdir_is ("normal") ? 1 : -1); |
|
1834 |
|
1835 Matrix xlim = sx.scale (get_xlim ().matrix_value ()); |
|
1836 Matrix ylim = sy.scale (get_ylim ().matrix_value ()); |
|
1837 Matrix zlim = sz.scale (get_zlim ().matrix_value ()); |
|
1838 |
|
1839 double xo = xlim(xd > 0 ? 0 : 1); |
|
1840 double yo = ylim(yd > 0 ? 0 : 1); |
|
1841 double zo = zlim(zd > 0 ? 0 : 1); |
|
1842 |
|
1843 Matrix pb = get_plotboxaspectratio ().matrix_value (); |
|
1844 |
|
1845 bool autocam = (camerapositionmode_is ("auto") |
|
1846 && cameratargetmode_is ("auto") |
|
1847 && cameraupvectormode_is ("auto") |
|
1848 && cameraviewanglemode_is ("auto")); |
|
1849 bool dowarp = (autocam && dataaspectratiomode_is("auto") |
|
1850 && plotboxaspectratiomode_is ("auto")); |
|
1851 |
|
1852 ColumnVector c_eye (xform_vector ()); |
|
1853 ColumnVector c_center (xform_vector ()); |
|
1854 ColumnVector c_upv (xform_vector ()); |
|
1855 |
|
1856 if (cameratargetmode_is ("auto")) |
|
1857 { |
|
1858 c_center(0) = (xlim(0)+xlim(1))/2; |
|
1859 c_center(1) = (ylim(0)+ylim(1))/2; |
|
1860 c_center(2) = (zlim(0)+zlim(1))/2; |
|
1861 |
|
1862 cameratarget = xform2cam (c_center); |
|
1863 } |
|
1864 else |
|
1865 c_center = cam2xform (get_cameratarget ().matrix_value ()); |
|
1866 |
|
1867 if (camerapositionmode_is ("auto")) |
|
1868 { |
|
1869 Matrix view = get_view ().matrix_value (); |
|
1870 double az = view(0), el = view(1); |
|
1871 double d = 5*sqrt(pb(0)*pb(0)+pb(1)*pb(1)+pb(2)*pb(2)); |
|
1872 |
|
1873 if (el == 90 || el == -90) |
|
1874 c_eye(2) = d*signum(el); |
|
1875 else |
|
1876 { |
|
1877 az *= M_PI/180.0; |
|
1878 el *= M_PI/180.0; |
|
1879 c_eye(0) = d*cos(el)*sin(az); |
|
1880 c_eye(1) = -d*cos(el)*cos(az); |
|
1881 c_eye(2) = d*sin(el); |
|
1882 } |
|
1883 c_eye(0) = c_eye(0)*(xlim(1)-xlim(0))/(xd*pb(0))+c_center(0); |
|
1884 c_eye(1) = c_eye(1)*(ylim(1)-ylim(0))/(yd*pb(1))+c_center(1); |
|
1885 c_eye(2) = c_eye(2)*(zlim(1)-zlim(0))/(zd*pb(2))+c_center(2); |
|
1886 |
|
1887 cameraposition = xform2cam (c_eye); |
|
1888 } |
|
1889 else |
|
1890 c_eye = cam2xform (get_cameraposition ().matrix_value ()); |
|
1891 |
|
1892 if (cameraupvectormode_is ("auto")) |
|
1893 { |
|
1894 Matrix view = get_view ().matrix_value (); |
|
1895 double az = view(0), el = view(1); |
|
1896 |
|
1897 if (el == 90 || el == -90) |
|
1898 { |
|
1899 c_upv(0) = -sin(az*M_PI/180.0)*(xlim(1)-xlim(0))/pb(0); |
|
1900 c_upv(1) = cos(az*M_PI/180.0)*(ylim(1)-ylim(0))/pb(1); |
|
1901 } |
|
1902 else |
|
1903 c_upv(2) = 1; |
|
1904 |
|
1905 cameraupvector = xform2cam (c_upv); |
|
1906 } |
|
1907 else |
|
1908 c_upv = cam2xform (get_cameraupvector ().matrix_value ()); |
|
1909 |
|
1910 Matrix x_view = xform_matrix (); |
|
1911 Matrix x_projection = xform_matrix (); |
|
1912 Matrix x_viewport = xform_matrix (); |
|
1913 Matrix x_normrender = xform_matrix (); |
|
1914 Matrix x_pre = xform_matrix (); |
|
1915 |
|
1916 x_render = xform_matrix (); |
|
1917 x_render_inv = xform_matrix (); |
|
1918 |
|
1919 scale (x_pre, pb(0), pb(1), pb(2)); |
|
1920 translate (x_pre, -0.5, -0.5, -0.5); |
|
1921 scale (x_pre, xd/(xlim(1)-xlim(0)), yd/(ylim(1)-ylim(0)), |
|
1922 zd/(zlim(1)-zlim(0))); |
|
1923 translate (x_pre, -xo, -yo, -zo); |
|
1924 |
|
1925 xform (c_eye, x_pre); |
|
1926 xform (c_center, x_pre); |
|
1927 scale (c_upv, pb(0)/(xlim(1)-xlim(0)), pb(1)/(ylim(1)-ylim(0)), |
|
1928 pb(2)/(zlim(1)-zlim(0))); |
|
1929 translate (c_center, -c_eye(0), -c_eye(1), -c_eye(2)); |
|
1930 |
|
1931 ColumnVector F (c_center), f (F), UP (c_upv); |
|
1932 normalize (f); |
|
1933 normalize (UP); |
|
1934 |
7440
|
1935 if (std::abs (dot (f, UP)) > 1e-15) |
7427
|
1936 { |
|
1937 double fa = 1/sqrt(1-f(2)*f(2)); |
|
1938 scale (UP, fa, fa, fa); |
|
1939 } |
|
1940 |
|
1941 ColumnVector s = cross (f, UP); |
|
1942 ColumnVector u = cross (s, f); |
|
1943 |
|
1944 scale (x_view, 1, 1, -1); |
|
1945 Matrix l = xform_matrix (); |
|
1946 l(0,0) = s(0); l(0,1) = s(1); l(0,2) = s(2); |
|
1947 l(1,0) = u(0); l(1,1) = u(1); l(1,2) = u(2); |
|
1948 l(2,0) = -f(0); l(2,1) = -f(1); l(2,2) = -f(2); |
|
1949 x_view = x_view * l; |
|
1950 translate (x_view, -c_eye(0), -c_eye(1), -c_eye(2)); |
|
1951 scale (x_view, pb(0), pb(1), pb(2)); |
|
1952 translate (x_view, -0.5, -0.5, -0.5); |
|
1953 |
|
1954 Matrix x_cube = x_view * unit_cube (); |
|
1955 ColumnVector cmin = x_cube.row_min (), cmax = x_cube.row_max (); |
|
1956 double xM = cmax(0)-cmin(0); |
|
1957 double yM = cmax(1)-cmin(1); |
|
1958 |
|
1959 Matrix bb = get_boundingbox (); |
|
1960 Matrix cs = get_backend ().get_canvas_size (__myhandle__); |
|
1961 double fh = cs(1); |
|
1962 |
|
1963 double v_angle; |
|
1964 |
|
1965 if (cameraviewanglemode_is ("auto")) |
|
1966 { |
|
1967 double af; |
|
1968 |
|
1969 // FIXME: Was this really needed? When compared to Matlab, it |
|
1970 // does not seem to be required. Need investigation with concrete |
|
1971 // backend to see results visually. |
|
1972 if (false && dowarp) |
|
1973 af = 1.0 / (xM > yM ? xM : yM); |
|
1974 else |
|
1975 { |
|
1976 if ((bb(2)/bb(3)) > (xM/yM)) |
|
1977 af = 1.0 / yM; |
|
1978 else |
|
1979 af = 1.0 / xM; |
|
1980 } |
|
1981 v_angle = 2 * (180.0 / M_PI) * atan (1 / (2 * af * norm (F))); |
|
1982 |
|
1983 cameraviewangle = v_angle; |
|
1984 } |
|
1985 else |
|
1986 v_angle = get_cameraviewangle (); |
|
1987 |
|
1988 double pf = 1 / (2 * tan ((v_angle / 2) * M_PI / 180.0) * norm (F)); |
|
1989 scale (x_projection, pf, pf, 1); |
|
1990 |
|
1991 if (dowarp) |
|
1992 { |
|
1993 xM *= pf; |
|
1994 yM *= pf; |
|
1995 translate (x_viewport, bb(0)+bb(2)/2, fh-(bb(1)+bb(3)/2)+1, 0); |
|
1996 scale (x_viewport, bb(2)/xM, -bb(3)/yM, 1); |
|
1997 } |
|
1998 else |
|
1999 { |
|
2000 double pix = 1; |
|
2001 if (autocam) |
|
2002 { |
|
2003 if ((bb(2)/bb(3)) > (xM/yM)) |
|
2004 pix = bb(3); |
|
2005 else |
|
2006 pix = bb(2); |
|
2007 } |
|
2008 else |
|
2009 pix = (bb(2) < bb(3) ? bb(2) : bb(3)); |
|
2010 translate (x_viewport, bb(0)+bb(2)/2, fh-(bb(1)+bb(3)/2)+1, 0); |
|
2011 scale (x_viewport, pix, -pix, 1); |
|
2012 } |
|
2013 |
|
2014 x_normrender = x_viewport * x_projection * x_view; |
|
2015 |
|
2016 x_cube = x_normrender * unit_cube (); |
|
2017 cmin = x_cube.row_min (); |
|
2018 cmax = x_cube.row_max (); |
|
2019 x_zlim.resize (1, 2); |
|
2020 x_zlim(0) = cmin(2); |
|
2021 x_zlim(1) = cmax(2); |
|
2022 |
|
2023 x_render = x_normrender; |
|
2024 scale (x_render, xd/(xlim(1)-xlim(0)), yd/(ylim(1)-ylim(0)), |
|
2025 zd/(zlim(1)-zlim(0))); |
|
2026 translate (x_render, -xo, -yo, -zo); |
|
2027 |
|
2028 x_viewtransform = x_view; |
|
2029 x_projectiontransform = x_projection; |
|
2030 x_viewporttransform = x_viewport; |
|
2031 x_normrendertransform = x_normrender; |
|
2032 x_rendertransform = x_render; |
|
2033 |
|
2034 x_render_inv = x_render.inverse (); |
|
2035 |
|
2036 // Note: these matrices are a slight modified version of the regular |
|
2037 // matrices, more suited for OpenGL rendering (x_gl_mat1 => light |
|
2038 // => x_gl_mat2) |
|
2039 x_gl_mat1 = x_view; |
|
2040 scale (x_gl_mat1, xd/(xlim(1)-xlim(0)), yd/(ylim(1)-ylim(0)), |
|
2041 zd/(zlim(1)-zlim(0))); |
|
2042 translate (x_gl_mat1, -xo, -yo, -zo); |
|
2043 x_gl_mat2 = x_viewport * x_projection; |
|
2044 } |
|
2045 |
|
2046 void |
|
2047 axes::properties::update_aspectratios (void) |
|
2048 { |
|
2049 Matrix xlim = get_xlim ().matrix_value (); |
|
2050 Matrix ylim = get_ylim ().matrix_value (); |
|
2051 Matrix zlim = get_zlim ().matrix_value (); |
|
2052 |
|
2053 double dx = (xlim(1)-xlim(0)); |
|
2054 double dy = (ylim(1)-ylim(0)); |
|
2055 double dz = (zlim(1)-zlim(0)); |
|
2056 |
|
2057 if (dataaspectratiomode_is ("auto")) |
|
2058 { |
|
2059 double dmin = xmin (xmin (dx, dy), dz); |
|
2060 Matrix da (1, 3, 0.0); |
|
2061 |
|
2062 da(0) = dx/dmin; |
|
2063 da(1) = dy/dmin; |
|
2064 da(2) = dz/dmin; |
|
2065 |
|
2066 dataaspectratio = da; |
|
2067 } |
|
2068 |
|
2069 if (plotboxaspectratiomode_is ("auto")) |
|
2070 { |
|
2071 if (dataaspectratiomode_is ("auto")) |
|
2072 plotboxaspectratio = Matrix (1, 3, 1.0); |
|
2073 else |
|
2074 { |
|
2075 Matrix da = get_dataaspectratio ().matrix_value (); |
|
2076 Matrix pba (1, 3, 0.0); |
|
2077 |
|
2078 pba(0) = dx/da(0); |
|
2079 pba(1) = dy/da(1); |
|
2080 pba(2) = dz/da(2); |
|
2081 } |
|
2082 } |
|
2083 |
|
2084 // FIXME: if plotboxaspectratiomode is "manual", limits |
|
2085 // and/or dataaspectratio might be adapted |
|
2086 } |
|
2087 |
|
2088 Matrix |
|
2089 axes::properties::get_boundingbox (void) const |
|
2090 { |
|
2091 graphics_backend b = get_backend (); |
|
2092 Matrix pos; |
|
2093 |
|
2094 pos = convert_position (get_position ().matrix_value (), get_units (), |
|
2095 "pixels", b.get_canvas_size (__myhandle__), b); |
|
2096 pos(0)--; |
|
2097 pos(1)--; |
|
2098 |
|
2099 return pos; |
|
2100 } |
|
2101 |
7435
|
2102 ColumnVector |
|
2103 graphics_xform::xform_vector (double x, double y, double z) |
|
2104 { return ::xform_vector (x, y, z); } |
|
2105 |
|
2106 Matrix |
|
2107 graphics_xform::xform_eye (void) |
|
2108 { return ::xform_matrix (); } |
|
2109 |
|
2110 ColumnVector |
|
2111 graphics_xform::transform (double x, double y, double z, |
|
2112 bool use_scale) const |
|
2113 { |
|
2114 if (use_scale) |
|
2115 { |
|
2116 x = sx.scale (x); |
|
2117 y = sy.scale (y); |
|
2118 z = sz.scale (z); |
|
2119 } |
|
2120 |
|
2121 return ::transform (xform, x, y, z); |
|
2122 } |
|
2123 |
|
2124 ColumnVector |
|
2125 graphics_xform::untransform (double x, double y, double z, |
|
2126 bool use_scale) const |
|
2127 { |
|
2128 ColumnVector v = ::transform (xform_inv, x, y, z); |
|
2129 |
|
2130 if (use_scale) |
|
2131 { |
|
2132 v(0) = sx.unscale (v(0)); |
|
2133 v(1) = sy.unscale (v(1)); |
|
2134 v(2) = sz.unscale (v(2)); |
|
2135 } |
|
2136 |
|
2137 return v; |
|
2138 } |
|
2139 |
6836
|
2140 octave_value |
7189
|
2141 axes::get_default (const caseless_str& name) const |
6836
|
2142 { |
|
2143 octave_value retval = default_properties.lookup (name); |
|
2144 |
|
2145 if (retval.is_undefined ()) |
|
2146 { |
|
2147 graphics_handle parent = get_parent (); |
|
2148 graphics_object parent_obj = gh_manager::get_object (parent); |
|
2149 |
|
2150 retval = parent_obj.get_default (name); |
|
2151 } |
|
2152 |
|
2153 return retval; |
|
2154 } |
|
2155 |
7222
|
2156 static void |
|
2157 check_limit_vals (double& min_val, double& max_val, double& min_pos, |
|
2158 const data_property& data) |
|
2159 { |
7267
|
2160 double val = data.min_val (); |
|
2161 if (! (xisinf (val) || xisnan (val)) && val < min_val) |
|
2162 min_val = val; |
|
2163 val = data.max_val (); |
|
2164 if (! (xisinf (val) || xisnan (val)) && val > max_val) |
|
2165 max_val = val; |
|
2166 val = data.min_pos (); |
|
2167 if (! (xisinf (val) || xisnan (val)) && val > 0 && val < min_pos) |
|
2168 min_pos = val; |
7222
|
2169 } |
|
2170 |
|
2171 // Attempt to make "nice" limits from the actual max and min of the |
|
2172 // data. For log plots, we will also use the smallest strictly positive |
|
2173 // value. |
|
2174 |
|
2175 static Matrix |
|
2176 get_axis_limits (double xmin, double xmax, double min_pos, bool logscale) |
|
2177 { |
|
2178 Matrix retval; |
|
2179 |
|
2180 double min_val = xmin; |
|
2181 double max_val = xmax; |
|
2182 |
|
2183 if (! (xisinf (min_val) || xisinf (max_val))) |
|
2184 { |
|
2185 if (logscale) |
|
2186 { |
|
2187 if (xisinf (min_pos)) |
|
2188 { |
|
2189 // warning ("axis: logscale with no positive values to plot"); |
|
2190 return retval; |
|
2191 } |
|
2192 |
|
2193 if (min_val <= 0) |
|
2194 { |
|
2195 warning ("axis: omitting nonpositive data in log plot"); |
|
2196 min_val = min_pos; |
|
2197 } |
|
2198 // FIXME -- maybe this test should also be relative? |
|
2199 if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) |
|
2200 { |
|
2201 min_val *= 0.9; |
|
2202 max_val *= 1.1; |
|
2203 } |
|
2204 min_val = pow (10, floor (log10 (min_val))); |
|
2205 max_val = pow (10, ceil (log10 (max_val))); |
|
2206 } |
|
2207 else |
|
2208 { |
|
2209 if (min_val == 0 && max_val == 0) |
|
2210 { |
|
2211 min_val = -1; |
|
2212 max_val = 1; |
|
2213 } |
|
2214 // FIXME -- maybe this test should also be relative? |
|
2215 else if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) |
|
2216 { |
|
2217 min_val -= 0.1 * std::abs (min_val); |
|
2218 max_val += 0.1 * std::abs (max_val); |
|
2219 } |
|
2220 // FIXME -- to do a better job, we should consider the tic spacing. |
|
2221 double scale = pow (10, floor (log10 (max_val - min_val) - 1)); |
|
2222 min_val = scale * floor (min_val / scale); |
|
2223 max_val = scale * ceil (max_val / scale); |
|
2224 } |
|
2225 } |
|
2226 |
|
2227 retval.resize (1, 2); |
|
2228 |
|
2229 retval(0) = min_val; |
|
2230 retval(1) = max_val; |
|
2231 |
|
2232 return retval; |
|
2233 } |
|
2234 |
7446
|
2235 // magform(x) Returns (a, b), where x = a * 10^b, a >= 1., and b is |
|
2236 // integral. Used by calc_ticks |
|
2237 |
|
2238 void |
|
2239 axes::properties::magform (double x, double& a, int &b) |
|
2240 { |
|
2241 if (x == 0) |
|
2242 { |
|
2243 a = 0; |
|
2244 b = 0; |
|
2245 } |
|
2246 else |
|
2247 { |
|
2248 double l = std::log10 (std::abs (x)); |
|
2249 double r = std::fmod (l, 1.); |
|
2250 a = std::pow (10.0, r); |
|
2251 b = static_cast<int> (l-r); |
|
2252 if (a < 1) |
|
2253 { |
|
2254 a *= 10; |
|
2255 b -= 1; |
|
2256 } |
|
2257 |
|
2258 if (x < 0) |
|
2259 a = -a; |
|
2260 } |
|
2261 } |
|
2262 |
|
2263 // A translation from Tom Holoryd's python code at |
|
2264 // http://kurage.nimh.nih.gov/tomh/tics.py |
|
2265 // FIXME -- add log ticks |
|
2266 void |
|
2267 axes::properties::calc_ticks (const array_property& lims, array_property& ticks) |
|
2268 { |
|
2269 |
|
2270 int ticint = 5; |
|
2271 |
|
2272 if (lims.get ().is_empty ()) |
|
2273 return; |
|
2274 |
|
2275 double lo = (lims.get ().matrix_value ()) (0); |
|
2276 double hi = (lims.get ().matrix_value ()) (1); |
|
2277 |
|
2278 // Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and |
|
2279 // SCALE3 for Determination of Scales on Computer Generated |
|
2280 // Plots", Communications of the ACM, 10 (1973), 639-640. |
|
2281 // Also cited as ACM Algorithm 463. |
|
2282 |
|
2283 double a; |
|
2284 int b, x; |
|
2285 magform ( (hi-lo)/ticint, a, b); |
|
2286 if (a < 1.41) // sqrt(2) |
|
2287 x = 1; |
|
2288 else if (a < 3.16) // sqrt(10) |
|
2289 x = 2; |
|
2290 else if (a < 7.07) // sqrt(50) |
|
2291 x = 5; |
|
2292 else |
|
2293 x = 10; |
|
2294 |
|
2295 |
|
2296 double sep = x * std::pow (10., b); |
|
2297 |
|
2298 // FIXME x can now be used to set minor ticks |
|
2299 if (x == 10) |
|
2300 x = 1; |
|
2301 |
|
2302 |
|
2303 // The following guarantees that if zero is in the range, it will be |
|
2304 // included as a tic. |
|
2305 |
|
2306 int i1 = static_cast<int> (std::floor (lo / sep)); |
|
2307 int i2 = static_cast<int> (std::ceil (hi / sep)); |
|
2308 |
|
2309 Matrix limits (1, i2-i1+1); |
|
2310 for (int i=0; i<i2-i1+1; i++) |
|
2311 limits (i) = sep*(i+i1); |
|
2312 |
|
2313 ticks = limits; |
|
2314 |
|
2315 } |
|
2316 |
7222
|
2317 static bool updating_axis_limits = false; |
|
2318 |
7214
|
2319 void |
7222
|
2320 axes::update_axis_limits (const std::string& axis_type) |
7214
|
2321 { |
7222
|
2322 if (updating_axis_limits) |
|
2323 return; |
|
2324 |
|
2325 Matrix kids = xproperties.get_children (); |
|
2326 |
|
2327 octave_idx_type n = kids.numel (); |
|
2328 |
|
2329 double min_val = octave_Inf; |
|
2330 double max_val = -octave_Inf; |
|
2331 double min_pos = octave_Inf; |
|
2332 |
|
2333 char update_type = 0; |
|
2334 |
|
2335 Matrix limits; |
|
2336 |
|
2337 if (axis_type == "xdata" || axis_type == "xscale" |
|
2338 || axis_type == "xldata" || axis_type == "xudata" |
|
2339 || axis_type == "xlimmode") |
|
2340 { |
7363
|
2341 if (xproperties.xlimmode_is ("auto")) |
7222
|
2342 { |
|
2343 for (octave_idx_type i = 0; i < n; i++) |
|
2344 { |
|
2345 graphics_object obj = gh_manager::get_object (kids(i)); |
|
2346 |
|
2347 if (obj.isa ("line") || obj.isa ("image") |
|
2348 || obj.isa ("patch") || obj.isa ("surface")) |
|
2349 { |
7363
|
2350 data_property xdata = obj.get_xdata_property (); |
7222
|
2351 |
|
2352 check_limit_vals (min_val, max_val, min_pos, xdata); |
|
2353 |
|
2354 if (obj.isa ("line")) |
|
2355 { |
7363
|
2356 data_property xldata = obj.get_xldata_property (); |
|
2357 data_property xudata = obj.get_xudata_property (); |
7222
|
2358 |
|
2359 check_limit_vals (min_val, max_val, min_pos, xldata); |
|
2360 check_limit_vals (min_val, max_val, min_pos, xudata); |
|
2361 } |
|
2362 } |
|
2363 } |
|
2364 |
|
2365 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
2366 xproperties.xscale_is ("log")); |
7222
|
2367 |
|
2368 update_type = 'x'; |
|
2369 } |
|
2370 } |
|
2371 else if (axis_type == "ydata" || axis_type == "yscale" |
|
2372 || axis_type == "ldata" || axis_type == "udata" |
|
2373 || axis_type == "ylimmode") |
|
2374 { |
7363
|
2375 if (xproperties.ylimmode_is ("auto")) |
7222
|
2376 { |
|
2377 for (octave_idx_type i = 0; i < n; i++) |
|
2378 { |
|
2379 graphics_object obj = gh_manager::get_object (kids(i)); |
|
2380 |
|
2381 if (obj.isa ("line") || obj.isa ("image") |
|
2382 || obj.isa ("patch") || obj.isa ("surface")) |
|
2383 { |
7363
|
2384 data_property ydata = obj.get_ydata_property (); |
7222
|
2385 |
|
2386 check_limit_vals (min_val, max_val, min_pos, ydata); |
|
2387 |
|
2388 if (obj.isa ("line")) |
|
2389 { |
7363
|
2390 data_property ldata = obj.get_ldata_property (); |
|
2391 data_property udata = obj.get_udata_property (); |
7222
|
2392 |
|
2393 check_limit_vals (min_val, max_val, min_pos, ldata); |
|
2394 check_limit_vals (min_val, max_val, min_pos, udata); |
|
2395 } |
|
2396 } |
|
2397 } |
|
2398 |
|
2399 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
2400 xproperties.yscale_is ("log")); |
7222
|
2401 |
|
2402 update_type = 'y'; |
|
2403 } |
|
2404 } |
|
2405 else if (axis_type == "zdata" || axis_type == "zscale" |
|
2406 || axis_type == "zlimmode") |
|
2407 { |
7363
|
2408 if (xproperties.zlimmode_is ("auto")) |
7222
|
2409 { |
|
2410 for (octave_idx_type i = 0; i < n; i++) |
|
2411 { |
|
2412 graphics_object obj = gh_manager::get_object (kids(i)); |
|
2413 |
|
2414 if (obj.isa ("line") || obj.isa ("patch") || obj.isa ("surface")) |
|
2415 { |
7363
|
2416 data_property zdata = obj.get_zdata_property (); |
7222
|
2417 |
|
2418 check_limit_vals (min_val, max_val, min_pos, zdata); |
|
2419 } |
|
2420 } |
|
2421 |
|
2422 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
2423 xproperties.zscale_is ("log")); |
7222
|
2424 |
|
2425 update_type = 'z'; |
|
2426 } |
|
2427 } |
|
2428 else if (axis_type == "cdata" || axis_type == "climmode") |
|
2429 { |
7363
|
2430 if (xproperties.climmode_is ("auto")) |
7222
|
2431 { |
|
2432 for (octave_idx_type i = 0; i < n; i++) |
|
2433 { |
|
2434 graphics_object obj = gh_manager::get_object (kids(i)); |
|
2435 |
|
2436 if (obj.isa ("image") || obj.isa ("patch") || obj.isa ("surface")) |
|
2437 { |
7363
|
2438 data_property cdata = obj.get_cdata_property (); |
7222
|
2439 |
|
2440 check_limit_vals (min_val, max_val, min_pos, cdata); |
|
2441 } |
|
2442 } |
|
2443 |
|
2444 if (min_val == max_val) |
|
2445 max_val = min_val + 1; |
|
2446 |
|
2447 limits.resize (1, 2); |
|
2448 |
|
2449 limits(0) = min_val; |
|
2450 limits(1) = max_val; |
|
2451 |
|
2452 update_type = 'c'; |
|
2453 } |
|
2454 |
|
2455 } |
|
2456 |
|
2457 unwind_protect_bool (updating_axis_limits); |
|
2458 updating_axis_limits = true; |
|
2459 |
|
2460 switch (update_type) |
|
2461 { |
|
2462 case 'x': |
|
2463 xproperties.set_xlim (limits); |
|
2464 xproperties.set_xlimmode ("auto"); |
7446
|
2465 xproperties.update_xlim (); |
7222
|
2466 break; |
|
2467 |
|
2468 case 'y': |
|
2469 xproperties.set_ylim (limits); |
|
2470 xproperties.set_ylimmode ("auto"); |
7446
|
2471 xproperties.update_ylim (); |
7222
|
2472 break; |
|
2473 |
|
2474 case 'z': |
|
2475 xproperties.set_zlim (limits); |
|
2476 xproperties.set_zlimmode ("auto"); |
7446
|
2477 xproperties.update_zlim (); |
7222
|
2478 break; |
|
2479 |
|
2480 case 'c': |
|
2481 xproperties.set_clim (limits); |
|
2482 xproperties.set_climmode ("auto"); |
|
2483 break; |
|
2484 |
|
2485 default: |
|
2486 break; |
|
2487 } |
|
2488 |
7427
|
2489 xproperties.update_transform (); |
|
2490 |
7222
|
2491 unwind_protect::run (); |
7214
|
2492 } |
|
2493 |
7363
|
2494 // --------------------------------------------------------------------- |
|
2495 |
|
2496 // Note: "line" code is entirely auto-generated |
6406
|
2497 |
|
2498 // --------------------------------------------------------------------- |
|
2499 |
7363
|
2500 // Note: "text" code is entirely auto-generated |
6406
|
2501 |
|
2502 // --------------------------------------------------------------------- |
|
2503 |
7363
|
2504 // Note: "image" code is entirely auto-generated |
6406
|
2505 |
|
2506 // --------------------------------------------------------------------- |
|
2507 |
7363
|
2508 // Note: "patch" code is entirely auto-generated |
6807
|
2509 |
|
2510 // --------------------------------------------------------------------- |
|
2511 |
7363
|
2512 // Note: "surface" code is entirely auto-generated |
6406
|
2513 |
|
2514 // --------------------------------------------------------------------- |
|
2515 |
|
2516 octave_value |
7189
|
2517 base_graphics_object::get_default (const caseless_str& name) const |
6406
|
2518 { |
|
2519 graphics_handle parent = get_parent (); |
|
2520 graphics_object parent_obj = gh_manager::get_object (parent); |
|
2521 |
|
2522 return parent_obj.get_default (type () + name); |
|
2523 } |
|
2524 |
|
2525 octave_value |
7189
|
2526 base_graphics_object::get_factory_default (const caseless_str& name) const |
6406
|
2527 { |
|
2528 graphics_object parent_obj = gh_manager::get_object (0); |
|
2529 |
|
2530 return parent_obj.get_factory_default (type () + name); |
|
2531 } |
|
2532 |
7286
|
2533 // We use a random value for the handle to avoid issues with plots and |
|
2534 // scalar values for the first argument. |
6406
|
2535 gh_manager::gh_manager (void) |
7286
|
2536 : handle_map (), handle_free_list (), |
|
2537 next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) |
6406
|
2538 { |
|
2539 handle_map[0] = graphics_object (new root_figure ()); |
|
2540 } |
|
2541 |
|
2542 graphics_handle |
|
2543 gh_manager::do_make_graphics_handle (const std::string& go_name, |
7370
|
2544 const graphics_handle& p, bool do_createfcn) |
6406
|
2545 { |
|
2546 graphics_handle h = get_handle (go_name); |
|
2547 |
|
2548 base_graphics_object *go = 0; |
|
2549 |
|
2550 if (go_name == "figure") |
|
2551 go = new figure (h, p); |
|
2552 else if (go_name == "axes") |
|
2553 go = new axes (h, p); |
|
2554 else if (go_name == "line") |
|
2555 go = new line (h, p); |
|
2556 else if (go_name == "text") |
|
2557 go = new text (h, p); |
|
2558 else if (go_name == "image") |
|
2559 go = new image (h, p); |
6807
|
2560 else if (go_name == "patch") |
|
2561 go = new patch (h, p); |
6406
|
2562 else if (go_name == "surface") |
|
2563 go = new surface (h, p); |
|
2564 if (go) |
7370
|
2565 { |
|
2566 handle_map[h] = graphics_object (go); |
|
2567 if (do_createfcn) |
|
2568 go->get_properties ().execute_createfcn (); |
|
2569 } |
6406
|
2570 else |
|
2571 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
|
2572 go_name.c_str ()); |
|
2573 |
|
2574 return h; |
|
2575 } |
|
2576 |
|
2577 graphics_handle |
|
2578 gh_manager::do_make_figure_handle (double val) |
|
2579 { |
|
2580 graphics_handle h = val; |
|
2581 |
|
2582 handle_map[h] = graphics_object (new figure (h, 0)); |
|
2583 |
|
2584 return h; |
|
2585 } |
|
2586 |
|
2587 void |
|
2588 gh_manager::do_push_figure (const graphics_handle& h) |
|
2589 { |
|
2590 do_pop_figure (h); |
|
2591 |
|
2592 figure_list.push_front (h); |
|
2593 } |
|
2594 |
|
2595 void |
|
2596 gh_manager::do_pop_figure (const graphics_handle& h) |
|
2597 { |
|
2598 for (figure_list_iterator p = figure_list.begin (); |
|
2599 p != figure_list.end (); |
|
2600 p++) |
|
2601 { |
|
2602 if (*p == h) |
|
2603 { |
|
2604 figure_list.erase (p); |
|
2605 break; |
|
2606 } |
|
2607 } |
|
2608 } |
|
2609 |
|
2610 property_list::plist_map_type |
|
2611 root_figure::init_factory_properties (void) |
|
2612 { |
|
2613 property_list::plist_map_type plist_map; |
|
2614 |
6844
|
2615 plist_map["figure"] = figure::properties::factory_defaults (); |
|
2616 plist_map["axes"] = axes::properties::factory_defaults (); |
|
2617 plist_map["line"] = line::properties::factory_defaults (); |
|
2618 plist_map["text"] = text::properties::factory_defaults (); |
|
2619 plist_map["image"] = image::properties::factory_defaults (); |
|
2620 plist_map["patch"] = patch::properties::factory_defaults (); |
|
2621 plist_map["surface"] = surface::properties::factory_defaults (); |
6406
|
2622 |
|
2623 return plist_map; |
|
2624 } |
|
2625 |
|
2626 // --------------------------------------------------------------------- |
|
2627 |
|
2628 DEFUN (ishandle, args, , |
|
2629 "-*- texinfo -*-\n\ |
6678
|
2630 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406
|
2631 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
|
2632 @end deftypefn") |
|
2633 { |
|
2634 octave_value retval; |
|
2635 |
|
2636 if (args.length () == 1) |
|
2637 retval = is_handle (args(0)); |
|
2638 else |
|
2639 print_usage (); |
|
2640 |
|
2641 return retval; |
|
2642 } |
|
2643 |
|
2644 DEFUN (set, args, , |
|
2645 "-*- texinfo -*-\n\ |
6678
|
2646 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6732
|
2647 Set the named property value or vector @var{p} to the value @var{v}\n\ |
6894
|
2648 for the graphics handle @var{h}.\n\ |
6406
|
2649 @end deftypefn") |
|
2650 { |
|
2651 octave_value retval; |
|
2652 |
|
2653 int nargin = args.length (); |
|
2654 |
|
2655 if (nargin > 0) |
|
2656 { |
6732
|
2657 ColumnVector hcv (args(0).vector_value ()); |
6406
|
2658 |
|
2659 if (! error_state) |
6732
|
2660 { |
6733
|
2661 bool request_drawnow = false; |
|
2662 |
6732
|
2663 for (octave_idx_type n = 0; n < hcv.length (); n++) |
|
2664 { |
|
2665 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
2666 |
6732
|
2667 if (obj) |
|
2668 { |
|
2669 obj.set (args.splice (0, 1)); |
6406
|
2670 |
6733
|
2671 request_drawnow = true; |
6732
|
2672 } |
|
2673 else |
6733
|
2674 { |
|
2675 error ("set: invalid handle (= %g)", hcv(n)); |
|
2676 break; |
|
2677 } |
6732
|
2678 } |
6733
|
2679 |
|
2680 if (! error_state && request_drawnow) |
7409
|
2681 Vdrawnow_requested = true; |
6732
|
2682 } |
6406
|
2683 else |
6732
|
2684 error ("set: expecting graphics handle as first argument"); |
6406
|
2685 } |
|
2686 else |
|
2687 print_usage (); |
|
2688 |
|
2689 return retval; |
|
2690 } |
|
2691 |
|
2692 DEFUN (get, args, , |
|
2693 "-*- texinfo -*-\n\ |
6678
|
2694 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406
|
2695 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
|
2696 If @var{p} is omitted, return the complete property list for @var{h}.\n\ |
6732
|
2697 If @var{h} is a vector, return a cell array including the property\n\ |
|
2698 values or lists respectively.\n\ |
6406
|
2699 @end deftypefn") |
|
2700 { |
|
2701 octave_value retval; |
6732
|
2702 octave_value_list vlist; |
6406
|
2703 |
|
2704 int nargin = args.length (); |
|
2705 |
|
2706 if (nargin == 1 || nargin == 2) |
|
2707 { |
6732
|
2708 ColumnVector hcv (args(0).vector_value ()); |
6406
|
2709 |
|
2710 if (! error_state) |
6732
|
2711 { |
6733
|
2712 octave_idx_type len = hcv.length (); |
|
2713 |
|
2714 vlist.resize (len); |
|
2715 |
|
2716 for (octave_idx_type n = 0; n < len; n++) |
6732
|
2717 { |
|
2718 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
2719 |
6732
|
2720 if (obj) |
|
2721 { |
|
2722 if (nargin == 1) |
|
2723 vlist(n) = obj.get (); |
|
2724 else |
|
2725 { |
7189
|
2726 caseless_str property = args(1).string_value (); |
6406
|
2727 |
6732
|
2728 if (! error_state) |
|
2729 vlist(n) = obj.get (property); |
|
2730 else |
6733
|
2731 { |
|
2732 error ("get: expecting property name as second argument"); |
|
2733 break; |
|
2734 } |
6732
|
2735 } |
|
2736 } |
|
2737 else |
6733
|
2738 { |
|
2739 error ("get: invalid handle (= %g)", hcv(n)); |
|
2740 break; |
|
2741 } |
6732
|
2742 } |
|
2743 } |
6406
|
2744 else |
6732
|
2745 error ("get: expecting graphics handle as first argument"); |
6406
|
2746 } |
|
2747 else |
|
2748 print_usage (); |
|
2749 |
6733
|
2750 if (! error_state) |
6732
|
2751 { |
6733
|
2752 octave_idx_type len = vlist.length (); |
|
2753 |
|
2754 if (len > 1) |
|
2755 retval = Cell (vlist); |
|
2756 else if (len == 1) |
|
2757 retval = vlist(0); |
6732
|
2758 } |
|
2759 |
6406
|
2760 return retval; |
|
2761 } |
|
2762 |
7379
|
2763 DEFUN (__get__, args, , |
|
2764 "-*- texinfo -*-\n\ |
|
2765 @deftypefn {Built-in Function} {} __get__ (@var{h})\n\ |
|
2766 Return all properties from the graphics handle @var{h}.\n\ |
|
2767 If @var{h} is a vector, return a cell array including the property\n\ |
|
2768 values or lists respectively.\n\ |
|
2769 @end deftypefn") |
|
2770 { |
|
2771 octave_value retval; |
|
2772 octave_value_list vlist; |
|
2773 |
|
2774 int nargin = args.length (); |
|
2775 |
|
2776 if (nargin == 1) |
|
2777 { |
|
2778 ColumnVector hcv (args(0).vector_value ()); |
|
2779 |
|
2780 if (! error_state) |
|
2781 { |
|
2782 octave_idx_type len = hcv.length (); |
|
2783 |
|
2784 vlist.resize (len); |
|
2785 |
|
2786 for (octave_idx_type n = 0; n < len; n++) |
|
2787 { |
|
2788 graphics_object obj = gh_manager::get_object (hcv(n)); |
|
2789 |
|
2790 if (obj) |
|
2791 vlist(n) = obj.get (true); |
|
2792 else |
|
2793 { |
|
2794 error ("get: invalid handle (= %g)", hcv(n)); |
|
2795 break; |
|
2796 } |
|
2797 } |
|
2798 } |
|
2799 else |
|
2800 error ("get: expecting graphics handle as first argument"); |
|
2801 } |
|
2802 else |
|
2803 print_usage (); |
|
2804 |
|
2805 if (! error_state) |
|
2806 { |
|
2807 octave_idx_type len = vlist.length (); |
|
2808 |
|
2809 if (len > 1) |
|
2810 retval = Cell (vlist); |
|
2811 else if (len == 1) |
|
2812 retval = vlist(0); |
|
2813 } |
|
2814 |
|
2815 return retval; |
|
2816 } |
|
2817 |
6406
|
2818 static octave_value |
|
2819 make_graphics_object (const std::string& go_name, |
6874
|
2820 const octave_value_list& args) |
6406
|
2821 { |
|
2822 octave_value retval; |
|
2823 |
|
2824 double val = args(0).double_value (); |
|
2825 |
|
2826 if (! error_state) |
|
2827 { |
|
2828 graphics_handle parent = gh_manager::lookup (val); |
|
2829 |
7056
|
2830 if (parent.ok ()) |
6406
|
2831 { |
|
2832 graphics_handle h |
7370
|
2833 = gh_manager::make_graphics_handle (go_name, parent, false); |
6406
|
2834 |
|
2835 if (! error_state) |
|
2836 { |
|
2837 adopt (parent, h); |
|
2838 |
|
2839 xset (h, args.splice (0, 1)); |
7370
|
2840 xcreatefcn (h); |
6406
|
2841 |
6874
|
2842 retval = h.value (); |
7296
|
2843 |
|
2844 if (! error_state) |
7409
|
2845 Vdrawnow_requested = true; |
6406
|
2846 } |
|
2847 else |
|
2848 error ("__go%s__: unable to create graphics handle", |
|
2849 go_name.c_str ()); |
|
2850 } |
|
2851 else |
|
2852 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2853 } |
|
2854 else |
|
2855 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2856 |
|
2857 return retval; |
|
2858 } |
|
2859 |
|
2860 DEFUN (__go_figure__, args, , |
|
2861 "-*- texinfo -*-\n\ |
|
2862 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ |
6945
|
2863 Undocumented internal function.\n\ |
6406
|
2864 @end deftypefn") |
|
2865 { |
|
2866 octave_value retval; |
|
2867 |
|
2868 if (args.length () > 0) |
|
2869 { |
|
2870 double val = args(0).double_value (); |
|
2871 |
|
2872 if (! error_state) |
|
2873 { |
|
2874 if (is_figure (val)) |
|
2875 { |
|
2876 graphics_handle h = gh_manager::lookup (val); |
|
2877 |
|
2878 xset (h, args.splice (0, 1)); |
|
2879 |
6874
|
2880 retval = h.value (); |
6406
|
2881 } |
|
2882 else |
|
2883 { |
|
2884 graphics_handle h = octave_NaN; |
|
2885 |
|
2886 if (xisnan (val)) |
7370
|
2887 h = gh_manager::make_graphics_handle ("figure", 0, false); |
6406
|
2888 else if (val > 0 && D_NINT (val) == val) |
|
2889 h = gh_manager::make_figure_handle (val); |
|
2890 else |
|
2891 error ("__go_figure__: invalid figure number"); |
|
2892 |
7056
|
2893 if (! error_state && h.ok ()) |
6406
|
2894 { |
|
2895 adopt (0, h); |
|
2896 |
|
2897 xset (h, args.splice (0, 1)); |
7370
|
2898 xcreatefcn (h); |
6406
|
2899 |
6874
|
2900 retval = h.value (); |
6406
|
2901 } |
|
2902 else |
|
2903 error ("__go_figure__: failed to create figure handle"); |
|
2904 } |
|
2905 } |
|
2906 else |
|
2907 error ("__go_figure__: expecting figure number to be double value"); |
|
2908 } |
|
2909 else |
|
2910 print_usage (); |
|
2911 |
|
2912 return retval; |
|
2913 } |
|
2914 |
|
2915 #define GO_BODY(TYPE) \ |
|
2916 octave_value retval; \ |
|
2917 \ |
|
2918 if (args.length () > 0) \ |
|
2919 retval = make_graphics_object (#TYPE, args); \ |
|
2920 else \ |
|
2921 print_usage (); \ |
|
2922 \ |
|
2923 return retval |
|
2924 |
|
2925 DEFUN (__go_axes__, args, , |
|
2926 "-*- texinfo -*-\n\ |
|
2927 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ |
6945
|
2928 Undocumented internal function.\n\ |
6406
|
2929 @end deftypefn") |
|
2930 { |
|
2931 GO_BODY (axes); |
|
2932 } |
|
2933 |
|
2934 DEFUN (__go_line__, args, , |
|
2935 "-*- texinfo -*-\n\ |
|
2936 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ |
6945
|
2937 Undocumented internal function.\n\ |
6406
|
2938 @end deftypefn") |
|
2939 { |
|
2940 GO_BODY (line); |
|
2941 } |
|
2942 |
|
2943 DEFUN (__go_text__, args, , |
|
2944 "-*- texinfo -*-\n\ |
|
2945 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ |
6945
|
2946 Undocumented internal function.\n\ |
6406
|
2947 @end deftypefn") |
|
2948 { |
|
2949 GO_BODY (text); |
|
2950 } |
|
2951 |
|
2952 DEFUN (__go_image__, args, , |
|
2953 "-*- texinfo -*-\n\ |
|
2954 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ |
6945
|
2955 Undocumented internal function.\n\ |
6406
|
2956 @end deftypefn") |
|
2957 { |
|
2958 GO_BODY (image); |
|
2959 } |
|
2960 |
|
2961 DEFUN (__go_surface__, args, , |
|
2962 "-*- texinfo -*-\n\ |
|
2963 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ |
6945
|
2964 Undocumented internal function.\n\ |
6406
|
2965 @end deftypefn") |
|
2966 { |
|
2967 GO_BODY (surface); |
|
2968 } |
|
2969 |
6807
|
2970 DEFUN (__go_patch__, args, , |
|
2971 "-*- texinfo -*-\n\ |
|
2972 @deftypefn {Built-in Function} {} __go_patch__ (@var{parent})\n\ |
6945
|
2973 Undocumented internal function.\n\ |
6807
|
2974 @end deftypefn") |
|
2975 { |
|
2976 GO_BODY (patch); |
|
2977 } |
|
2978 |
6406
|
2979 DEFUN (__go_delete__, args, , |
|
2980 "-*- texinfo -*-\n\ |
|
2981 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ |
6945
|
2982 Undocumented internal function.\n\ |
6406
|
2983 @end deftypefn") |
|
2984 { |
|
2985 octave_value_list retval; |
|
2986 |
|
2987 if (args.length () == 1) |
|
2988 { |
|
2989 graphics_handle h = octave_NaN; |
|
2990 |
|
2991 double val = args(0).double_value (); |
|
2992 |
|
2993 if (! error_state) |
|
2994 { |
|
2995 h = gh_manager::lookup (val); |
|
2996 |
7056
|
2997 if (h.ok ()) |
6406
|
2998 { |
|
2999 graphics_object obj = gh_manager::get_object (h); |
|
3000 |
|
3001 graphics_handle parent_h = obj.get_parent (); |
|
3002 |
|
3003 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
3004 |
7367
|
3005 // NOTE: free the handle before removing it from its parent's |
|
3006 // children, such that the object's state is correct when |
|
3007 // the deletefcn callback is executed |
6406
|
3008 |
|
3009 gh_manager::free (h); |
7367
|
3010 |
|
3011 parent_obj.remove_child (h); |
6406
|
3012 } |
|
3013 else |
|
3014 error ("delete: invalid graphics object (= %g)", val); |
|
3015 } |
|
3016 else |
|
3017 error ("delete: invalid graphics object"); |
|
3018 } |
|
3019 else |
|
3020 print_usage (); |
|
3021 |
|
3022 return retval; |
|
3023 } |
|
3024 |
|
3025 DEFUN (__go_axes_init__, args, , |
|
3026 "-*- texinfo -*-\n\ |
|
3027 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ |
6945
|
3028 Undocumented internal function.\n\ |
6406
|
3029 @end deftypefn") |
|
3030 { |
|
3031 octave_value retval; |
|
3032 |
|
3033 int nargin = args.length (); |
|
3034 |
|
3035 std::string mode = ""; |
|
3036 |
|
3037 if (nargin == 2) |
|
3038 { |
|
3039 mode = args(1).string_value (); |
|
3040 |
|
3041 if (error_state) |
|
3042 return retval; |
|
3043 } |
|
3044 |
|
3045 if (nargin == 1 || nargin == 2) |
|
3046 { |
|
3047 graphics_handle h = octave_NaN; |
|
3048 |
|
3049 double val = args(0).double_value (); |
|
3050 |
|
3051 if (! error_state) |
|
3052 { |
|
3053 h = gh_manager::lookup (val); |
|
3054 |
7056
|
3055 if (h.ok ()) |
6406
|
3056 { |
|
3057 graphics_object obj = gh_manager::get_object (h); |
|
3058 |
|
3059 obj.set_defaults (mode); |
|
3060 } |
|
3061 else |
|
3062 error ("__go_axes_init__: invalid graphics object (= %g)", val); |
|
3063 } |
|
3064 else |
|
3065 error ("__go_axes_init__: invalid graphics object"); |
|
3066 } |
|
3067 else |
|
3068 print_usage (); |
|
3069 |
|
3070 return retval; |
|
3071 } |
|
3072 |
|
3073 DEFUN (__go_handles__, , , |
|
3074 "-*- texinfo -*-\n\ |
|
3075 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ |
6945
|
3076 Undocumented internal function.\n\ |
6406
|
3077 @end deftypefn") |
|
3078 { |
6425
|
3079 return octave_value (gh_manager::handle_list ()); |
|
3080 } |
|
3081 |
|
3082 DEFUN (__go_figure_handles__, , , |
|
3083 "-*- texinfo -*-\n\ |
|
3084 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ |
6945
|
3085 Undocumented internal function.\n\ |
6425
|
3086 @end deftypefn") |
|
3087 { |
|
3088 return octave_value (gh_manager::figure_handle_list ()); |
6406
|
3089 } |
|
3090 |
7409
|
3091 static void |
|
3092 clear_drawnow_request (void *) |
|
3093 { |
|
3094 Vdrawnow_requested = false; |
|
3095 } |
|
3096 |
7408
|
3097 DEFUN (drawnow, args, , |
|
3098 "-*- texinfo -*-\n\ |
|
3099 @deftypefn {Built-in Function} {} __go_drawnow__ ()\n\ |
|
3100 @deftypefnx {Built-in Function} {} __go_drawnow__ (@var{term}, @var{file}, @var{mono}, @var{debug_file})\n\ |
|
3101 Undocumented internal function.\n\ |
|
3102 @end deftypefn") |
|
3103 { |
|
3104 static int drawnow_executing = 0; |
|
3105 static bool __go_close_all_registered__ = false; |
|
3106 |
|
3107 octave_value retval; |
|
3108 |
7409
|
3109 unwind_protect::begin_frame ("Fdrawnow"); |
|
3110 unwind_protect::add (clear_drawnow_request); |
|
3111 |
|
3112 unwind_protect_int (drawnow_executing); |
|
3113 |
|
3114 if (++drawnow_executing <= 1) |
7408
|
3115 { |
7409
|
3116 if (! __go_close_all_registered__) |
|
3117 { |
|
3118 octave_add_atexit_function ("__go_close_all__"); |
|
3119 |
|
3120 __go_close_all_registered__ = true; |
|
3121 } |
|
3122 |
|
3123 if (args.length () == 0) |
7408
|
3124 { |
7409
|
3125 Matrix hlist = gh_manager::figure_handle_list (); |
|
3126 |
|
3127 for (int i = 0; ! error_state && i < hlist.length (); i++) |
7408
|
3128 { |
7409
|
3129 graphics_handle h = gh_manager::lookup (hlist(i)); |
|
3130 |
|
3131 if (h.ok () && h != 0) |
7408
|
3132 { |
7409
|
3133 graphics_object go = gh_manager::get_object (h); |
|
3134 figure::properties& fprops = dynamic_cast <figure::properties&> (go.get_properties ()); |
|
3135 |
|
3136 if (fprops.is_modified ()) |
7408
|
3137 { |
7409
|
3138 if (fprops.is_visible ()) |
|
3139 fprops.get_backend ().redraw_figure (h); |
|
3140 else if (! fprops.get___plot_stream__ ().is_empty ()) |
|
3141 { |
|
3142 fprops.close (false); |
|
3143 fprops.set___plot_stream__ (Matrix ()); |
|
3144 fprops.set___enhanced__ (false); |
|
3145 } |
|
3146 fprops.set_modified (false); |
7408
|
3147 } |
|
3148 } |
|
3149 } |
|
3150 } |
7409
|
3151 else if (args.length () >= 2 && args.length () <= 4) |
7408
|
3152 { |
7409
|
3153 std::string term, file, debug_file; |
|
3154 bool mono; |
|
3155 |
|
3156 term = args(0).string_value (); |
7408
|
3157 |
|
3158 if (! error_state) |
|
3159 { |
7409
|
3160 file = args(1).string_value (); |
7408
|
3161 |
|
3162 if (! error_state) |
|
3163 { |
7409
|
3164 size_t pos = file.find_last_of (file_ops::dir_sep_chars); |
|
3165 |
|
3166 if (pos != NPOS) |
|
3167 { |
|
3168 file_stat fs (file.substr (0, pos)); |
|
3169 |
|
3170 if (! (fs && fs.is_dir ())) |
|
3171 error ("drawnow: nonexistent directory `%s'", |
|
3172 file.substr (0, pos).c_str ()); |
|
3173 } |
|
3174 |
|
3175 mono = (args.length () >= 3 ? args(2).bool_value () : false); |
7408
|
3176 |
|
3177 if (! error_state) |
|
3178 { |
7409
|
3179 debug_file = (args.length () > 3 ? args(3).string_value () |
|
3180 : ""); |
|
3181 |
|
3182 if (! error_state) |
7408
|
3183 { |
7409
|
3184 graphics_handle h = gcf (); |
|
3185 |
|
3186 if (h.ok ()) |
|
3187 { |
|
3188 graphics_object go = gh_manager::get_object (h); |
|
3189 |
7419
|
3190 go.get_backend () |
7409
|
3191 .print_figure (h, term, file, mono, debug_file); |
|
3192 } |
|
3193 else |
|
3194 error ("drawnow: nothing to draw"); |
7408
|
3195 } |
|
3196 else |
7409
|
3197 error ("drawnow: invalid debug_file, expected a string value"); |
7408
|
3198 } |
|
3199 else |
7409
|
3200 error ("drawnow: invalid colormode, expected a boolean value"); |
7408
|
3201 } |
|
3202 else |
7409
|
3203 error ("drawnow: invalid file, expected a string value"); |
7408
|
3204 } |
|
3205 else |
7409
|
3206 error ("drawnow: invalid terminal, expected a string value"); |
7408
|
3207 } |
|
3208 else |
7409
|
3209 print_usage (); |
7408
|
3210 } |
7409
|
3211 |
|
3212 unwind_protect::run_frame ("Fdrawnow"); |
7408
|
3213 |
|
3214 return retval; |
|
3215 } |
|
3216 |
6595
|
3217 octave_value |
|
3218 get_property_from_handle (double handle, const std::string &property, |
|
3219 const std::string &func) |
|
3220 { |
|
3221 graphics_object obj = gh_manager::get_object (handle); |
|
3222 octave_value retval; |
|
3223 |
|
3224 if (obj) |
|
3225 { |
7189
|
3226 caseless_str p = std::string (property); |
6595
|
3227 retval = obj.get (p); |
|
3228 } |
|
3229 else |
|
3230 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
3231 |
|
3232 return retval; |
|
3233 } |
|
3234 |
|
3235 bool |
|
3236 set_property_in_handle (double handle, const std::string &property, |
|
3237 const octave_value &arg, const std::string &func) |
|
3238 { |
|
3239 graphics_object obj = gh_manager::get_object (handle); |
|
3240 int ret = false; |
|
3241 |
|
3242 if (obj) |
|
3243 { |
7189
|
3244 caseless_str p = std::string (property); |
6595
|
3245 obj.set (p, arg); |
|
3246 if (!error_state) |
|
3247 ret = true; |
|
3248 } |
|
3249 else |
|
3250 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
3251 |
|
3252 return ret; |
|
3253 } |
|
3254 |
6406
|
3255 /* |
|
3256 ;;; Local Variables: *** |
|
3257 ;;; mode: C++ *** |
|
3258 ;;; End: *** |
|
3259 */ |