Mercurial > hg > octave-avbm
annotate src/graphics.h.in @ 7855:f317f14516cb
Add zoom stack facility in axes object.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Tue, 04 Mar 2008 15:34:38 +0100 |
parents | 228858e69bd1 |
children | 09b1a9c88128 |
rev | line source |
---|---|
6874 | 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. | |
6874 | 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/>. | |
6874 | 20 |
21 */ | |
22 | |
23 #if !defined (graphics_h) | |
24 #define graphics_h 1 | |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 #include <config.h> | |
28 #endif | |
29 | |
30 #include <cctype> | |
31 | |
32 #include <algorithm> | |
33 #include <list> | |
34 #include <map> | |
35 #include <set> | |
36 #include <string> | |
37 | |
6890 | 38 #include "gripes.h" |
6874 | 39 #include "oct-map.h" |
40 #include "ov.h" | |
41 | |
7189 | 42 class caseless_str : public std::string |
43 { | |
44 public: | |
45 typedef std::string::iterator iterator; | |
46 typedef std::string::const_iterator const_iterator; | |
47 | |
48 caseless_str (void) : std::string () { } | |
49 caseless_str (const std::string& s) : std::string (s) { } | |
50 caseless_str (const char *s) : std::string (s) { } | |
51 | |
52 caseless_str (const caseless_str& name) : std::string (name) { } | |
53 | |
54 caseless_str& operator = (const caseless_str& pname) | |
55 { | |
56 std::string::operator = (pname); | |
57 return *this; | |
58 } | |
59 | |
60 operator std::string (void) const { return *this; } | |
61 | |
62 // Case-insensitive comparison. | |
63 bool compare (const std::string& s, size_t limit = NPOS) const | |
64 { | |
65 const_iterator p1 = begin (); | |
66 const_iterator p2 = s.begin (); | |
67 | |
68 size_t k = 0; | |
69 | |
70 while (p1 != end () && p2 != s.end () && k++ < limit) | |
71 { | |
72 if (std::tolower (*p1) != std::tolower (*p2)) | |
73 return false; | |
74 | |
75 *p1++; | |
76 *p2++; | |
77 } | |
78 | |
79 return (limit == NPOS) ? size () == s.size () : k == limit; | |
80 } | |
81 }; | |
82 | |
83 // --------------------------------------------------------------------- | |
84 | |
6874 | 85 class graphics_handle |
86 { | |
87 public: | |
88 graphics_handle (void) : val (octave_NaN) { } | |
89 | |
90 graphics_handle (const octave_value& a); | |
91 | |
92 graphics_handle (int a) : val (a) { } | |
93 | |
94 graphics_handle (double a) : val (a) { } | |
95 | |
96 graphics_handle (const graphics_handle& a) : val (a.val) { } | |
97 | |
98 graphics_handle& operator = (const graphics_handle& a) | |
99 { | |
100 if (&a != this) | |
101 val = a.val; | |
102 | |
103 return *this; | |
104 } | |
105 | |
106 ~graphics_handle (void) { } | |
107 | |
108 double value (void) const { return val; } | |
109 | |
110 octave_value as_octave_value (void) const | |
111 { | |
112 return ok () ? octave_value (val) : octave_value (Matrix ()); | |
113 } | |
114 | |
115 graphics_handle operator ++ (void) | |
116 { | |
117 ++val; | |
118 return *this; | |
119 } | |
120 | |
121 graphics_handle operator ++ (int) | |
122 { | |
123 graphics_handle h = *this; | |
124 ++val; | |
125 return h; | |
126 } | |
127 | |
128 graphics_handle operator -- (void) | |
129 { | |
130 --val; | |
131 return *this; | |
132 } | |
133 | |
134 graphics_handle operator -- (int) | |
135 { | |
136 graphics_handle h = *this; | |
137 --val; | |
138 return h; | |
139 } | |
140 | |
141 bool ok (void) const { return ! xisnan (val); } | |
142 | |
143 private: | |
144 double val; | |
145 }; | |
146 | |
147 inline bool | |
148 operator == (const graphics_handle& a, const graphics_handle& b) | |
149 { | |
150 return a.value () == b.value (); | |
151 } | |
152 | |
153 inline bool | |
154 operator != (const graphics_handle& a, const graphics_handle& b) | |
155 { | |
156 return a.value () != b.value (); | |
157 } | |
158 | |
159 inline bool | |
160 operator < (const graphics_handle& a, const graphics_handle& b) | |
161 { | |
162 return a.value () < b.value (); | |
163 } | |
164 | |
165 inline bool | |
166 operator <= (const graphics_handle& a, const graphics_handle& b) | |
167 { | |
168 return a.value () <= b.value (); | |
169 } | |
170 | |
171 inline bool | |
172 operator >= (const graphics_handle& a, const graphics_handle& b) | |
173 { | |
174 return a.value () >= b.value (); | |
175 } | |
176 | |
177 inline bool | |
178 operator > (const graphics_handle& a, const graphics_handle& b) | |
179 { | |
180 return a.value () > b.value (); | |
181 } | |
182 | |
183 // --------------------------------------------------------------------- | |
184 | |
7427 | 185 class base_scaler |
186 { | |
187 public: | |
188 base_scaler (void) { } | |
189 | |
7441 | 190 virtual ~base_scaler (void) { } |
7440 | 191 |
7427 | 192 virtual Matrix scale (const Matrix& m) const |
193 { | |
194 error ("invalid axis scale"); | |
195 return m; | |
196 } | |
197 | |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
198 virtual NDArray scale (const NDArray& m) const |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
199 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
200 error ("invalid axis scale"); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
201 return m; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
202 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
203 |
7427 | 204 virtual double scale (double d) const |
205 { | |
206 error ("invalid axis scale"); | |
207 return d; | |
208 } | |
209 | |
210 virtual double unscale (double d) const | |
211 { | |
212 error ("invalid axis scale"); | |
213 return d; | |
214 } | |
215 | |
216 virtual base_scaler* clone () const | |
217 { return new base_scaler (); } | |
7832
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
218 |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
219 virtual bool is_linear (void) const |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
220 { return false; } |
7427 | 221 }; |
222 | |
223 class lin_scaler : public base_scaler | |
224 { | |
225 public: | |
226 lin_scaler (void) { } | |
227 | |
228 Matrix scale (const Matrix& m) const { return m; } | |
229 | |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
230 NDArray scale (const NDArray& m) const { return m; } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
231 |
7427 | 232 double scale (double d) const { return d; } |
233 | |
234 double unscale (double d) const { return d; } | |
235 | |
236 base_scaler* clone (void) const { return new lin_scaler (); } | |
7832
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
237 |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
238 bool is_linear (void) const { return true; } |
7427 | 239 }; |
240 | |
241 class log_scaler : public base_scaler | |
242 { | |
243 public: | |
244 log_scaler (void) { } | |
245 | |
246 Matrix scale (const Matrix& m) const | |
247 { | |
248 Matrix retval (m.rows (), m.cols ()); | |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
249 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
250 do_scale (m.data (), retval.fortran_vec (), m.numel ()); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
251 return retval; |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
252 } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
253 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
254 NDArray scale (const NDArray& m) const |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
255 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
256 NDArray retval (m.dims ()); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
257 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
258 do_scale (m.data (), retval.fortran_vec (), m.numel ()); |
7427 | 259 return retval; |
260 } | |
261 | |
262 double scale (double d) const | |
263 { return log10 (d); } | |
264 | |
265 double unscale (double d) const | |
266 { return pow (10.0, d); } | |
267 | |
268 base_scaler* clone (void) const | |
269 { return new log_scaler (); } | |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
270 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
271 private: |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
272 void do_scale (const double *src, double *dest, int n) const |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
273 { |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
274 for (int i = 0; i < n; i++) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
275 dest[i] = log10(src[i]); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
276 } |
7427 | 277 }; |
278 | |
279 class scaler | |
280 { | |
281 public: | |
282 scaler (void) : rep (new base_scaler ()) { } | |
283 | |
284 scaler (const scaler& s) : rep (s.rep->clone()) { } | |
285 | |
286 ~scaler (void) { delete rep; } | |
287 | |
288 Matrix scale (const Matrix& m) const | |
289 { return rep->scale (m); } | |
290 | |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
291 NDArray scale (const NDArray& m) const |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
292 { return rep->scale (m); } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
293 |
7427 | 294 double scale (double d) const |
295 { return rep->scale (d); } | |
296 | |
297 double unscale (double d) const | |
298 { return rep->unscale (d); } | |
299 | |
7832
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
300 bool is_linear (void) const |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
301 { return rep->is_linear (); } |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
302 |
7427 | 303 scaler& operator = (const scaler& s) |
304 { | |
305 if (rep) | |
306 { | |
307 delete rep; | |
308 rep = 0; | |
309 } | |
310 | |
311 rep = s.rep->clone (); | |
312 | |
313 return *this; | |
314 } | |
315 | |
316 scaler& operator = (const std::string& s) | |
317 { | |
318 if (rep) | |
319 { | |
320 delete rep; | |
321 rep = 0; | |
322 } | |
323 | |
324 if (s == "log") | |
325 rep = new log_scaler (); | |
326 else if (s == "linear") | |
327 rep = new lin_scaler (); | |
328 else | |
329 rep = new base_scaler (); | |
330 | |
331 return *this; | |
332 } | |
333 | |
334 private: | |
335 base_scaler *rep; | |
336 }; | |
337 | |
338 // --------------------------------------------------------------------- | |
339 | |
7363 | 340 class property; |
341 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
342 enum listener_mode { POSTSET }; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
343 |
7363 | 344 class base_property |
345 { | |
346 public: | |
347 friend class property; | |
348 | |
349 public: | |
7850
56254a8d4d59
Smarter reference counting in base_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
350 base_property (void) : count (1) { } |
7363 | 351 |
352 base_property (const std::string& s, const graphics_handle& h) | |
7850
56254a8d4d59
Smarter reference counting in base_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
353 : count (1), name (s), parent (h), hidden (false) { } |
7363 | 354 |
355 base_property (const base_property& p) | |
7850
56254a8d4d59
Smarter reference counting in base_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
356 : count (1), name (p.name), parent (p.parent), hidden (p.hidden) { } |
7363 | 357 |
358 virtual ~base_property (void) { } | |
359 | |
360 bool ok (void) const { return parent.ok (); } | |
361 | |
362 std::string get_name (void) const { return name; } | |
363 | |
364 void set_name (const std::string& s) { name = s; } | |
365 | |
366 graphics_handle get_parent (void) const { return parent; } | |
367 | |
368 void set_parent (const graphics_handle &h) { parent = h; } | |
369 | |
370 bool is_hidden (void) const { return hidden; } | |
371 | |
372 void set_hidden (bool flag) { hidden = flag; } | |
373 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
374 void set (const octave_value& v, bool do_run = true) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
375 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
376 do_set (v); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
377 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
378 if (do_run && ! error_state) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
379 run_listeners (POSTSET); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
380 } |
7363 | 381 |
382 virtual octave_value get (void) const | |
383 { | |
384 error ("get: invalid property \"%s\"", name.c_str ()); | |
385 return octave_value (); | |
386 } | |
387 | |
388 base_property& operator = (const octave_value& val) | |
389 { | |
390 set (val); | |
391 return *this; | |
392 } | |
393 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
394 void add_listener (const octave_value& v, listener_mode mode = POSTSET) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
395 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
396 octave_value_list& l = listeners[mode]; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
397 l.resize (l.length () + 1, v); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
398 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
399 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
400 OCTINTERP_API void run_listeners (listener_mode mode = POSTSET); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
401 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
402 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
403 virtual void do_set (const octave_value&) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
404 { error ("set: invalid property \"%s\"", name.c_str ()); } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
405 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
406 private: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
407 typedef std::map<listener_mode, octave_value_list> listener_map; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
408 typedef std::map<listener_mode, octave_value_list>::iterator listener_map_iterator; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
409 typedef std::map<listener_mode, octave_value_list>::const_iterator listener_map_const_iterator; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
410 |
7363 | 411 private: |
412 int count; | |
413 std::string name; | |
414 graphics_handle parent; | |
415 bool hidden; | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
416 listener_map listeners; |
7363 | 417 }; |
418 | |
419 // --------------------------------------------------------------------- | |
420 | |
421 class string_property : public base_property | |
422 { | |
423 public: | |
424 string_property (const std::string& s, const graphics_handle& h, | |
425 const std::string& val = "") | |
426 : base_property (s, h), str (val) { } | |
427 | |
428 string_property (const string_property& p) | |
429 : base_property (p), str (p.str) { } | |
430 | |
431 octave_value get (void) const | |
432 { return octave_value (str); } | |
433 | |
434 std::string string_value (void) const { return str; } | |
435 | |
436 string_property& operator = (const octave_value& val) | |
437 { | |
438 set (val); | |
439 return *this; | |
440 } | |
441 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
442 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
443 void do_set (const octave_value& val) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
444 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
445 if (val.is_string ()) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
446 str = val.string_value (); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
447 else |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
448 error ("set: invalid string property value for \"%s\"", |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
449 get_name ().c_str ()); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
450 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
451 |
7363 | 452 private: |
453 std::string str; | |
454 }; | |
455 | |
456 // --------------------------------------------------------------------- | |
457 | |
458 class radio_values | |
459 { | |
460 public: | |
461 OCTINTERP_API radio_values (const std::string& opt_string = std::string ()); | |
462 | |
463 radio_values (const radio_values& a) | |
464 : default_val (a.default_val), possible_vals (a.possible_vals) { } | |
465 | |
466 radio_values& operator = (const radio_values& a) | |
467 { | |
468 if (&a != this) | |
469 { | |
470 default_val = a.default_val; | |
471 possible_vals = a.possible_vals; | |
472 } | |
473 | |
474 return *this; | |
475 } | |
476 | |
477 std::string default_value (void) const { return default_val; } | |
478 | |
479 bool validate (const std::string& val) | |
480 { | |
481 bool retval = true; | |
482 | |
483 if (! contains (val)) | |
484 { | |
485 error ("invalid value = %s", val.c_str ()); | |
486 retval = false; | |
487 } | |
488 | |
489 return retval; | |
490 } | |
491 | |
492 bool contains (const std::string& val) | |
493 { | |
494 return (possible_vals.find (val) != possible_vals.end ()); | |
495 } | |
496 | |
497 private: | |
498 // Might also want to cache | |
499 std::string default_val; | |
500 std::set<caseless_str> possible_vals; | |
501 }; | |
502 | |
503 class radio_property : public base_property | |
504 { | |
505 public: | |
7364 | 506 radio_property (const std::string& nm, const graphics_handle& h, |
7363 | 507 const radio_values& v = radio_values ()) |
7364 | 508 : base_property (nm, h), |
7363 | 509 vals (v), current_val (v.default_value ()) { } |
510 | |
7364 | 511 radio_property (const std::string& nm, const graphics_handle& h, |
7363 | 512 const std::string& v) |
7364 | 513 : base_property (nm, h), |
7363 | 514 vals (v), current_val (vals.default_value ()) { } |
515 | |
7364 | 516 radio_property (const std::string& nm, const graphics_handle& h, |
7363 | 517 const radio_values& v, const std::string& def) |
7364 | 518 : base_property (nm, h), |
7363 | 519 vals (v), current_val (def) { } |
520 | |
521 radio_property (const radio_property& p) | |
522 : base_property (p), vals (p.vals), current_val (p.current_val) { } | |
523 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
524 octave_value get (void) const { return octave_value (current_val); } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
525 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
526 const std::string& current_value (void) const { return current_val; } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
527 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
528 bool is (const caseless_str& v) const |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
529 { return v.compare (current_val); } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
530 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
531 radio_property& operator = (const octave_value& val) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
532 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
533 set (val); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
534 return *this; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
535 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
536 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
537 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
538 void do_set (const octave_value& newval) |
7363 | 539 { |
540 if (newval.is_string ()) | |
541 { | |
542 std::string s = newval.string_value (); | |
543 if (vals.validate (s)) | |
544 current_val = s; | |
545 else | |
546 error ("set: invalid value for radio property \"%s\" (value = %s)", | |
547 get_name ().c_str (), s.c_str ()); | |
548 } | |
549 else | |
550 error ("set: invalid value for radio property \"%s\"", | |
551 get_name ().c_str ()); | |
552 } | |
553 | |
554 private: | |
555 radio_values vals; | |
556 std::string current_val; | |
557 }; | |
558 | |
559 // --------------------------------------------------------------------- | |
560 | |
561 class color_values | |
562 { | |
563 public: | |
564 color_values (double r = 0, double g = 0, double b = 1) | |
565 : xrgb (1, 3) | |
566 { | |
567 xrgb(0) = r; | |
568 xrgb(1) = g; | |
569 xrgb(2) = b; | |
570 | |
571 validate (); | |
572 } | |
573 | |
574 color_values (std::string str) | |
575 : xrgb (1, 3) | |
576 { | |
577 if (! str2rgb (str)) | |
578 error ("invalid color specification: %s", str.c_str ()); | |
579 } | |
580 | |
581 color_values (const color_values& c) | |
582 : xrgb (c.xrgb) | |
583 { } | |
584 | |
585 color_values& operator = (const color_values& c) | |
586 { | |
587 if (&c != this) | |
588 xrgb = c.xrgb; | |
589 | |
590 return *this; | |
591 } | |
592 | |
593 Matrix rgb (void) const { return xrgb; } | |
594 | |
595 operator octave_value (void) const { return xrgb; } | |
596 | |
597 void validate (void) const | |
598 { | |
599 for (int i = 0; i < 3; i++) | |
600 { | |
601 if (xrgb(i) < 0 || xrgb(i) > 1) | |
602 { | |
603 error ("invalid RGB color specification"); | |
604 break; | |
605 } | |
606 } | |
607 } | |
608 | |
609 private: | |
610 Matrix xrgb; | |
611 | |
612 OCTINTERP_API bool str2rgb (std::string str); | |
613 }; | |
614 | |
615 class color_property : public base_property | |
616 { | |
617 public: | |
618 color_property (const color_values& c, const radio_values& v) | |
619 : base_property ("", graphics_handle ()), | |
620 current_type (color_t), color_val (c), radio_val (v), | |
621 current_val (v.default_value ()) | |
622 { } | |
623 | |
7364 | 624 color_property (const std::string& nm, const graphics_handle& h, |
7363 | 625 const color_values& c = color_values (), |
626 const radio_values& v = radio_values ()) | |
7364 | 627 : base_property (nm, h), |
7363 | 628 current_type (color_t), color_val (c), radio_val (v), |
629 current_val (v.default_value ()) | |
630 { } | |
631 | |
7364 | 632 color_property (const std::string& nm, const graphics_handle& h, |
7363 | 633 const radio_values& v) |
7364 | 634 : base_property (nm, h), |
7363 | 635 current_type (radio_t), color_val (color_values ()), radio_val (v), |
636 current_val (v.default_value ()) | |
637 { } | |
638 | |
7364 | 639 color_property (const std::string& nm, const graphics_handle& h, |
7363 | 640 const std::string& v) |
7364 | 641 : base_property (nm, h), |
7363 | 642 current_type (radio_t), color_val (color_values ()), radio_val (v), |
643 current_val (radio_val.default_value ()) | |
644 { } | |
645 | |
7364 | 646 color_property (const std::string& nm, const graphics_handle& h, |
7363 | 647 const color_property& v) |
7364 | 648 : base_property (nm, h), |
7363 | 649 current_type (v.current_type), color_val (v.color_val), |
650 radio_val (v.radio_val), current_val (v.current_val) | |
651 { } | |
652 | |
653 color_property (const color_property& p) | |
654 : base_property (p), current_type (p.current_type), | |
655 color_val (p.color_val), radio_val (p.radio_val), | |
656 current_val (p.current_val) { } | |
657 | |
658 octave_value get (void) const | |
659 { | |
660 if (current_type == color_t) | |
661 return color_val.rgb (); | |
662 | |
663 return current_val; | |
664 } | |
665 | |
666 bool is_rgb (void) const { return (current_type == color_t); } | |
667 | |
668 bool is_radio (void) const { return (current_type == radio_t); } | |
669 | |
670 bool is (const std::string& v) const | |
671 { return (is_radio () && current_val == v); } | |
672 | |
673 Matrix rgb (void) const | |
674 { | |
675 if (current_type != color_t) | |
676 error ("color has no rgb value"); | |
677 | |
678 return color_val.rgb (); | |
679 } | |
680 | |
681 const std::string& current_value (void) const | |
682 { | |
683 if (current_type != radio_t) | |
684 error ("color has no radio value"); | |
685 | |
686 return current_val; | |
687 } | |
688 | |
689 color_property& operator = (const octave_value& val) | |
690 { | |
691 set (val); | |
692 return *this; | |
693 } | |
694 | |
695 operator octave_value (void) const { return get (); } | |
696 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
697 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
698 OCTINTERP_API void do_set (const octave_value& newval); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
699 |
7363 | 700 private: |
701 enum current_enum { color_t, radio_t } current_type; | |
702 color_values color_val; | |
703 radio_values radio_val; | |
704 std::string current_val; | |
705 }; | |
706 | |
707 // --------------------------------------------------------------------- | |
708 | |
709 class double_property : public base_property | |
710 { | |
711 public: | |
7364 | 712 double_property (const std::string& nm, const graphics_handle& h, |
7363 | 713 double d = 0) |
7364 | 714 : base_property (nm, h), |
7363 | 715 current_val (d) { } |
716 | |
717 double_property (const double_property& p) | |
718 : base_property (p), current_val (p.current_val) { } | |
719 | |
720 octave_value get (void) const { return octave_value (current_val); } | |
721 | |
722 double double_value (void) const { return current_val; } | |
723 | |
724 double_property& operator = (const octave_value& val) | |
725 { | |
726 set (val); | |
727 return *this; | |
728 } | |
729 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
730 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
731 void do_set (const octave_value& v) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
732 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
733 if (v.is_scalar_type () && v.is_real_type ()) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
734 current_val = v.double_value (); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
735 else |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
736 error ("set: invalid value for double property \"%s\"", |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
737 get_name ().c_str ()); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
738 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
739 |
7363 | 740 private: |
741 double current_val; | |
742 }; | |
743 | |
744 // --------------------------------------------------------------------- | |
745 | |
7844
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
746 class double_radio_property : public base_property |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
747 { |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
748 public: |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
749 double_radio_property (double d, const radio_values& v) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
750 : base_property ("", graphics_handle ()), |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
751 current_type (double_t), dval (d), radio_val (v), |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
752 current_val (v.default_value ()) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
753 { } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
754 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
755 double_radio_property (const std::string& nm, const graphics_handle& h, |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
756 const std::string& v) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
757 : base_property (nm, h), |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
758 current_type (radio_t), dval (0), radio_val (v), |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
759 current_val (radio_val.default_value ()) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
760 { } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
761 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
762 double_radio_property (const std::string& nm, const graphics_handle& h, |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
763 const double_radio_property& v) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
764 : base_property (nm, h), |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
765 current_type (v.current_type), dval (v.dval), |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
766 radio_val (v.radio_val), current_val (v.current_val) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
767 { } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
768 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
769 octave_value get (void) const |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
770 { |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
771 if (current_type == double_t) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
772 return dval; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
773 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
774 return current_val; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
775 } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
776 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
777 bool is_double (void) const { return (current_type == double_t); } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
778 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
779 bool is_radio (void) const { return (current_type == radio_t); } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
780 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
781 bool is (const std::string& v) const |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
782 { return (is_radio () && current_val == v); } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
783 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
784 double double_value (void) const |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
785 { |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
786 if (current_type != double_t) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
787 error ("%s: property has no double", get_name ().c_str ()); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
788 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
789 return dval; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
790 } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
791 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
792 const std::string& current_value (void) const |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
793 { |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
794 if (current_type != radio_t) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
795 error ("%s: property has no radio value"); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
796 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
797 return current_val; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
798 } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
799 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
800 double_radio_property& operator = (const octave_value& val) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
801 { |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
802 set (val); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
803 return *this; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
804 } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
805 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
806 operator octave_value (void) const { return get (); } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
807 |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
808 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
809 OCTINTERP_API void do_set (const octave_value& v); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
810 |
7844
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
811 private: |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
812 enum current_enum { double_t, radio_t } current_type; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
813 double dval; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
814 radio_values radio_val; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
815 std::string current_val; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
816 }; |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
817 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
818 // --------------------------------------------------------------------- |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
819 |
7363 | 820 class array_property : public base_property |
821 { | |
822 public: | |
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
|
823 array_property (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
|
824 : base_property ("", graphics_handle ()), data (Matrix ()) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
825 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
826 get_data_limits (); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
827 } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
828 |
7364 | 829 array_property (const std::string& nm, const graphics_handle& h, |
7363 | 830 const octave_value& m) |
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
|
831 : base_property (nm, h), data (m) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
832 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
833 get_data_limits (); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
834 } |
7363 | 835 |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
836 // This copy constructor is only intended to be used |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
837 // internally to access min/max values; no need to |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
838 // copy constraints. |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
839 array_property (const array_property& p) |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
840 : base_property (p), data (p.data), |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
841 xmin (p.xmin), xmax (p.xmax), xminp (p.xminp) { } |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
842 |
7363 | 843 octave_value get (void) const { return data; } |
844 | |
845 void add_constraint (const std::string& type) | |
846 { type_constraints.push_back (type); } | |
847 | |
7524
a653856aa3e1
array_value::add_constraint: pass dim_vector as const reference, not value
John W. Eaton <jwe@octave.org>
parents:
7523
diff
changeset
|
848 void add_constraint (const dim_vector& dims) |
7363 | 849 { size_constraints.push_back (dims); } |
850 | |
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
|
851 double min_val (void) const { return xmin; } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
852 double max_val (void) const { return xmax; } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
853 double min_pos (void) const { return 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
|
854 |
7363 | 855 array_property& operator = (const octave_value& val) |
856 { | |
857 set (val); | |
858 return *this; | |
859 } | |
860 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
861 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
862 void do_set (const octave_value& v) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
863 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
864 if (validate (v)) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
865 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
866 data = v; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
867 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
868 get_data_limits (); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
869 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
870 else |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
871 error ("invalid value for array property \"%s\"", |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
872 get_name ().c_str ()); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
873 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
874 |
7363 | 875 private: |
876 OCTINTERP_API bool validate (const octave_value& v); | |
877 | |
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
|
878 OCTINTERP_API void 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
|
879 |
7523
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
880 protected: |
7363 | 881 octave_value data; |
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
|
882 double xmin; |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
883 double xmax; |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
884 double xminp; |
7363 | 885 std::list<std::string> type_constraints; |
886 std::list<dim_vector> size_constraints; | |
887 }; | |
888 | |
7523
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
889 class row_vector_property : public array_property |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
890 { |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
891 public: |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
892 row_vector_property (const std::string& nm, const graphics_handle& h, |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
893 const octave_value& m) |
7527
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
894 : array_property (nm, h, m) |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
895 { |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
896 add_constraint (dim_vector (-1, 1)); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
897 add_constraint (dim_vector (1, -1)); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
898 } |
7523
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
899 |
7527
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
900 void add_constraint (const std::string& type) |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
901 { |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
902 array_property::add_constraint (type); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
903 } |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
904 |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
905 void add_constraint (const dim_vector& dims) |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
906 { |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
907 array_property::add_constraint (dims); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
908 } |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
909 |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
910 void add_constraint (octave_idx_type len) |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
911 { |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
912 size_constraints.remove (dim_vector (1, -1)); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
913 size_constraints.remove (dim_vector (-1, 1)); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
914 |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
915 add_constraint (dim_vector (1, len)); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
916 add_constraint (dim_vector (len, 1)); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
917 } |
7523
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
918 |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
919 row_vector_property& operator = (const octave_value& val) |
7527
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
920 { |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
921 set (val); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
922 return *this; |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
923 } |
7523
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
924 |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
925 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
926 void do_set (const octave_value& v) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
927 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
928 array_property::do_set (v); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
929 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
930 if (! error_state) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
931 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
932 dim_vector dv = data.dims (); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
933 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
934 if (dv(0) > 1 && dv(1) == 1) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
935 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
936 int tmp = dv(0); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
937 dv(0) = dv(1); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
938 dv(1) = tmp; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
939 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
940 data = data.reshape (dv); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
941 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
942 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
943 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
944 |
7523
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
945 private: |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
946 OCTINTERP_API bool validate (const octave_value& v); |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
947 }; |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
948 |
7363 | 949 // --------------------------------------------------------------------- |
950 | |
951 class bool_property : public radio_property | |
952 { | |
953 public: | |
7364 | 954 bool_property (const std::string& nm, const graphics_handle& h, |
7363 | 955 bool val) |
7364 | 956 : radio_property (nm, h, radio_values (val ? "{on}|off" : "on|{off}")) |
7363 | 957 { } |
958 | |
7364 | 959 bool_property (const std::string& nm, const graphics_handle& h, |
7363 | 960 const char* val) |
7364 | 961 : radio_property (nm, h, radio_values ("on|off"), val) |
7363 | 962 { } |
963 | |
964 bool_property (const bool_property& p) | |
965 : radio_property (p) { } | |
966 | |
967 bool is_on (void) const { return is ("on"); } | |
968 | |
969 bool_property& operator = (const octave_value& val) | |
970 { | |
971 set (val); | |
972 return *this; | |
973 } | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
974 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
975 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
976 void do_set (const octave_value& val) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
977 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
978 if (val.is_bool_scalar ()) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
979 radio_property::do_set (val.bool_value () ? "on" : "off"); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
980 else |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
981 radio_property::do_set (val); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
982 } |
7363 | 983 }; |
984 | |
985 // --------------------------------------------------------------------- | |
986 | |
987 class handle_property : public base_property | |
988 { | |
989 public: | |
7364 | 990 handle_property (const std::string& nm, const graphics_handle& h, |
7363 | 991 const graphics_handle& val = graphics_handle ()) |
7364 | 992 : base_property (nm, h), |
7363 | 993 current_val (val) { } |
994 | |
995 handle_property (const handle_property& p) | |
996 : base_property (p), current_val (p.current_val) { } | |
997 | |
998 octave_value get (void) const { return current_val.as_octave_value (); } | |
999 | |
1000 graphics_handle handle_value (void) const { return current_val; } | |
1001 | |
1002 handle_property& operator = (const octave_value& val) | |
1003 { | |
1004 set (val); | |
1005 return *this; | |
1006 } | |
1007 | |
1008 handle_property& operator = (const graphics_handle& h) | |
1009 { | |
1010 set (octave_value (h.value ())); | |
1011 return *this; | |
1012 } | |
1013 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1014 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1015 OCTINTERP_API void do_set (const octave_value& v); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1016 |
7363 | 1017 private: |
1018 graphics_handle current_val; | |
1019 }; | |
1020 | |
1021 // --------------------------------------------------------------------- | |
1022 | |
1023 class any_property : public base_property | |
1024 { | |
1025 public: | |
7364 | 1026 any_property (const std::string& nm, const graphics_handle& h, |
7363 | 1027 const octave_value& m = Matrix ()) |
7364 | 1028 : base_property (nm, h), data (m) { } |
7363 | 1029 |
1030 octave_value get (void) const { return data; } | |
1031 | |
1032 any_property& operator = (const octave_value& val) | |
1033 { | |
1034 set (val); | |
1035 return *this; | |
1036 } | |
1037 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1038 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1039 void do_set (const octave_value& v) { data = v; } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1040 |
7363 | 1041 private: |
1042 octave_value data; | |
1043 }; | |
1044 | |
1045 // --------------------------------------------------------------------- | |
1046 | |
1047 class callback_property : public base_property | |
1048 { | |
1049 public: | |
7364 | 1050 callback_property (const std::string& nm, const graphics_handle& h, |
7363 | 1051 const octave_value& m) |
7364 | 1052 : base_property (nm, h), callback (m) { } |
7363 | 1053 |
1054 octave_value get (void) const { return callback; } | |
1055 | |
7367 | 1056 OCTINTERP_API void execute (const octave_value& data = octave_value ()) const; |
7363 | 1057 |
7824
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
1058 OCTINTERP_API static |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
1059 void 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
|
1060 const octave_value& data = octave_value ()); |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
1061 |
adb520646d7e
Fix execution of callback strings and allow execution of callback by name.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7822
diff
changeset
|
1062 |
7363 | 1063 callback_property& operator = (const octave_value& val) |
1064 { | |
1065 set (val); | |
1066 return *this; | |
1067 } | |
1068 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1069 protected: |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1070 void do_set (const octave_value& v) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1071 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1072 if (validate (v)) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1073 callback = v; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1074 else |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1075 error ("invalid value for callback property \"%s\"", |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1076 get_name ().c_str ()); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1077 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1078 |
7363 | 1079 private: |
1080 OCTINTERP_API bool validate (const octave_value& v) const; | |
1081 | |
1082 private: | |
1083 octave_value callback; | |
1084 }; | |
1085 | |
1086 // --------------------------------------------------------------------- | |
1087 | |
1088 class property | |
1089 { | |
1090 public: | |
1091 property (void) : rep (new base_property ("", graphics_handle ())) | |
7850
56254a8d4d59
Smarter reference counting in base_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
1092 { } |
7363 | 1093 |
1094 property (base_property *bp, bool persist = false) : rep (bp) | |
7850
56254a8d4d59
Smarter reference counting in base_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
1095 { if (persist) rep->count++; } |
7363 | 1096 |
1097 property (const property& p) | |
1098 { | |
1099 rep = p.rep; | |
1100 rep->count++; | |
1101 } | |
1102 | |
1103 ~property (void) | |
1104 { | |
1105 if (--rep->count <= 0) | |
1106 delete rep; | |
1107 } | |
1108 | |
1109 bool ok (void) const | |
1110 { return rep->ok (); } | |
1111 | |
1112 std::string get_name (void) const | |
1113 { return rep->get_name (); } | |
1114 | |
1115 void set_name (const std::string& name) | |
1116 { rep->set_name (name); } | |
1117 | |
1118 graphics_handle get_parent (void) const | |
1119 { return rep->get_parent (); } | |
1120 | |
1121 void set_parent (const graphics_handle& h) | |
1122 { rep->set_parent (h); } | |
1123 | |
1124 bool is_hidden (void) const | |
1125 { return rep->is_hidden (); } | |
1126 | |
1127 void set_hidden (bool flag) | |
1128 { rep->set_hidden (flag); } | |
1129 | |
1130 octave_value get (void) const | |
1131 { return rep->get (); } | |
1132 | |
1133 void set (const octave_value& val) | |
1134 { rep->set (val); } | |
1135 | |
1136 property& operator = (const octave_value& val) | |
1137 { | |
1138 *rep = val; | |
1139 return *this; | |
1140 } | |
1141 | |
1142 property& operator = (const property& p) | |
1143 { | |
1144 if (rep && --rep->count <= 0) | |
1145 delete rep; | |
1146 | |
1147 rep = p.rep; | |
1148 rep->count++; | |
1149 | |
1150 return *this; | |
1151 } | |
1152 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1153 void add_listener (const octave_value& v, listener_mode mode = POSTSET) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1154 { rep->add_listener (v, mode); } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1155 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1156 void run_listeners (listener_mode mode = POSTSET) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1157 { rep->run_listeners (mode); } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1158 |
7363 | 1159 /* |
1160 const string_property& as_string_property (void) const | |
1161 { return *(dynamic_cast<string_property*> (rep)); } | |
1162 | |
1163 const radio_property& as_radio_property (void) const | |
1164 { return *(dynamic_cast<radio_property*> (rep)); } | |
1165 | |
1166 const color_property& as_color_property (void) const | |
1167 { return *(dynamic_cast<color_property*> (rep)); } | |
1168 | |
1169 const double_property& as_double_property (void) const | |
1170 { return *(dynamic_cast<double_property*> (rep)); } | |
1171 | |
1172 const bool_property& as_bool_property (void) const | |
1173 { return *(dynamic_cast<bool_property*> (rep)); } | |
1174 | |
1175 const handle_property& as_handle_property (void) const | |
1176 { return *(dynamic_cast<handle_property*> (rep)); } | |
1177 */ | |
1178 | |
1179 private: | |
1180 base_property *rep; | |
1181 }; | |
1182 | |
1183 // --------------------------------------------------------------------- | |
1184 | |
1185 class property_list | |
1186 { | |
1187 public: | |
1188 typedef std::map<std::string, octave_value> pval_map_type; | |
1189 typedef std::map<std::string, pval_map_type> plist_map_type; | |
1190 | |
1191 typedef pval_map_type::iterator pval_map_iterator; | |
1192 typedef pval_map_type::const_iterator pval_map_const_iterator; | |
1193 | |
1194 typedef plist_map_type::iterator plist_map_iterator; | |
1195 typedef plist_map_type::const_iterator plist_map_const_iterator; | |
1196 | |
1197 property_list (const plist_map_type& m = plist_map_type ()) | |
1198 : plist_map (m) { } | |
1199 | |
1200 ~property_list (void) { } | |
1201 | |
1202 void set (const caseless_str& name, const octave_value& val); | |
1203 | |
1204 octave_value lookup (const caseless_str& name) const; | |
1205 | |
1206 plist_map_iterator begin (void) { return plist_map.begin (); } | |
1207 plist_map_const_iterator begin (void) const { return plist_map.begin (); } | |
1208 | |
1209 plist_map_iterator end (void) { return plist_map.end (); } | |
1210 plist_map_const_iterator end (void) const { return plist_map.end (); } | |
1211 | |
1212 plist_map_iterator find (const std::string& go_name) | |
1213 { | |
1214 return plist_map.find (go_name); | |
1215 } | |
1216 | |
1217 plist_map_const_iterator find (const std::string& go_name) const | |
1218 { | |
1219 return plist_map.find (go_name); | |
1220 } | |
1221 | |
1222 Octave_map as_struct (const std::string& prefix_arg) const; | |
1223 | |
1224 private: | |
1225 plist_map_type plist_map; | |
1226 }; | |
1227 | |
1228 // --------------------------------------------------------------------- | |
1229 | |
7419 | 1230 class graphics_backend; |
1231 | |
1232 class base_graphics_backend | |
1233 { | |
1234 public: | |
1235 friend class graphics_backend; | |
1236 | |
1237 public: | |
1238 base_graphics_backend (const std::string& nm) | |
1239 : name (nm), count (0) { } | |
1240 | |
1241 virtual ~base_graphics_backend (void) { } | |
1242 | |
1243 std::string get_name (void) const { return name; } | |
1244 | |
1245 virtual bool is_valid (void) const { return false; } | |
1246 | |
7834
caab78e7e377
added checks for fltk & freetype in configure script
Shai Ayal <shaiay@sourceforge.net>
parents:
7833
diff
changeset
|
1247 virtual void close_figure (const octave_value& pstream) const |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1248 { gripe_invalid ("close_figure"); } |
7419 | 1249 |
1250 virtual void redraw_figure (const graphics_handle&) const | |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1251 { gripe_invalid ("redraw_figure"); } |
7419 | 1252 |
1253 virtual void print_figure (const graphics_handle&, const std::string&, | |
1254 const std::string&, bool, | |
1255 const std::string& = "") const | |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1256 { gripe_invalid ("print_figure"); } |
7419 | 1257 |
1258 virtual Matrix get_canvas_size (const graphics_handle&) const | |
1259 { | |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1260 gripe_invalid ("get_canvas_size"); |
7419 | 1261 return Matrix (1, 2, 0.0); |
1262 } | |
1263 | |
7427 | 1264 virtual double get_screen_resolution (void) const |
1265 { | |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1266 gripe_invalid ("get_screen_resolution"); |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1267 return 72.0; |
7427 | 1268 } |
7445 | 1269 |
1270 virtual Matrix get_screen_size (void) const | |
1271 { | |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1272 gripe_invalid ("get_screen_size"); |
7445 | 1273 return Matrix (1, 2, 0.0); |
1274 } | |
7427 | 1275 |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1276 virtual void set_figure_position (const graphics_handle&, const Matrix&) const |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1277 { gripe_invalid ("set_figure_position"); } |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1278 |
7419 | 1279 private: |
1280 std::string name; | |
1281 int count; | |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1282 |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1283 private: |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1284 void gripe_invalid (const std::string& fname) const |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1285 { |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1286 if (! is_valid ()) |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1287 error ("%s: invalid graphics backend", fname.c_str ()); |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1288 } |
7419 | 1289 }; |
1290 | |
1291 class graphics_backend | |
1292 { | |
1293 public: | |
1294 graphics_backend (void) | |
1295 : rep (new base_graphics_backend ("unknown")) | |
1296 { | |
1297 rep->count++; | |
1298 } | |
1299 | |
1300 graphics_backend (base_graphics_backend* b) | |
1301 : rep (b) | |
1302 { | |
1303 rep->count++; | |
1304 } | |
1305 | |
1306 graphics_backend (const graphics_backend& b) | |
1307 : rep (b.rep) | |
1308 { | |
1309 rep->count++; | |
1310 } | |
1311 | |
1312 ~graphics_backend (void) | |
1313 { | |
1314 if (--rep->count == 0) | |
1315 delete rep; | |
1316 } | |
1317 | |
1318 graphics_backend& operator = (const graphics_backend& b) | |
1319 { | |
1320 if (rep != b.rep) | |
1321 { | |
1322 if (--rep->count == 0) | |
1323 delete rep; | |
1324 | |
1325 rep = b.rep; | |
1326 rep->count++; | |
1327 } | |
1328 | |
1329 return *this; | |
1330 } | |
1331 | |
1332 operator bool (void) const { return rep->is_valid (); } | |
1333 | |
1334 std::string get_name (void) const { return rep->get_name (); } | |
1335 | |
1336 void close_figure (const octave_value& pstream) const | |
1337 { rep->close_figure (pstream); } | |
1338 | |
1339 void redraw_figure (const graphics_handle& fh) const | |
1340 { rep->redraw_figure (fh); } | |
1341 | |
1342 void print_figure (const graphics_handle& fh, const std::string& term, | |
1343 const std::string& file, bool mono, | |
1344 const std::string& debug_file = "") const | |
1345 { rep->print_figure (fh, term, file, mono, debug_file); } | |
1346 | |
1347 Matrix get_canvas_size (const graphics_handle& fh) const | |
1348 { return rep->get_canvas_size (fh); } | |
1349 | |
7427 | 1350 double get_screen_resolution (void) const |
1351 { return rep->get_screen_resolution (); } | |
1352 | |
7445 | 1353 Matrix get_screen_size (void) const |
1354 { return rep->get_screen_size (); } | |
1355 | |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1356 void set_figure_position (const graphics_handle& h, const Matrix& pos) const |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1357 { rep->set_figure_position (h, pos); } |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
1358 |
7419 | 1359 OCTINTERP_API static graphics_backend default_backend (void); |
1360 | |
1361 static void register_backend (const graphics_backend& b) | |
1362 { available_backends[b.get_name ()] = b; } | |
1363 | |
1364 static void unregister_backend (const std::string& name) | |
1365 { available_backends.erase (name); } | |
1366 | |
7439 | 1367 static graphics_backend find_backend (const std::string& name) |
1368 { | |
1369 const_available_backends_iterator p = available_backends.find (name); | |
1370 | |
1371 if (p != available_backends.end ()) | |
1372 return p->second; | |
1373 else | |
1374 return default_backend (); | |
1375 } | |
1376 | |
7835
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1377 static Cell available_backends_list (void) |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1378 { |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1379 Cell m (1 , available_backends.size ()); |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1380 const_available_backends_iterator p; |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1381 int i; |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1382 |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1383 for (i = 0,p = available_backends.begin (); p != available_backends.end (); p++,i++) |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1384 m(i) = p->first; |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1385 |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1386 return m; |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1387 } |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1388 |
ca8b97bb952c
added the function available_backends
Shai Ayal <shaiay@sourceforge.net>
parents:
7834
diff
changeset
|
1389 |
7419 | 1390 private: |
1391 base_graphics_backend *rep; | |
1392 | |
7445 | 1393 static OCTINTERP_API std::map<std::string, graphics_backend> available_backends; |
7439 | 1394 |
1395 typedef std::map<std::string, graphics_backend>::iterator available_backends_iterator; | |
1396 typedef std::map<std::string, graphics_backend>::const_iterator const_available_backends_iterator; | |
7419 | 1397 }; |
1398 | |
1399 // --------------------------------------------------------------------- | |
1400 | |
6874 | 1401 class base_graphics_object; |
1402 | |
7365 | 1403 class OCTINTERP_API base_properties |
6874 | 1404 { |
1405 public: | |
7176 | 1406 base_properties (const std::string& ty = "unknown", |
7363 | 1407 const graphics_handle& mh = graphics_handle (), |
1408 const graphics_handle& p = graphics_handle ()) | |
7404 | 1409 : beingdeleted ("beingdeleted", mh, false), |
7366 | 1410 busyaction ("parent", mh, "{queue}|cancel"), |
7367 | 1411 buttondownfcn ("buttondownfcn", mh, Matrix ()), |
7404 | 1412 children (), |
7366 | 1413 clipping ("clipping", mh, true), |
7406 | 1414 createfcn ("createfcn", mh, Matrix ()), |
7367 | 1415 deletefcn ("deletefcn", mh, Matrix ()), |
7366 | 1416 handlevisibility ("handlevisibility", mh, "{on}|callback|off"), |
1417 hittest ("hittest", mh, true), | |
1418 interruptible ("interruptible", mh, true), | |
7404 | 1419 parent ("parent", mh, p), |
7366 | 1420 selected ("selected", mh, false), |
1421 selectionhighlight ("selectionhighlight", mh, true), | |
7404 | 1422 tag ("tag", mh), |
1423 type ("type", mh, ty), | |
7367 | 1424 userdata ("userdata", mh, Matrix ()), |
7403 | 1425 visible ("visible", mh, true), |
7404 | 1426 __modified__ ("__modified__", mh, true), |
1427 __myhandle__ (mh), | |
1428 uicontextmenu ("uicontextmenu", mh, graphics_handle ()) | |
7363 | 1429 { } |
6874 | 1430 |
1431 virtual ~base_properties (void) { } | |
1432 | |
1433 virtual std::string graphics_object_name (void) const { return "unknonwn"; } | |
1434 | |
1435 void mark_modified (void); | |
1436 | |
1437 void override_defaults (base_graphics_object& obj); | |
1438 | |
1439 // Look through DEFAULTS for properties with given CLASS_NAME, and | |
1440 // apply them to the current object with set (virtual method). | |
1441 | |
1442 void set_from_list (base_graphics_object& obj, property_list& defaults); | |
1443 | |
7363 | 1444 void insert_property (const std::string& name, property p) |
1445 { | |
1446 p.set_name (name); | |
1447 p.set_parent (__myhandle__); | |
1448 all_props[name] = p; | |
1449 } | |
1450 | |
1451 virtual void set (const caseless_str&, const octave_value&); | |
1452 | |
1453 virtual octave_value get (const caseless_str&) const; | |
1454 | |
7379 | 1455 virtual octave_value get (bool all = false) const; |
7363 | 1456 |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1457 virtual property get_property (const caseless_str&); |
7363 | 1458 |
1459 std::string get_tag (void) const { return tag.string_value (); } | |
1460 | |
1461 graphics_handle get_parent (void) const { return parent.handle_value (); } | |
1462 | |
1463 std::string get_type (void) const { return type.string_value (); } | |
1464 | |
1465 bool is_modified (void) const { return __modified__.is_on (); } | |
7251 | 1466 |
1467 graphics_handle get___myhandle__ (void) const { return __myhandle__; } | |
7366 | 1468 |
1469 std::string get_busyaction (void) const { return busyaction.current_value (); } | |
1470 | |
1471 octave_value get_buttondownfcn (void) const { return buttondownfcn.get (); } | |
1472 | |
7435 | 1473 bool is_clipping (void) const { return clipping.is_on (); } |
7366 | 1474 std::string get_clipping (void) const { return clipping.current_value (); } |
1475 | |
7367 | 1476 void execute_createfcn (const octave_value& data = octave_value ()) const |
1477 { createfcn.execute (data); } | |
1478 | |
7366 | 1479 octave_value get_createfcn (void) const { return createfcn.get (); } |
1480 | |
7367 | 1481 void execute_deletefcn (const octave_value& data = octave_value ()) const |
1482 { deletefcn.execute (data); } | |
1483 | |
7366 | 1484 octave_value get_deletefcn (void) const { return deletefcn.get (); } |
1485 | |
1486 std::string get_handlevisibility (void) const { return handlevisibility.current_value (); } | |
1487 | |
1488 std::string get_hittest (void) const { return hittest.current_value (); } | |
1489 | |
1490 std::string get_interruptible (void) const { return interruptible.current_value (); } | |
1491 | |
1492 std::string get_selected (void) const { return selected.current_value (); } | |
1493 | |
1494 std::string get_selectionhighlight (void) const { return selectionhighlight.current_value (); } | |
1495 | |
1496 octave_value get_uicontextmenu (void) const { return uicontextmenu.get (); } | |
1497 | |
1498 octave_value get_userdata (void) const { return userdata.get (); } | |
7408 | 1499 |
1500 bool is_visible (void) const { return visible.is_on (); } | |
7366 | 1501 std::string get_visible (void) const { return visible.current_value (); } |
1502 | |
7403 | 1503 bool is_beingdeleted (void) const { return beingdeleted.is_on (); } |
1504 std::string get_beingdeleted (void) const { return beingdeleted.current_value (); } | |
1505 | |
7386 | 1506 virtual void remove_child (const graphics_handle& h); |
1507 | |
1508 virtual void adopt (const graphics_handle& h) | |
6874 | 1509 { |
1510 octave_idx_type n = children.numel (); | |
1511 children.resize (1, n+1); | |
7056 | 1512 children(n) = h.value (); |
6874 | 1513 } |
1514 | |
7419 | 1515 virtual graphics_backend get_backend (void) const; |
1516 | |
7526
52d58b0463ed
graphics.cc, graphics.h.in: avoid some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
7524
diff
changeset
|
1517 virtual Matrix get_boundingbox (bool /*internal*/ = false) const |
7447 | 1518 { return Matrix (1, 4, 0.0); } |
1519 | |
7828
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
1520 virtual void 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
|
1521 |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1522 virtual void add_listener (const caseless_str&, const octave_value&, |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1523 listener_mode = POSTSET); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1524 |
7363 | 1525 void set_tag (const octave_value& val) { tag = val; } |
7176 | 1526 |
6874 | 1527 void set_parent (const octave_value& val); |
1528 | |
7408 | 1529 void set_modified (const octave_value& val) { __modified__ = val; } |
1530 | |
7366 | 1531 void set_busyaction (const octave_value& val) |
1532 { | |
1533 if (! error_state) | |
1534 { | |
1535 busyaction = val; | |
1536 mark_modified (); | |
1537 } | |
1538 } | |
1539 | |
1540 void set_buttondownfcn (const octave_value& val) | |
1541 { | |
1542 if (! error_state) | |
1543 { | |
1544 buttondownfcn = val; | |
1545 mark_modified (); | |
1546 } | |
1547 } | |
1548 | |
1549 void set_clipping (const octave_value& val) | |
1550 { | |
1551 if (! error_state) | |
1552 { | |
1553 clipping = val; | |
1554 mark_modified (); | |
1555 } | |
1556 } | |
1557 | |
1558 void set_createfcn (const octave_value& val) | |
1559 { | |
1560 if (! error_state) | |
1561 { | |
1562 createfcn = val; | |
1563 mark_modified (); | |
1564 } | |
1565 } | |
1566 | |
1567 void set_deletefcn (const octave_value& val) | |
1568 { | |
1569 if (! error_state) | |
1570 { | |
1571 deletefcn = val; | |
1572 mark_modified (); | |
1573 } | |
1574 } | |
1575 | |
1576 void set_handlevisibility (const octave_value& val) | |
1577 { | |
1578 if (! error_state) | |
1579 { | |
1580 handlevisibility = val; | |
1581 mark_modified (); | |
1582 } | |
1583 } | |
1584 | |
1585 void set_hittest (const octave_value& val) | |
1586 { | |
1587 if (! error_state) | |
1588 { | |
1589 hittest = val; | |
1590 mark_modified (); | |
1591 } | |
1592 } | |
1593 | |
1594 void set_interruptible (const octave_value& val) | |
1595 { | |
1596 if (! error_state) | |
1597 { | |
1598 interruptible = val; | |
1599 mark_modified (); | |
1600 } | |
1601 } | |
1602 | |
1603 void set_selected (const octave_value& val) | |
1604 { | |
1605 if (! error_state) | |
1606 { | |
1607 selected = val; | |
1608 mark_modified (); | |
1609 } | |
1610 } | |
1611 | |
1612 void set_selectionhighlight (const octave_value& val) | |
1613 { | |
1614 if (! error_state) | |
1615 { | |
1616 selectionhighlight = val; | |
1617 mark_modified (); | |
1618 } | |
1619 } | |
1620 | |
1621 void set_uicontextmenu (const octave_value& val) | |
1622 { | |
1623 if (! error_state) | |
1624 { | |
1625 uicontextmenu = val; | |
1626 mark_modified (); | |
1627 } | |
1628 } | |
1629 | |
1630 void set_userdata (const octave_value& val) | |
1631 { | |
1632 if (! error_state) | |
1633 { | |
1634 userdata = val; | |
1635 mark_modified (); | |
1636 } | |
1637 } | |
1638 | |
1639 virtual void set_visible (const octave_value& val) | |
1640 { | |
1641 if (! error_state) | |
1642 { | |
1643 visible = val; | |
1644 mark_modified (); | |
1645 } | |
1646 } | |
1647 | |
7403 | 1648 void set_beingdeleted (const octave_value& val) |
1649 { | |
1650 if (! error_state) | |
1651 { | |
1652 beingdeleted = val; | |
1653 mark_modified (); | |
1654 } | |
1655 } | |
1656 | |
7366 | 1657 |
1658 | |
6874 | 1659 void reparent (const graphics_handle& new_parent) { parent = new_parent; } |
1660 | |
7214 | 1661 // Update data limits for AXIS_TYPE (xdata, ydata, etc.) in the parent |
1662 // axes object. | |
1663 | |
7386 | 1664 virtual void update_axis_limits (const std::string& axis_type) const; |
7214 | 1665 |
6874 | 1666 virtual void delete_children (void); |
1667 | |
7222 | 1668 Matrix get_children (void) const { return children; } |
1669 | |
1670 // FIXME -- these functions should be generated automatically by the | |
1671 // genprops.awk script. | |
1672 // | |
1673 // EMIT_BASE_PROPERTIES_GET_FUNCTIONS | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1674 virtual array_property get_xdata_property (void) const |
7222 | 1675 { |
1676 error ("get: invalid property \"xdata\""); | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1677 return array_property (); |
7222 | 1678 } |
1679 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1680 virtual array_property get_ydata_property (void) const |
7222 | 1681 { |
1682 error ("get: invalid property \"ydata\""); | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1683 return array_property (); |
7222 | 1684 } |
1685 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1686 virtual array_property get_zdata_property (void) const |
7222 | 1687 { |
1688 error ("get: invalid property \"zdata\""); | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1689 return array_property (); |
7222 | 1690 } |
1691 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1692 virtual array_property get_ldata_property (void) const |
7222 | 1693 { |
1694 error ("get: invalid property \"ldata\""); | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1695 return array_property (); |
7222 | 1696 } |
1697 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1698 virtual array_property get_udata_property (void) const |
7222 | 1699 { |
1700 error ("get: invalid property \"udata\""); | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1701 return array_property (); |
7222 | 1702 } |
1703 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1704 virtual array_property get_xldata_property (void) const |
7222 | 1705 { |
1706 error ("get: invalid property \"xldata\""); | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1707 return array_property (); |
7222 | 1708 } |
1709 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1710 virtual array_property get_xudata_property (void) const |
7222 | 1711 { |
1712 error ("get: invalid property \"xudata\""); | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
1713 return array_property (); |
7222 | 1714 } |
1715 | |
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
|
1716 virtual array_property get_cdata_property (void) const |
7222 | 1717 { |
1718 error ("get: invalid property \"cdata\""); | |
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
|
1719 return array_property (); |
7222 | 1720 } |
1721 | |
6874 | 1722 protected: |
7403 | 1723 // properties common to all objects |
1724 bool_property beingdeleted; | |
1725 radio_property busyaction; | |
1726 callback_property buttondownfcn; | |
7363 | 1727 // FIXME: use a property class for children |
6874 | 1728 Matrix children; |
7366 | 1729 bool_property clipping; |
1730 callback_property createfcn; | |
1731 callback_property deletefcn; | |
1732 radio_property handlevisibility; | |
1733 bool_property hittest; | |
1734 bool_property interruptible; | |
7403 | 1735 handle_property parent; |
7366 | 1736 bool_property selected; |
1737 bool_property selectionhighlight; | |
7403 | 1738 string_property tag; |
1739 string_property type; | |
7366 | 1740 any_property userdata; |
1741 bool_property visible; | |
7403 | 1742 // additional (octave-specific) properties |
1743 bool_property __modified__; | |
1744 graphics_handle __myhandle__; | |
1745 // FIXME: should this really be here? | |
1746 handle_property uicontextmenu; | |
7363 | 1747 |
1748 protected: | |
1749 std::map<caseless_str, property> all_props; | |
1750 | |
1751 protected: | |
1752 void insert_static_property (const std::string& name, base_property& p) | |
1753 { insert_property (name, property (&p, true)); } | |
1754 | |
1755 virtual void init (void) { } | |
6874 | 1756 }; |
1757 | |
7365 | 1758 class OCTINTERP_API base_graphics_object |
6874 | 1759 { |
1760 public: | |
1761 friend class graphics_object; | |
1762 | |
1763 base_graphics_object (void) : count (1) { } | |
1764 | |
1765 base_graphics_object (const base_graphics_object&) { } | |
1766 | |
1767 virtual ~base_graphics_object (void) { } | |
1768 | |
1769 virtual void mark_modified (void) | |
1770 { | |
7386 | 1771 if (valid_object ()) |
1772 get_properties ().mark_modified (); | |
1773 else | |
1774 error ("base_graphics_object::mark_modified: invalid graphics object"); | |
6874 | 1775 } |
1776 | |
7386 | 1777 virtual void override_defaults (base_graphics_object& obj) |
6874 | 1778 { |
7386 | 1779 if (valid_object ()) |
1780 get_properties ().override_defaults (obj); | |
1781 else | |
1782 error ("base_graphics_object::override_defaults: invalid graphics object"); | |
6874 | 1783 } |
1784 | |
7386 | 1785 virtual void set_from_list (property_list& plist) |
6874 | 1786 { |
7386 | 1787 if (valid_object ()) |
1788 get_properties ().set_from_list (*this, plist); | |
1789 else | |
1790 error ("base_graphics_object::set_from_list: invalid graphics object"); | |
6874 | 1791 } |
1792 | |
7386 | 1793 virtual void set (const caseless_str& pname, const octave_value& pval) |
6874 | 1794 { |
7386 | 1795 if (valid_object ()) |
1796 get_properties ().set (pname, pval); | |
1797 else | |
1798 error ("base_graphics_object::set: invalid graphics object"); | |
6874 | 1799 } |
1800 | |
1801 virtual void set_defaults (const std::string&) | |
1802 { | |
1803 error ("base_graphics_object::set_defaults: invalid graphics object"); | |
1804 } | |
1805 | |
7379 | 1806 virtual octave_value get (bool all = false) const |
6874 | 1807 { |
7386 | 1808 if (valid_object ()) |
1809 return get_properties ().get (all); | |
1810 else | |
1811 { | |
1812 error ("base_graphics_object::get: invalid graphics object"); | |
1813 return octave_value (); | |
1814 } | |
6874 | 1815 } |
1816 | |
7386 | 1817 virtual octave_value get (const caseless_str& pname) const |
6874 | 1818 { |
7386 | 1819 if (valid_object ()) |
1820 return get_properties ().get (pname); | |
1821 else | |
1822 { | |
1823 error ("base_graphics_object::get: invalid graphics object"); | |
1824 return octave_value (); | |
1825 } | |
6874 | 1826 } |
1827 | |
7189 | 1828 virtual octave_value get_default (const caseless_str&) const; |
6874 | 1829 |
7189 | 1830 virtual octave_value get_factory_default (const caseless_str&) const; |
6874 | 1831 |
1832 virtual octave_value get_defaults (void) const | |
1833 { | |
1834 error ("base_graphics_object::get_defaults: invalid graphics object"); | |
1835 return octave_value (); | |
1836 } | |
1837 | |
1838 virtual octave_value get_factory_defaults (void) const | |
1839 { | |
1840 error ("base_graphics_object::get_factory_defaults: invalid graphics object"); | |
1841 return octave_value (); | |
1842 } | |
1843 | |
1844 virtual graphics_handle get_parent (void) const | |
1845 { | |
7386 | 1846 if (valid_object ()) |
1847 return get_properties ().get_parent (); | |
1848 else | |
1849 { | |
1850 error ("base_graphics_object::get_parent: invalid graphics object"); | |
1851 return graphics_handle (); | |
1852 } | |
6874 | 1853 } |
1854 | |
7386 | 1855 virtual void remove_child (const graphics_handle& h) |
6874 | 1856 { |
7386 | 1857 if (valid_object ()) |
1858 get_properties ().remove_child (h); | |
1859 else | |
1860 error ("base_graphics_object::remove_child: invalid graphics object"); | |
6874 | 1861 } |
1862 | |
7386 | 1863 virtual void adopt (const graphics_handle& h) |
6874 | 1864 { |
7386 | 1865 if (valid_object ()) |
1866 get_properties ().adopt (h); | |
1867 else | |
1868 error ("base_graphics_object::adopt: invalid graphics object"); | |
6874 | 1869 } |
1870 | |
7386 | 1871 virtual void reparent (const graphics_handle& np) |
6874 | 1872 { |
7386 | 1873 if (valid_object ()) |
1874 get_properties ().reparent (np); | |
1875 else | |
1876 error ("base_graphics_object::reparent: invalid graphics object"); | |
6874 | 1877 } |
1878 | |
1879 virtual void defaults (void) const | |
1880 { | |
7386 | 1881 if (valid_object ()) |
1882 { | |
1883 std::string msg = (type () + "::defaults"); | |
1884 gripe_not_implemented (msg.c_str ()); | |
1885 } | |
1886 else | |
1887 error ("base_graphics_object::default: invalid graphics object"); | |
6874 | 1888 } |
1889 | |
1890 virtual base_properties& get_properties (void) | |
1891 { | |
1892 static base_properties properties; | |
1893 error ("base_graphics_object::get_properties: invalid graphics object"); | |
1894 return properties; | |
1895 } | |
1896 | |
7222 | 1897 virtual const base_properties& get_properties (void) const |
1898 { | |
1899 static base_properties properties; | |
1900 error ("base_graphics_object::get_properties: invalid graphics object"); | |
1901 return properties; | |
1902 } | |
1903 | |
1904 virtual void update_axis_limits (const std::string&) | |
7214 | 1905 { |
1906 error ("base_graphics_object::update_axis_limits: invalid graphics object"); | |
1907 } | |
1908 | |
6874 | 1909 virtual bool valid_object (void) const { return false; } |
1910 | |
7386 | 1911 virtual std::string type (void) const |
1912 { | |
1913 return (valid_object () ? get_properties ().graphics_object_name () | |
1914 : "unknown"); | |
1915 } | |
6874 | 1916 |
1917 bool isa (const std::string& go_name) const | |
1918 { | |
1919 return type () == go_name; | |
1920 } | |
1921 | |
7419 | 1922 virtual graphics_backend get_backend (void) const |
1923 { | |
1924 if (valid_object ()) | |
1925 return get_properties ().get_backend (); | |
1926 else | |
1927 { | |
1928 error ("base_graphics_object::get_backend: invalid graphics object"); | |
1929 return graphics_backend (); | |
1930 } | |
1931 } | |
1932 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1933 virtual void add_property_listener (const std::string& nm, |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1934 const octave_value& v, |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1935 listener_mode mode = POSTSET) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1936 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1937 if (valid_object ()) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1938 get_properties ().add_listener (nm, v, mode); |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1939 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
1940 |
6874 | 1941 protected: |
1942 // A reference count. | |
1943 int count; | |
1944 }; | |
1945 | |
7365 | 1946 class OCTINTERP_API graphics_object |
6874 | 1947 { |
1948 public: | |
1949 graphics_object (void) : rep (new base_graphics_object ()) { } | |
1950 | |
1951 graphics_object (base_graphics_object *new_rep) | |
1952 : rep (new_rep) { } | |
1953 | |
1954 graphics_object (const graphics_object& obj) | |
1955 { | |
1956 rep = obj.rep; | |
1957 rep->count++; | |
1958 } | |
1959 | |
1960 graphics_object& operator = (const graphics_object& obj) | |
1961 { | |
1962 if (rep != obj.rep) | |
1963 { | |
1964 if (--rep->count == 0) | |
1965 delete rep; | |
1966 | |
1967 rep = obj.rep; | |
1968 rep->count++; | |
1969 } | |
1970 | |
1971 return *this; | |
1972 } | |
1973 | |
1974 ~graphics_object (void) | |
1975 { | |
1976 if (--rep->count == 0) | |
1977 delete rep; | |
1978 } | |
1979 | |
1980 void mark_modified (void) { rep->mark_modified (); } | |
1981 | |
1982 void override_defaults (base_graphics_object& obj) | |
1983 { | |
1984 rep->override_defaults (obj); | |
1985 } | |
1986 | |
7214 | 1987 void set_from_list (property_list& plist) { rep->set_from_list (plist); } |
6874 | 1988 |
7189 | 1989 void set (const caseless_str& name, const octave_value& val) |
6874 | 1990 { |
1991 rep->set (name, val); | |
1992 } | |
1993 | |
1994 void set (const octave_value_list& args); | |
1995 | |
7214 | 1996 void set_defaults (const std::string& mode) { rep->set_defaults (mode); } |
1997 | |
7379 | 1998 octave_value get (bool all = false) const { return rep->get (all); } |
6874 | 1999 |
7189 | 2000 octave_value get (const caseless_str& name) const |
6874 | 2001 { |
2002 return name.compare ("default") | |
2003 ? get_defaults () | |
2004 : (name.compare ("factory") | |
2005 ? get_factory_defaults () : rep->get (name)); | |
2006 } | |
2007 | |
7189 | 2008 octave_value get_default (const caseless_str& name) const |
6874 | 2009 { |
2010 return rep->get_default (name); | |
2011 } | |
2012 | |
7189 | 2013 octave_value get_factory_default (const caseless_str& name) const |
6874 | 2014 { |
2015 return rep->get_factory_default (name); | |
2016 } | |
2017 | |
2018 octave_value get_defaults (void) const { return rep->get_defaults (); } | |
2019 | |
2020 octave_value get_factory_defaults (void) const | |
2021 { | |
2022 return rep->get_factory_defaults (); | |
2023 } | |
2024 | |
2025 graphics_handle get_parent (void) const { return rep->get_parent (); } | |
2026 | |
7214 | 2027 void remove_child (const graphics_handle& h) { rep->remove_child (h); } |
2028 | |
2029 void adopt (const graphics_handle& h) { rep->adopt (h); } | |
2030 | |
2031 void reparent (const graphics_handle& h) { rep->reparent (h); } | |
6874 | 2032 |
2033 void defaults (void) const { rep->defaults (); } | |
2034 | |
2035 bool isa (const std::string& go_name) const { return rep->isa (go_name); } | |
2036 | |
2037 base_properties& get_properties (void) { return rep->get_properties (); } | |
2038 | |
7222 | 2039 const base_properties& get_properties (void) const |
2040 { | |
2041 return rep->get_properties (); | |
2042 } | |
2043 | |
7214 | 2044 void update_axis_limits (const std::string& axis_type) |
2045 { | |
2046 rep->update_axis_limits (axis_type); | |
2047 } | |
2048 | |
6874 | 2049 bool valid_object (void) const { return rep->valid_object (); } |
2050 | |
2051 operator bool (void) const { return rep->valid_object (); } | |
2052 | |
7222 | 2053 // FIXME -- these functions should be generated automatically by the |
2054 // genprops.awk script. | |
2055 // | |
2056 // EMIT_GRAPHICS_OBJECT_GET_FUNCTIONS | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2057 array_property get_xdata_property (void) const |
7222 | 2058 { |
2059 const base_properties& props = get_properties (); | |
7363 | 2060 return props.get_xdata_property (); |
7222 | 2061 } |
2062 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2063 array_property get_ydata_property (void) const |
7222 | 2064 { |
2065 const base_properties& props = get_properties (); | |
7363 | 2066 return props.get_ydata_property (); |
7222 | 2067 } |
2068 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2069 array_property get_zdata_property (void) const |
7222 | 2070 { |
2071 const base_properties& props = get_properties (); | |
7363 | 2072 return props.get_zdata_property (); |
7222 | 2073 } |
2074 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2075 array_property get_ldata_property (void) const |
7222 | 2076 { |
2077 const base_properties& props = get_properties (); | |
7363 | 2078 return props.get_ldata_property (); |
7222 | 2079 } |
2080 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2081 array_property get_udata_property (void) const |
7222 | 2082 { |
2083 const base_properties& props = get_properties (); | |
7363 | 2084 return props.get_udata_property (); |
7222 | 2085 } |
2086 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2087 array_property get_xldata_property (void) const |
7222 | 2088 { |
2089 const base_properties& props = get_properties (); | |
7363 | 2090 return props.get_xldata_property (); |
7222 | 2091 } |
2092 | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2093 array_property get_xudata_property (void) const |
7222 | 2094 { |
2095 const base_properties& props = get_properties (); | |
7363 | 2096 return props.get_xudata_property (); |
7222 | 2097 } |
2098 | |
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
|
2099 array_property get_cdata_property (void) const |
7222 | 2100 { |
2101 const base_properties& props = get_properties (); | |
7363 | 2102 return props.get_cdata_property (); |
7222 | 2103 } |
2104 | |
7419 | 2105 graphics_backend get_backend (void) const { return rep->get_backend (); } |
7408 | 2106 |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
2107 void add_property_listener (const std::string& nm, const octave_value& v, |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
2108 listener_mode mode = POSTSET) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
2109 { rep->add_property_listener (nm, v, mode); } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
2110 |
7408 | 2111 private: |
7419 | 2112 base_graphics_object *rep; |
7408 | 2113 }; |
2114 | |
2115 // --------------------------------------------------------------------- | |
2116 | |
7365 | 2117 class OCTINTERP_API root_figure : public base_graphics_object |
6874 | 2118 { |
2119 public: | |
7821
f79dcba526a8
Export nested properties classes of all graphics object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7527
diff
changeset
|
2120 class OCTINTERP_API properties : public base_properties |
6874 | 2121 { |
2122 public: | |
2123 // See the genprops.awk script for an explanation of the | |
2124 // properties declarations. | |
2125 | |
7363 | 2126 BEGIN_PROPERTIES(root_figure) |
2127 handle_property currentfigure S , graphics_handle () | |
7822
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7821
diff
changeset
|
2128 handle_property callbackobject Sr , graphics_handle () |
6874 | 2129 END_PROPERTIES |
7822
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7821
diff
changeset
|
2130 |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7821
diff
changeset
|
2131 private: |
edbaa13397ee
Implement callbackobject property in root object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7821
diff
changeset
|
2132 std::list<graphics_handle> cbo_stack; |
6874 | 2133 }; |
2134 | |
2135 private: | |
2136 properties xproperties; | |
2137 | |
2138 public: | |
2139 | |
7363 | 2140 root_figure (void) : xproperties (0, graphics_handle ()), default_properties () { } |
6874 | 2141 |
2142 ~root_figure (void) { xproperties.delete_children (); } | |
2143 | |
2144 void mark_modified (void) { } | |
2145 | |
2146 void override_defaults (base_graphics_object& obj) | |
2147 { | |
2148 // Now override with our defaults. If the default_properties | |
2149 // list includes the properties for all defaults (line, | |
2150 // surface, etc.) then we don't have to know the type of OBJ | |
2151 // here, we just call its set function and let it decide which | |
2152 // properties from the list to use. | |
2153 obj.set_from_list (default_properties); | |
2154 } | |
2155 | |
7189 | 2156 void set (const caseless_str& name, const octave_value& value) |
6874 | 2157 { |
2158 if (name.compare ("default", 7)) | |
2159 // strip "default", pass rest to function that will | |
2160 // parse the remainder and add the element to the | |
2161 // default_properties map. | |
2162 default_properties.set (name.substr (7), value); | |
2163 else | |
2164 xproperties.set (name, value); | |
2165 } | |
2166 | |
7189 | 2167 octave_value get (const caseless_str& name) const |
6874 | 2168 { |
2169 octave_value retval; | |
2170 | |
2171 if (name.compare ("default", 7)) | |
2172 return get_default (name.substr (7)); | |
2173 else if (name.compare ("factory", 7)) | |
2174 return get_factory_default (name.substr (7)); | |
2175 else | |
2176 retval = xproperties.get (name); | |
2177 | |
2178 return retval; | |
2179 } | |
2180 | |
7189 | 2181 octave_value get_default (const caseless_str& name) const |
6874 | 2182 { |
2183 octave_value retval = default_properties.lookup (name); | |
2184 | |
2185 if (retval.is_undefined ()) | |
7847
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7846
diff
changeset
|
2186 { |
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7846
diff
changeset
|
2187 // no default property found, use factory default |
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7846
diff
changeset
|
2188 retval = factory_properties.lookup (name); |
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7846
diff
changeset
|
2189 |
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7846
diff
changeset
|
2190 if (retval.is_undefined ()) |
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7846
diff
changeset
|
2191 error ("get: invalid default property `%s'", name.c_str ()); |
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7846
diff
changeset
|
2192 } |
6874 | 2193 |
2194 return retval; | |
2195 } | |
2196 | |
7189 | 2197 octave_value get_factory_default (const caseless_str& name) const |
6874 | 2198 { |
2199 octave_value retval = factory_properties.lookup (name); | |
2200 | |
2201 if (retval.is_undefined ()) | |
2202 error ("get: invalid factory default property `%s'", name.c_str ()); | |
2203 | |
2204 return retval; | |
2205 } | |
2206 | |
2207 octave_value get_defaults (void) const | |
2208 { | |
2209 return default_properties.as_struct ("default"); | |
2210 } | |
2211 | |
2212 octave_value get_factory_defaults (void) const | |
2213 { | |
2214 return factory_properties.as_struct ("factory"); | |
2215 } | |
2216 | |
2217 base_properties& get_properties (void) { return xproperties; } | |
2218 | |
7222 | 2219 const base_properties& get_properties (void) const { return xproperties; } |
2220 | |
6874 | 2221 bool valid_object (void) const { return true; } |
2222 | |
2223 private: | |
2224 property_list default_properties; | |
2225 | |
2226 static property_list factory_properties; | |
2227 | |
2228 static property_list::plist_map_type init_factory_properties (void); | |
2229 }; | |
2230 | |
2231 // --------------------------------------------------------------------- | |
2232 | |
7365 | 2233 class OCTINTERP_API figure : public base_graphics_object |
6874 | 2234 { |
2235 public: | |
7445 | 2236 class OCTINTERP_API properties : public base_properties |
6874 | 2237 { |
2238 public: | |
7408 | 2239 void close (bool pop = true); |
2240 | |
7366 | 2241 void set_visible (const octave_value& val); |
6874 | 2242 |
7408 | 2243 graphics_backend get_backend (void) const |
2244 { | |
2245 if (! backend) | |
2246 backend = graphics_backend::default_backend (); | |
2247 | |
2248 return backend; | |
2249 } | |
2250 | |
7439 | 2251 void set_backend (const graphics_backend& b) |
2252 { | |
2253 close (false); | |
2254 backend = b; | |
2255 __backend__ = b.get_name (); | |
7847
40b16e04172a
Make backend switching work.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7846
diff
changeset
|
2256 __plot_stream__ = Matrix (); |
7439 | 2257 mark_modified (); |
2258 } | |
2259 | |
2260 void set___backend__ (const octave_value& val) | |
2261 { | |
2262 if (! error_state) | |
2263 { | |
2264 if (val.is_string ()) | |
2265 { | |
2266 std::string nm = val.string_value (); | |
2267 graphics_backend b = graphics_backend::find_backend (nm); | |
2268 if (b.get_name () != nm) | |
2269 { | |
2270 error ("figure::__backend__ : illegal backend"); | |
2271 } | |
2272 else | |
2273 { | |
2274 set_backend (b); | |
2275 mark_modified (); | |
2276 } | |
2277 } | |
2278 else | |
2279 error ("__backend__ must be a string"); | |
2280 } | |
2281 } | |
7408 | 2282 |
7447 | 2283 Matrix get_boundingbox (bool internal = false) const; |
7445 | 2284 |
7828
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
2285 void set_boundingbox (const Matrix& bb); |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7824
diff
changeset
|
2286 |
6874 | 2287 // See the genprops.awk script for an explanation of the |
2288 // properties declarations. | |
2289 | |
7363 | 2290 BEGIN_PROPERTIES(figure) |
7379 | 2291 any_property __plot_stream__ h , Matrix () |
2292 bool_property __enhanced__ h , "on" | |
7405 | 2293 radio_property nextplot , "new|{add}|replace_children|replace" |
7363 | 2294 callback_property closerequestfcn , "closereq" |
2295 handle_property currentaxes S , graphics_handle () | |
2296 array_property colormap , jet_colormap () | |
7405 | 2297 radio_property paperorientation , "{portrait}|landscape|rotated" |
7363 | 2298 color_property color , color_values (1, 1, 1) |
7405 | 2299 array_property alphamap , Matrix (64, 1, 1) |
2300 string_property currentcharacter r , "" | |
2301 handle_property currentobject r , graphics_handle () | |
2302 array_property current_point r , Matrix (2, 1, 0) | |
2303 bool_property dockcontrols , "off" | |
2304 bool_property doublebuffer , "on" | |
2305 string_property filename r , "" | |
2306 bool_property integerhandle , "on" | |
2307 bool_property inverthardcopy , "off" | |
2308 callback_property keypressfcn , Matrix () | |
2309 callback_property keyreleasefcn , Matrix () | |
2310 radio_property menubar , "none|{figure}" | |
2311 double_property mincolormap , 64 | |
2312 string_property name , "" | |
2313 bool_property numbertitle , "on" | |
2314 radio_property paperunits , "{inches}|centimeters|normalized|points" | |
2315 array_property paperposition , Matrix (1, 4 , 0) | |
2316 radio_property paperpositionmode , "auto|{manual}" | |
2317 array_property papersize r , Matrix (1, 4, 0) | |
2318 radio_property papertype , "{usletter}|uslegal|a0|a1|a2|a3|a4|a5|b0|b1|b2|b3|b4|b5|arch-a|arch-b|arch-c|arch-d|arch-e|a|b|c|d|e|tabloid" | |
2319 radio_property pointer , "crosshair|fullcrosshair|{arrow}|ibeam|watch|topl|topr|botl|botr|left|top|right|bottom|circle|cross|fleur|custom|hand" | |
2320 array_property pointershapecdata , Matrix (16, 16, 0) | |
2321 array_property pointershapehotspot , Matrix (1, 2, 0) | |
7828
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
2322 array_property position S , default_figure_position () |
7405 | 2323 radio_property renderer , "{painters}|zbuffer|opengl|none" |
2324 radio_property renderermode , "{auto}|manual" | |
2325 bool_property resize , "on" | |
2326 callback_property resizefcn , Matrix () | |
2327 radio_property selectiontype , "{normal}|open|alt|extend" | |
2328 radio_property toolbar , "none|{auto}|figure" | |
2329 radio_property units , "inches|centimeters|normalized|points|{pixels}|characters" | |
2330 callback_property windowbuttondownfcn , Matrix () | |
2331 callback_property windowbuttonmotionfcn , Matrix () | |
2332 callback_property windowbuttonupfcn , Matrix () | |
2333 callback_property windowbuttonwheelfcn , Matrix () | |
2334 radio_property windowstyle , "{normal}|modal|docked" | |
2335 string_property wvisual , "" | |
2336 radio_property wvisualmode , "{auto}|manual" | |
2337 string_property xdisplay , "" | |
2338 string_property xvisual , "" | |
2339 radio_property xvisualmode , "{auto}|manual" | |
2340 callback_property buttondownfcn , Matrix () | |
7439 | 2341 string_property __backend__ s , "gnuplot" |
6874 | 2342 END_PROPERTIES |
7363 | 2343 |
2344 protected: | |
2345 void init (void) | |
2346 { | |
2347 colormap.add_constraint (dim_vector (-1, 3)); | |
7406 | 2348 alphamap.add_constraint (dim_vector (-1, 1)); |
2349 paperposition.add_constraint (dim_vector (1, 4)); | |
2350 pointershapecdata.add_constraint (dim_vector (16, 16)); | |
2351 pointershapehotspot.add_constraint (dim_vector (1, 2)); | |
2352 position.add_constraint (dim_vector (1, 4)); | |
7363 | 2353 } |
7408 | 2354 |
2355 private: | |
2356 mutable graphics_backend backend; | |
6874 | 2357 }; |
2358 | |
2359 private: | |
2360 properties xproperties; | |
2361 | |
2362 public: | |
2363 figure (const graphics_handle& mh, const graphics_handle& p) | |
2364 : base_graphics_object (), xproperties (mh, p), default_properties () | |
2365 { | |
2366 xproperties.override_defaults (*this); | |
2367 } | |
2368 | |
2369 ~figure (void) | |
2370 { | |
7386 | 2371 xproperties.delete_children (); |
6874 | 2372 xproperties.close (); |
2373 } | |
2374 | |
2375 void override_defaults (base_graphics_object& obj) | |
2376 { | |
2377 // Allow parent (root figure) to override first (properties knows how | |
2378 // to find the parent object). | |
2379 xproperties.override_defaults (obj); | |
2380 | |
2381 // Now override with our defaults. If the default_properties | |
2382 // list includes the properties for all defaults (line, | |
2383 // surface, etc.) then we don't have to know the type of OBJ | |
2384 // here, we just call its set function and let it decide which | |
2385 // properties from the list to use. | |
2386 obj.set_from_list (default_properties); | |
2387 } | |
2388 | |
7189 | 2389 void set (const caseless_str& name, const octave_value& value) |
6874 | 2390 { |
2391 if (name.compare ("default", 7)) | |
2392 // strip "default", pass rest to function that will | |
2393 // parse the remainder and add the element to the | |
2394 // default_properties map. | |
2395 default_properties.set (name.substr (7), value); | |
2396 else | |
2397 xproperties.set (name, value); | |
2398 } | |
2399 | |
7189 | 2400 octave_value get (const caseless_str& name) const |
6874 | 2401 { |
2402 octave_value retval; | |
2403 | |
2404 if (name.compare ("default", 7)) | |
2405 retval = get_default (name.substr (7)); | |
2406 else | |
2407 retval = xproperties.get (name); | |
2408 | |
2409 return retval; | |
2410 } | |
2411 | |
7189 | 2412 octave_value get_default (const caseless_str& name) const; |
6874 | 2413 |
2414 octave_value get_defaults (void) const | |
2415 { | |
2416 return default_properties.as_struct ("default"); | |
2417 } | |
2418 | |
2419 base_properties& get_properties (void) { return xproperties; } | |
2420 | |
7222 | 2421 const base_properties& get_properties (void) const { return xproperties; } |
2422 | |
6874 | 2423 bool valid_object (void) const { return true; } |
2424 | |
2425 private: | |
2426 property_list default_properties; | |
2427 }; | |
2428 | |
2429 // --------------------------------------------------------------------- | |
2430 | |
7435 | 2431 class OCTINTERP_API graphics_xform |
2432 { | |
2433 public: | |
2434 graphics_xform (void) | |
2435 : xform (xform_eye ()), xform_inv (xform_eye ()) | |
2436 { | |
2437 sx = sy = sz = "linear"; | |
2438 } | |
2439 | |
2440 graphics_xform (const Matrix& xm, const Matrix& xim, | |
2441 const scaler& x, const scaler& y, const scaler& z) | |
2442 : xform (xm), xform_inv (xim), sx (x), sy (y), sz (z) { } | |
2443 | |
2444 graphics_xform (const graphics_xform& g) | |
2445 : xform (g.xform), xform_inv (g.xform_inv), sx (g.sx), | |
2446 sy (g.sy), sz (g.sz) { } | |
2447 | |
2448 ~graphics_xform (void) { } | |
2449 | |
2450 graphics_xform& operator = (const graphics_xform& g) | |
2451 { | |
2452 xform = g.xform; | |
2453 xform_inv = g.xform_inv; | |
2454 sx = g.sx; | |
2455 sy = g.sy; | |
2456 sz = g.sz; | |
2457 | |
2458 return *this; | |
2459 } | |
2460 | |
2461 static ColumnVector xform_vector (double x, double y, double z); | |
2462 | |
2463 static Matrix xform_eye (void); | |
2464 | |
2465 ColumnVector transform (double x, double y, double z, | |
2466 bool scale = true) const; | |
2467 | |
2468 ColumnVector untransform (double x, double y, double z, | |
2469 bool scale = true) const; | |
2470 | |
2471 Matrix xscale (const Matrix& m) const { return sx.scale (m); } | |
2472 Matrix yscale (const Matrix& m) const { return sy.scale (m); } | |
2473 Matrix zscale (const Matrix& m) const { return sz.scale (m); } | |
2474 | |
7832
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2475 Matrix scale (const Matrix& m) const |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2476 { |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2477 bool has_z = (m.columns () > 2); |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2478 |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2479 if (sx.is_linear () && sy.is_linear () |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2480 && (! has_z || sz.is_linear ())) |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2481 return m; |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2482 |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2483 Matrix retval (m.dims ()); |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2484 |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2485 int r = m.rows (); |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2486 |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2487 for (int i = 0; i < r; i++) |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2488 { |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2489 retval(i,0) = sx.scale (m(i,0)); |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2490 retval(i,1) = sy.scale (m(i,1)); |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2491 if (has_z) |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2492 retval(i,2) = sz.scale (m(i,2)); |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2493 } |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2494 |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2495 return retval; |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2496 } |
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
2497 |
7435 | 2498 private: |
2499 Matrix xform; | |
2500 Matrix xform_inv; | |
2501 scaler sx, sy, sz; | |
2502 }; | |
2503 | |
7365 | 2504 class OCTINTERP_API axes : public base_graphics_object |
6874 | 2505 { |
2506 public: | |
7445 | 2507 class OCTINTERP_API properties : public base_properties |
6874 | 2508 { |
2509 public: | |
2510 void set_defaults (base_graphics_object& obj, const std::string& mode); | |
2511 | |
2512 void remove_child (const graphics_handle& h); | |
2513 | |
2514 void delete_children (void); | |
2515 | |
7427 | 2516 const scaler& get_x_scaler (void) const { return sx; } |
2517 const scaler& get_y_scaler (void) const { return sy; } | |
2518 const scaler& get_z_scaler (void) const { return sz; } | |
2519 | |
7447 | 2520 Matrix get_boundingbox (bool internal = false) const; |
7427 | 2521 |
7828
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
2522 void 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
|
2523 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
2524 if (units_is ("normalized")) |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
2525 { |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
2526 update_transform (); |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
2527 base_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
|
2528 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
2529 } |
4739b6a1925c
Implement resize handler mechanism (call resizefcn on figure resize and notify children).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7827
diff
changeset
|
2530 |
7427 | 2531 void update_camera (void); |
2532 void update_aspectratios (void); | |
2533 void update_transform (void) | |
2534 { | |
2535 update_aspectratios (); | |
2536 update_camera (); | |
2537 } | |
2538 | |
7435 | 2539 graphics_xform get_transform (void) const |
2540 { return graphics_xform (x_render, x_render_inv, sx, sy, sz); } | |
2541 | |
2542 Matrix get_transform_matrix (void) const { return x_render; } | |
2543 Matrix get_inverse_transform_matrix (void) const { return x_render_inv; } | |
2544 Matrix get_opengl_matrix_1 (void) const { return x_gl_mat1; } | |
2545 Matrix get_opengl_matrix_2 (void) const { return x_gl_mat2; } | |
2546 Matrix get_transform_zlim (void) const { return x_zlim; } | |
2547 | |
7842
1357bcae6e29
added pixel<->coord transform in axes and use it for display of cursor
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2548 ColumnVector pixel2coord (double px, double py) const |
7855
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2549 { return get_transform ().untransform (px, py, (x_zlim(0)+x_zlim(1))/2); } |
7842
1357bcae6e29
added pixel<->coord transform in axes and use it for display of cursor
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2550 |
1357bcae6e29
added pixel<->coord transform in axes and use it for display of cursor
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2551 ColumnVector coord2pixel (double x, double y, double z) const |
1357bcae6e29
added pixel<->coord transform in axes and use it for display of cursor
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2552 { return get_transform ().transform (x, y, z); } |
1357bcae6e29
added pixel<->coord transform in axes and use it for display of cursor
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2553 |
7855
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2554 void zoom (const Matrix& xl, const Matrix& yl); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2555 void unzoom (void); |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2556 void clear_zoom_stack (void); |
7842
1357bcae6e29
added pixel<->coord transform in axes and use it for display of cursor
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7836
diff
changeset
|
2557 |
7427 | 2558 private: |
2559 scaler sx, sy, sz; | |
2560 Matrix x_render, x_render_inv; | |
2561 Matrix x_gl_mat1, x_gl_mat2; | |
2562 Matrix x_zlim; | |
7855
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2563 std::list<octave_value> zoom_stack; |
7427 | 2564 |
6874 | 2565 // See the genprops.awk script for an explanation of the |
2566 // properties declarations. | |
2567 | |
7363 | 2568 BEGIN_PROPERTIES(axes) |
7427 | 2569 array_property position , default_axes_position () |
7363 | 2570 mutable handle_property title GSO , graphics_handle () |
2571 bool_property box , "on" | |
2572 bool_property key , "off" | |
2573 bool_property keybox , "off" | |
2574 double_property keypos , 1 | |
2575 array_property colororder , default_colororder () | |
2576 array_property dataaspectratio m , Matrix (1, 3, 1.0) | |
2577 radio_property dataaspectratiomode , "{auto}|manual" | |
7379 | 2578 radio_property layer , "{bottom}|top" |
7523
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
2579 row_vector_property xlim mu , default_lim () |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
2580 row_vector_property ylim mu , default_lim () |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
2581 row_vector_property zlim mu , default_lim () |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
2582 row_vector_property clim m , default_lim () |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
2583 row_vector_property alim m , default_lim () |
7363 | 2584 radio_property xlimmode al , "{auto}|manual" |
2585 radio_property ylimmode al , "{auto}|manual" | |
2586 radio_property zlimmode al , "{auto}|manual" | |
2587 radio_property climmode al , "{auto}|manual" | |
7403 | 2588 radio_property alimmode , "{auto}|manual" |
7363 | 2589 mutable handle_property xlabel GSO , graphics_handle () |
2590 mutable handle_property ylabel GSO , graphics_handle () | |
2591 mutable handle_property zlabel GSO , graphics_handle () | |
2592 bool_property xgrid , "off" | |
2593 bool_property ygrid , "off" | |
2594 bool_property zgrid , "off" | |
2595 bool_property xminorgrid , "off" | |
2596 bool_property yminorgrid , "off" | |
2597 bool_property zminorgrid , "off" | |
7523
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
2598 row_vector_property xtick m , Matrix () |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
2599 row_vector_property ytick m , Matrix () |
f2000f1971ab
new row_vector_property class
John W. Eaton <jwe@octave.org>
parents:
7471
diff
changeset
|
2600 row_vector_property ztick m , Matrix () |
7363 | 2601 radio_property xtickmode , "{auto}|manual" |
2602 radio_property ytickmode , "{auto}|manual" | |
2603 radio_property ztickmode , "{auto}|manual" | |
7403 | 2604 bool_property xminortick , "off" |
2605 bool_property yminortick , "off" | |
2606 bool_property zminortick , "off" | |
2607 // FIXME: should be kind of string array | |
7363 | 2608 any_property xticklabel m , "" |
2609 any_property yticklabel m , "" | |
2610 any_property zticklabel m , "" | |
2611 radio_property xticklabelmode , "{auto}|manual" | |
2612 radio_property yticklabelmode , "{auto}|manual" | |
2613 radio_property zticklabelmode , "{auto}|manual" | |
7379 | 2614 color_property color , color_property (color_values (1, 1, 1), radio_values ("none")) |
7363 | 2615 color_property xcolor , color_values (0, 0, 0) |
2616 color_property ycolor , color_values (0, 0, 0) | |
2617 color_property zcolor , color_values (0, 0, 0) | |
7427 | 2618 radio_property xscale alu , "{linear}|log" |
2619 radio_property yscale alu , "{linear}|log" | |
2620 radio_property zscale alu , "{linear}|log" | |
2621 radio_property xdir u , "{normal}|reverse" | |
2622 radio_property ydir u , "{normal}|reverse" | |
2623 radio_property zdir u , "{normal}|reverse" | |
7365 | 2624 radio_property yaxislocation , "{left}|right|zero" |
2625 radio_property xaxislocation , "{bottom}|top|zero" | |
7427 | 2626 array_property view u , Matrix () |
7363 | 2627 radio_property nextplot , "add|replace_children|{replace}" |
7427 | 2628 array_property outerposition , default_axes_outerposition () |
7379 | 2629 radio_property activepositionproperty , "{outerposition}|position" |
2630 radio_property __colorbar__ h , "{none}|north|south|east|west|northoutside|southoutside|eastoutside|westoutside" | |
7403 | 2631 color_property ambientlightcolor , color_values (1, 1, 1) |
2632 array_property cameraposition m , Matrix (1, 3, 0.0) | |
2633 array_property cameratarget m , Matrix (1, 3, 0.0) | |
2634 array_property cameraupvector m , Matrix () | |
2635 double_property cameraviewangle m , 10.0 | |
2636 radio_property camerapositionmode , "{auto}|manual" | |
2637 radio_property cameratargetmode , "{auto}|manual" | |
2638 radio_property cameraupvectormode , "{auto}|manual" | |
2639 radio_property cameraviewanglemode , "{auto}|manual" | |
2640 array_property currentpoint , Matrix (2, 3, 0.0) | |
2641 radio_property drawmode , "{normal}|fast" | |
2642 radio_property fontangle , "{normal}|italic|oblique" | |
2643 string_property fontname , "Helvetica" | |
2644 double_property fontsize , 12 | |
2645 radio_property fontunits , "{points}|normalized|inches|centimeters|pixels" | |
2646 radio_property fontweight , "{normal}|light|demi|bold" | |
7445 | 2647 radio_property gridlinestyle , "-|--|{:}|-.|none" |
7403 | 2648 // FIXME: should be kind of string array |
2649 string_property linestyleorder , "-" | |
2650 double_property linewidth , 0.5 | |
7445 | 2651 radio_property minorgridlinestyle , "-|--|{:}|-.|none" |
7403 | 2652 array_property plotboxaspectratio m , Matrix (1, 3, 1.0) |
2653 radio_property plotboxaspectratiomode , "{auto}|manual" | |
2654 radio_property projection , "{orthographic}|perpective" | |
2655 radio_property tickdir m , "{in}|out" | |
2656 radio_property tickdirmode , "{auto}|manual" | |
2657 array_property ticklength , Matrix (1, 2, 0.1) | |
2658 array_property tightinset r , Matrix (1, 4, 0.0) | |
2659 // FIXME: uicontextmenu should be moved here | |
2660 radio_property units , "{normalized}|inches|centimeters|points|pixels|characters" | |
2661 // hidden properties for transformation computation | |
2662 array_property x_viewtransform h , Matrix (4, 4, 0.0) | |
2663 array_property x_projectiontransform h , Matrix (4, 4, 0.0) | |
2664 array_property x_viewporttransform h , Matrix (4, 4, 0.0) | |
2665 array_property x_normrendertransform h , Matrix (4, 4, 0.0) | |
2666 array_property x_rendertransform h , Matrix (4, 4, 0.0) | |
7189 | 2667 END_PROPERTIES |
6874 | 2668 |
7363 | 2669 protected: |
2670 void init (void) | |
2671 { | |
2672 position.add_constraint (dim_vector (1, 4)); | |
7403 | 2673 position.add_constraint (dim_vector (0, 0)); |
7363 | 2674 outerposition.add_constraint (dim_vector (1, 4)); |
2675 colororder.add_constraint (dim_vector (-1, 3)); | |
2676 dataaspectratio.add_constraint (dim_vector (1, 3)); | |
7403 | 2677 plotboxaspectratio.add_constraint (dim_vector (1, 3)); |
7527
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
2678 xlim.add_constraint (2); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
2679 ylim.add_constraint (2); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
2680 zlim.add_constraint (2); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
2681 clim.add_constraint (2); |
d219e712c20e
make row_vector_property work?
John W. Eaton <jwe@octave.org>
parents:
7526
diff
changeset
|
2682 alim.add_constraint (2); |
7363 | 2683 xtick.add_constraint (dim_vector (1, -1)); |
2684 ytick.add_constraint (dim_vector (1, -1)); | |
2685 ztick.add_constraint (dim_vector (1, -1)); | |
2686 Matrix vw (1, 2, 0); | |
2687 vw(1) = 90; | |
2688 view = vw; | |
2689 view.add_constraint (dim_vector (1, 2)); | |
7403 | 2690 cameraposition.add_constraint (dim_vector (1, 3)); |
2691 Matrix upv (1, 3, 0.0); | |
2692 upv(2) = 1.0; | |
2693 cameraupvector = upv; | |
2694 cameraupvector.add_constraint (dim_vector (1, 3)); | |
2695 currentpoint.add_constraint (dim_vector (2, 3)); | |
2696 ticklength.add_constraint (dim_vector (1, 2)); | |
2697 tightinset.add_constraint (dim_vector (1, 4)); | |
7427 | 2698 |
2699 x_zlim.resize (1, 2); | |
2700 sx = "linear"; | |
2701 sy = "linear"; | |
2702 sz = "linear"; | |
7363 | 2703 } |
7427 | 2704 |
2705 private: | |
2706 void update_xscale (void) { sx = get_xscale (); } | |
2707 void update_yscale (void) { sy = get_yscale (); } | |
2708 void update_zscale (void) { sz = get_zscale (); } | |
2709 | |
2710 void update_view (void) { update_camera (); } | |
2711 | |
2712 void update_xdir (void) { update_camera (); } | |
2713 void update_ydir (void) { update_camera (); } | |
2714 void update_zdir (void) { update_camera (); } | |
7446 | 2715 |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7826
diff
changeset
|
2716 double calc_tick_sep (double minval, double maxval); |
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7826
diff
changeset
|
2717 void calc_ticks_and_lims (array_property& lims, array_property& ticks, bool limmode_is_auto); |
7854
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2718 void fix_limits (array_property& lims) |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2719 { |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2720 if (lims.get ().is_empty ()) |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2721 return; |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2722 |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2723 Matrix l = lims.get ().matrix_value (); |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2724 if (l(0) > l(1)) |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2725 { |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2726 l(0) = 0; |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2727 l(1) = 1; |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2728 lims = l; |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2729 } |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2730 else if (l(0) == l(1)) |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2731 { |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2732 l(0) -= 0.5; |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2733 l(1) += 0.5; |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2734 lims = l; |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2735 } |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2736 } |
7446 | 2737 |
2738 public: | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7826
diff
changeset
|
2739 Matrix get_axis_limits (double xmin, double xmax, double min_pos, bool logscale); |
7855
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2740 |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2741 void update_xlim (bool do_clr_zoom = true) |
7446 | 2742 { |
2743 if (xtickmode.is ("auto")) | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7826
diff
changeset
|
2744 calc_ticks_and_lims (xlim, xtick, xlimmode.is ("auto")); |
7855
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2745 |
7854
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2746 fix_limits (xlim); |
7855
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2747 |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2748 if (do_clr_zoom) |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2749 zoom_stack.clear (); |
7446 | 2750 } |
2751 | |
7855
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2752 void update_ylim (bool do_clr_zoom = true) |
7446 | 2753 { |
2754 if (ytickmode.is ("auto")) | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7826
diff
changeset
|
2755 calc_ticks_and_lims (ylim, ytick, ylimmode.is ("auto")); |
7854
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2756 |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2757 fix_limits (ylim); |
7855
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2758 |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2759 if (do_clr_zoom) |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2760 zoom_stack.clear (); |
7446 | 2761 } |
2762 | |
2763 void update_zlim (void) | |
2764 { | |
2765 if (ztickmode.is ("auto")) | |
7827
3584f37eac69
better tick and limit handling, still missing logscale support
Shai Ayal <shaiay@sourceforge.net>
parents:
7826
diff
changeset
|
2766 calc_ticks_and_lims (zlim, ztick, zlimmode.is ("auto")); |
7854
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2767 |
228858e69bd1
added {x,y,z}lim sanity check
Shai Ayal <shaiay@users.sourceforge.net>
parents:
7850
diff
changeset
|
2768 fix_limits (zlim); |
7855
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2769 |
f317f14516cb
Add zoom stack facility in axes object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7854
diff
changeset
|
2770 zoom_stack.clear (); |
7446 | 2771 } |
2772 | |
6874 | 2773 }; |
2774 | |
2775 private: | |
2776 properties xproperties; | |
2777 | |
2778 public: | |
2779 axes (const graphics_handle& mh, const graphics_handle& p) | |
2780 : base_graphics_object (), xproperties (mh, p), default_properties () | |
2781 { | |
2782 xproperties.override_defaults (*this); | |
7830
61aee739a4da
Make sure to initialize axes xform data.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7829
diff
changeset
|
2783 xproperties.update_transform (); |
6874 | 2784 } |
2785 | |
2786 ~axes (void) { xproperties.delete_children (); } | |
2787 | |
2788 void override_defaults (base_graphics_object& obj) | |
2789 { | |
2790 // Allow parent (figure) to override first (properties knows how | |
2791 // to find the parent object). | |
2792 xproperties.override_defaults (obj); | |
2793 | |
2794 // Now override with our defaults. If the default_properties | |
2795 // list includes the properties for all defaults (line, | |
2796 // surface, etc.) then we don't have to know the type of OBJ | |
2797 // here, we just call its set function and let it decide which | |
2798 // properties from the list to use. | |
2799 obj.set_from_list (default_properties); | |
2800 } | |
2801 | |
7189 | 2802 void set (const caseless_str& name, const octave_value& value) |
6874 | 2803 { |
2804 if (name.compare ("default", 7)) | |
2805 // strip "default", pass rest to function that will | |
2806 // parse the remainder and add the element to the | |
2807 // default_properties map. | |
2808 default_properties.set (name.substr (7), value); | |
2809 else | |
2810 xproperties.set (name, value); | |
2811 } | |
2812 | |
2813 void set_defaults (const std::string& mode) | |
2814 { | |
2815 xproperties.set_defaults (*this, mode); | |
2816 } | |
2817 | |
7189 | 2818 octave_value get (const caseless_str& name) const |
6874 | 2819 { |
2820 octave_value retval; | |
2821 | |
2822 // FIXME -- finish this. | |
2823 if (name.compare ("default", 7)) | |
2824 retval = get_default (name.substr (7)); | |
2825 else | |
2826 retval = xproperties.get (name); | |
2827 | |
2828 return retval; | |
2829 } | |
2830 | |
7189 | 2831 octave_value get_default (const caseless_str& name) const; |
6874 | 2832 |
2833 octave_value get_defaults (void) const | |
2834 { | |
2835 return default_properties.as_struct ("default"); | |
2836 } | |
2837 | |
2838 base_properties& get_properties (void) { return xproperties; } | |
2839 | |
7222 | 2840 const base_properties& get_properties (void) const { return xproperties; } |
2841 | |
7214 | 2842 void update_axis_limits (const std::string& axis_type); |
2843 | |
6874 | 2844 bool valid_object (void) const { return true; } |
2845 | |
2846 private: | |
2847 property_list default_properties; | |
2848 }; | |
2849 | |
2850 // --------------------------------------------------------------------- | |
2851 | |
7365 | 2852 class OCTINTERP_API line : public base_graphics_object |
6874 | 2853 { |
2854 public: | |
7821
f79dcba526a8
Export nested properties classes of all graphics object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7527
diff
changeset
|
2855 class OCTINTERP_API properties : public base_properties |
6874 | 2856 { |
2857 public: | |
2858 // See the genprops.awk script for an explanation of the | |
2859 // properties declarations. | |
2860 | |
7366 | 2861 // properties which are not in matlab: |
7384 | 2862 // ldata, udata, xldata, xudata, keylabel, interpreter |
7366 | 2863 |
7363 | 2864 BEGIN_PROPERTIES(line) |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2865 row_vector_property xdata l , default_data () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2866 row_vector_property ydata l , default_data () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2867 row_vector_property zdata l , Matrix () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2868 row_vector_property ldata l , Matrix () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2869 row_vector_property udata l , Matrix () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2870 row_vector_property xldata l , Matrix () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2871 row_vector_property xudata l , Matrix () |
7363 | 2872 color_property color , color_values (0, 0, 0) |
2873 radio_property linestyle , "{-}|--|:|-.|none" | |
2874 double_property linewidth , 0.5 | |
2875 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" | |
2876 color_property markeredgecolor , "{auto}|none" | |
2877 color_property markerfacecolor , "auto|{none}" | |
2878 double_property markersize , 6 | |
2879 string_property keylabel , "" | |
7384 | 2880 radio_property interpreter , "{tex}|none|latex" |
7377 | 2881 string_property displayname , "" |
7380 | 2882 radio_property erasemode , "{normal}|none|xor|background" |
6874 | 2883 END_PROPERTIES |
2884 }; | |
2885 | |
2886 private: | |
2887 properties xproperties; | |
2888 | |
2889 public: | |
2890 line (const graphics_handle& mh, const graphics_handle& p) | |
2891 : base_graphics_object (), xproperties (mh, p) | |
2892 { | |
2893 xproperties.override_defaults (*this); | |
2894 } | |
2895 | |
2896 ~line (void) { xproperties.delete_children (); } | |
2897 | |
2898 base_properties& get_properties (void) { return xproperties; } | |
2899 | |
7222 | 2900 const base_properties& get_properties (void) const { return xproperties; } |
2901 | |
6874 | 2902 bool valid_object (void) const { return true; } |
2903 }; | |
2904 | |
2905 // --------------------------------------------------------------------- | |
2906 | |
7365 | 2907 class OCTINTERP_API text : public base_graphics_object |
6874 | 2908 { |
2909 public: | |
7821
f79dcba526a8
Export nested properties classes of all graphics object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7527
diff
changeset
|
2910 class OCTINTERP_API properties : public base_properties |
6874 | 2911 { |
2912 public: | |
2913 // See the genprops.awk script for an explanation of the | |
2914 // properties declarations. | |
2915 | |
7363 | 2916 BEGIN_PROPERTIES(text) |
2917 string_property string , "" | |
2918 radio_property units , "{data}|pixels|normalized|inches|centimeters|points" | |
2919 array_property position , Matrix (1, 3, 0.0) | |
2920 double_property rotation , 0 | |
2921 radio_property horizontalalignment , "{left}|center|right" | |
2922 color_property color , color_values (0, 0, 0) | |
2923 string_property fontname , "Helvetica" | |
2924 double_property fontsize , 10 | |
7379 | 2925 radio_property fontangle , "{normal}|italic|oblique" |
2926 radio_property fontweight , "light|{normal}|demi|bold" | |
2927 radio_property interpreter , "{tex}|none|latex" | |
7377 | 2928 color_property backgroundcolor , "{none}" |
2929 string_property displayname , "" | |
2930 color_property edgecolor , "{none}" | |
7380 | 2931 radio_property erasemode , "{normal}|none|xor|background" |
7377 | 2932 bool_property editing , "off" |
2933 radio_property fontunits , "inches|centimeters|normalized|{points}|pixel" | |
2934 radio_property linestyle , "{-}|--|:|-.|none" | |
2935 double_property linewidth , 0.5 | |
2936 double_property margin , 1 | |
2937 radio_property verticalalignment , "top|cap|{middle}|baseline|bottom" | |
6874 | 2938 END_PROPERTIES |
2939 | |
7363 | 2940 protected: |
2941 void init (void) | |
2942 { | |
2943 position.add_constraint (dim_vector (1, 3)); | |
2944 } | |
6874 | 2945 }; |
2946 | |
2947 private: | |
2948 properties xproperties; | |
2949 | |
2950 public: | |
2951 text (const graphics_handle& mh, const graphics_handle& p) | |
2952 : base_graphics_object (), xproperties (mh, p) | |
2953 { | |
2954 xproperties.override_defaults (*this); | |
2955 } | |
2956 | |
2957 ~text (void) { xproperties.delete_children (); } | |
2958 | |
2959 base_properties& get_properties (void) { return xproperties; } | |
2960 | |
7222 | 2961 const base_properties& get_properties (void) const { return xproperties; } |
2962 | |
6874 | 2963 bool valid_object (void) const { return true; } |
2964 }; | |
2965 | |
2966 // --------------------------------------------------------------------- | |
2967 | |
7365 | 2968 class OCTINTERP_API image : public base_graphics_object |
6874 | 2969 { |
2970 public: | |
7821
f79dcba526a8
Export nested properties classes of all graphics object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7527
diff
changeset
|
2971 class OCTINTERP_API properties : public base_properties |
6874 | 2972 { |
2973 public: | |
2974 // See the genprops.awk script for an explanation of the | |
2975 // properties declarations. | |
2976 | |
7363 | 2977 BEGIN_PROPERTIES(image) |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2978 row_vector_property xdata l , Matrix () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2979 row_vector_property ydata l , Matrix () |
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
|
2980 array_property cdata l , Matrix () |
7471
86ba621332ff
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
7447
diff
changeset
|
2981 radio_property cdatamapping a , "{scaled}|direct" |
6874 | 2982 END_PROPERTIES |
2983 | |
7363 | 2984 protected: |
2985 void init (void) | |
2986 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2987 xdata.add_constraint (2); |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
2988 ydata.add_constraint (2); |
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
|
2989 cdata.add_constraint ("double"); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2990 cdata.add_constraint ("uint8"); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2991 cdata.add_constraint (dim_vector (-1, -1)); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
2992 cdata.add_constraint (dim_vector (-1, -1, 3)); |
7363 | 2993 } |
6874 | 2994 }; |
2995 | |
2996 private: | |
2997 properties xproperties; | |
2998 | |
2999 public: | |
3000 image (const graphics_handle& mh, const graphics_handle& p) | |
3001 : base_graphics_object (), xproperties (mh, p) | |
3002 { | |
3003 xproperties.override_defaults (*this); | |
3004 } | |
3005 | |
3006 ~image (void) { xproperties.delete_children (); } | |
3007 | |
3008 base_properties& get_properties (void) { return xproperties; } | |
3009 | |
7222 | 3010 const base_properties& get_properties (void) const { return xproperties; } |
3011 | |
6874 | 3012 bool valid_object (void) const { return true; } |
3013 }; | |
3014 | |
3015 // --------------------------------------------------------------------- | |
3016 | |
7365 | 3017 class OCTINTERP_API patch : public base_graphics_object |
6874 | 3018 { |
3019 public: | |
7821
f79dcba526a8
Export nested properties classes of all graphics object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7527
diff
changeset
|
3020 class OCTINTERP_API properties : public base_properties |
6874 | 3021 { |
3022 public: | |
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:
7832
diff
changeset
|
3023 octave_value 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:
7832
diff
changeset
|
3024 |
6874 | 3025 // See the genprops.awk script for an explanation of the |
3026 // properties declarations. | |
3027 | |
7363 | 3028 BEGIN_PROPERTIES(patch) |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3029 array_property xdata l , Matrix () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3030 array_property ydata l , Matrix () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3031 array_property zdata l , Matrix () |
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
|
3032 array_property cdata l , Matrix () |
7379 | 3033 radio_property cdatamapping , "{scaled}|direct" |
7363 | 3034 array_property faces , Matrix () |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3035 array_property facevertexalphadata , Matrix () |
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
|
3036 array_property facevertexcdata , Matrix () |
7363 | 3037 array_property vertices , Matrix () |
7368 | 3038 array_property vertexnormals , Matrix () |
7379 | 3039 radio_property normalmode , "{auto}|manual" |
3040 color_property facecolor , "{flat}|none|interp" | |
7844
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7842
diff
changeset
|
3041 double_radio_property facealpha , double_radio_property (1.0, radio_values ("flat|interp")) |
7832
e06fdf7ea647
Fix default value of patch::facelighting. Add scaler/graphics_xform utilities
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7830
diff
changeset
|
3042 radio_property facelighting , "flat|{none}|gouraud|phong" |
7379 | 3043 color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
7846
d7737a4268b7
Fix typos in property names (edgealpha/facealpha).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7844
diff
changeset
|
3044 double_radio_property edgealpha , double_radio_property (1.0, radio_values ("flat|interp")) |
7379 | 3045 radio_property edgelighting , "{none}|flat|gouraud|phong" |
3046 radio_property backfacelighting , "{reverselit}|unlit|lit" | |
7368 | 3047 double_property ambientstrength , 0.3 |
3048 double_property diffusestrength , 0.6 | |
3049 double_property specularstrength , 0.6 | |
3050 double_property specularexponent , 10.0 | |
3051 double_property specularcolorreflectance , 1.0 | |
7379 | 3052 radio_property erasemode , "{normal}|background|xor|none" |
7363 | 3053 radio_property linestyle , "{-}|--|:|-.|none" |
3054 double_property linewidth , 0.5 | |
3055 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" | |
3056 color_property markeredgecolor , "{auto}|none" | |
3057 color_property markerfacecolor , "auto|{none}" | |
3058 double_property markersize , 6 | |
3059 string_property keylabel , "" | |
7384 | 3060 radio_property interpreter , "{tex}|none|latex" |
6874 | 3061 END_PROPERTIES |
3062 | |
7363 | 3063 protected: |
3064 void init (void) | |
3065 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3066 xdata.add_constraint (dim_vector (-1, -1)); |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3067 ydata.add_constraint (dim_vector (-1, -1)); |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3068 zdata.add_constraint (dim_vector (-1, -1)); |
7363 | 3069 vertices.add_constraint (dim_vector (-1, 2)); |
3070 vertices.add_constraint (dim_vector (-1, 3)); | |
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
|
3071 cdata.add_constraint (dim_vector (-1, -1)); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
3072 cdata.add_constraint (dim_vector (-1, -1, 3)); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
3073 facevertexcdata.add_constraint (dim_vector (-1, 1)); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
3074 facevertexcdata.add_constraint (dim_vector (-1, 3)); |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3075 facevertexalphadata.add_constraint (dim_vector (-1, 1)); |
7363 | 3076 } |
6874 | 3077 }; |
3078 | |
3079 private: | |
3080 properties xproperties; | |
3081 | |
3082 public: | |
3083 patch (const graphics_handle& mh, const graphics_handle& p) | |
3084 : base_graphics_object (), xproperties (mh, p) | |
3085 { | |
3086 xproperties.override_defaults (*this); | |
3087 } | |
3088 | |
3089 ~patch (void) { xproperties.delete_children (); } | |
3090 | |
3091 base_properties& get_properties (void) { return xproperties; } | |
3092 | |
7222 | 3093 const base_properties& get_properties (void) const { return xproperties; } |
3094 | |
6874 | 3095 bool valid_object (void) const { return true; } |
3096 }; | |
3097 | |
3098 // --------------------------------------------------------------------- | |
3099 | |
7365 | 3100 class OCTINTERP_API surface : public base_graphics_object |
6874 | 3101 { |
3102 public: | |
7821
f79dcba526a8
Export nested properties classes of all graphics object.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7527
diff
changeset
|
3103 class OCTINTERP_API properties : public base_properties |
6874 | 3104 { |
3105 public: | |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3106 octave_value 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
|
3107 |
6874 | 3108 // See the genprops.awk script for an explanation of the |
3109 // properties declarations. | |
3110 | |
7363 | 3111 BEGIN_PROPERTIES(surface) |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3112 array_property xdata lu , Matrix () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3113 array_property ydata lu , Matrix () |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3114 array_property zdata lu , Matrix () |
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
|
3115 array_property cdata l , Matrix () |
7471
86ba621332ff
Implement cdatamapping and respect to to allow correct image/imagesc rendering
David Bateman <dbateman@free.fr>
parents:
7447
diff
changeset
|
3116 radio_property cdatamapping a , "{scaled}|direct" |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3117 color_property facecolor , "{flat}|none|interp|texturemap" |
7846
d7737a4268b7
Fix typos in property names (edgealpha/facealpha).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7844
diff
changeset
|
3118 double_radio_property facealpha , double_radio_property (1.0, radio_values ("flat|interp")) |
7379 | 3119 color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
7363 | 3120 radio_property linestyle , "{-}|--|:|-.|none" |
3121 double_property linewidth , 0.5 | |
3122 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" | |
3123 color_property markeredgecolor , "{auto}|none" | |
3124 color_property markerfacecolor , "auto|{none}" | |
3125 double_property markersize , 6 | |
3126 string_property keylabel , "" | |
7384 | 3127 radio_property interpreter , "{tex}|none|latex" |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3128 array_property alphadata , Matrix () |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3129 radio_property alphadatamapping , "none|direct|{scaled}" |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3130 double_property ambientstrength , 0.3 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3131 radio_property backfacelighting , "unlit|lit|{reverselit}" |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3132 double_property diffusestrength , 0.6 |
7846
d7737a4268b7
Fix typos in property names (edgealpha/facealpha).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7844
diff
changeset
|
3133 double_radio_property edgealpha , double_radio_property (1.0, radio_values ("flat|interp")) |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3134 radio_property edgelighting , "{none}|flat|gouraud|phong" |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3135 radio_property erasemode , "{normal}|none|xor|background" |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3136 radio_property facelighting , "{none}|flat|gouraud|phong" |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3137 radio_property meshstyle , "{both}|row|column" |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3138 radio_property normalmode u , "{auto}|manual" |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3139 double_property specularcolorreflectance , 1 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3140 double_property specularexponent , 10 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3141 double_property specularstrength , 0.9 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3142 array_property vertexnormals u , Matrix () |
6874 | 3143 END_PROPERTIES |
3144 | |
7363 | 3145 protected: |
3146 void init (void) | |
3147 { | |
7848
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3148 xdata.add_constraint (dim_vector (-1, -1)); |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3149 ydata.add_constraint (dim_vector (-1, -1)); |
6bb2bbc2bf45
Remove data_property, replace with array_property or row_vector_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7847
diff
changeset
|
3150 zdata.add_constraint (dim_vector (-1, -1)); |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3151 alphadata.add_constraint ("double"); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3152 alphadata.add_constraint ("uint8"); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3153 alphadata.add_constraint (dim_vector (-1, -1)); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3154 vertexnormals.add_constraint (dim_vector (-1, -1, 3)); |
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
|
3155 cdata.add_constraint ("double"); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
3156 cdata.add_constraint ("uint8"); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
3157 cdata.add_constraint (dim_vector (-1, -1)); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7835
diff
changeset
|
3158 cdata.add_constraint (dim_vector (-1, -1, 3)); |
7363 | 3159 } |
7829
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3160 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3161 private: |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3162 void update_normals (void); |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3163 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3164 void update_xdata (void) { update_normals (); } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3165 void update_ydata (void) { update_normals (); } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3166 void update_zdata (void) { update_normals (); } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3167 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3168 void update_normalmode (void) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3169 { update_normals (); } |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3170 |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3171 void update_vertexnormals (void) |
8ca8e97e8c0a
Add rendering interface for surface object (no implementation yet).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7828
diff
changeset
|
3172 { set_normalmode ("manual"); } |
6874 | 3173 }; |
3174 | |
3175 private: | |
3176 properties xproperties; | |
3177 | |
3178 public: | |
3179 surface (const graphics_handle& mh, const graphics_handle& p) | |
3180 : base_graphics_object (), xproperties (mh, p) | |
3181 { | |
3182 xproperties.override_defaults (*this); | |
3183 } | |
3184 | |
3185 ~surface (void) { xproperties.delete_children (); } | |
3186 | |
3187 base_properties& get_properties (void) { return xproperties; } | |
3188 | |
7222 | 3189 const base_properties& get_properties (void) const { return xproperties; } |
3190 | |
6874 | 3191 bool valid_object (void) const { return true; } |
3192 }; | |
3193 | |
3194 octave_value | |
3195 get_property_from_handle (double handle, const std::string &property, | |
3196 const std::string &func); | |
3197 bool | |
3198 set_property_in_handle (double handle, const std::string &property, | |
3199 const octave_value &arg, const std::string &func); | |
3200 | |
3201 // --------------------------------------------------------------------- | |
3202 | |
7365 | 3203 class OCTINTERP_API gh_manager |
6874 | 3204 { |
3205 protected: | |
3206 | |
3207 gh_manager (void); | |
3208 | |
3209 public: | |
3210 | |
3211 static bool instance_ok (void) | |
3212 { | |
3213 bool retval = true; | |
3214 | |
3215 if (! instance) | |
3216 instance = new gh_manager (); | |
3217 | |
3218 if (! instance) | |
3219 { | |
3220 ::error ("unable to create gh_manager!"); | |
3221 | |
3222 retval = false; | |
3223 } | |
3224 | |
3225 return retval; | |
3226 } | |
3227 | |
3228 static void free (const graphics_handle& h) | |
3229 { | |
3230 if (instance_ok ()) | |
3231 instance->do_free (h); | |
3232 } | |
3233 | |
3234 static graphics_handle lookup (double val) | |
3235 { | |
3236 return instance_ok () ? instance->do_lookup (val) : graphics_handle (); | |
3237 } | |
3238 | |
3239 static graphics_object get_object (const graphics_handle& h) | |
3240 { | |
3241 return instance_ok () ? instance->do_get_object (h) : graphics_object (); | |
3242 } | |
3243 | |
3244 static graphics_handle | |
3245 make_graphics_handle (const std::string& go_name, | |
7370 | 3246 const graphics_handle& parent, bool do_createfcn = true) |
6874 | 3247 { |
3248 return instance_ok () | |
7370 | 3249 ? instance->do_make_graphics_handle (go_name, parent, do_createfcn) |
6874 | 3250 : graphics_handle (); |
3251 } | |
3252 | |
3253 static graphics_handle make_figure_handle (double val) | |
3254 { | |
3255 return instance_ok () | |
3256 ? instance->do_make_figure_handle (val) : graphics_handle (); | |
3257 } | |
3258 | |
3259 static void push_figure (const graphics_handle& h) | |
3260 { | |
3261 if (instance_ok ()) | |
3262 instance->do_push_figure (h); | |
3263 } | |
3264 | |
3265 static void pop_figure (const graphics_handle& h) | |
3266 { | |
3267 if (instance_ok ()) | |
3268 instance->do_pop_figure (h); | |
3269 } | |
3270 | |
3271 static graphics_handle current_figure (void) | |
3272 { | |
3273 return instance_ok () | |
3274 ? instance->do_current_figure () : graphics_handle (); | |
3275 } | |
3276 | |
3277 static Matrix handle_list (void) | |
3278 { | |
3279 return instance_ok () ? instance->do_handle_list () : Matrix (); | |
3280 } | |
3281 | |
3282 static Matrix figure_handle_list (void) | |
3283 { | |
3284 return instance_ok () ? instance->do_figure_handle_list () : Matrix (); | |
3285 } | |
3286 | |
3287 private: | |
3288 | |
3289 static gh_manager *instance; | |
3290 | |
3291 typedef std::map<graphics_handle, graphics_object>::iterator iterator; | |
3292 typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator; | |
3293 | |
3294 typedef std::set<graphics_handle>::iterator free_list_iterator; | |
3295 typedef std::set<graphics_handle>::const_iterator const_free_list_iterator; | |
3296 | |
3297 typedef std::list<graphics_handle>::iterator figure_list_iterator; | |
3298 typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator; | |
3299 | |
3300 // A map of handles to graphics objects. | |
3301 std::map<graphics_handle, graphics_object> handle_map; | |
3302 | |
3303 // The available graphics handles. | |
3304 std::set<graphics_handle> handle_free_list; | |
3305 | |
3306 // The next handle available if handle_free_list is empty. | |
7286 | 3307 double next_handle; |
6874 | 3308 |
3309 // The allocated figure handles. Top of the stack is most recently | |
3310 // created. | |
3311 std::list<graphics_handle> figure_list; | |
3312 | |
3313 graphics_handle get_handle (const std::string& go_name); | |
3314 | |
3315 void do_free (const graphics_handle& h); | |
3316 | |
3317 graphics_handle do_lookup (double val) | |
3318 { | |
7363 | 3319 iterator p = (xisnan (val) ? handle_map.end () : handle_map.find (val)); |
6874 | 3320 |
3321 return (p != handle_map.end ()) ? p->first : graphics_handle (); | |
3322 } | |
3323 | |
3324 graphics_object do_get_object (const graphics_handle& h) | |
3325 { | |
7379 | 3326 iterator p = (h.ok () ? handle_map.find (h) : handle_map.end ()); |
6874 | 3327 |
3328 return (p != handle_map.end ()) ? p->second : graphics_object (); | |
3329 } | |
3330 | |
3331 graphics_handle do_make_graphics_handle (const std::string& go_name, | |
7370 | 3332 const graphics_handle& p, bool do_createfcn); |
6874 | 3333 |
3334 graphics_handle do_make_figure_handle (double val); | |
3335 | |
3336 Matrix do_handle_list (void) | |
3337 { | |
3338 Matrix retval (1, handle_map.size ()); | |
3339 octave_idx_type i = 0; | |
3340 for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++) | |
7056 | 3341 { |
3342 graphics_handle h = p->first; | |
3343 retval(i++) = h.value (); | |
3344 } | |
6874 | 3345 return retval; |
3346 } | |
3347 | |
3348 Matrix do_figure_handle_list (void) | |
3349 { | |
3350 Matrix retval (1, figure_list.size ()); | |
3351 octave_idx_type i = 0; | |
3352 for (const_figure_list_iterator p = figure_list.begin (); | |
3353 p != figure_list.end (); | |
3354 p++) | |
7056 | 3355 { |
3356 graphics_handle h = *p; | |
3357 retval(i++) = h.value (); | |
3358 } | |
6874 | 3359 return retval; |
3360 } | |
3361 | |
3362 void do_push_figure (const graphics_handle& h); | |
3363 | |
3364 void do_pop_figure (const graphics_handle& h); | |
3365 | |
3366 graphics_handle do_current_figure (void) const | |
3367 { | |
3368 return figure_list.empty () ? graphics_handle () : figure_list.front (); | |
3369 } | |
3370 }; | |
3371 | |
3372 | |
3373 // This function is NOT equivalent to the scripting language function gcf. | |
7365 | 3374 OCTINTERP_API graphics_handle gcf (void); |
6874 | 3375 |
3376 // This function is NOT equivalent to the scripting language function gca. | |
7365 | 3377 OCTINTERP_API graphics_handle gca (void); |
6874 | 3378 |
3379 #endif | |
3380 | |
3381 /* | |
3382 ;;; Local Variables: *** | |
3383 ;;; mode: C++ *** | |
3384 ;;; End: *** | |
3385 */ |