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