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 |
|
1277 std::string get_clipping (void) const { return clipping.current_value (); } |
|
1278 |
7367
|
1279 void execute_createfcn (const octave_value& data = octave_value ()) const |
|
1280 { createfcn.execute (data); } |
|
1281 |
7366
|
1282 octave_value get_createfcn (void) const { return createfcn.get (); } |
|
1283 |
7367
|
1284 void execute_deletefcn (const octave_value& data = octave_value ()) const |
|
1285 { deletefcn.execute (data); } |
|
1286 |
7366
|
1287 octave_value get_deletefcn (void) const { return deletefcn.get (); } |
|
1288 |
|
1289 std::string get_handlevisibility (void) const { return handlevisibility.current_value (); } |
|
1290 |
|
1291 std::string get_hittest (void) const { return hittest.current_value (); } |
|
1292 |
|
1293 std::string get_interruptible (void) const { return interruptible.current_value (); } |
|
1294 |
|
1295 std::string get_selected (void) const { return selected.current_value (); } |
|
1296 |
|
1297 std::string get_selectionhighlight (void) const { return selectionhighlight.current_value (); } |
|
1298 |
|
1299 octave_value get_uicontextmenu (void) const { return uicontextmenu.get (); } |
|
1300 |
|
1301 octave_value get_userdata (void) const { return userdata.get (); } |
7408
|
1302 |
|
1303 bool is_visible (void) const { return visible.is_on (); } |
7366
|
1304 std::string get_visible (void) const { return visible.current_value (); } |
|
1305 |
7403
|
1306 bool is_beingdeleted (void) const { return beingdeleted.is_on (); } |
|
1307 std::string get_beingdeleted (void) const { return beingdeleted.current_value (); } |
|
1308 |
7386
|
1309 virtual void remove_child (const graphics_handle& h); |
|
1310 |
|
1311 virtual void adopt (const graphics_handle& h) |
6874
|
1312 { |
|
1313 octave_idx_type n = children.numel (); |
|
1314 children.resize (1, n+1); |
7056
|
1315 children(n) = h.value (); |
6874
|
1316 } |
|
1317 |
7419
|
1318 virtual graphics_backend get_backend (void) const; |
|
1319 |
7363
|
1320 void set_tag (const octave_value& val) { tag = val; } |
7176
|
1321 |
6874
|
1322 void set_parent (const octave_value& val); |
|
1323 |
7408
|
1324 void set_modified (const octave_value& val) { __modified__ = val; } |
|
1325 |
7366
|
1326 void set_busyaction (const octave_value& val) |
|
1327 { |
|
1328 if (! error_state) |
|
1329 { |
|
1330 busyaction = val; |
|
1331 mark_modified (); |
|
1332 } |
|
1333 } |
|
1334 |
|
1335 void set_buttondownfcn (const octave_value& val) |
|
1336 { |
|
1337 if (! error_state) |
|
1338 { |
|
1339 buttondownfcn = val; |
|
1340 mark_modified (); |
|
1341 } |
|
1342 } |
|
1343 |
|
1344 void set_clipping (const octave_value& val) |
|
1345 { |
|
1346 if (! error_state) |
|
1347 { |
|
1348 clipping = val; |
|
1349 mark_modified (); |
|
1350 } |
|
1351 } |
|
1352 |
|
1353 void set_createfcn (const octave_value& val) |
|
1354 { |
|
1355 if (! error_state) |
|
1356 { |
|
1357 createfcn = val; |
|
1358 mark_modified (); |
|
1359 } |
|
1360 } |
|
1361 |
|
1362 void set_deletefcn (const octave_value& val) |
|
1363 { |
|
1364 if (! error_state) |
|
1365 { |
|
1366 deletefcn = val; |
|
1367 mark_modified (); |
|
1368 } |
|
1369 } |
|
1370 |
|
1371 void set_handlevisibility (const octave_value& val) |
|
1372 { |
|
1373 if (! error_state) |
|
1374 { |
|
1375 handlevisibility = val; |
|
1376 mark_modified (); |
|
1377 } |
|
1378 } |
|
1379 |
|
1380 void set_hittest (const octave_value& val) |
|
1381 { |
|
1382 if (! error_state) |
|
1383 { |
|
1384 hittest = val; |
|
1385 mark_modified (); |
|
1386 } |
|
1387 } |
|
1388 |
|
1389 void set_interruptible (const octave_value& val) |
|
1390 { |
|
1391 if (! error_state) |
|
1392 { |
|
1393 interruptible = val; |
|
1394 mark_modified (); |
|
1395 } |
|
1396 } |
|
1397 |
|
1398 void set_selected (const octave_value& val) |
|
1399 { |
|
1400 if (! error_state) |
|
1401 { |
|
1402 selected = val; |
|
1403 mark_modified (); |
|
1404 } |
|
1405 } |
|
1406 |
|
1407 void set_selectionhighlight (const octave_value& val) |
|
1408 { |
|
1409 if (! error_state) |
|
1410 { |
|
1411 selectionhighlight = val; |
|
1412 mark_modified (); |
|
1413 } |
|
1414 } |
|
1415 |
|
1416 void set_uicontextmenu (const octave_value& val) |
|
1417 { |
|
1418 if (! error_state) |
|
1419 { |
|
1420 uicontextmenu = val; |
|
1421 mark_modified (); |
|
1422 } |
|
1423 } |
|
1424 |
|
1425 void set_userdata (const octave_value& val) |
|
1426 { |
|
1427 if (! error_state) |
|
1428 { |
|
1429 userdata = val; |
|
1430 mark_modified (); |
|
1431 } |
|
1432 } |
|
1433 |
|
1434 virtual void set_visible (const octave_value& val) |
|
1435 { |
|
1436 if (! error_state) |
|
1437 { |
|
1438 visible = val; |
|
1439 mark_modified (); |
|
1440 } |
|
1441 } |
|
1442 |
7403
|
1443 void set_beingdeleted (const octave_value& val) |
|
1444 { |
|
1445 if (! error_state) |
|
1446 { |
|
1447 beingdeleted = val; |
|
1448 mark_modified (); |
|
1449 } |
|
1450 } |
|
1451 |
7366
|
1452 |
|
1453 |
6874
|
1454 void reparent (const graphics_handle& new_parent) { parent = new_parent; } |
|
1455 |
7214
|
1456 // Update data limits for AXIS_TYPE (xdata, ydata, etc.) in the parent |
|
1457 // axes object. |
|
1458 |
7386
|
1459 virtual void update_axis_limits (const std::string& axis_type) const; |
7214
|
1460 |
6874
|
1461 virtual void delete_children (void); |
|
1462 |
7222
|
1463 Matrix get_children (void) const { return children; } |
|
1464 |
|
1465 // FIXME -- these functions should be generated automatically by the |
|
1466 // genprops.awk script. |
|
1467 // |
|
1468 // EMIT_BASE_PROPERTIES_GET_FUNCTIONS |
7363
|
1469 virtual data_property get_xdata_property (void) const |
7222
|
1470 { |
|
1471 error ("get: invalid property \"xdata\""); |
|
1472 return data_property (); |
|
1473 } |
|
1474 |
7363
|
1475 virtual data_property get_ydata_property (void) const |
7222
|
1476 { |
|
1477 error ("get: invalid property \"ydata\""); |
|
1478 return data_property (); |
|
1479 } |
|
1480 |
7363
|
1481 virtual data_property get_zdata_property (void) const |
7222
|
1482 { |
|
1483 error ("get: invalid property \"zdata\""); |
|
1484 return data_property (); |
|
1485 } |
|
1486 |
7363
|
1487 virtual data_property get_ldata_property (void) const |
7222
|
1488 { |
|
1489 error ("get: invalid property \"ldata\""); |
|
1490 return data_property (); |
|
1491 } |
|
1492 |
7363
|
1493 virtual data_property get_udata_property (void) const |
7222
|
1494 { |
|
1495 error ("get: invalid property \"udata\""); |
|
1496 return data_property (); |
|
1497 } |
|
1498 |
7363
|
1499 virtual data_property get_xldata_property (void) const |
7222
|
1500 { |
|
1501 error ("get: invalid property \"xldata\""); |
|
1502 return data_property (); |
|
1503 } |
|
1504 |
7363
|
1505 virtual data_property get_xudata_property (void) const |
7222
|
1506 { |
|
1507 error ("get: invalid property \"xudata\""); |
|
1508 return data_property (); |
|
1509 } |
|
1510 |
7363
|
1511 virtual data_property get_cdata_property (void) const |
7222
|
1512 { |
|
1513 error ("get: invalid property \"cdata\""); |
|
1514 return data_property (); |
|
1515 } |
|
1516 |
6874
|
1517 protected: |
7403
|
1518 // properties common to all objects |
|
1519 bool_property beingdeleted; |
|
1520 radio_property busyaction; |
|
1521 callback_property buttondownfcn; |
7363
|
1522 // FIXME: use a property class for children |
6874
|
1523 Matrix children; |
7366
|
1524 bool_property clipping; |
|
1525 callback_property createfcn; |
|
1526 callback_property deletefcn; |
|
1527 radio_property handlevisibility; |
|
1528 bool_property hittest; |
|
1529 bool_property interruptible; |
7403
|
1530 handle_property parent; |
7366
|
1531 bool_property selected; |
|
1532 bool_property selectionhighlight; |
7403
|
1533 string_property tag; |
|
1534 string_property type; |
7366
|
1535 any_property userdata; |
|
1536 bool_property visible; |
7403
|
1537 // additional (octave-specific) properties |
|
1538 bool_property __modified__; |
|
1539 graphics_handle __myhandle__; |
|
1540 // FIXME: should this really be here? |
|
1541 handle_property uicontextmenu; |
7363
|
1542 |
|
1543 protected: |
|
1544 std::map<caseless_str, property> all_props; |
|
1545 |
|
1546 protected: |
|
1547 void insert_static_property (const std::string& name, base_property& p) |
|
1548 { insert_property (name, property (&p, true)); } |
|
1549 |
|
1550 virtual void init (void) { } |
6874
|
1551 }; |
|
1552 |
7365
|
1553 class OCTINTERP_API base_graphics_object |
6874
|
1554 { |
|
1555 public: |
|
1556 friend class graphics_object; |
|
1557 |
|
1558 base_graphics_object (void) : count (1) { } |
|
1559 |
|
1560 base_graphics_object (const base_graphics_object&) { } |
|
1561 |
|
1562 virtual ~base_graphics_object (void) { } |
|
1563 |
|
1564 virtual void mark_modified (void) |
|
1565 { |
7386
|
1566 if (valid_object ()) |
|
1567 get_properties ().mark_modified (); |
|
1568 else |
|
1569 error ("base_graphics_object::mark_modified: invalid graphics object"); |
6874
|
1570 } |
|
1571 |
7386
|
1572 virtual void override_defaults (base_graphics_object& obj) |
6874
|
1573 { |
7386
|
1574 if (valid_object ()) |
|
1575 get_properties ().override_defaults (obj); |
|
1576 else |
|
1577 error ("base_graphics_object::override_defaults: invalid graphics object"); |
6874
|
1578 } |
|
1579 |
7386
|
1580 virtual void set_from_list (property_list& plist) |
6874
|
1581 { |
7386
|
1582 if (valid_object ()) |
|
1583 get_properties ().set_from_list (*this, plist); |
|
1584 else |
|
1585 error ("base_graphics_object::set_from_list: invalid graphics object"); |
6874
|
1586 } |
|
1587 |
7386
|
1588 virtual void set (const caseless_str& pname, const octave_value& pval) |
6874
|
1589 { |
7386
|
1590 if (valid_object ()) |
|
1591 get_properties ().set (pname, pval); |
|
1592 else |
|
1593 error ("base_graphics_object::set: invalid graphics object"); |
6874
|
1594 } |
|
1595 |
|
1596 virtual void set_defaults (const std::string&) |
|
1597 { |
|
1598 error ("base_graphics_object::set_defaults: invalid graphics object"); |
|
1599 } |
|
1600 |
7379
|
1601 virtual octave_value get (bool all = false) const |
6874
|
1602 { |
7386
|
1603 if (valid_object ()) |
|
1604 return get_properties ().get (all); |
|
1605 else |
|
1606 { |
|
1607 error ("base_graphics_object::get: invalid graphics object"); |
|
1608 return octave_value (); |
|
1609 } |
6874
|
1610 } |
|
1611 |
7386
|
1612 virtual octave_value get (const caseless_str& pname) const |
6874
|
1613 { |
7386
|
1614 if (valid_object ()) |
|
1615 return get_properties ().get (pname); |
|
1616 else |
|
1617 { |
|
1618 error ("base_graphics_object::get: invalid graphics object"); |
|
1619 return octave_value (); |
|
1620 } |
6874
|
1621 } |
|
1622 |
7189
|
1623 virtual octave_value get_default (const caseless_str&) const; |
6874
|
1624 |
7189
|
1625 virtual octave_value get_factory_default (const caseless_str&) const; |
6874
|
1626 |
|
1627 virtual octave_value get_defaults (void) const |
|
1628 { |
|
1629 error ("base_graphics_object::get_defaults: invalid graphics object"); |
|
1630 return octave_value (); |
|
1631 } |
|
1632 |
|
1633 virtual octave_value get_factory_defaults (void) const |
|
1634 { |
|
1635 error ("base_graphics_object::get_factory_defaults: invalid graphics object"); |
|
1636 return octave_value (); |
|
1637 } |
|
1638 |
|
1639 virtual graphics_handle get_parent (void) const |
|
1640 { |
7386
|
1641 if (valid_object ()) |
|
1642 return get_properties ().get_parent (); |
|
1643 else |
|
1644 { |
|
1645 error ("base_graphics_object::get_parent: invalid graphics object"); |
|
1646 return graphics_handle (); |
|
1647 } |
6874
|
1648 } |
|
1649 |
7386
|
1650 virtual void remove_child (const graphics_handle& h) |
6874
|
1651 { |
7386
|
1652 if (valid_object ()) |
|
1653 get_properties ().remove_child (h); |
|
1654 else |
|
1655 error ("base_graphics_object::remove_child: invalid graphics object"); |
6874
|
1656 } |
|
1657 |
7386
|
1658 virtual void adopt (const graphics_handle& h) |
6874
|
1659 { |
7386
|
1660 if (valid_object ()) |
|
1661 get_properties ().adopt (h); |
|
1662 else |
|
1663 error ("base_graphics_object::adopt: invalid graphics object"); |
6874
|
1664 } |
|
1665 |
7386
|
1666 virtual void reparent (const graphics_handle& np) |
6874
|
1667 { |
7386
|
1668 if (valid_object ()) |
|
1669 get_properties ().reparent (np); |
|
1670 else |
|
1671 error ("base_graphics_object::reparent: invalid graphics object"); |
6874
|
1672 } |
|
1673 |
|
1674 virtual void defaults (void) const |
|
1675 { |
7386
|
1676 if (valid_object ()) |
|
1677 { |
|
1678 std::string msg = (type () + "::defaults"); |
|
1679 gripe_not_implemented (msg.c_str ()); |
|
1680 } |
|
1681 else |
|
1682 error ("base_graphics_object::default: invalid graphics object"); |
6874
|
1683 } |
|
1684 |
|
1685 virtual base_properties& get_properties (void) |
|
1686 { |
|
1687 static base_properties properties; |
|
1688 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
1689 return properties; |
|
1690 } |
|
1691 |
7222
|
1692 virtual const base_properties& get_properties (void) const |
|
1693 { |
|
1694 static base_properties properties; |
|
1695 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
1696 return properties; |
|
1697 } |
|
1698 |
|
1699 virtual void update_axis_limits (const std::string&) |
7214
|
1700 { |
|
1701 error ("base_graphics_object::update_axis_limits: invalid graphics object"); |
|
1702 } |
|
1703 |
6874
|
1704 virtual bool valid_object (void) const { return false; } |
|
1705 |
7386
|
1706 virtual std::string type (void) const |
|
1707 { |
|
1708 return (valid_object () ? get_properties ().graphics_object_name () |
|
1709 : "unknown"); |
|
1710 } |
6874
|
1711 |
|
1712 bool isa (const std::string& go_name) const |
|
1713 { |
|
1714 return type () == go_name; |
|
1715 } |
|
1716 |
7419
|
1717 virtual graphics_backend get_backend (void) const |
|
1718 { |
|
1719 if (valid_object ()) |
|
1720 return get_properties ().get_backend (); |
|
1721 else |
|
1722 { |
|
1723 error ("base_graphics_object::get_backend: invalid graphics object"); |
|
1724 return graphics_backend (); |
|
1725 } |
|
1726 } |
|
1727 |
6874
|
1728 protected: |
|
1729 // A reference count. |
|
1730 int count; |
|
1731 }; |
|
1732 |
7365
|
1733 class OCTINTERP_API graphics_object |
6874
|
1734 { |
|
1735 public: |
|
1736 graphics_object (void) : rep (new base_graphics_object ()) { } |
|
1737 |
|
1738 graphics_object (base_graphics_object *new_rep) |
|
1739 : rep (new_rep) { } |
|
1740 |
|
1741 graphics_object (const graphics_object& obj) |
|
1742 { |
|
1743 rep = obj.rep; |
|
1744 rep->count++; |
|
1745 } |
|
1746 |
|
1747 graphics_object& operator = (const graphics_object& obj) |
|
1748 { |
|
1749 if (rep != obj.rep) |
|
1750 { |
|
1751 if (--rep->count == 0) |
|
1752 delete rep; |
|
1753 |
|
1754 rep = obj.rep; |
|
1755 rep->count++; |
|
1756 } |
|
1757 |
|
1758 return *this; |
|
1759 } |
|
1760 |
|
1761 ~graphics_object (void) |
|
1762 { |
|
1763 if (--rep->count == 0) |
|
1764 delete rep; |
|
1765 } |
|
1766 |
|
1767 void mark_modified (void) { rep->mark_modified (); } |
|
1768 |
|
1769 void override_defaults (base_graphics_object& obj) |
|
1770 { |
|
1771 rep->override_defaults (obj); |
|
1772 } |
|
1773 |
7214
|
1774 void set_from_list (property_list& plist) { rep->set_from_list (plist); } |
6874
|
1775 |
7189
|
1776 void set (const caseless_str& name, const octave_value& val) |
6874
|
1777 { |
|
1778 rep->set (name, val); |
|
1779 } |
|
1780 |
|
1781 void set (const octave_value_list& args); |
|
1782 |
7214
|
1783 void set_defaults (const std::string& mode) { rep->set_defaults (mode); } |
|
1784 |
7379
|
1785 octave_value get (bool all = false) const { return rep->get (all); } |
6874
|
1786 |
7189
|
1787 octave_value get (const caseless_str& name) const |
6874
|
1788 { |
|
1789 return name.compare ("default") |
|
1790 ? get_defaults () |
|
1791 : (name.compare ("factory") |
|
1792 ? get_factory_defaults () : rep->get (name)); |
|
1793 } |
|
1794 |
7189
|
1795 octave_value get_default (const caseless_str& name) const |
6874
|
1796 { |
|
1797 return rep->get_default (name); |
|
1798 } |
|
1799 |
7189
|
1800 octave_value get_factory_default (const caseless_str& name) const |
6874
|
1801 { |
|
1802 return rep->get_factory_default (name); |
|
1803 } |
|
1804 |
|
1805 octave_value get_defaults (void) const { return rep->get_defaults (); } |
|
1806 |
|
1807 octave_value get_factory_defaults (void) const |
|
1808 { |
|
1809 return rep->get_factory_defaults (); |
|
1810 } |
|
1811 |
|
1812 graphics_handle get_parent (void) const { return rep->get_parent (); } |
|
1813 |
7214
|
1814 void remove_child (const graphics_handle& h) { rep->remove_child (h); } |
|
1815 |
|
1816 void adopt (const graphics_handle& h) { rep->adopt (h); } |
|
1817 |
|
1818 void reparent (const graphics_handle& h) { rep->reparent (h); } |
6874
|
1819 |
|
1820 void defaults (void) const { rep->defaults (); } |
|
1821 |
|
1822 bool isa (const std::string& go_name) const { return rep->isa (go_name); } |
|
1823 |
|
1824 base_properties& get_properties (void) { return rep->get_properties (); } |
|
1825 |
7222
|
1826 const base_properties& get_properties (void) const |
|
1827 { |
|
1828 return rep->get_properties (); |
|
1829 } |
|
1830 |
7214
|
1831 void update_axis_limits (const std::string& axis_type) |
|
1832 { |
|
1833 rep->update_axis_limits (axis_type); |
|
1834 } |
|
1835 |
6874
|
1836 bool valid_object (void) const { return rep->valid_object (); } |
|
1837 |
|
1838 operator bool (void) const { return rep->valid_object (); } |
|
1839 |
7222
|
1840 // FIXME -- these functions should be generated automatically by the |
|
1841 // genprops.awk script. |
|
1842 // |
|
1843 // EMIT_GRAPHICS_OBJECT_GET_FUNCTIONS |
7363
|
1844 data_property get_xdata_property (void) const |
7222
|
1845 { |
|
1846 const base_properties& props = get_properties (); |
7363
|
1847 return props.get_xdata_property (); |
7222
|
1848 } |
|
1849 |
7363
|
1850 data_property get_ydata_property (void) const |
7222
|
1851 { |
|
1852 const base_properties& props = get_properties (); |
7363
|
1853 return props.get_ydata_property (); |
7222
|
1854 } |
|
1855 |
7363
|
1856 data_property get_zdata_property (void) const |
7222
|
1857 { |
|
1858 const base_properties& props = get_properties (); |
7363
|
1859 return props.get_zdata_property (); |
7222
|
1860 } |
|
1861 |
7363
|
1862 data_property get_ldata_property (void) const |
7222
|
1863 { |
|
1864 const base_properties& props = get_properties (); |
7363
|
1865 return props.get_ldata_property (); |
7222
|
1866 } |
|
1867 |
7363
|
1868 data_property get_udata_property (void) const |
7222
|
1869 { |
|
1870 const base_properties& props = get_properties (); |
7363
|
1871 return props.get_udata_property (); |
7222
|
1872 } |
|
1873 |
7363
|
1874 data_property get_xldata_property (void) const |
7222
|
1875 { |
|
1876 const base_properties& props = get_properties (); |
7363
|
1877 return props.get_xldata_property (); |
7222
|
1878 } |
|
1879 |
7363
|
1880 data_property get_xudata_property (void) const |
7222
|
1881 { |
|
1882 const base_properties& props = get_properties (); |
7363
|
1883 return props.get_xudata_property (); |
7222
|
1884 } |
|
1885 |
7363
|
1886 data_property get_cdata_property (void) const |
7222
|
1887 { |
|
1888 const base_properties& props = get_properties (); |
7363
|
1889 return props.get_cdata_property (); |
7222
|
1890 } |
|
1891 |
7419
|
1892 graphics_backend get_backend (void) const { return rep->get_backend (); } |
7408
|
1893 |
|
1894 private: |
7419
|
1895 base_graphics_object *rep; |
7408
|
1896 }; |
|
1897 |
|
1898 // --------------------------------------------------------------------- |
|
1899 |
7365
|
1900 class OCTINTERP_API root_figure : public base_graphics_object |
6874
|
1901 { |
|
1902 public: |
|
1903 class properties : public base_properties |
|
1904 { |
|
1905 public: |
|
1906 // See the genprops.awk script for an explanation of the |
|
1907 // properties declarations. |
|
1908 |
7363
|
1909 BEGIN_PROPERTIES(root_figure) |
|
1910 handle_property currentfigure S , graphics_handle () |
6874
|
1911 END_PROPERTIES |
|
1912 }; |
|
1913 |
|
1914 private: |
|
1915 properties xproperties; |
|
1916 |
|
1917 public: |
|
1918 |
7363
|
1919 root_figure (void) : xproperties (0, graphics_handle ()), default_properties () { } |
6874
|
1920 |
|
1921 ~root_figure (void) { xproperties.delete_children (); } |
|
1922 |
|
1923 void mark_modified (void) { } |
|
1924 |
|
1925 void override_defaults (base_graphics_object& obj) |
|
1926 { |
|
1927 // Now override with our defaults. If the default_properties |
|
1928 // list includes the properties for all defaults (line, |
|
1929 // surface, etc.) then we don't have to know the type of OBJ |
|
1930 // here, we just call its set function and let it decide which |
|
1931 // properties from the list to use. |
|
1932 obj.set_from_list (default_properties); |
|
1933 } |
|
1934 |
7189
|
1935 void set (const caseless_str& name, const octave_value& value) |
6874
|
1936 { |
|
1937 if (name.compare ("default", 7)) |
|
1938 // strip "default", pass rest to function that will |
|
1939 // parse the remainder and add the element to the |
|
1940 // default_properties map. |
|
1941 default_properties.set (name.substr (7), value); |
|
1942 else |
|
1943 xproperties.set (name, value); |
|
1944 } |
|
1945 |
7189
|
1946 octave_value get (const caseless_str& name) const |
6874
|
1947 { |
|
1948 octave_value retval; |
|
1949 |
|
1950 if (name.compare ("default", 7)) |
|
1951 return get_default (name.substr (7)); |
|
1952 else if (name.compare ("factory", 7)) |
|
1953 return get_factory_default (name.substr (7)); |
|
1954 else |
|
1955 retval = xproperties.get (name); |
|
1956 |
|
1957 return retval; |
|
1958 } |
|
1959 |
7189
|
1960 octave_value get_default (const caseless_str& name) const |
6874
|
1961 { |
|
1962 octave_value retval = default_properties.lookup (name); |
|
1963 |
|
1964 if (retval.is_undefined ()) |
|
1965 error ("get: invalid default property `%s'", name.c_str ()); |
|
1966 |
|
1967 return retval; |
|
1968 } |
|
1969 |
7189
|
1970 octave_value get_factory_default (const caseless_str& name) const |
6874
|
1971 { |
|
1972 octave_value retval = factory_properties.lookup (name); |
|
1973 |
|
1974 if (retval.is_undefined ()) |
|
1975 error ("get: invalid factory default property `%s'", name.c_str ()); |
|
1976 |
|
1977 return retval; |
|
1978 } |
|
1979 |
|
1980 octave_value get_defaults (void) const |
|
1981 { |
|
1982 return default_properties.as_struct ("default"); |
|
1983 } |
|
1984 |
|
1985 octave_value get_factory_defaults (void) const |
|
1986 { |
|
1987 return factory_properties.as_struct ("factory"); |
|
1988 } |
|
1989 |
|
1990 base_properties& get_properties (void) { return xproperties; } |
|
1991 |
7222
|
1992 const base_properties& get_properties (void) const { return xproperties; } |
|
1993 |
6874
|
1994 bool valid_object (void) const { return true; } |
|
1995 |
|
1996 private: |
|
1997 property_list default_properties; |
|
1998 |
|
1999 static property_list factory_properties; |
|
2000 |
|
2001 static property_list::plist_map_type init_factory_properties (void); |
|
2002 }; |
|
2003 |
|
2004 // --------------------------------------------------------------------- |
|
2005 |
7365
|
2006 class OCTINTERP_API figure : public base_graphics_object |
6874
|
2007 { |
|
2008 public: |
|
2009 class properties : public base_properties |
|
2010 { |
|
2011 public: |
7408
|
2012 void close (bool pop = true); |
|
2013 |
7366
|
2014 void set_visible (const octave_value& val); |
6874
|
2015 |
7408
|
2016 graphics_backend get_backend (void) const |
|
2017 { |
|
2018 if (! backend) |
|
2019 backend = graphics_backend::default_backend (); |
|
2020 |
|
2021 return backend; |
|
2022 } |
|
2023 |
|
2024 void set_backend (const graphics_backend& b) { backend = b; } |
|
2025 |
6874
|
2026 // See the genprops.awk script for an explanation of the |
|
2027 // properties declarations. |
|
2028 |
7363
|
2029 BEGIN_PROPERTIES(figure) |
7379
|
2030 any_property __plot_stream__ h , Matrix () |
|
2031 bool_property __enhanced__ h , "on" |
7405
|
2032 radio_property nextplot , "new|{add}|replace_children|replace" |
7363
|
2033 callback_property closerequestfcn , "closereq" |
|
2034 handle_property currentaxes S , graphics_handle () |
|
2035 array_property colormap , jet_colormap () |
7405
|
2036 radio_property paperorientation , "{portrait}|landscape|rotated" |
7363
|
2037 color_property color , color_values (1, 1, 1) |
7405
|
2038 array_property alphamap , Matrix (64, 1, 1) |
|
2039 string_property currentcharacter r , "" |
|
2040 handle_property currentobject r , graphics_handle () |
|
2041 array_property current_point r , Matrix (2, 1, 0) |
|
2042 bool_property dockcontrols , "off" |
|
2043 bool_property doublebuffer , "on" |
|
2044 string_property filename r , "" |
|
2045 bool_property integerhandle , "on" |
|
2046 bool_property inverthardcopy , "off" |
|
2047 callback_property keypressfcn , Matrix () |
|
2048 callback_property keyreleasefcn , Matrix () |
|
2049 radio_property menubar , "none|{figure}" |
|
2050 double_property mincolormap , 64 |
|
2051 string_property name , "" |
|
2052 bool_property numbertitle , "on" |
|
2053 radio_property paperunits , "{inches}|centimeters|normalized|points" |
|
2054 array_property paperposition , Matrix (1, 4 , 0) |
|
2055 radio_property paperpositionmode , "auto|{manual}" |
|
2056 array_property papersize r , Matrix (1, 4, 0) |
|
2057 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" |
|
2058 radio_property pointer , "crosshair|fullcrosshair|{arrow}|ibeam|watch|topl|topr|botl|botr|left|top|right|bottom|circle|cross|fleur|custom|hand" |
|
2059 array_property pointershapecdata , Matrix (16, 16, 0) |
|
2060 array_property pointershapehotspot , Matrix (1, 2, 0) |
|
2061 array_property position , Matrix (1, 4, 0) |
|
2062 radio_property renderer , "{painters}|zbuffer|opengl|none" |
|
2063 radio_property renderermode , "{auto}|manual" |
|
2064 bool_property resize , "on" |
|
2065 callback_property resizefcn , Matrix () |
|
2066 radio_property selectiontype , "{normal}|open|alt|extend" |
|
2067 radio_property toolbar , "none|{auto}|figure" |
|
2068 radio_property units , "inches|centimeters|normalized|points|{pixels}|characters" |
|
2069 callback_property windowbuttondownfcn , Matrix () |
|
2070 callback_property windowbuttonmotionfcn , Matrix () |
|
2071 callback_property windowbuttonupfcn , Matrix () |
|
2072 callback_property windowbuttonwheelfcn , Matrix () |
|
2073 radio_property windowstyle , "{normal}|modal|docked" |
|
2074 string_property wvisual , "" |
|
2075 radio_property wvisualmode , "{auto}|manual" |
|
2076 string_property xdisplay , "" |
|
2077 string_property xvisual , "" |
|
2078 radio_property xvisualmode , "{auto}|manual" |
|
2079 callback_property buttondownfcn , Matrix () |
6874
|
2080 END_PROPERTIES |
7363
|
2081 |
|
2082 protected: |
|
2083 void init (void) |
|
2084 { |
|
2085 colormap.add_constraint (dim_vector (-1, 3)); |
7406
|
2086 alphamap.add_constraint (dim_vector (-1, 1)); |
|
2087 paperposition.add_constraint (dim_vector (1, 4)); |
|
2088 pointershapecdata.add_constraint (dim_vector (16, 16)); |
|
2089 pointershapehotspot.add_constraint (dim_vector (1, 2)); |
|
2090 position.add_constraint (dim_vector (1, 4)); |
7363
|
2091 } |
7408
|
2092 |
|
2093 private: |
|
2094 mutable graphics_backend backend; |
6874
|
2095 }; |
|
2096 |
|
2097 private: |
|
2098 properties xproperties; |
|
2099 |
|
2100 public: |
|
2101 figure (const graphics_handle& mh, const graphics_handle& p) |
|
2102 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
2103 { |
|
2104 xproperties.override_defaults (*this); |
|
2105 } |
|
2106 |
|
2107 ~figure (void) |
|
2108 { |
7386
|
2109 xproperties.delete_children (); |
6874
|
2110 xproperties.close (); |
|
2111 } |
|
2112 |
|
2113 void override_defaults (base_graphics_object& obj) |
|
2114 { |
|
2115 // Allow parent (root figure) to override first (properties knows how |
|
2116 // to find the parent object). |
|
2117 xproperties.override_defaults (obj); |
|
2118 |
|
2119 // Now override with our defaults. If the default_properties |
|
2120 // list includes the properties for all defaults (line, |
|
2121 // surface, etc.) then we don't have to know the type of OBJ |
|
2122 // here, we just call its set function and let it decide which |
|
2123 // properties from the list to use. |
|
2124 obj.set_from_list (default_properties); |
|
2125 } |
|
2126 |
7189
|
2127 void set (const caseless_str& name, const octave_value& value) |
6874
|
2128 { |
|
2129 if (name.compare ("default", 7)) |
|
2130 // strip "default", pass rest to function that will |
|
2131 // parse the remainder and add the element to the |
|
2132 // default_properties map. |
|
2133 default_properties.set (name.substr (7), value); |
|
2134 else |
|
2135 xproperties.set (name, value); |
|
2136 } |
|
2137 |
7189
|
2138 octave_value get (const caseless_str& name) const |
6874
|
2139 { |
|
2140 octave_value retval; |
|
2141 |
|
2142 if (name.compare ("default", 7)) |
|
2143 retval = get_default (name.substr (7)); |
|
2144 else |
|
2145 retval = xproperties.get (name); |
|
2146 |
|
2147 return retval; |
|
2148 } |
|
2149 |
7189
|
2150 octave_value get_default (const caseless_str& name) const; |
6874
|
2151 |
|
2152 octave_value get_defaults (void) const |
|
2153 { |
|
2154 return default_properties.as_struct ("default"); |
|
2155 } |
|
2156 |
|
2157 base_properties& get_properties (void) { return xproperties; } |
|
2158 |
7222
|
2159 const base_properties& get_properties (void) const { return xproperties; } |
|
2160 |
6874
|
2161 bool valid_object (void) const { return true; } |
|
2162 |
|
2163 private: |
|
2164 property_list default_properties; |
|
2165 }; |
|
2166 |
|
2167 // --------------------------------------------------------------------- |
|
2168 |
7365
|
2169 class OCTINTERP_API axes : public base_graphics_object |
6874
|
2170 { |
|
2171 public: |
|
2172 class properties : public base_properties |
|
2173 { |
|
2174 public: |
|
2175 void set_defaults (base_graphics_object& obj, const std::string& mode); |
|
2176 |
|
2177 void remove_child (const graphics_handle& h); |
|
2178 |
|
2179 void delete_children (void); |
|
2180 |
7427
|
2181 const scaler& get_x_scaler (void) const { return sx; } |
|
2182 const scaler& get_y_scaler (void) const { return sy; } |
|
2183 const scaler& get_z_scaler (void) const { return sz; } |
|
2184 |
|
2185 Matrix get_boundingbox (void) const; |
|
2186 |
|
2187 void update_camera (void); |
|
2188 void update_aspectratios (void); |
|
2189 void update_transform (void) |
|
2190 { |
|
2191 update_aspectratios (); |
|
2192 update_camera (); |
|
2193 } |
|
2194 |
|
2195 private: |
|
2196 scaler sx, sy, sz; |
|
2197 Matrix x_render, x_render_inv; |
|
2198 Matrix x_gl_mat1, x_gl_mat2; |
|
2199 Matrix x_zlim; |
|
2200 |
6874
|
2201 // See the genprops.awk script for an explanation of the |
|
2202 // properties declarations. |
|
2203 |
7363
|
2204 BEGIN_PROPERTIES(axes) |
7427
|
2205 array_property position , default_axes_position () |
7363
|
2206 mutable handle_property title GSO , graphics_handle () |
|
2207 bool_property box , "on" |
|
2208 bool_property key , "off" |
|
2209 bool_property keybox , "off" |
|
2210 double_property keypos , 1 |
|
2211 array_property colororder , default_colororder () |
|
2212 array_property dataaspectratio m , Matrix (1, 3, 1.0) |
|
2213 radio_property dataaspectratiomode , "{auto}|manual" |
7379
|
2214 radio_property layer , "{bottom}|top" |
7363
|
2215 array_property xlim m , default_lim () |
|
2216 array_property ylim m , default_lim () |
|
2217 array_property zlim m , default_lim () |
|
2218 array_property clim m , default_lim () |
7403
|
2219 array_property alim m , default_lim () |
7363
|
2220 radio_property xlimmode al , "{auto}|manual" |
|
2221 radio_property ylimmode al , "{auto}|manual" |
|
2222 radio_property zlimmode al , "{auto}|manual" |
|
2223 radio_property climmode al , "{auto}|manual" |
7403
|
2224 radio_property alimmode , "{auto}|manual" |
7363
|
2225 mutable handle_property xlabel GSO , graphics_handle () |
|
2226 mutable handle_property ylabel GSO , graphics_handle () |
|
2227 mutable handle_property zlabel GSO , graphics_handle () |
|
2228 bool_property xgrid , "off" |
|
2229 bool_property ygrid , "off" |
|
2230 bool_property zgrid , "off" |
|
2231 bool_property xminorgrid , "off" |
|
2232 bool_property yminorgrid , "off" |
|
2233 bool_property zminorgrid , "off" |
|
2234 array_property xtick m , Matrix () |
|
2235 array_property ytick m , Matrix () |
|
2236 array_property ztick m , Matrix () |
|
2237 radio_property xtickmode , "{auto}|manual" |
|
2238 radio_property ytickmode , "{auto}|manual" |
|
2239 radio_property ztickmode , "{auto}|manual" |
7403
|
2240 bool_property xminortick , "off" |
|
2241 bool_property yminortick , "off" |
|
2242 bool_property zminortick , "off" |
|
2243 // FIXME: should be kind of string array |
7363
|
2244 any_property xticklabel m , "" |
|
2245 any_property yticklabel m , "" |
|
2246 any_property zticklabel m , "" |
|
2247 radio_property xticklabelmode , "{auto}|manual" |
|
2248 radio_property yticklabelmode , "{auto}|manual" |
|
2249 radio_property zticklabelmode , "{auto}|manual" |
7379
|
2250 color_property color , color_property (color_values (1, 1, 1), radio_values ("none")) |
7363
|
2251 color_property xcolor , color_values (0, 0, 0) |
|
2252 color_property ycolor , color_values (0, 0, 0) |
|
2253 color_property zcolor , color_values (0, 0, 0) |
7427
|
2254 radio_property xscale alu , "{linear}|log" |
|
2255 radio_property yscale alu , "{linear}|log" |
|
2256 radio_property zscale alu , "{linear}|log" |
|
2257 radio_property xdir u , "{normal}|reverse" |
|
2258 radio_property ydir u , "{normal}|reverse" |
|
2259 radio_property zdir u , "{normal}|reverse" |
7365
|
2260 radio_property yaxislocation , "{left}|right|zero" |
|
2261 radio_property xaxislocation , "{bottom}|top|zero" |
7427
|
2262 array_property view u , Matrix () |
7363
|
2263 radio_property nextplot , "add|replace_children|{replace}" |
7427
|
2264 array_property outerposition , default_axes_outerposition () |
7379
|
2265 radio_property activepositionproperty , "{outerposition}|position" |
|
2266 radio_property __colorbar__ h , "{none}|north|south|east|west|northoutside|southoutside|eastoutside|westoutside" |
7403
|
2267 color_property ambientlightcolor , color_values (1, 1, 1) |
|
2268 array_property cameraposition m , Matrix (1, 3, 0.0) |
|
2269 array_property cameratarget m , Matrix (1, 3, 0.0) |
|
2270 array_property cameraupvector m , Matrix () |
|
2271 double_property cameraviewangle m , 10.0 |
|
2272 radio_property camerapositionmode , "{auto}|manual" |
|
2273 radio_property cameratargetmode , "{auto}|manual" |
|
2274 radio_property cameraupvectormode , "{auto}|manual" |
|
2275 radio_property cameraviewanglemode , "{auto}|manual" |
|
2276 array_property currentpoint , Matrix (2, 3, 0.0) |
|
2277 radio_property drawmode , "{normal}|fast" |
|
2278 radio_property fontangle , "{normal}|italic|oblique" |
|
2279 string_property fontname , "Helvetica" |
|
2280 double_property fontsize , 12 |
|
2281 radio_property fontunits , "{points}|normalized|inches|centimeters|pixels" |
|
2282 radio_property fontweight , "{normal}|light|demi|bold" |
|
2283 radio_property gridlinestyle , "{-}|--|:|-.|none" |
|
2284 // FIXME: should be kind of string array |
|
2285 string_property linestyleorder , "-" |
|
2286 double_property linewidth , 0.5 |
|
2287 radio_property minorgridlinestyle , "{-}|--|:|-.|none" |
|
2288 array_property plotboxaspectratio m , Matrix (1, 3, 1.0) |
|
2289 radio_property plotboxaspectratiomode , "{auto}|manual" |
|
2290 radio_property projection , "{orthographic}|perpective" |
|
2291 radio_property tickdir m , "{in}|out" |
|
2292 radio_property tickdirmode , "{auto}|manual" |
|
2293 array_property ticklength , Matrix (1, 2, 0.1) |
|
2294 array_property tightinset r , Matrix (1, 4, 0.0) |
|
2295 // FIXME: uicontextmenu should be moved here |
|
2296 radio_property units , "{normalized}|inches|centimeters|points|pixels|characters" |
|
2297 // hidden properties for transformation computation |
|
2298 array_property x_viewtransform h , Matrix (4, 4, 0.0) |
|
2299 array_property x_projectiontransform h , Matrix (4, 4, 0.0) |
|
2300 array_property x_viewporttransform h , Matrix (4, 4, 0.0) |
|
2301 array_property x_normrendertransform h , Matrix (4, 4, 0.0) |
|
2302 array_property x_rendertransform h , Matrix (4, 4, 0.0) |
7189
|
2303 END_PROPERTIES |
6874
|
2304 |
7363
|
2305 protected: |
|
2306 void init (void) |
|
2307 { |
|
2308 position.add_constraint (dim_vector (1, 4)); |
7403
|
2309 position.add_constraint (dim_vector (0, 0)); |
7363
|
2310 outerposition.add_constraint (dim_vector (1, 4)); |
|
2311 colororder.add_constraint (dim_vector (-1, 3)); |
|
2312 dataaspectratio.add_constraint (dim_vector (1, 3)); |
7403
|
2313 plotboxaspectratio.add_constraint (dim_vector (1, 3)); |
7363
|
2314 xlim.add_constraint (dim_vector (1, 2)); |
|
2315 ylim.add_constraint (dim_vector (1, 2)); |
|
2316 zlim.add_constraint (dim_vector (1, 2)); |
|
2317 clim.add_constraint (dim_vector (1, 2)); |
7403
|
2318 alim.add_constraint (dim_vector (1, 2)); |
7363
|
2319 xtick.add_constraint (dim_vector (1, -1)); |
|
2320 ytick.add_constraint (dim_vector (1, -1)); |
|
2321 ztick.add_constraint (dim_vector (1, -1)); |
|
2322 Matrix vw (1, 2, 0); |
|
2323 vw(1) = 90; |
|
2324 view = vw; |
|
2325 view.add_constraint (dim_vector (1, 2)); |
7403
|
2326 cameraposition.add_constraint (dim_vector (1, 3)); |
|
2327 Matrix upv (1, 3, 0.0); |
|
2328 upv(2) = 1.0; |
|
2329 cameraupvector = upv; |
|
2330 cameraupvector.add_constraint (dim_vector (1, 3)); |
|
2331 currentpoint.add_constraint (dim_vector (2, 3)); |
|
2332 ticklength.add_constraint (dim_vector (1, 2)); |
|
2333 tightinset.add_constraint (dim_vector (1, 4)); |
7427
|
2334 |
|
2335 x_zlim.resize (1, 2); |
|
2336 sx = "linear"; |
|
2337 sy = "linear"; |
|
2338 sz = "linear"; |
7363
|
2339 } |
7427
|
2340 |
|
2341 private: |
|
2342 void update_xscale (void) { sx = get_xscale (); } |
|
2343 void update_yscale (void) { sy = get_yscale (); } |
|
2344 void update_zscale (void) { sz = get_zscale (); } |
|
2345 |
|
2346 void update_view (void) { update_camera (); } |
|
2347 |
|
2348 void update_xdir (void) { update_camera (); } |
|
2349 void update_ydir (void) { update_camera (); } |
|
2350 void update_zdir (void) { update_camera (); } |
6874
|
2351 }; |
|
2352 |
|
2353 private: |
|
2354 properties xproperties; |
|
2355 |
|
2356 public: |
|
2357 axes (const graphics_handle& mh, const graphics_handle& p) |
|
2358 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
2359 { |
|
2360 xproperties.override_defaults (*this); |
|
2361 } |
|
2362 |
|
2363 ~axes (void) { xproperties.delete_children (); } |
|
2364 |
|
2365 void override_defaults (base_graphics_object& obj) |
|
2366 { |
|
2367 // Allow parent (figure) to override first (properties knows how |
|
2368 // to find the parent object). |
|
2369 xproperties.override_defaults (obj); |
|
2370 |
|
2371 // Now override with our defaults. If the default_properties |
|
2372 // list includes the properties for all defaults (line, |
|
2373 // surface, etc.) then we don't have to know the type of OBJ |
|
2374 // here, we just call its set function and let it decide which |
|
2375 // properties from the list to use. |
|
2376 obj.set_from_list (default_properties); |
|
2377 } |
|
2378 |
7189
|
2379 void set (const caseless_str& name, const octave_value& value) |
6874
|
2380 { |
|
2381 if (name.compare ("default", 7)) |
|
2382 // strip "default", pass rest to function that will |
|
2383 // parse the remainder and add the element to the |
|
2384 // default_properties map. |
|
2385 default_properties.set (name.substr (7), value); |
|
2386 else |
|
2387 xproperties.set (name, value); |
|
2388 } |
|
2389 |
|
2390 void set_defaults (const std::string& mode) |
|
2391 { |
|
2392 xproperties.set_defaults (*this, mode); |
|
2393 } |
|
2394 |
7189
|
2395 octave_value get (const caseless_str& name) const |
6874
|
2396 { |
|
2397 octave_value retval; |
|
2398 |
|
2399 // FIXME -- finish this. |
|
2400 if (name.compare ("default", 7)) |
|
2401 retval = get_default (name.substr (7)); |
|
2402 else |
|
2403 retval = xproperties.get (name); |
|
2404 |
|
2405 return retval; |
|
2406 } |
|
2407 |
7189
|
2408 octave_value get_default (const caseless_str& name) const; |
6874
|
2409 |
|
2410 octave_value get_defaults (void) const |
|
2411 { |
|
2412 return default_properties.as_struct ("default"); |
|
2413 } |
|
2414 |
|
2415 base_properties& get_properties (void) { return xproperties; } |
|
2416 |
7222
|
2417 const base_properties& get_properties (void) const { return xproperties; } |
|
2418 |
7214
|
2419 void update_axis_limits (const std::string& axis_type); |
|
2420 |
6874
|
2421 bool valid_object (void) const { return true; } |
|
2422 |
|
2423 private: |
|
2424 property_list default_properties; |
|
2425 }; |
|
2426 |
|
2427 // --------------------------------------------------------------------- |
|
2428 |
7365
|
2429 class OCTINTERP_API line : public base_graphics_object |
6874
|
2430 { |
|
2431 public: |
|
2432 class properties : public base_properties |
|
2433 { |
|
2434 public: |
|
2435 // See the genprops.awk script for an explanation of the |
|
2436 // properties declarations. |
|
2437 |
7366
|
2438 // properties which are not in matlab: |
7384
|
2439 // ldata, udata, xldata, xudata, keylabel, interpreter |
7366
|
2440 |
7363
|
2441 BEGIN_PROPERTIES(line) |
|
2442 data_property xdata l , default_data () |
|
2443 data_property ydata l , default_data () |
|
2444 data_property zdata l , Matrix () |
|
2445 data_property ldata l , Matrix () |
|
2446 data_property udata l , Matrix () |
|
2447 data_property xldata l , Matrix () |
|
2448 data_property xudata l , Matrix () |
|
2449 color_property color , color_values (0, 0, 0) |
|
2450 radio_property linestyle , "{-}|--|:|-.|none" |
|
2451 double_property linewidth , 0.5 |
|
2452 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2453 color_property markeredgecolor , "{auto}|none" |
|
2454 color_property markerfacecolor , "auto|{none}" |
|
2455 double_property markersize , 6 |
|
2456 string_property keylabel , "" |
7384
|
2457 radio_property interpreter , "{tex}|none|latex" |
7377
|
2458 string_property displayname , "" |
7380
|
2459 radio_property erasemode , "{normal}|none|xor|background" |
6874
|
2460 END_PROPERTIES |
|
2461 }; |
|
2462 |
|
2463 private: |
|
2464 properties xproperties; |
|
2465 |
|
2466 public: |
|
2467 line (const graphics_handle& mh, const graphics_handle& p) |
|
2468 : base_graphics_object (), xproperties (mh, p) |
|
2469 { |
|
2470 xproperties.override_defaults (*this); |
|
2471 } |
|
2472 |
|
2473 ~line (void) { xproperties.delete_children (); } |
|
2474 |
|
2475 base_properties& get_properties (void) { return xproperties; } |
|
2476 |
7222
|
2477 const base_properties& get_properties (void) const { return xproperties; } |
|
2478 |
6874
|
2479 bool valid_object (void) const { return true; } |
|
2480 }; |
|
2481 |
|
2482 // --------------------------------------------------------------------- |
|
2483 |
7365
|
2484 class OCTINTERP_API text : public base_graphics_object |
6874
|
2485 { |
|
2486 public: |
|
2487 class properties : public base_properties |
|
2488 { |
|
2489 public: |
|
2490 // See the genprops.awk script for an explanation of the |
|
2491 // properties declarations. |
|
2492 |
7363
|
2493 BEGIN_PROPERTIES(text) |
|
2494 string_property string , "" |
|
2495 radio_property units , "{data}|pixels|normalized|inches|centimeters|points" |
|
2496 array_property position , Matrix (1, 3, 0.0) |
|
2497 double_property rotation , 0 |
|
2498 radio_property horizontalalignment , "{left}|center|right" |
|
2499 color_property color , color_values (0, 0, 0) |
|
2500 string_property fontname , "Helvetica" |
|
2501 double_property fontsize , 10 |
7379
|
2502 radio_property fontangle , "{normal}|italic|oblique" |
|
2503 radio_property fontweight , "light|{normal}|demi|bold" |
|
2504 radio_property interpreter , "{tex}|none|latex" |
7377
|
2505 color_property backgroundcolor , "{none}" |
|
2506 string_property displayname , "" |
|
2507 color_property edgecolor , "{none}" |
7380
|
2508 radio_property erasemode , "{normal}|none|xor|background" |
7377
|
2509 bool_property editing , "off" |
|
2510 radio_property fontunits , "inches|centimeters|normalized|{points}|pixel" |
|
2511 radio_property linestyle , "{-}|--|:|-.|none" |
|
2512 double_property linewidth , 0.5 |
|
2513 double_property margin , 1 |
|
2514 radio_property verticalalignment , "top|cap|{middle}|baseline|bottom" |
6874
|
2515 END_PROPERTIES |
|
2516 |
7363
|
2517 protected: |
|
2518 void init (void) |
|
2519 { |
|
2520 position.add_constraint (dim_vector (1, 3)); |
|
2521 } |
6874
|
2522 }; |
|
2523 |
|
2524 private: |
|
2525 properties xproperties; |
|
2526 |
|
2527 public: |
|
2528 text (const graphics_handle& mh, const graphics_handle& p) |
|
2529 : base_graphics_object (), xproperties (mh, p) |
|
2530 { |
|
2531 xproperties.override_defaults (*this); |
|
2532 } |
|
2533 |
|
2534 ~text (void) { xproperties.delete_children (); } |
|
2535 |
|
2536 base_properties& get_properties (void) { return xproperties; } |
|
2537 |
7222
|
2538 const base_properties& get_properties (void) const { return xproperties; } |
|
2539 |
6874
|
2540 bool valid_object (void) const { return true; } |
|
2541 }; |
|
2542 |
|
2543 // --------------------------------------------------------------------- |
|
2544 |
7365
|
2545 class OCTINTERP_API image : public base_graphics_object |
6874
|
2546 { |
|
2547 public: |
|
2548 class properties : public base_properties |
|
2549 { |
|
2550 public: |
|
2551 // See the genprops.awk script for an explanation of the |
|
2552 // properties declarations. |
|
2553 |
7363
|
2554 BEGIN_PROPERTIES(image) |
|
2555 data_property xdata l , Matrix () |
|
2556 data_property ydata l , Matrix () |
|
2557 data_property cdata l , Matrix () |
6874
|
2558 END_PROPERTIES |
|
2559 |
7363
|
2560 protected: |
|
2561 void init (void) |
|
2562 { |
|
2563 } |
6874
|
2564 }; |
|
2565 |
|
2566 private: |
|
2567 properties xproperties; |
|
2568 |
|
2569 public: |
|
2570 image (const graphics_handle& mh, const graphics_handle& p) |
|
2571 : base_graphics_object (), xproperties (mh, p) |
|
2572 { |
|
2573 xproperties.override_defaults (*this); |
|
2574 } |
|
2575 |
|
2576 ~image (void) { xproperties.delete_children (); } |
|
2577 |
|
2578 base_properties& get_properties (void) { return xproperties; } |
|
2579 |
7222
|
2580 const base_properties& get_properties (void) const { return xproperties; } |
|
2581 |
6874
|
2582 bool valid_object (void) const { return true; } |
|
2583 }; |
|
2584 |
|
2585 // --------------------------------------------------------------------- |
|
2586 |
7365
|
2587 class OCTINTERP_API patch : public base_graphics_object |
6874
|
2588 { |
|
2589 public: |
|
2590 class properties : public base_properties |
|
2591 { |
|
2592 public: |
|
2593 // See the genprops.awk script for an explanation of the |
|
2594 // properties declarations. |
|
2595 |
7363
|
2596 BEGIN_PROPERTIES(patch) |
7403
|
2597 data_property xdata l , Matrix () |
7363
|
2598 data_property ydata l , Matrix () |
|
2599 data_property zdata l , Matrix () |
|
2600 data_property cdata l , Matrix () |
7379
|
2601 radio_property cdatamapping , "{scaled}|direct" |
7363
|
2602 array_property faces , Matrix () |
7368
|
2603 data_property facevertexalphadata , Matrix () |
|
2604 data_property facevertexcdata , Matrix () |
7363
|
2605 array_property vertices , Matrix () |
7368
|
2606 array_property vertexnormals , Matrix () |
7379
|
2607 radio_property normalmode , "{auto}|manual" |
|
2608 color_property facecolor , "{flat}|none|interp" |
7363
|
2609 double_property facealpha , 1.0 |
7379
|
2610 radio_property facelighting , "{flat}|none|gouraud|phong" |
|
2611 color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
7368
|
2612 double_property edgealpha , 1.0 |
7379
|
2613 radio_property edgelighting , "{none}|flat|gouraud|phong" |
|
2614 radio_property backfacelighting , "{reverselit}|unlit|lit" |
7368
|
2615 double_property ambientstrength , 0.3 |
|
2616 double_property diffusestrength , 0.6 |
|
2617 double_property specularstrength , 0.6 |
|
2618 double_property specularexponent , 10.0 |
|
2619 double_property specularcolorreflectance , 1.0 |
7379
|
2620 radio_property erasemode , "{normal}|background|xor|none" |
7363
|
2621 radio_property linestyle , "{-}|--|:|-.|none" |
|
2622 double_property linewidth , 0.5 |
|
2623 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2624 color_property markeredgecolor , "{auto}|none" |
|
2625 color_property markerfacecolor , "auto|{none}" |
|
2626 double_property markersize , 6 |
|
2627 string_property keylabel , "" |
7384
|
2628 radio_property interpreter , "{tex}|none|latex" |
6874
|
2629 END_PROPERTIES |
|
2630 |
7363
|
2631 protected: |
|
2632 void init (void) |
|
2633 { |
|
2634 vertices.add_constraint (dim_vector (-1, 2)); |
|
2635 vertices.add_constraint (dim_vector (-1, 3)); |
|
2636 } |
6874
|
2637 }; |
|
2638 |
|
2639 private: |
|
2640 properties xproperties; |
|
2641 |
|
2642 public: |
|
2643 patch (const graphics_handle& mh, const graphics_handle& p) |
|
2644 : base_graphics_object (), xproperties (mh, p) |
|
2645 { |
|
2646 xproperties.override_defaults (*this); |
|
2647 } |
|
2648 |
|
2649 ~patch (void) { xproperties.delete_children (); } |
|
2650 |
|
2651 base_properties& get_properties (void) { return xproperties; } |
|
2652 |
7222
|
2653 const base_properties& get_properties (void) const { return xproperties; } |
|
2654 |
6874
|
2655 bool valid_object (void) const { return true; } |
|
2656 }; |
|
2657 |
|
2658 // --------------------------------------------------------------------- |
|
2659 |
7365
|
2660 class OCTINTERP_API surface : public base_graphics_object |
6874
|
2661 { |
|
2662 public: |
|
2663 class properties : public base_properties |
|
2664 { |
|
2665 public: |
|
2666 // See the genprops.awk script for an explanation of the |
|
2667 // properties declarations. |
|
2668 |
7363
|
2669 BEGIN_PROPERTIES(surface) |
|
2670 data_property xdata l , Matrix () |
|
2671 data_property ydata l , Matrix () |
|
2672 data_property zdata l , Matrix () |
|
2673 data_property cdata l , Matrix () |
7379
|
2674 color_property facecolor , "{flat}|none|interp" |
7363
|
2675 double_property facealpha , 1.0 |
7379
|
2676 color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
7363
|
2677 radio_property linestyle , "{-}|--|:|-.|none" |
|
2678 double_property linewidth , 0.5 |
|
2679 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2680 color_property markeredgecolor , "{auto}|none" |
|
2681 color_property markerfacecolor , "auto|{none}" |
|
2682 double_property markersize , 6 |
|
2683 string_property keylabel , "" |
7384
|
2684 radio_property interpreter , "{tex}|none|latex" |
6874
|
2685 END_PROPERTIES |
|
2686 |
7363
|
2687 protected: |
|
2688 void init (void) |
|
2689 { |
|
2690 } |
6874
|
2691 }; |
|
2692 |
|
2693 private: |
|
2694 properties xproperties; |
|
2695 |
|
2696 public: |
|
2697 surface (const graphics_handle& mh, const graphics_handle& p) |
|
2698 : base_graphics_object (), xproperties (mh, p) |
|
2699 { |
|
2700 xproperties.override_defaults (*this); |
|
2701 } |
|
2702 |
|
2703 ~surface (void) { xproperties.delete_children (); } |
|
2704 |
|
2705 base_properties& get_properties (void) { return xproperties; } |
|
2706 |
7222
|
2707 const base_properties& get_properties (void) const { return xproperties; } |
|
2708 |
6874
|
2709 bool valid_object (void) const { return true; } |
|
2710 }; |
|
2711 |
|
2712 octave_value |
|
2713 get_property_from_handle (double handle, const std::string &property, |
|
2714 const std::string &func); |
|
2715 bool |
|
2716 set_property_in_handle (double handle, const std::string &property, |
|
2717 const octave_value &arg, const std::string &func); |
|
2718 |
|
2719 // --------------------------------------------------------------------- |
|
2720 |
7365
|
2721 class OCTINTERP_API gh_manager |
6874
|
2722 { |
|
2723 protected: |
|
2724 |
|
2725 gh_manager (void); |
|
2726 |
|
2727 public: |
|
2728 |
|
2729 static bool instance_ok (void) |
|
2730 { |
|
2731 bool retval = true; |
|
2732 |
|
2733 if (! instance) |
|
2734 instance = new gh_manager (); |
|
2735 |
|
2736 if (! instance) |
|
2737 { |
|
2738 ::error ("unable to create gh_manager!"); |
|
2739 |
|
2740 retval = false; |
|
2741 } |
|
2742 |
|
2743 return retval; |
|
2744 } |
|
2745 |
|
2746 static void free (const graphics_handle& h) |
|
2747 { |
|
2748 if (instance_ok ()) |
|
2749 instance->do_free (h); |
|
2750 } |
|
2751 |
|
2752 static graphics_handle lookup (double val) |
|
2753 { |
|
2754 return instance_ok () ? instance->do_lookup (val) : graphics_handle (); |
|
2755 } |
|
2756 |
|
2757 static graphics_object get_object (const graphics_handle& h) |
|
2758 { |
|
2759 return instance_ok () ? instance->do_get_object (h) : graphics_object (); |
|
2760 } |
|
2761 |
|
2762 static graphics_handle |
|
2763 make_graphics_handle (const std::string& go_name, |
7370
|
2764 const graphics_handle& parent, bool do_createfcn = true) |
6874
|
2765 { |
|
2766 return instance_ok () |
7370
|
2767 ? instance->do_make_graphics_handle (go_name, parent, do_createfcn) |
6874
|
2768 : graphics_handle (); |
|
2769 } |
|
2770 |
|
2771 static graphics_handle make_figure_handle (double val) |
|
2772 { |
|
2773 return instance_ok () |
|
2774 ? instance->do_make_figure_handle (val) : graphics_handle (); |
|
2775 } |
|
2776 |
|
2777 static void push_figure (const graphics_handle& h) |
|
2778 { |
|
2779 if (instance_ok ()) |
|
2780 instance->do_push_figure (h); |
|
2781 } |
|
2782 |
|
2783 static void pop_figure (const graphics_handle& h) |
|
2784 { |
|
2785 if (instance_ok ()) |
|
2786 instance->do_pop_figure (h); |
|
2787 } |
|
2788 |
|
2789 static graphics_handle current_figure (void) |
|
2790 { |
|
2791 return instance_ok () |
|
2792 ? instance->do_current_figure () : graphics_handle (); |
|
2793 } |
|
2794 |
|
2795 static Matrix handle_list (void) |
|
2796 { |
|
2797 return instance_ok () ? instance->do_handle_list () : Matrix (); |
|
2798 } |
|
2799 |
|
2800 static Matrix figure_handle_list (void) |
|
2801 { |
|
2802 return instance_ok () ? instance->do_figure_handle_list () : Matrix (); |
|
2803 } |
|
2804 |
|
2805 private: |
|
2806 |
|
2807 static gh_manager *instance; |
|
2808 |
|
2809 typedef std::map<graphics_handle, graphics_object>::iterator iterator; |
|
2810 typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator; |
|
2811 |
|
2812 typedef std::set<graphics_handle>::iterator free_list_iterator; |
|
2813 typedef std::set<graphics_handle>::const_iterator const_free_list_iterator; |
|
2814 |
|
2815 typedef std::list<graphics_handle>::iterator figure_list_iterator; |
|
2816 typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator; |
|
2817 |
|
2818 // A map of handles to graphics objects. |
|
2819 std::map<graphics_handle, graphics_object> handle_map; |
|
2820 |
|
2821 // The available graphics handles. |
|
2822 std::set<graphics_handle> handle_free_list; |
|
2823 |
|
2824 // The next handle available if handle_free_list is empty. |
7286
|
2825 double next_handle; |
6874
|
2826 |
|
2827 // The allocated figure handles. Top of the stack is most recently |
|
2828 // created. |
|
2829 std::list<graphics_handle> figure_list; |
|
2830 |
|
2831 graphics_handle get_handle (const std::string& go_name); |
|
2832 |
|
2833 void do_free (const graphics_handle& h); |
|
2834 |
|
2835 graphics_handle do_lookup (double val) |
|
2836 { |
7363
|
2837 iterator p = (xisnan (val) ? handle_map.end () : handle_map.find (val)); |
6874
|
2838 |
|
2839 return (p != handle_map.end ()) ? p->first : graphics_handle (); |
|
2840 } |
|
2841 |
|
2842 graphics_object do_get_object (const graphics_handle& h) |
|
2843 { |
7379
|
2844 iterator p = (h.ok () ? handle_map.find (h) : handle_map.end ()); |
6874
|
2845 |
|
2846 return (p != handle_map.end ()) ? p->second : graphics_object (); |
|
2847 } |
|
2848 |
|
2849 graphics_handle do_make_graphics_handle (const std::string& go_name, |
7370
|
2850 const graphics_handle& p, bool do_createfcn); |
6874
|
2851 |
|
2852 graphics_handle do_make_figure_handle (double val); |
|
2853 |
|
2854 Matrix do_handle_list (void) |
|
2855 { |
|
2856 Matrix retval (1, handle_map.size ()); |
|
2857 octave_idx_type i = 0; |
|
2858 for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++) |
7056
|
2859 { |
|
2860 graphics_handle h = p->first; |
|
2861 retval(i++) = h.value (); |
|
2862 } |
6874
|
2863 return retval; |
|
2864 } |
|
2865 |
|
2866 Matrix do_figure_handle_list (void) |
|
2867 { |
|
2868 Matrix retval (1, figure_list.size ()); |
|
2869 octave_idx_type i = 0; |
|
2870 for (const_figure_list_iterator p = figure_list.begin (); |
|
2871 p != figure_list.end (); |
|
2872 p++) |
7056
|
2873 { |
|
2874 graphics_handle h = *p; |
|
2875 retval(i++) = h.value (); |
|
2876 } |
6874
|
2877 return retval; |
|
2878 } |
|
2879 |
|
2880 void do_push_figure (const graphics_handle& h); |
|
2881 |
|
2882 void do_pop_figure (const graphics_handle& h); |
|
2883 |
|
2884 graphics_handle do_current_figure (void) const |
|
2885 { |
|
2886 return figure_list.empty () ? graphics_handle () : figure_list.front (); |
|
2887 } |
|
2888 }; |
|
2889 |
|
2890 |
|
2891 // This function is NOT equivalent to the scripting language function gcf. |
7365
|
2892 OCTINTERP_API graphics_handle gcf (void); |
6874
|
2893 |
|
2894 // This function is NOT equivalent to the scripting language function gca. |
7365
|
2895 OCTINTERP_API graphics_handle gca (void); |
6874
|
2896 |
|
2897 #endif |
|
2898 |
|
2899 /* |
|
2900 ;;; Local Variables: *** |
|
2901 ;;; mode: C++ *** |
|
2902 ;;; End: *** |
|
2903 */ |