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