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