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