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