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