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