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