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