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