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