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