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 |
|
42 class |
|
43 radio_values |
|
44 { |
|
45 public: |
|
46 radio_values (const std::string& opt_string = std::string ()); |
7168
|
47 |
6874
|
48 radio_values (const radio_values& a) |
|
49 : default_val (a.default_val), possible_vals (a.possible_vals) { } |
|
50 |
|
51 radio_values& operator = (const radio_values& a) |
|
52 { |
|
53 if (&a != this) |
|
54 { |
|
55 default_val = a.default_val; |
|
56 possible_vals = a.possible_vals; |
|
57 } |
|
58 |
|
59 return *this; |
|
60 } |
|
61 |
|
62 std::string default_value (void) const { return default_val; } |
|
63 |
|
64 std::set<std::string> possible_values (void) const { return possible_vals; } |
|
65 |
|
66 bool validate (const std::string& val) |
|
67 { |
|
68 bool retval = true; |
|
69 |
6898
|
70 if (! contains (val)) |
6874
|
71 { |
|
72 error ("invalid value = %s", val.c_str ()); |
|
73 retval = false; |
|
74 } |
|
75 |
|
76 return retval; |
|
77 } |
6898
|
78 |
|
79 bool contains (const std::string& val) |
|
80 { |
|
81 return (possible_vals.find (val) != possible_vals.end ()); |
|
82 } |
6874
|
83 |
|
84 private: |
|
85 // Might also want to cache |
|
86 std::string default_val; |
|
87 std::set<std::string> possible_vals; |
|
88 }; |
|
89 |
|
90 class |
|
91 radio_property |
|
92 { |
|
93 public: |
|
94 radio_property (const radio_values& v) |
|
95 : vals (v), current_val (v.default_value ()) { } |
|
96 |
|
97 radio_property (const radio_values& v, const std::string& initial_value) |
|
98 : vals (v), current_val (initial_value) { } |
|
99 |
|
100 radio_property (const radio_property& a) |
|
101 : vals (a.vals), current_val (a.current_val) { } |
|
102 |
|
103 radio_property& operator = (const radio_property& a) |
|
104 { |
|
105 if (&a != this) |
|
106 { |
|
107 vals = a.vals; |
|
108 current_val = a.current_val; |
|
109 } |
|
110 |
|
111 return *this; |
|
112 } |
|
113 |
|
114 radio_property& operator = (const std::string& newval) |
|
115 { |
|
116 if (vals.validate (newval)) |
|
117 current_val = newval; |
|
118 |
|
119 return *this; |
|
120 } |
|
121 |
|
122 const std::string& current_value (void) const { return current_val; } |
|
123 |
|
124 private: |
|
125 radio_values vals; |
|
126 std::string current_val; |
|
127 }; |
|
128 |
|
129 class |
|
130 color_values |
|
131 { |
|
132 public: |
|
133 color_values (double r = 0, double g = 0, double b = 1) |
|
134 { |
|
135 xrgb[0] = r; |
|
136 xrgb[1] = g; |
|
137 xrgb[2] = b; |
|
138 |
|
139 validate (); |
|
140 } |
|
141 |
|
142 color_values (std::string str) |
|
143 { |
|
144 if (! str2rgb (str)) |
|
145 error ("invalid color specification"); |
|
146 } |
|
147 |
|
148 color_values (const color_values& c) |
|
149 { |
|
150 xrgb[0] = c.xrgb[0]; |
|
151 xrgb[1] = c.xrgb[1]; |
|
152 xrgb[2] = c.xrgb[2]; |
|
153 } |
|
154 |
|
155 color_values& operator = (const color_values& c) |
|
156 { |
|
157 if (&c != this) |
|
158 { |
|
159 xrgb[0] = c.xrgb[0]; |
|
160 xrgb[1] = c.xrgb[1]; |
|
161 xrgb[2] = c.xrgb[2]; |
|
162 |
|
163 } |
|
164 |
|
165 return *this; |
|
166 } |
|
167 |
|
168 const double* rgb (void) const { return xrgb; } |
|
169 |
|
170 void validate (void) const |
|
171 { |
|
172 for (int i = 0; i < 3; i++) |
|
173 { |
|
174 if (xrgb[i] < 0 || xrgb[i] > 1) |
|
175 { |
|
176 error ("invalid RGB color specification"); |
|
177 break; |
|
178 } |
|
179 } |
|
180 } |
|
181 |
|
182 private: |
|
183 double xrgb[3]; |
|
184 |
|
185 bool str2rgb (std::string str); |
|
186 }; |
|
187 |
|
188 |
|
189 class |
|
190 color_property |
|
191 { |
|
192 public: |
|
193 color_property (const color_values& c = color_values (), |
|
194 const radio_values& v = radio_values ()) |
|
195 : current_type (color_t), color_val (c), radio_val (v), |
|
196 current_val (v.default_value ()) |
|
197 { } |
|
198 |
|
199 color_property (const radio_values& v) |
|
200 : current_type (radio_t), color_val (color_values ()), radio_val (v), |
|
201 current_val (v.default_value ()) |
|
202 { } |
|
203 |
|
204 color_property (const radio_values& v, const std::string& initial_value) |
|
205 : current_type (radio_t), color_val (color_values ()), radio_val (v), |
|
206 current_val (initial_value) |
|
207 { } |
|
208 |
6938
|
209 color_property (const octave_value& val); |
6874
|
210 |
|
211 operator octave_value (void) const |
|
212 { |
|
213 if (current_type == color_t) |
|
214 { |
|
215 Matrix retval (1, 3); |
|
216 const double *xrgb = color_val.rgb (); |
|
217 |
|
218 for (int i = 0; i < 3 ; i++) |
|
219 retval(i) = xrgb[i]; |
|
220 |
|
221 return retval; |
|
222 } |
|
223 |
|
224 return current_val; |
|
225 } |
|
226 |
|
227 color_property& operator = (const color_property& a) |
|
228 { |
|
229 if (&a != this) |
|
230 { |
|
231 current_type = a.current_type; |
|
232 color_val = a.color_val; |
|
233 radio_val = a.radio_val; |
|
234 current_val = a.current_val; |
|
235 } |
|
236 |
|
237 return *this; |
|
238 } |
|
239 |
|
240 color_property& operator = (const std::string& newval) |
|
241 { |
|
242 if (radio_val.validate (newval)) |
|
243 { |
|
244 current_val = newval; |
|
245 current_type = radio_t; |
|
246 } |
|
247 |
|
248 return *this; |
|
249 } |
|
250 |
|
251 color_property& operator = (const color_values& newval) |
|
252 { |
|
253 color_val = newval; |
|
254 current_type = color_t; |
|
255 |
|
256 return *this; |
|
257 } |
|
258 |
|
259 color_property& operator = (const octave_value& newval); |
|
260 |
|
261 bool is_rgb (void) const { return (current_type == color_t); } |
|
262 |
|
263 bool is_radio (void) const { return (current_type == radio_t); } |
|
264 |
|
265 const double* rgb (void) const |
|
266 { |
|
267 if (current_type != color_t) |
|
268 error ("color has no rgb value"); |
|
269 |
|
270 return color_val.rgb (); |
|
271 } |
|
272 |
|
273 const std::string& current_value (void) const |
|
274 { |
|
275 if (current_type != radio_t) |
|
276 error ("color has no radio value"); |
|
277 |
|
278 return current_val; |
|
279 } |
|
280 |
|
281 private: |
|
282 enum current_enum { color_t, radio_t } current_type; |
|
283 color_values color_val; |
|
284 radio_values radio_val; |
|
285 std::string current_val; |
|
286 }; |
|
287 |
|
288 class |
|
289 colormap_property |
|
290 { |
|
291 public: |
|
292 colormap_property (const Matrix& m = Matrix ()) |
|
293 : cmap (m) |
|
294 { |
|
295 if (cmap.is_empty ()) |
|
296 { |
6893
|
297 cmap = Matrix (64, 3, 0.0); |
6874
|
298 |
|
299 for (octave_idx_type i = 0; i < 64; i++) |
6893
|
300 { |
|
301 // This is the jet colormap. It would be nice to be able |
|
302 // to feval the jet function but since there is a static |
|
303 // property object that includes a colormap_property |
|
304 // object, we need to initialize this before main is even |
|
305 // called, so calling an interpreted function is not |
|
306 // possible. |
|
307 |
|
308 double x = i / 63.0; |
|
309 |
|
310 if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
311 cmap(i,0) = 4.0 * x - 3.0/2.0; |
|
312 else if (x >= 5.0/8.0 && x < 7.0/8.0) |
|
313 cmap(i,0) = 1.0; |
|
314 else if (x >= 7.0/8.0) |
|
315 cmap(i,0) = -4.0 * x + 9.0/2.0; |
|
316 |
|
317 if (x >= 1.0/8.0 && x < 3.0/8.0) |
|
318 cmap(i,1) = 4.0 * x - 1.0/2.0; |
|
319 else if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
320 cmap(i,1) = 1.0; |
|
321 else if (x >= 5.0/8.0 && x < 7.0/8.0) |
|
322 cmap(i,1) = -4.0 * x + 7.0/2.0; |
|
323 |
6931
|
324 if (x < 1.0/8.0) |
6893
|
325 cmap(i,2) = 4.0 * x + 1.0/2.0; |
|
326 else if (x >= 1.0/8.0 && x < 3.0/8.0) |
|
327 cmap(i,2) = 1.0; |
|
328 else if (x >= 3.0/8.0 && x < 5.0/8.0) |
|
329 cmap(i,2) = -4.0 * x + 5.0/2.0; |
|
330 } |
6874
|
331 } |
|
332 |
|
333 validate (); |
|
334 } |
|
335 |
|
336 colormap_property (const octave_value& val) |
|
337 { |
|
338 cmap = val.matrix_value (); |
|
339 |
|
340 validate (); |
|
341 } |
|
342 |
|
343 void validate (void) const |
|
344 { |
|
345 if (error_state || cmap.columns () != 3) |
|
346 error ("invalid colormap specification"); |
|
347 } |
|
348 |
|
349 operator octave_value (void) const { return cmap; } |
|
350 |
|
351 private: |
|
352 Matrix cmap; |
|
353 }; |
|
354 |
7168
|
355 class |
|
356 string_property |
|
357 { |
|
358 public: |
|
359 string_property (const octave_value& c = octave_value (std::string ()), |
|
360 const radio_values& v = radio_values ()) |
|
361 : radio_val (v) |
|
362 { |
|
363 if (c.is_defined ()) |
|
364 { |
|
365 std::string newval = c.string_value (); |
|
366 |
|
367 std::transform (newval.begin (), newval.end (), |
|
368 newval.begin (), tolower); |
|
369 |
|
370 if (! error_state) |
|
371 { |
|
372 if (radio_val.validate (newval)) |
|
373 current_val = newval; |
|
374 } |
|
375 } |
|
376 else |
|
377 current_val = v.default_value (); |
|
378 } |
|
379 |
|
380 string_property (const radio_values& v) |
|
381 : current_val (v.default_value()), radio_val (v) |
|
382 { } |
|
383 |
|
384 string_property (const radio_values& v, const std::string& initial_value) |
|
385 : radio_val (v) |
|
386 { |
|
387 current_val = initial_value; |
|
388 std::transform (current_val.begin (), current_val.end (), |
|
389 current_val.begin (), tolower); |
|
390 } |
|
391 |
|
392 operator octave_value (void) const { return current_val; } |
|
393 |
|
394 string_property& operator = (const string_property& a) |
|
395 { |
|
396 if (&a != this) |
|
397 { |
|
398 current_val = a.current_val; |
|
399 radio_val = a.radio_val; |
|
400 } |
|
401 |
|
402 return *this; |
|
403 } |
|
404 |
|
405 string_property& operator = (const std::string& s) |
|
406 { |
|
407 std::string newval = s; |
|
408 |
|
409 std::transform (newval.begin (), newval.end (), |
|
410 newval.begin (), tolower); |
|
411 |
|
412 if (! newval.empty ()) |
|
413 { |
|
414 if (radio_val.contains (newval)) |
|
415 current_val = newval; |
|
416 else |
|
417 error ("invalid string specification"); |
|
418 } |
|
419 else |
|
420 error ("invalid string specification"); |
|
421 |
|
422 return *this; |
|
423 } |
|
424 |
|
425 string_property& operator = (const octave_value& val) |
|
426 { |
|
427 if (val.is_string ()) |
|
428 { |
|
429 std::string newval = val.string_value (); |
|
430 |
|
431 std::transform (newval.begin (), newval.end (), |
|
432 newval.begin (), tolower); |
|
433 |
|
434 if (! newval.empty ()) |
|
435 { |
|
436 if (radio_val.contains (newval)) |
|
437 current_val = newval; |
|
438 else |
|
439 error ("invalid string specification"); |
|
440 } |
|
441 else |
|
442 error ("invalid string specification"); |
|
443 } |
|
444 else |
|
445 error ("invalid string specification"); |
|
446 |
|
447 return *this; |
|
448 } |
|
449 |
|
450 const std::string& current_value (void) const { return current_val; } |
|
451 |
|
452 private: |
|
453 std::string current_val; |
|
454 radio_values radio_val; |
|
455 }; |
|
456 |
6874
|
457 // --------------------------------------------------------------------- |
|
458 |
|
459 class property_name : public std::string |
|
460 { |
|
461 public: |
|
462 typedef std::string::iterator iterator; |
|
463 typedef std::string::const_iterator const_iterator; |
|
464 |
|
465 property_name (void) : std::string () { } |
|
466 property_name (const std::string& s) : std::string (s) { } |
|
467 property_name (const char *s) : std::string (s) { } |
|
468 |
|
469 property_name (const property_name& name) : std::string (name) { } |
|
470 |
|
471 property_name& operator = (const property_name& pname) |
|
472 { |
|
473 std::string::operator = (pname); |
|
474 return *this; |
|
475 } |
|
476 |
|
477 operator std::string (void) const { return *this; } |
|
478 |
|
479 // Case-insensitive comparison. |
|
480 bool compare (const std::string& s, size_t limit = NPOS) const |
|
481 { |
|
482 const_iterator p1 = begin (); |
|
483 const_iterator p2 = s.begin (); |
|
484 |
|
485 size_t k = 0; |
|
486 |
|
487 while (p1 != end () && p2 != s.end () && k++ < limit) |
|
488 { |
|
489 if (std::tolower (*p1) != std::tolower (*p2)) |
|
490 return false; |
|
491 |
|
492 *p1++; |
|
493 *p2++; |
|
494 } |
|
495 |
|
496 return (limit == NPOS) ? size () == s.size () : k == limit; |
|
497 } |
|
498 }; |
|
499 |
|
500 // --------------------------------------------------------------------- |
|
501 |
|
502 class property_list |
|
503 { |
|
504 public: |
|
505 typedef std::map<std::string, octave_value> pval_map_type; |
|
506 typedef std::map<std::string, pval_map_type> plist_map_type; |
|
507 |
|
508 typedef pval_map_type::iterator pval_map_iterator; |
|
509 typedef pval_map_type::const_iterator pval_map_const_iterator; |
|
510 |
|
511 typedef plist_map_type::iterator plist_map_iterator; |
|
512 typedef plist_map_type::const_iterator plist_map_const_iterator; |
|
513 |
|
514 property_list (const plist_map_type& m = plist_map_type ()) |
|
515 : plist_map (m) { } |
|
516 |
|
517 ~property_list (void) { } |
|
518 |
|
519 void set (const property_name& name, const octave_value& val); |
|
520 |
|
521 octave_value lookup (const property_name& name) const; |
|
522 |
|
523 plist_map_iterator begin (void) { return plist_map.begin (); } |
|
524 plist_map_const_iterator begin (void) const { return plist_map.begin (); } |
|
525 |
|
526 plist_map_iterator end (void) { return plist_map.end (); } |
|
527 plist_map_const_iterator end (void) const { return plist_map.end (); } |
|
528 |
|
529 plist_map_iterator find (const std::string& go_name) |
|
530 { |
|
531 return plist_map.find (go_name); |
|
532 } |
|
533 |
|
534 plist_map_const_iterator find (const std::string& go_name) const |
|
535 { |
|
536 return plist_map.find (go_name); |
|
537 } |
|
538 |
|
539 Octave_map as_struct (const std::string& prefix_arg) const; |
|
540 |
|
541 private: |
|
542 plist_map_type plist_map; |
|
543 }; |
|
544 |
|
545 // --------------------------------------------------------------------- |
|
546 |
|
547 class graphics_handle |
|
548 { |
|
549 public: |
|
550 graphics_handle (void) : val (octave_NaN) { } |
|
551 |
|
552 graphics_handle (const octave_value& a); |
|
553 |
|
554 graphics_handle (int a) : val (a) { } |
|
555 |
|
556 graphics_handle (double a) : val (a) { } |
|
557 |
|
558 graphics_handle (const graphics_handle& a) : val (a.val) { } |
|
559 |
|
560 graphics_handle& operator = (const graphics_handle& a) |
|
561 { |
|
562 if (&a != this) |
|
563 val = a.val; |
|
564 |
|
565 return *this; |
|
566 } |
|
567 |
|
568 ~graphics_handle (void) { } |
|
569 |
|
570 double value (void) const { return val; } |
|
571 |
|
572 octave_value as_octave_value (void) const |
|
573 { |
|
574 return ok () ? octave_value (val) : octave_value (Matrix ()); |
|
575 } |
|
576 |
|
577 graphics_handle operator ++ (void) |
|
578 { |
|
579 ++val; |
|
580 return *this; |
|
581 } |
|
582 |
|
583 graphics_handle operator ++ (int) |
|
584 { |
|
585 graphics_handle h = *this; |
|
586 ++val; |
|
587 return h; |
|
588 } |
|
589 |
|
590 graphics_handle operator -- (void) |
|
591 { |
|
592 --val; |
|
593 return *this; |
|
594 } |
|
595 |
|
596 graphics_handle operator -- (int) |
|
597 { |
|
598 graphics_handle h = *this; |
|
599 --val; |
|
600 return h; |
|
601 } |
|
602 |
|
603 bool ok (void) const { return ! xisnan (val); } |
|
604 |
|
605 private: |
|
606 double val; |
|
607 }; |
|
608 |
|
609 inline bool |
|
610 operator == (const graphics_handle& a, const graphics_handle& b) |
|
611 { |
|
612 return a.value () == b.value (); |
|
613 } |
|
614 |
|
615 inline bool |
|
616 operator != (const graphics_handle& a, const graphics_handle& b) |
|
617 { |
|
618 return a.value () != b.value (); |
|
619 } |
|
620 |
|
621 inline bool |
|
622 operator < (const graphics_handle& a, const graphics_handle& b) |
|
623 { |
|
624 return a.value () < b.value (); |
|
625 } |
|
626 |
|
627 inline bool |
|
628 operator <= (const graphics_handle& a, const graphics_handle& b) |
|
629 { |
|
630 return a.value () <= b.value (); |
|
631 } |
|
632 |
|
633 inline bool |
|
634 operator >= (const graphics_handle& a, const graphics_handle& b) |
|
635 { |
|
636 return a.value () >= b.value (); |
|
637 } |
|
638 |
|
639 inline bool |
|
640 operator > (const graphics_handle& a, const graphics_handle& b) |
|
641 { |
|
642 return a.value () > b.value (); |
|
643 } |
|
644 |
|
645 // --------------------------------------------------------------------- |
|
646 |
|
647 class base_graphics_object; |
|
648 |
|
649 class base_properties |
|
650 { |
|
651 public: |
|
652 base_properties (const std::string& t = "unknown", |
|
653 const graphics_handle& mh = graphics_handle (), |
|
654 const graphics_handle& p = graphics_handle ()) |
|
655 : type (t), __modified__ (true), __myhandle__ (mh), parent (p), |
|
656 children () { } |
|
657 |
|
658 virtual ~base_properties (void) { } |
|
659 |
|
660 virtual std::string graphics_object_name (void) const { return "unknonwn"; } |
|
661 |
|
662 void mark_modified (void); |
|
663 |
|
664 void override_defaults (base_graphics_object& obj); |
|
665 |
|
666 // Look through DEFAULTS for properties with given CLASS_NAME, and |
|
667 // apply them to the current object with set (virtual method). |
|
668 |
|
669 void set_from_list (base_graphics_object& obj, property_list& defaults); |
|
670 |
|
671 virtual void set (const property_name&, const octave_value&) { } |
|
672 |
|
673 graphics_handle get_parent (void) const { return parent; } |
|
674 |
|
675 void remove_child (const graphics_handle& h); |
|
676 |
|
677 void adopt (const graphics_handle& h) |
|
678 { |
|
679 octave_idx_type n = children.numel (); |
|
680 children.resize (1, n+1); |
7056
|
681 children(n) = h.value (); |
6874
|
682 } |
|
683 |
|
684 void set_parent (const octave_value& val); |
|
685 |
|
686 void reparent (const graphics_handle& new_parent) { parent = new_parent; } |
|
687 |
|
688 virtual void delete_children (void); |
|
689 |
|
690 protected: |
|
691 std::string type; |
|
692 bool __modified__; |
|
693 graphics_handle __myhandle__; |
|
694 graphics_handle parent; |
|
695 Matrix children; |
|
696 }; |
|
697 |
|
698 class base_graphics_object |
|
699 { |
|
700 public: |
|
701 friend class graphics_object; |
|
702 |
|
703 base_graphics_object (void) : count (1) { } |
|
704 |
|
705 base_graphics_object (const base_graphics_object&) { } |
|
706 |
|
707 virtual ~base_graphics_object (void) { } |
|
708 |
|
709 virtual void mark_modified (void) |
|
710 { |
|
711 error ("base_graphics_object::mark_modified: invalid graphics object"); |
|
712 } |
|
713 |
|
714 virtual void override_defaults (base_graphics_object&) |
|
715 { |
|
716 error ("base_graphics_object::override_defaults: invalid graphics object"); |
|
717 } |
|
718 |
|
719 virtual void set_from_list (property_list&) |
|
720 { |
|
721 error ("base_graphics_object::set_from_list: invalid graphics object"); |
|
722 } |
|
723 |
|
724 virtual void set (const property_name&, const octave_value&) |
|
725 { |
|
726 error ("base_graphics_object::set: invalid graphics object"); |
|
727 } |
|
728 |
|
729 virtual void set_defaults (const std::string&) |
|
730 { |
|
731 error ("base_graphics_object::set_defaults: invalid graphics object"); |
|
732 } |
|
733 |
|
734 virtual octave_value get (void) const |
|
735 { |
|
736 error ("base_graphics_object::get: invalid graphics object"); |
|
737 return octave_value (); |
|
738 } |
|
739 |
|
740 virtual octave_value get (const property_name&) const |
|
741 { |
|
742 error ("base_graphics_object::get: invalid graphics object"); |
|
743 return octave_value (); |
|
744 } |
|
745 |
|
746 virtual octave_value get_default (const property_name&) const; |
|
747 |
|
748 virtual octave_value get_factory_default (const property_name&) const; |
|
749 |
|
750 virtual octave_value get_defaults (void) const |
|
751 { |
|
752 error ("base_graphics_object::get_defaults: invalid graphics object"); |
|
753 return octave_value (); |
|
754 } |
|
755 |
|
756 virtual octave_value get_factory_defaults (void) const |
|
757 { |
|
758 error ("base_graphics_object::get_factory_defaults: invalid graphics object"); |
|
759 return octave_value (); |
|
760 } |
|
761 |
|
762 virtual graphics_handle get_parent (void) const |
|
763 { |
|
764 error ("base_graphics_object::get_parent: invalid graphics object"); |
|
765 return graphics_handle (); |
|
766 } |
|
767 |
|
768 virtual void remove_child (const graphics_handle&) |
|
769 { |
|
770 error ("base_graphics_object::remove_child: invalid graphics object"); |
|
771 } |
|
772 |
|
773 virtual void adopt (const graphics_handle&) |
|
774 { |
|
775 error ("base_graphics_object::adopt: invalid graphics object"); |
|
776 } |
|
777 |
|
778 virtual void reparent (const graphics_handle&) |
|
779 { |
|
780 error ("base_graphics_object::reparent: invalid graphics object"); |
|
781 } |
|
782 |
|
783 virtual void defaults (void) const |
|
784 { |
|
785 error ("base_graphics_object::default: invalid graphics object"); |
|
786 } |
|
787 |
|
788 virtual base_properties& get_properties (void) |
|
789 { |
|
790 static base_properties properties; |
|
791 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
792 return properties; |
|
793 } |
|
794 |
|
795 virtual bool valid_object (void) const { return false; } |
|
796 |
|
797 virtual std::string type (void) const { return "unknown"; } |
|
798 |
|
799 bool isa (const std::string& go_name) const |
|
800 { |
|
801 return type () == go_name; |
|
802 } |
|
803 |
|
804 protected: |
|
805 // A reference count. |
|
806 int count; |
|
807 }; |
|
808 |
|
809 class graphics_object |
|
810 { |
|
811 public: |
|
812 graphics_object (void) : rep (new base_graphics_object ()) { } |
|
813 |
|
814 graphics_object (base_graphics_object *new_rep) |
|
815 : rep (new_rep) { } |
|
816 |
|
817 graphics_object (const graphics_object& obj) |
|
818 { |
|
819 rep = obj.rep; |
|
820 rep->count++; |
|
821 } |
|
822 |
|
823 graphics_object& operator = (const graphics_object& obj) |
|
824 { |
|
825 if (rep != obj.rep) |
|
826 { |
|
827 if (--rep->count == 0) |
|
828 delete rep; |
|
829 |
|
830 rep = obj.rep; |
|
831 rep->count++; |
|
832 } |
|
833 |
|
834 return *this; |
|
835 } |
|
836 |
|
837 ~graphics_object (void) |
|
838 { |
|
839 if (--rep->count == 0) |
|
840 delete rep; |
|
841 } |
|
842 |
|
843 void mark_modified (void) { rep->mark_modified (); } |
|
844 |
|
845 void override_defaults (base_graphics_object& obj) |
|
846 { |
|
847 rep->override_defaults (obj); |
|
848 } |
|
849 |
|
850 void set_from_list (property_list& plist) |
|
851 { |
|
852 rep->set_from_list (plist); |
|
853 } |
|
854 |
|
855 void set (const property_name& name, const octave_value& val) |
|
856 { |
|
857 rep->set (name, val); |
|
858 } |
|
859 |
|
860 void set (const octave_value_list& args); |
|
861 |
|
862 void set_defaults (const std::string& mode) |
|
863 { |
|
864 rep->set_defaults (mode); |
|
865 } |
|
866 |
|
867 octave_value get (void) const |
|
868 { |
|
869 return rep->get (); |
|
870 } |
|
871 |
|
872 octave_value get (const property_name& name) const |
|
873 { |
|
874 return name.compare ("default") |
|
875 ? get_defaults () |
|
876 : (name.compare ("factory") |
|
877 ? get_factory_defaults () : rep->get (name)); |
|
878 } |
|
879 |
|
880 octave_value get_default (const property_name& name) const |
|
881 { |
|
882 return rep->get_default (name); |
|
883 } |
|
884 |
|
885 octave_value get_factory_default (const property_name& name) const |
|
886 { |
|
887 return rep->get_factory_default (name); |
|
888 } |
|
889 |
|
890 octave_value get_defaults (void) const { return rep->get_defaults (); } |
|
891 |
|
892 octave_value get_factory_defaults (void) const |
|
893 { |
|
894 return rep->get_factory_defaults (); |
|
895 } |
|
896 |
|
897 graphics_handle get_parent (void) const { return rep->get_parent (); } |
|
898 |
|
899 void remove_child (const graphics_handle& h) { return rep->remove_child (h); } |
|
900 |
|
901 void adopt (const graphics_handle& h) { return rep->adopt (h); } |
|
902 |
|
903 void reparent (const graphics_handle& h) { return rep->reparent (h); } |
|
904 |
|
905 void defaults (void) const { rep->defaults (); } |
|
906 |
|
907 bool isa (const std::string& go_name) const { return rep->isa (go_name); } |
|
908 |
|
909 base_properties& get_properties (void) { return rep->get_properties (); } |
|
910 |
|
911 bool valid_object (void) const { return rep->valid_object (); } |
|
912 |
|
913 operator bool (void) const { return rep->valid_object (); } |
|
914 |
|
915 private: |
|
916 base_graphics_object *rep; |
|
917 }; |
|
918 |
|
919 // --------------------------------------------------------------------- |
|
920 |
|
921 class root_figure : public base_graphics_object |
|
922 { |
|
923 public: |
|
924 class properties : public base_properties |
|
925 { |
|
926 public: |
|
927 properties (void) |
|
928 : base_properties ("root figure", 0, graphics_handle ()), |
|
929 currentfigure (), |
|
930 visible ("on") |
|
931 { } |
|
932 |
|
933 ~properties (void) { } |
|
934 |
|
935 void set (const property_name& name, const octave_value& val); |
|
936 |
|
937 octave_value get (void) const; |
|
938 |
|
939 octave_value get (const property_name& name) const; |
|
940 |
|
941 std::string graphics_object_name (void) const { return go_name; } |
|
942 |
|
943 // See the genprops.awk script for an explanation of the |
|
944 // properties declarations. |
|
945 |
|
946 BEGIN_PROPERTIES |
|
947 graphics_handle currentfigure S |
|
948 octave_value visible |
|
949 END_PROPERTIES |
|
950 |
|
951 static std::string go_name; |
|
952 }; |
|
953 |
|
954 private: |
|
955 properties xproperties; |
|
956 |
|
957 public: |
|
958 |
|
959 root_figure (void) : xproperties (), default_properties () { } |
|
960 |
|
961 ~root_figure (void) { xproperties.delete_children (); } |
|
962 |
|
963 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
964 |
|
965 void mark_modified (void) { } |
|
966 |
|
967 void override_defaults (base_graphics_object& obj) |
|
968 { |
|
969 // Now override with our defaults. If the default_properties |
|
970 // list includes the properties for all defaults (line, |
|
971 // surface, etc.) then we don't have to know the type of OBJ |
|
972 // here, we just call its set function and let it decide which |
|
973 // properties from the list to use. |
|
974 obj.set_from_list (default_properties); |
|
975 } |
|
976 |
|
977 void set_from_list (property_list& plist) |
|
978 { |
|
979 xproperties.set_from_list (*this, plist); |
|
980 } |
|
981 |
|
982 void set (const property_name& name, const octave_value& value) |
|
983 { |
|
984 if (name.compare ("default", 7)) |
|
985 // strip "default", pass rest to function that will |
|
986 // parse the remainder and add the element to the |
|
987 // default_properties map. |
|
988 default_properties.set (name.substr (7), value); |
|
989 else |
|
990 xproperties.set (name, value); |
|
991 } |
|
992 |
|
993 octave_value get (void) const |
|
994 { |
|
995 return xproperties.get (); |
|
996 } |
|
997 |
|
998 octave_value get (const property_name& name) const |
|
999 { |
|
1000 octave_value retval; |
|
1001 |
|
1002 if (name.compare ("default", 7)) |
|
1003 return get_default (name.substr (7)); |
|
1004 else if (name.compare ("factory", 7)) |
|
1005 return get_factory_default (name.substr (7)); |
|
1006 else |
|
1007 retval = xproperties.get (name); |
|
1008 |
|
1009 return retval; |
|
1010 } |
|
1011 |
|
1012 octave_value get_default (const property_name& name) const |
|
1013 { |
|
1014 octave_value retval = default_properties.lookup (name); |
|
1015 |
|
1016 if (retval.is_undefined ()) |
|
1017 error ("get: invalid default property `%s'", name.c_str ()); |
|
1018 |
|
1019 return retval; |
|
1020 } |
|
1021 |
|
1022 octave_value get_factory_default (const property_name& name) const |
|
1023 { |
|
1024 octave_value retval = factory_properties.lookup (name); |
|
1025 |
|
1026 if (retval.is_undefined ()) |
|
1027 error ("get: invalid factory default property `%s'", name.c_str ()); |
|
1028 |
|
1029 return retval; |
|
1030 } |
|
1031 |
|
1032 octave_value get_defaults (void) const |
|
1033 { |
|
1034 return default_properties.as_struct ("default"); |
|
1035 } |
|
1036 |
|
1037 octave_value get_factory_defaults (void) const |
|
1038 { |
|
1039 return factory_properties.as_struct ("factory"); |
|
1040 } |
|
1041 |
|
1042 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1043 |
|
1044 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1045 |
|
1046 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1047 |
|
1048 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
1049 |
|
1050 base_properties& get_properties (void) { return xproperties; } |
|
1051 |
6890
|
1052 void defaults (void) const |
|
1053 { |
|
1054 gripe_not_implemented ("root_figure::defaults"); |
|
1055 } |
|
1056 |
6874
|
1057 bool valid_object (void) const { return true; } |
|
1058 |
|
1059 private: |
|
1060 property_list default_properties; |
|
1061 |
|
1062 static property_list factory_properties; |
|
1063 |
|
1064 static property_list::plist_map_type init_factory_properties (void); |
|
1065 }; |
|
1066 |
|
1067 // --------------------------------------------------------------------- |
|
1068 |
|
1069 class figure : public base_graphics_object |
|
1070 { |
|
1071 public: |
|
1072 class properties : public base_properties |
|
1073 { |
|
1074 public: |
|
1075 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1076 |
|
1077 ~properties (void) { } |
|
1078 |
|
1079 void set (const property_name& name, const octave_value& val); |
|
1080 |
|
1081 octave_value get (void) const; |
|
1082 |
|
1083 octave_value get (const property_name& name) const; |
|
1084 |
|
1085 void close (void); |
|
1086 |
|
1087 std::string graphics_object_name (void) const { return go_name; } |
|
1088 |
|
1089 static property_list::pval_map_type factory_defaults (void); |
|
1090 |
|
1091 // See the genprops.awk script for an explanation of the |
|
1092 // properties declarations. |
|
1093 |
|
1094 BEGIN_PROPERTIES |
|
1095 octave_value __plot_stream__ |
|
1096 octave_value nextplot |
|
1097 octave_value closerequestfcn |
|
1098 graphics_handle currentaxes S |
|
1099 colormap_property colormap |
|
1100 octave_value visible S |
|
1101 octave_value paperorientation |
|
1102 END_PROPERTIES |
|
1103 |
|
1104 static std::string go_name; |
|
1105 }; |
|
1106 |
|
1107 private: |
|
1108 properties xproperties; |
|
1109 |
|
1110 public: |
|
1111 figure (const graphics_handle& mh, const graphics_handle& p) |
|
1112 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1113 { |
|
1114 xproperties.override_defaults (*this); |
|
1115 } |
|
1116 |
|
1117 ~figure (void) |
|
1118 { |
|
1119 xproperties.delete_children (); |
|
1120 xproperties.close (); |
|
1121 } |
|
1122 |
|
1123 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1124 |
|
1125 void mark_modified (void) { xproperties.mark_modified (); } |
|
1126 |
|
1127 void override_defaults (base_graphics_object& obj) |
|
1128 { |
|
1129 // Allow parent (root figure) to override first (properties knows how |
|
1130 // to find the parent object). |
|
1131 xproperties.override_defaults (obj); |
|
1132 |
|
1133 // Now override with our defaults. If the default_properties |
|
1134 // list includes the properties for all defaults (line, |
|
1135 // surface, etc.) then we don't have to know the type of OBJ |
|
1136 // here, we just call its set function and let it decide which |
|
1137 // properties from the list to use. |
|
1138 obj.set_from_list (default_properties); |
|
1139 } |
|
1140 |
|
1141 void set_from_list (property_list& plist) |
|
1142 { |
|
1143 xproperties.set_from_list (*this, plist); |
|
1144 } |
|
1145 |
|
1146 void set (const property_name& name, const octave_value& value) |
|
1147 { |
|
1148 if (name.compare ("default", 7)) |
|
1149 // strip "default", pass rest to function that will |
|
1150 // parse the remainder and add the element to the |
|
1151 // default_properties map. |
|
1152 default_properties.set (name.substr (7), value); |
|
1153 else |
|
1154 xproperties.set (name, value); |
|
1155 } |
|
1156 |
|
1157 octave_value get (void) const |
|
1158 { |
|
1159 return xproperties.get (); |
|
1160 } |
|
1161 |
|
1162 octave_value get (const property_name& name) const |
|
1163 { |
|
1164 octave_value retval; |
|
1165 |
|
1166 if (name.compare ("default", 7)) |
|
1167 retval = get_default (name.substr (7)); |
|
1168 else |
|
1169 retval = xproperties.get (name); |
|
1170 |
|
1171 return retval; |
|
1172 } |
|
1173 |
|
1174 octave_value get_default (const property_name& name) const; |
|
1175 |
|
1176 octave_value get_defaults (void) const |
|
1177 { |
|
1178 return default_properties.as_struct ("default"); |
|
1179 } |
|
1180 |
|
1181 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1182 |
|
1183 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1184 |
|
1185 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1186 |
|
1187 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
1188 |
|
1189 base_properties& get_properties (void) { return xproperties; } |
|
1190 |
6890
|
1191 void defaults (void) const { gripe_not_implemented ("figure::defaults"); } |
|
1192 |
6874
|
1193 bool valid_object (void) const { return true; } |
|
1194 |
|
1195 private: |
|
1196 property_list default_properties; |
|
1197 }; |
|
1198 |
|
1199 // --------------------------------------------------------------------- |
|
1200 |
|
1201 class axes : public base_graphics_object |
|
1202 { |
|
1203 public: |
|
1204 class properties : public base_properties |
|
1205 { |
|
1206 public: |
|
1207 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1208 |
|
1209 ~properties (void) { } |
|
1210 |
|
1211 void set (const property_name& name, const octave_value& val); |
|
1212 |
|
1213 void set_defaults (base_graphics_object& obj, const std::string& mode); |
|
1214 |
|
1215 octave_value get (void) const; |
|
1216 |
|
1217 octave_value get (const property_name& name) const; |
|
1218 |
|
1219 void remove_child (const graphics_handle& h); |
|
1220 |
|
1221 void delete_children (void); |
|
1222 |
|
1223 std::string graphics_object_name (void) const { return go_name; } |
|
1224 |
|
1225 static property_list::pval_map_type factory_defaults (void); |
|
1226 |
|
1227 // See the genprops.awk script for an explanation of the |
|
1228 // properties declarations. |
|
1229 |
|
1230 BEGIN_PROPERTIES |
|
1231 octave_value position |
|
1232 mutable graphics_handle title GSO |
|
1233 octave_value box |
|
1234 octave_value key |
|
1235 octave_value keybox |
|
1236 octave_value keypos |
6962
|
1237 octave_value colororder |
6874
|
1238 octave_value dataaspectratio m |
|
1239 octave_value dataaspectratiomode |
|
1240 octave_value xlim m |
|
1241 octave_value ylim m |
|
1242 octave_value zlim m |
|
1243 octave_value clim m |
|
1244 octave_value xlimmode |
|
1245 octave_value ylimmode |
|
1246 octave_value zlimmode |
|
1247 octave_value climmode |
|
1248 mutable graphics_handle xlabel GSO |
|
1249 mutable graphics_handle ylabel GSO |
|
1250 mutable graphics_handle zlabel GSO |
|
1251 octave_value xgrid |
|
1252 octave_value ygrid |
|
1253 octave_value zgrid |
|
1254 octave_value xminorgrid |
|
1255 octave_value yminorgrid |
|
1256 octave_value zminorgrid |
|
1257 octave_value xtick m |
|
1258 octave_value ytick m |
|
1259 octave_value ztick m |
|
1260 octave_value xtickmode |
|
1261 octave_value ytickmode |
|
1262 octave_value ztickmode |
|
1263 octave_value xticklabel m |
|
1264 octave_value yticklabel m |
|
1265 octave_value zticklabel m |
|
1266 octave_value xticklabelmode |
|
1267 octave_value yticklabelmode |
|
1268 octave_value zticklabelmode |
|
1269 octave_value xscale |
|
1270 octave_value yscale |
|
1271 octave_value zscale |
|
1272 octave_value xdir |
|
1273 octave_value ydir |
|
1274 octave_value zdir |
|
1275 octave_value xaxislocation |
|
1276 octave_value yaxislocation |
|
1277 octave_value view |
|
1278 octave_value visible |
|
1279 octave_value nextplot |
|
1280 octave_value outerposition |
|
1281 END_PROPERTIES |
|
1282 |
|
1283 static std::string go_name; |
|
1284 }; |
|
1285 |
|
1286 private: |
|
1287 properties xproperties; |
|
1288 |
|
1289 public: |
|
1290 axes (const graphics_handle& mh, const graphics_handle& p) |
|
1291 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1292 { |
|
1293 xproperties.override_defaults (*this); |
|
1294 } |
|
1295 |
|
1296 ~axes (void) { xproperties.delete_children (); } |
|
1297 |
|
1298 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1299 |
|
1300 void mark_modified (void) { xproperties.mark_modified (); } |
|
1301 |
|
1302 void override_defaults (base_graphics_object& obj) |
|
1303 { |
|
1304 // Allow parent (figure) to override first (properties knows how |
|
1305 // to find the parent object). |
|
1306 xproperties.override_defaults (obj); |
|
1307 |
|
1308 // Now override with our defaults. If the default_properties |
|
1309 // list includes the properties for all defaults (line, |
|
1310 // surface, etc.) then we don't have to know the type of OBJ |
|
1311 // here, we just call its set function and let it decide which |
|
1312 // properties from the list to use. |
|
1313 obj.set_from_list (default_properties); |
|
1314 } |
|
1315 |
|
1316 void set_from_list (property_list& plist) |
|
1317 { |
|
1318 xproperties.set_from_list (*this, plist); |
|
1319 } |
|
1320 |
|
1321 void set (const property_name& name, const octave_value& value) |
|
1322 { |
|
1323 if (name.compare ("default", 7)) |
|
1324 // strip "default", pass rest to function that will |
|
1325 // parse the remainder and add the element to the |
|
1326 // default_properties map. |
|
1327 default_properties.set (name.substr (7), value); |
|
1328 else |
|
1329 xproperties.set (name, value); |
|
1330 } |
|
1331 |
|
1332 void set_defaults (const std::string& mode) |
|
1333 { |
|
1334 xproperties.set_defaults (*this, mode); |
|
1335 } |
|
1336 |
|
1337 octave_value get (void) const |
|
1338 { |
|
1339 return xproperties.get (); |
|
1340 } |
|
1341 |
|
1342 octave_value get (const property_name& name) const |
|
1343 { |
|
1344 octave_value retval; |
|
1345 |
|
1346 // FIXME -- finish this. |
|
1347 if (name.compare ("default", 7)) |
|
1348 retval = get_default (name.substr (7)); |
|
1349 else |
|
1350 retval = xproperties.get (name); |
|
1351 |
|
1352 return retval; |
|
1353 } |
|
1354 |
|
1355 octave_value get_default (const property_name& name) const; |
|
1356 |
|
1357 octave_value get_defaults (void) const |
|
1358 { |
|
1359 return default_properties.as_struct ("default"); |
|
1360 } |
|
1361 |
|
1362 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1363 |
|
1364 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1365 |
|
1366 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1367 |
|
1368 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
1369 |
|
1370 base_properties& get_properties (void) { return xproperties; } |
|
1371 |
6890
|
1372 void defaults (void) const { gripe_not_implemented ("axes::defaults"); } |
|
1373 |
6874
|
1374 bool valid_object (void) const { return true; } |
|
1375 |
|
1376 private: |
|
1377 property_list default_properties; |
|
1378 }; |
|
1379 |
|
1380 // --------------------------------------------------------------------- |
|
1381 |
|
1382 class line : public base_graphics_object |
|
1383 { |
|
1384 public: |
|
1385 class properties : public base_properties |
|
1386 { |
|
1387 public: |
|
1388 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1389 |
|
1390 ~properties (void) { } |
|
1391 |
|
1392 void set (const property_name& name, const octave_value& val); |
|
1393 |
|
1394 octave_value get (void) const; |
|
1395 |
|
1396 octave_value get (const property_name& name) const; |
|
1397 |
|
1398 std::string graphics_object_name (void) const { return go_name; } |
|
1399 |
|
1400 static property_list::pval_map_type factory_defaults (void); |
|
1401 |
|
1402 // See the genprops.awk script for an explanation of the |
|
1403 // properties declarations. |
|
1404 |
|
1405 BEGIN_PROPERTIES |
|
1406 octave_value xdata |
|
1407 octave_value ydata |
|
1408 octave_value zdata |
|
1409 octave_value ldata |
|
1410 octave_value udata |
|
1411 octave_value xldata |
|
1412 octave_value xudata |
|
1413 color_property color |
|
1414 octave_value linestyle |
|
1415 octave_value linewidth |
|
1416 octave_value marker |
|
1417 octave_value markeredgecolor |
|
1418 octave_value markerfacecolor |
|
1419 octave_value markersize |
|
1420 octave_value keylabel |
|
1421 END_PROPERTIES |
|
1422 |
|
1423 static std::string go_name; |
|
1424 }; |
|
1425 |
|
1426 private: |
|
1427 properties xproperties; |
|
1428 |
|
1429 public: |
|
1430 line (const graphics_handle& mh, const graphics_handle& p) |
|
1431 : base_graphics_object (), xproperties (mh, p) |
|
1432 { |
|
1433 xproperties.override_defaults (*this); |
|
1434 } |
|
1435 |
|
1436 ~line (void) { xproperties.delete_children (); } |
|
1437 |
|
1438 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1439 |
|
1440 void mark_modified (void) { xproperties.mark_modified (); } |
|
1441 |
|
1442 void override_defaults (base_graphics_object& obj) |
|
1443 { |
|
1444 // Allow parent (figure) to override first (properties knows how |
|
1445 // to find the parent object). |
|
1446 xproperties.override_defaults (obj); |
|
1447 } |
|
1448 |
|
1449 void set_from_list (property_list& plist) |
|
1450 { |
|
1451 xproperties.set_from_list (*this, plist); |
|
1452 } |
|
1453 |
|
1454 void set (const property_name& name, const octave_value& val) |
|
1455 { |
|
1456 xproperties.set (name, val); |
|
1457 } |
|
1458 |
|
1459 octave_value get (void) const |
|
1460 { |
|
1461 return xproperties.get (); |
|
1462 } |
|
1463 |
|
1464 octave_value get (const property_name& name) const |
|
1465 { |
|
1466 return xproperties.get (name); |
|
1467 } |
|
1468 |
|
1469 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1470 |
|
1471 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1472 |
|
1473 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1474 |
|
1475 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1476 |
|
1477 base_properties& get_properties (void) { return xproperties; } |
|
1478 |
6890
|
1479 void defaults (void) const { gripe_not_implemented ("line::defaults"); } |
|
1480 |
6874
|
1481 bool valid_object (void) const { return true; } |
|
1482 }; |
|
1483 |
|
1484 // --------------------------------------------------------------------- |
|
1485 |
|
1486 class text : public base_graphics_object |
|
1487 { |
|
1488 public: |
|
1489 class properties : public base_properties |
|
1490 { |
|
1491 public: |
|
1492 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1493 |
|
1494 ~properties (void) { } |
|
1495 |
|
1496 void set (const property_name& name, const octave_value& val); |
|
1497 |
|
1498 octave_value get (void) const; |
|
1499 |
|
1500 octave_value get (const property_name& name) const; |
|
1501 |
|
1502 std::string graphics_object_name (void) const { return go_name; } |
|
1503 |
|
1504 static property_list::pval_map_type factory_defaults (void); |
|
1505 |
|
1506 // See the genprops.awk script for an explanation of the |
|
1507 // properties declarations. |
|
1508 |
|
1509 BEGIN_PROPERTIES |
|
1510 octave_value string |
|
1511 octave_value units |
|
1512 octave_value position |
|
1513 octave_value rotation |
|
1514 octave_value horizontalalignment |
6890
|
1515 color_property color |
7162
|
1516 octave_value fontname |
|
1517 octave_value fontsize |
7168
|
1518 string_property fontangle a |
|
1519 string_property fontweight a |
6874
|
1520 END_PROPERTIES |
|
1521 |
|
1522 static std::string go_name; |
|
1523 }; |
|
1524 |
|
1525 private: |
|
1526 properties xproperties; |
|
1527 |
|
1528 public: |
|
1529 text (const graphics_handle& mh, const graphics_handle& p) |
|
1530 : base_graphics_object (), xproperties (mh, p) |
|
1531 { |
|
1532 xproperties.override_defaults (*this); |
|
1533 } |
|
1534 |
|
1535 ~text (void) { xproperties.delete_children (); } |
|
1536 |
|
1537 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1538 |
|
1539 void mark_modified (void) { xproperties.mark_modified (); } |
|
1540 |
|
1541 void override_defaults (base_graphics_object& obj) |
|
1542 { |
|
1543 // Allow parent (figure) to override first (properties knows how |
|
1544 // to find the parent object). |
|
1545 xproperties.override_defaults (obj); |
|
1546 } |
|
1547 |
|
1548 void set_from_list (property_list& plist) |
|
1549 { |
|
1550 xproperties.set_from_list (*this, plist); |
|
1551 } |
|
1552 |
|
1553 void set (const property_name& name, const octave_value& val) |
|
1554 { |
|
1555 xproperties.set (name, val); |
|
1556 } |
|
1557 |
|
1558 octave_value get (void) const |
|
1559 { |
|
1560 return xproperties.get (); |
|
1561 } |
|
1562 |
|
1563 octave_value get (const property_name& name) const |
|
1564 { |
|
1565 return xproperties.get (name); |
|
1566 } |
|
1567 |
|
1568 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1569 |
|
1570 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1571 |
|
1572 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1573 |
|
1574 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1575 |
|
1576 base_properties& get_properties (void) { return xproperties; } |
|
1577 |
6890
|
1578 void defaults (void) const { gripe_not_implemented ("text::defaults"); } |
|
1579 |
6874
|
1580 bool valid_object (void) const { return true; } |
|
1581 }; |
|
1582 |
|
1583 // --------------------------------------------------------------------- |
|
1584 |
|
1585 class image : public base_graphics_object |
|
1586 { |
|
1587 public: |
|
1588 class properties : public base_properties |
|
1589 { |
|
1590 public: |
|
1591 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1592 |
|
1593 ~properties (void) { } |
|
1594 |
|
1595 void set (const property_name& name, const octave_value& val); |
|
1596 |
|
1597 octave_value get (void) const; |
|
1598 |
|
1599 octave_value get (const property_name& name) const; |
|
1600 |
|
1601 std::string graphics_object_name (void) const { return go_name; } |
|
1602 |
|
1603 static property_list::pval_map_type factory_defaults (void); |
|
1604 |
|
1605 // See the genprops.awk script for an explanation of the |
|
1606 // properties declarations. |
|
1607 |
|
1608 BEGIN_PROPERTIES |
|
1609 octave_value cdata |
|
1610 octave_value xdata |
|
1611 octave_value ydata |
|
1612 END_PROPERTIES |
|
1613 |
|
1614 static std::string go_name; |
|
1615 }; |
|
1616 |
|
1617 private: |
|
1618 properties xproperties; |
|
1619 |
|
1620 public: |
|
1621 image (const graphics_handle& mh, const graphics_handle& p) |
|
1622 : base_graphics_object (), xproperties (mh, p) |
|
1623 { |
|
1624 xproperties.override_defaults (*this); |
|
1625 } |
|
1626 |
|
1627 ~image (void) { xproperties.delete_children (); } |
|
1628 |
|
1629 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1630 |
|
1631 void mark_modified (void) { xproperties.mark_modified (); } |
|
1632 |
|
1633 void override_defaults (base_graphics_object& obj) |
|
1634 { |
|
1635 // Allow parent (figure) to override first (properties knows how |
|
1636 // to find the parent object). |
|
1637 xproperties.override_defaults (obj); |
|
1638 } |
|
1639 |
|
1640 void set_from_list (property_list& plist) |
|
1641 { |
|
1642 xproperties.set_from_list (*this, plist); |
|
1643 } |
|
1644 |
|
1645 void set (const property_name& name, const octave_value& val) |
|
1646 { |
|
1647 xproperties.set (name, val); |
|
1648 } |
|
1649 |
|
1650 octave_value get (void) const |
|
1651 { |
|
1652 return xproperties.get (); |
|
1653 } |
|
1654 |
|
1655 octave_value get (const property_name& name) const |
|
1656 { |
|
1657 return xproperties.get (name); |
|
1658 } |
|
1659 |
|
1660 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1661 |
|
1662 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1663 |
|
1664 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1665 |
|
1666 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1667 |
|
1668 base_properties& get_properties (void) { return xproperties; } |
|
1669 |
6890
|
1670 void defaults (void) const { gripe_not_implemented ("image::defaults"); } |
|
1671 |
6874
|
1672 bool valid_object (void) const { return true; } |
|
1673 }; |
|
1674 |
|
1675 // --------------------------------------------------------------------- |
|
1676 |
|
1677 class patch : public base_graphics_object |
|
1678 { |
|
1679 public: |
|
1680 class properties : public base_properties |
|
1681 { |
|
1682 public: |
|
1683 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1684 |
|
1685 ~properties (void) { } |
|
1686 |
|
1687 void set (const property_name& name, const octave_value& val); |
|
1688 |
|
1689 octave_value get (void) const; |
|
1690 |
|
1691 octave_value get (const property_name& name) const; |
|
1692 |
|
1693 std::string graphics_object_name (void) const { return go_name; } |
|
1694 |
|
1695 static property_list::pval_map_type factory_defaults (void); |
|
1696 |
|
1697 // See the genprops.awk script for an explanation of the |
|
1698 // properties declarations. |
|
1699 |
|
1700 BEGIN_PROPERTIES |
|
1701 octave_value cdata |
|
1702 octave_value xdata |
|
1703 octave_value ydata |
|
1704 octave_value zdata |
7020
|
1705 octave_value faces |
|
1706 octave_value vertices |
6938
|
1707 color_property facecolor a |
6874
|
1708 octave_value facealpha |
6938
|
1709 color_property edgecolor a |
6874
|
1710 octave_value linestyle |
|
1711 octave_value linewidth |
|
1712 octave_value marker |
|
1713 octave_value markeredgecolor |
|
1714 octave_value markerfacecolor |
|
1715 octave_value markersize |
7148
|
1716 octave_value keylabel |
6874
|
1717 END_PROPERTIES |
|
1718 |
|
1719 static std::string go_name; |
|
1720 }; |
|
1721 |
|
1722 private: |
|
1723 properties xproperties; |
|
1724 |
|
1725 public: |
|
1726 patch (const graphics_handle& mh, const graphics_handle& p) |
|
1727 : base_graphics_object (), xproperties (mh, p) |
|
1728 { |
|
1729 xproperties.override_defaults (*this); |
|
1730 } |
|
1731 |
|
1732 ~patch (void) { xproperties.delete_children (); } |
|
1733 |
|
1734 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1735 |
|
1736 void mark_modified (void) { xproperties.mark_modified (); } |
|
1737 |
|
1738 void override_defaults (base_graphics_object& obj) |
|
1739 { |
|
1740 // Allow parent (figure) to override first (properties knows how |
|
1741 // to find the parent object). |
|
1742 xproperties.override_defaults (obj); |
|
1743 } |
|
1744 |
|
1745 void set_from_list (property_list& plist) |
|
1746 { |
|
1747 xproperties.set_from_list (*this, plist); |
|
1748 } |
|
1749 |
|
1750 void set (const property_name& name, const octave_value& val) |
|
1751 { |
|
1752 xproperties.set (name, val); |
|
1753 } |
|
1754 |
|
1755 octave_value get (void) const |
|
1756 { |
|
1757 return xproperties.get (); |
|
1758 } |
|
1759 |
|
1760 octave_value get (const property_name& name) const |
|
1761 { |
|
1762 return xproperties.get (name); |
|
1763 } |
|
1764 |
|
1765 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1766 |
|
1767 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1768 |
|
1769 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1770 |
|
1771 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1772 |
|
1773 base_properties& get_properties (void) { return xproperties; } |
|
1774 |
6890
|
1775 void defaults (void) const { gripe_not_implemented ("patch::defaults"); } |
|
1776 |
6874
|
1777 bool valid_object (void) const { return true; } |
|
1778 }; |
|
1779 |
|
1780 // --------------------------------------------------------------------- |
|
1781 |
|
1782 class surface : public base_graphics_object |
|
1783 { |
|
1784 public: |
|
1785 class properties : public base_properties |
|
1786 { |
|
1787 public: |
|
1788 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1789 |
|
1790 ~properties (void) { } |
|
1791 |
|
1792 void set (const property_name& name, const octave_value& val); |
|
1793 |
|
1794 octave_value get (void) const; |
|
1795 |
|
1796 octave_value get (const property_name& name) const; |
|
1797 |
|
1798 std::string graphics_object_name (void) const { return go_name; } |
|
1799 |
|
1800 static property_list::pval_map_type factory_defaults (void); |
|
1801 |
|
1802 // See the genprops.awk script for an explanation of the |
|
1803 // properties declarations. |
|
1804 |
|
1805 BEGIN_PROPERTIES |
|
1806 octave_value xdata |
|
1807 octave_value ydata |
|
1808 octave_value zdata |
7108
|
1809 octave_value cdata |
|
1810 color_property facecolor a |
|
1811 octave_value facealpha |
|
1812 color_property edgecolor a |
|
1813 octave_value linestyle |
|
1814 octave_value linewidth |
|
1815 octave_value marker |
|
1816 octave_value markeredgecolor |
|
1817 octave_value markerfacecolor |
|
1818 octave_value markersize |
6874
|
1819 octave_value keylabel |
|
1820 END_PROPERTIES |
|
1821 |
|
1822 static std::string go_name; |
|
1823 }; |
|
1824 |
|
1825 private: |
|
1826 properties xproperties; |
|
1827 |
|
1828 public: |
|
1829 surface (const graphics_handle& mh, const graphics_handle& p) |
|
1830 : base_graphics_object (), xproperties (mh, p) |
|
1831 { |
|
1832 xproperties.override_defaults (*this); |
|
1833 } |
|
1834 |
|
1835 ~surface (void) { xproperties.delete_children (); } |
|
1836 |
|
1837 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1838 |
|
1839 void mark_modified (void) { xproperties.mark_modified (); } |
|
1840 |
|
1841 void override_defaults (base_graphics_object& obj) |
|
1842 { |
|
1843 // Allow parent (figure) to override first (properties knows how |
|
1844 // to find the parent object). |
|
1845 xproperties.override_defaults (obj); |
|
1846 } |
|
1847 |
|
1848 void set_from_list (property_list& plist) |
|
1849 { |
|
1850 xproperties.set_from_list (*this, plist); |
|
1851 } |
|
1852 |
|
1853 void set (const property_name& name, const octave_value& val) |
|
1854 { |
|
1855 xproperties.set (name, val); |
|
1856 } |
|
1857 |
|
1858 octave_value get (void) const |
|
1859 { |
|
1860 return xproperties.get (); |
|
1861 } |
|
1862 |
|
1863 octave_value get (const property_name& name) const |
|
1864 { |
|
1865 return xproperties.get (name); |
|
1866 } |
|
1867 |
|
1868 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1869 |
|
1870 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1871 |
|
1872 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1873 |
|
1874 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1875 |
|
1876 base_properties& get_properties (void) { return xproperties; } |
|
1877 |
6890
|
1878 void defaults (void) const { gripe_not_implemented ("surface::defaults"); } |
|
1879 |
6874
|
1880 bool valid_object (void) const { return true; } |
|
1881 }; |
|
1882 |
|
1883 octave_value |
|
1884 get_property_from_handle (double handle, const std::string &property, |
|
1885 const std::string &func); |
|
1886 bool |
|
1887 set_property_in_handle (double handle, const std::string &property, |
|
1888 const octave_value &arg, const std::string &func); |
|
1889 |
|
1890 // --------------------------------------------------------------------- |
|
1891 |
|
1892 class gh_manager |
|
1893 { |
|
1894 protected: |
|
1895 |
|
1896 gh_manager (void); |
|
1897 |
|
1898 public: |
|
1899 |
|
1900 static bool instance_ok (void) |
|
1901 { |
|
1902 bool retval = true; |
|
1903 |
|
1904 if (! instance) |
|
1905 instance = new gh_manager (); |
|
1906 |
|
1907 if (! instance) |
|
1908 { |
|
1909 ::error ("unable to create gh_manager!"); |
|
1910 |
|
1911 retval = false; |
|
1912 } |
|
1913 |
|
1914 return retval; |
|
1915 } |
|
1916 |
|
1917 static void free (const graphics_handle& h) |
|
1918 { |
|
1919 if (instance_ok ()) |
|
1920 instance->do_free (h); |
|
1921 } |
|
1922 |
|
1923 static graphics_handle lookup (double val) |
|
1924 { |
|
1925 return instance_ok () ? instance->do_lookup (val) : graphics_handle (); |
|
1926 } |
|
1927 |
|
1928 static graphics_object get_object (const graphics_handle& h) |
|
1929 { |
|
1930 return instance_ok () ? instance->do_get_object (h) : graphics_object (); |
|
1931 } |
|
1932 |
|
1933 static graphics_handle |
|
1934 make_graphics_handle (const std::string& go_name, |
|
1935 const graphics_handle& parent) |
|
1936 { |
|
1937 return instance_ok () |
|
1938 ? instance->do_make_graphics_handle (go_name, parent) |
|
1939 : graphics_handle (); |
|
1940 } |
|
1941 |
|
1942 static graphics_handle make_figure_handle (double val) |
|
1943 { |
|
1944 return instance_ok () |
|
1945 ? instance->do_make_figure_handle (val) : graphics_handle (); |
|
1946 } |
|
1947 |
|
1948 static void push_figure (const graphics_handle& h) |
|
1949 { |
|
1950 if (instance_ok ()) |
|
1951 instance->do_push_figure (h); |
|
1952 } |
|
1953 |
|
1954 static void pop_figure (const graphics_handle& h) |
|
1955 { |
|
1956 if (instance_ok ()) |
|
1957 instance->do_pop_figure (h); |
|
1958 } |
|
1959 |
|
1960 static graphics_handle current_figure (void) |
|
1961 { |
|
1962 return instance_ok () |
|
1963 ? instance->do_current_figure () : graphics_handle (); |
|
1964 } |
|
1965 |
|
1966 static Matrix handle_list (void) |
|
1967 { |
|
1968 return instance_ok () ? instance->do_handle_list () : Matrix (); |
|
1969 } |
|
1970 |
|
1971 static Matrix figure_handle_list (void) |
|
1972 { |
|
1973 return instance_ok () ? instance->do_figure_handle_list () : Matrix (); |
|
1974 } |
|
1975 |
|
1976 private: |
|
1977 |
|
1978 static gh_manager *instance; |
|
1979 |
|
1980 typedef std::map<graphics_handle, graphics_object>::iterator iterator; |
|
1981 typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator; |
|
1982 |
|
1983 typedef std::set<graphics_handle>::iterator free_list_iterator; |
|
1984 typedef std::set<graphics_handle>::const_iterator const_free_list_iterator; |
|
1985 |
|
1986 typedef std::list<graphics_handle>::iterator figure_list_iterator; |
|
1987 typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator; |
|
1988 |
|
1989 // A map of handles to graphics objects. |
|
1990 std::map<graphics_handle, graphics_object> handle_map; |
|
1991 |
|
1992 // The available graphics handles. |
|
1993 std::set<graphics_handle> handle_free_list; |
|
1994 |
|
1995 // The next handle available if handle_free_list is empty. |
|
1996 graphics_handle next_handle; |
|
1997 |
|
1998 // The allocated figure handles. Top of the stack is most recently |
|
1999 // created. |
|
2000 std::list<graphics_handle> figure_list; |
|
2001 |
|
2002 graphics_handle get_handle (const std::string& go_name); |
|
2003 |
|
2004 void do_free (const graphics_handle& h); |
|
2005 |
|
2006 graphics_handle do_lookup (double val) |
|
2007 { |
|
2008 iterator p = handle_map.find (val); |
|
2009 |
|
2010 return (p != handle_map.end ()) ? p->first : graphics_handle (); |
|
2011 } |
|
2012 |
|
2013 graphics_object do_get_object (const graphics_handle& h) |
|
2014 { |
|
2015 iterator p = handle_map.find (h); |
|
2016 |
|
2017 return (p != handle_map.end ()) ? p->second : graphics_object (); |
|
2018 } |
|
2019 |
|
2020 graphics_handle do_make_graphics_handle (const std::string& go_name, |
|
2021 const graphics_handle& p); |
|
2022 |
|
2023 graphics_handle do_make_figure_handle (double val); |
|
2024 |
|
2025 Matrix do_handle_list (void) |
|
2026 { |
|
2027 Matrix retval (1, handle_map.size ()); |
|
2028 octave_idx_type i = 0; |
|
2029 for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++) |
7056
|
2030 { |
|
2031 graphics_handle h = p->first; |
|
2032 retval(i++) = h.value (); |
|
2033 } |
6874
|
2034 return retval; |
|
2035 } |
|
2036 |
|
2037 Matrix do_figure_handle_list (void) |
|
2038 { |
|
2039 Matrix retval (1, figure_list.size ()); |
|
2040 octave_idx_type i = 0; |
|
2041 for (const_figure_list_iterator p = figure_list.begin (); |
|
2042 p != figure_list.end (); |
|
2043 p++) |
7056
|
2044 { |
|
2045 graphics_handle h = *p; |
|
2046 retval(i++) = h.value (); |
|
2047 } |
6874
|
2048 return retval; |
|
2049 } |
|
2050 |
|
2051 void do_push_figure (const graphics_handle& h); |
|
2052 |
|
2053 void do_pop_figure (const graphics_handle& h); |
|
2054 |
|
2055 graphics_handle do_current_figure (void) const |
|
2056 { |
|
2057 return figure_list.empty () ? graphics_handle () : figure_list.front (); |
|
2058 } |
|
2059 }; |
|
2060 |
|
2061 |
|
2062 // This function is NOT equivalent to the scripting language function gcf. |
|
2063 graphics_handle gcf (void); |
|
2064 |
|
2065 // This function is NOT equivalent to the scripting language function gca. |
|
2066 graphics_handle gca (void); |
|
2067 |
|
2068 #endif |
|
2069 |
|
2070 /* |
|
2071 ;;; Local Variables: *** |
|
2072 ;;; mode: C++ *** |
|
2073 ;;; End: *** |
|
2074 */ |