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), |
7406
|
971 createfcn ("createfcn", mh, Matrix ()), |
7367
|
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 (); } |
7408
|
1055 |
|
1056 bool is_visible (void) const { return visible.is_on (); } |
7366
|
1057 std::string get_visible (void) const { return visible.current_value (); } |
|
1058 |
7403
|
1059 bool is_beingdeleted (void) const { return beingdeleted.is_on (); } |
|
1060 std::string get_beingdeleted (void) const { return beingdeleted.current_value (); } |
|
1061 |
7386
|
1062 virtual void remove_child (const graphics_handle& h); |
|
1063 |
|
1064 virtual void adopt (const graphics_handle& h) |
6874
|
1065 { |
|
1066 octave_idx_type n = children.numel (); |
|
1067 children.resize (1, n+1); |
7056
|
1068 children(n) = h.value (); |
6874
|
1069 } |
|
1070 |
7363
|
1071 void set_tag (const octave_value& val) { tag = val; } |
7176
|
1072 |
6874
|
1073 void set_parent (const octave_value& val); |
|
1074 |
7408
|
1075 void set_modified (const octave_value& val) { __modified__ = val; } |
|
1076 |
7366
|
1077 void set_busyaction (const octave_value& val) |
|
1078 { |
|
1079 if (! error_state) |
|
1080 { |
|
1081 busyaction = val; |
|
1082 mark_modified (); |
|
1083 } |
|
1084 } |
|
1085 |
|
1086 void set_buttondownfcn (const octave_value& val) |
|
1087 { |
|
1088 if (! error_state) |
|
1089 { |
|
1090 buttondownfcn = val; |
|
1091 mark_modified (); |
|
1092 } |
|
1093 } |
|
1094 |
|
1095 void set_clipping (const octave_value& val) |
|
1096 { |
|
1097 if (! error_state) |
|
1098 { |
|
1099 clipping = val; |
|
1100 mark_modified (); |
|
1101 } |
|
1102 } |
|
1103 |
|
1104 void set_createfcn (const octave_value& val) |
|
1105 { |
|
1106 if (! error_state) |
|
1107 { |
|
1108 createfcn = val; |
|
1109 mark_modified (); |
|
1110 } |
|
1111 } |
|
1112 |
|
1113 void set_deletefcn (const octave_value& val) |
|
1114 { |
|
1115 if (! error_state) |
|
1116 { |
|
1117 deletefcn = val; |
|
1118 mark_modified (); |
|
1119 } |
|
1120 } |
|
1121 |
|
1122 void set_handlevisibility (const octave_value& val) |
|
1123 { |
|
1124 if (! error_state) |
|
1125 { |
|
1126 handlevisibility = val; |
|
1127 mark_modified (); |
|
1128 } |
|
1129 } |
|
1130 |
|
1131 void set_hittest (const octave_value& val) |
|
1132 { |
|
1133 if (! error_state) |
|
1134 { |
|
1135 hittest = val; |
|
1136 mark_modified (); |
|
1137 } |
|
1138 } |
|
1139 |
|
1140 void set_interruptible (const octave_value& val) |
|
1141 { |
|
1142 if (! error_state) |
|
1143 { |
|
1144 interruptible = val; |
|
1145 mark_modified (); |
|
1146 } |
|
1147 } |
|
1148 |
|
1149 void set_selected (const octave_value& val) |
|
1150 { |
|
1151 if (! error_state) |
|
1152 { |
|
1153 selected = val; |
|
1154 mark_modified (); |
|
1155 } |
|
1156 } |
|
1157 |
|
1158 void set_selectionhighlight (const octave_value& val) |
|
1159 { |
|
1160 if (! error_state) |
|
1161 { |
|
1162 selectionhighlight = val; |
|
1163 mark_modified (); |
|
1164 } |
|
1165 } |
|
1166 |
|
1167 void set_uicontextmenu (const octave_value& val) |
|
1168 { |
|
1169 if (! error_state) |
|
1170 { |
|
1171 uicontextmenu = val; |
|
1172 mark_modified (); |
|
1173 } |
|
1174 } |
|
1175 |
|
1176 void set_userdata (const octave_value& val) |
|
1177 { |
|
1178 if (! error_state) |
|
1179 { |
|
1180 userdata = val; |
|
1181 mark_modified (); |
|
1182 } |
|
1183 } |
|
1184 |
|
1185 virtual void set_visible (const octave_value& val) |
|
1186 { |
|
1187 if (! error_state) |
|
1188 { |
|
1189 visible = val; |
|
1190 mark_modified (); |
|
1191 } |
|
1192 } |
|
1193 |
7403
|
1194 void set_beingdeleted (const octave_value& val) |
|
1195 { |
|
1196 if (! error_state) |
|
1197 { |
|
1198 beingdeleted = val; |
|
1199 mark_modified (); |
|
1200 } |
|
1201 } |
|
1202 |
7366
|
1203 |
|
1204 |
6874
|
1205 void reparent (const graphics_handle& new_parent) { parent = new_parent; } |
|
1206 |
7214
|
1207 // Update data limits for AXIS_TYPE (xdata, ydata, etc.) in the parent |
|
1208 // axes object. |
|
1209 |
7386
|
1210 virtual void update_axis_limits (const std::string& axis_type) const; |
7214
|
1211 |
6874
|
1212 virtual void delete_children (void); |
|
1213 |
7222
|
1214 Matrix get_children (void) const { return children; } |
|
1215 |
|
1216 // FIXME -- these functions should be generated automatically by the |
|
1217 // genprops.awk script. |
|
1218 // |
|
1219 // EMIT_BASE_PROPERTIES_GET_FUNCTIONS |
7363
|
1220 virtual data_property get_xdata_property (void) const |
7222
|
1221 { |
|
1222 error ("get: invalid property \"xdata\""); |
|
1223 return data_property (); |
|
1224 } |
|
1225 |
7363
|
1226 virtual data_property get_ydata_property (void) const |
7222
|
1227 { |
|
1228 error ("get: invalid property \"ydata\""); |
|
1229 return data_property (); |
|
1230 } |
|
1231 |
7363
|
1232 virtual data_property get_zdata_property (void) const |
7222
|
1233 { |
|
1234 error ("get: invalid property \"zdata\""); |
|
1235 return data_property (); |
|
1236 } |
|
1237 |
7363
|
1238 virtual data_property get_ldata_property (void) const |
7222
|
1239 { |
|
1240 error ("get: invalid property \"ldata\""); |
|
1241 return data_property (); |
|
1242 } |
|
1243 |
7363
|
1244 virtual data_property get_udata_property (void) const |
7222
|
1245 { |
|
1246 error ("get: invalid property \"udata\""); |
|
1247 return data_property (); |
|
1248 } |
|
1249 |
7363
|
1250 virtual data_property get_xldata_property (void) const |
7222
|
1251 { |
|
1252 error ("get: invalid property \"xldata\""); |
|
1253 return data_property (); |
|
1254 } |
|
1255 |
7363
|
1256 virtual data_property get_xudata_property (void) const |
7222
|
1257 { |
|
1258 error ("get: invalid property \"xudata\""); |
|
1259 return data_property (); |
|
1260 } |
|
1261 |
7363
|
1262 virtual data_property get_cdata_property (void) const |
7222
|
1263 { |
|
1264 error ("get: invalid property \"cdata\""); |
|
1265 return data_property (); |
|
1266 } |
|
1267 |
6874
|
1268 protected: |
7403
|
1269 // properties common to all objects |
|
1270 bool_property beingdeleted; |
|
1271 radio_property busyaction; |
|
1272 callback_property buttondownfcn; |
7363
|
1273 // FIXME: use a property class for children |
6874
|
1274 Matrix children; |
7366
|
1275 bool_property clipping; |
|
1276 callback_property createfcn; |
|
1277 callback_property deletefcn; |
|
1278 radio_property handlevisibility; |
|
1279 bool_property hittest; |
|
1280 bool_property interruptible; |
7403
|
1281 handle_property parent; |
7366
|
1282 bool_property selected; |
|
1283 bool_property selectionhighlight; |
7403
|
1284 string_property tag; |
|
1285 string_property type; |
7366
|
1286 any_property userdata; |
|
1287 bool_property visible; |
7403
|
1288 // additional (octave-specific) properties |
|
1289 bool_property __modified__; |
|
1290 graphics_handle __myhandle__; |
|
1291 // FIXME: should this really be here? |
|
1292 handle_property uicontextmenu; |
7363
|
1293 |
|
1294 protected: |
|
1295 std::map<caseless_str, property> all_props; |
|
1296 |
|
1297 protected: |
|
1298 void insert_static_property (const std::string& name, base_property& p) |
|
1299 { insert_property (name, property (&p, true)); } |
|
1300 |
|
1301 virtual void init (void) { } |
6874
|
1302 }; |
|
1303 |
7365
|
1304 class OCTINTERP_API base_graphics_object |
6874
|
1305 { |
|
1306 public: |
|
1307 friend class graphics_object; |
|
1308 |
|
1309 base_graphics_object (void) : count (1) { } |
|
1310 |
|
1311 base_graphics_object (const base_graphics_object&) { } |
|
1312 |
|
1313 virtual ~base_graphics_object (void) { } |
|
1314 |
|
1315 virtual void mark_modified (void) |
|
1316 { |
7386
|
1317 if (valid_object ()) |
|
1318 get_properties ().mark_modified (); |
|
1319 else |
|
1320 error ("base_graphics_object::mark_modified: invalid graphics object"); |
6874
|
1321 } |
|
1322 |
7386
|
1323 virtual void override_defaults (base_graphics_object& obj) |
6874
|
1324 { |
7386
|
1325 if (valid_object ()) |
|
1326 get_properties ().override_defaults (obj); |
|
1327 else |
|
1328 error ("base_graphics_object::override_defaults: invalid graphics object"); |
6874
|
1329 } |
|
1330 |
7386
|
1331 virtual void set_from_list (property_list& plist) |
6874
|
1332 { |
7386
|
1333 if (valid_object ()) |
|
1334 get_properties ().set_from_list (*this, plist); |
|
1335 else |
|
1336 error ("base_graphics_object::set_from_list: invalid graphics object"); |
6874
|
1337 } |
|
1338 |
7386
|
1339 virtual void set (const caseless_str& pname, const octave_value& pval) |
6874
|
1340 { |
7386
|
1341 if (valid_object ()) |
|
1342 get_properties ().set (pname, pval); |
|
1343 else |
|
1344 error ("base_graphics_object::set: invalid graphics object"); |
6874
|
1345 } |
|
1346 |
|
1347 virtual void set_defaults (const std::string&) |
|
1348 { |
|
1349 error ("base_graphics_object::set_defaults: invalid graphics object"); |
|
1350 } |
|
1351 |
7379
|
1352 virtual octave_value get (bool all = false) const |
6874
|
1353 { |
7386
|
1354 if (valid_object ()) |
|
1355 return get_properties ().get (all); |
|
1356 else |
|
1357 { |
|
1358 error ("base_graphics_object::get: invalid graphics object"); |
|
1359 return octave_value (); |
|
1360 } |
6874
|
1361 } |
|
1362 |
7386
|
1363 virtual octave_value get (const caseless_str& pname) const |
6874
|
1364 { |
7386
|
1365 if (valid_object ()) |
|
1366 return get_properties ().get (pname); |
|
1367 else |
|
1368 { |
|
1369 error ("base_graphics_object::get: invalid graphics object"); |
|
1370 return octave_value (); |
|
1371 } |
6874
|
1372 } |
|
1373 |
7189
|
1374 virtual octave_value get_default (const caseless_str&) const; |
6874
|
1375 |
7189
|
1376 virtual octave_value get_factory_default (const caseless_str&) const; |
6874
|
1377 |
|
1378 virtual octave_value get_defaults (void) const |
|
1379 { |
|
1380 error ("base_graphics_object::get_defaults: invalid graphics object"); |
|
1381 return octave_value (); |
|
1382 } |
|
1383 |
|
1384 virtual octave_value get_factory_defaults (void) const |
|
1385 { |
|
1386 error ("base_graphics_object::get_factory_defaults: invalid graphics object"); |
|
1387 return octave_value (); |
|
1388 } |
|
1389 |
|
1390 virtual graphics_handle get_parent (void) const |
|
1391 { |
7386
|
1392 if (valid_object ()) |
|
1393 return get_properties ().get_parent (); |
|
1394 else |
|
1395 { |
|
1396 error ("base_graphics_object::get_parent: invalid graphics object"); |
|
1397 return graphics_handle (); |
|
1398 } |
6874
|
1399 } |
|
1400 |
7386
|
1401 virtual void remove_child (const graphics_handle& h) |
6874
|
1402 { |
7386
|
1403 if (valid_object ()) |
|
1404 get_properties ().remove_child (h); |
|
1405 else |
|
1406 error ("base_graphics_object::remove_child: invalid graphics object"); |
6874
|
1407 } |
|
1408 |
7386
|
1409 virtual void adopt (const graphics_handle& h) |
6874
|
1410 { |
7386
|
1411 if (valid_object ()) |
|
1412 get_properties ().adopt (h); |
|
1413 else |
|
1414 error ("base_graphics_object::adopt: invalid graphics object"); |
6874
|
1415 } |
|
1416 |
7386
|
1417 virtual void reparent (const graphics_handle& np) |
6874
|
1418 { |
7386
|
1419 if (valid_object ()) |
|
1420 get_properties ().reparent (np); |
|
1421 else |
|
1422 error ("base_graphics_object::reparent: invalid graphics object"); |
6874
|
1423 } |
|
1424 |
|
1425 virtual void defaults (void) const |
|
1426 { |
7386
|
1427 if (valid_object ()) |
|
1428 { |
|
1429 std::string msg = (type () + "::defaults"); |
|
1430 gripe_not_implemented (msg.c_str ()); |
|
1431 } |
|
1432 else |
|
1433 error ("base_graphics_object::default: invalid graphics object"); |
6874
|
1434 } |
|
1435 |
|
1436 virtual base_properties& get_properties (void) |
|
1437 { |
|
1438 static base_properties properties; |
|
1439 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
1440 return properties; |
|
1441 } |
|
1442 |
7222
|
1443 virtual const base_properties& get_properties (void) const |
|
1444 { |
|
1445 static base_properties properties; |
|
1446 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
1447 return properties; |
|
1448 } |
|
1449 |
|
1450 virtual void update_axis_limits (const std::string&) |
7214
|
1451 { |
|
1452 error ("base_graphics_object::update_axis_limits: invalid graphics object"); |
|
1453 } |
|
1454 |
6874
|
1455 virtual bool valid_object (void) const { return false; } |
|
1456 |
7386
|
1457 virtual std::string type (void) const |
|
1458 { |
|
1459 return (valid_object () ? get_properties ().graphics_object_name () |
|
1460 : "unknown"); |
|
1461 } |
6874
|
1462 |
|
1463 bool isa (const std::string& go_name) const |
|
1464 { |
|
1465 return type () == go_name; |
|
1466 } |
|
1467 |
|
1468 protected: |
|
1469 // A reference count. |
|
1470 int count; |
|
1471 }; |
|
1472 |
7365
|
1473 class OCTINTERP_API graphics_object |
6874
|
1474 { |
|
1475 public: |
|
1476 graphics_object (void) : rep (new base_graphics_object ()) { } |
|
1477 |
|
1478 graphics_object (base_graphics_object *new_rep) |
|
1479 : rep (new_rep) { } |
|
1480 |
|
1481 graphics_object (const graphics_object& obj) |
|
1482 { |
|
1483 rep = obj.rep; |
|
1484 rep->count++; |
|
1485 } |
|
1486 |
|
1487 graphics_object& operator = (const graphics_object& obj) |
|
1488 { |
|
1489 if (rep != obj.rep) |
|
1490 { |
|
1491 if (--rep->count == 0) |
|
1492 delete rep; |
|
1493 |
|
1494 rep = obj.rep; |
|
1495 rep->count++; |
|
1496 } |
|
1497 |
|
1498 return *this; |
|
1499 } |
|
1500 |
|
1501 ~graphics_object (void) |
|
1502 { |
|
1503 if (--rep->count == 0) |
|
1504 delete rep; |
|
1505 } |
|
1506 |
|
1507 void mark_modified (void) { rep->mark_modified (); } |
|
1508 |
|
1509 void override_defaults (base_graphics_object& obj) |
|
1510 { |
|
1511 rep->override_defaults (obj); |
|
1512 } |
|
1513 |
7214
|
1514 void set_from_list (property_list& plist) { rep->set_from_list (plist); } |
6874
|
1515 |
7189
|
1516 void set (const caseless_str& name, const octave_value& val) |
6874
|
1517 { |
|
1518 rep->set (name, val); |
|
1519 } |
|
1520 |
|
1521 void set (const octave_value_list& args); |
|
1522 |
7214
|
1523 void set_defaults (const std::string& mode) { rep->set_defaults (mode); } |
|
1524 |
7379
|
1525 octave_value get (bool all = false) const { return rep->get (all); } |
6874
|
1526 |
7189
|
1527 octave_value get (const caseless_str& name) const |
6874
|
1528 { |
|
1529 return name.compare ("default") |
|
1530 ? get_defaults () |
|
1531 : (name.compare ("factory") |
|
1532 ? get_factory_defaults () : rep->get (name)); |
|
1533 } |
|
1534 |
7189
|
1535 octave_value get_default (const caseless_str& name) const |
6874
|
1536 { |
|
1537 return rep->get_default (name); |
|
1538 } |
|
1539 |
7189
|
1540 octave_value get_factory_default (const caseless_str& name) const |
6874
|
1541 { |
|
1542 return rep->get_factory_default (name); |
|
1543 } |
|
1544 |
|
1545 octave_value get_defaults (void) const { return rep->get_defaults (); } |
|
1546 |
|
1547 octave_value get_factory_defaults (void) const |
|
1548 { |
|
1549 return rep->get_factory_defaults (); |
|
1550 } |
|
1551 |
|
1552 graphics_handle get_parent (void) const { return rep->get_parent (); } |
|
1553 |
7214
|
1554 void remove_child (const graphics_handle& h) { rep->remove_child (h); } |
|
1555 |
|
1556 void adopt (const graphics_handle& h) { rep->adopt (h); } |
|
1557 |
|
1558 void reparent (const graphics_handle& h) { rep->reparent (h); } |
6874
|
1559 |
|
1560 void defaults (void) const { rep->defaults (); } |
|
1561 |
|
1562 bool isa (const std::string& go_name) const { return rep->isa (go_name); } |
|
1563 |
|
1564 base_properties& get_properties (void) { return rep->get_properties (); } |
|
1565 |
7222
|
1566 const base_properties& get_properties (void) const |
|
1567 { |
|
1568 return rep->get_properties (); |
|
1569 } |
|
1570 |
7214
|
1571 void update_axis_limits (const std::string& axis_type) |
|
1572 { |
|
1573 rep->update_axis_limits (axis_type); |
|
1574 } |
|
1575 |
6874
|
1576 bool valid_object (void) const { return rep->valid_object (); } |
|
1577 |
|
1578 operator bool (void) const { return rep->valid_object (); } |
|
1579 |
7222
|
1580 // FIXME -- these functions should be generated automatically by the |
|
1581 // genprops.awk script. |
|
1582 // |
|
1583 // EMIT_GRAPHICS_OBJECT_GET_FUNCTIONS |
7363
|
1584 data_property get_xdata_property (void) const |
7222
|
1585 { |
|
1586 const base_properties& props = get_properties (); |
7363
|
1587 return props.get_xdata_property (); |
7222
|
1588 } |
|
1589 |
7363
|
1590 data_property get_ydata_property (void) const |
7222
|
1591 { |
|
1592 const base_properties& props = get_properties (); |
7363
|
1593 return props.get_ydata_property (); |
7222
|
1594 } |
|
1595 |
7363
|
1596 data_property get_zdata_property (void) const |
7222
|
1597 { |
|
1598 const base_properties& props = get_properties (); |
7363
|
1599 return props.get_zdata_property (); |
7222
|
1600 } |
|
1601 |
7363
|
1602 data_property get_ldata_property (void) const |
7222
|
1603 { |
|
1604 const base_properties& props = get_properties (); |
7363
|
1605 return props.get_ldata_property (); |
7222
|
1606 } |
|
1607 |
7363
|
1608 data_property get_udata_property (void) const |
7222
|
1609 { |
|
1610 const base_properties& props = get_properties (); |
7363
|
1611 return props.get_udata_property (); |
7222
|
1612 } |
|
1613 |
7363
|
1614 data_property get_xldata_property (void) const |
7222
|
1615 { |
|
1616 const base_properties& props = get_properties (); |
7363
|
1617 return props.get_xldata_property (); |
7222
|
1618 } |
|
1619 |
7363
|
1620 data_property get_xudata_property (void) const |
7222
|
1621 { |
|
1622 const base_properties& props = get_properties (); |
7363
|
1623 return props.get_xudata_property (); |
7222
|
1624 } |
|
1625 |
7363
|
1626 data_property get_cdata_property (void) const |
7222
|
1627 { |
|
1628 const base_properties& props = get_properties (); |
7363
|
1629 return props.get_cdata_property (); |
7222
|
1630 } |
|
1631 |
6874
|
1632 private: |
|
1633 base_graphics_object *rep; |
|
1634 }; |
|
1635 |
|
1636 // --------------------------------------------------------------------- |
|
1637 |
7408
|
1638 class graphics_backend; |
|
1639 |
|
1640 class base_graphics_backend |
|
1641 { |
|
1642 public: |
|
1643 friend class graphics_backend; |
|
1644 |
|
1645 public: |
|
1646 base_graphics_backend (const std::string& nm) |
|
1647 : name (nm), count (0) { } |
|
1648 |
|
1649 virtual ~base_graphics_backend (void) { } |
|
1650 |
|
1651 std::string get_name (void) const { return name; } |
|
1652 |
|
1653 virtual bool is_valid (void) const { return false; } |
|
1654 |
|
1655 virtual void close_figure (const octave_value&) const |
|
1656 { error ("close_figure: invalid graphics backend"); } |
|
1657 |
|
1658 virtual void redraw_figure (const graphics_handle&) const |
|
1659 { error ("redraw_figure: invalid graphics backend"); } |
|
1660 |
|
1661 virtual void print_figure (const graphics_handle&, const std::string&, |
|
1662 const std::string&, bool, |
|
1663 const std::string& = "") const |
|
1664 { error ("print_figure: invalid graphics backend"); } |
|
1665 |
|
1666 virtual Matrix get_canvas_size (const graphics_handle&) const |
|
1667 { |
|
1668 error ("get_canvas_size: invalid graphics backend"); |
|
1669 return Matrix (1, 2, 0.0); |
|
1670 } |
|
1671 |
|
1672 private: |
|
1673 std::string name; |
|
1674 int count; |
|
1675 }; |
|
1676 |
|
1677 class graphics_backend |
|
1678 { |
|
1679 public: |
|
1680 graphics_backend (void) |
|
1681 : rep (new base_graphics_backend ("unknown")) |
|
1682 { |
|
1683 rep->count++; |
|
1684 } |
|
1685 |
|
1686 graphics_backend (base_graphics_backend* b) |
|
1687 : rep (b) |
|
1688 { |
|
1689 rep->count++; |
|
1690 } |
|
1691 |
|
1692 graphics_backend (const graphics_backend& b) |
|
1693 : rep (b.rep) |
|
1694 { |
|
1695 rep->count++; |
|
1696 } |
|
1697 |
|
1698 ~graphics_backend (void) |
|
1699 { |
|
1700 if (--rep->count == 0) |
|
1701 delete rep; |
|
1702 } |
|
1703 |
|
1704 graphics_backend& operator = (const graphics_backend& b) |
|
1705 { |
|
1706 if (rep != b.rep) |
|
1707 { |
|
1708 if (--rep->count == 0) |
|
1709 delete rep; |
|
1710 |
|
1711 rep = b.rep; |
|
1712 rep->count++; |
|
1713 } |
|
1714 |
|
1715 return *this; |
|
1716 } |
|
1717 |
|
1718 operator bool (void) const { return rep->is_valid (); } |
|
1719 |
|
1720 std::string get_name (void) const { return rep->get_name (); } |
|
1721 |
|
1722 void close_figure (const octave_value& pstream) const |
|
1723 { rep->close_figure (pstream); } |
|
1724 |
|
1725 void redraw_figure (const graphics_handle& fh) const |
|
1726 { rep->redraw_figure (fh); } |
|
1727 |
|
1728 void print_figure (const graphics_handle& fh, const std::string& term, |
|
1729 const std::string& file, bool mono, |
|
1730 const std::string& debug_file = "") const |
|
1731 { rep->print_figure (fh, term, file, mono, debug_file); } |
|
1732 |
|
1733 Matrix get_canvas_size (const graphics_handle& fh) const |
|
1734 { return rep->get_canvas_size (fh); } |
|
1735 |
|
1736 OCTINTERP_API static graphics_backend default_backend (void); |
|
1737 |
|
1738 static void register_backend (const graphics_backend& b) |
|
1739 { available_backends[b.get_name ()] = b; } |
|
1740 |
|
1741 static void unregister_backend (const std::string& name) |
|
1742 { available_backends.erase (name); } |
|
1743 |
|
1744 private: |
|
1745 base_graphics_backend *rep; |
|
1746 |
|
1747 private: |
|
1748 static std::map<std::string, graphics_backend> available_backends; |
|
1749 }; |
|
1750 |
|
1751 // --------------------------------------------------------------------- |
|
1752 |
7365
|
1753 class OCTINTERP_API root_figure : public base_graphics_object |
6874
|
1754 { |
|
1755 public: |
|
1756 class properties : public base_properties |
|
1757 { |
|
1758 public: |
|
1759 // See the genprops.awk script for an explanation of the |
|
1760 // properties declarations. |
|
1761 |
7363
|
1762 BEGIN_PROPERTIES(root_figure) |
|
1763 handle_property currentfigure S , graphics_handle () |
6874
|
1764 END_PROPERTIES |
|
1765 }; |
|
1766 |
|
1767 private: |
|
1768 properties xproperties; |
|
1769 |
|
1770 public: |
|
1771 |
7363
|
1772 root_figure (void) : xproperties (0, graphics_handle ()), default_properties () { } |
6874
|
1773 |
|
1774 ~root_figure (void) { xproperties.delete_children (); } |
|
1775 |
|
1776 void mark_modified (void) { } |
|
1777 |
|
1778 void override_defaults (base_graphics_object& obj) |
|
1779 { |
|
1780 // Now override with our defaults. If the default_properties |
|
1781 // list includes the properties for all defaults (line, |
|
1782 // surface, etc.) then we don't have to know the type of OBJ |
|
1783 // here, we just call its set function and let it decide which |
|
1784 // properties from the list to use. |
|
1785 obj.set_from_list (default_properties); |
|
1786 } |
|
1787 |
7189
|
1788 void set (const caseless_str& name, const octave_value& value) |
6874
|
1789 { |
|
1790 if (name.compare ("default", 7)) |
|
1791 // strip "default", pass rest to function that will |
|
1792 // parse the remainder and add the element to the |
|
1793 // default_properties map. |
|
1794 default_properties.set (name.substr (7), value); |
|
1795 else |
|
1796 xproperties.set (name, value); |
|
1797 } |
|
1798 |
7189
|
1799 octave_value get (const caseless_str& name) const |
6874
|
1800 { |
|
1801 octave_value retval; |
|
1802 |
|
1803 if (name.compare ("default", 7)) |
|
1804 return get_default (name.substr (7)); |
|
1805 else if (name.compare ("factory", 7)) |
|
1806 return get_factory_default (name.substr (7)); |
|
1807 else |
|
1808 retval = xproperties.get (name); |
|
1809 |
|
1810 return retval; |
|
1811 } |
|
1812 |
7189
|
1813 octave_value get_default (const caseless_str& name) const |
6874
|
1814 { |
|
1815 octave_value retval = default_properties.lookup (name); |
|
1816 |
|
1817 if (retval.is_undefined ()) |
|
1818 error ("get: invalid default property `%s'", name.c_str ()); |
|
1819 |
|
1820 return retval; |
|
1821 } |
|
1822 |
7189
|
1823 octave_value get_factory_default (const caseless_str& name) const |
6874
|
1824 { |
|
1825 octave_value retval = factory_properties.lookup (name); |
|
1826 |
|
1827 if (retval.is_undefined ()) |
|
1828 error ("get: invalid factory default property `%s'", name.c_str ()); |
|
1829 |
|
1830 return retval; |
|
1831 } |
|
1832 |
|
1833 octave_value get_defaults (void) const |
|
1834 { |
|
1835 return default_properties.as_struct ("default"); |
|
1836 } |
|
1837 |
|
1838 octave_value get_factory_defaults (void) const |
|
1839 { |
|
1840 return factory_properties.as_struct ("factory"); |
|
1841 } |
|
1842 |
|
1843 base_properties& get_properties (void) { return xproperties; } |
|
1844 |
7222
|
1845 const base_properties& get_properties (void) const { return xproperties; } |
|
1846 |
6874
|
1847 bool valid_object (void) const { return true; } |
|
1848 |
|
1849 private: |
|
1850 property_list default_properties; |
|
1851 |
|
1852 static property_list factory_properties; |
|
1853 |
|
1854 static property_list::plist_map_type init_factory_properties (void); |
|
1855 }; |
|
1856 |
|
1857 // --------------------------------------------------------------------- |
|
1858 |
7365
|
1859 class OCTINTERP_API figure : public base_graphics_object |
6874
|
1860 { |
|
1861 public: |
|
1862 class properties : public base_properties |
|
1863 { |
|
1864 public: |
7408
|
1865 void close (bool pop = true); |
|
1866 |
7366
|
1867 void set_visible (const octave_value& val); |
6874
|
1868 |
7408
|
1869 graphics_backend get_backend (void) const |
|
1870 { |
|
1871 if (! backend) |
|
1872 backend = graphics_backend::default_backend (); |
|
1873 |
|
1874 return backend; |
|
1875 } |
|
1876 |
|
1877 void set_backend (const graphics_backend& b) { backend = b; } |
|
1878 |
6874
|
1879 // See the genprops.awk script for an explanation of the |
|
1880 // properties declarations. |
|
1881 |
7363
|
1882 BEGIN_PROPERTIES(figure) |
7379
|
1883 any_property __plot_stream__ h , Matrix () |
|
1884 bool_property __enhanced__ h , "on" |
7405
|
1885 radio_property nextplot , "new|{add}|replace_children|replace" |
7363
|
1886 callback_property closerequestfcn , "closereq" |
|
1887 handle_property currentaxes S , graphics_handle () |
|
1888 array_property colormap , jet_colormap () |
7405
|
1889 radio_property paperorientation , "{portrait}|landscape|rotated" |
7363
|
1890 color_property color , color_values (1, 1, 1) |
7405
|
1891 array_property alphamap , Matrix (64, 1, 1) |
|
1892 string_property currentcharacter r , "" |
|
1893 handle_property currentobject r , graphics_handle () |
|
1894 array_property current_point r , Matrix (2, 1, 0) |
|
1895 bool_property dockcontrols , "off" |
|
1896 bool_property doublebuffer , "on" |
|
1897 string_property filename r , "" |
|
1898 bool_property integerhandle , "on" |
|
1899 bool_property inverthardcopy , "off" |
|
1900 callback_property keypressfcn , Matrix () |
|
1901 callback_property keyreleasefcn , Matrix () |
|
1902 radio_property menubar , "none|{figure}" |
|
1903 double_property mincolormap , 64 |
|
1904 string_property name , "" |
|
1905 bool_property numbertitle , "on" |
|
1906 radio_property paperunits , "{inches}|centimeters|normalized|points" |
|
1907 array_property paperposition , Matrix (1, 4 , 0) |
|
1908 radio_property paperpositionmode , "auto|{manual}" |
|
1909 array_property papersize r , Matrix (1, 4, 0) |
|
1910 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" |
|
1911 radio_property pointer , "crosshair|fullcrosshair|{arrow}|ibeam|watch|topl|topr|botl|botr|left|top|right|bottom|circle|cross|fleur|custom|hand" |
|
1912 array_property pointershapecdata , Matrix (16, 16, 0) |
|
1913 array_property pointershapehotspot , Matrix (1, 2, 0) |
|
1914 array_property position , Matrix (1, 4, 0) |
|
1915 radio_property renderer , "{painters}|zbuffer|opengl|none" |
|
1916 radio_property renderermode , "{auto}|manual" |
|
1917 bool_property resize , "on" |
|
1918 callback_property resizefcn , Matrix () |
|
1919 radio_property selectiontype , "{normal}|open|alt|extend" |
|
1920 radio_property toolbar , "none|{auto}|figure" |
|
1921 radio_property units , "inches|centimeters|normalized|points|{pixels}|characters" |
|
1922 callback_property windowbuttondownfcn , Matrix () |
|
1923 callback_property windowbuttonmotionfcn , Matrix () |
|
1924 callback_property windowbuttonupfcn , Matrix () |
|
1925 callback_property windowbuttonwheelfcn , Matrix () |
|
1926 radio_property windowstyle , "{normal}|modal|docked" |
|
1927 string_property wvisual , "" |
|
1928 radio_property wvisualmode , "{auto}|manual" |
|
1929 string_property xdisplay , "" |
|
1930 string_property xvisual , "" |
|
1931 radio_property xvisualmode , "{auto}|manual" |
|
1932 callback_property buttondownfcn , Matrix () |
6874
|
1933 END_PROPERTIES |
7363
|
1934 |
|
1935 protected: |
|
1936 void init (void) |
|
1937 { |
|
1938 colormap.add_constraint (dim_vector (-1, 3)); |
7406
|
1939 alphamap.add_constraint (dim_vector (-1, 1)); |
|
1940 paperposition.add_constraint (dim_vector (1, 4)); |
|
1941 pointershapecdata.add_constraint (dim_vector (16, 16)); |
|
1942 pointershapehotspot.add_constraint (dim_vector (1, 2)); |
|
1943 position.add_constraint (dim_vector (1, 4)); |
7363
|
1944 } |
7408
|
1945 |
|
1946 private: |
|
1947 mutable graphics_backend backend; |
6874
|
1948 }; |
|
1949 |
|
1950 private: |
|
1951 properties xproperties; |
|
1952 |
|
1953 public: |
|
1954 figure (const graphics_handle& mh, const graphics_handle& p) |
|
1955 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1956 { |
|
1957 xproperties.override_defaults (*this); |
|
1958 } |
|
1959 |
|
1960 ~figure (void) |
|
1961 { |
7386
|
1962 xproperties.delete_children (); |
6874
|
1963 xproperties.close (); |
|
1964 } |
|
1965 |
|
1966 void override_defaults (base_graphics_object& obj) |
|
1967 { |
|
1968 // Allow parent (root figure) to override first (properties knows how |
|
1969 // to find the parent object). |
|
1970 xproperties.override_defaults (obj); |
|
1971 |
|
1972 // Now override with our defaults. If the default_properties |
|
1973 // list includes the properties for all defaults (line, |
|
1974 // surface, etc.) then we don't have to know the type of OBJ |
|
1975 // here, we just call its set function and let it decide which |
|
1976 // properties from the list to use. |
|
1977 obj.set_from_list (default_properties); |
|
1978 } |
|
1979 |
7189
|
1980 void set (const caseless_str& name, const octave_value& value) |
6874
|
1981 { |
|
1982 if (name.compare ("default", 7)) |
|
1983 // strip "default", pass rest to function that will |
|
1984 // parse the remainder and add the element to the |
|
1985 // default_properties map. |
|
1986 default_properties.set (name.substr (7), value); |
|
1987 else |
|
1988 xproperties.set (name, value); |
|
1989 } |
|
1990 |
7189
|
1991 octave_value get (const caseless_str& name) const |
6874
|
1992 { |
|
1993 octave_value retval; |
|
1994 |
|
1995 if (name.compare ("default", 7)) |
|
1996 retval = get_default (name.substr (7)); |
|
1997 else |
|
1998 retval = xproperties.get (name); |
|
1999 |
|
2000 return retval; |
|
2001 } |
|
2002 |
7189
|
2003 octave_value get_default (const caseless_str& name) const; |
6874
|
2004 |
|
2005 octave_value get_defaults (void) const |
|
2006 { |
|
2007 return default_properties.as_struct ("default"); |
|
2008 } |
|
2009 |
|
2010 base_properties& get_properties (void) { return xproperties; } |
|
2011 |
7222
|
2012 const base_properties& get_properties (void) const { return xproperties; } |
|
2013 |
6874
|
2014 bool valid_object (void) const { return true; } |
|
2015 |
7408
|
2016 graphics_backend get_backend (void) const |
|
2017 { return xproperties.get_backend (); } |
|
2018 |
|
2019 void set_backend (const graphics_backend& b) |
|
2020 { xproperties.set_backend (b); } |
|
2021 |
6874
|
2022 private: |
|
2023 property_list default_properties; |
|
2024 }; |
|
2025 |
|
2026 // --------------------------------------------------------------------- |
|
2027 |
7365
|
2028 class OCTINTERP_API axes : public base_graphics_object |
6874
|
2029 { |
|
2030 public: |
|
2031 class properties : public base_properties |
|
2032 { |
|
2033 public: |
|
2034 void set_defaults (base_graphics_object& obj, const std::string& mode); |
|
2035 |
|
2036 void remove_child (const graphics_handle& h); |
|
2037 |
|
2038 void delete_children (void); |
|
2039 |
|
2040 // See the genprops.awk script for an explanation of the |
|
2041 // properties declarations. |
|
2042 |
7363
|
2043 BEGIN_PROPERTIES(axes) |
|
2044 array_property position , Matrix () |
|
2045 mutable handle_property title GSO , graphics_handle () |
|
2046 bool_property box , "on" |
|
2047 bool_property key , "off" |
|
2048 bool_property keybox , "off" |
|
2049 double_property keypos , 1 |
|
2050 array_property colororder , default_colororder () |
|
2051 array_property dataaspectratio m , Matrix (1, 3, 1.0) |
|
2052 radio_property dataaspectratiomode , "{auto}|manual" |
7379
|
2053 radio_property layer , "{bottom}|top" |
7363
|
2054 array_property xlim m , default_lim () |
|
2055 array_property ylim m , default_lim () |
|
2056 array_property zlim m , default_lim () |
|
2057 array_property clim m , default_lim () |
7403
|
2058 array_property alim m , default_lim () |
7363
|
2059 radio_property xlimmode al , "{auto}|manual" |
|
2060 radio_property ylimmode al , "{auto}|manual" |
|
2061 radio_property zlimmode al , "{auto}|manual" |
|
2062 radio_property climmode al , "{auto}|manual" |
7403
|
2063 radio_property alimmode , "{auto}|manual" |
7363
|
2064 mutable handle_property xlabel GSO , graphics_handle () |
|
2065 mutable handle_property ylabel GSO , graphics_handle () |
|
2066 mutable handle_property zlabel GSO , graphics_handle () |
|
2067 bool_property xgrid , "off" |
|
2068 bool_property ygrid , "off" |
|
2069 bool_property zgrid , "off" |
|
2070 bool_property xminorgrid , "off" |
|
2071 bool_property yminorgrid , "off" |
|
2072 bool_property zminorgrid , "off" |
|
2073 array_property xtick m , Matrix () |
|
2074 array_property ytick m , Matrix () |
|
2075 array_property ztick m , Matrix () |
|
2076 radio_property xtickmode , "{auto}|manual" |
|
2077 radio_property ytickmode , "{auto}|manual" |
|
2078 radio_property ztickmode , "{auto}|manual" |
7403
|
2079 bool_property xminortick , "off" |
|
2080 bool_property yminortick , "off" |
|
2081 bool_property zminortick , "off" |
|
2082 // FIXME: should be kind of string array |
7363
|
2083 any_property xticklabel m , "" |
|
2084 any_property yticklabel m , "" |
|
2085 any_property zticklabel m , "" |
|
2086 radio_property xticklabelmode , "{auto}|manual" |
|
2087 radio_property yticklabelmode , "{auto}|manual" |
|
2088 radio_property zticklabelmode , "{auto}|manual" |
7379
|
2089 color_property color , color_property (color_values (1, 1, 1), radio_values ("none")) |
7363
|
2090 color_property xcolor , color_values (0, 0, 0) |
|
2091 color_property ycolor , color_values (0, 0, 0) |
|
2092 color_property zcolor , color_values (0, 0, 0) |
|
2093 radio_property xscale al , "{linear}|log" |
|
2094 radio_property yscale al , "{linear}|log" |
|
2095 radio_property zscale al , "{linear}|log" |
|
2096 radio_property xdir , "{normal}|reverse" |
|
2097 radio_property ydir , "{normal}|reverse" |
|
2098 radio_property zdir , "{normal}|reverse" |
7365
|
2099 radio_property yaxislocation , "{left}|right|zero" |
|
2100 radio_property xaxislocation , "{bottom}|top|zero" |
7363
|
2101 array_property view , Matrix () |
|
2102 radio_property nextplot , "add|replace_children|{replace}" |
|
2103 array_property outerposition , Matrix () |
7379
|
2104 radio_property activepositionproperty , "{outerposition}|position" |
|
2105 radio_property __colorbar__ h , "{none}|north|south|east|west|northoutside|southoutside|eastoutside|westoutside" |
7403
|
2106 color_property ambientlightcolor , color_values (1, 1, 1) |
|
2107 array_property cameraposition m , Matrix (1, 3, 0.0) |
|
2108 array_property cameratarget m , Matrix (1, 3, 0.0) |
|
2109 array_property cameraupvector m , Matrix () |
|
2110 double_property cameraviewangle m , 10.0 |
|
2111 radio_property camerapositionmode , "{auto}|manual" |
|
2112 radio_property cameratargetmode , "{auto}|manual" |
|
2113 radio_property cameraupvectormode , "{auto}|manual" |
|
2114 radio_property cameraviewanglemode , "{auto}|manual" |
|
2115 array_property currentpoint , Matrix (2, 3, 0.0) |
|
2116 radio_property drawmode , "{normal}|fast" |
|
2117 radio_property fontangle , "{normal}|italic|oblique" |
|
2118 string_property fontname , "Helvetica" |
|
2119 double_property fontsize , 12 |
|
2120 radio_property fontunits , "{points}|normalized|inches|centimeters|pixels" |
|
2121 radio_property fontweight , "{normal}|light|demi|bold" |
|
2122 radio_property gridlinestyle , "{-}|--|:|-.|none" |
|
2123 // FIXME: should be kind of string array |
|
2124 string_property linestyleorder , "-" |
|
2125 double_property linewidth , 0.5 |
|
2126 radio_property minorgridlinestyle , "{-}|--|:|-.|none" |
|
2127 array_property plotboxaspectratio m , Matrix (1, 3, 1.0) |
|
2128 radio_property plotboxaspectratiomode , "{auto}|manual" |
|
2129 radio_property projection , "{orthographic}|perpective" |
|
2130 radio_property tickdir m , "{in}|out" |
|
2131 radio_property tickdirmode , "{auto}|manual" |
|
2132 array_property ticklength , Matrix (1, 2, 0.1) |
|
2133 array_property tightinset r , Matrix (1, 4, 0.0) |
|
2134 // FIXME: uicontextmenu should be moved here |
|
2135 radio_property units , "{normalized}|inches|centimeters|points|pixels|characters" |
|
2136 // hidden properties for transformation computation |
|
2137 array_property x_viewtransform h , Matrix (4, 4, 0.0) |
|
2138 array_property x_projectiontransform h , Matrix (4, 4, 0.0) |
|
2139 array_property x_viewporttransform h , Matrix (4, 4, 0.0) |
|
2140 array_property x_normrendertransform h , Matrix (4, 4, 0.0) |
|
2141 array_property x_rendertransform h , Matrix (4, 4, 0.0) |
7189
|
2142 END_PROPERTIES |
6874
|
2143 |
7363
|
2144 protected: |
|
2145 void init (void) |
|
2146 { |
|
2147 position.add_constraint (dim_vector (1, 4)); |
7403
|
2148 position.add_constraint (dim_vector (0, 0)); |
7363
|
2149 outerposition.add_constraint (dim_vector (1, 4)); |
|
2150 colororder.add_constraint (dim_vector (-1, 3)); |
|
2151 dataaspectratio.add_constraint (dim_vector (1, 3)); |
7403
|
2152 plotboxaspectratio.add_constraint (dim_vector (1, 3)); |
7363
|
2153 xlim.add_constraint (dim_vector (1, 2)); |
|
2154 ylim.add_constraint (dim_vector (1, 2)); |
|
2155 zlim.add_constraint (dim_vector (1, 2)); |
|
2156 clim.add_constraint (dim_vector (1, 2)); |
7403
|
2157 alim.add_constraint (dim_vector (1, 2)); |
7363
|
2158 xtick.add_constraint (dim_vector (1, -1)); |
|
2159 ytick.add_constraint (dim_vector (1, -1)); |
|
2160 ztick.add_constraint (dim_vector (1, -1)); |
|
2161 Matrix vw (1, 2, 0); |
|
2162 vw(1) = 90; |
|
2163 view = vw; |
|
2164 view.add_constraint (dim_vector (1, 2)); |
7403
|
2165 cameraposition.add_constraint (dim_vector (1, 3)); |
|
2166 Matrix upv (1, 3, 0.0); |
|
2167 upv(2) = 1.0; |
|
2168 cameraupvector = upv; |
|
2169 cameraupvector.add_constraint (dim_vector (1, 3)); |
|
2170 currentpoint.add_constraint (dim_vector (2, 3)); |
|
2171 ticklength.add_constraint (dim_vector (1, 2)); |
|
2172 tightinset.add_constraint (dim_vector (1, 4)); |
7363
|
2173 } |
6874
|
2174 }; |
|
2175 |
|
2176 private: |
|
2177 properties xproperties; |
|
2178 |
|
2179 public: |
|
2180 axes (const graphics_handle& mh, const graphics_handle& p) |
|
2181 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
2182 { |
|
2183 xproperties.override_defaults (*this); |
|
2184 } |
|
2185 |
|
2186 ~axes (void) { xproperties.delete_children (); } |
|
2187 |
|
2188 void override_defaults (base_graphics_object& obj) |
|
2189 { |
|
2190 // Allow parent (figure) to override first (properties knows how |
|
2191 // to find the parent object). |
|
2192 xproperties.override_defaults (obj); |
|
2193 |
|
2194 // Now override with our defaults. If the default_properties |
|
2195 // list includes the properties for all defaults (line, |
|
2196 // surface, etc.) then we don't have to know the type of OBJ |
|
2197 // here, we just call its set function and let it decide which |
|
2198 // properties from the list to use. |
|
2199 obj.set_from_list (default_properties); |
|
2200 } |
|
2201 |
7189
|
2202 void set (const caseless_str& name, const octave_value& value) |
6874
|
2203 { |
|
2204 if (name.compare ("default", 7)) |
|
2205 // strip "default", pass rest to function that will |
|
2206 // parse the remainder and add the element to the |
|
2207 // default_properties map. |
|
2208 default_properties.set (name.substr (7), value); |
|
2209 else |
|
2210 xproperties.set (name, value); |
|
2211 } |
|
2212 |
|
2213 void set_defaults (const std::string& mode) |
|
2214 { |
|
2215 xproperties.set_defaults (*this, mode); |
|
2216 } |
|
2217 |
7189
|
2218 octave_value get (const caseless_str& name) const |
6874
|
2219 { |
|
2220 octave_value retval; |
|
2221 |
|
2222 // FIXME -- finish this. |
|
2223 if (name.compare ("default", 7)) |
|
2224 retval = get_default (name.substr (7)); |
|
2225 else |
|
2226 retval = xproperties.get (name); |
|
2227 |
|
2228 return retval; |
|
2229 } |
|
2230 |
7189
|
2231 octave_value get_default (const caseless_str& name) const; |
6874
|
2232 |
|
2233 octave_value get_defaults (void) const |
|
2234 { |
|
2235 return default_properties.as_struct ("default"); |
|
2236 } |
|
2237 |
|
2238 base_properties& get_properties (void) { return xproperties; } |
|
2239 |
7222
|
2240 const base_properties& get_properties (void) const { return xproperties; } |
|
2241 |
7214
|
2242 void update_axis_limits (const std::string& axis_type); |
|
2243 |
6874
|
2244 bool valid_object (void) const { return true; } |
|
2245 |
|
2246 private: |
|
2247 property_list default_properties; |
|
2248 }; |
|
2249 |
|
2250 // --------------------------------------------------------------------- |
|
2251 |
7365
|
2252 class OCTINTERP_API line : public base_graphics_object |
6874
|
2253 { |
|
2254 public: |
|
2255 class properties : public base_properties |
|
2256 { |
|
2257 public: |
|
2258 // See the genprops.awk script for an explanation of the |
|
2259 // properties declarations. |
|
2260 |
7366
|
2261 // properties which are not in matlab: |
7384
|
2262 // ldata, udata, xldata, xudata, keylabel, interpreter |
7366
|
2263 |
7363
|
2264 BEGIN_PROPERTIES(line) |
|
2265 data_property xdata l , default_data () |
|
2266 data_property ydata l , default_data () |
|
2267 data_property zdata l , Matrix () |
|
2268 data_property ldata l , Matrix () |
|
2269 data_property udata l , Matrix () |
|
2270 data_property xldata l , Matrix () |
|
2271 data_property xudata l , Matrix () |
|
2272 color_property color , color_values (0, 0, 0) |
|
2273 radio_property linestyle , "{-}|--|:|-.|none" |
|
2274 double_property linewidth , 0.5 |
|
2275 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2276 color_property markeredgecolor , "{auto}|none" |
|
2277 color_property markerfacecolor , "auto|{none}" |
|
2278 double_property markersize , 6 |
|
2279 string_property keylabel , "" |
7384
|
2280 radio_property interpreter , "{tex}|none|latex" |
7377
|
2281 string_property displayname , "" |
7380
|
2282 radio_property erasemode , "{normal}|none|xor|background" |
6874
|
2283 END_PROPERTIES |
|
2284 }; |
|
2285 |
|
2286 private: |
|
2287 properties xproperties; |
|
2288 |
|
2289 public: |
|
2290 line (const graphics_handle& mh, const graphics_handle& p) |
|
2291 : base_graphics_object (), xproperties (mh, p) |
|
2292 { |
|
2293 xproperties.override_defaults (*this); |
|
2294 } |
|
2295 |
|
2296 ~line (void) { xproperties.delete_children (); } |
|
2297 |
|
2298 base_properties& get_properties (void) { return xproperties; } |
|
2299 |
7222
|
2300 const base_properties& get_properties (void) const { return xproperties; } |
|
2301 |
6874
|
2302 bool valid_object (void) const { return true; } |
|
2303 }; |
|
2304 |
|
2305 // --------------------------------------------------------------------- |
|
2306 |
7365
|
2307 class OCTINTERP_API text : public base_graphics_object |
6874
|
2308 { |
|
2309 public: |
|
2310 class properties : public base_properties |
|
2311 { |
|
2312 public: |
|
2313 // See the genprops.awk script for an explanation of the |
|
2314 // properties declarations. |
|
2315 |
7363
|
2316 BEGIN_PROPERTIES(text) |
|
2317 string_property string , "" |
|
2318 radio_property units , "{data}|pixels|normalized|inches|centimeters|points" |
|
2319 array_property position , Matrix (1, 3, 0.0) |
|
2320 double_property rotation , 0 |
|
2321 radio_property horizontalalignment , "{left}|center|right" |
|
2322 color_property color , color_values (0, 0, 0) |
|
2323 string_property fontname , "Helvetica" |
|
2324 double_property fontsize , 10 |
7379
|
2325 radio_property fontangle , "{normal}|italic|oblique" |
|
2326 radio_property fontweight , "light|{normal}|demi|bold" |
|
2327 radio_property interpreter , "{tex}|none|latex" |
7377
|
2328 color_property backgroundcolor , "{none}" |
|
2329 string_property displayname , "" |
|
2330 color_property edgecolor , "{none}" |
7380
|
2331 radio_property erasemode , "{normal}|none|xor|background" |
7377
|
2332 bool_property editing , "off" |
|
2333 radio_property fontunits , "inches|centimeters|normalized|{points}|pixel" |
|
2334 radio_property linestyle , "{-}|--|:|-.|none" |
|
2335 double_property linewidth , 0.5 |
|
2336 double_property margin , 1 |
|
2337 radio_property verticalalignment , "top|cap|{middle}|baseline|bottom" |
6874
|
2338 END_PROPERTIES |
|
2339 |
7363
|
2340 protected: |
|
2341 void init (void) |
|
2342 { |
|
2343 position.add_constraint (dim_vector (1, 3)); |
|
2344 } |
6874
|
2345 }; |
|
2346 |
|
2347 private: |
|
2348 properties xproperties; |
|
2349 |
|
2350 public: |
|
2351 text (const graphics_handle& mh, const graphics_handle& p) |
|
2352 : base_graphics_object (), xproperties (mh, p) |
|
2353 { |
|
2354 xproperties.override_defaults (*this); |
|
2355 } |
|
2356 |
|
2357 ~text (void) { xproperties.delete_children (); } |
|
2358 |
|
2359 base_properties& get_properties (void) { return xproperties; } |
|
2360 |
7222
|
2361 const base_properties& get_properties (void) const { return xproperties; } |
|
2362 |
6874
|
2363 bool valid_object (void) const { return true; } |
|
2364 }; |
|
2365 |
|
2366 // --------------------------------------------------------------------- |
|
2367 |
7365
|
2368 class OCTINTERP_API image : public base_graphics_object |
6874
|
2369 { |
|
2370 public: |
|
2371 class properties : public base_properties |
|
2372 { |
|
2373 public: |
|
2374 // See the genprops.awk script for an explanation of the |
|
2375 // properties declarations. |
|
2376 |
7363
|
2377 BEGIN_PROPERTIES(image) |
|
2378 data_property xdata l , Matrix () |
|
2379 data_property ydata l , Matrix () |
|
2380 data_property cdata l , Matrix () |
6874
|
2381 END_PROPERTIES |
|
2382 |
7363
|
2383 protected: |
|
2384 void init (void) |
|
2385 { |
|
2386 } |
6874
|
2387 }; |
|
2388 |
|
2389 private: |
|
2390 properties xproperties; |
|
2391 |
|
2392 public: |
|
2393 image (const graphics_handle& mh, const graphics_handle& p) |
|
2394 : base_graphics_object (), xproperties (mh, p) |
|
2395 { |
|
2396 xproperties.override_defaults (*this); |
|
2397 } |
|
2398 |
|
2399 ~image (void) { xproperties.delete_children (); } |
|
2400 |
|
2401 base_properties& get_properties (void) { return xproperties; } |
|
2402 |
7222
|
2403 const base_properties& get_properties (void) const { return xproperties; } |
|
2404 |
6874
|
2405 bool valid_object (void) const { return true; } |
|
2406 }; |
|
2407 |
|
2408 // --------------------------------------------------------------------- |
|
2409 |
7365
|
2410 class OCTINTERP_API patch : public base_graphics_object |
6874
|
2411 { |
|
2412 public: |
|
2413 class properties : public base_properties |
|
2414 { |
|
2415 public: |
|
2416 // See the genprops.awk script for an explanation of the |
|
2417 // properties declarations. |
|
2418 |
7363
|
2419 BEGIN_PROPERTIES(patch) |
7403
|
2420 data_property xdata l , Matrix () |
7363
|
2421 data_property ydata l , Matrix () |
|
2422 data_property zdata l , Matrix () |
|
2423 data_property cdata l , Matrix () |
7379
|
2424 radio_property cdatamapping , "{scaled}|direct" |
7363
|
2425 array_property faces , Matrix () |
7368
|
2426 data_property facevertexalphadata , Matrix () |
|
2427 data_property facevertexcdata , Matrix () |
7363
|
2428 array_property vertices , Matrix () |
7368
|
2429 array_property vertexnormals , Matrix () |
7379
|
2430 radio_property normalmode , "{auto}|manual" |
|
2431 color_property facecolor , "{flat}|none|interp" |
7363
|
2432 double_property facealpha , 1.0 |
7379
|
2433 radio_property facelighting , "{flat}|none|gouraud|phong" |
|
2434 color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
7368
|
2435 double_property edgealpha , 1.0 |
7379
|
2436 radio_property edgelighting , "{none}|flat|gouraud|phong" |
|
2437 radio_property backfacelighting , "{reverselit}|unlit|lit" |
7368
|
2438 double_property ambientstrength , 0.3 |
|
2439 double_property diffusestrength , 0.6 |
|
2440 double_property specularstrength , 0.6 |
|
2441 double_property specularexponent , 10.0 |
|
2442 double_property specularcolorreflectance , 1.0 |
7379
|
2443 radio_property erasemode , "{normal}|background|xor|none" |
7363
|
2444 radio_property linestyle , "{-}|--|:|-.|none" |
|
2445 double_property linewidth , 0.5 |
|
2446 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2447 color_property markeredgecolor , "{auto}|none" |
|
2448 color_property markerfacecolor , "auto|{none}" |
|
2449 double_property markersize , 6 |
|
2450 string_property keylabel , "" |
7384
|
2451 radio_property interpreter , "{tex}|none|latex" |
6874
|
2452 END_PROPERTIES |
|
2453 |
7363
|
2454 protected: |
|
2455 void init (void) |
|
2456 { |
|
2457 vertices.add_constraint (dim_vector (-1, 2)); |
|
2458 vertices.add_constraint (dim_vector (-1, 3)); |
|
2459 } |
6874
|
2460 }; |
|
2461 |
|
2462 private: |
|
2463 properties xproperties; |
|
2464 |
|
2465 public: |
|
2466 patch (const graphics_handle& mh, const graphics_handle& p) |
|
2467 : base_graphics_object (), xproperties (mh, p) |
|
2468 { |
|
2469 xproperties.override_defaults (*this); |
|
2470 } |
|
2471 |
|
2472 ~patch (void) { xproperties.delete_children (); } |
|
2473 |
|
2474 base_properties& get_properties (void) { return xproperties; } |
|
2475 |
7222
|
2476 const base_properties& get_properties (void) const { return xproperties; } |
|
2477 |
6874
|
2478 bool valid_object (void) const { return true; } |
|
2479 }; |
|
2480 |
|
2481 // --------------------------------------------------------------------- |
|
2482 |
7365
|
2483 class OCTINTERP_API surface : public base_graphics_object |
6874
|
2484 { |
|
2485 public: |
|
2486 class properties : public base_properties |
|
2487 { |
|
2488 public: |
|
2489 // See the genprops.awk script for an explanation of the |
|
2490 // properties declarations. |
|
2491 |
7363
|
2492 BEGIN_PROPERTIES(surface) |
|
2493 data_property xdata l , Matrix () |
|
2494 data_property ydata l , Matrix () |
|
2495 data_property zdata l , Matrix () |
|
2496 data_property cdata l , Matrix () |
7379
|
2497 color_property facecolor , "{flat}|none|interp" |
7363
|
2498 double_property facealpha , 1.0 |
7379
|
2499 color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
7363
|
2500 radio_property linestyle , "{-}|--|:|-.|none" |
|
2501 double_property linewidth , 0.5 |
|
2502 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2503 color_property markeredgecolor , "{auto}|none" |
|
2504 color_property markerfacecolor , "auto|{none}" |
|
2505 double_property markersize , 6 |
|
2506 string_property keylabel , "" |
7384
|
2507 radio_property interpreter , "{tex}|none|latex" |
6874
|
2508 END_PROPERTIES |
|
2509 |
7363
|
2510 protected: |
|
2511 void init (void) |
|
2512 { |
|
2513 } |
6874
|
2514 }; |
|
2515 |
|
2516 private: |
|
2517 properties xproperties; |
|
2518 |
|
2519 public: |
|
2520 surface (const graphics_handle& mh, const graphics_handle& p) |
|
2521 : base_graphics_object (), xproperties (mh, p) |
|
2522 { |
|
2523 xproperties.override_defaults (*this); |
|
2524 } |
|
2525 |
|
2526 ~surface (void) { xproperties.delete_children (); } |
|
2527 |
|
2528 base_properties& get_properties (void) { return xproperties; } |
|
2529 |
7222
|
2530 const base_properties& get_properties (void) const { return xproperties; } |
|
2531 |
6874
|
2532 bool valid_object (void) const { return true; } |
|
2533 }; |
|
2534 |
|
2535 octave_value |
|
2536 get_property_from_handle (double handle, const std::string &property, |
|
2537 const std::string &func); |
|
2538 bool |
|
2539 set_property_in_handle (double handle, const std::string &property, |
|
2540 const octave_value &arg, const std::string &func); |
|
2541 |
|
2542 // --------------------------------------------------------------------- |
|
2543 |
7365
|
2544 class OCTINTERP_API gh_manager |
6874
|
2545 { |
|
2546 protected: |
|
2547 |
|
2548 gh_manager (void); |
|
2549 |
|
2550 public: |
|
2551 |
|
2552 static bool instance_ok (void) |
|
2553 { |
|
2554 bool retval = true; |
|
2555 |
|
2556 if (! instance) |
|
2557 instance = new gh_manager (); |
|
2558 |
|
2559 if (! instance) |
|
2560 { |
|
2561 ::error ("unable to create gh_manager!"); |
|
2562 |
|
2563 retval = false; |
|
2564 } |
|
2565 |
|
2566 return retval; |
|
2567 } |
|
2568 |
|
2569 static void free (const graphics_handle& h) |
|
2570 { |
|
2571 if (instance_ok ()) |
|
2572 instance->do_free (h); |
|
2573 } |
|
2574 |
|
2575 static graphics_handle lookup (double val) |
|
2576 { |
|
2577 return instance_ok () ? instance->do_lookup (val) : graphics_handle (); |
|
2578 } |
|
2579 |
|
2580 static graphics_object get_object (const graphics_handle& h) |
|
2581 { |
|
2582 return instance_ok () ? instance->do_get_object (h) : graphics_object (); |
|
2583 } |
|
2584 |
|
2585 static graphics_handle |
|
2586 make_graphics_handle (const std::string& go_name, |
7370
|
2587 const graphics_handle& parent, bool do_createfcn = true) |
6874
|
2588 { |
|
2589 return instance_ok () |
7370
|
2590 ? instance->do_make_graphics_handle (go_name, parent, do_createfcn) |
6874
|
2591 : graphics_handle (); |
|
2592 } |
|
2593 |
|
2594 static graphics_handle make_figure_handle (double val) |
|
2595 { |
|
2596 return instance_ok () |
|
2597 ? instance->do_make_figure_handle (val) : graphics_handle (); |
|
2598 } |
|
2599 |
|
2600 static void push_figure (const graphics_handle& h) |
|
2601 { |
|
2602 if (instance_ok ()) |
|
2603 instance->do_push_figure (h); |
|
2604 } |
|
2605 |
|
2606 static void pop_figure (const graphics_handle& h) |
|
2607 { |
|
2608 if (instance_ok ()) |
|
2609 instance->do_pop_figure (h); |
|
2610 } |
|
2611 |
|
2612 static graphics_handle current_figure (void) |
|
2613 { |
|
2614 return instance_ok () |
|
2615 ? instance->do_current_figure () : graphics_handle (); |
|
2616 } |
|
2617 |
|
2618 static Matrix handle_list (void) |
|
2619 { |
|
2620 return instance_ok () ? instance->do_handle_list () : Matrix (); |
|
2621 } |
|
2622 |
|
2623 static Matrix figure_handle_list (void) |
|
2624 { |
|
2625 return instance_ok () ? instance->do_figure_handle_list () : Matrix (); |
|
2626 } |
|
2627 |
|
2628 private: |
|
2629 |
|
2630 static gh_manager *instance; |
|
2631 |
|
2632 typedef std::map<graphics_handle, graphics_object>::iterator iterator; |
|
2633 typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator; |
|
2634 |
|
2635 typedef std::set<graphics_handle>::iterator free_list_iterator; |
|
2636 typedef std::set<graphics_handle>::const_iterator const_free_list_iterator; |
|
2637 |
|
2638 typedef std::list<graphics_handle>::iterator figure_list_iterator; |
|
2639 typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator; |
|
2640 |
|
2641 // A map of handles to graphics objects. |
|
2642 std::map<graphics_handle, graphics_object> handle_map; |
|
2643 |
|
2644 // The available graphics handles. |
|
2645 std::set<graphics_handle> handle_free_list; |
|
2646 |
|
2647 // The next handle available if handle_free_list is empty. |
7286
|
2648 double next_handle; |
6874
|
2649 |
|
2650 // The allocated figure handles. Top of the stack is most recently |
|
2651 // created. |
|
2652 std::list<graphics_handle> figure_list; |
|
2653 |
|
2654 graphics_handle get_handle (const std::string& go_name); |
|
2655 |
|
2656 void do_free (const graphics_handle& h); |
|
2657 |
|
2658 graphics_handle do_lookup (double val) |
|
2659 { |
7363
|
2660 iterator p = (xisnan (val) ? handle_map.end () : handle_map.find (val)); |
6874
|
2661 |
|
2662 return (p != handle_map.end ()) ? p->first : graphics_handle (); |
|
2663 } |
|
2664 |
|
2665 graphics_object do_get_object (const graphics_handle& h) |
|
2666 { |
7379
|
2667 iterator p = (h.ok () ? handle_map.find (h) : handle_map.end ()); |
6874
|
2668 |
|
2669 return (p != handle_map.end ()) ? p->second : graphics_object (); |
|
2670 } |
|
2671 |
|
2672 graphics_handle do_make_graphics_handle (const std::string& go_name, |
7370
|
2673 const graphics_handle& p, bool do_createfcn); |
6874
|
2674 |
|
2675 graphics_handle do_make_figure_handle (double val); |
|
2676 |
|
2677 Matrix do_handle_list (void) |
|
2678 { |
|
2679 Matrix retval (1, handle_map.size ()); |
|
2680 octave_idx_type i = 0; |
|
2681 for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++) |
7056
|
2682 { |
|
2683 graphics_handle h = p->first; |
|
2684 retval(i++) = h.value (); |
|
2685 } |
6874
|
2686 return retval; |
|
2687 } |
|
2688 |
|
2689 Matrix do_figure_handle_list (void) |
|
2690 { |
|
2691 Matrix retval (1, figure_list.size ()); |
|
2692 octave_idx_type i = 0; |
|
2693 for (const_figure_list_iterator p = figure_list.begin (); |
|
2694 p != figure_list.end (); |
|
2695 p++) |
7056
|
2696 { |
|
2697 graphics_handle h = *p; |
|
2698 retval(i++) = h.value (); |
|
2699 } |
6874
|
2700 return retval; |
|
2701 } |
|
2702 |
|
2703 void do_push_figure (const graphics_handle& h); |
|
2704 |
|
2705 void do_pop_figure (const graphics_handle& h); |
|
2706 |
|
2707 graphics_handle do_current_figure (void) const |
|
2708 { |
|
2709 return figure_list.empty () ? graphics_handle () : figure_list.front (); |
|
2710 } |
|
2711 }; |
|
2712 |
|
2713 |
|
2714 // This function is NOT equivalent to the scripting language function gcf. |
7365
|
2715 OCTINTERP_API graphics_handle gcf (void); |
6874
|
2716 |
|
2717 // This function is NOT equivalent to the scripting language function gca. |
7365
|
2718 OCTINTERP_API graphics_handle gca (void); |
6874
|
2719 |
|
2720 #endif |
|
2721 |
|
2722 /* |
|
2723 ;;; Local Variables: *** |
|
2724 ;;; mode: C++ *** |
|
2725 ;;; End: *** |
|
2726 */ |