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