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