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