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 |
7447
|
1422 figure::properties::get_boundingbox (bool) const |
7445
|
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)--; |
7447
|
1434 pos(1) = screen_size(1) - pos(1) - pos(3); |
7445
|
1435 |
|
1436 return pos; |
|
1437 } |
|
1438 |
6836
|
1439 octave_value |
7189
|
1440 figure::get_default (const caseless_str& name) const |
6836
|
1441 { |
|
1442 octave_value retval = default_properties.lookup (name); |
|
1443 |
|
1444 if (retval.is_undefined ()) |
|
1445 { |
|
1446 graphics_handle parent = get_parent (); |
|
1447 graphics_object parent_obj = gh_manager::get_object (parent); |
|
1448 |
|
1449 retval = parent_obj.get_default (name); |
|
1450 } |
|
1451 |
|
1452 return retval; |
|
1453 } |
|
1454 |
6406
|
1455 // --------------------------------------------------------------------- |
|
1456 |
7363
|
1457 void |
|
1458 axes::properties::set_title (const octave_value& v) |
6962
|
1459 { |
7363
|
1460 graphics_handle val = ::reparent (v, "set", "title", __myhandle__, false); |
6962
|
1461 |
6874
|
1462 if (! error_state) |
|
1463 { |
7363
|
1464 gh_manager::free (title.handle_value ()); |
6874
|
1465 title = val; |
|
1466 } |
|
1467 } |
|
1468 |
|
1469 void |
7363
|
1470 axes::properties::set_xlabel (const octave_value& v) |
6874
|
1471 { |
7363
|
1472 graphics_handle val = ::reparent (v, "set", "xlabel", __myhandle__, false); |
6874
|
1473 |
|
1474 if (! error_state) |
|
1475 { |
7363
|
1476 gh_manager::free (xlabel.handle_value ()); |
6874
|
1477 xlabel = val; |
|
1478 } |
|
1479 } |
|
1480 |
|
1481 void |
7363
|
1482 axes::properties::set_ylabel (const octave_value& v) |
6874
|
1483 { |
7363
|
1484 graphics_handle val = ::reparent (v, "set", "ylabel", __myhandle__, false); |
6874
|
1485 |
|
1486 if (! error_state) |
|
1487 { |
7363
|
1488 gh_manager::free (ylabel.handle_value ()); |
6874
|
1489 ylabel = val; |
|
1490 } |
|
1491 } |
|
1492 |
|
1493 void |
7363
|
1494 axes::properties::set_zlabel (const octave_value& v) |
6874
|
1495 { |
7363
|
1496 graphics_handle val = ::reparent (v, "set", "zlabel", __myhandle__, false); |
6874
|
1497 |
|
1498 if (! error_state) |
|
1499 { |
7363
|
1500 gh_manager::free (zlabel.handle_value ()); |
6874
|
1501 zlabel = val; |
|
1502 } |
|
1503 } |
|
1504 |
|
1505 void |
6844
|
1506 axes::properties::set_defaults (base_graphics_object& obj, |
6890
|
1507 const std::string& mode) |
6705
|
1508 { |
7427
|
1509 position = default_axes_position (); |
7363
|
1510 title = graphics_handle (); |
6705
|
1511 box = "on"; |
|
1512 key = "off"; |
|
1513 keybox = "off"; |
7363
|
1514 keypos = 1.0; |
6962
|
1515 colororder = default_colororder (); |
6705
|
1516 dataaspectratio = Matrix (1, 3, 1.0); |
|
1517 dataaspectratiomode = "auto"; |
7363
|
1518 layer = "bottom"; |
6705
|
1519 |
|
1520 Matrix tlim (1, 2, 0.0); |
|
1521 tlim(1) = 1; |
|
1522 xlim = tlim; |
|
1523 ylim = tlim; |
|
1524 zlim = tlim; |
6807
|
1525 |
|
1526 Matrix cl (1, 2, 0); |
|
1527 cl(1) = 1; |
|
1528 clim = cl; |
|
1529 |
7363
|
1530 xlimmode = "auto"; |
|
1531 ylimmode = "auto"; |
|
1532 zlimmode = "auto"; |
|
1533 climmode = "auto"; |
|
1534 xlabel = graphics_handle (); |
|
1535 ylabel = graphics_handle (); |
|
1536 zlabel = graphics_handle (); |
6705
|
1537 xgrid = "off"; |
|
1538 ygrid = "off"; |
|
1539 zgrid = "off"; |
|
1540 xminorgrid = "off"; |
|
1541 yminorgrid = "off"; |
|
1542 zminorgrid = "off"; |
|
1543 xtick = Matrix (); |
|
1544 ytick = Matrix (); |
|
1545 ztick = Matrix (); |
|
1546 xtickmode = "auto"; |
|
1547 ytickmode = "auto"; |
|
1548 ztickmode = "auto"; |
|
1549 xticklabel = ""; |
|
1550 yticklabel = ""; |
|
1551 zticklabel = ""; |
|
1552 xticklabelmode = "auto"; |
|
1553 yticklabelmode = "auto"; |
|
1554 zticklabelmode = "auto"; |
7364
|
1555 color = color_values (0, 0, 0); |
|
1556 xcolor = color_values ("black"); |
|
1557 ycolor = color_values ("black"); |
|
1558 zcolor = color_values ("black"); |
7363
|
1559 xscale = "linear"; |
|
1560 yscale = "linear"; |
|
1561 zscale = "linear"; |
6705
|
1562 xdir = "normal"; |
|
1563 ydir = "normal"; |
|
1564 zdir = "normal"; |
7363
|
1565 yaxislocation = "left"; |
|
1566 xaxislocation = "bottom"; |
6705
|
1567 |
7427
|
1568 // Note: camera properties will be set through update_transform |
|
1569 camerapositionmode = "auto"; |
|
1570 cameratargetmode = "auto"; |
|
1571 cameraupvectormode = "auto"; |
|
1572 cameraviewanglemode = "auto"; |
|
1573 plotboxaspectratio = Matrix (1, 3, 1.0); |
|
1574 drawmode = "normal"; |
|
1575 fontangle = "normal"; |
|
1576 fontname = "Helvetica"; |
|
1577 fontsize = 12; |
|
1578 fontunits = "points"; |
|
1579 fontweight = "normal"; |
|
1580 gridlinestyle = "-"; |
|
1581 linestyleorder = "-"; |
|
1582 linewidth = 0.5; |
|
1583 minorgridlinestyle = "-"; |
|
1584 // Note: plotboxaspectratio will be set through update_aspectratiors |
|
1585 plotboxaspectratiomode = "auto"; |
|
1586 projection = "orthographic"; |
|
1587 tickdir = "in"; |
|
1588 tickdirmode = "auto"; |
|
1589 ticklength = Matrix (1, 2, 0.1); |
|
1590 tightinset = Matrix (1, 4, 0.0); |
|
1591 |
|
1592 sx = "linear"; |
|
1593 sy = "linear"; |
|
1594 sz = "linear"; |
|
1595 |
6705
|
1596 Matrix tview (1, 2, 0.0); |
|
1597 tview(1) = 90; |
|
1598 view = tview; |
|
1599 |
6765
|
1600 visible = "on"; |
6705
|
1601 nextplot = "replace"; |
|
1602 |
|
1603 // FIXME -- this is not quite right; we should preserve |
|
1604 // "position" and "units". |
|
1605 |
|
1606 if (mode != "replace") |
|
1607 { |
6406
|
1608 Matrix touterposition (1, 4, 0.0); |
|
1609 touterposition(2) = 1; |
|
1610 touterposition(3) = 1; |
|
1611 outerposition = touterposition; |
|
1612 } |
|
1613 |
7363
|
1614 activepositionproperty = "outerposition"; |
|
1615 __colorbar__ = "none"; |
7189
|
1616 |
6705
|
1617 delete_children (); |
6406
|
1618 |
6705
|
1619 children = Matrix (); |
6432
|
1620 |
7427
|
1621 update_transform (); |
|
1622 |
6705
|
1623 override_defaults (obj); |
|
1624 } |
|
1625 |
6874
|
1626 graphics_handle |
|
1627 axes::properties::get_title (void) const |
|
1628 { |
7363
|
1629 if (! title.handle_value ().ok ()) |
6874
|
1630 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1631 |
7363
|
1632 return title.handle_value (); |
6874
|
1633 } |
|
1634 |
|
1635 graphics_handle |
|
1636 axes::properties::get_xlabel (void) const |
|
1637 { |
7363
|
1638 if (! xlabel.handle_value ().ok ()) |
6874
|
1639 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1640 |
7363
|
1641 return xlabel.handle_value (); |
6874
|
1642 } |
|
1643 |
|
1644 graphics_handle |
|
1645 axes::properties::get_ylabel (void) const |
|
1646 { |
7363
|
1647 if (! ylabel.handle_value ().ok ()) |
6874
|
1648 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1649 |
7363
|
1650 return ylabel.handle_value (); |
6874
|
1651 } |
|
1652 |
|
1653 graphics_handle |
|
1654 axes::properties::get_zlabel (void) const |
|
1655 { |
7363
|
1656 if (! zlabel.handle_value ().ok ()) |
6874
|
1657 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1658 |
7363
|
1659 return zlabel.handle_value (); |
6705
|
1660 } |
6406
|
1661 |
6705
|
1662 void |
6844
|
1663 axes::properties::remove_child (const graphics_handle& h) |
6705
|
1664 { |
7363
|
1665 if (title.handle_value ().ok () && h == title.handle_value ()) |
6705
|
1666 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1667 else if (xlabel.handle_value ().ok () && h == xlabel.handle_value ()) |
6705
|
1668 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1669 else if (ylabel.handle_value ().ok () && h == ylabel.handle_value ()) |
6705
|
1670 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363
|
1671 else if (zlabel.handle_value ().ok () && h == zlabel.handle_value ()) |
6705
|
1672 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
|
1673 else |
|
1674 base_properties::remove_child (h); |
|
1675 } |
6406
|
1676 |
6705
|
1677 void |
6844
|
1678 axes::properties::delete_children (void) |
6705
|
1679 { |
|
1680 base_properties::delete_children (); |
|
1681 |
7363
|
1682 gh_manager::free (title.handle_value ()); |
|
1683 gh_manager::free (xlabel.handle_value ()); |
|
1684 gh_manager::free (ylabel.handle_value ()); |
|
1685 gh_manager::free (zlabel.handle_value ()); |
6705
|
1686 } |
6406
|
1687 |
7427
|
1688 inline Matrix |
|
1689 xform_matrix (void) |
|
1690 { |
|
1691 Matrix m (4, 4, 0.0); |
|
1692 for (int i = 0; i < 4; i++) |
|
1693 m(i,i) = 1; |
|
1694 return m; |
|
1695 } |
|
1696 |
|
1697 inline ColumnVector |
|
1698 xform_vector (void) |
|
1699 { |
|
1700 ColumnVector v (4, 0.0); |
|
1701 v(3) = 1; |
|
1702 return v; |
|
1703 } |
|
1704 |
|
1705 inline ColumnVector |
|
1706 xform_vector (double x, double y, double z) |
|
1707 { |
|
1708 ColumnVector v (4, 1.0); |
|
1709 v(0) = x; v(1) = y; v(2) = z; |
|
1710 return v; |
|
1711 } |
|
1712 |
|
1713 inline ColumnVector |
|
1714 transform (const Matrix& m, double x, double y, double z) |
|
1715 { |
|
1716 return (m * xform_vector (x, y, z)); |
|
1717 } |
|
1718 |
|
1719 inline Matrix |
|
1720 xform_scale (double x, double y, double z) |
|
1721 { |
|
1722 Matrix m (4, 4, 0.0); |
|
1723 m(0,0) = x; m(1,1) = y; m(2,2) = z; m(3,3) = 1; |
|
1724 return m; |
|
1725 } |
|
1726 |
|
1727 inline Matrix |
|
1728 xform_translate (double x, double y, double z) |
|
1729 { |
|
1730 Matrix m = xform_matrix (); |
|
1731 m(0,3) = x; m(1,3) = y; m(2,3) = z; m(3,3) = 1; |
|
1732 return m; |
|
1733 } |
|
1734 |
|
1735 inline void |
|
1736 scale (Matrix& m, double x, double y, double z) |
|
1737 { |
|
1738 m = m * xform_scale (x, y, z); |
|
1739 } |
|
1740 |
|
1741 inline void |
|
1742 translate (Matrix& m, double x, double y, double z) |
|
1743 { |
|
1744 m = m * xform_translate (x, y, z); |
|
1745 } |
|
1746 |
|
1747 inline void |
|
1748 xform (ColumnVector& v, const Matrix& m) |
|
1749 { |
|
1750 v = m*v; |
|
1751 } |
|
1752 |
|
1753 inline void |
|
1754 scale (ColumnVector& v, double x, double y, double z) |
|
1755 { |
|
1756 v(0) *= x; |
|
1757 v(1) *= y; |
|
1758 v(2) *= z; |
|
1759 } |
|
1760 |
|
1761 inline void |
|
1762 translate (ColumnVector& v, double x, double y, double z) |
|
1763 { |
|
1764 v(0) += x; |
|
1765 v(1) += y; |
|
1766 v(2) += z; |
|
1767 } |
|
1768 |
|
1769 inline void |
|
1770 normalize (ColumnVector& v) |
|
1771 { |
|
1772 double fact = 1.0/sqrt(v(0)*v(0)+v(1)*v(1)+v(2)*v(2)); |
|
1773 scale (v, fact, fact, fact); |
|
1774 } |
|
1775 |
|
1776 inline double |
|
1777 dot (const ColumnVector& v1, const ColumnVector& v2) |
|
1778 { |
|
1779 return (v1(0)*v2(0)+v1(1)*v2(1)+v1(2)*v2(2)); |
|
1780 } |
|
1781 |
|
1782 inline double |
|
1783 norm (const ColumnVector& v) |
|
1784 { |
|
1785 return sqrt (dot (v, v)); |
|
1786 } |
|
1787 |
|
1788 inline ColumnVector |
|
1789 cross (const ColumnVector& v1, const ColumnVector& v2) |
|
1790 { |
|
1791 ColumnVector r = xform_vector (); |
|
1792 r(0) = v1(1)*v2(2)-v1(2)*v2(1); |
|
1793 r(1) = v1(2)*v2(0)-v1(0)*v2(2); |
|
1794 r(2) = v1(0)*v2(1)-v1(1)*v2(0); |
|
1795 return r; |
|
1796 } |
|
1797 |
|
1798 inline Matrix |
|
1799 unit_cube (void) |
|
1800 { |
|
1801 static double data[32] = { |
|
1802 0,0,0,1, |
|
1803 1,0,0,1, |
|
1804 0,1,0,1, |
|
1805 0,0,1,1, |
|
1806 1,1,0,1, |
|
1807 1,0,1,1, |
|
1808 0,1,1,1, |
|
1809 1,1,1,1}; |
|
1810 Matrix m (4, 8); |
|
1811 memcpy (m.fortran_vec (), data, sizeof(double)*32); |
|
1812 return m; |
|
1813 } |
|
1814 |
|
1815 inline ColumnVector |
|
1816 cam2xform (const Array<double>& m) |
|
1817 { |
|
1818 ColumnVector retval (4, 1.0); |
|
1819 memcpy (retval.fortran_vec (), m.fortran_vec (), sizeof(double)*3); |
|
1820 return retval; |
|
1821 } |
|
1822 |
|
1823 inline RowVector |
|
1824 xform2cam (const ColumnVector& v) |
|
1825 { |
|
1826 return v.extract_n (0, 3).transpose (); |
|
1827 } |
|
1828 |
|
1829 void |
|
1830 axes::properties::update_camera (void) |
|
1831 { |
|
1832 double xd = (xdir_is ("normal") ? 1 : -1); |
|
1833 double yd = (ydir_is ("normal") ? 1 : -1); |
|
1834 double zd = (zdir_is ("normal") ? 1 : -1); |
|
1835 |
|
1836 Matrix xlim = sx.scale (get_xlim ().matrix_value ()); |
|
1837 Matrix ylim = sy.scale (get_ylim ().matrix_value ()); |
|
1838 Matrix zlim = sz.scale (get_zlim ().matrix_value ()); |
|
1839 |
|
1840 double xo = xlim(xd > 0 ? 0 : 1); |
|
1841 double yo = ylim(yd > 0 ? 0 : 1); |
|
1842 double zo = zlim(zd > 0 ? 0 : 1); |
|
1843 |
|
1844 Matrix pb = get_plotboxaspectratio ().matrix_value (); |
|
1845 |
|
1846 bool autocam = (camerapositionmode_is ("auto") |
|
1847 && cameratargetmode_is ("auto") |
|
1848 && cameraupvectormode_is ("auto") |
|
1849 && cameraviewanglemode_is ("auto")); |
|
1850 bool dowarp = (autocam && dataaspectratiomode_is("auto") |
|
1851 && plotboxaspectratiomode_is ("auto")); |
|
1852 |
|
1853 ColumnVector c_eye (xform_vector ()); |
|
1854 ColumnVector c_center (xform_vector ()); |
|
1855 ColumnVector c_upv (xform_vector ()); |
|
1856 |
|
1857 if (cameratargetmode_is ("auto")) |
|
1858 { |
|
1859 c_center(0) = (xlim(0)+xlim(1))/2; |
|
1860 c_center(1) = (ylim(0)+ylim(1))/2; |
|
1861 c_center(2) = (zlim(0)+zlim(1))/2; |
|
1862 |
|
1863 cameratarget = xform2cam (c_center); |
|
1864 } |
|
1865 else |
|
1866 c_center = cam2xform (get_cameratarget ().matrix_value ()); |
|
1867 |
|
1868 if (camerapositionmode_is ("auto")) |
|
1869 { |
|
1870 Matrix view = get_view ().matrix_value (); |
|
1871 double az = view(0), el = view(1); |
|
1872 double d = 5*sqrt(pb(0)*pb(0)+pb(1)*pb(1)+pb(2)*pb(2)); |
|
1873 |
|
1874 if (el == 90 || el == -90) |
|
1875 c_eye(2) = d*signum(el); |
|
1876 else |
|
1877 { |
|
1878 az *= M_PI/180.0; |
|
1879 el *= M_PI/180.0; |
|
1880 c_eye(0) = d*cos(el)*sin(az); |
|
1881 c_eye(1) = -d*cos(el)*cos(az); |
|
1882 c_eye(2) = d*sin(el); |
|
1883 } |
|
1884 c_eye(0) = c_eye(0)*(xlim(1)-xlim(0))/(xd*pb(0))+c_center(0); |
|
1885 c_eye(1) = c_eye(1)*(ylim(1)-ylim(0))/(yd*pb(1))+c_center(1); |
|
1886 c_eye(2) = c_eye(2)*(zlim(1)-zlim(0))/(zd*pb(2))+c_center(2); |
|
1887 |
|
1888 cameraposition = xform2cam (c_eye); |
|
1889 } |
|
1890 else |
|
1891 c_eye = cam2xform (get_cameraposition ().matrix_value ()); |
|
1892 |
|
1893 if (cameraupvectormode_is ("auto")) |
|
1894 { |
|
1895 Matrix view = get_view ().matrix_value (); |
|
1896 double az = view(0), el = view(1); |
|
1897 |
|
1898 if (el == 90 || el == -90) |
|
1899 { |
|
1900 c_upv(0) = -sin(az*M_PI/180.0)*(xlim(1)-xlim(0))/pb(0); |
|
1901 c_upv(1) = cos(az*M_PI/180.0)*(ylim(1)-ylim(0))/pb(1); |
|
1902 } |
|
1903 else |
|
1904 c_upv(2) = 1; |
|
1905 |
|
1906 cameraupvector = xform2cam (c_upv); |
|
1907 } |
|
1908 else |
|
1909 c_upv = cam2xform (get_cameraupvector ().matrix_value ()); |
|
1910 |
|
1911 Matrix x_view = xform_matrix (); |
|
1912 Matrix x_projection = xform_matrix (); |
|
1913 Matrix x_viewport = xform_matrix (); |
|
1914 Matrix x_normrender = xform_matrix (); |
|
1915 Matrix x_pre = xform_matrix (); |
|
1916 |
|
1917 x_render = xform_matrix (); |
|
1918 x_render_inv = xform_matrix (); |
|
1919 |
|
1920 scale (x_pre, pb(0), pb(1), pb(2)); |
|
1921 translate (x_pre, -0.5, -0.5, -0.5); |
|
1922 scale (x_pre, xd/(xlim(1)-xlim(0)), yd/(ylim(1)-ylim(0)), |
|
1923 zd/(zlim(1)-zlim(0))); |
|
1924 translate (x_pre, -xo, -yo, -zo); |
|
1925 |
|
1926 xform (c_eye, x_pre); |
|
1927 xform (c_center, x_pre); |
|
1928 scale (c_upv, pb(0)/(xlim(1)-xlim(0)), pb(1)/(ylim(1)-ylim(0)), |
|
1929 pb(2)/(zlim(1)-zlim(0))); |
|
1930 translate (c_center, -c_eye(0), -c_eye(1), -c_eye(2)); |
|
1931 |
|
1932 ColumnVector F (c_center), f (F), UP (c_upv); |
|
1933 normalize (f); |
|
1934 normalize (UP); |
|
1935 |
7440
|
1936 if (std::abs (dot (f, UP)) > 1e-15) |
7427
|
1937 { |
|
1938 double fa = 1/sqrt(1-f(2)*f(2)); |
|
1939 scale (UP, fa, fa, fa); |
|
1940 } |
|
1941 |
|
1942 ColumnVector s = cross (f, UP); |
|
1943 ColumnVector u = cross (s, f); |
|
1944 |
|
1945 scale (x_view, 1, 1, -1); |
|
1946 Matrix l = xform_matrix (); |
|
1947 l(0,0) = s(0); l(0,1) = s(1); l(0,2) = s(2); |
|
1948 l(1,0) = u(0); l(1,1) = u(1); l(1,2) = u(2); |
|
1949 l(2,0) = -f(0); l(2,1) = -f(1); l(2,2) = -f(2); |
|
1950 x_view = x_view * l; |
|
1951 translate (x_view, -c_eye(0), -c_eye(1), -c_eye(2)); |
|
1952 scale (x_view, pb(0), pb(1), pb(2)); |
|
1953 translate (x_view, -0.5, -0.5, -0.5); |
|
1954 |
|
1955 Matrix x_cube = x_view * unit_cube (); |
|
1956 ColumnVector cmin = x_cube.row_min (), cmax = x_cube.row_max (); |
|
1957 double xM = cmax(0)-cmin(0); |
|
1958 double yM = cmax(1)-cmin(1); |
|
1959 |
7447
|
1960 Matrix bb = get_boundingbox (true); |
7427
|
1961 |
|
1962 double v_angle; |
|
1963 |
|
1964 if (cameraviewanglemode_is ("auto")) |
|
1965 { |
|
1966 double af; |
|
1967 |
|
1968 // FIXME: Was this really needed? When compared to Matlab, it |
|
1969 // does not seem to be required. Need investigation with concrete |
|
1970 // backend to see results visually. |
|
1971 if (false && dowarp) |
|
1972 af = 1.0 / (xM > yM ? xM : yM); |
|
1973 else |
|
1974 { |
|
1975 if ((bb(2)/bb(3)) > (xM/yM)) |
|
1976 af = 1.0 / yM; |
|
1977 else |
|
1978 af = 1.0 / xM; |
|
1979 } |
|
1980 v_angle = 2 * (180.0 / M_PI) * atan (1 / (2 * af * norm (F))); |
|
1981 |
|
1982 cameraviewangle = v_angle; |
|
1983 } |
|
1984 else |
|
1985 v_angle = get_cameraviewangle (); |
|
1986 |
|
1987 double pf = 1 / (2 * tan ((v_angle / 2) * M_PI / 180.0) * norm (F)); |
|
1988 scale (x_projection, pf, pf, 1); |
|
1989 |
|
1990 if (dowarp) |
|
1991 { |
|
1992 xM *= pf; |
|
1993 yM *= pf; |
7447
|
1994 translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); |
7427
|
1995 scale (x_viewport, bb(2)/xM, -bb(3)/yM, 1); |
|
1996 } |
|
1997 else |
|
1998 { |
|
1999 double pix = 1; |
|
2000 if (autocam) |
|
2001 { |
|
2002 if ((bb(2)/bb(3)) > (xM/yM)) |
|
2003 pix = bb(3); |
|
2004 else |
|
2005 pix = bb(2); |
|
2006 } |
|
2007 else |
|
2008 pix = (bb(2) < bb(3) ? bb(2) : bb(3)); |
7447
|
2009 translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); |
7427
|
2010 scale (x_viewport, pix, -pix, 1); |
|
2011 } |
|
2012 |
|
2013 x_normrender = x_viewport * x_projection * x_view; |
|
2014 |
|
2015 x_cube = x_normrender * unit_cube (); |
|
2016 cmin = x_cube.row_min (); |
|
2017 cmax = x_cube.row_max (); |
|
2018 x_zlim.resize (1, 2); |
|
2019 x_zlim(0) = cmin(2); |
|
2020 x_zlim(1) = cmax(2); |
|
2021 |
|
2022 x_render = x_normrender; |
|
2023 scale (x_render, xd/(xlim(1)-xlim(0)), yd/(ylim(1)-ylim(0)), |
|
2024 zd/(zlim(1)-zlim(0))); |
|
2025 translate (x_render, -xo, -yo, -zo); |
|
2026 |
|
2027 x_viewtransform = x_view; |
|
2028 x_projectiontransform = x_projection; |
|
2029 x_viewporttransform = x_viewport; |
|
2030 x_normrendertransform = x_normrender; |
|
2031 x_rendertransform = x_render; |
|
2032 |
|
2033 x_render_inv = x_render.inverse (); |
|
2034 |
|
2035 // Note: these matrices are a slight modified version of the regular |
|
2036 // matrices, more suited for OpenGL rendering (x_gl_mat1 => light |
|
2037 // => x_gl_mat2) |
|
2038 x_gl_mat1 = x_view; |
|
2039 scale (x_gl_mat1, xd/(xlim(1)-xlim(0)), yd/(ylim(1)-ylim(0)), |
|
2040 zd/(zlim(1)-zlim(0))); |
|
2041 translate (x_gl_mat1, -xo, -yo, -zo); |
|
2042 x_gl_mat2 = x_viewport * x_projection; |
|
2043 } |
|
2044 |
|
2045 void |
|
2046 axes::properties::update_aspectratios (void) |
|
2047 { |
|
2048 Matrix xlim = get_xlim ().matrix_value (); |
|
2049 Matrix ylim = get_ylim ().matrix_value (); |
|
2050 Matrix zlim = get_zlim ().matrix_value (); |
|
2051 |
|
2052 double dx = (xlim(1)-xlim(0)); |
|
2053 double dy = (ylim(1)-ylim(0)); |
|
2054 double dz = (zlim(1)-zlim(0)); |
|
2055 |
|
2056 if (dataaspectratiomode_is ("auto")) |
|
2057 { |
|
2058 double dmin = xmin (xmin (dx, dy), dz); |
|
2059 Matrix da (1, 3, 0.0); |
|
2060 |
|
2061 da(0) = dx/dmin; |
|
2062 da(1) = dy/dmin; |
|
2063 da(2) = dz/dmin; |
|
2064 |
|
2065 dataaspectratio = da; |
|
2066 } |
|
2067 |
|
2068 if (plotboxaspectratiomode_is ("auto")) |
|
2069 { |
|
2070 if (dataaspectratiomode_is ("auto")) |
|
2071 plotboxaspectratio = Matrix (1, 3, 1.0); |
|
2072 else |
|
2073 { |
|
2074 Matrix da = get_dataaspectratio ().matrix_value (); |
|
2075 Matrix pba (1, 3, 0.0); |
|
2076 |
|
2077 pba(0) = dx/da(0); |
|
2078 pba(1) = dy/da(1); |
|
2079 pba(2) = dz/da(2); |
|
2080 } |
|
2081 } |
|
2082 |
|
2083 // FIXME: if plotboxaspectratiomode is "manual", limits |
|
2084 // and/or dataaspectratio might be adapted |
|
2085 } |
|
2086 |
7447
|
2087 // The INTERNAL flag defines whether position or outerposition is used. |
|
2088 |
7427
|
2089 Matrix |
7447
|
2090 axes::properties::get_boundingbox (bool internal) const |
7427
|
2091 { |
7447
|
2092 graphics_object obj = gh_manager::get_object (get_parent ()); |
|
2093 Matrix parent_bb = obj.get_properties ().get_boundingbox (true); |
|
2094 Matrix pos = (internal ? |
|
2095 get_position ().matrix_value () |
|
2096 : get_outerposition ().matrix_value ()); |
|
2097 |
|
2098 |
|
2099 pos = convert_position (pos, get_units (), "pixels", |
|
2100 parent_bb.extract_n (0, 2, 1, 2), get_backend ()); |
7427
|
2101 pos(0)--; |
|
2102 pos(1)--; |
7447
|
2103 pos(1) = parent_bb(3) - pos(1) - pos(3); |
7427
|
2104 |
|
2105 return pos; |
|
2106 } |
|
2107 |
7435
|
2108 ColumnVector |
|
2109 graphics_xform::xform_vector (double x, double y, double z) |
|
2110 { return ::xform_vector (x, y, z); } |
|
2111 |
|
2112 Matrix |
|
2113 graphics_xform::xform_eye (void) |
|
2114 { return ::xform_matrix (); } |
|
2115 |
|
2116 ColumnVector |
|
2117 graphics_xform::transform (double x, double y, double z, |
|
2118 bool use_scale) const |
|
2119 { |
|
2120 if (use_scale) |
|
2121 { |
|
2122 x = sx.scale (x); |
|
2123 y = sy.scale (y); |
|
2124 z = sz.scale (z); |
|
2125 } |
|
2126 |
|
2127 return ::transform (xform, x, y, z); |
|
2128 } |
|
2129 |
|
2130 ColumnVector |
|
2131 graphics_xform::untransform (double x, double y, double z, |
|
2132 bool use_scale) const |
|
2133 { |
|
2134 ColumnVector v = ::transform (xform_inv, x, y, z); |
|
2135 |
|
2136 if (use_scale) |
|
2137 { |
|
2138 v(0) = sx.unscale (v(0)); |
|
2139 v(1) = sy.unscale (v(1)); |
|
2140 v(2) = sz.unscale (v(2)); |
|
2141 } |
|
2142 |
|
2143 return v; |
|
2144 } |
|
2145 |
6836
|
2146 octave_value |
7189
|
2147 axes::get_default (const caseless_str& name) const |
6836
|
2148 { |
|
2149 octave_value retval = default_properties.lookup (name); |
|
2150 |
|
2151 if (retval.is_undefined ()) |
|
2152 { |
|
2153 graphics_handle parent = get_parent (); |
|
2154 graphics_object parent_obj = gh_manager::get_object (parent); |
|
2155 |
|
2156 retval = parent_obj.get_default (name); |
|
2157 } |
|
2158 |
|
2159 return retval; |
|
2160 } |
|
2161 |
7222
|
2162 static void |
|
2163 check_limit_vals (double& min_val, double& max_val, double& min_pos, |
|
2164 const data_property& data) |
|
2165 { |
7267
|
2166 double val = data.min_val (); |
|
2167 if (! (xisinf (val) || xisnan (val)) && val < min_val) |
|
2168 min_val = val; |
|
2169 val = data.max_val (); |
|
2170 if (! (xisinf (val) || xisnan (val)) && val > max_val) |
|
2171 max_val = val; |
|
2172 val = data.min_pos (); |
|
2173 if (! (xisinf (val) || xisnan (val)) && val > 0 && val < min_pos) |
|
2174 min_pos = val; |
7222
|
2175 } |
|
2176 |
|
2177 // Attempt to make "nice" limits from the actual max and min of the |
|
2178 // data. For log plots, we will also use the smallest strictly positive |
|
2179 // value. |
|
2180 |
|
2181 static Matrix |
|
2182 get_axis_limits (double xmin, double xmax, double min_pos, bool logscale) |
|
2183 { |
|
2184 Matrix retval; |
|
2185 |
|
2186 double min_val = xmin; |
|
2187 double max_val = xmax; |
|
2188 |
|
2189 if (! (xisinf (min_val) || xisinf (max_val))) |
|
2190 { |
|
2191 if (logscale) |
|
2192 { |
|
2193 if (xisinf (min_pos)) |
|
2194 { |
|
2195 // warning ("axis: logscale with no positive values to plot"); |
|
2196 return retval; |
|
2197 } |
|
2198 |
|
2199 if (min_val <= 0) |
|
2200 { |
|
2201 warning ("axis: omitting nonpositive data in log plot"); |
|
2202 min_val = min_pos; |
|
2203 } |
|
2204 // FIXME -- maybe this test should also be relative? |
|
2205 if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) |
|
2206 { |
|
2207 min_val *= 0.9; |
|
2208 max_val *= 1.1; |
|
2209 } |
|
2210 min_val = pow (10, floor (log10 (min_val))); |
|
2211 max_val = pow (10, ceil (log10 (max_val))); |
|
2212 } |
|
2213 else |
|
2214 { |
|
2215 if (min_val == 0 && max_val == 0) |
|
2216 { |
|
2217 min_val = -1; |
|
2218 max_val = 1; |
|
2219 } |
|
2220 // FIXME -- maybe this test should also be relative? |
|
2221 else if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) |
|
2222 { |
|
2223 min_val -= 0.1 * std::abs (min_val); |
|
2224 max_val += 0.1 * std::abs (max_val); |
|
2225 } |
|
2226 // FIXME -- to do a better job, we should consider the tic spacing. |
|
2227 double scale = pow (10, floor (log10 (max_val - min_val) - 1)); |
|
2228 min_val = scale * floor (min_val / scale); |
|
2229 max_val = scale * ceil (max_val / scale); |
|
2230 } |
|
2231 } |
|
2232 |
|
2233 retval.resize (1, 2); |
|
2234 |
|
2235 retval(0) = min_val; |
|
2236 retval(1) = max_val; |
|
2237 |
|
2238 return retval; |
|
2239 } |
|
2240 |
7446
|
2241 // magform(x) Returns (a, b), where x = a * 10^b, a >= 1., and b is |
7447
|
2242 // integral. |
7446
|
2243 |
|
2244 void |
7447
|
2245 axes::properties::magform (double x, double& a, int& b) |
7446
|
2246 { |
|
2247 if (x == 0) |
|
2248 { |
|
2249 a = 0; |
|
2250 b = 0; |
|
2251 } |
|
2252 else |
|
2253 { |
|
2254 double l = std::log10 (std::abs (x)); |
|
2255 double r = std::fmod (l, 1.); |
|
2256 a = std::pow (10.0, r); |
|
2257 b = static_cast<int> (l-r); |
|
2258 if (a < 1) |
|
2259 { |
|
2260 a *= 10; |
|
2261 b -= 1; |
|
2262 } |
|
2263 |
|
2264 if (x < 0) |
|
2265 a = -a; |
|
2266 } |
|
2267 } |
|
2268 |
|
2269 // A translation from Tom Holoryd's python code at |
|
2270 // http://kurage.nimh.nih.gov/tomh/tics.py |
|
2271 // FIXME -- add log ticks |
7447
|
2272 |
7446
|
2273 void |
|
2274 axes::properties::calc_ticks (const array_property& lims, array_property& ticks) |
|
2275 { |
|
2276 int ticint = 5; |
|
2277 |
|
2278 if (lims.get ().is_empty ()) |
|
2279 return; |
|
2280 |
|
2281 double lo = (lims.get ().matrix_value ()) (0); |
|
2282 double hi = (lims.get ().matrix_value ()) (1); |
|
2283 |
|
2284 // Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and |
|
2285 // SCALE3 for Determination of Scales on Computer Generated |
|
2286 // Plots", Communications of the ACM, 10 (1973), 639-640. |
|
2287 // Also cited as ACM Algorithm 463. |
|
2288 |
|
2289 double a; |
|
2290 int b, x; |
7447
|
2291 |
|
2292 magform ((hi-lo)/ticint, a, b); |
|
2293 |
|
2294 static const double sqrt_2 = sqrt (2.0); |
|
2295 static const double sqrt_10 = sqrt (10.0); |
|
2296 static const double sqrt_50 = sqrt (50.0); |
|
2297 |
|
2298 if (a < sqrt_2) |
7446
|
2299 x = 1; |
7447
|
2300 else if (a < sqrt_10) |
7446
|
2301 x = 2; |
7447
|
2302 else if (a < sqrt_50) |
7446
|
2303 x = 5; |
|
2304 else |
|
2305 x = 10; |
|
2306 |
|
2307 double sep = x * std::pow (10., b); |
|
2308 |
|
2309 // FIXME x can now be used to set minor ticks |
|
2310 if (x == 10) |
|
2311 x = 1; |
|
2312 |
|
2313 // The following guarantees that if zero is in the range, it will be |
|
2314 // included as a tic. |
|
2315 |
|
2316 int i1 = static_cast<int> (std::floor (lo / sep)); |
|
2317 int i2 = static_cast<int> (std::ceil (hi / sep)); |
|
2318 |
|
2319 Matrix limits (1, i2-i1+1); |
7447
|
2320 for (int i = 0; i < i2-i1+1; i++) |
7446
|
2321 limits (i) = sep*(i+i1); |
|
2322 |
|
2323 ticks = limits; |
|
2324 } |
|
2325 |
7222
|
2326 static bool updating_axis_limits = false; |
|
2327 |
7214
|
2328 void |
7222
|
2329 axes::update_axis_limits (const std::string& axis_type) |
7214
|
2330 { |
7222
|
2331 if (updating_axis_limits) |
|
2332 return; |
|
2333 |
|
2334 Matrix kids = xproperties.get_children (); |
|
2335 |
|
2336 octave_idx_type n = kids.numel (); |
|
2337 |
|
2338 double min_val = octave_Inf; |
|
2339 double max_val = -octave_Inf; |
|
2340 double min_pos = octave_Inf; |
|
2341 |
|
2342 char update_type = 0; |
|
2343 |
|
2344 Matrix limits; |
|
2345 |
|
2346 if (axis_type == "xdata" || axis_type == "xscale" |
|
2347 || axis_type == "xldata" || axis_type == "xudata" |
|
2348 || axis_type == "xlimmode") |
|
2349 { |
7363
|
2350 if (xproperties.xlimmode_is ("auto")) |
7222
|
2351 { |
|
2352 for (octave_idx_type i = 0; i < n; i++) |
|
2353 { |
|
2354 graphics_object obj = gh_manager::get_object (kids(i)); |
|
2355 |
|
2356 if (obj.isa ("line") || obj.isa ("image") |
|
2357 || obj.isa ("patch") || obj.isa ("surface")) |
|
2358 { |
7363
|
2359 data_property xdata = obj.get_xdata_property (); |
7222
|
2360 |
|
2361 check_limit_vals (min_val, max_val, min_pos, xdata); |
|
2362 |
|
2363 if (obj.isa ("line")) |
|
2364 { |
7363
|
2365 data_property xldata = obj.get_xldata_property (); |
|
2366 data_property xudata = obj.get_xudata_property (); |
7222
|
2367 |
|
2368 check_limit_vals (min_val, max_val, min_pos, xldata); |
|
2369 check_limit_vals (min_val, max_val, min_pos, xudata); |
|
2370 } |
|
2371 } |
|
2372 } |
|
2373 |
|
2374 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
2375 xproperties.xscale_is ("log")); |
7222
|
2376 |
|
2377 update_type = 'x'; |
|
2378 } |
|
2379 } |
|
2380 else if (axis_type == "ydata" || axis_type == "yscale" |
|
2381 || axis_type == "ldata" || axis_type == "udata" |
|
2382 || axis_type == "ylimmode") |
|
2383 { |
7363
|
2384 if (xproperties.ylimmode_is ("auto")) |
7222
|
2385 { |
|
2386 for (octave_idx_type i = 0; i < n; i++) |
|
2387 { |
|
2388 graphics_object obj = gh_manager::get_object (kids(i)); |
|
2389 |
|
2390 if (obj.isa ("line") || obj.isa ("image") |
|
2391 || obj.isa ("patch") || obj.isa ("surface")) |
|
2392 { |
7363
|
2393 data_property ydata = obj.get_ydata_property (); |
7222
|
2394 |
|
2395 check_limit_vals (min_val, max_val, min_pos, ydata); |
|
2396 |
|
2397 if (obj.isa ("line")) |
|
2398 { |
7363
|
2399 data_property ldata = obj.get_ldata_property (); |
|
2400 data_property udata = obj.get_udata_property (); |
7222
|
2401 |
|
2402 check_limit_vals (min_val, max_val, min_pos, ldata); |
|
2403 check_limit_vals (min_val, max_val, min_pos, udata); |
|
2404 } |
|
2405 } |
|
2406 } |
|
2407 |
|
2408 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
2409 xproperties.yscale_is ("log")); |
7222
|
2410 |
|
2411 update_type = 'y'; |
|
2412 } |
|
2413 } |
|
2414 else if (axis_type == "zdata" || axis_type == "zscale" |
|
2415 || axis_type == "zlimmode") |
|
2416 { |
7363
|
2417 if (xproperties.zlimmode_is ("auto")) |
7222
|
2418 { |
|
2419 for (octave_idx_type i = 0; i < n; i++) |
|
2420 { |
|
2421 graphics_object obj = gh_manager::get_object (kids(i)); |
|
2422 |
|
2423 if (obj.isa ("line") || obj.isa ("patch") || obj.isa ("surface")) |
|
2424 { |
7363
|
2425 data_property zdata = obj.get_zdata_property (); |
7222
|
2426 |
|
2427 check_limit_vals (min_val, max_val, min_pos, zdata); |
|
2428 } |
|
2429 } |
|
2430 |
|
2431 limits = get_axis_limits (min_val, max_val, min_pos, |
7363
|
2432 xproperties.zscale_is ("log")); |
7222
|
2433 |
|
2434 update_type = 'z'; |
|
2435 } |
|
2436 } |
|
2437 else if (axis_type == "cdata" || axis_type == "climmode") |
|
2438 { |
7363
|
2439 if (xproperties.climmode_is ("auto")) |
7222
|
2440 { |
|
2441 for (octave_idx_type i = 0; i < n; i++) |
|
2442 { |
|
2443 graphics_object obj = gh_manager::get_object (kids(i)); |
|
2444 |
|
2445 if (obj.isa ("image") || obj.isa ("patch") || obj.isa ("surface")) |
|
2446 { |
7363
|
2447 data_property cdata = obj.get_cdata_property (); |
7222
|
2448 |
|
2449 check_limit_vals (min_val, max_val, min_pos, cdata); |
|
2450 } |
|
2451 } |
|
2452 |
|
2453 if (min_val == max_val) |
|
2454 max_val = min_val + 1; |
|
2455 |
|
2456 limits.resize (1, 2); |
|
2457 |
|
2458 limits(0) = min_val; |
|
2459 limits(1) = max_val; |
|
2460 |
|
2461 update_type = 'c'; |
|
2462 } |
|
2463 |
|
2464 } |
|
2465 |
|
2466 unwind_protect_bool (updating_axis_limits); |
|
2467 updating_axis_limits = true; |
|
2468 |
|
2469 switch (update_type) |
|
2470 { |
|
2471 case 'x': |
|
2472 xproperties.set_xlim (limits); |
|
2473 xproperties.set_xlimmode ("auto"); |
7446
|
2474 xproperties.update_xlim (); |
7222
|
2475 break; |
|
2476 |
|
2477 case 'y': |
|
2478 xproperties.set_ylim (limits); |
|
2479 xproperties.set_ylimmode ("auto"); |
7446
|
2480 xproperties.update_ylim (); |
7222
|
2481 break; |
|
2482 |
|
2483 case 'z': |
|
2484 xproperties.set_zlim (limits); |
|
2485 xproperties.set_zlimmode ("auto"); |
7446
|
2486 xproperties.update_zlim (); |
7222
|
2487 break; |
|
2488 |
|
2489 case 'c': |
|
2490 xproperties.set_clim (limits); |
|
2491 xproperties.set_climmode ("auto"); |
|
2492 break; |
|
2493 |
|
2494 default: |
|
2495 break; |
|
2496 } |
|
2497 |
7427
|
2498 xproperties.update_transform (); |
|
2499 |
7222
|
2500 unwind_protect::run (); |
7214
|
2501 } |
|
2502 |
7363
|
2503 // --------------------------------------------------------------------- |
|
2504 |
|
2505 // Note: "line" code is entirely auto-generated |
6406
|
2506 |
|
2507 // --------------------------------------------------------------------- |
|
2508 |
7363
|
2509 // Note: "text" code is entirely auto-generated |
6406
|
2510 |
|
2511 // --------------------------------------------------------------------- |
|
2512 |
7363
|
2513 // Note: "image" code is entirely auto-generated |
6406
|
2514 |
|
2515 // --------------------------------------------------------------------- |
|
2516 |
7363
|
2517 // Note: "patch" code is entirely auto-generated |
6807
|
2518 |
|
2519 // --------------------------------------------------------------------- |
|
2520 |
7363
|
2521 // Note: "surface" code is entirely auto-generated |
6406
|
2522 |
|
2523 // --------------------------------------------------------------------- |
|
2524 |
|
2525 octave_value |
7189
|
2526 base_graphics_object::get_default (const caseless_str& name) const |
6406
|
2527 { |
|
2528 graphics_handle parent = get_parent (); |
|
2529 graphics_object parent_obj = gh_manager::get_object (parent); |
|
2530 |
|
2531 return parent_obj.get_default (type () + name); |
|
2532 } |
|
2533 |
|
2534 octave_value |
7189
|
2535 base_graphics_object::get_factory_default (const caseless_str& name) const |
6406
|
2536 { |
|
2537 graphics_object parent_obj = gh_manager::get_object (0); |
|
2538 |
|
2539 return parent_obj.get_factory_default (type () + name); |
|
2540 } |
|
2541 |
7286
|
2542 // We use a random value for the handle to avoid issues with plots and |
|
2543 // scalar values for the first argument. |
6406
|
2544 gh_manager::gh_manager (void) |
7286
|
2545 : handle_map (), handle_free_list (), |
|
2546 next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) |
6406
|
2547 { |
|
2548 handle_map[0] = graphics_object (new root_figure ()); |
|
2549 } |
|
2550 |
|
2551 graphics_handle |
|
2552 gh_manager::do_make_graphics_handle (const std::string& go_name, |
7370
|
2553 const graphics_handle& p, bool do_createfcn) |
6406
|
2554 { |
|
2555 graphics_handle h = get_handle (go_name); |
|
2556 |
|
2557 base_graphics_object *go = 0; |
|
2558 |
|
2559 if (go_name == "figure") |
|
2560 go = new figure (h, p); |
|
2561 else if (go_name == "axes") |
|
2562 go = new axes (h, p); |
|
2563 else if (go_name == "line") |
|
2564 go = new line (h, p); |
|
2565 else if (go_name == "text") |
|
2566 go = new text (h, p); |
|
2567 else if (go_name == "image") |
|
2568 go = new image (h, p); |
6807
|
2569 else if (go_name == "patch") |
|
2570 go = new patch (h, p); |
6406
|
2571 else if (go_name == "surface") |
|
2572 go = new surface (h, p); |
|
2573 if (go) |
7370
|
2574 { |
|
2575 handle_map[h] = graphics_object (go); |
|
2576 if (do_createfcn) |
|
2577 go->get_properties ().execute_createfcn (); |
|
2578 } |
6406
|
2579 else |
|
2580 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", |
|
2581 go_name.c_str ()); |
|
2582 |
|
2583 return h; |
|
2584 } |
|
2585 |
|
2586 graphics_handle |
|
2587 gh_manager::do_make_figure_handle (double val) |
|
2588 { |
|
2589 graphics_handle h = val; |
|
2590 |
|
2591 handle_map[h] = graphics_object (new figure (h, 0)); |
|
2592 |
|
2593 return h; |
|
2594 } |
|
2595 |
|
2596 void |
|
2597 gh_manager::do_push_figure (const graphics_handle& h) |
|
2598 { |
|
2599 do_pop_figure (h); |
|
2600 |
|
2601 figure_list.push_front (h); |
|
2602 } |
|
2603 |
|
2604 void |
|
2605 gh_manager::do_pop_figure (const graphics_handle& h) |
|
2606 { |
|
2607 for (figure_list_iterator p = figure_list.begin (); |
|
2608 p != figure_list.end (); |
|
2609 p++) |
|
2610 { |
|
2611 if (*p == h) |
|
2612 { |
|
2613 figure_list.erase (p); |
|
2614 break; |
|
2615 } |
|
2616 } |
|
2617 } |
|
2618 |
|
2619 property_list::plist_map_type |
|
2620 root_figure::init_factory_properties (void) |
|
2621 { |
|
2622 property_list::plist_map_type plist_map; |
|
2623 |
6844
|
2624 plist_map["figure"] = figure::properties::factory_defaults (); |
|
2625 plist_map["axes"] = axes::properties::factory_defaults (); |
|
2626 plist_map["line"] = line::properties::factory_defaults (); |
|
2627 plist_map["text"] = text::properties::factory_defaults (); |
|
2628 plist_map["image"] = image::properties::factory_defaults (); |
|
2629 plist_map["patch"] = patch::properties::factory_defaults (); |
|
2630 plist_map["surface"] = surface::properties::factory_defaults (); |
6406
|
2631 |
|
2632 return plist_map; |
|
2633 } |
|
2634 |
|
2635 // --------------------------------------------------------------------- |
|
2636 |
|
2637 DEFUN (ishandle, args, , |
|
2638 "-*- texinfo -*-\n\ |
6678
|
2639 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406
|
2640 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
|
2641 @end deftypefn") |
|
2642 { |
|
2643 octave_value retval; |
|
2644 |
|
2645 if (args.length () == 1) |
|
2646 retval = is_handle (args(0)); |
|
2647 else |
|
2648 print_usage (); |
|
2649 |
|
2650 return retval; |
|
2651 } |
|
2652 |
|
2653 DEFUN (set, args, , |
|
2654 "-*- texinfo -*-\n\ |
6678
|
2655 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6732
|
2656 Set the named property value or vector @var{p} to the value @var{v}\n\ |
6894
|
2657 for the graphics handle @var{h}.\n\ |
6406
|
2658 @end deftypefn") |
|
2659 { |
|
2660 octave_value retval; |
|
2661 |
|
2662 int nargin = args.length (); |
|
2663 |
|
2664 if (nargin > 0) |
|
2665 { |
6732
|
2666 ColumnVector hcv (args(0).vector_value ()); |
6406
|
2667 |
|
2668 if (! error_state) |
6732
|
2669 { |
6733
|
2670 bool request_drawnow = false; |
|
2671 |
6732
|
2672 for (octave_idx_type n = 0; n < hcv.length (); n++) |
|
2673 { |
|
2674 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
2675 |
6732
|
2676 if (obj) |
|
2677 { |
|
2678 obj.set (args.splice (0, 1)); |
6406
|
2679 |
6733
|
2680 request_drawnow = true; |
6732
|
2681 } |
|
2682 else |
6733
|
2683 { |
|
2684 error ("set: invalid handle (= %g)", hcv(n)); |
|
2685 break; |
|
2686 } |
6732
|
2687 } |
6733
|
2688 |
|
2689 if (! error_state && request_drawnow) |
7409
|
2690 Vdrawnow_requested = true; |
6732
|
2691 } |
6406
|
2692 else |
6732
|
2693 error ("set: expecting graphics handle as first argument"); |
6406
|
2694 } |
|
2695 else |
|
2696 print_usage (); |
|
2697 |
|
2698 return retval; |
|
2699 } |
|
2700 |
|
2701 DEFUN (get, args, , |
|
2702 "-*- texinfo -*-\n\ |
6678
|
2703 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406
|
2704 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
|
2705 If @var{p} is omitted, return the complete property list for @var{h}.\n\ |
6732
|
2706 If @var{h} is a vector, return a cell array including the property\n\ |
|
2707 values or lists respectively.\n\ |
6406
|
2708 @end deftypefn") |
|
2709 { |
|
2710 octave_value retval; |
6732
|
2711 octave_value_list vlist; |
6406
|
2712 |
|
2713 int nargin = args.length (); |
|
2714 |
|
2715 if (nargin == 1 || nargin == 2) |
|
2716 { |
6732
|
2717 ColumnVector hcv (args(0).vector_value ()); |
6406
|
2718 |
|
2719 if (! error_state) |
6732
|
2720 { |
6733
|
2721 octave_idx_type len = hcv.length (); |
|
2722 |
|
2723 vlist.resize (len); |
|
2724 |
|
2725 for (octave_idx_type n = 0; n < len; n++) |
6732
|
2726 { |
|
2727 graphics_object obj = gh_manager::get_object (hcv(n)); |
6406
|
2728 |
6732
|
2729 if (obj) |
|
2730 { |
|
2731 if (nargin == 1) |
|
2732 vlist(n) = obj.get (); |
|
2733 else |
|
2734 { |
7189
|
2735 caseless_str property = args(1).string_value (); |
6406
|
2736 |
6732
|
2737 if (! error_state) |
|
2738 vlist(n) = obj.get (property); |
|
2739 else |
6733
|
2740 { |
|
2741 error ("get: expecting property name as second argument"); |
|
2742 break; |
|
2743 } |
6732
|
2744 } |
|
2745 } |
|
2746 else |
6733
|
2747 { |
|
2748 error ("get: invalid handle (= %g)", hcv(n)); |
|
2749 break; |
|
2750 } |
6732
|
2751 } |
|
2752 } |
6406
|
2753 else |
6732
|
2754 error ("get: expecting graphics handle as first argument"); |
6406
|
2755 } |
|
2756 else |
|
2757 print_usage (); |
|
2758 |
6733
|
2759 if (! error_state) |
6732
|
2760 { |
6733
|
2761 octave_idx_type len = vlist.length (); |
|
2762 |
|
2763 if (len > 1) |
|
2764 retval = Cell (vlist); |
|
2765 else if (len == 1) |
|
2766 retval = vlist(0); |
6732
|
2767 } |
|
2768 |
6406
|
2769 return retval; |
|
2770 } |
|
2771 |
7379
|
2772 DEFUN (__get__, args, , |
|
2773 "-*- texinfo -*-\n\ |
|
2774 @deftypefn {Built-in Function} {} __get__ (@var{h})\n\ |
|
2775 Return all properties from the graphics handle @var{h}.\n\ |
|
2776 If @var{h} is a vector, return a cell array including the property\n\ |
|
2777 values or lists respectively.\n\ |
|
2778 @end deftypefn") |
|
2779 { |
|
2780 octave_value retval; |
|
2781 octave_value_list vlist; |
|
2782 |
|
2783 int nargin = args.length (); |
|
2784 |
|
2785 if (nargin == 1) |
|
2786 { |
|
2787 ColumnVector hcv (args(0).vector_value ()); |
|
2788 |
|
2789 if (! error_state) |
|
2790 { |
|
2791 octave_idx_type len = hcv.length (); |
|
2792 |
|
2793 vlist.resize (len); |
|
2794 |
|
2795 for (octave_idx_type n = 0; n < len; n++) |
|
2796 { |
|
2797 graphics_object obj = gh_manager::get_object (hcv(n)); |
|
2798 |
|
2799 if (obj) |
|
2800 vlist(n) = obj.get (true); |
|
2801 else |
|
2802 { |
|
2803 error ("get: invalid handle (= %g)", hcv(n)); |
|
2804 break; |
|
2805 } |
|
2806 } |
|
2807 } |
|
2808 else |
|
2809 error ("get: expecting graphics handle as first argument"); |
|
2810 } |
|
2811 else |
|
2812 print_usage (); |
|
2813 |
|
2814 if (! error_state) |
|
2815 { |
|
2816 octave_idx_type len = vlist.length (); |
|
2817 |
|
2818 if (len > 1) |
|
2819 retval = Cell (vlist); |
|
2820 else if (len == 1) |
|
2821 retval = vlist(0); |
|
2822 } |
|
2823 |
|
2824 return retval; |
|
2825 } |
|
2826 |
6406
|
2827 static octave_value |
|
2828 make_graphics_object (const std::string& go_name, |
6874
|
2829 const octave_value_list& args) |
6406
|
2830 { |
|
2831 octave_value retval; |
|
2832 |
|
2833 double val = args(0).double_value (); |
|
2834 |
|
2835 if (! error_state) |
|
2836 { |
|
2837 graphics_handle parent = gh_manager::lookup (val); |
|
2838 |
7056
|
2839 if (parent.ok ()) |
6406
|
2840 { |
|
2841 graphics_handle h |
7370
|
2842 = gh_manager::make_graphics_handle (go_name, parent, false); |
6406
|
2843 |
|
2844 if (! error_state) |
|
2845 { |
|
2846 adopt (parent, h); |
|
2847 |
|
2848 xset (h, args.splice (0, 1)); |
7370
|
2849 xcreatefcn (h); |
6406
|
2850 |
6874
|
2851 retval = h.value (); |
7296
|
2852 |
|
2853 if (! error_state) |
7409
|
2854 Vdrawnow_requested = true; |
6406
|
2855 } |
|
2856 else |
|
2857 error ("__go%s__: unable to create graphics handle", |
|
2858 go_name.c_str ()); |
|
2859 } |
|
2860 else |
|
2861 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2862 } |
|
2863 else |
|
2864 error ("__go_%s__: invalid parent", go_name.c_str ()); |
|
2865 |
|
2866 return retval; |
|
2867 } |
|
2868 |
|
2869 DEFUN (__go_figure__, args, , |
|
2870 "-*- texinfo -*-\n\ |
|
2871 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ |
6945
|
2872 Undocumented internal function.\n\ |
6406
|
2873 @end deftypefn") |
|
2874 { |
|
2875 octave_value retval; |
|
2876 |
|
2877 if (args.length () > 0) |
|
2878 { |
|
2879 double val = args(0).double_value (); |
|
2880 |
|
2881 if (! error_state) |
|
2882 { |
|
2883 if (is_figure (val)) |
|
2884 { |
|
2885 graphics_handle h = gh_manager::lookup (val); |
|
2886 |
|
2887 xset (h, args.splice (0, 1)); |
|
2888 |
6874
|
2889 retval = h.value (); |
6406
|
2890 } |
|
2891 else |
|
2892 { |
|
2893 graphics_handle h = octave_NaN; |
|
2894 |
|
2895 if (xisnan (val)) |
7370
|
2896 h = gh_manager::make_graphics_handle ("figure", 0, false); |
6406
|
2897 else if (val > 0 && D_NINT (val) == val) |
|
2898 h = gh_manager::make_figure_handle (val); |
|
2899 else |
|
2900 error ("__go_figure__: invalid figure number"); |
|
2901 |
7056
|
2902 if (! error_state && h.ok ()) |
6406
|
2903 { |
|
2904 adopt (0, h); |
|
2905 |
|
2906 xset (h, args.splice (0, 1)); |
7370
|
2907 xcreatefcn (h); |
6406
|
2908 |
6874
|
2909 retval = h.value (); |
6406
|
2910 } |
|
2911 else |
|
2912 error ("__go_figure__: failed to create figure handle"); |
|
2913 } |
|
2914 } |
|
2915 else |
|
2916 error ("__go_figure__: expecting figure number to be double value"); |
|
2917 } |
|
2918 else |
|
2919 print_usage (); |
|
2920 |
|
2921 return retval; |
|
2922 } |
|
2923 |
|
2924 #define GO_BODY(TYPE) \ |
|
2925 octave_value retval; \ |
|
2926 \ |
|
2927 if (args.length () > 0) \ |
|
2928 retval = make_graphics_object (#TYPE, args); \ |
|
2929 else \ |
|
2930 print_usage (); \ |
|
2931 \ |
|
2932 return retval |
|
2933 |
|
2934 DEFUN (__go_axes__, args, , |
|
2935 "-*- texinfo -*-\n\ |
|
2936 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ |
6945
|
2937 Undocumented internal function.\n\ |
6406
|
2938 @end deftypefn") |
|
2939 { |
|
2940 GO_BODY (axes); |
|
2941 } |
|
2942 |
|
2943 DEFUN (__go_line__, args, , |
|
2944 "-*- texinfo -*-\n\ |
|
2945 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ |
6945
|
2946 Undocumented internal function.\n\ |
6406
|
2947 @end deftypefn") |
|
2948 { |
|
2949 GO_BODY (line); |
|
2950 } |
|
2951 |
|
2952 DEFUN (__go_text__, args, , |
|
2953 "-*- texinfo -*-\n\ |
|
2954 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ |
6945
|
2955 Undocumented internal function.\n\ |
6406
|
2956 @end deftypefn") |
|
2957 { |
|
2958 GO_BODY (text); |
|
2959 } |
|
2960 |
|
2961 DEFUN (__go_image__, args, , |
|
2962 "-*- texinfo -*-\n\ |
|
2963 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ |
6945
|
2964 Undocumented internal function.\n\ |
6406
|
2965 @end deftypefn") |
|
2966 { |
|
2967 GO_BODY (image); |
|
2968 } |
|
2969 |
|
2970 DEFUN (__go_surface__, args, , |
|
2971 "-*- texinfo -*-\n\ |
|
2972 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ |
6945
|
2973 Undocumented internal function.\n\ |
6406
|
2974 @end deftypefn") |
|
2975 { |
|
2976 GO_BODY (surface); |
|
2977 } |
|
2978 |
6807
|
2979 DEFUN (__go_patch__, args, , |
|
2980 "-*- texinfo -*-\n\ |
|
2981 @deftypefn {Built-in Function} {} __go_patch__ (@var{parent})\n\ |
6945
|
2982 Undocumented internal function.\n\ |
6807
|
2983 @end deftypefn") |
|
2984 { |
|
2985 GO_BODY (patch); |
|
2986 } |
|
2987 |
6406
|
2988 DEFUN (__go_delete__, args, , |
|
2989 "-*- texinfo -*-\n\ |
|
2990 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ |
6945
|
2991 Undocumented internal function.\n\ |
6406
|
2992 @end deftypefn") |
|
2993 { |
|
2994 octave_value_list retval; |
|
2995 |
|
2996 if (args.length () == 1) |
|
2997 { |
|
2998 graphics_handle h = octave_NaN; |
|
2999 |
|
3000 double val = args(0).double_value (); |
|
3001 |
|
3002 if (! error_state) |
|
3003 { |
|
3004 h = gh_manager::lookup (val); |
|
3005 |
7056
|
3006 if (h.ok ()) |
6406
|
3007 { |
|
3008 graphics_object obj = gh_manager::get_object (h); |
|
3009 |
|
3010 graphics_handle parent_h = obj.get_parent (); |
|
3011 |
|
3012 graphics_object parent_obj = gh_manager::get_object (parent_h); |
|
3013 |
7367
|
3014 // NOTE: free the handle before removing it from its parent's |
|
3015 // children, such that the object's state is correct when |
|
3016 // the deletefcn callback is executed |
6406
|
3017 |
|
3018 gh_manager::free (h); |
7367
|
3019 |
|
3020 parent_obj.remove_child (h); |
6406
|
3021 } |
|
3022 else |
|
3023 error ("delete: invalid graphics object (= %g)", val); |
|
3024 } |
|
3025 else |
|
3026 error ("delete: invalid graphics object"); |
|
3027 } |
|
3028 else |
|
3029 print_usage (); |
|
3030 |
|
3031 return retval; |
|
3032 } |
|
3033 |
|
3034 DEFUN (__go_axes_init__, args, , |
|
3035 "-*- texinfo -*-\n\ |
|
3036 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ |
6945
|
3037 Undocumented internal function.\n\ |
6406
|
3038 @end deftypefn") |
|
3039 { |
|
3040 octave_value retval; |
|
3041 |
|
3042 int nargin = args.length (); |
|
3043 |
|
3044 std::string mode = ""; |
|
3045 |
|
3046 if (nargin == 2) |
|
3047 { |
|
3048 mode = args(1).string_value (); |
|
3049 |
|
3050 if (error_state) |
|
3051 return retval; |
|
3052 } |
|
3053 |
|
3054 if (nargin == 1 || nargin == 2) |
|
3055 { |
|
3056 graphics_handle h = octave_NaN; |
|
3057 |
|
3058 double val = args(0).double_value (); |
|
3059 |
|
3060 if (! error_state) |
|
3061 { |
|
3062 h = gh_manager::lookup (val); |
|
3063 |
7056
|
3064 if (h.ok ()) |
6406
|
3065 { |
|
3066 graphics_object obj = gh_manager::get_object (h); |
|
3067 |
|
3068 obj.set_defaults (mode); |
|
3069 } |
|
3070 else |
|
3071 error ("__go_axes_init__: invalid graphics object (= %g)", val); |
|
3072 } |
|
3073 else |
|
3074 error ("__go_axes_init__: invalid graphics object"); |
|
3075 } |
|
3076 else |
|
3077 print_usage (); |
|
3078 |
|
3079 return retval; |
|
3080 } |
|
3081 |
|
3082 DEFUN (__go_handles__, , , |
|
3083 "-*- texinfo -*-\n\ |
|
3084 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ |
6945
|
3085 Undocumented internal function.\n\ |
6406
|
3086 @end deftypefn") |
|
3087 { |
6425
|
3088 return octave_value (gh_manager::handle_list ()); |
|
3089 } |
|
3090 |
|
3091 DEFUN (__go_figure_handles__, , , |
|
3092 "-*- texinfo -*-\n\ |
|
3093 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ |
6945
|
3094 Undocumented internal function.\n\ |
6425
|
3095 @end deftypefn") |
|
3096 { |
|
3097 return octave_value (gh_manager::figure_handle_list ()); |
6406
|
3098 } |
|
3099 |
7409
|
3100 static void |
|
3101 clear_drawnow_request (void *) |
|
3102 { |
|
3103 Vdrawnow_requested = false; |
|
3104 } |
|
3105 |
7408
|
3106 DEFUN (drawnow, args, , |
|
3107 "-*- texinfo -*-\n\ |
|
3108 @deftypefn {Built-in Function} {} __go_drawnow__ ()\n\ |
|
3109 @deftypefnx {Built-in Function} {} __go_drawnow__ (@var{term}, @var{file}, @var{mono}, @var{debug_file})\n\ |
|
3110 Undocumented internal function.\n\ |
|
3111 @end deftypefn") |
|
3112 { |
|
3113 static int drawnow_executing = 0; |
|
3114 static bool __go_close_all_registered__ = false; |
|
3115 |
|
3116 octave_value retval; |
|
3117 |
7409
|
3118 unwind_protect::begin_frame ("Fdrawnow"); |
|
3119 unwind_protect::add (clear_drawnow_request); |
|
3120 |
|
3121 unwind_protect_int (drawnow_executing); |
|
3122 |
|
3123 if (++drawnow_executing <= 1) |
7408
|
3124 { |
7409
|
3125 if (! __go_close_all_registered__) |
|
3126 { |
|
3127 octave_add_atexit_function ("__go_close_all__"); |
|
3128 |
|
3129 __go_close_all_registered__ = true; |
|
3130 } |
|
3131 |
|
3132 if (args.length () == 0) |
7408
|
3133 { |
7409
|
3134 Matrix hlist = gh_manager::figure_handle_list (); |
|
3135 |
|
3136 for (int i = 0; ! error_state && i < hlist.length (); i++) |
7408
|
3137 { |
7409
|
3138 graphics_handle h = gh_manager::lookup (hlist(i)); |
|
3139 |
|
3140 if (h.ok () && h != 0) |
7408
|
3141 { |
7409
|
3142 graphics_object go = gh_manager::get_object (h); |
|
3143 figure::properties& fprops = dynamic_cast <figure::properties&> (go.get_properties ()); |
|
3144 |
|
3145 if (fprops.is_modified ()) |
7408
|
3146 { |
7409
|
3147 if (fprops.is_visible ()) |
|
3148 fprops.get_backend ().redraw_figure (h); |
|
3149 else if (! fprops.get___plot_stream__ ().is_empty ()) |
|
3150 { |
|
3151 fprops.close (false); |
|
3152 fprops.set___plot_stream__ (Matrix ()); |
|
3153 fprops.set___enhanced__ (false); |
|
3154 } |
|
3155 fprops.set_modified (false); |
7408
|
3156 } |
|
3157 } |
|
3158 } |
|
3159 } |
7409
|
3160 else if (args.length () >= 2 && args.length () <= 4) |
7408
|
3161 { |
7409
|
3162 std::string term, file, debug_file; |
|
3163 bool mono; |
|
3164 |
|
3165 term = args(0).string_value (); |
7408
|
3166 |
|
3167 if (! error_state) |
|
3168 { |
7409
|
3169 file = args(1).string_value (); |
7408
|
3170 |
|
3171 if (! error_state) |
|
3172 { |
7409
|
3173 size_t pos = file.find_last_of (file_ops::dir_sep_chars); |
|
3174 |
|
3175 if (pos != NPOS) |
|
3176 { |
|
3177 file_stat fs (file.substr (0, pos)); |
|
3178 |
|
3179 if (! (fs && fs.is_dir ())) |
|
3180 error ("drawnow: nonexistent directory `%s'", |
|
3181 file.substr (0, pos).c_str ()); |
|
3182 } |
|
3183 |
|
3184 mono = (args.length () >= 3 ? args(2).bool_value () : false); |
7408
|
3185 |
|
3186 if (! error_state) |
|
3187 { |
7409
|
3188 debug_file = (args.length () > 3 ? args(3).string_value () |
|
3189 : ""); |
|
3190 |
|
3191 if (! error_state) |
7408
|
3192 { |
7409
|
3193 graphics_handle h = gcf (); |
|
3194 |
|
3195 if (h.ok ()) |
|
3196 { |
|
3197 graphics_object go = gh_manager::get_object (h); |
|
3198 |
7419
|
3199 go.get_backend () |
7409
|
3200 .print_figure (h, term, file, mono, debug_file); |
|
3201 } |
|
3202 else |
|
3203 error ("drawnow: nothing to draw"); |
7408
|
3204 } |
|
3205 else |
7409
|
3206 error ("drawnow: invalid debug_file, expected a string value"); |
7408
|
3207 } |
|
3208 else |
7409
|
3209 error ("drawnow: invalid colormode, expected a boolean value"); |
7408
|
3210 } |
|
3211 else |
7409
|
3212 error ("drawnow: invalid file, expected a string value"); |
7408
|
3213 } |
|
3214 else |
7409
|
3215 error ("drawnow: invalid terminal, expected a string value"); |
7408
|
3216 } |
|
3217 else |
7409
|
3218 print_usage (); |
7408
|
3219 } |
7409
|
3220 |
|
3221 unwind_protect::run_frame ("Fdrawnow"); |
7408
|
3222 |
|
3223 return retval; |
|
3224 } |
|
3225 |
6595
|
3226 octave_value |
7447
|
3227 get_property_from_handle (double handle, const std::string& property, |
|
3228 const std::string& func) |
6595
|
3229 { |
|
3230 graphics_object obj = gh_manager::get_object (handle); |
|
3231 octave_value retval; |
|
3232 |
|
3233 if (obj) |
|
3234 { |
7189
|
3235 caseless_str p = std::string (property); |
6595
|
3236 retval = obj.get (p); |
|
3237 } |
|
3238 else |
|
3239 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
3240 |
|
3241 return retval; |
|
3242 } |
|
3243 |
|
3244 bool |
7447
|
3245 set_property_in_handle (double handle, const std::string& property, |
|
3246 const octave_value& arg, const std::string& func) |
6595
|
3247 { |
|
3248 graphics_object obj = gh_manager::get_object (handle); |
|
3249 int ret = false; |
|
3250 |
|
3251 if (obj) |
|
3252 { |
7189
|
3253 caseless_str p = std::string (property); |
6595
|
3254 obj.set (p, arg); |
|
3255 if (!error_state) |
|
3256 ret = true; |
|
3257 } |
|
3258 else |
|
3259 error ("%s: invalid handle (= %g)", func.c_str(), handle); |
|
3260 |
|
3261 return ret; |
|
3262 } |
|
3263 |
6406
|
3264 /* |
|
3265 ;;; Local Variables: *** |
|
3266 ;;; mode: C++ *** |
|
3267 ;;; End: *** |
|
3268 */ |