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