Mercurial > hg > octave-lyh
annotate src/graphics.cc @ 7860:67edbcb19665
rudimentry (i.e. no font metrics) sync of axes.position and axes.outerposition
* * *
preserve axes position if mode is replace
* * *
use default_axes_postion when syncing outerposition and position
* * *
Update transformation matrices when axes position changes.
author | Shai Ayal <shaiay@users.sourceforge.net> |
---|---|
date | Fri, 14 Mar 2008 21:02:16 +0200 |
parents | fdd465b00ec0 |
children | 8f3459a90bf3 |
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 { | |
7363 | 1511 graphics_handle h = (get_type () == "axes") ? __myhandle__ : get_parent (); |
7214 | 1512 |
1513 graphics_object obj = gh_manager::get_object (h); | |
1514 | |
1515 if (obj.isa ("axes")) | |
1516 obj.update_axis_limits (axis_type); | |
1517 } | |
1518 | |
1519 void | |
6836 | 1520 base_properties::delete_children (void) |
1521 { | |
1522 octave_idx_type n = children.numel (); | |
1523 | |
1524 for (octave_idx_type i = 0; i < n; i++) | |
1525 gh_manager::free (children(i)); | |
1526 } | |
1527 | |
7419 | 1528 graphics_backend |
1529 base_properties::get_backend (void) const | |
1530 { | |
1531 graphics_object go = gh_manager::get_object (get_parent ()); | |
1532 | |
1533 if (go) | |
1534 return go.get_backend (); | |
1535 else | |
1536 return graphics_backend (); | |
1537 } | |
1538 | |
7828
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1539 void |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1540 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
|
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 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
|
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 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
|
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 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
|
1547 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1548 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
|
1549 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
|
1550 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1551 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1552 |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1553 void |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1554 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
|
1555 listener_mode mode) |
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 property p = get_property (nm); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1558 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1559 if (! error_state && p.ok ()) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1560 p.add_listener (v, mode); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1561 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1562 |
7363 | 1563 // --------------------------------------------------------------------- |
1564 | |
7408 | 1565 class gnuplot_backend : public base_graphics_backend |
1566 { | |
1567 public: | |
1568 gnuplot_backend (void) | |
1569 : base_graphics_backend ("gnuplot") { } | |
1570 | |
1571 ~gnuplot_backend (void) { } | |
1572 | |
1573 bool is_valid (void) const { return true; } | |
1574 | |
1575 void close_figure (const octave_value& pstream) const | |
1576 { | |
1577 if (! pstream.is_empty()) | |
1578 { | |
1579 octave_value_list args; | |
7680
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1580 Matrix fids = pstream.matrix_value (); |
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 if (! error_state) |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1583 { |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1584 args(1) = "\nquit;\n"; |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1585 args(0) = octave_value (fids (0)); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1586 feval ("fputs", args); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1587 args.resize (1); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1588 feval ("fflush", args); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1589 feval ("pclose", args); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1590 if (fids.numel () > 1) |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1591 { |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1592 args(0) = octave_value (fids (1)); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1593 feval ("pclose", args); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1594 } |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7527
diff
changeset
|
1595 } |
7408 | 1596 } |
1597 } | |
1598 | |
1599 void redraw_figure (const graphics_handle& fh) const | |
1600 { | |
1601 octave_value_list args; | |
1602 args(0) = fh.as_octave_value (); | |
1603 feval ("gnuplot_drawnow", args); | |
1604 } | |
1605 | |
1606 void print_figure (const graphics_handle& fh, const std::string& term, | |
1607 const std::string& file, bool mono, | |
1608 const std::string& debug_file) const | |
1609 { | |
1610 octave_value_list args; | |
1611 if (! debug_file.empty ()) | |
1612 args(4) = debug_file; | |
7409 | 1613 args(3) = mono; |
1614 args(2) = file; | |
1615 args(1) = term; | |
1616 args(0) = fh.as_octave_value (); | |
7408 | 1617 feval ("gnuplot_drawnow", args); |
1618 } | |
1619 | |
7409 | 1620 Matrix get_canvas_size (const graphics_handle&) const |
7427 | 1621 { |
1622 Matrix sz (1, 2, 0.0); | |
1623 return sz; | |
1624 } | |
1625 | |
1626 double get_screen_resolution (void) const | |
1627 { return 72.0; } | |
7445 | 1628 |
1629 Matrix get_screen_size (void) const | |
1630 { return Matrix (1, 2, 0.0); } | |
7408 | 1631 }; |
1632 | |
1633 graphics_backend | |
1634 graphics_backend::default_backend (void) | |
1635 { | |
1636 if (available_backends.size () == 0) | |
1637 register_backend (new gnuplot_backend ()); | |
1638 | |
1639 return available_backends["gnuplot"]; | |
1640 } | |
1641 | |
1642 std::map<std::string, graphics_backend> graphics_backend::available_backends; | |
1643 | |
1644 // --------------------------------------------------------------------- | |
1645 | |
7363 | 1646 #include "graphics-props.cc" |
1647 | |
1648 // --------------------------------------------------------------------- | |
1649 | |
6836 | 1650 void |
7363 | 1651 root_figure::properties::set_currentfigure (const octave_value& v) |
6874 | 1652 { |
7378 | 1653 graphics_handle val (v); |
7363 | 1654 |
6874 | 1655 if (error_state) |
1656 return; | |
1657 | |
7059 | 1658 if (xisnan (val.value ()) || is_handle (val)) |
6874 | 1659 { |
1660 currentfigure = val; | |
1661 | |
7363 | 1662 gh_manager::push_figure (val); |
6874 | 1663 } |
1664 else | |
1665 gripe_set_invalid ("currentfigure"); | |
1666 } | |
1667 | |
7822
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1668 void |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1669 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
|
1670 { |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1671 graphics_handle val (v); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1672 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1673 if (error_state) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1674 return; |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1675 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1676 if (xisnan (val.value ())) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1677 { |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1678 if (! cbo_stack.empty ()) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1679 { |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1680 val = cbo_stack.front (); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1681 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1682 cbo_stack.pop_front (); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1683 } |
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 callbackobject = val; |
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 else if (is_handle (val)) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1688 { |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1689 if (get_callbackobject ().ok ()) |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1690 cbo_stack.push_front (get_callbackobject ()); |
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 callbackobject = val; |
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 else |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1695 gripe_set_invalid ("callbackobject"); |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1696 } |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7820
diff
changeset
|
1697 |
6406 | 1698 property_list |
1699 root_figure::factory_properties = root_figure::init_factory_properties (); | |
1700 | |
1701 // --------------------------------------------------------------------- | |
1702 | |
7363 | 1703 void |
1704 figure::properties::set_currentaxes (const octave_value& v) | |
1705 { | |
7378 | 1706 graphics_handle val (v); |
6705 | 1707 |
6874 | 1708 if (error_state) |
1709 return; | |
1710 | |
7070 | 1711 if (xisnan (val.value ()) || is_handle (val)) |
6874 | 1712 currentaxes = val; |
1713 else | |
1714 gripe_set_invalid ("currentaxes"); | |
1715 } | |
1716 | |
1717 void | |
1718 figure::properties::set_visible (const octave_value& val) | |
1719 { | |
1720 std::string s = val.string_value (); | |
1721 | |
1722 if (! error_state) | |
1723 { | |
1724 if (s == "on") | |
1725 xset (0, "currentfigure", __myhandle__.value ()); | |
1726 | |
1727 visible = val; | |
1728 } | |
1729 } | |
1730 | |
1731 void | |
7408 | 1732 figure::properties::close (bool pop) |
6705 | 1733 { |
7408 | 1734 if (backend) |
1735 backend.close_figure (get___plot_stream__ ()); | |
1736 | |
1737 if (pop) | |
6406 | 1738 { |
7408 | 1739 gh_manager::pop_figure (__myhandle__); |
1740 | |
1741 graphics_handle cf = gh_manager::current_figure (); | |
1742 | |
1743 xset (0, "currentfigure", cf.value ()); | |
6406 | 1744 } |
6705 | 1745 } |
6432 | 1746 |
7445 | 1747 Matrix |
7447 | 1748 figure::properties::get_boundingbox (bool) const |
7445 | 1749 { |
1750 graphics_backend b = get_backend (); | |
1751 // FIXME: screen size should be obtained from root object | |
1752 Matrix screen_size = b.get_screen_size (); | |
1753 Matrix pos; | |
1754 | |
1755 pos = convert_position (get_position ().matrix_value (), get_units (), | |
1756 "pixels", screen_size, b); | |
1757 | |
1758 pos(0)--; | |
1759 pos(1)--; | |
7447 | 1760 pos(1) = screen_size(1) - pos(1) - pos(3); |
7445 | 1761 |
1762 return pos; | |
1763 } | |
1764 | |
7828
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1765 void |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1766 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
|
1767 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1768 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
|
1769 // 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
|
1770 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
|
1771 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
|
1772 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1773 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
|
1774 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
|
1775 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
|
1776 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
|
1777 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1778 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
|
1779 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1780 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1781 void |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1782 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
|
1783 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1784 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
|
1785 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1786 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
|
1787 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1788 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
|
1789 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
|
1790 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
|
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 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
|
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 // 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
|
1795 // 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
|
1796 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
|
1797 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
|
1798 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1799 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
|
1800 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
|
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 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1803 |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1804 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
|
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 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1807 |
6836 | 1808 octave_value |
7189 | 1809 figure::get_default (const caseless_str& name) const |
6836 | 1810 { |
1811 octave_value retval = default_properties.lookup (name); | |
1812 | |
1813 if (retval.is_undefined ()) | |
1814 { | |
1815 graphics_handle parent = get_parent (); | |
1816 graphics_object parent_obj = gh_manager::get_object (parent); | |
1817 | |
1818 retval = parent_obj.get_default (name); | |
1819 } | |
1820 | |
1821 return retval; | |
1822 } | |
1823 | |
6406 | 1824 // --------------------------------------------------------------------- |
1825 | |
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
|
1826 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
|
1827 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
|
1828 { |
67edbcb19665
rudimentry (i.e. no font metrics) sync of axes.position and axes.outerposition
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7859
diff
changeset
|
1829 // 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
|
1830 // 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
|
1831 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
|
1832 { |
67edbcb19665
rudimentry (i.e. no font metrics) sync of axes.position and axes.outerposition
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7859
diff
changeset
|
1833 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
|
1834 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
|
1835 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
|
1836 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
|
1837 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
|
1838 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
|
1839 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
|
1840 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
|
1841 } |
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 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
|
1843 { |
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 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
|
1845 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
|
1846 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
|
1847 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
|
1848 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
|
1849 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
|
1850 } |
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 |
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 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
|
1853 } |
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 |
7363 | 1855 void |
1856 axes::properties::set_title (const octave_value& v) | |
6962 | 1857 { |
7363 | 1858 graphics_handle val = ::reparent (v, "set", "title", __myhandle__, false); |
6962 | 1859 |
6874 | 1860 if (! error_state) |
1861 { | |
7363 | 1862 gh_manager::free (title.handle_value ()); |
6874 | 1863 title = val; |
1864 } | |
1865 } | |
1866 | |
1867 void | |
7363 | 1868 axes::properties::set_xlabel (const octave_value& v) |
6874 | 1869 { |
7363 | 1870 graphics_handle val = ::reparent (v, "set", "xlabel", __myhandle__, false); |
6874 | 1871 |
1872 if (! error_state) | |
1873 { | |
7363 | 1874 gh_manager::free (xlabel.handle_value ()); |
6874 | 1875 xlabel = val; |
1876 } | |
1877 } | |
1878 | |
1879 void | |
7363 | 1880 axes::properties::set_ylabel (const octave_value& v) |
6874 | 1881 { |
7363 | 1882 graphics_handle val = ::reparent (v, "set", "ylabel", __myhandle__, false); |
6874 | 1883 |
1884 if (! error_state) | |
1885 { | |
7363 | 1886 gh_manager::free (ylabel.handle_value ()); |
6874 | 1887 ylabel = val; |
1888 } | |
1889 } | |
1890 | |
1891 void | |
7363 | 1892 axes::properties::set_zlabel (const octave_value& v) |
6874 | 1893 { |
7363 | 1894 graphics_handle val = ::reparent (v, "set", "zlabel", __myhandle__, false); |
6874 | 1895 |
1896 if (! error_state) | |
1897 { | |
7363 | 1898 gh_manager::free (zlabel.handle_value ()); |
6874 | 1899 zlabel = val; |
1900 } | |
1901 } | |
1902 | |
1903 void | |
6844 | 1904 axes::properties::set_defaults (base_graphics_object& obj, |
6890 | 1905 const std::string& mode) |
6705 | 1906 { |
7363 | 1907 title = graphics_handle (); |
6705 | 1908 box = "on"; |
1909 key = "off"; | |
1910 keybox = "off"; | |
7363 | 1911 keypos = 1.0; |
6962 | 1912 colororder = default_colororder (); |
6705 | 1913 dataaspectratio = Matrix (1, 3, 1.0); |
1914 dataaspectratiomode = "auto"; | |
7363 | 1915 layer = "bottom"; |
6705 | 1916 |
1917 Matrix tlim (1, 2, 0.0); | |
1918 tlim(1) = 1; | |
1919 xlim = tlim; | |
1920 ylim = tlim; | |
1921 zlim = tlim; | |
6807 | 1922 |
1923 Matrix cl (1, 2, 0); | |
1924 cl(1) = 1; | |
1925 clim = cl; | |
1926 | |
7363 | 1927 xlimmode = "auto"; |
1928 ylimmode = "auto"; | |
1929 zlimmode = "auto"; | |
1930 climmode = "auto"; | |
1931 xlabel = graphics_handle (); | |
1932 ylabel = graphics_handle (); | |
1933 zlabel = graphics_handle (); | |
6705 | 1934 xgrid = "off"; |
1935 ygrid = "off"; | |
1936 zgrid = "off"; | |
1937 xminorgrid = "off"; | |
1938 yminorgrid = "off"; | |
1939 zminorgrid = "off"; | |
1940 xtick = Matrix (); | |
1941 ytick = Matrix (); | |
1942 ztick = Matrix (); | |
1943 xtickmode = "auto"; | |
1944 ytickmode = "auto"; | |
1945 ztickmode = "auto"; | |
1946 xticklabel = ""; | |
1947 yticklabel = ""; | |
1948 zticklabel = ""; | |
1949 xticklabelmode = "auto"; | |
1950 yticklabelmode = "auto"; | |
1951 zticklabelmode = "auto"; | |
7453 | 1952 color = color_values (1, 1, 1); |
7364 | 1953 xcolor = color_values ("black"); |
1954 ycolor = color_values ("black"); | |
1955 zcolor = color_values ("black"); | |
7363 | 1956 xscale = "linear"; |
1957 yscale = "linear"; | |
1958 zscale = "linear"; | |
6705 | 1959 xdir = "normal"; |
1960 ydir = "normal"; | |
1961 zdir = "normal"; | |
7363 | 1962 yaxislocation = "left"; |
1963 xaxislocation = "bottom"; | |
6705 | 1964 |
7427 | 1965 // Note: camera properties will be set through update_transform |
1966 camerapositionmode = "auto"; | |
1967 cameratargetmode = "auto"; | |
1968 cameraupvectormode = "auto"; | |
1969 cameraviewanglemode = "auto"; | |
1970 plotboxaspectratio = Matrix (1, 3, 1.0); | |
1971 drawmode = "normal"; | |
1972 fontangle = "normal"; | |
1973 fontname = "Helvetica"; | |
1974 fontsize = 12; | |
1975 fontunits = "points"; | |
1976 fontweight = "normal"; | |
7820
cb4838d70ab2
Fix default value for axes gridlinestyle and minorgridlinestyle.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7680
diff
changeset
|
1977 gridlinestyle = ":"; |
7427 | 1978 linestyleorder = "-"; |
1979 linewidth = 0.5; | |
7820
cb4838d70ab2
Fix default value for axes gridlinestyle and minorgridlinestyle.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7680
diff
changeset
|
1980 minorgridlinestyle = ":"; |
7427 | 1981 // Note: plotboxaspectratio will be set through update_aspectratiors |
1982 plotboxaspectratiomode = "auto"; | |
1983 projection = "orthographic"; | |
1984 tickdir = "in"; | |
1985 tickdirmode = "auto"; | |
1986 ticklength = Matrix (1, 2, 0.1); | |
1987 tightinset = Matrix (1, 4, 0.0); | |
1988 | |
1989 sx = "linear"; | |
1990 sy = "linear"; | |
1991 sz = "linear"; | |
1992 | |
6705 | 1993 Matrix tview (1, 2, 0.0); |
1994 tview(1) = 90; | |
1995 view = tview; | |
1996 | |
6765 | 1997 visible = "on"; |
6705 | 1998 nextplot = "replace"; |
1999 | |
2000 // FIXME -- this is not quite right; we should preserve | |
2001 // "position" and "units". | |
2002 | |
2003 if (mode != "replace") | |
2004 { | |
6406 | 2005 Matrix touterposition (1, 4, 0.0); |
2006 touterposition(2) = 1; | |
2007 touterposition(3) = 1; | |
2008 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
|
2009 |
67edbcb19665
rudimentry (i.e. no font metrics) sync of axes.position and axes.outerposition
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7859
diff
changeset
|
2010 position = default_axes_position (); |
6406 | 2011 } |
2012 | |
7363 | 2013 activepositionproperty = "outerposition"; |
2014 __colorbar__ = "none"; | |
7189 | 2015 |
6705 | 2016 delete_children (); |
6406 | 2017 |
6705 | 2018 children = Matrix (); |
6432 | 2019 |
7427 | 2020 update_transform (); |
2021 | |
6705 | 2022 override_defaults (obj); |
2023 } | |
2024 | |
6874 | 2025 graphics_handle |
2026 axes::properties::get_title (void) const | |
2027 { | |
7363 | 2028 if (! title.handle_value ().ok ()) |
6874 | 2029 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
2030 | |
7363 | 2031 return title.handle_value (); |
6874 | 2032 } |
2033 | |
2034 graphics_handle | |
2035 axes::properties::get_xlabel (void) const | |
2036 { | |
7363 | 2037 if (! xlabel.handle_value ().ok ()) |
6874 | 2038 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
2039 | |
7363 | 2040 return xlabel.handle_value (); |
6874 | 2041 } |
2042 | |
2043 graphics_handle | |
2044 axes::properties::get_ylabel (void) const | |
2045 { | |
7363 | 2046 if (! ylabel.handle_value ().ok ()) |
6874 | 2047 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
2048 | |
7363 | 2049 return ylabel.handle_value (); |
6874 | 2050 } |
2051 | |
2052 graphics_handle | |
2053 axes::properties::get_zlabel (void) const | |
2054 { | |
7363 | 2055 if (! zlabel.handle_value ().ok ()) |
6874 | 2056 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
2057 | |
7363 | 2058 return zlabel.handle_value (); |
6705 | 2059 } |
6406 | 2060 |
6705 | 2061 void |
6844 | 2062 axes::properties::remove_child (const graphics_handle& h) |
6705 | 2063 { |
7363 | 2064 if (title.handle_value ().ok () && h == title.handle_value ()) |
6705 | 2065 title = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363 | 2066 else if (xlabel.handle_value ().ok () && h == xlabel.handle_value ()) |
6705 | 2067 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363 | 2068 else if (ylabel.handle_value ().ok () && h == ylabel.handle_value ()) |
6705 | 2069 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
7363 | 2070 else if (zlabel.handle_value ().ok () && h == zlabel.handle_value ()) |
6705 | 2071 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__); |
2072 else | |
2073 base_properties::remove_child (h); | |
2074 } | |
6406 | 2075 |
6705 | 2076 void |
6844 | 2077 axes::properties::delete_children (void) |
6705 | 2078 { |
2079 base_properties::delete_children (); | |
2080 | |
7363 | 2081 gh_manager::free (title.handle_value ()); |
2082 gh_manager::free (xlabel.handle_value ()); | |
2083 gh_manager::free (ylabel.handle_value ()); | |
2084 gh_manager::free (zlabel.handle_value ()); | |
6705 | 2085 } |
6406 | 2086 |
7427 | 2087 inline Matrix |
2088 xform_matrix (void) | |
2089 { | |
2090 Matrix m (4, 4, 0.0); | |
2091 for (int i = 0; i < 4; i++) | |
2092 m(i,i) = 1; | |
2093 return m; | |
2094 } | |
2095 | |
2096 inline ColumnVector | |
2097 xform_vector (void) | |
2098 { | |
2099 ColumnVector v (4, 0.0); | |
2100 v(3) = 1; | |
2101 return v; | |
2102 } | |
2103 | |
2104 inline ColumnVector | |
2105 xform_vector (double x, double y, double z) | |
2106 { | |
2107 ColumnVector v (4, 1.0); | |
2108 v(0) = x; v(1) = y; v(2) = z; | |
2109 return v; | |
2110 } | |
2111 | |
2112 inline ColumnVector | |
2113 transform (const Matrix& m, double x, double y, double z) | |
2114 { | |
2115 return (m * xform_vector (x, y, z)); | |
2116 } | |
2117 | |
2118 inline Matrix | |
2119 xform_scale (double x, double y, double z) | |
2120 { | |
2121 Matrix m (4, 4, 0.0); | |
2122 m(0,0) = x; m(1,1) = y; m(2,2) = z; m(3,3) = 1; | |
2123 return m; | |
2124 } | |
2125 | |
2126 inline Matrix | |
2127 xform_translate (double x, double y, double z) | |
2128 { | |
2129 Matrix m = xform_matrix (); | |
2130 m(0,3) = x; m(1,3) = y; m(2,3) = z; m(3,3) = 1; | |
2131 return m; | |
2132 } | |
2133 | |
2134 inline void | |
2135 scale (Matrix& m, double x, double y, double z) | |
2136 { | |
2137 m = m * xform_scale (x, y, z); | |
2138 } | |
2139 | |
2140 inline void | |
2141 translate (Matrix& m, double x, double y, double z) | |
2142 { | |
2143 m = m * xform_translate (x, y, z); | |
2144 } | |
2145 | |
2146 inline void | |
2147 xform (ColumnVector& v, const Matrix& m) | |
2148 { | |
2149 v = m*v; | |
2150 } | |
2151 | |
2152 inline void | |
2153 scale (ColumnVector& v, double x, double y, double z) | |
2154 { | |
2155 v(0) *= x; | |
2156 v(1) *= y; | |
2157 v(2) *= z; | |
2158 } | |
2159 | |
2160 inline void | |
2161 translate (ColumnVector& v, double x, double y, double z) | |
2162 { | |
2163 v(0) += x; | |
2164 v(1) += y; | |
2165 v(2) += z; | |
2166 } | |
2167 | |
2168 inline void | |
2169 normalize (ColumnVector& v) | |
2170 { | |
2171 double fact = 1.0/sqrt(v(0)*v(0)+v(1)*v(1)+v(2)*v(2)); | |
2172 scale (v, fact, fact, fact); | |
2173 } | |
2174 | |
2175 inline double | |
2176 dot (const ColumnVector& v1, const ColumnVector& v2) | |
2177 { | |
2178 return (v1(0)*v2(0)+v1(1)*v2(1)+v1(2)*v2(2)); | |
2179 } | |
2180 | |
2181 inline double | |
2182 norm (const ColumnVector& v) | |
2183 { | |
2184 return sqrt (dot (v, v)); | |
2185 } | |
2186 | |
2187 inline ColumnVector | |
2188 cross (const ColumnVector& v1, const ColumnVector& v2) | |
2189 { | |
2190 ColumnVector r = xform_vector (); | |
2191 r(0) = v1(1)*v2(2)-v1(2)*v2(1); | |
2192 r(1) = v1(2)*v2(0)-v1(0)*v2(2); | |
2193 r(2) = v1(0)*v2(1)-v1(1)*v2(0); | |
2194 return r; | |
2195 } | |
2196 | |
2197 inline Matrix | |
2198 unit_cube (void) | |
2199 { | |
2200 static double data[32] = { | |
2201 0,0,0,1, | |
2202 1,0,0,1, | |
2203 0,1,0,1, | |
2204 0,0,1,1, | |
2205 1,1,0,1, | |
2206 1,0,1,1, | |
2207 0,1,1,1, | |
2208 1,1,1,1}; | |
2209 Matrix m (4, 8); | |
2210 memcpy (m.fortran_vec (), data, sizeof(double)*32); | |
2211 return m; | |
2212 } | |
2213 | |
2214 inline ColumnVector | |
2215 cam2xform (const Array<double>& m) | |
2216 { | |
2217 ColumnVector retval (4, 1.0); | |
2218 memcpy (retval.fortran_vec (), m.fortran_vec (), sizeof(double)*3); | |
2219 return retval; | |
2220 } | |
2221 | |
2222 inline RowVector | |
2223 xform2cam (const ColumnVector& v) | |
2224 { | |
2225 return v.extract_n (0, 3).transpose (); | |
2226 } | |
2227 | |
2228 void | |
2229 axes::properties::update_camera (void) | |
2230 { | |
2231 double xd = (xdir_is ("normal") ? 1 : -1); | |
2232 double yd = (ydir_is ("normal") ? 1 : -1); | |
2233 double zd = (zdir_is ("normal") ? 1 : -1); | |
2234 | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2235 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
|
2236 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
|
2237 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
|
2238 |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2239 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
|
2240 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
|
2241 double zo = zlimits(zd > 0 ? 0 : 1); |
7427 | 2242 |
2243 Matrix pb = get_plotboxaspectratio ().matrix_value (); | |
2244 | |
2245 bool autocam = (camerapositionmode_is ("auto") | |
2246 && cameratargetmode_is ("auto") | |
2247 && cameraupvectormode_is ("auto") | |
2248 && cameraviewanglemode_is ("auto")); | |
2249 bool dowarp = (autocam && dataaspectratiomode_is("auto") | |
2250 && plotboxaspectratiomode_is ("auto")); | |
2251 | |
2252 ColumnVector c_eye (xform_vector ()); | |
2253 ColumnVector c_center (xform_vector ()); | |
2254 ColumnVector c_upv (xform_vector ()); | |
2255 | |
2256 if (cameratargetmode_is ("auto")) | |
2257 { | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2258 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
|
2259 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
|
2260 c_center(2) = (zlimits(0)+zlimits(1))/2; |
7427 | 2261 |
2262 cameratarget = xform2cam (c_center); | |
2263 } | |
2264 else | |
2265 c_center = cam2xform (get_cameratarget ().matrix_value ()); | |
2266 | |
2267 if (camerapositionmode_is ("auto")) | |
2268 { | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2269 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
|
2270 double az = tview(0), el = tview(1); |
7427 | 2271 double d = 5*sqrt(pb(0)*pb(0)+pb(1)*pb(1)+pb(2)*pb(2)); |
2272 | |
2273 if (el == 90 || el == -90) | |
2274 c_eye(2) = d*signum(el); | |
2275 else | |
2276 { | |
2277 az *= M_PI/180.0; | |
2278 el *= M_PI/180.0; | |
2279 c_eye(0) = d*cos(el)*sin(az); | |
2280 c_eye(1) = -d*cos(el)*cos(az); | |
2281 c_eye(2) = d*sin(el); | |
2282 } | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2283 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
|
2284 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
|
2285 c_eye(2) = c_eye(2)*(zlimits(1)-zlimits(0))/(zd*pb(2))+c_center(2); |
7427 | 2286 |
2287 cameraposition = xform2cam (c_eye); | |
2288 } | |
2289 else | |
2290 c_eye = cam2xform (get_cameraposition ().matrix_value ()); | |
2291 | |
2292 if (cameraupvectormode_is ("auto")) | |
2293 { | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2294 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
|
2295 double az = tview(0), el = tview(1); |
7427 | 2296 |
2297 if (el == 90 || el == -90) | |
2298 { | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2299 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
|
2300 c_upv(1) = cos(az*M_PI/180.0)*(ylimits(1)-ylimits(0))/pb(1); |
7427 | 2301 } |
2302 else | |
2303 c_upv(2) = 1; | |
2304 | |
2305 cameraupvector = xform2cam (c_upv); | |
2306 } | |
2307 else | |
2308 c_upv = cam2xform (get_cameraupvector ().matrix_value ()); | |
2309 | |
2310 Matrix x_view = xform_matrix (); | |
2311 Matrix x_projection = xform_matrix (); | |
2312 Matrix x_viewport = xform_matrix (); | |
2313 Matrix x_normrender = xform_matrix (); | |
2314 Matrix x_pre = xform_matrix (); | |
2315 | |
2316 x_render = xform_matrix (); | |
2317 x_render_inv = xform_matrix (); | |
2318 | |
2319 scale (x_pre, pb(0), pb(1), pb(2)); | |
2320 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
|
2321 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
|
2322 zd/(zlimits(1)-zlimits(0))); |
7427 | 2323 translate (x_pre, -xo, -yo, -zo); |
2324 | |
2325 xform (c_eye, x_pre); | |
2326 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
|
2327 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
|
2328 pb(2)/(zlimits(1)-zlimits(0))); |
7427 | 2329 translate (c_center, -c_eye(0), -c_eye(1), -c_eye(2)); |
2330 | |
2331 ColumnVector F (c_center), f (F), UP (c_upv); | |
2332 normalize (f); | |
2333 normalize (UP); | |
2334 | |
7440 | 2335 if (std::abs (dot (f, UP)) > 1e-15) |
7427 | 2336 { |
2337 double fa = 1/sqrt(1-f(2)*f(2)); | |
2338 scale (UP, fa, fa, fa); | |
2339 } | |
2340 | |
2341 ColumnVector s = cross (f, UP); | |
2342 ColumnVector u = cross (s, f); | |
2343 | |
2344 scale (x_view, 1, 1, -1); | |
2345 Matrix l = xform_matrix (); | |
2346 l(0,0) = s(0); l(0,1) = s(1); l(0,2) = s(2); | |
2347 l(1,0) = u(0); l(1,1) = u(1); l(1,2) = u(2); | |
2348 l(2,0) = -f(0); l(2,1) = -f(1); l(2,2) = -f(2); | |
2349 x_view = x_view * l; | |
2350 translate (x_view, -c_eye(0), -c_eye(1), -c_eye(2)); | |
2351 scale (x_view, pb(0), pb(1), pb(2)); | |
2352 translate (x_view, -0.5, -0.5, -0.5); | |
2353 | |
2354 Matrix x_cube = x_view * unit_cube (); | |
2355 ColumnVector cmin = x_cube.row_min (), cmax = x_cube.row_max (); | |
2356 double xM = cmax(0)-cmin(0); | |
2357 double yM = cmax(1)-cmin(1); | |
2358 | |
7447 | 2359 Matrix bb = get_boundingbox (true); |
7427 | 2360 |
2361 double v_angle; | |
2362 | |
2363 if (cameraviewanglemode_is ("auto")) | |
2364 { | |
2365 double af; | |
2366 | |
2367 // FIXME: Was this really needed? When compared to Matlab, it | |
2368 // does not seem to be required. Need investigation with concrete | |
2369 // backend to see results visually. | |
2370 if (false && dowarp) | |
2371 af = 1.0 / (xM > yM ? xM : yM); | |
2372 else | |
2373 { | |
2374 if ((bb(2)/bb(3)) > (xM/yM)) | |
2375 af = 1.0 / yM; | |
2376 else | |
2377 af = 1.0 / xM; | |
2378 } | |
2379 v_angle = 2 * (180.0 / M_PI) * atan (1 / (2 * af * norm (F))); | |
2380 | |
2381 cameraviewangle = v_angle; | |
2382 } | |
2383 else | |
2384 v_angle = get_cameraviewangle (); | |
2385 | |
2386 double pf = 1 / (2 * tan ((v_angle / 2) * M_PI / 180.0) * norm (F)); | |
2387 scale (x_projection, pf, pf, 1); | |
2388 | |
2389 if (dowarp) | |
2390 { | |
2391 xM *= pf; | |
2392 yM *= pf; | |
7447 | 2393 translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); |
7427 | 2394 scale (x_viewport, bb(2)/xM, -bb(3)/yM, 1); |
2395 } | |
2396 else | |
2397 { | |
2398 double pix = 1; | |
2399 if (autocam) | |
2400 { | |
2401 if ((bb(2)/bb(3)) > (xM/yM)) | |
2402 pix = bb(3); | |
2403 else | |
2404 pix = bb(2); | |
2405 } | |
2406 else | |
2407 pix = (bb(2) < bb(3) ? bb(2) : bb(3)); | |
7447 | 2408 translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); |
7427 | 2409 scale (x_viewport, pix, -pix, 1); |
2410 } | |
2411 | |
2412 x_normrender = x_viewport * x_projection * x_view; | |
2413 | |
2414 x_cube = x_normrender * unit_cube (); | |
2415 cmin = x_cube.row_min (); | |
2416 cmax = x_cube.row_max (); | |
2417 x_zlim.resize (1, 2); | |
2418 x_zlim(0) = cmin(2); | |
2419 x_zlim(1) = cmax(2); | |
2420 | |
2421 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
|
2422 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
|
2423 zd/(zlimits(1)-zlimits(0))); |
7427 | 2424 translate (x_render, -xo, -yo, -zo); |
2425 | |
2426 x_viewtransform = x_view; | |
2427 x_projectiontransform = x_projection; | |
2428 x_viewporttransform = x_viewport; | |
2429 x_normrendertransform = x_normrender; | |
2430 x_rendertransform = x_render; | |
2431 | |
2432 x_render_inv = x_render.inverse (); | |
2433 | |
2434 // Note: these matrices are a slight modified version of the regular | |
2435 // matrices, more suited for OpenGL rendering (x_gl_mat1 => light | |
2436 // => x_gl_mat2) | |
2437 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
|
2438 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
|
2439 zd/(zlimits(1)-zlimits(0))); |
7427 | 2440 translate (x_gl_mat1, -xo, -yo, -zo); |
2441 x_gl_mat2 = x_viewport * x_projection; | |
2442 } | |
2443 | |
2444 void | |
2445 axes::properties::update_aspectratios (void) | |
2446 { | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2447 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
|
2448 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
|
2449 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
|
2450 |
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
2451 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
|
2452 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
|
2453 double dz = (zlimits(1)-zlimits(0)); |
7427 | 2454 |
2455 if (dataaspectratiomode_is ("auto")) | |
2456 { | |
2457 double dmin = xmin (xmin (dx, dy), dz); | |
2458 Matrix da (1, 3, 0.0); | |
2459 | |
2460 da(0) = dx/dmin; | |
2461 da(1) = dy/dmin; | |
2462 da(2) = dz/dmin; | |
2463 | |
2464 dataaspectratio = da; | |
2465 } | |
2466 | |
2467 if (plotboxaspectratiomode_is ("auto")) | |
2468 { | |
2469 if (dataaspectratiomode_is ("auto")) | |
2470 plotboxaspectratio = Matrix (1, 3, 1.0); | |
2471 else | |
2472 { | |
2473 Matrix da = get_dataaspectratio ().matrix_value (); | |
2474 Matrix pba (1, 3, 0.0); | |
2475 | |
2476 pba(0) = dx/da(0); | |
2477 pba(1) = dy/da(1); | |
2478 pba(2) = dz/da(2); | |
2479 } | |
2480 } | |
2481 | |
2482 // FIXME: if plotboxaspectratiomode is "manual", limits | |
2483 // and/or dataaspectratio might be adapted | |
2484 } | |
2485 | |
7447 | 2486 // The INTERNAL flag defines whether position or outerposition is used. |
2487 | |
7427 | 2488 Matrix |
7447 | 2489 axes::properties::get_boundingbox (bool internal) const |
7427 | 2490 { |
7447 | 2491 graphics_object obj = gh_manager::get_object (get_parent ()); |
2492 Matrix parent_bb = obj.get_properties ().get_boundingbox (true); | |
2493 Matrix pos = (internal ? | |
2494 get_position ().matrix_value () | |
2495 : get_outerposition ().matrix_value ()); | |
2496 | |
2497 | |
2498 pos = convert_position (pos, get_units (), "pixels", | |
2499 parent_bb.extract_n (0, 2, 1, 2), get_backend ()); | |
7427 | 2500 pos(0)--; |
2501 pos(1)--; | |
7447 | 2502 pos(1) = parent_bb(3) - pos(1) - pos(3); |
7427 | 2503 |
2504 return pos; | |
2505 } | |
2506 | |
7435 | 2507 ColumnVector |
2508 graphics_xform::xform_vector (double x, double y, double z) | |
2509 { return ::xform_vector (x, y, z); } | |
2510 | |
2511 Matrix | |
2512 graphics_xform::xform_eye (void) | |
2513 { return ::xform_matrix (); } | |
2514 | |
2515 ColumnVector | |
2516 graphics_xform::transform (double x, double y, double z, | |
2517 bool use_scale) const | |
2518 { | |
2519 if (use_scale) | |
2520 { | |
2521 x = sx.scale (x); | |
2522 y = sy.scale (y); | |
2523 z = sz.scale (z); | |
2524 } | |
2525 | |
2526 return ::transform (xform, x, y, z); | |
2527 } | |
2528 | |
2529 ColumnVector | |
2530 graphics_xform::untransform (double x, double y, double z, | |
2531 bool use_scale) const | |
2532 { | |
2533 ColumnVector v = ::transform (xform_inv, x, y, z); | |
2534 | |
2535 if (use_scale) | |
2536 { | |
2537 v(0) = sx.unscale (v(0)); | |
2538 v(1) = sy.unscale (v(1)); | |
2539 v(2) = sz.unscale (v(2)); | |
2540 } | |
2541 | |
2542 return v; | |
2543 } | |
2544 | |
6836 | 2545 octave_value |
7189 | 2546 axes::get_default (const caseless_str& name) const |
6836 | 2547 { |
2548 octave_value retval = default_properties.lookup (name); | |
2549 | |
2550 if (retval.is_undefined ()) | |
2551 { | |
2552 graphics_handle parent = get_parent (); | |
2553 graphics_object parent_obj = gh_manager::get_object (parent); | |
2554 | |
2555 retval = parent_obj.get_default (name); | |
2556 } | |
2557 | |
2558 return retval; | |
2559 } | |
2560 | |
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
|
2561 // FIXME: Maybe this should go into array_property class? |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2562 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
|
2563 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
|
2564 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
|
2565 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2566 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
|
2567 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
|
2568 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
|
2569 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
|
2570 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
|
2571 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
|
2572 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
|
2573 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
|
2574 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
|
2575 } |
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 |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2577 // 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
|
2578 // integral. |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2579 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2580 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
|
2581 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2582 if (x == 0) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2583 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2584 a = 0; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2585 b = 0; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2586 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2587 else |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2588 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2589 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
|
2590 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
|
2591 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
|
2592 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
|
2593 if (a < 1) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2594 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2595 a *= 10; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2596 b -= 1; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2597 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2598 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2599 if (x < 0) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2600 a = -a; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2601 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2602 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2603 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2604 // 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
|
2605 // 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
|
2606 // FIXME -- add log ticks |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2607 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2608 double |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2609 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
|
2610 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2611 int ticint = 5; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2612 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2613 // 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
|
2614 // 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
|
2615 // 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
|
2616 // 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
|
2617 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2618 double a; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2619 int b, x; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2620 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2621 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
|
2622 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2623 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
|
2624 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
|
2625 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
|
2626 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2627 if (a < sqrt_2) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2628 x = 1; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2629 else if (a < sqrt_10) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2630 x = 2; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2631 else if (a < sqrt_50) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2632 x = 5; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2633 else |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2634 x = 10; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2635 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2636 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
|
2637 |
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 |
7222 | 2640 // Attempt to make "nice" limits from the actual max and min of the |
2641 // data. For log plots, we will also use the smallest strictly positive | |
2642 // value. | |
2643 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2644 Matrix |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2645 axes::properties::get_axis_limits (double xmin, double xmax, double min_pos, bool logscale) |
7222 | 2646 { |
2647 Matrix retval; | |
2648 | |
2649 double min_val = xmin; | |
2650 double max_val = xmax; | |
2651 | |
2652 if (! (xisinf (min_val) || xisinf (max_val))) | |
2653 { | |
2654 if (logscale) | |
2655 { | |
2656 if (xisinf (min_pos)) | |
2657 { | |
2658 // warning ("axis: logscale with no positive values to plot"); | |
2659 return retval; | |
2660 } | |
2661 | |
2662 if (min_val <= 0) | |
2663 { | |
2664 warning ("axis: omitting nonpositive data in log plot"); | |
2665 min_val = min_pos; | |
2666 } | |
2667 // FIXME -- maybe this test should also be relative? | |
2668 if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) | |
2669 { | |
2670 min_val *= 0.9; | |
2671 max_val *= 1.1; | |
2672 } | |
2673 min_val = pow (10, floor (log10 (min_val))); | |
2674 max_val = pow (10, ceil (log10 (max_val))); | |
2675 } | |
2676 else | |
2677 { | |
2678 if (min_val == 0 && max_val == 0) | |
2679 { | |
2680 min_val = -1; | |
2681 max_val = 1; | |
2682 } | |
2683 // FIXME -- maybe this test should also be relative? | |
2684 else if (std::abs (min_val - max_val) < sqrt (DBL_EPSILON)) | |
2685 { | |
2686 min_val -= 0.1 * std::abs (min_val); | |
2687 max_val += 0.1 * std::abs (max_val); | |
2688 } | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2689 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2690 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
|
2691 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
|
2692 max_val = tick_sep * ceil (max_val / tick_sep); |
7222 | 2693 } |
2694 } | |
2695 | |
2696 retval.resize (1, 2); | |
2697 | |
2698 retval(0) = min_val; | |
2699 retval(1) = max_val; | |
2700 | |
2701 return retval; | |
2702 } | |
2703 | |
7446 | 2704 void |
7857
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2705 axes::properties::calc_ticks_and_lims (array_property& lims, array_property& ticks, bool limmode_is_auto, bool is_logscale) |
7446 | 2706 { |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2707 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2708 // FIXME -- add log ticks and lims |
7446 | 2709 |
2710 if (lims.get ().is_empty ()) | |
2711 return; | |
2712 | |
2713 double lo = (lims.get ().matrix_value ()) (0); | |
2714 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
|
2715 // 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
|
2716 if (hi < lo) |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2717 { |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2718 double tmp = hi; |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2719 hi = lo; |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2720 lo = tmp; |
d3dcfdfdc434
handle unsorted limits when calculatin gticks and limits
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2721 } |
7857
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2722 |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2723 if (is_logscale) |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2724 { |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2725 // 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
|
2726 hi = std::log10 (hi); |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2727 lo = std::log10 (lo); |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2728 } |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2729 |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2730 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
|
2731 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2732 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
|
2733 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
|
2734 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2735 if (limmode_is_auto) |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2736 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2737 // 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
|
2738 Matrix tmp_lims (1,2); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2739 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
|
2740 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
|
2741 |
7857
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2742 if (is_logscale) |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2743 { |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2744 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
|
2745 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
|
2746 } |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2747 lims = tmp_lims; |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2748 } |
7446 | 2749 else |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2750 { |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2751 // 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
|
2752 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
|
2753 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
|
2754 } |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2755 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2756 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
|
2757 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
|
2758 { |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2759 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
|
2760 if (is_logscale) |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2761 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
|
2762 } |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2763 |
09b1a9c88128
added (far from perfect) support for logscale ticks
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7855
diff
changeset
|
2764 |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2765 |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2766 ticks = tmp_ticks; |
7446 | 2767 } |
2768 | |
7222 | 2769 static bool updating_axis_limits = false; |
2770 | |
7214 | 2771 void |
7222 | 2772 axes::update_axis_limits (const std::string& axis_type) |
7214 | 2773 { |
7222 | 2774 if (updating_axis_limits) |
2775 return; | |
2776 | |
2777 Matrix kids = xproperties.get_children (); | |
2778 | |
2779 octave_idx_type n = kids.numel (); | |
2780 | |
2781 double min_val = octave_Inf; | |
2782 double max_val = -octave_Inf; | |
2783 double min_pos = octave_Inf; | |
2784 | |
2785 char update_type = 0; | |
2786 | |
2787 Matrix limits; | |
2788 | |
2789 if (axis_type == "xdata" || axis_type == "xscale" | |
2790 || axis_type == "xldata" || axis_type == "xudata" | |
2791 || axis_type == "xlimmode") | |
2792 { | |
7363 | 2793 if (xproperties.xlimmode_is ("auto")) |
7222 | 2794 { |
2795 for (octave_idx_type i = 0; i < n; i++) | |
2796 { | |
2797 graphics_object obj = gh_manager::get_object (kids(i)); | |
2798 | |
2799 if (obj.isa ("line") || obj.isa ("image") | |
2800 || obj.isa ("patch") || obj.isa ("surface")) | |
2801 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2802 array_property xdata = obj.get_xdata_property (); |
7222 | 2803 |
2804 check_limit_vals (min_val, max_val, min_pos, xdata); | |
2805 | |
2806 if (obj.isa ("line")) | |
2807 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2808 array_property xldata = obj.get_xldata_property (); |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2809 array_property xudata = obj.get_xudata_property (); |
7222 | 2810 |
2811 check_limit_vals (min_val, max_val, min_pos, xldata); | |
2812 check_limit_vals (min_val, max_val, min_pos, xudata); | |
2813 } | |
2814 } | |
2815 } | |
2816 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2817 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
|
2818 xproperties.xscale_is ("log")); |
7222 | 2819 |
2820 update_type = 'x'; | |
2821 } | |
2822 } | |
2823 else if (axis_type == "ydata" || axis_type == "yscale" | |
2824 || axis_type == "ldata" || axis_type == "udata" | |
2825 || axis_type == "ylimmode") | |
2826 { | |
7363 | 2827 if (xproperties.ylimmode_is ("auto")) |
7222 | 2828 { |
2829 for (octave_idx_type i = 0; i < n; i++) | |
2830 { | |
2831 graphics_object obj = gh_manager::get_object (kids(i)); | |
2832 | |
2833 if (obj.isa ("line") || obj.isa ("image") | |
2834 || obj.isa ("patch") || obj.isa ("surface")) | |
2835 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2836 array_property ydata = obj.get_ydata_property (); |
7222 | 2837 |
2838 check_limit_vals (min_val, max_val, min_pos, ydata); | |
2839 | |
2840 if (obj.isa ("line")) | |
2841 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2842 array_property ldata = obj.get_ldata_property (); |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2843 array_property udata = obj.get_udata_property (); |
7222 | 2844 |
2845 check_limit_vals (min_val, max_val, min_pos, ldata); | |
2846 check_limit_vals (min_val, max_val, min_pos, udata); | |
2847 } | |
2848 } | |
2849 } | |
2850 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2851 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
|
2852 xproperties.yscale_is ("log")); |
7222 | 2853 |
2854 update_type = 'y'; | |
2855 } | |
2856 } | |
2857 else if (axis_type == "zdata" || axis_type == "zscale" | |
2858 || axis_type == "zlimmode") | |
2859 { | |
7363 | 2860 if (xproperties.zlimmode_is ("auto")) |
7222 | 2861 { |
2862 for (octave_idx_type i = 0; i < n; i++) | |
2863 { | |
2864 graphics_object obj = gh_manager::get_object (kids(i)); | |
2865 | |
2866 if (obj.isa ("line") || obj.isa ("patch") || obj.isa ("surface")) | |
2867 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2868 array_property zdata = obj.get_zdata_property (); |
7222 | 2869 |
2870 check_limit_vals (min_val, max_val, min_pos, zdata); | |
2871 } | |
2872 } | |
2873 | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7824
diff
changeset
|
2874 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
|
2875 xproperties.zscale_is ("log")); |
7222 | 2876 |
2877 update_type = 'z'; | |
2878 } | |
2879 } | |
2880 else if (axis_type == "cdata" || axis_type == "climmode") | |
2881 { | |
7363 | 2882 if (xproperties.climmode_is ("auto")) |
7222 | 2883 { |
2884 for (octave_idx_type i = 0; i < n; i++) | |
2885 { | |
2886 graphics_object obj = gh_manager::get_object (kids(i)); | |
2887 | |
2888 if (obj.isa ("image") || obj.isa ("patch") || obj.isa ("surface")) | |
2889 { | |
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
|
2890 array_property cdata = obj.get_cdata_property (); |
7222 | 2891 |
2892 check_limit_vals (min_val, max_val, min_pos, cdata); | |
2893 } | |
2894 } | |
2895 | |
2896 if (min_val == max_val) | |
2897 max_val = min_val + 1; | |
2898 | |
2899 limits.resize (1, 2); | |
2900 | |
2901 limits(0) = min_val; | |
2902 limits(1) = max_val; | |
2903 | |
2904 update_type = 'c'; | |
2905 } | |
2906 | |
2907 } | |
2908 | |
2909 unwind_protect_bool (updating_axis_limits); | |
2910 updating_axis_limits = true; | |
2911 | |
2912 switch (update_type) | |
2913 { | |
2914 case 'x': | |
2915 xproperties.set_xlim (limits); | |
2916 xproperties.set_xlimmode ("auto"); | |
7446 | 2917 xproperties.update_xlim (); |
7222 | 2918 break; |
2919 | |
2920 case 'y': | |
2921 xproperties.set_ylim (limits); | |
2922 xproperties.set_ylimmode ("auto"); | |
7446 | 2923 xproperties.update_ylim (); |
7222 | 2924 break; |
2925 | |
2926 case 'z': | |
2927 xproperties.set_zlim (limits); | |
2928 xproperties.set_zlimmode ("auto"); | |
7446 | 2929 xproperties.update_zlim (); |
7222 | 2930 break; |
2931 | |
2932 case 'c': | |
2933 xproperties.set_clim (limits); | |
2934 xproperties.set_climmode ("auto"); | |
2935 break; | |
2936 | |
2937 default: | |
2938 break; | |
2939 } | |
2940 | |
7427 | 2941 xproperties.update_transform (); |
2942 | |
7222 | 2943 unwind_protect::run (); |
7214 | 2944 } |
2945 | |
7855
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2946 void |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2947 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
|
2948 { |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2949 zoom_stack.push_front (xlimmode.get ()); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2950 zoom_stack.push_front (xlim.get ()); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2951 zoom_stack.push_front (ylimmode.get ()); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2952 zoom_stack.push_front (ylim.get ()); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2953 |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2954 xlim = xl; |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2955 xlimmode = "manual"; |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2956 ylim = yl; |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2957 ylimmode = "manual"; |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2958 |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2959 update_transform (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2960 update_xlim (false); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2961 update_ylim (false); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2962 } |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2963 |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2964 void |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2965 axes::properties::unzoom (void) |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2966 { |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2967 if (zoom_stack.size () >= 4) |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2968 { |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2969 ylim = zoom_stack.front (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2970 zoom_stack.pop_front (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2971 ylimmode = zoom_stack.front (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2972 zoom_stack.pop_front (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2973 xlim = zoom_stack.front (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2974 zoom_stack.pop_front (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2975 xlimmode = zoom_stack.front (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2976 zoom_stack.pop_front (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2977 |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2978 update_transform (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2979 update_xlim (false); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2980 update_ylim (false); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2981 } |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2982 } |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2983 |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2984 void |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2985 axes::properties::clear_zoom_stack (void) |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2986 { |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2987 while (zoom_stack.size () > 4) |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2988 zoom_stack.pop_front (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2989 |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2990 unzoom (); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2991 } |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
2992 |
7363 | 2993 // --------------------------------------------------------------------- |
2994 | |
2995 // Note: "line" code is entirely auto-generated | |
6406 | 2996 |
2997 // --------------------------------------------------------------------- | |
2998 | |
7363 | 2999 // Note: "text" code is entirely auto-generated |
6406 | 3000 |
3001 // --------------------------------------------------------------------- | |
3002 | |
7363 | 3003 // Note: "image" code is entirely auto-generated |
6406 | 3004 |
3005 // --------------------------------------------------------------------- | |
3006 | |
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
|
3007 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
|
3008 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
|
3009 { |
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
|
3010 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
|
3011 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
|
3012 } |
6807 | 3013 |
3014 // --------------------------------------------------------------------- | |
3015 | |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3016 octave_value |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3017 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
|
3018 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3019 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
|
3020 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3021 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3022 inline void |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3023 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
|
3024 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
|
3025 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
|
3026 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3027 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
|
3028 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
|
3029 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
|
3030 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3031 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3032 void |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3033 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
|
3034 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3035 if (normalmode_is ("auto")) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3036 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3037 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
|
3038 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
|
3039 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
|
3040 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3041 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
|
3042 int i1, i2, i3; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3043 int j1, j2, j3; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3044 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3045 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
|
3046 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
|
3047 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3048 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
|
3049 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3050 i1 = i2 = i3 = 0; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3051 j1 = j2 = j3 = 0; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3052 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3053 // 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
|
3054 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
|
3055 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3056 if (y_mat) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3057 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3058 i1 = i-1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3059 i2 = i; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3060 i3 = i+1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3061 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3062 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3063 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
|
3064 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3065 if (x_mat) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3066 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3067 j1 = j-1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3068 j2 = j; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3069 j3 = j+1; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3070 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3071 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3072 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
|
3073 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
|
3074 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
|
3075 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3076 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
|
3077 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
|
3078 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3079 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
|
3080 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
|
3081 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3082 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
|
3083 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
|
3084 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3085 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
|
3086 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
|
3087 nx, ny, nz); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3088 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3089 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
|
3090 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3091 nx /= d; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3092 ny /= d; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3093 nz /= d; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3094 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3095 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3096 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3097 vertexnormals = n; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3098 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3099 } |
6406 | 3100 |
3101 // --------------------------------------------------------------------- | |
3102 | |
3103 octave_value | |
7189 | 3104 base_graphics_object::get_default (const caseless_str& name) const |
6406 | 3105 { |
3106 graphics_handle parent = get_parent (); | |
3107 graphics_object parent_obj = gh_manager::get_object (parent); | |
3108 | |
3109 return parent_obj.get_default (type () + name); | |
3110 } | |
3111 | |
3112 octave_value | |
7189 | 3113 base_graphics_object::get_factory_default (const caseless_str& name) const |
6406 | 3114 { |
3115 graphics_object parent_obj = gh_manager::get_object (0); | |
3116 | |
3117 return parent_obj.get_factory_default (type () + name); | |
3118 } | |
3119 | |
7286 | 3120 // We use a random value for the handle to avoid issues with plots and |
3121 // scalar values for the first argument. | |
6406 | 3122 gh_manager::gh_manager (void) |
7286 | 3123 : handle_map (), handle_free_list (), |
3124 next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) | |
6406 | 3125 { |
3126 handle_map[0] = graphics_object (new root_figure ()); | |
7847
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7844
diff
changeset
|
3127 |
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7844
diff
changeset
|
3128 // Make sure the default backend is registered. |
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7844
diff
changeset
|
3129 graphics_backend::default_backend (); |
6406 | 3130 } |
3131 | |
3132 graphics_handle | |
3133 gh_manager::do_make_graphics_handle (const std::string& go_name, | |
7370 | 3134 const graphics_handle& p, bool do_createfcn) |
6406 | 3135 { |
3136 graphics_handle h = get_handle (go_name); | |
3137 | |
3138 base_graphics_object *go = 0; | |
3139 | |
3140 if (go_name == "figure") | |
3141 go = new figure (h, p); | |
3142 else if (go_name == "axes") | |
3143 go = new axes (h, p); | |
3144 else if (go_name == "line") | |
3145 go = new line (h, p); | |
3146 else if (go_name == "text") | |
3147 go = new text (h, p); | |
3148 else if (go_name == "image") | |
3149 go = new image (h, p); | |
6807 | 3150 else if (go_name == "patch") |
3151 go = new patch (h, p); | |
6406 | 3152 else if (go_name == "surface") |
3153 go = new surface (h, p); | |
3154 if (go) | |
7370 | 3155 { |
3156 handle_map[h] = graphics_object (go); | |
3157 if (do_createfcn) | |
3158 go->get_properties ().execute_createfcn (); | |
3159 } | |
6406 | 3160 else |
3161 error ("gh_manager::do_make_graphics_handle: invalid object type `%s'", | |
3162 go_name.c_str ()); | |
3163 | |
3164 return h; | |
3165 } | |
3166 | |
3167 graphics_handle | |
3168 gh_manager::do_make_figure_handle (double val) | |
3169 { | |
3170 graphics_handle h = val; | |
3171 | |
3172 handle_map[h] = graphics_object (new figure (h, 0)); | |
3173 | |
3174 return h; | |
3175 } | |
3176 | |
3177 void | |
3178 gh_manager::do_push_figure (const graphics_handle& h) | |
3179 { | |
3180 do_pop_figure (h); | |
3181 | |
3182 figure_list.push_front (h); | |
3183 } | |
3184 | |
3185 void | |
3186 gh_manager::do_pop_figure (const graphics_handle& h) | |
3187 { | |
3188 for (figure_list_iterator p = figure_list.begin (); | |
3189 p != figure_list.end (); | |
3190 p++) | |
3191 { | |
3192 if (*p == h) | |
3193 { | |
3194 figure_list.erase (p); | |
3195 break; | |
3196 } | |
3197 } | |
3198 } | |
3199 | |
3200 property_list::plist_map_type | |
3201 root_figure::init_factory_properties (void) | |
3202 { | |
3203 property_list::plist_map_type plist_map; | |
3204 | |
6844 | 3205 plist_map["figure"] = figure::properties::factory_defaults (); |
3206 plist_map["axes"] = axes::properties::factory_defaults (); | |
3207 plist_map["line"] = line::properties::factory_defaults (); | |
3208 plist_map["text"] = text::properties::factory_defaults (); | |
3209 plist_map["image"] = image::properties::factory_defaults (); | |
3210 plist_map["patch"] = patch::properties::factory_defaults (); | |
3211 plist_map["surface"] = surface::properties::factory_defaults (); | |
6406 | 3212 |
3213 return plist_map; | |
3214 } | |
3215 | |
3216 // --------------------------------------------------------------------- | |
3217 | |
3218 DEFUN (ishandle, args, , | |
3219 "-*- texinfo -*-\n\ | |
6678 | 3220 @deftypefn {Built-in Function} {} ishandle (@var{h})\n\ |
6406 | 3221 Return true if @var{h} is a graphics handle and false otherwise.\n\ |
3222 @end deftypefn") | |
3223 { | |
3224 octave_value retval; | |
3225 | |
3226 if (args.length () == 1) | |
3227 retval = is_handle (args(0)); | |
3228 else | |
3229 print_usage (); | |
3230 | |
3231 return retval; | |
3232 } | |
3233 | |
3234 DEFUN (set, args, , | |
3235 "-*- texinfo -*-\n\ | |
6678 | 3236 @deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v}, @dots{})\n\ |
6732 | 3237 Set the named property value or vector @var{p} to the value @var{v}\n\ |
6894 | 3238 for the graphics handle @var{h}.\n\ |
6406 | 3239 @end deftypefn") |
3240 { | |
3241 octave_value retval; | |
3242 | |
3243 int nargin = args.length (); | |
3244 | |
3245 if (nargin > 0) | |
3246 { | |
6732 | 3247 ColumnVector hcv (args(0).vector_value ()); |
6406 | 3248 |
3249 if (! error_state) | |
6732 | 3250 { |
6733 | 3251 bool request_drawnow = false; |
3252 | |
6732 | 3253 for (octave_idx_type n = 0; n < hcv.length (); n++) |
3254 { | |
3255 graphics_object obj = gh_manager::get_object (hcv(n)); | |
6406 | 3256 |
6732 | 3257 if (obj) |
3258 { | |
3259 obj.set (args.splice (0, 1)); | |
6406 | 3260 |
6733 | 3261 request_drawnow = true; |
6732 | 3262 } |
3263 else | |
6733 | 3264 { |
3265 error ("set: invalid handle (= %g)", hcv(n)); | |
3266 break; | |
3267 } | |
6732 | 3268 } |
6733 | 3269 |
3270 if (! error_state && request_drawnow) | |
7409 | 3271 Vdrawnow_requested = true; |
6732 | 3272 } |
6406 | 3273 else |
6732 | 3274 error ("set: expecting graphics handle as first argument"); |
6406 | 3275 } |
3276 else | |
3277 print_usage (); | |
3278 | |
3279 return retval; | |
3280 } | |
3281 | |
3282 DEFUN (get, args, , | |
3283 "-*- texinfo -*-\n\ | |
6678 | 3284 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ |
6406 | 3285 Return the named property @var{p} from the graphics handle @var{h}.\n\ |
3286 If @var{p} is omitted, return the complete property list for @var{h}.\n\ | |
6732 | 3287 If @var{h} is a vector, return a cell array including the property\n\ |
3288 values or lists respectively.\n\ | |
6406 | 3289 @end deftypefn") |
3290 { | |
3291 octave_value retval; | |
6732 | 3292 octave_value_list vlist; |
6406 | 3293 |
3294 int nargin = args.length (); | |
3295 | |
3296 if (nargin == 1 || nargin == 2) | |
3297 { | |
6732 | 3298 ColumnVector hcv (args(0).vector_value ()); |
6406 | 3299 |
3300 if (! error_state) | |
6732 | 3301 { |
6733 | 3302 octave_idx_type len = hcv.length (); |
3303 | |
3304 vlist.resize (len); | |
3305 | |
3306 for (octave_idx_type n = 0; n < len; n++) | |
6732 | 3307 { |
3308 graphics_object obj = gh_manager::get_object (hcv(n)); | |
6406 | 3309 |
6732 | 3310 if (obj) |
3311 { | |
3312 if (nargin == 1) | |
3313 vlist(n) = obj.get (); | |
3314 else | |
3315 { | |
7189 | 3316 caseless_str property = args(1).string_value (); |
6406 | 3317 |
6732 | 3318 if (! error_state) |
3319 vlist(n) = obj.get (property); | |
3320 else | |
6733 | 3321 { |
3322 error ("get: expecting property name as second argument"); | |
3323 break; | |
3324 } | |
6732 | 3325 } |
3326 } | |
3327 else | |
6733 | 3328 { |
3329 error ("get: invalid handle (= %g)", hcv(n)); | |
3330 break; | |
3331 } | |
6732 | 3332 } |
3333 } | |
6406 | 3334 else |
6732 | 3335 error ("get: expecting graphics handle as first argument"); |
6406 | 3336 } |
3337 else | |
3338 print_usage (); | |
3339 | |
6733 | 3340 if (! error_state) |
6732 | 3341 { |
6733 | 3342 octave_idx_type len = vlist.length (); |
3343 | |
3344 if (len > 1) | |
3345 retval = Cell (vlist); | |
3346 else if (len == 1) | |
3347 retval = vlist(0); | |
6732 | 3348 } |
3349 | |
6406 | 3350 return retval; |
3351 } | |
3352 | |
7379 | 3353 DEFUN (__get__, args, , |
3354 "-*- texinfo -*-\n\ | |
3355 @deftypefn {Built-in Function} {} __get__ (@var{h})\n\ | |
3356 Return all properties from the graphics handle @var{h}.\n\ | |
3357 If @var{h} is a vector, return a cell array including the property\n\ | |
3358 values or lists respectively.\n\ | |
3359 @end deftypefn") | |
3360 { | |
3361 octave_value retval; | |
3362 octave_value_list vlist; | |
3363 | |
3364 int nargin = args.length (); | |
3365 | |
3366 if (nargin == 1) | |
3367 { | |
3368 ColumnVector hcv (args(0).vector_value ()); | |
3369 | |
3370 if (! error_state) | |
3371 { | |
3372 octave_idx_type len = hcv.length (); | |
3373 | |
3374 vlist.resize (len); | |
3375 | |
3376 for (octave_idx_type n = 0; n < len; n++) | |
3377 { | |
3378 graphics_object obj = gh_manager::get_object (hcv(n)); | |
3379 | |
3380 if (obj) | |
3381 vlist(n) = obj.get (true); | |
3382 else | |
3383 { | |
3384 error ("get: invalid handle (= %g)", hcv(n)); | |
3385 break; | |
3386 } | |
3387 } | |
3388 } | |
3389 else | |
3390 error ("get: expecting graphics handle as first argument"); | |
3391 } | |
3392 else | |
3393 print_usage (); | |
3394 | |
3395 if (! error_state) | |
3396 { | |
3397 octave_idx_type len = vlist.length (); | |
3398 | |
3399 if (len > 1) | |
3400 retval = Cell (vlist); | |
3401 else if (len == 1) | |
3402 retval = vlist(0); | |
3403 } | |
3404 | |
3405 return retval; | |
3406 } | |
3407 | |
6406 | 3408 static octave_value |
3409 make_graphics_object (const std::string& go_name, | |
6874 | 3410 const octave_value_list& args) |
6406 | 3411 { |
3412 octave_value retval; | |
3413 | |
3414 double val = args(0).double_value (); | |
3415 | |
3416 if (! error_state) | |
3417 { | |
3418 graphics_handle parent = gh_manager::lookup (val); | |
3419 | |
7056 | 3420 if (parent.ok ()) |
6406 | 3421 { |
3422 graphics_handle h | |
7370 | 3423 = gh_manager::make_graphics_handle (go_name, parent, false); |
6406 | 3424 |
3425 if (! error_state) | |
3426 { | |
3427 adopt (parent, h); | |
3428 | |
3429 xset (h, args.splice (0, 1)); | |
7370 | 3430 xcreatefcn (h); |
6406 | 3431 |
6874 | 3432 retval = h.value (); |
7296 | 3433 |
3434 if (! error_state) | |
7409 | 3435 Vdrawnow_requested = true; |
6406 | 3436 } |
3437 else | |
3438 error ("__go%s__: unable to create graphics handle", | |
3439 go_name.c_str ()); | |
3440 } | |
3441 else | |
3442 error ("__go_%s__: invalid parent", go_name.c_str ()); | |
3443 } | |
3444 else | |
3445 error ("__go_%s__: invalid parent", go_name.c_str ()); | |
3446 | |
3447 return retval; | |
3448 } | |
3449 | |
3450 DEFUN (__go_figure__, args, , | |
3451 "-*- texinfo -*-\n\ | |
3452 @deftypefn {Built-in Function} {} __go_figure__ (@var{fignum})\n\ | |
6945 | 3453 Undocumented internal function.\n\ |
6406 | 3454 @end deftypefn") |
3455 { | |
3456 octave_value retval; | |
3457 | |
3458 if (args.length () > 0) | |
3459 { | |
3460 double val = args(0).double_value (); | |
3461 | |
3462 if (! error_state) | |
3463 { | |
3464 if (is_figure (val)) | |
3465 { | |
3466 graphics_handle h = gh_manager::lookup (val); | |
3467 | |
3468 xset (h, args.splice (0, 1)); | |
3469 | |
6874 | 3470 retval = h.value (); |
6406 | 3471 } |
3472 else | |
3473 { | |
3474 graphics_handle h = octave_NaN; | |
3475 | |
3476 if (xisnan (val)) | |
7370 | 3477 h = gh_manager::make_graphics_handle ("figure", 0, false); |
6406 | 3478 else if (val > 0 && D_NINT (val) == val) |
3479 h = gh_manager::make_figure_handle (val); | |
3480 else | |
3481 error ("__go_figure__: invalid figure number"); | |
3482 | |
7056 | 3483 if (! error_state && h.ok ()) |
6406 | 3484 { |
3485 adopt (0, h); | |
3486 | |
3487 xset (h, args.splice (0, 1)); | |
7370 | 3488 xcreatefcn (h); |
6406 | 3489 |
6874 | 3490 retval = h.value (); |
6406 | 3491 } |
3492 else | |
3493 error ("__go_figure__: failed to create figure handle"); | |
3494 } | |
3495 } | |
3496 else | |
3497 error ("__go_figure__: expecting figure number to be double value"); | |
3498 } | |
3499 else | |
3500 print_usage (); | |
3501 | |
3502 return retval; | |
3503 } | |
3504 | |
3505 #define GO_BODY(TYPE) \ | |
3506 octave_value retval; \ | |
3507 \ | |
3508 if (args.length () > 0) \ | |
3509 retval = make_graphics_object (#TYPE, args); \ | |
3510 else \ | |
3511 print_usage (); \ | |
3512 \ | |
3513 return retval | |
3514 | |
3515 DEFUN (__go_axes__, args, , | |
3516 "-*- texinfo -*-\n\ | |
3517 @deftypefn {Built-in Function} {} __go_axes__ (@var{parent})\n\ | |
6945 | 3518 Undocumented internal function.\n\ |
6406 | 3519 @end deftypefn") |
3520 { | |
3521 GO_BODY (axes); | |
3522 } | |
3523 | |
3524 DEFUN (__go_line__, args, , | |
3525 "-*- texinfo -*-\n\ | |
3526 @deftypefn {Built-in Function} {} __go_line__ (@var{parent})\n\ | |
6945 | 3527 Undocumented internal function.\n\ |
6406 | 3528 @end deftypefn") |
3529 { | |
3530 GO_BODY (line); | |
3531 } | |
3532 | |
3533 DEFUN (__go_text__, args, , | |
3534 "-*- texinfo -*-\n\ | |
3535 @deftypefn {Built-in Function} {} __go_text__ (@var{parent})\n\ | |
6945 | 3536 Undocumented internal function.\n\ |
6406 | 3537 @end deftypefn") |
3538 { | |
3539 GO_BODY (text); | |
3540 } | |
3541 | |
3542 DEFUN (__go_image__, args, , | |
3543 "-*- texinfo -*-\n\ | |
3544 @deftypefn {Built-in Function} {} __go_image__ (@var{parent})\n\ | |
6945 | 3545 Undocumented internal function.\n\ |
6406 | 3546 @end deftypefn") |
3547 { | |
3548 GO_BODY (image); | |
3549 } | |
3550 | |
3551 DEFUN (__go_surface__, args, , | |
3552 "-*- texinfo -*-\n\ | |
3553 @deftypefn {Built-in Function} {} __go_surface__ (@var{parent})\n\ | |
6945 | 3554 Undocumented internal function.\n\ |
6406 | 3555 @end deftypefn") |
3556 { | |
3557 GO_BODY (surface); | |
3558 } | |
3559 | |
6807 | 3560 DEFUN (__go_patch__, args, , |
3561 "-*- texinfo -*-\n\ | |
3562 @deftypefn {Built-in Function} {} __go_patch__ (@var{parent})\n\ | |
6945 | 3563 Undocumented internal function.\n\ |
6807 | 3564 @end deftypefn") |
3565 { | |
3566 GO_BODY (patch); | |
3567 } | |
3568 | |
6406 | 3569 DEFUN (__go_delete__, args, , |
3570 "-*- texinfo -*-\n\ | |
3571 @deftypefn {Built-in Function} {} __go_delete__ (@var{h})\n\ | |
6945 | 3572 Undocumented internal function.\n\ |
6406 | 3573 @end deftypefn") |
3574 { | |
3575 octave_value_list retval; | |
3576 | |
3577 if (args.length () == 1) | |
3578 { | |
3579 graphics_handle h = octave_NaN; | |
3580 | |
3581 double val = args(0).double_value (); | |
3582 | |
3583 if (! error_state) | |
3584 { | |
3585 h = gh_manager::lookup (val); | |
3586 | |
7056 | 3587 if (h.ok ()) |
6406 | 3588 { |
3589 graphics_object obj = gh_manager::get_object (h); | |
3590 | |
3591 graphics_handle parent_h = obj.get_parent (); | |
3592 | |
3593 graphics_object parent_obj = gh_manager::get_object (parent_h); | |
3594 | |
7367 | 3595 // NOTE: free the handle before removing it from its parent's |
3596 // children, such that the object's state is correct when | |
3597 // the deletefcn callback is executed | |
6406 | 3598 |
3599 gh_manager::free (h); | |
7367 | 3600 |
3601 parent_obj.remove_child (h); | |
6406 | 3602 } |
3603 else | |
3604 error ("delete: invalid graphics object (= %g)", val); | |
3605 } | |
3606 else | |
3607 error ("delete: invalid graphics object"); | |
3608 } | |
3609 else | |
3610 print_usage (); | |
3611 | |
3612 return retval; | |
3613 } | |
3614 | |
3615 DEFUN (__go_axes_init__, args, , | |
3616 "-*- texinfo -*-\n\ | |
3617 @deftypefn {Built-in Function} {} __go_axes_init__ (@var{h}, @var{mode})\n\ | |
6945 | 3618 Undocumented internal function.\n\ |
6406 | 3619 @end deftypefn") |
3620 { | |
3621 octave_value retval; | |
3622 | |
3623 int nargin = args.length (); | |
3624 | |
3625 std::string mode = ""; | |
3626 | |
3627 if (nargin == 2) | |
3628 { | |
3629 mode = args(1).string_value (); | |
3630 | |
3631 if (error_state) | |
3632 return retval; | |
3633 } | |
3634 | |
3635 if (nargin == 1 || nargin == 2) | |
3636 { | |
3637 graphics_handle h = octave_NaN; | |
3638 | |
3639 double val = args(0).double_value (); | |
3640 | |
3641 if (! error_state) | |
3642 { | |
3643 h = gh_manager::lookup (val); | |
3644 | |
7056 | 3645 if (h.ok ()) |
6406 | 3646 { |
3647 graphics_object obj = gh_manager::get_object (h); | |
3648 | |
3649 obj.set_defaults (mode); | |
3650 } | |
3651 else | |
3652 error ("__go_axes_init__: invalid graphics object (= %g)", val); | |
3653 } | |
3654 else | |
3655 error ("__go_axes_init__: invalid graphics object"); | |
3656 } | |
3657 else | |
3658 print_usage (); | |
3659 | |
3660 return retval; | |
3661 } | |
3662 | |
3663 DEFUN (__go_handles__, , , | |
3664 "-*- texinfo -*-\n\ | |
3665 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ | |
6945 | 3666 Undocumented internal function.\n\ |
6406 | 3667 @end deftypefn") |
3668 { | |
6425 | 3669 return octave_value (gh_manager::handle_list ()); |
3670 } | |
3671 | |
3672 DEFUN (__go_figure_handles__, , , | |
3673 "-*- texinfo -*-\n\ | |
3674 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ | |
6945 | 3675 Undocumented internal function.\n\ |
6425 | 3676 @end deftypefn") |
3677 { | |
3678 return octave_value (gh_manager::figure_handle_list ()); | |
6406 | 3679 } |
3680 | |
7835
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3681 DEFUN (available_backends, args, , |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3682 "-*- texinfo -*-\n\ |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3683 @deftypefn {Built-in Function} {} available_backends ()\n\ |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3684 Returns resgistered graphics backends.\n\ |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3685 @end deftypefn") |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3686 { |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3687 return octave_value (graphics_backend::available_backends_list ()); |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3688 } |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
3689 |
7409 | 3690 static void |
3691 clear_drawnow_request (void *) | |
3692 { | |
3693 Vdrawnow_requested = false; | |
3694 } | |
3695 | |
7408 | 3696 DEFUN (drawnow, args, , |
3697 "-*- texinfo -*-\n\ | |
3698 @deftypefn {Built-in Function} {} __go_drawnow__ ()\n\ | |
3699 @deftypefnx {Built-in Function} {} __go_drawnow__ (@var{term}, @var{file}, @var{mono}, @var{debug_file})\n\ | |
3700 Undocumented internal function.\n\ | |
3701 @end deftypefn") | |
3702 { | |
3703 static int drawnow_executing = 0; | |
3704 static bool __go_close_all_registered__ = false; | |
3705 | |
3706 octave_value retval; | |
3707 | |
7409 | 3708 unwind_protect::begin_frame ("Fdrawnow"); |
3709 unwind_protect::add (clear_drawnow_request); | |
3710 | |
3711 unwind_protect_int (drawnow_executing); | |
3712 | |
3713 if (++drawnow_executing <= 1) | |
7408 | 3714 { |
7409 | 3715 if (! __go_close_all_registered__) |
3716 { | |
3717 octave_add_atexit_function ("__go_close_all__"); | |
3718 | |
3719 __go_close_all_registered__ = true; | |
3720 } | |
3721 | |
3722 if (args.length () == 0) | |
7408 | 3723 { |
7409 | 3724 Matrix hlist = gh_manager::figure_handle_list (); |
3725 | |
3726 for (int i = 0; ! error_state && i < hlist.length (); i++) | |
7408 | 3727 { |
7409 | 3728 graphics_handle h = gh_manager::lookup (hlist(i)); |
3729 | |
3730 if (h.ok () && h != 0) | |
7408 | 3731 { |
7409 | 3732 graphics_object go = gh_manager::get_object (h); |
3733 figure::properties& fprops = dynamic_cast <figure::properties&> (go.get_properties ()); | |
3734 | |
3735 if (fprops.is_modified ()) | |
7408 | 3736 { |
7409 | 3737 if (fprops.is_visible ()) |
3738 fprops.get_backend ().redraw_figure (h); | |
3739 else if (! fprops.get___plot_stream__ ().is_empty ()) | |
3740 { | |
3741 fprops.close (false); | |
3742 fprops.set___plot_stream__ (Matrix ()); | |
3743 fprops.set___enhanced__ (false); | |
3744 } | |
3745 fprops.set_modified (false); | |
7408 | 3746 } |
3747 } | |
3748 } | |
3749 } | |
7409 | 3750 else if (args.length () >= 2 && args.length () <= 4) |
7408 | 3751 { |
7409 | 3752 std::string term, file, debug_file; |
3753 bool mono; | |
3754 | |
3755 term = args(0).string_value (); | |
7408 | 3756 |
3757 if (! error_state) | |
3758 { | |
7409 | 3759 file = args(1).string_value (); |
7408 | 3760 |
3761 if (! error_state) | |
3762 { | |
7409 | 3763 size_t pos = file.find_last_of (file_ops::dir_sep_chars); |
3764 | |
3765 if (pos != NPOS) | |
3766 { | |
3767 file_stat fs (file.substr (0, pos)); | |
3768 | |
3769 if (! (fs && fs.is_dir ())) | |
3770 error ("drawnow: nonexistent directory `%s'", | |
3771 file.substr (0, pos).c_str ()); | |
3772 } | |
3773 | |
3774 mono = (args.length () >= 3 ? args(2).bool_value () : false); | |
7408 | 3775 |
3776 if (! error_state) | |
3777 { | |
7409 | 3778 debug_file = (args.length () > 3 ? args(3).string_value () |
3779 : ""); | |
3780 | |
3781 if (! error_state) | |
7408 | 3782 { |
7409 | 3783 graphics_handle h = gcf (); |
3784 | |
3785 if (h.ok ()) | |
3786 { | |
3787 graphics_object go = gh_manager::get_object (h); | |
3788 | |
7419 | 3789 go.get_backend () |
7409 | 3790 .print_figure (h, term, file, mono, debug_file); |
3791 } | |
3792 else | |
3793 error ("drawnow: nothing to draw"); | |
7408 | 3794 } |
3795 else | |
7409 | 3796 error ("drawnow: invalid debug_file, expected a string value"); |
7408 | 3797 } |
3798 else | |
7409 | 3799 error ("drawnow: invalid colormode, expected a boolean value"); |
7408 | 3800 } |
3801 else | |
7409 | 3802 error ("drawnow: invalid file, expected a string value"); |
7408 | 3803 } |
3804 else | |
7409 | 3805 error ("drawnow: invalid terminal, expected a string value"); |
7408 | 3806 } |
3807 else | |
7409 | 3808 print_usage (); |
7408 | 3809 } |
7409 | 3810 |
3811 unwind_protect::run_frame ("Fdrawnow"); | |
7408 | 3812 |
3813 return retval; | |
3814 } | |
3815 | |
7859
fdd465b00ec0
Rename add_listener to addlistener.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7857
diff
changeset
|
3816 DEFUN (addlistener, args, , |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3817 "-*- texinfo -*-\n\ |
7859
fdd465b00ec0
Rename add_listener to addlistener.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7857
diff
changeset
|
3818 @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
|
3819 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
|
3820 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
|
3821 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
|
3822 listeners are executed.\n\ |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3823 \n\ |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3824 @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
|
3825 \n\ |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3826 @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
|
3827 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
|
3828 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
|
3829 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
|
3830 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
|
3831 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
|
3832 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
|
3833 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
|
3834 \n\ |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3835 @example\n\ |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3836 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
|
3837 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
|
3838 endfunction\n\ |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3839 \n\ |
7859
fdd465b00ec0
Rename add_listener to addlistener.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7857
diff
changeset
|
3840 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
|
3841 @end example\n\ |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3842 \n\ |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3843 @end deftypefn") |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3844 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3845 octave_value retval; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3846 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3847 if (args.length () == 3) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3848 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3849 double h = args(0).double_value (); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3850 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3851 if (! error_state) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3852 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3853 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
|
3854 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3855 if (! error_state) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3856 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3857 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
|
3858 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3859 if (gh.ok ()) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3860 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3861 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
|
3862 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3863 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
|
3864 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3865 else |
7859
fdd465b00ec0
Rename add_listener to addlistener.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7857
diff
changeset
|
3866 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
|
3867 h); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3868 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3869 else |
7859
fdd465b00ec0
Rename add_listener to addlistener.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7857
diff
changeset
|
3870 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
|
3871 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3872 else |
7859
fdd465b00ec0
Rename add_listener to addlistener.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7857
diff
changeset
|
3873 error ("addlistener: invalid handle"); |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3874 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3875 else |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3876 print_usage (); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3877 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3878 return retval; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3879 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
3880 |
6595 | 3881 octave_value |
7447 | 3882 get_property_from_handle (double handle, const std::string& property, |
3883 const std::string& func) | |
6595 | 3884 { |
3885 graphics_object obj = gh_manager::get_object (handle); | |
3886 octave_value retval; | |
3887 | |
3888 if (obj) | |
3889 { | |
7189 | 3890 caseless_str p = std::string (property); |
6595 | 3891 retval = obj.get (p); |
3892 } | |
3893 else | |
3894 error ("%s: invalid handle (= %g)", func.c_str(), handle); | |
3895 | |
3896 return retval; | |
3897 } | |
3898 | |
3899 bool | |
7447 | 3900 set_property_in_handle (double handle, const std::string& property, |
3901 const octave_value& arg, const std::string& func) | |
6595 | 3902 { |
3903 graphics_object obj = gh_manager::get_object (handle); | |
3904 int ret = false; | |
3905 | |
3906 if (obj) | |
3907 { | |
7189 | 3908 caseless_str p = std::string (property); |
6595 | 3909 obj.set (p, arg); |
3910 if (!error_state) | |
3911 ret = true; | |
3912 } | |
3913 else | |
3914 error ("%s: invalid handle (= %g)", func.c_str(), handle); | |
3915 | |
3916 return ret; | |
3917 } | |
3918 | |
6406 | 3919 /* |
3920 ;;; Local Variables: *** | |
3921 ;;; mode: C++ *** | |
3922 ;;; End: *** | |
3923 */ |