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