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 |
|
662 if (nel > 0) |
|
663 { |
|
664 const double *d = data.data (); |
|
665 |
|
666 for (octave_idx_type i = 0; i < nel; i++) |
|
667 { |
|
668 double val = d[i]; |
|
669 |
|
670 if (! (xisinf (val) || xisnan (val))) |
|
671 { |
|
672 if (val < xmin) |
|
673 xmin = val; |
|
674 |
|
675 if (val > xmax) |
|
676 xmax = val; |
|
677 |
|
678 if (val > 0 && val < xminp) |
|
679 xminp = val; |
|
680 } |
|
681 } |
|
682 } |
|
683 } |
|
684 }; |
|
685 |
|
686 // --------------------------------------------------------------------- |
|
687 |
|
688 class bool_property : public radio_property |
|
689 { |
|
690 public: |
7364
|
691 bool_property (const std::string& nm, const graphics_handle& h, |
7363
|
692 bool val) |
7364
|
693 : radio_property (nm, h, radio_values (val ? "{on}|off" : "on|{off}")) |
7363
|
694 { } |
|
695 |
7364
|
696 bool_property (const std::string& nm, const graphics_handle& h, |
7363
|
697 const char* val) |
7364
|
698 : radio_property (nm, h, radio_values ("on|off"), val) |
7363
|
699 { } |
|
700 |
|
701 bool_property (const bool_property& p) |
|
702 : radio_property (p) { } |
|
703 |
|
704 void set (const octave_value& val) |
|
705 { |
|
706 if (val.is_bool_scalar ()) |
|
707 radio_property::set (val.bool_value () ? "on" : "off"); |
|
708 else |
|
709 radio_property::set (val); |
|
710 } |
|
711 |
|
712 bool is_on (void) const { return is ("on"); } |
|
713 |
|
714 bool_property& operator = (const octave_value& val) |
|
715 { |
|
716 set (val); |
|
717 return *this; |
|
718 } |
|
719 }; |
|
720 |
|
721 // --------------------------------------------------------------------- |
|
722 |
|
723 class handle_property : public base_property |
|
724 { |
|
725 public: |
7364
|
726 handle_property (const std::string& nm, const graphics_handle& h, |
7363
|
727 const graphics_handle& val = graphics_handle ()) |
7364
|
728 : base_property (nm, h), |
7363
|
729 current_val (val) { } |
|
730 |
|
731 handle_property (const handle_property& p) |
|
732 : base_property (p), current_val (p.current_val) { } |
|
733 |
|
734 OCTINTERP_API void set (const octave_value& v); |
|
735 |
|
736 octave_value get (void) const { return current_val.as_octave_value (); } |
|
737 |
|
738 graphics_handle handle_value (void) const { return current_val; } |
|
739 |
|
740 handle_property& operator = (const octave_value& val) |
|
741 { |
|
742 set (val); |
|
743 return *this; |
|
744 } |
|
745 |
|
746 handle_property& operator = (const graphics_handle& h) |
|
747 { |
|
748 set (octave_value (h.value ())); |
|
749 return *this; |
|
750 } |
|
751 |
|
752 private: |
|
753 graphics_handle current_val; |
|
754 }; |
|
755 |
|
756 // --------------------------------------------------------------------- |
|
757 |
|
758 class any_property : public base_property |
|
759 { |
|
760 public: |
7364
|
761 any_property (const std::string& nm, const graphics_handle& h, |
7363
|
762 const octave_value& m = Matrix ()) |
7364
|
763 : base_property (nm, h), data (m) { } |
7363
|
764 |
|
765 octave_value get (void) const { return data; } |
|
766 |
|
767 void set (const octave_value& v) { data = v; } |
|
768 |
|
769 any_property& operator = (const octave_value& val) |
|
770 { |
|
771 set (val); |
|
772 return *this; |
|
773 } |
|
774 |
|
775 private: |
|
776 octave_value data; |
|
777 }; |
|
778 |
|
779 // --------------------------------------------------------------------- |
|
780 |
|
781 class callback_property : public base_property |
|
782 { |
|
783 public: |
7364
|
784 callback_property (const std::string& nm, const graphics_handle& h, |
7363
|
785 const octave_value& m) |
7364
|
786 : base_property (nm, h), callback (m) { } |
7363
|
787 |
|
788 octave_value get (void) const { return callback; } |
|
789 |
|
790 void set (const octave_value& v) |
|
791 { |
|
792 if (validate (v)) |
|
793 callback = v; |
|
794 else |
|
795 error ("invalid value for callback property \"%s\"", |
|
796 get_name ().c_str ()); |
|
797 } |
|
798 |
7367
|
799 OCTINTERP_API void execute (const octave_value& data = octave_value ()) const; |
7363
|
800 |
|
801 callback_property& operator = (const octave_value& val) |
|
802 { |
|
803 set (val); |
|
804 return *this; |
|
805 } |
|
806 |
|
807 private: |
|
808 OCTINTERP_API bool validate (const octave_value& v) const; |
|
809 |
|
810 private: |
|
811 octave_value callback; |
|
812 }; |
|
813 |
|
814 // --------------------------------------------------------------------- |
|
815 |
|
816 class property |
|
817 { |
|
818 public: |
|
819 property (void) : rep (new base_property ("", graphics_handle ())) |
|
820 { rep->count++; } |
|
821 |
|
822 property (base_property *bp, bool persist = false) : rep (bp) |
|
823 { rep->count++; if (persist) rep->count++; } |
|
824 |
|
825 property (const property& p) |
|
826 { |
|
827 rep = p.rep; |
|
828 rep->count++; |
|
829 } |
|
830 |
|
831 ~property (void) |
|
832 { |
|
833 if (--rep->count <= 0) |
|
834 delete rep; |
|
835 } |
|
836 |
|
837 bool ok (void) const |
|
838 { return rep->ok (); } |
|
839 |
|
840 std::string get_name (void) const |
|
841 { return rep->get_name (); } |
|
842 |
|
843 void set_name (const std::string& name) |
|
844 { rep->set_name (name); } |
|
845 |
|
846 graphics_handle get_parent (void) const |
|
847 { return rep->get_parent (); } |
|
848 |
|
849 void set_parent (const graphics_handle& h) |
|
850 { rep->set_parent (h); } |
|
851 |
|
852 bool is_hidden (void) const |
|
853 { return rep->is_hidden (); } |
|
854 |
|
855 void set_hidden (bool flag) |
|
856 { rep->set_hidden (flag); } |
|
857 |
|
858 octave_value get (void) const |
|
859 { return rep->get (); } |
|
860 |
|
861 void set (const octave_value& val) |
|
862 { rep->set (val); } |
|
863 |
|
864 property& operator = (const octave_value& val) |
|
865 { |
|
866 *rep = val; |
|
867 return *this; |
|
868 } |
|
869 |
|
870 property& operator = (const property& p) |
|
871 { |
|
872 if (rep && --rep->count <= 0) |
|
873 delete rep; |
|
874 |
|
875 rep = p.rep; |
|
876 rep->count++; |
|
877 |
|
878 return *this; |
|
879 } |
|
880 |
|
881 /* |
|
882 const string_property& as_string_property (void) const |
|
883 { return *(dynamic_cast<string_property*> (rep)); } |
|
884 |
|
885 const radio_property& as_radio_property (void) const |
|
886 { return *(dynamic_cast<radio_property*> (rep)); } |
|
887 |
|
888 const color_property& as_color_property (void) const |
|
889 { return *(dynamic_cast<color_property*> (rep)); } |
|
890 |
|
891 const double_property& as_double_property (void) const |
|
892 { return *(dynamic_cast<double_property*> (rep)); } |
|
893 |
|
894 const data_property& as_data_property (void) const |
|
895 { return *(dynamic_cast<data_property*> (rep)); } |
|
896 |
|
897 const bool_property& as_bool_property (void) const |
|
898 { return *(dynamic_cast<bool_property*> (rep)); } |
|
899 |
|
900 const handle_property& as_handle_property (void) const |
|
901 { return *(dynamic_cast<handle_property*> (rep)); } |
|
902 */ |
|
903 |
|
904 private: |
|
905 base_property *rep; |
|
906 }; |
|
907 |
|
908 // --------------------------------------------------------------------- |
|
909 |
|
910 class property_list |
|
911 { |
|
912 public: |
|
913 typedef std::map<std::string, octave_value> pval_map_type; |
|
914 typedef std::map<std::string, pval_map_type> plist_map_type; |
|
915 |
|
916 typedef pval_map_type::iterator pval_map_iterator; |
|
917 typedef pval_map_type::const_iterator pval_map_const_iterator; |
|
918 |
|
919 typedef plist_map_type::iterator plist_map_iterator; |
|
920 typedef plist_map_type::const_iterator plist_map_const_iterator; |
|
921 |
|
922 property_list (const plist_map_type& m = plist_map_type ()) |
|
923 : plist_map (m) { } |
|
924 |
|
925 ~property_list (void) { } |
|
926 |
|
927 void set (const caseless_str& name, const octave_value& val); |
|
928 |
|
929 octave_value lookup (const caseless_str& name) const; |
|
930 |
|
931 plist_map_iterator begin (void) { return plist_map.begin (); } |
|
932 plist_map_const_iterator begin (void) const { return plist_map.begin (); } |
|
933 |
|
934 plist_map_iterator end (void) { return plist_map.end (); } |
|
935 plist_map_const_iterator end (void) const { return plist_map.end (); } |
|
936 |
|
937 plist_map_iterator find (const std::string& go_name) |
|
938 { |
|
939 return plist_map.find (go_name); |
|
940 } |
|
941 |
|
942 plist_map_const_iterator find (const std::string& go_name) const |
|
943 { |
|
944 return plist_map.find (go_name); |
|
945 } |
|
946 |
|
947 Octave_map as_struct (const std::string& prefix_arg) const; |
|
948 |
|
949 private: |
|
950 plist_map_type plist_map; |
|
951 }; |
|
952 |
|
953 // --------------------------------------------------------------------- |
|
954 |
6874
|
955 class base_graphics_object; |
|
956 |
7365
|
957 class OCTINTERP_API base_properties |
6874
|
958 { |
|
959 public: |
7176
|
960 base_properties (const std::string& ty = "unknown", |
7363
|
961 const graphics_handle& mh = graphics_handle (), |
|
962 const graphics_handle& p = graphics_handle ()) |
|
963 : tag ("tag", mh), |
|
964 type ("type", mh, ty), |
|
965 __modified__ ("__modified__", mh, true), |
|
966 __myhandle__ (mh), |
7366
|
967 parent ("parent", mh, p), |
|
968 children (), |
|
969 busyaction ("parent", mh, "{queue}|cancel"), |
7367
|
970 buttondownfcn ("buttondownfcn", mh, Matrix ()), |
7366
|
971 clipping ("clipping", mh, true), |
7367
|
972 createfcn ("createfcn" , mh, Matrix ()), |
|
973 deletefcn ("deletefcn", mh, Matrix ()), |
7366
|
974 handlevisibility ("handlevisibility", mh, "{on}|callback|off"), |
|
975 hittest ("hittest", mh, true), |
|
976 interruptible ("interruptible", mh, true), |
|
977 selected ("selected", mh, false), |
|
978 selectionhighlight ("selectionhighlight", mh, true), |
|
979 uicontextmenu ("uicontextmenu", mh, graphics_handle ()), |
7367
|
980 userdata ("userdata", mh, Matrix ()), |
7366
|
981 visible ("visible", mh, true) |
7363
|
982 { } |
6874
|
983 |
|
984 virtual ~base_properties (void) { } |
|
985 |
|
986 virtual std::string graphics_object_name (void) const { return "unknonwn"; } |
|
987 |
|
988 void mark_modified (void); |
|
989 |
|
990 void override_defaults (base_graphics_object& obj); |
|
991 |
|
992 // Look through DEFAULTS for properties with given CLASS_NAME, and |
|
993 // apply them to the current object with set (virtual method). |
|
994 |
|
995 void set_from_list (base_graphics_object& obj, property_list& defaults); |
|
996 |
7363
|
997 void insert_property (const std::string& name, property p) |
|
998 { |
|
999 p.set_name (name); |
|
1000 p.set_parent (__myhandle__); |
|
1001 all_props[name] = p; |
|
1002 } |
|
1003 |
|
1004 virtual void set (const caseless_str&, const octave_value&); |
|
1005 |
|
1006 virtual octave_value get (const caseless_str&) const; |
|
1007 |
7379
|
1008 virtual octave_value get (bool all = false) const; |
7363
|
1009 |
|
1010 property get_property (const caseless_str&) const; |
|
1011 |
|
1012 std::string get_tag (void) const { return tag.string_value (); } |
|
1013 |
|
1014 graphics_handle get_parent (void) const { return parent.handle_value (); } |
|
1015 |
|
1016 std::string get_type (void) const { return type.string_value (); } |
|
1017 |
|
1018 bool is_modified (void) const { return __modified__.is_on (); } |
7251
|
1019 |
|
1020 graphics_handle get___myhandle__ (void) const { return __myhandle__; } |
7366
|
1021 |
|
1022 std::string get_busyaction (void) const { return busyaction.current_value (); } |
|
1023 |
|
1024 octave_value get_buttondownfcn (void) const { return buttondownfcn.get (); } |
|
1025 |
|
1026 std::string get_clipping (void) const { return clipping.current_value (); } |
|
1027 |
7367
|
1028 void execute_createfcn (const octave_value& data = octave_value ()) const |
|
1029 { createfcn.execute (data); } |
|
1030 |
7366
|
1031 octave_value get_createfcn (void) const { return createfcn.get (); } |
|
1032 |
7367
|
1033 void execute_deletefcn (const octave_value& data = octave_value ()) const |
|
1034 { deletefcn.execute (data); } |
|
1035 |
7366
|
1036 octave_value get_deletefcn (void) const { return deletefcn.get (); } |
|
1037 |
|
1038 std::string get_handlevisibility (void) const { return handlevisibility.current_value (); } |
|
1039 |
|
1040 std::string get_hittest (void) const { return hittest.current_value (); } |
|
1041 |
|
1042 std::string get_interruptible (void) const { return interruptible.current_value (); } |
|
1043 |
|
1044 std::string get_selected (void) const { return selected.current_value (); } |
|
1045 |
|
1046 std::string get_selectionhighlight (void) const { return selectionhighlight.current_value (); } |
|
1047 |
|
1048 octave_value get_uicontextmenu (void) const { return uicontextmenu.get (); } |
|
1049 |
|
1050 octave_value get_userdata (void) const { return userdata.get (); } |
|
1051 |
|
1052 std::string get_visible (void) const { return visible.current_value (); } |
|
1053 |
7386
|
1054 virtual void remove_child (const graphics_handle& h); |
|
1055 |
|
1056 virtual void adopt (const graphics_handle& h) |
6874
|
1057 { |
|
1058 octave_idx_type n = children.numel (); |
|
1059 children.resize (1, n+1); |
7056
|
1060 children(n) = h.value (); |
6874
|
1061 } |
|
1062 |
7363
|
1063 void set_tag (const octave_value& val) { tag = val; } |
7176
|
1064 |
6874
|
1065 void set_parent (const octave_value& val); |
|
1066 |
7366
|
1067 void set_busyaction (const octave_value& val) |
|
1068 { |
|
1069 if (! error_state) |
|
1070 { |
|
1071 busyaction = val; |
|
1072 mark_modified (); |
|
1073 } |
|
1074 } |
|
1075 |
|
1076 void set_buttondownfcn (const octave_value& val) |
|
1077 { |
|
1078 if (! error_state) |
|
1079 { |
|
1080 buttondownfcn = val; |
|
1081 mark_modified (); |
|
1082 } |
|
1083 } |
|
1084 |
|
1085 void set_clipping (const octave_value& val) |
|
1086 { |
|
1087 if (! error_state) |
|
1088 { |
|
1089 clipping = val; |
|
1090 mark_modified (); |
|
1091 } |
|
1092 } |
|
1093 |
|
1094 void set_createfcn (const octave_value& val) |
|
1095 { |
|
1096 if (! error_state) |
|
1097 { |
|
1098 createfcn = val; |
|
1099 mark_modified (); |
|
1100 } |
|
1101 } |
|
1102 |
|
1103 void set_deletefcn (const octave_value& val) |
|
1104 { |
|
1105 if (! error_state) |
|
1106 { |
|
1107 deletefcn = val; |
|
1108 mark_modified (); |
|
1109 } |
|
1110 } |
|
1111 |
|
1112 void set_handlevisibility (const octave_value& val) |
|
1113 { |
|
1114 if (! error_state) |
|
1115 { |
|
1116 handlevisibility = val; |
|
1117 mark_modified (); |
|
1118 } |
|
1119 } |
|
1120 |
|
1121 void set_hittest (const octave_value& val) |
|
1122 { |
|
1123 if (! error_state) |
|
1124 { |
|
1125 hittest = val; |
|
1126 mark_modified (); |
|
1127 } |
|
1128 } |
|
1129 |
|
1130 void set_interruptible (const octave_value& val) |
|
1131 { |
|
1132 if (! error_state) |
|
1133 { |
|
1134 interruptible = val; |
|
1135 mark_modified (); |
|
1136 } |
|
1137 } |
|
1138 |
|
1139 void set_selected (const octave_value& val) |
|
1140 { |
|
1141 if (! error_state) |
|
1142 { |
|
1143 selected = val; |
|
1144 mark_modified (); |
|
1145 } |
|
1146 } |
|
1147 |
|
1148 void set_selectionhighlight (const octave_value& val) |
|
1149 { |
|
1150 if (! error_state) |
|
1151 { |
|
1152 selectionhighlight = val; |
|
1153 mark_modified (); |
|
1154 } |
|
1155 } |
|
1156 |
|
1157 void set_uicontextmenu (const octave_value& val) |
|
1158 { |
|
1159 if (! error_state) |
|
1160 { |
|
1161 uicontextmenu = val; |
|
1162 mark_modified (); |
|
1163 } |
|
1164 } |
|
1165 |
|
1166 void set_userdata (const octave_value& val) |
|
1167 { |
|
1168 if (! error_state) |
|
1169 { |
|
1170 userdata = val; |
|
1171 mark_modified (); |
|
1172 } |
|
1173 } |
|
1174 |
|
1175 virtual void set_visible (const octave_value& val) |
|
1176 { |
|
1177 if (! error_state) |
|
1178 { |
|
1179 visible = val; |
|
1180 mark_modified (); |
|
1181 } |
|
1182 } |
|
1183 |
|
1184 |
|
1185 |
6874
|
1186 void reparent (const graphics_handle& new_parent) { parent = new_parent; } |
|
1187 |
7214
|
1188 // Update data limits for AXIS_TYPE (xdata, ydata, etc.) in the parent |
|
1189 // axes object. |
|
1190 |
7386
|
1191 virtual void update_axis_limits (const std::string& axis_type) const; |
7214
|
1192 |
6874
|
1193 virtual void delete_children (void); |
|
1194 |
7222
|
1195 Matrix get_children (void) const { return children; } |
|
1196 |
|
1197 // FIXME -- these functions should be generated automatically by the |
|
1198 // genprops.awk script. |
|
1199 // |
|
1200 // EMIT_BASE_PROPERTIES_GET_FUNCTIONS |
7363
|
1201 virtual data_property get_xdata_property (void) const |
7222
|
1202 { |
|
1203 error ("get: invalid property \"xdata\""); |
|
1204 return data_property (); |
|
1205 } |
|
1206 |
7363
|
1207 virtual data_property get_ydata_property (void) const |
7222
|
1208 { |
|
1209 error ("get: invalid property \"ydata\""); |
|
1210 return data_property (); |
|
1211 } |
|
1212 |
7363
|
1213 virtual data_property get_zdata_property (void) const |
7222
|
1214 { |
|
1215 error ("get: invalid property \"zdata\""); |
|
1216 return data_property (); |
|
1217 } |
|
1218 |
7363
|
1219 virtual data_property get_ldata_property (void) const |
7222
|
1220 { |
|
1221 error ("get: invalid property \"ldata\""); |
|
1222 return data_property (); |
|
1223 } |
|
1224 |
7363
|
1225 virtual data_property get_udata_property (void) const |
7222
|
1226 { |
|
1227 error ("get: invalid property \"udata\""); |
|
1228 return data_property (); |
|
1229 } |
|
1230 |
7363
|
1231 virtual data_property get_xldata_property (void) const |
7222
|
1232 { |
|
1233 error ("get: invalid property \"xldata\""); |
|
1234 return data_property (); |
|
1235 } |
|
1236 |
7363
|
1237 virtual data_property get_xudata_property (void) const |
7222
|
1238 { |
|
1239 error ("get: invalid property \"xudata\""); |
|
1240 return data_property (); |
|
1241 } |
|
1242 |
7363
|
1243 virtual data_property get_cdata_property (void) const |
7222
|
1244 { |
|
1245 error ("get: invalid property \"cdata\""); |
|
1246 return data_property (); |
|
1247 } |
|
1248 |
6874
|
1249 protected: |
7363
|
1250 string_property tag; |
|
1251 string_property type; |
|
1252 bool_property __modified__; |
6874
|
1253 graphics_handle __myhandle__; |
7363
|
1254 handle_property parent; |
|
1255 // FIXME: use a property class for children |
6874
|
1256 Matrix children; |
7366
|
1257 radio_property busyaction; |
|
1258 callback_property buttondownfcn; |
|
1259 bool_property clipping; |
|
1260 callback_property createfcn; |
|
1261 callback_property deletefcn; |
|
1262 radio_property handlevisibility; |
|
1263 bool_property hittest; |
|
1264 bool_property interruptible; |
|
1265 bool_property selected; |
|
1266 bool_property selectionhighlight; |
|
1267 handle_property uicontextmenu; |
|
1268 any_property userdata; |
|
1269 bool_property visible; |
7363
|
1270 |
|
1271 protected: |
|
1272 std::map<caseless_str, property> all_props; |
|
1273 |
|
1274 protected: |
|
1275 void insert_static_property (const std::string& name, base_property& p) |
|
1276 { insert_property (name, property (&p, true)); } |
|
1277 |
|
1278 virtual void init (void) { } |
6874
|
1279 }; |
|
1280 |
7365
|
1281 class OCTINTERP_API base_graphics_object |
6874
|
1282 { |
|
1283 public: |
|
1284 friend class graphics_object; |
|
1285 |
|
1286 base_graphics_object (void) : count (1) { } |
|
1287 |
|
1288 base_graphics_object (const base_graphics_object&) { } |
|
1289 |
|
1290 virtual ~base_graphics_object (void) { } |
|
1291 |
|
1292 virtual void mark_modified (void) |
|
1293 { |
7386
|
1294 if (valid_object ()) |
|
1295 get_properties ().mark_modified (); |
|
1296 else |
|
1297 error ("base_graphics_object::mark_modified: invalid graphics object"); |
6874
|
1298 } |
|
1299 |
7386
|
1300 virtual void override_defaults (base_graphics_object& obj) |
6874
|
1301 { |
7386
|
1302 if (valid_object ()) |
|
1303 get_properties ().override_defaults (obj); |
|
1304 else |
|
1305 error ("base_graphics_object::override_defaults: invalid graphics object"); |
6874
|
1306 } |
|
1307 |
7386
|
1308 virtual void set_from_list (property_list& plist) |
6874
|
1309 { |
7386
|
1310 if (valid_object ()) |
|
1311 get_properties ().set_from_list (*this, plist); |
|
1312 else |
|
1313 error ("base_graphics_object::set_from_list: invalid graphics object"); |
6874
|
1314 } |
|
1315 |
7386
|
1316 virtual void set (const caseless_str& pname, const octave_value& pval) |
6874
|
1317 { |
7386
|
1318 if (valid_object ()) |
|
1319 get_properties ().set (pname, pval); |
|
1320 else |
|
1321 error ("base_graphics_object::set: invalid graphics object"); |
6874
|
1322 } |
|
1323 |
|
1324 virtual void set_defaults (const std::string&) |
|
1325 { |
|
1326 error ("base_graphics_object::set_defaults: invalid graphics object"); |
|
1327 } |
|
1328 |
7379
|
1329 virtual octave_value get (bool all = false) const |
6874
|
1330 { |
7386
|
1331 if (valid_object ()) |
|
1332 return get_properties ().get (all); |
|
1333 else |
|
1334 { |
|
1335 error ("base_graphics_object::get: invalid graphics object"); |
|
1336 return octave_value (); |
|
1337 } |
6874
|
1338 } |
|
1339 |
7386
|
1340 virtual octave_value get (const caseless_str& pname) const |
6874
|
1341 { |
7386
|
1342 if (valid_object ()) |
|
1343 return get_properties ().get (pname); |
|
1344 else |
|
1345 { |
|
1346 error ("base_graphics_object::get: invalid graphics object"); |
|
1347 return octave_value (); |
|
1348 } |
6874
|
1349 } |
|
1350 |
7189
|
1351 virtual octave_value get_default (const caseless_str&) const; |
6874
|
1352 |
7189
|
1353 virtual octave_value get_factory_default (const caseless_str&) const; |
6874
|
1354 |
|
1355 virtual octave_value get_defaults (void) const |
|
1356 { |
|
1357 error ("base_graphics_object::get_defaults: invalid graphics object"); |
|
1358 return octave_value (); |
|
1359 } |
|
1360 |
|
1361 virtual octave_value get_factory_defaults (void) const |
|
1362 { |
|
1363 error ("base_graphics_object::get_factory_defaults: invalid graphics object"); |
|
1364 return octave_value (); |
|
1365 } |
|
1366 |
|
1367 virtual graphics_handle get_parent (void) const |
|
1368 { |
7386
|
1369 if (valid_object ()) |
|
1370 return get_properties ().get_parent (); |
|
1371 else |
|
1372 { |
|
1373 error ("base_graphics_object::get_parent: invalid graphics object"); |
|
1374 return graphics_handle (); |
|
1375 } |
6874
|
1376 } |
|
1377 |
7386
|
1378 virtual void remove_child (const graphics_handle& h) |
6874
|
1379 { |
7386
|
1380 if (valid_object ()) |
|
1381 get_properties ().remove_child (h); |
|
1382 else |
|
1383 error ("base_graphics_object::remove_child: invalid graphics object"); |
6874
|
1384 } |
|
1385 |
7386
|
1386 virtual void adopt (const graphics_handle& h) |
6874
|
1387 { |
7386
|
1388 if (valid_object ()) |
|
1389 get_properties ().adopt (h); |
|
1390 else |
|
1391 error ("base_graphics_object::adopt: invalid graphics object"); |
6874
|
1392 } |
|
1393 |
7386
|
1394 virtual void reparent (const graphics_handle& np) |
6874
|
1395 { |
7386
|
1396 if (valid_object ()) |
|
1397 get_properties ().reparent (np); |
|
1398 else |
|
1399 error ("base_graphics_object::reparent: invalid graphics object"); |
6874
|
1400 } |
|
1401 |
|
1402 virtual void defaults (void) const |
|
1403 { |
7386
|
1404 if (valid_object ()) |
|
1405 { |
|
1406 std::string msg = (type () + "::defaults"); |
|
1407 gripe_not_implemented (msg.c_str ()); |
|
1408 } |
|
1409 else |
|
1410 error ("base_graphics_object::default: invalid graphics object"); |
6874
|
1411 } |
|
1412 |
|
1413 virtual base_properties& get_properties (void) |
|
1414 { |
|
1415 static base_properties properties; |
|
1416 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
1417 return properties; |
|
1418 } |
|
1419 |
7222
|
1420 virtual const base_properties& get_properties (void) const |
|
1421 { |
|
1422 static base_properties properties; |
|
1423 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
1424 return properties; |
|
1425 } |
|
1426 |
|
1427 virtual void update_axis_limits (const std::string&) |
7214
|
1428 { |
|
1429 error ("base_graphics_object::update_axis_limits: invalid graphics object"); |
|
1430 } |
|
1431 |
6874
|
1432 virtual bool valid_object (void) const { return false; } |
|
1433 |
7386
|
1434 virtual std::string type (void) const |
|
1435 { |
|
1436 return (valid_object () ? get_properties ().graphics_object_name () |
|
1437 : "unknown"); |
|
1438 } |
6874
|
1439 |
|
1440 bool isa (const std::string& go_name) const |
|
1441 { |
|
1442 return type () == go_name; |
|
1443 } |
|
1444 |
|
1445 protected: |
|
1446 // A reference count. |
|
1447 int count; |
|
1448 }; |
|
1449 |
7365
|
1450 class OCTINTERP_API graphics_object |
6874
|
1451 { |
|
1452 public: |
|
1453 graphics_object (void) : rep (new base_graphics_object ()) { } |
|
1454 |
|
1455 graphics_object (base_graphics_object *new_rep) |
|
1456 : rep (new_rep) { } |
|
1457 |
|
1458 graphics_object (const graphics_object& obj) |
|
1459 { |
|
1460 rep = obj.rep; |
|
1461 rep->count++; |
|
1462 } |
|
1463 |
|
1464 graphics_object& operator = (const graphics_object& obj) |
|
1465 { |
|
1466 if (rep != obj.rep) |
|
1467 { |
|
1468 if (--rep->count == 0) |
|
1469 delete rep; |
|
1470 |
|
1471 rep = obj.rep; |
|
1472 rep->count++; |
|
1473 } |
|
1474 |
|
1475 return *this; |
|
1476 } |
|
1477 |
|
1478 ~graphics_object (void) |
|
1479 { |
|
1480 if (--rep->count == 0) |
|
1481 delete rep; |
|
1482 } |
|
1483 |
|
1484 void mark_modified (void) { rep->mark_modified (); } |
|
1485 |
|
1486 void override_defaults (base_graphics_object& obj) |
|
1487 { |
|
1488 rep->override_defaults (obj); |
|
1489 } |
|
1490 |
7214
|
1491 void set_from_list (property_list& plist) { rep->set_from_list (plist); } |
6874
|
1492 |
7189
|
1493 void set (const caseless_str& name, const octave_value& val) |
6874
|
1494 { |
|
1495 rep->set (name, val); |
|
1496 } |
|
1497 |
|
1498 void set (const octave_value_list& args); |
|
1499 |
7214
|
1500 void set_defaults (const std::string& mode) { rep->set_defaults (mode); } |
|
1501 |
7379
|
1502 octave_value get (bool all = false) const { return rep->get (all); } |
6874
|
1503 |
7189
|
1504 octave_value get (const caseless_str& name) const |
6874
|
1505 { |
|
1506 return name.compare ("default") |
|
1507 ? get_defaults () |
|
1508 : (name.compare ("factory") |
|
1509 ? get_factory_defaults () : rep->get (name)); |
|
1510 } |
|
1511 |
7189
|
1512 octave_value get_default (const caseless_str& name) const |
6874
|
1513 { |
|
1514 return rep->get_default (name); |
|
1515 } |
|
1516 |
7189
|
1517 octave_value get_factory_default (const caseless_str& name) const |
6874
|
1518 { |
|
1519 return rep->get_factory_default (name); |
|
1520 } |
|
1521 |
|
1522 octave_value get_defaults (void) const { return rep->get_defaults (); } |
|
1523 |
|
1524 octave_value get_factory_defaults (void) const |
|
1525 { |
|
1526 return rep->get_factory_defaults (); |
|
1527 } |
|
1528 |
|
1529 graphics_handle get_parent (void) const { return rep->get_parent (); } |
|
1530 |
7214
|
1531 void remove_child (const graphics_handle& h) { rep->remove_child (h); } |
|
1532 |
|
1533 void adopt (const graphics_handle& h) { rep->adopt (h); } |
|
1534 |
|
1535 void reparent (const graphics_handle& h) { rep->reparent (h); } |
6874
|
1536 |
|
1537 void defaults (void) const { rep->defaults (); } |
|
1538 |
|
1539 bool isa (const std::string& go_name) const { return rep->isa (go_name); } |
|
1540 |
|
1541 base_properties& get_properties (void) { return rep->get_properties (); } |
|
1542 |
7222
|
1543 const base_properties& get_properties (void) const |
|
1544 { |
|
1545 return rep->get_properties (); |
|
1546 } |
|
1547 |
7214
|
1548 void update_axis_limits (const std::string& axis_type) |
|
1549 { |
|
1550 rep->update_axis_limits (axis_type); |
|
1551 } |
|
1552 |
6874
|
1553 bool valid_object (void) const { return rep->valid_object (); } |
|
1554 |
|
1555 operator bool (void) const { return rep->valid_object (); } |
|
1556 |
7222
|
1557 // FIXME -- these functions should be generated automatically by the |
|
1558 // genprops.awk script. |
|
1559 // |
|
1560 // EMIT_GRAPHICS_OBJECT_GET_FUNCTIONS |
7363
|
1561 data_property get_xdata_property (void) const |
7222
|
1562 { |
|
1563 const base_properties& props = get_properties (); |
7363
|
1564 return props.get_xdata_property (); |
7222
|
1565 } |
|
1566 |
7363
|
1567 data_property get_ydata_property (void) const |
7222
|
1568 { |
|
1569 const base_properties& props = get_properties (); |
7363
|
1570 return props.get_ydata_property (); |
7222
|
1571 } |
|
1572 |
7363
|
1573 data_property get_zdata_property (void) const |
7222
|
1574 { |
|
1575 const base_properties& props = get_properties (); |
7363
|
1576 return props.get_zdata_property (); |
7222
|
1577 } |
|
1578 |
7363
|
1579 data_property get_ldata_property (void) const |
7222
|
1580 { |
|
1581 const base_properties& props = get_properties (); |
7363
|
1582 return props.get_ldata_property (); |
7222
|
1583 } |
|
1584 |
7363
|
1585 data_property get_udata_property (void) const |
7222
|
1586 { |
|
1587 const base_properties& props = get_properties (); |
7363
|
1588 return props.get_udata_property (); |
7222
|
1589 } |
|
1590 |
7363
|
1591 data_property get_xldata_property (void) const |
7222
|
1592 { |
|
1593 const base_properties& props = get_properties (); |
7363
|
1594 return props.get_xldata_property (); |
7222
|
1595 } |
|
1596 |
7363
|
1597 data_property get_xudata_property (void) const |
7222
|
1598 { |
|
1599 const base_properties& props = get_properties (); |
7363
|
1600 return props.get_xudata_property (); |
7222
|
1601 } |
|
1602 |
7363
|
1603 data_property get_cdata_property (void) const |
7222
|
1604 { |
|
1605 const base_properties& props = get_properties (); |
7363
|
1606 return props.get_cdata_property (); |
7222
|
1607 } |
|
1608 |
6874
|
1609 private: |
|
1610 base_graphics_object *rep; |
|
1611 }; |
|
1612 |
|
1613 // --------------------------------------------------------------------- |
|
1614 |
7365
|
1615 class OCTINTERP_API root_figure : public base_graphics_object |
6874
|
1616 { |
|
1617 public: |
|
1618 class properties : public base_properties |
|
1619 { |
|
1620 public: |
|
1621 // See the genprops.awk script for an explanation of the |
|
1622 // properties declarations. |
|
1623 |
7363
|
1624 BEGIN_PROPERTIES(root_figure) |
|
1625 handle_property currentfigure S , graphics_handle () |
6874
|
1626 END_PROPERTIES |
|
1627 }; |
|
1628 |
|
1629 private: |
|
1630 properties xproperties; |
|
1631 |
|
1632 public: |
|
1633 |
7363
|
1634 root_figure (void) : xproperties (0, graphics_handle ()), default_properties () { } |
6874
|
1635 |
|
1636 ~root_figure (void) { xproperties.delete_children (); } |
|
1637 |
|
1638 void mark_modified (void) { } |
|
1639 |
|
1640 void override_defaults (base_graphics_object& obj) |
|
1641 { |
|
1642 // Now override with our defaults. If the default_properties |
|
1643 // list includes the properties for all defaults (line, |
|
1644 // surface, etc.) then we don't have to know the type of OBJ |
|
1645 // here, we just call its set function and let it decide which |
|
1646 // properties from the list to use. |
|
1647 obj.set_from_list (default_properties); |
|
1648 } |
|
1649 |
7189
|
1650 void set (const caseless_str& name, const octave_value& value) |
6874
|
1651 { |
|
1652 if (name.compare ("default", 7)) |
|
1653 // strip "default", pass rest to function that will |
|
1654 // parse the remainder and add the element to the |
|
1655 // default_properties map. |
|
1656 default_properties.set (name.substr (7), value); |
|
1657 else |
|
1658 xproperties.set (name, value); |
|
1659 } |
|
1660 |
7189
|
1661 octave_value get (const caseless_str& name) const |
6874
|
1662 { |
|
1663 octave_value retval; |
|
1664 |
|
1665 if (name.compare ("default", 7)) |
|
1666 return get_default (name.substr (7)); |
|
1667 else if (name.compare ("factory", 7)) |
|
1668 return get_factory_default (name.substr (7)); |
|
1669 else |
|
1670 retval = xproperties.get (name); |
|
1671 |
|
1672 return retval; |
|
1673 } |
|
1674 |
7189
|
1675 octave_value get_default (const caseless_str& name) const |
6874
|
1676 { |
|
1677 octave_value retval = default_properties.lookup (name); |
|
1678 |
|
1679 if (retval.is_undefined ()) |
|
1680 error ("get: invalid default property `%s'", name.c_str ()); |
|
1681 |
|
1682 return retval; |
|
1683 } |
|
1684 |
7189
|
1685 octave_value get_factory_default (const caseless_str& name) const |
6874
|
1686 { |
|
1687 octave_value retval = factory_properties.lookup (name); |
|
1688 |
|
1689 if (retval.is_undefined ()) |
|
1690 error ("get: invalid factory default property `%s'", name.c_str ()); |
|
1691 |
|
1692 return retval; |
|
1693 } |
|
1694 |
|
1695 octave_value get_defaults (void) const |
|
1696 { |
|
1697 return default_properties.as_struct ("default"); |
|
1698 } |
|
1699 |
|
1700 octave_value get_factory_defaults (void) const |
|
1701 { |
|
1702 return factory_properties.as_struct ("factory"); |
|
1703 } |
|
1704 |
|
1705 base_properties& get_properties (void) { return xproperties; } |
|
1706 |
7222
|
1707 const base_properties& get_properties (void) const { return xproperties; } |
|
1708 |
6874
|
1709 bool valid_object (void) const { return true; } |
|
1710 |
|
1711 private: |
|
1712 property_list default_properties; |
|
1713 |
|
1714 static property_list factory_properties; |
|
1715 |
|
1716 static property_list::plist_map_type init_factory_properties (void); |
|
1717 }; |
|
1718 |
|
1719 // --------------------------------------------------------------------- |
|
1720 |
7365
|
1721 class OCTINTERP_API figure : public base_graphics_object |
6874
|
1722 { |
|
1723 public: |
|
1724 class properties : public base_properties |
|
1725 { |
|
1726 public: |
|
1727 void close (void); |
7366
|
1728 void set_visible (const octave_value& val); |
6874
|
1729 |
|
1730 // See the genprops.awk script for an explanation of the |
|
1731 // properties declarations. |
|
1732 |
7363
|
1733 BEGIN_PROPERTIES(figure) |
7379
|
1734 any_property __plot_stream__ h , Matrix () |
|
1735 bool_property __enhanced__ h , "on" |
7363
|
1736 radio_property nextplot , "add|replace_children|{replace}" |
|
1737 callback_property closerequestfcn , "closereq" |
|
1738 handle_property currentaxes S , graphics_handle () |
|
1739 array_property colormap , jet_colormap () |
|
1740 radio_property paperorientation , "{portrait}|landscape" |
|
1741 color_property color , color_values (1, 1, 1) |
6874
|
1742 END_PROPERTIES |
7363
|
1743 |
|
1744 protected: |
|
1745 void init (void) |
|
1746 { |
|
1747 colormap.add_constraint (dim_vector (-1, 3)); |
|
1748 } |
6874
|
1749 }; |
|
1750 |
|
1751 private: |
|
1752 properties xproperties; |
|
1753 |
|
1754 public: |
|
1755 figure (const graphics_handle& mh, const graphics_handle& p) |
|
1756 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1757 { |
|
1758 xproperties.override_defaults (*this); |
|
1759 } |
|
1760 |
|
1761 ~figure (void) |
|
1762 { |
7386
|
1763 xproperties.delete_children (); |
6874
|
1764 xproperties.close (); |
|
1765 } |
|
1766 |
|
1767 void override_defaults (base_graphics_object& obj) |
|
1768 { |
|
1769 // Allow parent (root figure) to override first (properties knows how |
|
1770 // to find the parent object). |
|
1771 xproperties.override_defaults (obj); |
|
1772 |
|
1773 // Now override with our defaults. If the default_properties |
|
1774 // list includes the properties for all defaults (line, |
|
1775 // surface, etc.) then we don't have to know the type of OBJ |
|
1776 // here, we just call its set function and let it decide which |
|
1777 // properties from the list to use. |
|
1778 obj.set_from_list (default_properties); |
|
1779 } |
|
1780 |
7189
|
1781 void set (const caseless_str& name, const octave_value& value) |
6874
|
1782 { |
|
1783 if (name.compare ("default", 7)) |
|
1784 // strip "default", pass rest to function that will |
|
1785 // parse the remainder and add the element to the |
|
1786 // default_properties map. |
|
1787 default_properties.set (name.substr (7), value); |
|
1788 else |
|
1789 xproperties.set (name, value); |
|
1790 } |
|
1791 |
7189
|
1792 octave_value get (const caseless_str& name) const |
6874
|
1793 { |
|
1794 octave_value retval; |
|
1795 |
|
1796 if (name.compare ("default", 7)) |
|
1797 retval = get_default (name.substr (7)); |
|
1798 else |
|
1799 retval = xproperties.get (name); |
|
1800 |
|
1801 return retval; |
|
1802 } |
|
1803 |
7189
|
1804 octave_value get_default (const caseless_str& name) const; |
6874
|
1805 |
|
1806 octave_value get_defaults (void) const |
|
1807 { |
|
1808 return default_properties.as_struct ("default"); |
|
1809 } |
|
1810 |
|
1811 base_properties& get_properties (void) { return xproperties; } |
|
1812 |
7222
|
1813 const base_properties& get_properties (void) const { return xproperties; } |
|
1814 |
6874
|
1815 bool valid_object (void) const { return true; } |
|
1816 |
|
1817 private: |
|
1818 property_list default_properties; |
|
1819 }; |
|
1820 |
|
1821 // --------------------------------------------------------------------- |
|
1822 |
7365
|
1823 class OCTINTERP_API axes : public base_graphics_object |
6874
|
1824 { |
|
1825 public: |
|
1826 class properties : public base_properties |
|
1827 { |
|
1828 public: |
|
1829 void set_defaults (base_graphics_object& obj, const std::string& mode); |
|
1830 |
|
1831 void remove_child (const graphics_handle& h); |
|
1832 |
|
1833 void delete_children (void); |
|
1834 |
|
1835 // See the genprops.awk script for an explanation of the |
|
1836 // properties declarations. |
|
1837 |
7363
|
1838 BEGIN_PROPERTIES(axes) |
|
1839 array_property position , Matrix () |
|
1840 mutable handle_property title GSO , graphics_handle () |
|
1841 bool_property box , "on" |
|
1842 bool_property key , "off" |
|
1843 bool_property keybox , "off" |
|
1844 double_property keypos , 1 |
|
1845 array_property colororder , default_colororder () |
|
1846 array_property dataaspectratio m , Matrix (1, 3, 1.0) |
|
1847 radio_property dataaspectratiomode , "{auto}|manual" |
7379
|
1848 radio_property layer , "{bottom}|top" |
7363
|
1849 array_property xlim m , default_lim () |
|
1850 array_property ylim m , default_lim () |
|
1851 array_property zlim m , default_lim () |
|
1852 array_property clim m , default_lim () |
|
1853 radio_property xlimmode al , "{auto}|manual" |
|
1854 radio_property ylimmode al , "{auto}|manual" |
|
1855 radio_property zlimmode al , "{auto}|manual" |
|
1856 radio_property climmode al , "{auto}|manual" |
|
1857 mutable handle_property xlabel GSO , graphics_handle () |
|
1858 mutable handle_property ylabel GSO , graphics_handle () |
|
1859 mutable handle_property zlabel GSO , graphics_handle () |
|
1860 bool_property xgrid , "off" |
|
1861 bool_property ygrid , "off" |
|
1862 bool_property zgrid , "off" |
|
1863 bool_property xminorgrid , "off" |
|
1864 bool_property yminorgrid , "off" |
|
1865 bool_property zminorgrid , "off" |
|
1866 array_property xtick m , Matrix () |
|
1867 array_property ytick m , Matrix () |
|
1868 array_property ztick m , Matrix () |
|
1869 radio_property xtickmode , "{auto}|manual" |
|
1870 radio_property ytickmode , "{auto}|manual" |
|
1871 radio_property ztickmode , "{auto}|manual" |
|
1872 any_property xticklabel m , "" |
|
1873 any_property yticklabel m , "" |
|
1874 any_property zticklabel m , "" |
|
1875 radio_property xticklabelmode , "{auto}|manual" |
|
1876 radio_property yticklabelmode , "{auto}|manual" |
|
1877 radio_property zticklabelmode , "{auto}|manual" |
7379
|
1878 color_property color , color_property (color_values (1, 1, 1), radio_values ("none")) |
7363
|
1879 color_property xcolor , color_values (0, 0, 0) |
|
1880 color_property ycolor , color_values (0, 0, 0) |
|
1881 color_property zcolor , color_values (0, 0, 0) |
|
1882 radio_property xscale al , "{linear}|log" |
|
1883 radio_property yscale al , "{linear}|log" |
|
1884 radio_property zscale al , "{linear}|log" |
|
1885 radio_property xdir , "{normal}|reverse" |
|
1886 radio_property ydir , "{normal}|reverse" |
|
1887 radio_property zdir , "{normal}|reverse" |
7365
|
1888 radio_property yaxislocation , "{left}|right|zero" |
|
1889 radio_property xaxislocation , "{bottom}|top|zero" |
7363
|
1890 array_property view , Matrix () |
|
1891 radio_property nextplot , "add|replace_children|{replace}" |
|
1892 array_property outerposition , Matrix () |
7379
|
1893 radio_property activepositionproperty , "{outerposition}|position" |
|
1894 radio_property __colorbar__ h , "{none}|north|south|east|west|northoutside|southoutside|eastoutside|westoutside" |
7189
|
1895 END_PROPERTIES |
6874
|
1896 |
7363
|
1897 protected: |
|
1898 void init (void) |
|
1899 { |
|
1900 position.add_constraint (dim_vector (1, 4)); |
|
1901 position.add_constraint (dim_vector (0, 0)); |
|
1902 outerposition.add_constraint (dim_vector (1, 4)); |
|
1903 colororder.add_constraint (dim_vector (-1, 3)); |
|
1904 dataaspectratio.add_constraint (dim_vector (1, 3)); |
|
1905 xlim.add_constraint (dim_vector (1, 2)); |
|
1906 ylim.add_constraint (dim_vector (1, 2)); |
|
1907 zlim.add_constraint (dim_vector (1, 2)); |
|
1908 clim.add_constraint (dim_vector (1, 2)); |
|
1909 xtick.add_constraint (dim_vector (1, -1)); |
|
1910 ytick.add_constraint (dim_vector (1, -1)); |
|
1911 ztick.add_constraint (dim_vector (1, -1)); |
|
1912 Matrix vw (1, 2, 0); |
|
1913 vw(1) = 90; |
|
1914 view = vw; |
|
1915 view.add_constraint (dim_vector (1, 2)); |
|
1916 } |
6874
|
1917 }; |
|
1918 |
|
1919 private: |
|
1920 properties xproperties; |
|
1921 |
|
1922 public: |
|
1923 axes (const graphics_handle& mh, const graphics_handle& p) |
|
1924 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1925 { |
|
1926 xproperties.override_defaults (*this); |
|
1927 } |
|
1928 |
|
1929 ~axes (void) { xproperties.delete_children (); } |
|
1930 |
|
1931 void override_defaults (base_graphics_object& obj) |
|
1932 { |
|
1933 // Allow parent (figure) to override first (properties knows how |
|
1934 // to find the parent object). |
|
1935 xproperties.override_defaults (obj); |
|
1936 |
|
1937 // Now override with our defaults. If the default_properties |
|
1938 // list includes the properties for all defaults (line, |
|
1939 // surface, etc.) then we don't have to know the type of OBJ |
|
1940 // here, we just call its set function and let it decide which |
|
1941 // properties from the list to use. |
|
1942 obj.set_from_list (default_properties); |
|
1943 } |
|
1944 |
7189
|
1945 void set (const caseless_str& name, const octave_value& value) |
6874
|
1946 { |
|
1947 if (name.compare ("default", 7)) |
|
1948 // strip "default", pass rest to function that will |
|
1949 // parse the remainder and add the element to the |
|
1950 // default_properties map. |
|
1951 default_properties.set (name.substr (7), value); |
|
1952 else |
|
1953 xproperties.set (name, value); |
|
1954 } |
|
1955 |
|
1956 void set_defaults (const std::string& mode) |
|
1957 { |
|
1958 xproperties.set_defaults (*this, mode); |
|
1959 } |
|
1960 |
7189
|
1961 octave_value get (const caseless_str& name) const |
6874
|
1962 { |
|
1963 octave_value retval; |
|
1964 |
|
1965 // FIXME -- finish this. |
|
1966 if (name.compare ("default", 7)) |
|
1967 retval = get_default (name.substr (7)); |
|
1968 else |
|
1969 retval = xproperties.get (name); |
|
1970 |
|
1971 return retval; |
|
1972 } |
|
1973 |
7189
|
1974 octave_value get_default (const caseless_str& name) const; |
6874
|
1975 |
|
1976 octave_value get_defaults (void) const |
|
1977 { |
|
1978 return default_properties.as_struct ("default"); |
|
1979 } |
|
1980 |
|
1981 base_properties& get_properties (void) { return xproperties; } |
|
1982 |
7222
|
1983 const base_properties& get_properties (void) const { return xproperties; } |
|
1984 |
7214
|
1985 void update_axis_limits (const std::string& axis_type); |
|
1986 |
6874
|
1987 bool valid_object (void) const { return true; } |
|
1988 |
|
1989 private: |
|
1990 property_list default_properties; |
|
1991 }; |
|
1992 |
|
1993 // --------------------------------------------------------------------- |
|
1994 |
7365
|
1995 class OCTINTERP_API line : public base_graphics_object |
6874
|
1996 { |
|
1997 public: |
|
1998 class properties : public base_properties |
|
1999 { |
|
2000 public: |
|
2001 // See the genprops.awk script for an explanation of the |
|
2002 // properties declarations. |
|
2003 |
7366
|
2004 // properties which are not in matlab: |
7384
|
2005 // ldata, udata, xldata, xudata, keylabel, interpreter |
7366
|
2006 |
7363
|
2007 BEGIN_PROPERTIES(line) |
|
2008 data_property xdata l , default_data () |
|
2009 data_property ydata l , default_data () |
|
2010 data_property zdata l , Matrix () |
|
2011 data_property ldata l , Matrix () |
|
2012 data_property udata l , Matrix () |
|
2013 data_property xldata l , Matrix () |
|
2014 data_property xudata l , Matrix () |
|
2015 color_property color , color_values (0, 0, 0) |
|
2016 radio_property linestyle , "{-}|--|:|-.|none" |
|
2017 double_property linewidth , 0.5 |
|
2018 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2019 color_property markeredgecolor , "{auto}|none" |
|
2020 color_property markerfacecolor , "auto|{none}" |
|
2021 double_property markersize , 6 |
|
2022 string_property keylabel , "" |
7384
|
2023 radio_property interpreter , "{tex}|none|latex" |
7377
|
2024 string_property displayname , "" |
7380
|
2025 radio_property erasemode , "{normal}|none|xor|background" |
6874
|
2026 END_PROPERTIES |
|
2027 }; |
|
2028 |
|
2029 private: |
|
2030 properties xproperties; |
|
2031 |
|
2032 public: |
|
2033 line (const graphics_handle& mh, const graphics_handle& p) |
|
2034 : base_graphics_object (), xproperties (mh, p) |
|
2035 { |
|
2036 xproperties.override_defaults (*this); |
|
2037 } |
|
2038 |
|
2039 ~line (void) { xproperties.delete_children (); } |
|
2040 |
|
2041 base_properties& get_properties (void) { return xproperties; } |
|
2042 |
7222
|
2043 const base_properties& get_properties (void) const { return xproperties; } |
|
2044 |
6874
|
2045 bool valid_object (void) const { return true; } |
|
2046 }; |
|
2047 |
|
2048 // --------------------------------------------------------------------- |
|
2049 |
7365
|
2050 class OCTINTERP_API text : public base_graphics_object |
6874
|
2051 { |
|
2052 public: |
|
2053 class properties : public base_properties |
|
2054 { |
|
2055 public: |
|
2056 // See the genprops.awk script for an explanation of the |
|
2057 // properties declarations. |
|
2058 |
7363
|
2059 BEGIN_PROPERTIES(text) |
|
2060 string_property string , "" |
|
2061 radio_property units , "{data}|pixels|normalized|inches|centimeters|points" |
|
2062 array_property position , Matrix (1, 3, 0.0) |
|
2063 double_property rotation , 0 |
|
2064 radio_property horizontalalignment , "{left}|center|right" |
|
2065 color_property color , color_values (0, 0, 0) |
|
2066 string_property fontname , "Helvetica" |
|
2067 double_property fontsize , 10 |
7379
|
2068 radio_property fontangle , "{normal}|italic|oblique" |
|
2069 radio_property fontweight , "light|{normal}|demi|bold" |
|
2070 radio_property interpreter , "{tex}|none|latex" |
7377
|
2071 color_property backgroundcolor , "{none}" |
|
2072 string_property displayname , "" |
|
2073 color_property edgecolor , "{none}" |
7380
|
2074 radio_property erasemode , "{normal}|none|xor|background" |
7377
|
2075 bool_property editing , "off" |
|
2076 radio_property fontunits , "inches|centimeters|normalized|{points}|pixel" |
|
2077 radio_property linestyle , "{-}|--|:|-.|none" |
|
2078 double_property linewidth , 0.5 |
|
2079 double_property margin , 1 |
|
2080 radio_property verticalalignment , "top|cap|{middle}|baseline|bottom" |
6874
|
2081 END_PROPERTIES |
|
2082 |
7363
|
2083 protected: |
|
2084 void init (void) |
|
2085 { |
|
2086 position.add_constraint (dim_vector (1, 3)); |
|
2087 } |
6874
|
2088 }; |
|
2089 |
|
2090 private: |
|
2091 properties xproperties; |
|
2092 |
|
2093 public: |
|
2094 text (const graphics_handle& mh, const graphics_handle& p) |
|
2095 : base_graphics_object (), xproperties (mh, p) |
|
2096 { |
|
2097 xproperties.override_defaults (*this); |
|
2098 } |
|
2099 |
|
2100 ~text (void) { xproperties.delete_children (); } |
|
2101 |
|
2102 base_properties& get_properties (void) { return xproperties; } |
|
2103 |
7222
|
2104 const base_properties& get_properties (void) const { return xproperties; } |
|
2105 |
6874
|
2106 bool valid_object (void) const { return true; } |
|
2107 }; |
|
2108 |
|
2109 // --------------------------------------------------------------------- |
|
2110 |
7365
|
2111 class OCTINTERP_API image : public base_graphics_object |
6874
|
2112 { |
|
2113 public: |
|
2114 class properties : public base_properties |
|
2115 { |
|
2116 public: |
|
2117 // See the genprops.awk script for an explanation of the |
|
2118 // properties declarations. |
|
2119 |
7363
|
2120 BEGIN_PROPERTIES(image) |
|
2121 data_property xdata l , Matrix () |
|
2122 data_property ydata l , Matrix () |
|
2123 data_property cdata l , Matrix () |
6874
|
2124 END_PROPERTIES |
|
2125 |
7363
|
2126 protected: |
|
2127 void init (void) |
|
2128 { |
|
2129 } |
6874
|
2130 }; |
|
2131 |
|
2132 private: |
|
2133 properties xproperties; |
|
2134 |
|
2135 public: |
|
2136 image (const graphics_handle& mh, const graphics_handle& p) |
|
2137 : base_graphics_object (), xproperties (mh, p) |
|
2138 { |
|
2139 xproperties.override_defaults (*this); |
|
2140 } |
|
2141 |
|
2142 ~image (void) { xproperties.delete_children (); } |
|
2143 |
|
2144 base_properties& get_properties (void) { return xproperties; } |
|
2145 |
7222
|
2146 const base_properties& get_properties (void) const { return xproperties; } |
|
2147 |
6874
|
2148 bool valid_object (void) const { return true; } |
|
2149 }; |
|
2150 |
|
2151 // --------------------------------------------------------------------- |
|
2152 |
7365
|
2153 class OCTINTERP_API patch : public base_graphics_object |
6874
|
2154 { |
|
2155 public: |
|
2156 class properties : public base_properties |
|
2157 { |
|
2158 public: |
|
2159 // See the genprops.awk script for an explanation of the |
|
2160 // properties declarations. |
|
2161 |
7363
|
2162 BEGIN_PROPERTIES(patch) |
7368
|
2163 data_property xdata l , Matrix () |
7363
|
2164 data_property ydata l , Matrix () |
|
2165 data_property zdata l , Matrix () |
|
2166 data_property cdata l , Matrix () |
7379
|
2167 radio_property cdatamapping , "{scaled}|direct" |
7363
|
2168 array_property faces , Matrix () |
7368
|
2169 data_property facevertexalphadata , Matrix () |
|
2170 data_property facevertexcdata , Matrix () |
7363
|
2171 array_property vertices , Matrix () |
7368
|
2172 array_property vertexnormals , Matrix () |
7379
|
2173 radio_property normalmode , "{auto}|manual" |
|
2174 color_property facecolor , "{flat}|none|interp" |
7363
|
2175 double_property facealpha , 1.0 |
7379
|
2176 radio_property facelighting , "{flat}|none|gouraud|phong" |
|
2177 color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
7368
|
2178 double_property edgealpha , 1.0 |
7379
|
2179 radio_property edgelighting , "{none}|flat|gouraud|phong" |
|
2180 radio_property backfacelighting , "{reverselit}|unlit|lit" |
7368
|
2181 double_property ambientstrength , 0.3 |
|
2182 double_property diffusestrength , 0.6 |
|
2183 double_property specularstrength , 0.6 |
|
2184 double_property specularexponent , 10.0 |
|
2185 double_property specularcolorreflectance , 1.0 |
7379
|
2186 radio_property erasemode , "{normal}|background|xor|none" |
7363
|
2187 radio_property linestyle , "{-}|--|:|-.|none" |
|
2188 double_property linewidth , 0.5 |
|
2189 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2190 color_property markeredgecolor , "{auto}|none" |
|
2191 color_property markerfacecolor , "auto|{none}" |
|
2192 double_property markersize , 6 |
|
2193 string_property keylabel , "" |
7384
|
2194 radio_property interpreter , "{tex}|none|latex" |
6874
|
2195 END_PROPERTIES |
|
2196 |
7363
|
2197 protected: |
|
2198 void init (void) |
|
2199 { |
|
2200 vertices.add_constraint (dim_vector (-1, 2)); |
|
2201 vertices.add_constraint (dim_vector (-1, 3)); |
|
2202 } |
6874
|
2203 }; |
|
2204 |
|
2205 private: |
|
2206 properties xproperties; |
|
2207 |
|
2208 public: |
|
2209 patch (const graphics_handle& mh, const graphics_handle& p) |
|
2210 : base_graphics_object (), xproperties (mh, p) |
|
2211 { |
|
2212 xproperties.override_defaults (*this); |
|
2213 } |
|
2214 |
|
2215 ~patch (void) { xproperties.delete_children (); } |
|
2216 |
|
2217 base_properties& get_properties (void) { return xproperties; } |
|
2218 |
7222
|
2219 const base_properties& get_properties (void) const { return xproperties; } |
|
2220 |
6874
|
2221 bool valid_object (void) const { return true; } |
|
2222 }; |
|
2223 |
|
2224 // --------------------------------------------------------------------- |
|
2225 |
7365
|
2226 class OCTINTERP_API surface : public base_graphics_object |
6874
|
2227 { |
|
2228 public: |
|
2229 class properties : public base_properties |
|
2230 { |
|
2231 public: |
|
2232 // See the genprops.awk script for an explanation of the |
|
2233 // properties declarations. |
|
2234 |
7363
|
2235 BEGIN_PROPERTIES(surface) |
|
2236 data_property xdata l , Matrix () |
|
2237 data_property ydata l , Matrix () |
|
2238 data_property zdata l , Matrix () |
|
2239 data_property cdata l , Matrix () |
7379
|
2240 color_property facecolor , "{flat}|none|interp" |
7363
|
2241 double_property facealpha , 1.0 |
7379
|
2242 color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
7363
|
2243 radio_property linestyle , "{-}|--|:|-.|none" |
|
2244 double_property linewidth , 0.5 |
|
2245 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
|
2246 color_property markeredgecolor , "{auto}|none" |
|
2247 color_property markerfacecolor , "auto|{none}" |
|
2248 double_property markersize , 6 |
|
2249 string_property keylabel , "" |
7384
|
2250 radio_property interpreter , "{tex}|none|latex" |
6874
|
2251 END_PROPERTIES |
|
2252 |
7363
|
2253 protected: |
|
2254 void init (void) |
|
2255 { |
|
2256 } |
6874
|
2257 }; |
|
2258 |
|
2259 private: |
|
2260 properties xproperties; |
|
2261 |
|
2262 public: |
|
2263 surface (const graphics_handle& mh, const graphics_handle& p) |
|
2264 : base_graphics_object (), xproperties (mh, p) |
|
2265 { |
|
2266 xproperties.override_defaults (*this); |
|
2267 } |
|
2268 |
|
2269 ~surface (void) { xproperties.delete_children (); } |
|
2270 |
|
2271 base_properties& get_properties (void) { return xproperties; } |
|
2272 |
7222
|
2273 const base_properties& get_properties (void) const { return xproperties; } |
|
2274 |
6874
|
2275 bool valid_object (void) const { return true; } |
|
2276 }; |
|
2277 |
|
2278 octave_value |
|
2279 get_property_from_handle (double handle, const std::string &property, |
|
2280 const std::string &func); |
|
2281 bool |
|
2282 set_property_in_handle (double handle, const std::string &property, |
|
2283 const octave_value &arg, const std::string &func); |
|
2284 |
|
2285 // --------------------------------------------------------------------- |
|
2286 |
7365
|
2287 class OCTINTERP_API gh_manager |
6874
|
2288 { |
|
2289 protected: |
|
2290 |
|
2291 gh_manager (void); |
|
2292 |
|
2293 public: |
|
2294 |
|
2295 static bool instance_ok (void) |
|
2296 { |
|
2297 bool retval = true; |
|
2298 |
|
2299 if (! instance) |
|
2300 instance = new gh_manager (); |
|
2301 |
|
2302 if (! instance) |
|
2303 { |
|
2304 ::error ("unable to create gh_manager!"); |
|
2305 |
|
2306 retval = false; |
|
2307 } |
|
2308 |
|
2309 return retval; |
|
2310 } |
|
2311 |
|
2312 static void free (const graphics_handle& h) |
|
2313 { |
|
2314 if (instance_ok ()) |
|
2315 instance->do_free (h); |
|
2316 } |
|
2317 |
|
2318 static graphics_handle lookup (double val) |
|
2319 { |
|
2320 return instance_ok () ? instance->do_lookup (val) : graphics_handle (); |
|
2321 } |
|
2322 |
|
2323 static graphics_object get_object (const graphics_handle& h) |
|
2324 { |
|
2325 return instance_ok () ? instance->do_get_object (h) : graphics_object (); |
|
2326 } |
|
2327 |
|
2328 static graphics_handle |
|
2329 make_graphics_handle (const std::string& go_name, |
7370
|
2330 const graphics_handle& parent, bool do_createfcn = true) |
6874
|
2331 { |
|
2332 return instance_ok () |
7370
|
2333 ? instance->do_make_graphics_handle (go_name, parent, do_createfcn) |
6874
|
2334 : graphics_handle (); |
|
2335 } |
|
2336 |
|
2337 static graphics_handle make_figure_handle (double val) |
|
2338 { |
|
2339 return instance_ok () |
|
2340 ? instance->do_make_figure_handle (val) : graphics_handle (); |
|
2341 } |
|
2342 |
|
2343 static void push_figure (const graphics_handle& h) |
|
2344 { |
|
2345 if (instance_ok ()) |
|
2346 instance->do_push_figure (h); |
|
2347 } |
|
2348 |
|
2349 static void pop_figure (const graphics_handle& h) |
|
2350 { |
|
2351 if (instance_ok ()) |
|
2352 instance->do_pop_figure (h); |
|
2353 } |
|
2354 |
|
2355 static graphics_handle current_figure (void) |
|
2356 { |
|
2357 return instance_ok () |
|
2358 ? instance->do_current_figure () : graphics_handle (); |
|
2359 } |
|
2360 |
|
2361 static Matrix handle_list (void) |
|
2362 { |
|
2363 return instance_ok () ? instance->do_handle_list () : Matrix (); |
|
2364 } |
|
2365 |
|
2366 static Matrix figure_handle_list (void) |
|
2367 { |
|
2368 return instance_ok () ? instance->do_figure_handle_list () : Matrix (); |
|
2369 } |
|
2370 |
|
2371 private: |
|
2372 |
|
2373 static gh_manager *instance; |
|
2374 |
|
2375 typedef std::map<graphics_handle, graphics_object>::iterator iterator; |
|
2376 typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator; |
|
2377 |
|
2378 typedef std::set<graphics_handle>::iterator free_list_iterator; |
|
2379 typedef std::set<graphics_handle>::const_iterator const_free_list_iterator; |
|
2380 |
|
2381 typedef std::list<graphics_handle>::iterator figure_list_iterator; |
|
2382 typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator; |
|
2383 |
|
2384 // A map of handles to graphics objects. |
|
2385 std::map<graphics_handle, graphics_object> handle_map; |
|
2386 |
|
2387 // The available graphics handles. |
|
2388 std::set<graphics_handle> handle_free_list; |
|
2389 |
|
2390 // The next handle available if handle_free_list is empty. |
7286
|
2391 double next_handle; |
6874
|
2392 |
|
2393 // The allocated figure handles. Top of the stack is most recently |
|
2394 // created. |
|
2395 std::list<graphics_handle> figure_list; |
|
2396 |
|
2397 graphics_handle get_handle (const std::string& go_name); |
|
2398 |
|
2399 void do_free (const graphics_handle& h); |
|
2400 |
|
2401 graphics_handle do_lookup (double val) |
|
2402 { |
7363
|
2403 iterator p = (xisnan (val) ? handle_map.end () : handle_map.find (val)); |
6874
|
2404 |
|
2405 return (p != handle_map.end ()) ? p->first : graphics_handle (); |
|
2406 } |
|
2407 |
|
2408 graphics_object do_get_object (const graphics_handle& h) |
|
2409 { |
7379
|
2410 iterator p = (h.ok () ? handle_map.find (h) : handle_map.end ()); |
6874
|
2411 |
|
2412 return (p != handle_map.end ()) ? p->second : graphics_object (); |
|
2413 } |
|
2414 |
|
2415 graphics_handle do_make_graphics_handle (const std::string& go_name, |
7370
|
2416 const graphics_handle& p, bool do_createfcn); |
6874
|
2417 |
|
2418 graphics_handle do_make_figure_handle (double val); |
|
2419 |
|
2420 Matrix do_handle_list (void) |
|
2421 { |
|
2422 Matrix retval (1, handle_map.size ()); |
|
2423 octave_idx_type i = 0; |
|
2424 for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++) |
7056
|
2425 { |
|
2426 graphics_handle h = p->first; |
|
2427 retval(i++) = h.value (); |
|
2428 } |
6874
|
2429 return retval; |
|
2430 } |
|
2431 |
|
2432 Matrix do_figure_handle_list (void) |
|
2433 { |
|
2434 Matrix retval (1, figure_list.size ()); |
|
2435 octave_idx_type i = 0; |
|
2436 for (const_figure_list_iterator p = figure_list.begin (); |
|
2437 p != figure_list.end (); |
|
2438 p++) |
7056
|
2439 { |
|
2440 graphics_handle h = *p; |
|
2441 retval(i++) = h.value (); |
|
2442 } |
6874
|
2443 return retval; |
|
2444 } |
|
2445 |
|
2446 void do_push_figure (const graphics_handle& h); |
|
2447 |
|
2448 void do_pop_figure (const graphics_handle& h); |
|
2449 |
|
2450 graphics_handle do_current_figure (void) const |
|
2451 { |
|
2452 return figure_list.empty () ? graphics_handle () : figure_list.front (); |
|
2453 } |
|
2454 }; |
|
2455 |
|
2456 |
|
2457 // This function is NOT equivalent to the scripting language function gcf. |
7365
|
2458 OCTINTERP_API graphics_handle gcf (void); |
6874
|
2459 |
|
2460 // This function is NOT equivalent to the scripting language function gca. |
7365
|
2461 OCTINTERP_API graphics_handle gca (void); |
6874
|
2462 |
|
2463 #endif |
|
2464 |
|
2465 /* |
|
2466 ;;; Local Variables: *** |
|
2467 ;;; mode: C++ *** |
|
2468 ;;; End: *** |
|
2469 */ |