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