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