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