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 |
7363
|
185 class property; |
|
186 |
|
187 class base_property |
|
188 { |
|
189 public: |
|
190 friend class property; |
|
191 |
|
192 public: |
|
193 base_property (void) : count (0) { } |
|
194 |
|
195 base_property (const std::string& s, const graphics_handle& h) |
|
196 : count (0), name (s), parent (h), hidden (false) { } |
|
197 |
|
198 base_property (const base_property& p) |
|
199 : count (0), name (p.name), parent (p.parent), hidden (p.hidden) { } |
|
200 |
|
201 virtual ~base_property (void) { } |
|
202 |
|
203 bool ok (void) const { return parent.ok (); } |
|
204 |
|
205 std::string get_name (void) const { return name; } |
|
206 |
|
207 void set_name (const std::string& s) { name = s; } |
|
208 |
|
209 graphics_handle get_parent (void) const { return parent; } |
|
210 |
|
211 void set_parent (const graphics_handle &h) { parent = h; } |
|
212 |
|
213 bool is_hidden (void) const { return hidden; } |
|
214 |
|
215 void set_hidden (bool flag) { hidden = flag; } |
|
216 |
7364
|
217 virtual void set (const octave_value&) |
7363
|
218 { error ("set: invalid property \"%s\"", name.c_str ()); } |
|
219 |
|
220 virtual octave_value get (void) const |
|
221 { |
|
222 error ("get: invalid property \"%s\"", name.c_str ()); |
|
223 return octave_value (); |
|
224 } |
|
225 |
|
226 base_property& operator = (const octave_value& val) |
|
227 { |
|
228 set (val); |
|
229 return *this; |
|
230 } |
|
231 |
|
232 private: |
|
233 int count; |
|
234 std::string name; |
|
235 graphics_handle parent; |
|
236 bool hidden; |
|
237 }; |
|
238 |
|
239 // --------------------------------------------------------------------- |
|
240 |
|
241 class string_property : public base_property |
|
242 { |
|
243 public: |
|
244 string_property (const std::string& s, const graphics_handle& h, |
|
245 const std::string& val = "") |
|
246 : base_property (s, h), str (val) { } |
|
247 |
|
248 string_property (const string_property& p) |
|
249 : base_property (p), str (p.str) { } |
|
250 |
|
251 void set (const octave_value& val) |
|
252 { |
|
253 if (val.is_string ()) |
|
254 str = val.string_value (); |
|
255 else |
|
256 error ("set: invalid string property value for \"%s\"", |
|
257 get_name ().c_str ()); |
|
258 } |
|
259 |
|
260 octave_value get (void) const |
|
261 { return octave_value (str); } |
|
262 |
|
263 std::string string_value (void) const { return str; } |
|
264 |
|
265 string_property& operator = (const octave_value& val) |
|
266 { |
|
267 set (val); |
|
268 return *this; |
|
269 } |
|
270 |
|
271 private: |
|
272 std::string str; |
|
273 }; |
|
274 |
|
275 // --------------------------------------------------------------------- |
|
276 |
|
277 class radio_values |
|
278 { |
|
279 public: |
|
280 OCTINTERP_API radio_values (const std::string& opt_string = std::string ()); |
|
281 |
|
282 radio_values (const radio_values& a) |
|
283 : default_val (a.default_val), possible_vals (a.possible_vals) { } |
|
284 |
|
285 radio_values& operator = (const radio_values& a) |
|
286 { |
|
287 if (&a != this) |
|
288 { |
|
289 default_val = a.default_val; |
|
290 possible_vals = a.possible_vals; |
|
291 } |
|
292 |
|
293 return *this; |
|
294 } |
|
295 |
|
296 std::string default_value (void) const { return default_val; } |
|
297 |
|
298 bool validate (const std::string& val) |
|
299 { |
|
300 bool retval = true; |
|
301 |
|
302 if (! contains (val)) |
|
303 { |
|
304 error ("invalid value = %s", val.c_str ()); |
|
305 retval = false; |
|
306 } |
|
307 |
|
308 return retval; |
|
309 } |
|
310 |
|
311 bool contains (const std::string& val) |
|
312 { |
|
313 return (possible_vals.find (val) != possible_vals.end ()); |
|
314 } |
|
315 |
|
316 private: |
|
317 // Might also want to cache |
|
318 std::string default_val; |
|
319 std::set<caseless_str> possible_vals; |
|
320 }; |
|
321 |
|
322 class radio_property : public base_property |
|
323 { |
|
324 public: |
7364
|
325 radio_property (const std::string& nm, const graphics_handle& h, |
7363
|
326 const radio_values& v = radio_values ()) |
7364
|
327 : base_property (nm, h), |
7363
|
328 vals (v), current_val (v.default_value ()) { } |
|
329 |
7364
|
330 radio_property (const std::string& nm, const graphics_handle& h, |
7363
|
331 const std::string& v) |
7364
|
332 : base_property (nm, h), |
7363
|
333 vals (v), current_val (vals.default_value ()) { } |
|
334 |
7364
|
335 radio_property (const std::string& nm, const graphics_handle& h, |
7363
|
336 const radio_values& v, const std::string& def) |
7364
|
337 : base_property (nm, h), |
7363
|
338 vals (v), current_val (def) { } |
|
339 |
|
340 radio_property (const radio_property& p) |
|
341 : base_property (p), vals (p.vals), current_val (p.current_val) { } |
|
342 |
|
343 void set (const octave_value& newval) |
|
344 { |
|
345 if (newval.is_string ()) |
|
346 { |
|
347 std::string s = newval.string_value (); |
|
348 if (vals.validate (s)) |
|
349 current_val = s; |
|
350 else |
|
351 error ("set: invalid value for radio property \"%s\" (value = %s)", |
|
352 get_name ().c_str (), s.c_str ()); |
|
353 } |
|
354 else |
|
355 error ("set: invalid value for radio property \"%s\"", |
|
356 get_name ().c_str ()); |
|
357 } |
|
358 |
|
359 octave_value get (void) const { return octave_value (current_val); } |
|
360 |
|
361 const std::string& current_value (void) const { return current_val; } |
|
362 |
|
363 bool is (const caseless_str& v) const |
|
364 { return v.compare (current_val); } |
|
365 |
|
366 radio_property& operator = (const octave_value& val) |
|
367 { |
|
368 set (val); |
|
369 return *this; |
|
370 } |
|
371 |
|
372 private: |
|
373 radio_values vals; |
|
374 std::string current_val; |
|
375 }; |
|
376 |
|
377 // --------------------------------------------------------------------- |
|
378 |
|
379 class color_values |
|
380 { |
|
381 public: |
|
382 color_values (double r = 0, double g = 0, double b = 1) |
|
383 : xrgb (1, 3) |
|
384 { |
|
385 xrgb(0) = r; |
|
386 xrgb(1) = g; |
|
387 xrgb(2) = b; |
|
388 |
|
389 validate (); |
|
390 } |
|
391 |
|
392 color_values (std::string str) |
|
393 : xrgb (1, 3) |
|
394 { |
|
395 if (! str2rgb (str)) |
|
396 error ("invalid color specification: %s", str.c_str ()); |
|
397 } |
|
398 |
|
399 color_values (const color_values& c) |
|
400 : xrgb (c.xrgb) |
|
401 { } |
|
402 |
|
403 color_values& operator = (const color_values& c) |
|
404 { |
|
405 if (&c != this) |
|
406 xrgb = c.xrgb; |
|
407 |
|
408 return *this; |
|
409 } |
|
410 |
|
411 Matrix rgb (void) const { return xrgb; } |
|
412 |
|
413 operator octave_value (void) const { return xrgb; } |
|
414 |
|
415 void validate (void) const |
|
416 { |
|
417 for (int i = 0; i < 3; i++) |
|
418 { |
|
419 if (xrgb(i) < 0 || xrgb(i) > 1) |
|
420 { |
|
421 error ("invalid RGB color specification"); |
|
422 break; |
|
423 } |
|
424 } |
|
425 } |
|
426 |
|
427 private: |
|
428 Matrix xrgb; |
|
429 |
|
430 OCTINTERP_API bool str2rgb (std::string str); |
|
431 }; |
|
432 |
|
433 class color_property : public base_property |
|
434 { |
|
435 public: |
|
436 color_property (const color_values& c, const radio_values& v) |
|
437 : base_property ("", graphics_handle ()), |
|
438 current_type (color_t), color_val (c), radio_val (v), |
|
439 current_val (v.default_value ()) |
|
440 { } |
|
441 |
7364
|
442 color_property (const std::string& nm, const graphics_handle& h, |
7363
|
443 const color_values& c = color_values (), |
|
444 const radio_values& v = radio_values ()) |
7364
|
445 : base_property (nm, h), |
7363
|
446 current_type (color_t), color_val (c), radio_val (v), |
|
447 current_val (v.default_value ()) |
|
448 { } |
|
449 |
7364
|
450 color_property (const std::string& nm, const graphics_handle& h, |
7363
|
451 const radio_values& v) |
7364
|
452 : base_property (nm, h), |
7363
|
453 current_type (radio_t), color_val (color_values ()), radio_val (v), |
|
454 current_val (v.default_value ()) |
|
455 { } |
|
456 |
7364
|
457 color_property (const std::string& nm, const graphics_handle& h, |
7363
|
458 const std::string& v) |
7364
|
459 : base_property (nm, h), |
7363
|
460 current_type (radio_t), color_val (color_values ()), radio_val (v), |
|
461 current_val (radio_val.default_value ()) |
|
462 { } |
|
463 |
7364
|
464 color_property (const std::string& nm, const graphics_handle& h, |
7363
|
465 const color_property& v) |
7364
|
466 : base_property (nm, h), |
7363
|
467 current_type (v.current_type), color_val (v.color_val), |
|
468 radio_val (v.radio_val), current_val (v.current_val) |
|
469 { } |
|
470 |
|
471 color_property (const color_property& p) |
|
472 : base_property (p), current_type (p.current_type), |
|
473 color_val (p.color_val), radio_val (p.radio_val), |
|
474 current_val (p.current_val) { } |
|
475 |
|
476 octave_value get (void) const |
|
477 { |
|
478 if (current_type == color_t) |
|
479 return color_val.rgb (); |
|
480 |
|
481 return current_val; |
|
482 } |
|
483 |
|
484 OCTINTERP_API void set (const octave_value& newval); |
|
485 |
|
486 bool is_rgb (void) const { return (current_type == color_t); } |
|
487 |
|
488 bool is_radio (void) const { return (current_type == radio_t); } |
|
489 |
|
490 bool is (const std::string& v) const |
|
491 { return (is_radio () && current_val == v); } |
|
492 |
|
493 Matrix rgb (void) const |
|
494 { |
|
495 if (current_type != color_t) |
|
496 error ("color has no rgb value"); |
|
497 |
|
498 return color_val.rgb (); |
|
499 } |
|
500 |
|
501 const std::string& current_value (void) const |
|
502 { |
|
503 if (current_type != radio_t) |
|
504 error ("color has no radio value"); |
|
505 |
|
506 return current_val; |
|
507 } |
|
508 |
|
509 color_property& operator = (const octave_value& val) |
|
510 { |
|
511 set (val); |
|
512 return *this; |
|
513 } |
|
514 |
|
515 operator octave_value (void) const { return get (); } |
|
516 |
|
517 private: |
|
518 enum current_enum { color_t, radio_t } current_type; |
|
519 color_values color_val; |
|
520 radio_values radio_val; |
|
521 std::string current_val; |
|
522 }; |
|
523 |
|
524 // --------------------------------------------------------------------- |
|
525 |
|
526 class double_property : public base_property |
|
527 { |
|
528 public: |
7364
|
529 double_property (const std::string& nm, const graphics_handle& h, |
7363
|
530 double d = 0) |
7364
|
531 : base_property (nm, h), |
7363
|
532 current_val (d) { } |
|
533 |
|
534 double_property (const double_property& p) |
|
535 : base_property (p), current_val (p.current_val) { } |
|
536 |
|
537 void set (const octave_value& v) |
|
538 { |
|
539 if (v.is_scalar_type () && v.is_real_type ()) |
|
540 current_val = v.double_value (); |
|
541 else |
|
542 error ("set: invalid value for double property \"%s\"", |
|
543 get_name ().c_str ()); |
|
544 } |
|
545 |
|
546 octave_value get (void) const { return octave_value (current_val); } |
|
547 |
|
548 double double_value (void) const { return current_val; } |
|
549 |
|
550 double_property& operator = (const octave_value& val) |
|
551 { |
|
552 set (val); |
|
553 return *this; |
|
554 } |
|
555 |
|
556 private: |
|
557 double current_val; |
|
558 }; |
|
559 |
|
560 // --------------------------------------------------------------------- |
|
561 |
|
562 class array_property : public base_property |
|
563 { |
|
564 public: |
7364
|
565 array_property (const std::string& nm, const graphics_handle& h, |
7363
|
566 const octave_value& m) |
7364
|
567 : base_property (nm, h), data (m) { } |
7363
|
568 |
|
569 octave_value get (void) const { return data; } |
|
570 |
|
571 void set (const octave_value& v) |
|
572 { |
|
573 if (validate (v)) |
|
574 data = v; |
|
575 else |
|
576 error ("invalid value for array property \"%s\"", |
|
577 get_name ().c_str ()); |
|
578 } |
|
579 |
|
580 void add_constraint (const std::string& type) |
|
581 { type_constraints.push_back (type); } |
|
582 |
|
583 void add_constraint (dim_vector dims) |
|
584 { size_constraints.push_back (dims); } |
|
585 |
|
586 array_property& operator = (const octave_value& val) |
|
587 { |
|
588 set (val); |
|
589 return *this; |
|
590 } |
|
591 |
|
592 private: |
|
593 OCTINTERP_API bool validate (const octave_value& v); |
|
594 |
|
595 private: |
|
596 octave_value data; |
|
597 std::list<std::string> type_constraints; |
|
598 std::list<dim_vector> size_constraints; |
|
599 }; |
|
600 |
|
601 // --------------------------------------------------------------------- |
|
602 |
|
603 class data_property : public base_property |
|
604 { |
|
605 public: |
|
606 data_property (void) |
|
607 : base_property ("", graphics_handle ()) { } |
|
608 |
7364
|
609 data_property (const std::string& nm, const graphics_handle& h, |
7363
|
610 const NDArray& m = NDArray ()) |
7364
|
611 : base_property (nm, h), |
7363
|
612 data (m), xmin (octave_Inf), xmax (-octave_Inf), xminp (octave_Inf) |
|
613 { |
|
614 get_data_limits (); |
|
615 } |
|
616 |
7364
|
617 data_property (const std::string& nm, const graphics_handle& h, |
7363
|
618 const Matrix& m) |
7364
|
619 : base_property (nm, h), |
7363
|
620 data (m), xmin (octave_Inf), xmax (-octave_Inf), xminp (octave_Inf) |
|
621 { |
|
622 get_data_limits (); |
|
623 } |
|
624 |
|
625 data_property (const data_property& p) |
|
626 : base_property (p), data (p.data), |
|
627 xmin (p.xmin), xmax (p.xmax), xminp (p.xminp) { } |
|
628 |
|
629 void set (const octave_value& val) |
|
630 { |
|
631 data = val.array_value (); |
|
632 |
|
633 get_data_limits (); |
|
634 } |
|
635 |
|
636 octave_value get (void) const { return data; } |
|
637 |
|
638 NDArray array_value (void) const { return data; } |
|
639 |
|
640 Matrix matrix_value (void) const { return data.matrix_value (); } |
|
641 |
|
642 double min_val (void) const { return xmin; } |
|
643 double max_val (void) const { return xmax; } |
|
644 double min_pos (void) const { return xminp; } |
|
645 |
|
646 data_property& operator = (const octave_value& val) |
|
647 { |
|
648 set (val); |
|
649 return *this; |
|
650 } |
|
651 |
|
652 private: |
|
653 NDArray data; |
|
654 double xmin; |
|
655 double xmax; |
|
656 double xminp; |
|
657 |
|
658 void get_data_limits (void) |
|
659 { |
|
660 octave_idx_type nel = data.numel (); |
|
661 |
7395
|
662 xmin = xminp = octave_Inf; |
|
663 xmax = -octave_Inf; |
|
664 |
7363
|
665 if (nel > 0) |
|
666 { |
|
667 const double *d = data.data (); |
|
668 |
|
669 for (octave_idx_type i = 0; i < nel; i++) |
|
670 { |
|
671 double val = d[i]; |
|
672 |
|
673 if (! (xisinf (val) || xisnan (val))) |
|
674 { |
|
675 if (val < xmin) |
|
676 xmin = val; |
|
677 |
|
678 if (val > xmax) |
|
679 xmax = val; |
|
680 |
|
681 if (val > 0 && val < xminp) |
|
682 xminp = val; |
|
683 } |
|
684 } |
|
685 } |
|
686 } |
|
687 }; |
|
688 |
|
689 // --------------------------------------------------------------------- |
|
690 |
|
691 class bool_property : public radio_property |
|
692 { |
|
693 public: |
7364
|
694 bool_property (const std::string& nm, const graphics_handle& h, |
7363
|
695 bool val) |
7364
|
696 : radio_property (nm, h, radio_values (val ? "{on}|off" : "on|{off}")) |
7363
|
697 { } |
|
698 |
7364
|
699 bool_property (const std::string& nm, const graphics_handle& h, |
7363
|
700 const char* val) |
7364
|
701 : radio_property (nm, h, radio_values ("on|off"), val) |
7363
|
702 { } |
|
703 |
|
704 bool_property (const bool_property& p) |
|
705 : radio_property (p) { } |
|
706 |
|
707 void set (const octave_value& val) |
|
708 { |
|
709 if (val.is_bool_scalar ()) |
|
710 radio_property::set (val.bool_value () ? "on" : "off"); |
|
711 else |
|
712 radio_property::set (val); |
|
713 } |
|
714 |
|
715 bool is_on (void) const { return is ("on"); } |
|
716 |
|
717 bool_property& operator = (const octave_value& val) |
|
718 { |
|
719 set (val); |
|
720 return *this; |
|
721 } |
|
722 }; |
|
723 |
|
724 // --------------------------------------------------------------------- |
|
725 |
|
726 class handle_property : public base_property |
|
727 { |
|
728 public: |
7364
|
729 handle_property (const std::string& nm, const graphics_handle& h, |
7363
|
730 const graphics_handle& val = graphics_handle ()) |
7364
|
731 : base_property (nm, h), |
7363
|
732 current_val (val) { } |
|
733 |
|
734 handle_property (const handle_property& p) |
|
735 : base_property (p), current_val (p.current_val) { } |
|
736 |
|
737 OCTINTERP_API void set (const octave_value& v); |
|
738 |
|
739 octave_value get (void) const { return current_val.as_octave_value (); } |
|
740 |
|
741 graphics_handle handle_value (void) const { return current_val; } |
|
742 |
|
743 handle_property& operator = (const octave_value& val) |
|
744 { |
|
745 set (val); |
|
746 return *this; |
|
747 } |
|
748 |
|
749 handle_property& operator = (const graphics_handle& h) |
|
750 { |
|
751 set (octave_value (h.value ())); |
|
752 return *this; |
|
753 } |
|
754 |
|
755 private: |
|
756 graphics_handle current_val; |
|
757 }; |
|
758 |
|
759 // --------------------------------------------------------------------- |
|
760 |
|
761 class any_property : public base_property |
|
762 { |
|
763 public: |
7364
|
764 any_property (const std::string& nm, const graphics_handle& h, |
7363
|
765 const octave_value& m = Matrix ()) |
7364
|
766 : base_property (nm, h), data (m) { } |
7363
|
767 |
|
768 octave_value get (void) const { return data; } |
|
769 |
|
770 void set (const octave_value& v) { data = v; } |
|
771 |
|
772 any_property& operator = (const octave_value& val) |
|
773 { |
|
774 set (val); |
|
775 return *this; |
|
776 } |
|
777 |
|
778 private: |
|
779 octave_value data; |
|
780 }; |
|
781 |
|
782 // --------------------------------------------------------------------- |
|
783 |
|
784 class callback_property : public base_property |
|
785 { |
|
786 public: |
7364
|
787 callback_property (const std::string& nm, const graphics_handle& h, |
7363
|
788 const octave_value& m) |
7364
|
789 : base_property (nm, h), callback (m) { } |
7363
|
790 |
|
791 octave_value get (void) const { return callback; } |
|
792 |
|
793 void set (const octave_value& v) |
|
794 { |
|
795 if (validate (v)) |
|
796 callback = v; |
|
797 else |
|
798 error ("invalid value for callback property \"%s\"", |
|
799 get_name ().c_str ()); |
|
800 } |
|
801 |
7367
|
802 OCTINTERP_API void execute (const octave_value& data = octave_value ()) const; |
7363
|
803 |
|
804 callback_property& operator = (const octave_value& val) |
|
805 { |
|
806 set (val); |
|
807 return *this; |
|
808 } |
|
809 |
|
810 private: |
|
811 OCTINTERP_API bool validate (const octave_value& v) const; |
|
812 |
|
813 private: |
|
814 octave_value callback; |
|
815 }; |
|
816 |
|
817 // --------------------------------------------------------------------- |
|
818 |
|
819 class property |
|
820 { |
|
821 public: |
|
822 property (void) : rep (new base_property ("", graphics_handle ())) |
|
823 { rep->count++; } |
|
824 |
|
825 property (base_property *bp, bool persist = false) : rep (bp) |
|
826 { rep->count++; if (persist) rep->count++; } |
|
827 |
|
828 property (const property& p) |
|
829 { |
|
830 rep = p.rep; |
|
831 rep->count++; |
|
832 } |
|
833 |
|
834 ~property (void) |
|
835 { |
|
836 if (--rep->count <= 0) |
|
837 delete rep; |
|
838 } |
|
839 |
|
840 bool ok (void) const |
|
841 { return rep->ok (); } |
|
842 |
|
843 std::string get_name (void) const |
|
844 { return rep->get_name (); } |
|
845 |
|
846 void set_name (const std::string& name) |
|
847 { rep->set_name (name); } |
|
848 |
|
849 graphics_handle get_parent (void) const |
|
850 { return rep->get_parent (); } |
|
851 |
|
852 void set_parent (const graphics_handle& h) |
|
853 { rep->set_parent (h); } |
|
854 |
|
855 bool is_hidden (void) const |
|
856 { return rep->is_hidden (); } |
|
857 |
|
858 void set_hidden (bool flag) |
|
859 { rep->set_hidden (flag); } |
|
860 |
|
861 octave_value get (void) const |
|
862 { return rep->get (); } |
|
863 |
|
864 void set (const octave_value& val) |
|
865 { rep->set (val); } |
|
866 |
|
867 property& operator = (const octave_value& val) |
|
868 { |
|
869 *rep = val; |
|
870 return *this; |
|
871 } |
|
872 |
|
873 property& operator = (const property& p) |
|
874 { |
|
875 if (rep && --rep->count <= 0) |
|
876 delete rep; |
|
877 |
|
878 rep = p.rep; |
|
879 rep->count++; |
|
880 |
|
881 return *this; |
|
882 } |
|
883 |
|
884 /* |
|
885 const string_property& as_string_property (void) const |
|
886 { return *(dynamic_cast<string_property*> (rep)); } |
|
887 |
|
888 const radio_property& as_radio_property (void) const |
|
889 { return *(dynamic_cast<radio_property*> (rep)); } |
|
890 |
|
891 const color_property& as_color_property (void) const |
|
892 { return *(dynamic_cast<color_property*> (rep)); } |
|
893 |
|
894 const double_property& as_double_property (void) const |
|
895 { return *(dynamic_cast<double_property*> (rep)); } |
|
896 |
|
897 const data_property& as_data_property (void) const |
|
898 { return *(dynamic_cast<data_property*> (rep)); } |
|
899 |
|
900 const bool_property& as_bool_property (void) const |
|
901 { return *(dynamic_cast<bool_property*> (rep)); } |
|
902 |
|
903 const handle_property& as_handle_property (void) const |
|
904 { return *(dynamic_cast<handle_property*> (rep)); } |
|
905 */ |
|
906 |
|
907 private: |
|
908 base_property *rep; |
|
909 }; |
|
910 |
|
911 // --------------------------------------------------------------------- |
|
912 |
|
913 class property_list |
|
914 { |
|
915 public: |
|
916 typedef std::map<std::string, octave_value> pval_map_type; |
|
917 typedef std::map<std::string, pval_map_type> plist_map_type; |
|
918 |
|
919 typedef pval_map_type::iterator pval_map_iterator; |
|
920 typedef pval_map_type::const_iterator pval_map_const_iterator; |
|
921 |
|
922 typedef plist_map_type::iterator plist_map_iterator; |
|
923 typedef plist_map_type::const_iterator plist_map_const_iterator; |
|
924 |
|
925 property_list (const plist_map_type& m = plist_map_type ()) |
|
926 : plist_map (m) { } |
|
927 |
|
928 ~property_list (void) { } |
|
929 |
|
930 void set (const caseless_str& name, const octave_value& val); |
|
931 |
|
932 octave_value lookup (const caseless_str& name) const; |
|
933 |
|
934 plist_map_iterator begin (void) { return plist_map.begin (); } |
|
935 plist_map_const_iterator begin (void) const { return plist_map.begin (); } |
|
936 |
|
937 plist_map_iterator end (void) { return plist_map.end (); } |
|
938 plist_map_const_iterator end (void) const { return plist_map.end (); } |
|
939 |
|
940 plist_map_iterator find (const std::string& go_name) |
|
941 { |
|
942 return plist_map.find (go_name); |
|
943 } |
|
944 |
|
945 plist_map_const_iterator find (const std::string& go_name) const |
|
946 { |
|
947 return plist_map.find (go_name); |
|
948 } |
|
949 |
|
950 Octave_map as_struct (const std::string& prefix_arg) const; |
|
951 |
|
952 private: |
|
953 plist_map_type plist_map; |
|
954 }; |
|
955 |
|
956 // --------------------------------------------------------------------- |
|
957 |
6874
|
958 class base_graphics_object; |
|
959 |
7365
|
960 class OCTINTERP_API base_properties |
6874
|
961 { |
|
962 public: |
7176
|
963 base_properties (const std::string& ty = "unknown", |
7363
|
964 const graphics_handle& mh = graphics_handle (), |
|
965 const graphics_handle& p = graphics_handle ()) |
7404
|
966 : beingdeleted ("beingdeleted", mh, false), |
7366
|
967 busyaction ("parent", mh, "{queue}|cancel"), |
7367
|
968 buttondownfcn ("buttondownfcn", mh, Matrix ()), |
7404
|
969 children (), |
7366
|
970 clipping ("clipping", mh, true), |
7367
|
971 createfcn ("createfcn" , mh, Matrix ()), |
|
972 deletefcn ("deletefcn", mh, Matrix ()), |
7366
|
973 handlevisibility ("handlevisibility", mh, "{on}|callback|off"), |
|
974 hittest ("hittest", mh, true), |
|
975 interruptible ("interruptible", mh, true), |
7404
|
976 parent ("parent", mh, p), |
7366
|
977 selected ("selected", mh, false), |
|
978 selectionhighlight ("selectionhighlight", mh, true), |
7404
|
979 tag ("tag", mh), |
|
980 type ("type", mh, ty), |
7367
|
981 userdata ("userdata", mh, Matrix ()), |
7403
|
982 visible ("visible", mh, true), |
7404
|
983 __modified__ ("__modified__", mh, true), |
|
984 __myhandle__ (mh), |
|
985 uicontextmenu ("uicontextmenu", mh, graphics_handle ()) |
7363
|
986 { } |
6874
|
987 |
|
988 virtual ~base_properties (void) { } |
|
989 |
|
990 virtual std::string graphics_object_name (void) const { return "unknonwn"; } |
|
991 |
|
992 void mark_modified (void); |
|
993 |
|
994 void override_defaults (base_graphics_object& obj); |
|
995 |
|
996 // Look through DEFAULTS for properties with given CLASS_NAME, and |
|
997 // apply them to the current object with set (virtual method). |
|
998 |
|
999 void set_from_list (base_graphics_object& obj, property_list& defaults); |
|
1000 |
7363
|
1001 void insert_property (const std::string& name, property p) |
|
1002 { |
|
1003 p.set_name (name); |
|
1004 p.set_parent (__myhandle__); |
|
1005 all_props[name] = p; |
|
1006 } |
|
1007 |
|
1008 virtual void set (const caseless_str&, const octave_value&); |
|
1009 |
|
1010 virtual octave_value get (const caseless_str&) const; |
|
1011 |
7379
|
1012 virtual octave_value get (bool all = false) const; |
7363
|
1013 |
|
1014 property get_property (const caseless_str&) const; |
|
1015 |
|
1016 std::string get_tag (void) const { return tag.string_value (); } |
|
1017 |
|
1018 graphics_handle get_parent (void) const { return parent.handle_value (); } |
|
1019 |
|
1020 std::string get_type (void) const { return type.string_value (); } |
|
1021 |
|
1022 bool is_modified (void) const { return __modified__.is_on (); } |
7251
|
1023 |
|
1024 graphics_handle get___myhandle__ (void) const { return __myhandle__; } |
7366
|
1025 |
|
1026 std::string get_busyaction (void) const { return busyaction.current_value (); } |
|
1027 |
|
1028 octave_value get_buttondownfcn (void) const { return buttondownfcn.get (); } |
|
1029 |
|
1030 std::string get_clipping (void) const { return clipping.current_value (); } |
|
1031 |
7367
|
1032 void execute_createfcn (const octave_value& data = octave_value ()) const |
|
1033 { createfcn.execute (data); } |
|
1034 |
7366
|
1035 octave_value get_createfcn (void) const { return createfcn.get (); } |
|
1036 |
7367
|
1037 void execute_deletefcn (const octave_value& data = octave_value ()) const |
|
1038 { deletefcn.execute (data); } |
|
1039 |
7366
|
1040 octave_value get_deletefcn (void) const { return deletefcn.get (); } |
|
1041 |
|
1042 std::string get_handlevisibility (void) const { return handlevisibility.current_value (); } |
|
1043 |
|
1044 std::string get_hittest (void) const { return hittest.current_value (); } |
|
1045 |
|
1046 std::string get_interruptible (void) const { return interruptible.current_value (); } |
|
1047 |
|
1048 std::string get_selected (void) const { return selected.current_value (); } |
|
1049 |
|
1050 std::string get_selectionhighlight (void) const { return selectionhighlight.current_value (); } |
|
1051 |
|
1052 octave_value get_uicontextmenu (void) const { return uicontextmenu.get (); } |
|
1053 |
|
1054 octave_value get_userdata (void) const { return userdata.get (); } |
|
1055 |
|
1056 std::string get_visible (void) const { return visible.current_value (); } |
|
1057 |
7403
|
1058 bool is_beingdeleted (void) const { return beingdeleted.is_on (); } |
|
1059 std::string get_beingdeleted (void) const { return beingdeleted.current_value (); } |
|
1060 |
7386
|
1061 virtual void remove_child (const graphics_handle& h); |
|
1062 |
|
1063 virtual void adopt (const graphics_handle& h) |
6874
|
1064 { |
|
1065 octave_idx_type n = children.numel (); |
|
1066 children.resize (1, n+1); |
7056
|
1067 children(n) = h.value (); |
6874
|
1068 } |
|
1069 |
7363
|
1070 void set_tag (const octave_value& val) { tag = val; } |
7176
|
1071 |
6874
|
1072 void set_parent (const octave_value& val); |
|
1073 |
7366
|
1074 void set_busyaction (const octave_value& val) |
|
1075 { |
|
1076 if (! error_state) |
|
1077 { |
|
1078 busyaction = val; |
|
1079 mark_modified (); |
|
1080 } |
|
1081 } |
|
1082 |
|
1083 void set_buttondownfcn (const octave_value& val) |
|
1084 { |
|
1085 if (! error_state) |
|
1086 { |
|
1087 buttondownfcn = val; |
|
1088 mark_modified (); |
|
1089 } |
|
1090 } |
|
1091 |
|
1092 void set_clipping (const octave_value& val) |
|
1093 { |
|
1094 if (! error_state) |
|
1095 { |
|
1096 clipping = val; |
|
1097 mark_modified (); |
|
1098 } |
|
1099 } |
|
1100 |
|
1101 void set_createfcn (const octave_value& val) |
|
1102 { |
|
1103 if (! error_state) |
|
1104 { |
|
1105 createfcn = val; |
|
1106 mark_modified (); |
|
1107 } |
|
1108 } |
|
1109 |
|
1110 void set_deletefcn (const octave_value& val) |
|
1111 { |
|
1112 if (! error_state) |
|
1113 { |
|
1114 deletefcn = val; |
|
1115 mark_modified (); |
|
1116 } |
|
1117 } |
|
1118 |
|
1119 void set_handlevisibility (const octave_value& val) |
|
1120 { |
|
1121 if (! error_state) |
|
1122 { |
|
1123 handlevisibility = val; |
|
1124 mark_modified (); |
|
1125 } |
|
1126 } |
|
1127 |
|
1128 void set_hittest (const octave_value& val) |
|
1129 { |
|
1130 if (! error_state) |
|
1131 { |
|
1132 hittest = val; |
|
1133 mark_modified (); |
|
1134 } |
|
1135 } |
|
1136 |
|
1137 void set_interruptible (const octave_value& val) |
|
1138 { |
|
1139 if (! error_state) |
|
1140 { |
|
1141 interruptible = val; |
|
1142 mark_modified (); |
|
1143 } |
|
1144 } |
|
1145 |
|
1146 void set_selected (const octave_value& val) |
|
1147 { |
|
1148 if (! error_state) |
|
1149 { |
|
1150 selected = val; |
|
1151 mark_modified (); |
|
1152 } |
|
1153 } |
|
1154 |
|
1155 void set_selectionhighlight (const octave_value& val) |
|
1156 { |
|
1157 if (! error_state) |
|
1158 { |
|
1159 selectionhighlight = val; |
|
1160 mark_modified (); |
|
1161 } |
|
1162 } |
|
1163 |
|
1164 void set_uicontextmenu (const octave_value& val) |
|
1165 { |
|
1166 if (! error_state) |
|
1167 { |
|
1168 uicontextmenu = val; |
|
1169 mark_modified (); |
|
1170 } |
|
1171 } |
|
1172 |
|
1173 void set_userdata (const octave_value& val) |
|
1174 { |
|
1175 if (! error_state) |
|
1176 { |
|
1177 userdata = val; |
|
1178 mark_modified (); |
|
1179 } |
|
1180 } |
|
1181 |
|
1182 virtual void set_visible (const octave_value& val) |
|
1183 { |
|
1184 if (! error_state) |
|
1185 { |
|
1186 visible = val; |
|
1187 mark_modified (); |
|
1188 } |
|
1189 } |
|
1190 |
7403
|
1191 void set_beingdeleted (const octave_value& val) |
|
1192 { |
|
1193 if (! error_state) |
|
1194 { |
|
1195 beingdeleted = val; |
|
1196 mark_modified (); |
|
1197 } |
|
1198 } |
|
1199 |
7366
|
1200 |
|
1201 |
6874
|
1202 void reparent (const graphics_handle& new_parent) { parent = new_parent; } |
|
1203 |
7214
|
1204 // Update data limits for AXIS_TYPE (xdata, ydata, etc.) in the parent |
|
1205 // axes object. |
|
1206 |
7386
|
1207 virtual void update_axis_limits (const std::string& axis_type) const; |
7214
|
1208 |
6874
|
1209 virtual void delete_children (void); |
|
1210 |
7222
|
1211 Matrix get_children (void) const { return children; } |
|
1212 |
|
1213 // FIXME -- these functions should be generated automatically by the |
|
1214 // genprops.awk script. |
|
1215 // |
|
1216 // EMIT_BASE_PROPERTIES_GET_FUNCTIONS |
7363
|
1217 virtual data_property get_xdata_property (void) const |
7222
|
1218 { |
|
1219 error ("get: invalid property \"xdata\""); |
|
1220 return data_property (); |
|
1221 } |
|
1222 |
7363
|
1223 virtual data_property get_ydata_property (void) const |
7222
|
1224 { |
|
1225 error ("get: invalid property \"ydata\""); |
|
1226 return data_property (); |
|
1227 } |
|
1228 |
7363
|
1229 virtual data_property get_zdata_property (void) const |
7222
|
1230 { |
|
1231 error ("get: invalid property \"zdata\""); |
|
1232 return data_property (); |
|
1233 } |
|
1234 |
7363
|
1235 virtual data_property get_ldata_property (void) const |
7222
|
1236 { |
|
1237 error ("get: invalid property \"ldata\""); |
|
1238 return data_property (); |
|
1239 } |
|
1240 |
7363
|
1241 virtual data_property get_udata_property (void) const |
7222
|
1242 { |
|
1243 error ("get: invalid property \"udata\""); |
|
1244 return data_property (); |
|
1245 } |
|
1246 |
7363
|
1247 virtual data_property get_xldata_property (void) const |
7222
|
1248 { |
|
1249 error ("get: invalid property \"xldata\""); |
|
1250 return data_property (); |
|
1251 } |
|
1252 |
7363
|
1253 virtual data_property get_xudata_property (void) const |
7222
|
1254 { |
|
1255 error ("get: invalid property \"xudata\""); |
|
1256 return data_property (); |
|
1257 } |
|
1258 |
7363
|
1259 virtual data_property get_cdata_property (void) const |
7222
|
1260 { |
|
1261 error ("get: invalid property \"cdata\""); |
|
1262 return data_property (); |
|
1263 } |
|
1264 |
6874
|
1265 protected: |
7403
|
1266 // properties common to all objects |
|
1267 bool_property beingdeleted; |
|
1268 radio_property busyaction; |
|
1269 callback_property buttondownfcn; |
7363
|
1270 // FIXME: use a property class for children |
6874
|
1271 Matrix children; |
7366
|
1272 bool_property clipping; |
|
1273 callback_property createfcn; |
|
1274 callback_property deletefcn; |
|
1275 radio_property handlevisibility; |
|
1276 bool_property hittest; |
|
1277 bool_property interruptible; |
7403
|
1278 handle_property parent; |
7366
|
1279 bool_property selected; |
|
1280 bool_property selectionhighlight; |
7403
|
1281 string_property tag; |
|
1282 string_property type; |
7366
|
1283 any_property userdata; |
|
1284 bool_property visible; |
7403
|
1285 // additional (octave-specific) properties |
|
1286 bool_property __modified__; |
|
1287 graphics_handle __myhandle__; |
|
1288 // FIXME: should this really be here? |
|
1289 handle_property uicontextmenu; |
7363
|
1290 |
|
1291 protected: |
|
1292 std::map<caseless_str, property> all_props; |
|
1293 |
|
1294 protected: |
|
1295 void insert_static_property (const std::string& name, base_property& p) |
|
1296 { insert_property (name, property (&p, true)); } |
|
1297 |
|
1298 virtual void init (void) { } |
6874
|
1299 }; |
|
1300 |
7365
|
1301 class OCTINTERP_API base_graphics_object |
6874
|
1302 { |
|
1303 public: |
|
1304 friend class graphics_object; |
|
1305 |
|
1306 base_graphics_object (void) : count (1) { } |
|
1307 |
|
1308 base_graphics_object (const base_graphics_object&) { } |
|
1309 |
|
1310 virtual ~base_graphics_object (void) { } |
|
1311 |
|
1312 virtual void mark_modified (void) |
|
1313 { |
7386
|
1314 if (valid_object ()) |
|
1315 get_properties ().mark_modified (); |
|
1316 else |
|
1317 error ("base_graphics_object::mark_modified: invalid graphics object"); |
6874
|
1318 } |
|
1319 |
7386
|
1320 virtual void override_defaults (base_graphics_object& obj) |
6874
|
1321 { |
7386
|
1322 if (valid_object ()) |
|
1323 get_properties ().override_defaults (obj); |
|
1324 else |
|
1325 error ("base_graphics_object::override_defaults: invalid graphics object"); |
6874
|
1326 } |
|
1327 |
7386
|
1328 virtual void set_from_list (property_list& plist) |
6874
|
1329 { |
7386
|
1330 if (valid_object ()) |
|
1331 get_properties ().set_from_list (*this, plist); |
|
1332 else |
|
1333 error ("base_graphics_object::set_from_list: invalid graphics object"); |
6874
|
1334 } |
|
1335 |
7386
|
1336 virtual void set (const caseless_str& pname, const octave_value& pval) |
6874
|
1337 { |
7386
|
1338 if (valid_object ()) |
|
1339 get_properties ().set (pname, pval); |
|
1340 else |
|
1341 error ("base_graphics_object::set: invalid graphics object"); |
6874
|
1342 } |
|
1343 |
|
1344 virtual void set_defaults (const std::string&) |
|
1345 { |
|
1346 error ("base_graphics_object::set_defaults: invalid graphics object"); |
|
1347 } |
|
1348 |
7379
|
1349 virtual octave_value get (bool all = false) const |
6874
|
1350 { |
7386
|
1351 if (valid_object ()) |
|
1352 return get_properties ().get (all); |
|
1353 else |
|
1354 { |
|
1355 error ("base_graphics_object::get: invalid graphics object"); |
|
1356 return octave_value (); |
|
1357 } |
6874
|
1358 } |
|
1359 |
7386
|
1360 virtual octave_value get (const caseless_str& pname) const |
6874
|
1361 { |
7386
|
1362 if (valid_object ()) |
|
1363 return get_properties ().get (pname); |
|
1364 else |
|
1365 { |
|
1366 error ("base_graphics_object::get: invalid graphics object"); |
|
1367 return octave_value (); |
|
1368 } |
6874
|
1369 } |
|
1370 |
7189
|
1371 virtual octave_value get_default (const caseless_str&) const; |
6874
|
1372 |
7189
|
1373 virtual octave_value get_factory_default (const caseless_str&) const; |
6874
|
1374 |
|
1375 virtual octave_value get_defaults (void) const |
|
1376 { |
|
1377 error ("base_graphics_object::get_defaults: invalid graphics object"); |
|
1378 return octave_value (); |
|
1379 } |
|
1380 |
|
1381 virtual octave_value get_factory_defaults (void) const |
|
1382 { |
|
1383 error ("base_graphics_object::get_factory_defaults: invalid graphics object"); |
|
1384 return octave_value (); |
|
1385 } |
|
1386 |
|
1387 virtual graphics_handle get_parent (void) const |
|
1388 { |
7386
|
1389 if (valid_object ()) |
|
1390 return get_properties ().get_parent (); |
|
1391 else |
|
1392 { |
|
1393 error ("base_graphics_object::get_parent: invalid graphics object"); |
|
1394 return graphics_handle (); |
|
1395 } |
6874
|
1396 } |
|
1397 |
7386
|
1398 virtual void remove_child (const graphics_handle& h) |
6874
|
1399 { |
7386
|
1400 if (valid_object ()) |
|
1401 get_properties ().remove_child (h); |
|
1402 else |
|
1403 error ("base_graphics_object::remove_child: invalid graphics object"); |
6874
|
1404 } |
|
1405 |
7386
|
1406 virtual void adopt (const graphics_handle& h) |
6874
|
1407 { |
7386
|
1408 if (valid_object ()) |
|
1409 get_properties ().adopt (h); |
|
1410 else |
|
1411 error ("base_graphics_object::adopt: invalid graphics object"); |
6874
|
1412 } |
|
1413 |
7386
|
1414 virtual void reparent (const graphics_handle& np) |
6874
|
1415 { |
7386
|
1416 if (valid_object ()) |
|
1417 get_properties ().reparent (np); |
|
1418 else |
|
1419 error ("base_graphics_object::reparent: invalid graphics object"); |
6874
|
1420 } |
|
1421 |
|
1422 virtual void defaults (void) const |
|
1423 { |
7386
|
1424 if (valid_object ()) |
|
1425 { |
|
1426 std::string msg = (type () + "::defaults"); |
|
1427 gripe_not_implemented (msg.c_str ()); |
|
1428 } |
|
1429 else |
|
1430 error ("base_graphics_object::default: invalid graphics object"); |
6874
|
1431 } |
|
1432 |
|
1433 virtual base_properties& get_properties (void) |
|
1434 { |
|
1435 static base_properties properties; |
|
1436 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
1437 return properties; |
|
1438 } |
|
1439 |
7222
|
1440 virtual const base_properties& get_properties (void) const |
|
1441 { |
|
1442 static base_properties properties; |
|
1443 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
1444 return properties; |
|
1445 } |
|
1446 |
|
1447 virtual void update_axis_limits (const std::string&) |
7214
|
1448 { |
|
1449 error ("base_graphics_object::update_axis_limits: invalid graphics object"); |
|
1450 } |
|
1451 |
6874
|
1452 virtual bool valid_object (void) const { return false; } |
|
1453 |
7386
|
1454 virtual std::string type (void) const |
|
1455 { |
|
1456 return (valid_object () ? get_properties ().graphics_object_name () |
|
1457 : "unknown"); |
|
1458 } |
6874
|
1459 |
|
1460 bool isa (const std::string& go_name) const |
|
1461 { |
|
1462 return type () == go_name; |
|
1463 } |
|
1464 |
|
1465 protected: |
|
1466 // A reference count. |
|
1467 int count; |
|
1468 }; |
|
1469 |
7365
|
1470 class OCTINTERP_API graphics_object |
6874
|
1471 { |
|
1472 public: |
|
1473 graphics_object (void) : rep (new base_graphics_object ()) { } |
|
1474 |
|
1475 graphics_object (base_graphics_object *new_rep) |
|
1476 : rep (new_rep) { } |
|
1477 |
|
1478 graphics_object (const graphics_object& obj) |
|
1479 { |
|
1480 rep = obj.rep; |
|
1481 rep->count++; |
|
1482 } |
|
1483 |
|
1484 graphics_object& operator = (const graphics_object& obj) |
|
1485 { |
|
1486 if (rep != obj.rep) |
|
1487 { |
|
1488 if (--rep->count == 0) |
|
1489 delete rep; |
|
1490 |
|
1491 rep = obj.rep; |
|
1492 rep->count++; |
|
1493 } |
|
1494 |
|
1495 return *this; |
|
1496 } |
|
1497 |
|
1498 ~graphics_object (void) |
|
1499 { |
|
1500 if (--rep->count == 0) |
|
1501 delete rep; |
|
1502 } |
|
1503 |
|
1504 void mark_modified (void) { rep->mark_modified (); } |
|
1505 |
|
1506 void override_defaults (base_graphics_object& obj) |
|
1507 { |
|
1508 rep->override_defaults (obj); |
|
1509 } |
|
1510 |
7214
|
1511 void set_from_list (property_list& plist) { rep->set_from_list (plist); } |
6874
|
1512 |
7189
|
1513 void set (const caseless_str& name, const octave_value& val) |
6874
|
1514 { |
|
1515 rep->set (name, val); |
|
1516 } |
|
1517 |
|
1518 void set (const octave_value_list& args); |
|
1519 |
7214
|
1520 void set_defaults (const std::string& mode) { rep->set_defaults (mode); } |
|
1521 |
7379
|
1522 octave_value get (bool all = false) const { return rep->get (all); } |
6874
|
1523 |
7189
|
1524 octave_value get (const caseless_str& name) const |
6874
|
1525 { |
|
1526 return name.compare ("default") |
|
1527 ? get_defaults () |
|
1528 : (name.compare ("factory") |
|
1529 ? get_factory_defaults () : rep->get (name)); |
|
1530 } |
|
1531 |
7189
|
1532 octave_value get_default (const caseless_str& name) const |
6874
|
1533 { |
|
1534 return rep->get_default (name); |
|
1535 } |
|
1536 |
7189
|
1537 octave_value get_factory_default (const caseless_str& name) const |
6874
|
1538 { |
|
1539 return rep->get_factory_default (name); |
|
1540 } |
|
1541 |
|
1542 octave_value get_defaults (void) const { return rep->get_defaults (); } |
|
1543 |
|
1544 octave_value get_factory_defaults (void) const |
|
1545 { |
|
1546 return rep->get_factory_defaults (); |
|
1547 } |
|
1548 |
|
1549 graphics_handle get_parent (void) const { return rep->get_parent (); } |
|
1550 |
7214
|
1551 void remove_child (const graphics_handle& h) { rep->remove_child (h); } |
|
1552 |
|
1553 void adopt (const graphics_handle& h) { rep->adopt (h); } |
|
1554 |
|
1555 void reparent (const graphics_handle& h) { rep->reparent (h); } |
6874
|
1556 |
|
1557 void defaults (void) const { rep->defaults (); } |
|
1558 |
|
1559 bool isa (const std::string& go_name) const { return rep->isa (go_name); } |
|
1560 |
|
1561 base_properties& get_properties (void) { return rep->get_properties (); } |
|
1562 |
7222
|
1563 const base_properties& get_properties (void) const |
|
1564 { |
|
1565 return rep->get_properties (); |
|
1566 } |
|
1567 |
7214
|
1568 void update_axis_limits (const std::string& axis_type) |
|
1569 { |
|
1570 rep->update_axis_limits (axis_type); |
|
1571 } |
|
1572 |
6874
|
1573 bool valid_object (void) const { return rep->valid_object (); } |
|
1574 |
|
1575 operator bool (void) const { return rep->valid_object (); } |
|
1576 |
7222
|
1577 // FIXME -- these functions should be generated automatically by the |
|
1578 // genprops.awk script. |
|
1579 // |
|
1580 // EMIT_GRAPHICS_OBJECT_GET_FUNCTIONS |
7363
|
1581 data_property get_xdata_property (void) const |
7222
|
1582 { |
|
1583 const base_properties& props = get_properties (); |
7363
|
1584 return props.get_xdata_property (); |
7222
|
1585 } |
|
1586 |
7363
|
1587 data_property get_ydata_property (void) const |
7222
|
1588 { |
|
1589 const base_properties& props = get_properties (); |
7363
|
1590 return props.get_ydata_property (); |
7222
|
1591 } |
|
1592 |
7363
|
1593 data_property get_zdata_property (void) const |
7222
|
1594 { |
|
1595 const base_properties& props = get_properties (); |
7363
|
1596 return props.get_zdata_property (); |
7222
|
1597 } |
|
1598 |
7363
|
1599 data_property get_ldata_property (void) const |
7222
|
1600 { |
|
1601 const base_properties& props = get_properties (); |
7363
|
1602 return props.get_ldata_property (); |
7222
|
1603 } |
|
1604 |
7363
|
1605 data_property get_udata_property (void) const |
7222
|
1606 { |
|
1607 const base_properties& props = get_properties (); |
7363
|
1608 return props.get_udata_property (); |
7222
|
1609 } |
|
1610 |
7363
|
1611 data_property get_xldata_property (void) const |
7222
|
1612 { |
|
1613 const base_properties& props = get_properties (); |
7363
|
1614 return props.get_xldata_property (); |
7222
|
1615 } |
|
1616 |
7363
|
1617 data_property get_xudata_property (void) const |
7222
|
1618 { |
|
1619 const base_properties& props = get_properties (); |
7363
|
1620 return props.get_xudata_property (); |
7222
|
1621 } |
|
1622 |
7363
|
1623 data_property get_cdata_property (void) const |
7222
|
1624 { |
|
1625 const base_properties& props = get_properties (); |
7363
|
1626 return props.get_cdata_property (); |
7222
|
1627 } |
|
1628 |
6874
|
1629 private: |
|
1630 base_graphics_object *rep; |
|
1631 }; |
|
1632 |
|
1633 // --------------------------------------------------------------------- |
|
1634 |
7365
|
1635 class OCTINTERP_API root_figure : public base_graphics_object |
6874
|
1636 { |
|
1637 public: |
|
1638 class properties : public base_properties |
|
1639 { |
|
1640 public: |
|
1641 // See the genprops.awk script for an explanation of the |
|
1642 // properties declarations. |
|
1643 |
7363
|
1644 BEGIN_PROPERTIES(root_figure) |
|
1645 handle_property currentfigure S , graphics_handle () |
6874
|
1646 END_PROPERTIES |
|
1647 }; |
|
1648 |
|
1649 private: |
|
1650 properties xproperties; |
|
1651 |
|
1652 public: |
|
1653 |
7363
|
1654 root_figure (void) : xproperties (0, graphics_handle ()), default_properties () { } |
6874
|
1655 |
|
1656 ~root_figure (void) { xproperties.delete_children (); } |
|
1657 |
|
1658 void mark_modified (void) { } |
|
1659 |
|
1660 void override_defaults (base_graphics_object& obj) |
|
1661 { |
|
1662 // Now override with our defaults. If the default_properties |
|
1663 // list includes the properties for all defaults (line, |
|
1664 // surface, etc.) then we don't have to know the type of OBJ |
|
1665 // here, we just call its set function and let it decide which |
|
1666 // properties from the list to use. |
|
1667 obj.set_from_list (default_properties); |
|
1668 } |
|
1669 |
7189
|
1670 void set (const caseless_str& name, const octave_value& value) |
6874
|
1671 { |
|
1672 if (name.compare ("default", 7)) |
|
1673 // strip "default", pass rest to function that will |
|
1674 // parse the remainder and add the element to the |
|
1675 // default_properties map. |
|
1676 default_properties.set (name.substr (7), value); |
|
1677 else |
|
1678 xproperties.set (name, value); |
|
1679 } |
|
1680 |
7189
|
1681 octave_value get (const caseless_str& name) const |
6874
|
1682 { |
|
1683 octave_value retval; |
|
1684 |
|
1685 if (name.compare ("default", 7)) |
|
1686 return get_default (name.substr (7)); |
|
1687 else if (name.compare ("factory", 7)) |
|
1688 return get_factory_default (name.substr (7)); |
|
1689 else |
|
1690 retval = xproperties.get (name); |
|
1691 |
|
1692 return retval; |
|
1693 } |
|
1694 |
7189
|
1695 octave_value get_default (const caseless_str& name) const |
6874
|
1696 { |
|
1697 octave_value retval = default_properties.lookup (name); |
|
1698 |
|
1699 if (retval.is_undefined ()) |
|
1700 error ("get: invalid default property `%s'", name.c_str ()); |
|
1701 |
|
1702 return retval; |
|
1703 } |
|
1704 |
7189
|
1705 octave_value get_factory_default (const caseless_str& name) const |
6874
|
1706 { |
|
1707 octave_value retval = factory_properties.lookup (name); |
|
1708 |
|
1709 if (retval.is_undefined ()) |
|
1710 error ("get: invalid factory default property `%s'", name.c_str ()); |
|
1711 |
|
1712 return retval; |
|
1713 } |
|
1714 |
|
1715 octave_value get_defaults (void) const |
|
1716 { |
|
1717 return default_properties.as_struct ("default"); |
|
1718 } |
|
1719 |
|
1720 octave_value get_factory_defaults (void) const |
|
1721 { |
|
1722 return factory_properties.as_struct ("factory"); |
|
1723 } |
|
1724 |
|
1725 base_properties& get_properties (void) { return xproperties; } |
|
1726 |
7222
|
1727 const base_properties& get_properties (void) const { return xproperties; } |
|
1728 |
6874
|
1729 bool valid_object (void) const { return true; } |
|
1730 |
|
1731 private: |
|
1732 property_list default_properties; |
|
1733 |
|
1734 static property_list factory_properties; |
|
1735 |
|
1736 static property_list::plist_map_type init_factory_properties (void); |
|
1737 }; |
|
1738 |
|
1739 // --------------------------------------------------------------------- |
|
1740 |
7365
|
1741 class OCTINTERP_API figure : public base_graphics_object |
6874
|
1742 { |
|
1743 public: |
|
1744 class properties : public base_properties |
|
1745 { |
|
1746 public: |
|
1747 void close (void); |
7366
|
1748 void set_visible (const octave_value& val); |
6874
|
1749 |
|
1750 // See the genprops.awk script for an explanation of the |
|
1751 // properties declarations. |
|
1752 |
7363
|
1753 BEGIN_PROPERTIES(figure) |
7379
|
1754 any_property __plot_stream__ h , Matrix () |
|
1755 bool_property __enhanced__ h , "on" |
7363
|
1756 radio_property nextplot , "add|replace_children|{replace}" |
|
1757 callback_property closerequestfcn , "closereq" |
|
1758 handle_property currentaxes S , graphics_handle () |
|
1759 array_property colormap , jet_colormap () |
|
1760 radio_property paperorientation , "{portrait}|landscape" |
|
1761 color_property color , color_values (1, 1, 1) |
6874
|
1762 END_PROPERTIES |
7363
|
1763 |
|
1764 protected: |
|
1765 void init (void) |
|
1766 { |
|
1767 colormap.add_constraint (dim_vector (-1, 3)); |
|
1768 } |
6874
|
1769 }; |
|
1770 |
|
1771 private: |
|
1772 properties xproperties; |
|
1773 |
|
1774 public: |
|
1775 figure (const graphics_handle& mh, const graphics_handle& p) |
|
1776 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1777 { |
|
1778 xproperties.override_defaults (*this); |
|
1779 } |
|
1780 |
|
1781 ~figure (void) |
|
1782 { |
7386
|
1783 xproperties.delete_children (); |
6874
|
1784 xproperties.close (); |
|
1785 } |
|
1786 |
|
1787 void override_defaults (base_graphics_object& obj) |
|
1788 { |
|
1789 // Allow parent (root figure) to override first (properties knows how |
|
1790 // to find the parent object). |
|
1791 xproperties.override_defaults (obj); |
|
1792 |
|
1793 // Now override with our defaults. If the default_properties |
|
1794 // list includes the properties for all defaults (line, |
|
1795 // surface, etc.) then we don't have to know the type of OBJ |
|
1796 // here, we just call its set function and let it decide which |
|
1797 // properties from the list to use. |
|
1798 obj.set_from_list (default_properties); |
|
1799 } |
|
1800 |
7189
|
1801 void set (const caseless_str& name, const octave_value& value) |
6874
|
1802 { |
|
1803 if (name.compare ("default", 7)) |
|
1804 // strip "default", pass rest to function that will |
|
1805 // parse the remainder and add the element to the |
|
1806 // default_properties map. |
|
1807 default_properties.set (name.substr (7), value); |
|
1808 else |
|
1809 xproperties.set (name, value); |
|
1810 } |
|
1811 |
7189
|
1812 octave_value get (const caseless_str& name) const |
6874
|
1813 { |
|
1814 octave_value retval; |
|
1815 |
|
1816 if (name.compare ("default", 7)) |
|
1817 retval = get_default (name.substr (7)); |
|
1818 else |
|
1819 retval = xproperties.get (name); |
|
1820 |
|
1821 return retval; |
|
1822 } |
|
1823 |
7189
|
1824 octave_value get_default (const caseless_str& name) const; |
6874
|
1825 |
|
1826 octave_value get_defaults (void) const |
|
1827 { |
|
1828 return default_properties.as_struct ("default"); |
|
1829 } |
|
1830 |
|
1831 base_properties& get_properties (void) { return xproperties; } |
|
1832 |
7222
|
1833 const base_properties& get_properties (void) const { return xproperties; } |
|
1834 |
6874
|
1835 bool valid_object (void) const { return true; } |
|
1836 |
|
1837 private: |
|
1838 property_list default_properties; |
|
1839 }; |
|
1840 |
|
1841 // --------------------------------------------------------------------- |
|
1842 |
7365
|
1843 class OCTINTERP_API axes : public base_graphics_object |
6874
|
1844 { |
|
1845 public: |
|
1846 class properties : public base_properties |
|
1847 { |
|
1848 public: |
|
1849 void set_defaults (base_graphics_object& obj, const std::string& mode); |
|
1850 |
|
1851 void remove_child (const graphics_handle& h); |
|
1852 |
|
1853 void delete_children (void); |
|
1854 |
|
1855 // See the genprops.awk script for an explanation of the |
|
1856 // properties declarations. |
|
1857 |
7363
|
1858 BEGIN_PROPERTIES(axes) |
|
1859 array_property position , Matrix () |
|
1860 mutable handle_property title GSO , graphics_handle () |
|
1861 bool_property box , "on" |
|
1862 bool_property key , "off" |
|
1863 bool_property keybox , "off" |
|
1864 double_property keypos , 1 |
|
1865 array_property colororder , default_colororder () |
|
1866 array_property dataaspectratio m , Matrix (1, 3, 1.0) |
|
1867 radio_property dataaspectratiomode , "{auto}|manual" |
7379
|
1868 radio_property layer , "{bottom}|top" |
7363
|
1869 array_property xlim m , default_lim () |
|
1870 array_property ylim m , default_lim () |
|
1871 array_property zlim m , default_lim () |
|
1872 array_property clim m , default_lim () |
7403
|
1873 array_property alim m , default_lim () |
7363
|
1874 radio_property xlimmode al , "{auto}|manual" |
|
1875 radio_property ylimmode al , "{auto}|manual" |
|
1876 radio_property zlimmode al , "{auto}|manual" |
|
1877 radio_property climmode al , "{auto}|manual" |
7403
|
1878 radio_property alimmode , "{auto}|manual" |
7363
|
1879 mutable handle_property xlabel GSO , graphics_handle () |
|
1880 mutable handle_property ylabel GSO , graphics_handle () |
|
1881 mutable handle_property zlabel GSO , graphics_handle () |
|
1882 bool_property xgrid , "off" |
|
1883 bool_property ygrid , "off" |
|
1884 bool_property zgrid , "off" |
|
1885 bool_property xminorgrid , "off" |
|
1886 bool_property yminorgrid , "off" |
|
1887 bool_property zminorgrid , "off" |
|
1888 array_property xtick m , Matrix () |
|
1889 array_property ytick m , Matrix () |
|
1890 array_property ztick m , Matrix () |
|
1891 radio_property xtickmode , "{auto}|manual" |
|
1892 radio_property ytickmode , "{auto}|manual" |
|
1893 radio_property ztickmode , "{auto}|manual" |
7403
|
1894 bool_property xminortick , "off" |
|
1895 bool_property yminortick , "off" |
|
1896 bool_property zminortick , "off" |
|
1897 // FIXME: should be kind of string array |
7363
|
1898 any_property xticklabel m , "" |
|
1899 any_property yticklabel m , "" |
|
1900 any_property zticklabel m , "" |
|
1901 radio_property xticklabelmode , "{auto}|manual" |
|
1902 radio_property yticklabelmode , "{auto}|manual" |
|
1903 radio_property zticklabelmode , "{auto}|manual" |
7379
|
1904 color_property color , color_property (color_values (1, 1, 1), radio_values ("none")) |
7363
|
1905 color_property xcolor , color_values (0, 0, 0) |
|
1906 color_property ycolor , color_values (0, 0, 0) |
|
1907 color_property zcolor , color_values (0, 0, 0) |
|
1908 radio_property xscale al , "{linear}|log" |
|
1909 radio_property yscale al , "{linear}|log" |
|
1910 radio_property zscale al , "{linear}|log" |
|
1911 radio_property xdir , "{normal}|reverse" |
|
1912 radio_property ydir , "{normal}|reverse" |
|
1913 radio_property zdir , "{normal}|reverse" |
7365
|
1914 radio_property yaxislocation , "{left}|right|zero" |
|
1915 radio_property xaxislocation , "{bottom}|top|zero" |
7363
|
1916 array_property view , Matrix () |
|
1917 radio_property nextplot , "add|replace_children|{replace}" |
|
1918 array_property outerposition , Matrix () |
7379
|
1919 radio_property activepositionproperty , "{outerposition}|position" |
|
1920 radio_property __colorbar__ h , "{none}|north|south|east|west|northoutside|southoutside|eastoutside|westoutside" |
7403
|
1921 color_property ambientlightcolor , color_values (1, 1, 1) |
|
1922 array_property cameraposition m , Matrix (1, 3, 0.0) |
|
1923 array_property cameratarget m , Matrix (1, 3, 0.0) |
|
1924 array_property cameraupvector m , Matrix () |
|
1925 double_property cameraviewangle m , 10.0 |
|
1926 radio_property camerapositionmode , "{auto}|manual" |
|
1927 radio_property cameratargetmode , "{auto}|manual" |
|
1928 radio_property cameraupvectormode , "{auto}|manual" |
|
1929 radio_property cameraviewanglemode , "{auto}|manual" |
|
1930 array_property currentpoint , Matrix (2, 3, 0.0) |
|
1931 radio_property drawmode , "{normal}|fast" |
|
1932 radio_property fontangle , "{normal}|italic|oblique" |
|
1933 string_property fontname , "Helvetica" |
|
1934 double_property fontsize , 12 |
|
1935 radio_property fontunits , "{points}|normalized|inches|centimeters|pixels" |
|
1936 radio_property fontweight , "{normal}|light|demi|bold" |
|
1937 radio_property gridlinestyle , "{-}|--|:|-.|none" |
|
1938 // FIXME: should be kind of string array |
|
1939 string_property linestyleorder , "-" |
|
1940 double_property linewidth , 0.5 |
|
1941 radio_property minorgridlinestyle , "{-}|--|:|-.|none" |
|
1942 array_property plotboxaspectratio m , Matrix (1, 3, 1.0) |
|
1943 radio_property plotboxaspectratiomode , "{auto}|manual" |
|
1944 radio_property projection , "{orthographic}|perpective" |
|
1945 radio_property tickdir m , "{in}|out" |
|
1946 radio_property tickdirmode , "{auto}|manual" |
|
1947 array_property ticklength , Matrix (1, 2, 0.1) |
|
1948 array_property tightinset r , Matrix (1, 4, 0.0) |
|
1949 // FIXME: uicontextmenu should be moved here |
|
1950 radio_property units , "{normalized}|inches|centimeters|points|pixels|characters" |
|
1951 // hidden properties for transformation computation |
|
1952 array_property x_viewtransform h , Matrix (4, 4, 0.0) |
|
1953 array_property x_projectiontransform h , Matrix (4, 4, 0.0) |
|
1954 array_property x_viewporttransform h , Matrix (4, 4, 0.0) |
|
1955 array_property x_normrendertransform h , Matrix (4, 4, 0.0) |
|
1956 array_property x_rendertransform h , Matrix (4, 4, 0.0) |
7189
|
1957 END_PROPERTIES |
6874
|
1958 |
7363
|
1959 protected: |
|
1960 void init (void) |
|
1961 { |
|
1962 position.add_constraint (dim_vector (1, 4)); |
7403
|
1963 position.add_constraint (dim_vector (0, 0)); |
7363
|
1964 outerposition.add_constraint (dim_vector (1, 4)); |
|
1965 colororder.add_constraint (dim_vector (-1, 3)); |
|
1966 dataaspectratio.add_constraint (dim_vector (1, 3)); |
7403
|
1967 plotboxaspectratio.add_constraint (dim_vector (1, 3)); |
7363
|
1968 xlim.add_constraint (dim_vector (1, 2)); |
|
1969 ylim.add_constraint (dim_vector (1, 2)); |
|
1970 zlim.add_constraint (dim_vector (1, 2)); |
|
1971 clim.add_constraint (dim_vector (1, 2)); |
7403
|
1972 alim.add_constraint (dim_vector (1, 2)); |
7363
|
1973 xtick.add_constraint (dim_vector (1, -1)); |
|
1974 ytick.add_constraint (dim_vector (1, -1)); |
|
1975 ztick.add_constraint (dim_vector (1, -1)); |
|
1976 Matrix vw (1, 2, 0); |
|
1977 vw(1) = 90; |
|
1978 view = vw; |
|
1979 view.add_constraint (dim_vector (1, 2)); |
7403
|
1980 cameraposition.add_constraint (dim_vector (1, 3)); |
|
1981 Matrix upv (1, 3, 0.0); |
|
1982 upv(2) = 1.0; |
|
1983 cameraupvector = upv; |
|
1984 cameraupvector.add_constraint (dim_vector (1, 3)); |
|
1985 currentpoint.add_constraint (dim_vector (2, 3)); |
|
1986 ticklength.add_constraint (dim_vector (1, 2)); |
|
1987 tightinset.add_constraint (dim_vector (1, 4)); |
7363
|
1988 } |
6874
|
1989 }; |
|
1990 |
|
1991 private: |
|
1992 properties xproperties; |
|
1993 |
|
1994 public: |
|
1995 axes (const graphics_handle& mh, const graphics_handle& p) |
|
1996 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1997 { |
|
1998 xproperties.override_defaults (*this); |
|
1999 } |
|
2000 |
|
2001 ~axes (void) { xproperties.delete_children (); } |
|
2002 |
|
2003 void override_defaults (base_graphics_object& obj) |
|
2004 { |
|
2005 // Allow parent (figure) to override first (properties knows how |
|
2006 // to find the parent object). |
|
2007 xproperties.override_defaults (obj); |
|
2008 |
|
2009 // Now override with our defaults. If the default_properties |
|
2010 // list includes the properties for all defaults (line, |
|
2011 // surface, etc.) then we don't have to know the type of OBJ |
|
2012 // here, we just call its set function and let it decide which |
|
2013 // properties from the list to use. |
|
2014 obj.set_from_list (default_properties); |
|
2015 } |
|
2016 |
7189
|
2017 void set (const caseless_str& name, const octave_value& value) |
6874
|
2018 { |
|
2019 if (name.compare ("default", 7)) |
|
2020 // strip "default", pass rest to function that will |
|
2021 // parse the remainder and add the element to the |
|
2022 // default_properties map. |
|
2023 default_properties.set (name.substr (7), value); |
|
2024 else |
|
2025 xproperties.set (name, value); |
|
2026 } |
|
2027 |
|
2028 void set_defaults (const std::string& mode) |
|
2029 { |
|
2030 xproperties.set_defaults (*this, mode); |
|
2031 } |
|
2032 |
7189
|
2033 octave_value get (const caseless_str& name) const |
6874
|
2034 { |
|
2035 octave_value retval; |
|
2036 |
|
2037 // FIXME -- finish this. |
|
2038 if (name.compare ("default", 7)) |
|
2039 retval = get_default (name.substr (7)); |
|
2040 else |
|
2041 retval = xproperties.get (name); |
|
2042 |
|
2043 return retval; |
|
2044 } |
|
2045 |
7189
|
2046 octave_value get_default (const caseless_str& name) const; |
6874
|
2047 |
|
2048 octave_value get_defaults (void) const |
|
2049 { |
|
2050 return default_properties.as_struct ("default"); |
|
2051 } |
|
2052 |
|
2053 base_properties& get_properties (void) { return xproperties; } |
|
2054 |
7222
|
2055 const base_properties& get_properties (void) const { return xproperties; } |
|
2056 |
7214
|
2057 void update_axis_limits (const std::string& axis_type); |
|
2058 |
6874
|
2059 bool valid_object (void) const { return true; } |
|
2060 |
|
2061 private: |
|
2062 property_list default_properties; |
|
2063 }; |
|
2064 |
|
2065 // --------------------------------------------------------------------- |
|
2066 |
7365
|
2067 class OCTINTERP_API line : public base_graphics_object |
6874
|
2068 { |
|
2069 public: |
|
2070 class properties : public base_properties |
|
2071 { |
|
2072 public: |
|
2073 // See the genprops.awk script for an explanation of the |
|
2074 // properties declarations. |
|
2075 |
7366
|
2076 // properties which are not in matlab: |
7384
|
2077 // ldata, udata, xldata, xudata, keylabel, interpreter |
7366
|
2078 |
7363
|
2079 BEGIN_PROPERTIES(line) |
|
2080 data_property xdata l , default_data () |
|
2081 data_property ydata l , default_data () |
|
2082 data_property zdata l , Matrix () |
|
2083 data_property ldata l , Matrix () |
|
2084 data_property udata l , Matrix () |
|
2085 data_property xldata l , Matrix () |
|
2086 data_property xudata l , Matrix () |
|
2087 color_property color , color_values (0, 0, 0) |
|
2088 radio_property linestyle , "{-}|--|:|-.|none" |
|
2089 double_property linewidth , 0.5 |
|
2090 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2091 color_property markeredgecolor , "{auto}|none" |
|
2092 color_property markerfacecolor , "auto|{none}" |
|
2093 double_property markersize , 6 |
|
2094 string_property keylabel , "" |
7384
|
2095 radio_property interpreter , "{tex}|none|latex" |
7377
|
2096 string_property displayname , "" |
7380
|
2097 radio_property erasemode , "{normal}|none|xor|background" |
6874
|
2098 END_PROPERTIES |
|
2099 }; |
|
2100 |
|
2101 private: |
|
2102 properties xproperties; |
|
2103 |
|
2104 public: |
|
2105 line (const graphics_handle& mh, const graphics_handle& p) |
|
2106 : base_graphics_object (), xproperties (mh, p) |
|
2107 { |
|
2108 xproperties.override_defaults (*this); |
|
2109 } |
|
2110 |
|
2111 ~line (void) { xproperties.delete_children (); } |
|
2112 |
|
2113 base_properties& get_properties (void) { return xproperties; } |
|
2114 |
7222
|
2115 const base_properties& get_properties (void) const { return xproperties; } |
|
2116 |
6874
|
2117 bool valid_object (void) const { return true; } |
|
2118 }; |
|
2119 |
|
2120 // --------------------------------------------------------------------- |
|
2121 |
7365
|
2122 class OCTINTERP_API text : public base_graphics_object |
6874
|
2123 { |
|
2124 public: |
|
2125 class properties : public base_properties |
|
2126 { |
|
2127 public: |
|
2128 // See the genprops.awk script for an explanation of the |
|
2129 // properties declarations. |
|
2130 |
7363
|
2131 BEGIN_PROPERTIES(text) |
|
2132 string_property string , "" |
|
2133 radio_property units , "{data}|pixels|normalized|inches|centimeters|points" |
|
2134 array_property position , Matrix (1, 3, 0.0) |
|
2135 double_property rotation , 0 |
|
2136 radio_property horizontalalignment , "{left}|center|right" |
|
2137 color_property color , color_values (0, 0, 0) |
|
2138 string_property fontname , "Helvetica" |
|
2139 double_property fontsize , 10 |
7379
|
2140 radio_property fontangle , "{normal}|italic|oblique" |
|
2141 radio_property fontweight , "light|{normal}|demi|bold" |
|
2142 radio_property interpreter , "{tex}|none|latex" |
7377
|
2143 color_property backgroundcolor , "{none}" |
|
2144 string_property displayname , "" |
|
2145 color_property edgecolor , "{none}" |
7380
|
2146 radio_property erasemode , "{normal}|none|xor|background" |
7377
|
2147 bool_property editing , "off" |
|
2148 radio_property fontunits , "inches|centimeters|normalized|{points}|pixel" |
|
2149 radio_property linestyle , "{-}|--|:|-.|none" |
|
2150 double_property linewidth , 0.5 |
|
2151 double_property margin , 1 |
|
2152 radio_property verticalalignment , "top|cap|{middle}|baseline|bottom" |
6874
|
2153 END_PROPERTIES |
|
2154 |
7363
|
2155 protected: |
|
2156 void init (void) |
|
2157 { |
|
2158 position.add_constraint (dim_vector (1, 3)); |
|
2159 } |
6874
|
2160 }; |
|
2161 |
|
2162 private: |
|
2163 properties xproperties; |
|
2164 |
|
2165 public: |
|
2166 text (const graphics_handle& mh, const graphics_handle& p) |
|
2167 : base_graphics_object (), xproperties (mh, p) |
|
2168 { |
|
2169 xproperties.override_defaults (*this); |
|
2170 } |
|
2171 |
|
2172 ~text (void) { xproperties.delete_children (); } |
|
2173 |
|
2174 base_properties& get_properties (void) { return xproperties; } |
|
2175 |
7222
|
2176 const base_properties& get_properties (void) const { return xproperties; } |
|
2177 |
6874
|
2178 bool valid_object (void) const { return true; } |
|
2179 }; |
|
2180 |
|
2181 // --------------------------------------------------------------------- |
|
2182 |
7365
|
2183 class OCTINTERP_API image : public base_graphics_object |
6874
|
2184 { |
|
2185 public: |
|
2186 class properties : public base_properties |
|
2187 { |
|
2188 public: |
|
2189 // See the genprops.awk script for an explanation of the |
|
2190 // properties declarations. |
|
2191 |
7363
|
2192 BEGIN_PROPERTIES(image) |
|
2193 data_property xdata l , Matrix () |
|
2194 data_property ydata l , Matrix () |
|
2195 data_property cdata l , Matrix () |
6874
|
2196 END_PROPERTIES |
|
2197 |
7363
|
2198 protected: |
|
2199 void init (void) |
|
2200 { |
|
2201 } |
6874
|
2202 }; |
|
2203 |
|
2204 private: |
|
2205 properties xproperties; |
|
2206 |
|
2207 public: |
|
2208 image (const graphics_handle& mh, const graphics_handle& p) |
|
2209 : base_graphics_object (), xproperties (mh, p) |
|
2210 { |
|
2211 xproperties.override_defaults (*this); |
|
2212 } |
|
2213 |
|
2214 ~image (void) { xproperties.delete_children (); } |
|
2215 |
|
2216 base_properties& get_properties (void) { return xproperties; } |
|
2217 |
7222
|
2218 const base_properties& get_properties (void) const { return xproperties; } |
|
2219 |
6874
|
2220 bool valid_object (void) const { return true; } |
|
2221 }; |
|
2222 |
|
2223 // --------------------------------------------------------------------- |
|
2224 |
7365
|
2225 class OCTINTERP_API patch : public base_graphics_object |
6874
|
2226 { |
|
2227 public: |
|
2228 class properties : public base_properties |
|
2229 { |
|
2230 public: |
|
2231 // See the genprops.awk script for an explanation of the |
|
2232 // properties declarations. |
|
2233 |
7363
|
2234 BEGIN_PROPERTIES(patch) |
7403
|
2235 data_property xdata l , Matrix () |
7363
|
2236 data_property ydata l , Matrix () |
|
2237 data_property zdata l , Matrix () |
|
2238 data_property cdata l , Matrix () |
7379
|
2239 radio_property cdatamapping , "{scaled}|direct" |
7363
|
2240 array_property faces , Matrix () |
7368
|
2241 data_property facevertexalphadata , Matrix () |
|
2242 data_property facevertexcdata , Matrix () |
7363
|
2243 array_property vertices , Matrix () |
7368
|
2244 array_property vertexnormals , Matrix () |
7379
|
2245 radio_property normalmode , "{auto}|manual" |
|
2246 color_property facecolor , "{flat}|none|interp" |
7363
|
2247 double_property facealpha , 1.0 |
7379
|
2248 radio_property facelighting , "{flat}|none|gouraud|phong" |
|
2249 color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
7368
|
2250 double_property edgealpha , 1.0 |
7379
|
2251 radio_property edgelighting , "{none}|flat|gouraud|phong" |
|
2252 radio_property backfacelighting , "{reverselit}|unlit|lit" |
7368
|
2253 double_property ambientstrength , 0.3 |
|
2254 double_property diffusestrength , 0.6 |
|
2255 double_property specularstrength , 0.6 |
|
2256 double_property specularexponent , 10.0 |
|
2257 double_property specularcolorreflectance , 1.0 |
7379
|
2258 radio_property erasemode , "{normal}|background|xor|none" |
7363
|
2259 radio_property linestyle , "{-}|--|:|-.|none" |
|
2260 double_property linewidth , 0.5 |
|
2261 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2262 color_property markeredgecolor , "{auto}|none" |
|
2263 color_property markerfacecolor , "auto|{none}" |
|
2264 double_property markersize , 6 |
|
2265 string_property keylabel , "" |
7384
|
2266 radio_property interpreter , "{tex}|none|latex" |
6874
|
2267 END_PROPERTIES |
|
2268 |
7363
|
2269 protected: |
|
2270 void init (void) |
|
2271 { |
|
2272 vertices.add_constraint (dim_vector (-1, 2)); |
|
2273 vertices.add_constraint (dim_vector (-1, 3)); |
|
2274 } |
6874
|
2275 }; |
|
2276 |
|
2277 private: |
|
2278 properties xproperties; |
|
2279 |
|
2280 public: |
|
2281 patch (const graphics_handle& mh, const graphics_handle& p) |
|
2282 : base_graphics_object (), xproperties (mh, p) |
|
2283 { |
|
2284 xproperties.override_defaults (*this); |
|
2285 } |
|
2286 |
|
2287 ~patch (void) { xproperties.delete_children (); } |
|
2288 |
|
2289 base_properties& get_properties (void) { return xproperties; } |
|
2290 |
7222
|
2291 const base_properties& get_properties (void) const { return xproperties; } |
|
2292 |
6874
|
2293 bool valid_object (void) const { return true; } |
|
2294 }; |
|
2295 |
|
2296 // --------------------------------------------------------------------- |
|
2297 |
7365
|
2298 class OCTINTERP_API surface : public base_graphics_object |
6874
|
2299 { |
|
2300 public: |
|
2301 class properties : public base_properties |
|
2302 { |
|
2303 public: |
|
2304 // See the genprops.awk script for an explanation of the |
|
2305 // properties declarations. |
|
2306 |
7363
|
2307 BEGIN_PROPERTIES(surface) |
|
2308 data_property xdata l , Matrix () |
|
2309 data_property ydata l , Matrix () |
|
2310 data_property zdata l , Matrix () |
|
2311 data_property cdata l , Matrix () |
7379
|
2312 color_property facecolor , "{flat}|none|interp" |
7363
|
2313 double_property facealpha , 1.0 |
7379
|
2314 color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
7363
|
2315 radio_property linestyle , "{-}|--|:|-.|none" |
|
2316 double_property linewidth , 0.5 |
|
2317 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2318 color_property markeredgecolor , "{auto}|none" |
|
2319 color_property markerfacecolor , "auto|{none}" |
|
2320 double_property markersize , 6 |
|
2321 string_property keylabel , "" |
7384
|
2322 radio_property interpreter , "{tex}|none|latex" |
6874
|
2323 END_PROPERTIES |
|
2324 |
7363
|
2325 protected: |
|
2326 void init (void) |
|
2327 { |
|
2328 } |
6874
|
2329 }; |
|
2330 |
|
2331 private: |
|
2332 properties xproperties; |
|
2333 |
|
2334 public: |
|
2335 surface (const graphics_handle& mh, const graphics_handle& p) |
|
2336 : base_graphics_object (), xproperties (mh, p) |
|
2337 { |
|
2338 xproperties.override_defaults (*this); |
|
2339 } |
|
2340 |
|
2341 ~surface (void) { xproperties.delete_children (); } |
|
2342 |
|
2343 base_properties& get_properties (void) { return xproperties; } |
|
2344 |
7222
|
2345 const base_properties& get_properties (void) const { return xproperties; } |
|
2346 |
6874
|
2347 bool valid_object (void) const { return true; } |
|
2348 }; |
|
2349 |
|
2350 octave_value |
|
2351 get_property_from_handle (double handle, const std::string &property, |
|
2352 const std::string &func); |
|
2353 bool |
|
2354 set_property_in_handle (double handle, const std::string &property, |
|
2355 const octave_value &arg, const std::string &func); |
|
2356 |
|
2357 // --------------------------------------------------------------------- |
|
2358 |
7365
|
2359 class OCTINTERP_API gh_manager |
6874
|
2360 { |
|
2361 protected: |
|
2362 |
|
2363 gh_manager (void); |
|
2364 |
|
2365 public: |
|
2366 |
|
2367 static bool instance_ok (void) |
|
2368 { |
|
2369 bool retval = true; |
|
2370 |
|
2371 if (! instance) |
|
2372 instance = new gh_manager (); |
|
2373 |
|
2374 if (! instance) |
|
2375 { |
|
2376 ::error ("unable to create gh_manager!"); |
|
2377 |
|
2378 retval = false; |
|
2379 } |
|
2380 |
|
2381 return retval; |
|
2382 } |
|
2383 |
|
2384 static void free (const graphics_handle& h) |
|
2385 { |
|
2386 if (instance_ok ()) |
|
2387 instance->do_free (h); |
|
2388 } |
|
2389 |
|
2390 static graphics_handle lookup (double val) |
|
2391 { |
|
2392 return instance_ok () ? instance->do_lookup (val) : graphics_handle (); |
|
2393 } |
|
2394 |
|
2395 static graphics_object get_object (const graphics_handle& h) |
|
2396 { |
|
2397 return instance_ok () ? instance->do_get_object (h) : graphics_object (); |
|
2398 } |
|
2399 |
|
2400 static graphics_handle |
|
2401 make_graphics_handle (const std::string& go_name, |
7370
|
2402 const graphics_handle& parent, bool do_createfcn = true) |
6874
|
2403 { |
|
2404 return instance_ok () |
7370
|
2405 ? instance->do_make_graphics_handle (go_name, parent, do_createfcn) |
6874
|
2406 : graphics_handle (); |
|
2407 } |
|
2408 |
|
2409 static graphics_handle make_figure_handle (double val) |
|
2410 { |
|
2411 return instance_ok () |
|
2412 ? instance->do_make_figure_handle (val) : graphics_handle (); |
|
2413 } |
|
2414 |
|
2415 static void push_figure (const graphics_handle& h) |
|
2416 { |
|
2417 if (instance_ok ()) |
|
2418 instance->do_push_figure (h); |
|
2419 } |
|
2420 |
|
2421 static void pop_figure (const graphics_handle& h) |
|
2422 { |
|
2423 if (instance_ok ()) |
|
2424 instance->do_pop_figure (h); |
|
2425 } |
|
2426 |
|
2427 static graphics_handle current_figure (void) |
|
2428 { |
|
2429 return instance_ok () |
|
2430 ? instance->do_current_figure () : graphics_handle (); |
|
2431 } |
|
2432 |
|
2433 static Matrix handle_list (void) |
|
2434 { |
|
2435 return instance_ok () ? instance->do_handle_list () : Matrix (); |
|
2436 } |
|
2437 |
|
2438 static Matrix figure_handle_list (void) |
|
2439 { |
|
2440 return instance_ok () ? instance->do_figure_handle_list () : Matrix (); |
|
2441 } |
|
2442 |
|
2443 private: |
|
2444 |
|
2445 static gh_manager *instance; |
|
2446 |
|
2447 typedef std::map<graphics_handle, graphics_object>::iterator iterator; |
|
2448 typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator; |
|
2449 |
|
2450 typedef std::set<graphics_handle>::iterator free_list_iterator; |
|
2451 typedef std::set<graphics_handle>::const_iterator const_free_list_iterator; |
|
2452 |
|
2453 typedef std::list<graphics_handle>::iterator figure_list_iterator; |
|
2454 typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator; |
|
2455 |
|
2456 // A map of handles to graphics objects. |
|
2457 std::map<graphics_handle, graphics_object> handle_map; |
|
2458 |
|
2459 // The available graphics handles. |
|
2460 std::set<graphics_handle> handle_free_list; |
|
2461 |
|
2462 // The next handle available if handle_free_list is empty. |
7286
|
2463 double next_handle; |
6874
|
2464 |
|
2465 // The allocated figure handles. Top of the stack is most recently |
|
2466 // created. |
|
2467 std::list<graphics_handle> figure_list; |
|
2468 |
|
2469 graphics_handle get_handle (const std::string& go_name); |
|
2470 |
|
2471 void do_free (const graphics_handle& h); |
|
2472 |
|
2473 graphics_handle do_lookup (double val) |
|
2474 { |
7363
|
2475 iterator p = (xisnan (val) ? handle_map.end () : handle_map.find (val)); |
6874
|
2476 |
|
2477 return (p != handle_map.end ()) ? p->first : graphics_handle (); |
|
2478 } |
|
2479 |
|
2480 graphics_object do_get_object (const graphics_handle& h) |
|
2481 { |
7379
|
2482 iterator p = (h.ok () ? handle_map.find (h) : handle_map.end ()); |
6874
|
2483 |
|
2484 return (p != handle_map.end ()) ? p->second : graphics_object (); |
|
2485 } |
|
2486 |
|
2487 graphics_handle do_make_graphics_handle (const std::string& go_name, |
7370
|
2488 const graphics_handle& p, bool do_createfcn); |
6874
|
2489 |
|
2490 graphics_handle do_make_figure_handle (double val); |
|
2491 |
|
2492 Matrix do_handle_list (void) |
|
2493 { |
|
2494 Matrix retval (1, handle_map.size ()); |
|
2495 octave_idx_type i = 0; |
|
2496 for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++) |
7056
|
2497 { |
|
2498 graphics_handle h = p->first; |
|
2499 retval(i++) = h.value (); |
|
2500 } |
6874
|
2501 return retval; |
|
2502 } |
|
2503 |
|
2504 Matrix do_figure_handle_list (void) |
|
2505 { |
|
2506 Matrix retval (1, figure_list.size ()); |
|
2507 octave_idx_type i = 0; |
|
2508 for (const_figure_list_iterator p = figure_list.begin (); |
|
2509 p != figure_list.end (); |
|
2510 p++) |
7056
|
2511 { |
|
2512 graphics_handle h = *p; |
|
2513 retval(i++) = h.value (); |
|
2514 } |
6874
|
2515 return retval; |
|
2516 } |
|
2517 |
|
2518 void do_push_figure (const graphics_handle& h); |
|
2519 |
|
2520 void do_pop_figure (const graphics_handle& h); |
|
2521 |
|
2522 graphics_handle do_current_figure (void) const |
|
2523 { |
|
2524 return figure_list.empty () ? graphics_handle () : figure_list.front (); |
|
2525 } |
|
2526 }; |
|
2527 |
|
2528 |
|
2529 // This function is NOT equivalent to the scripting language function gcf. |
7365
|
2530 OCTINTERP_API graphics_handle gcf (void); |
6874
|
2531 |
|
2532 // This function is NOT equivalent to the scripting language function gca. |
7365
|
2533 OCTINTERP_API graphics_handle gca (void); |
6874
|
2534 |
|
2535 #endif |
|
2536 |
|
2537 /* |
|
2538 ;;; Local Variables: *** |
|
2539 ;;; mode: C++ *** |
|
2540 ;;; End: *** |
|
2541 */ |