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