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 operator double (void) const { return val; } |
|
468 |
|
469 double value (void) const { return val; } |
|
470 |
|
471 octave_value as_octave_value (void) const |
|
472 { |
|
473 return ok () ? octave_value (val) : octave_value (Matrix ()); |
|
474 } |
|
475 |
|
476 graphics_handle operator ++ (void) |
|
477 { |
|
478 ++val; |
|
479 return *this; |
|
480 } |
|
481 |
|
482 graphics_handle operator ++ (int) |
|
483 { |
|
484 graphics_handle h = *this; |
|
485 ++val; |
|
486 return h; |
|
487 } |
|
488 |
|
489 graphics_handle operator -- (void) |
|
490 { |
|
491 --val; |
|
492 return *this; |
|
493 } |
|
494 |
|
495 graphics_handle operator -- (int) |
|
496 { |
|
497 graphics_handle h = *this; |
|
498 --val; |
|
499 return h; |
|
500 } |
|
501 |
|
502 bool ok (void) const { return ! xisnan (val); } |
|
503 |
|
504 operator bool () const { return ok (); } |
|
505 |
|
506 private: |
|
507 double val; |
|
508 }; |
|
509 |
|
510 inline bool |
|
511 operator == (const graphics_handle& a, const graphics_handle& b) |
|
512 { |
|
513 return a.value () == b.value (); |
|
514 } |
|
515 |
|
516 inline bool |
|
517 operator != (const graphics_handle& a, const graphics_handle& b) |
|
518 { |
|
519 return a.value () != b.value (); |
|
520 } |
|
521 |
|
522 inline bool |
|
523 operator < (const graphics_handle& a, const graphics_handle& b) |
|
524 { |
|
525 return a.value () < b.value (); |
|
526 } |
|
527 |
|
528 inline bool |
|
529 operator <= (const graphics_handle& a, const graphics_handle& b) |
|
530 { |
|
531 return a.value () <= b.value (); |
|
532 } |
|
533 |
|
534 inline bool |
|
535 operator >= (const graphics_handle& a, const graphics_handle& b) |
|
536 { |
|
537 return a.value () >= b.value (); |
|
538 } |
|
539 |
|
540 inline bool |
|
541 operator > (const graphics_handle& a, const graphics_handle& b) |
|
542 { |
|
543 return a.value () > b.value (); |
|
544 } |
|
545 |
|
546 // --------------------------------------------------------------------- |
|
547 |
|
548 class base_graphics_object; |
|
549 |
|
550 class base_properties |
|
551 { |
|
552 public: |
|
553 base_properties (const std::string& t = "unknown", |
|
554 const graphics_handle& mh = graphics_handle (), |
|
555 const graphics_handle& p = graphics_handle ()) |
|
556 : type (t), __modified__ (true), __myhandle__ (mh), parent (p), |
|
557 children () { } |
|
558 |
|
559 virtual ~base_properties (void) { } |
|
560 |
|
561 virtual std::string graphics_object_name (void) const { return "unknonwn"; } |
|
562 |
|
563 void mark_modified (void); |
|
564 |
|
565 void override_defaults (base_graphics_object& obj); |
|
566 |
|
567 // Look through DEFAULTS for properties with given CLASS_NAME, and |
|
568 // apply them to the current object with set (virtual method). |
|
569 |
|
570 void set_from_list (base_graphics_object& obj, property_list& defaults); |
|
571 |
|
572 virtual void set (const property_name&, const octave_value&) { } |
|
573 |
|
574 graphics_handle get_parent (void) const { return parent; } |
|
575 |
|
576 void remove_child (const graphics_handle& h); |
|
577 |
|
578 void adopt (const graphics_handle& h) |
|
579 { |
|
580 octave_idx_type n = children.numel (); |
|
581 children.resize (1, n+1); |
|
582 children(n) = h; |
|
583 } |
|
584 |
|
585 void set_parent (const octave_value& val); |
|
586 |
|
587 void reparent (const graphics_handle& new_parent) { parent = new_parent; } |
|
588 |
|
589 virtual void delete_children (void); |
|
590 |
|
591 protected: |
|
592 std::string type; |
|
593 bool __modified__; |
|
594 graphics_handle __myhandle__; |
|
595 graphics_handle parent; |
|
596 Matrix children; |
|
597 }; |
|
598 |
|
599 class base_graphics_object |
|
600 { |
|
601 public: |
|
602 friend class graphics_object; |
|
603 |
|
604 base_graphics_object (void) : count (1) { } |
|
605 |
|
606 base_graphics_object (const base_graphics_object&) { } |
|
607 |
|
608 virtual ~base_graphics_object (void) { } |
|
609 |
|
610 virtual void mark_modified (void) |
|
611 { |
|
612 error ("base_graphics_object::mark_modified: invalid graphics object"); |
|
613 } |
|
614 |
|
615 virtual void override_defaults (base_graphics_object&) |
|
616 { |
|
617 error ("base_graphics_object::override_defaults: invalid graphics object"); |
|
618 } |
|
619 |
|
620 virtual void set_from_list (property_list&) |
|
621 { |
|
622 error ("base_graphics_object::set_from_list: invalid graphics object"); |
|
623 } |
|
624 |
|
625 virtual void set (const property_name&, const octave_value&) |
|
626 { |
|
627 error ("base_graphics_object::set: invalid graphics object"); |
|
628 } |
|
629 |
|
630 virtual void set_defaults (const std::string&) |
|
631 { |
|
632 error ("base_graphics_object::set_defaults: invalid graphics object"); |
|
633 } |
|
634 |
|
635 virtual octave_value get (void) const |
|
636 { |
|
637 error ("base_graphics_object::get: invalid graphics object"); |
|
638 return octave_value (); |
|
639 } |
|
640 |
|
641 virtual octave_value get (const property_name&) const |
|
642 { |
|
643 error ("base_graphics_object::get: invalid graphics object"); |
|
644 return octave_value (); |
|
645 } |
|
646 |
|
647 virtual octave_value get_default (const property_name&) const; |
|
648 |
|
649 virtual octave_value get_factory_default (const property_name&) const; |
|
650 |
|
651 virtual octave_value get_defaults (void) const |
|
652 { |
|
653 error ("base_graphics_object::get_defaults: invalid graphics object"); |
|
654 return octave_value (); |
|
655 } |
|
656 |
|
657 virtual octave_value get_factory_defaults (void) const |
|
658 { |
|
659 error ("base_graphics_object::get_factory_defaults: invalid graphics object"); |
|
660 return octave_value (); |
|
661 } |
|
662 |
|
663 virtual graphics_handle get_parent (void) const |
|
664 { |
|
665 error ("base_graphics_object::get_parent: invalid graphics object"); |
|
666 return graphics_handle (); |
|
667 } |
|
668 |
|
669 virtual void remove_child (const graphics_handle&) |
|
670 { |
|
671 error ("base_graphics_object::remove_child: invalid graphics object"); |
|
672 } |
|
673 |
|
674 virtual void adopt (const graphics_handle&) |
|
675 { |
|
676 error ("base_graphics_object::adopt: invalid graphics object"); |
|
677 } |
|
678 |
|
679 virtual void reparent (const graphics_handle&) |
|
680 { |
|
681 error ("base_graphics_object::reparent: invalid graphics object"); |
|
682 } |
|
683 |
|
684 virtual void defaults (void) const |
|
685 { |
|
686 error ("base_graphics_object::default: invalid graphics object"); |
|
687 } |
|
688 |
|
689 virtual base_properties& get_properties (void) |
|
690 { |
|
691 static base_properties properties; |
|
692 error ("base_graphics_object::get_properties: invalid graphics object"); |
|
693 return properties; |
|
694 } |
|
695 |
|
696 virtual bool valid_object (void) const { return false; } |
|
697 |
|
698 virtual std::string type (void) const { return "unknown"; } |
|
699 |
|
700 bool isa (const std::string& go_name) const |
|
701 { |
|
702 return type () == go_name; |
|
703 } |
|
704 |
|
705 protected: |
|
706 // A reference count. |
|
707 int count; |
|
708 }; |
|
709 |
|
710 class graphics_object |
|
711 { |
|
712 public: |
|
713 graphics_object (void) : rep (new base_graphics_object ()) { } |
|
714 |
|
715 graphics_object (base_graphics_object *new_rep) |
|
716 : rep (new_rep) { } |
|
717 |
|
718 graphics_object (const graphics_object& obj) |
|
719 { |
|
720 rep = obj.rep; |
|
721 rep->count++; |
|
722 } |
|
723 |
|
724 graphics_object& operator = (const graphics_object& obj) |
|
725 { |
|
726 if (rep != obj.rep) |
|
727 { |
|
728 if (--rep->count == 0) |
|
729 delete rep; |
|
730 |
|
731 rep = obj.rep; |
|
732 rep->count++; |
|
733 } |
|
734 |
|
735 return *this; |
|
736 } |
|
737 |
|
738 ~graphics_object (void) |
|
739 { |
|
740 if (--rep->count == 0) |
|
741 delete rep; |
|
742 } |
|
743 |
|
744 void mark_modified (void) { rep->mark_modified (); } |
|
745 |
|
746 void override_defaults (base_graphics_object& obj) |
|
747 { |
|
748 rep->override_defaults (obj); |
|
749 } |
|
750 |
|
751 void set_from_list (property_list& plist) |
|
752 { |
|
753 rep->set_from_list (plist); |
|
754 } |
|
755 |
|
756 void set (const property_name& name, const octave_value& val) |
|
757 { |
|
758 rep->set (name, val); |
|
759 } |
|
760 |
|
761 void set (const octave_value_list& args); |
|
762 |
|
763 void set_defaults (const std::string& mode) |
|
764 { |
|
765 rep->set_defaults (mode); |
|
766 } |
|
767 |
|
768 octave_value get (void) const |
|
769 { |
|
770 return rep->get (); |
|
771 } |
|
772 |
|
773 octave_value get (const property_name& name) const |
|
774 { |
|
775 return name.compare ("default") |
|
776 ? get_defaults () |
|
777 : (name.compare ("factory") |
|
778 ? get_factory_defaults () : rep->get (name)); |
|
779 } |
|
780 |
|
781 octave_value get_default (const property_name& name) const |
|
782 { |
|
783 return rep->get_default (name); |
|
784 } |
|
785 |
|
786 octave_value get_factory_default (const property_name& name) const |
|
787 { |
|
788 return rep->get_factory_default (name); |
|
789 } |
|
790 |
|
791 octave_value get_defaults (void) const { return rep->get_defaults (); } |
|
792 |
|
793 octave_value get_factory_defaults (void) const |
|
794 { |
|
795 return rep->get_factory_defaults (); |
|
796 } |
|
797 |
|
798 graphics_handle get_parent (void) const { return rep->get_parent (); } |
|
799 |
|
800 void remove_child (const graphics_handle& h) { return rep->remove_child (h); } |
|
801 |
|
802 void adopt (const graphics_handle& h) { return rep->adopt (h); } |
|
803 |
|
804 void reparent (const graphics_handle& h) { return rep->reparent (h); } |
|
805 |
|
806 void defaults (void) const { rep->defaults (); } |
|
807 |
|
808 bool isa (const std::string& go_name) const { return rep->isa (go_name); } |
|
809 |
|
810 base_properties& get_properties (void) { return rep->get_properties (); } |
|
811 |
|
812 bool valid_object (void) const { return rep->valid_object (); } |
|
813 |
|
814 operator bool (void) const { return rep->valid_object (); } |
|
815 |
|
816 private: |
|
817 base_graphics_object *rep; |
|
818 }; |
|
819 |
|
820 // --------------------------------------------------------------------- |
|
821 |
|
822 class root_figure : public base_graphics_object |
|
823 { |
|
824 public: |
|
825 class properties : public base_properties |
|
826 { |
|
827 public: |
|
828 properties (void) |
|
829 : base_properties ("root figure", 0, graphics_handle ()), |
|
830 currentfigure (), |
|
831 visible ("on") |
|
832 { } |
|
833 |
|
834 ~properties (void) { } |
|
835 |
|
836 void set (const property_name& name, const octave_value& val); |
|
837 |
|
838 octave_value get (void) const; |
|
839 |
|
840 octave_value get (const property_name& name) const; |
|
841 |
|
842 std::string graphics_object_name (void) const { return go_name; } |
|
843 |
|
844 // See the genprops.awk script for an explanation of the |
|
845 // properties declarations. |
|
846 |
|
847 BEGIN_PROPERTIES |
|
848 graphics_handle currentfigure S |
|
849 octave_value visible |
|
850 END_PROPERTIES |
|
851 |
|
852 static std::string go_name; |
|
853 }; |
|
854 |
|
855 private: |
|
856 properties xproperties; |
|
857 |
|
858 public: |
|
859 |
|
860 root_figure (void) : xproperties (), default_properties () { } |
|
861 |
|
862 ~root_figure (void) { xproperties.delete_children (); } |
|
863 |
|
864 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
865 |
|
866 void mark_modified (void) { } |
|
867 |
|
868 void override_defaults (base_graphics_object& obj) |
|
869 { |
|
870 // Now override with our defaults. If the default_properties |
|
871 // list includes the properties for all defaults (line, |
|
872 // surface, etc.) then we don't have to know the type of OBJ |
|
873 // here, we just call its set function and let it decide which |
|
874 // properties from the list to use. |
|
875 obj.set_from_list (default_properties); |
|
876 } |
|
877 |
|
878 void set_from_list (property_list& plist) |
|
879 { |
|
880 xproperties.set_from_list (*this, plist); |
|
881 } |
|
882 |
|
883 void set (const property_name& name, const octave_value& value) |
|
884 { |
|
885 if (name.compare ("default", 7)) |
|
886 // strip "default", pass rest to function that will |
|
887 // parse the remainder and add the element to the |
|
888 // default_properties map. |
|
889 default_properties.set (name.substr (7), value); |
|
890 else |
|
891 xproperties.set (name, value); |
|
892 } |
|
893 |
|
894 octave_value get (void) const |
|
895 { |
|
896 return xproperties.get (); |
|
897 } |
|
898 |
|
899 octave_value get (const property_name& name) const |
|
900 { |
|
901 octave_value retval; |
|
902 |
|
903 if (name.compare ("default", 7)) |
|
904 return get_default (name.substr (7)); |
|
905 else if (name.compare ("factory", 7)) |
|
906 return get_factory_default (name.substr (7)); |
|
907 else |
|
908 retval = xproperties.get (name); |
|
909 |
|
910 return retval; |
|
911 } |
|
912 |
|
913 octave_value get_default (const property_name& name) const |
|
914 { |
|
915 octave_value retval = default_properties.lookup (name); |
|
916 |
|
917 if (retval.is_undefined ()) |
|
918 error ("get: invalid default property `%s'", name.c_str ()); |
|
919 |
|
920 return retval; |
|
921 } |
|
922 |
|
923 octave_value get_factory_default (const property_name& name) const |
|
924 { |
|
925 octave_value retval = factory_properties.lookup (name); |
|
926 |
|
927 if (retval.is_undefined ()) |
|
928 error ("get: invalid factory default property `%s'", name.c_str ()); |
|
929 |
|
930 return retval; |
|
931 } |
|
932 |
|
933 octave_value get_defaults (void) const |
|
934 { |
|
935 return default_properties.as_struct ("default"); |
|
936 } |
|
937 |
|
938 octave_value get_factory_defaults (void) const |
|
939 { |
|
940 return factory_properties.as_struct ("factory"); |
|
941 } |
|
942 |
|
943 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
944 |
|
945 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
946 |
|
947 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
948 |
|
949 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
950 |
|
951 base_properties& get_properties (void) { return xproperties; } |
|
952 |
6890
|
953 void defaults (void) const |
|
954 { |
|
955 gripe_not_implemented ("root_figure::defaults"); |
|
956 } |
|
957 |
6874
|
958 bool valid_object (void) const { return true; } |
|
959 |
|
960 private: |
|
961 property_list default_properties; |
|
962 |
|
963 static property_list factory_properties; |
|
964 |
|
965 static property_list::plist_map_type init_factory_properties (void); |
|
966 }; |
|
967 |
|
968 // --------------------------------------------------------------------- |
|
969 |
|
970 class figure : public base_graphics_object |
|
971 { |
|
972 public: |
|
973 class properties : public base_properties |
|
974 { |
|
975 public: |
|
976 properties (const graphics_handle& mh, const graphics_handle& p); |
|
977 |
|
978 ~properties (void) { } |
|
979 |
|
980 void set (const property_name& name, const octave_value& val); |
|
981 |
|
982 octave_value get (void) const; |
|
983 |
|
984 octave_value get (const property_name& name) const; |
|
985 |
|
986 void close (void); |
|
987 |
|
988 std::string graphics_object_name (void) const { return go_name; } |
|
989 |
|
990 static property_list::pval_map_type factory_defaults (void); |
|
991 |
|
992 // See the genprops.awk script for an explanation of the |
|
993 // properties declarations. |
|
994 |
|
995 BEGIN_PROPERTIES |
|
996 octave_value __plot_stream__ |
|
997 octave_value nextplot |
|
998 octave_value closerequestfcn |
|
999 graphics_handle currentaxes S |
|
1000 colormap_property colormap |
|
1001 octave_value visible S |
|
1002 octave_value paperorientation |
|
1003 END_PROPERTIES |
|
1004 |
|
1005 static std::string go_name; |
|
1006 }; |
|
1007 |
|
1008 private: |
|
1009 properties xproperties; |
|
1010 |
|
1011 public: |
|
1012 figure (const graphics_handle& mh, const graphics_handle& p) |
|
1013 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1014 { |
|
1015 xproperties.override_defaults (*this); |
|
1016 } |
|
1017 |
|
1018 ~figure (void) |
|
1019 { |
|
1020 xproperties.delete_children (); |
|
1021 xproperties.close (); |
|
1022 } |
|
1023 |
|
1024 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1025 |
|
1026 void mark_modified (void) { xproperties.mark_modified (); } |
|
1027 |
|
1028 void override_defaults (base_graphics_object& obj) |
|
1029 { |
|
1030 // Allow parent (root figure) to override first (properties knows how |
|
1031 // to find the parent object). |
|
1032 xproperties.override_defaults (obj); |
|
1033 |
|
1034 // Now override with our defaults. If the default_properties |
|
1035 // list includes the properties for all defaults (line, |
|
1036 // surface, etc.) then we don't have to know the type of OBJ |
|
1037 // here, we just call its set function and let it decide which |
|
1038 // properties from the list to use. |
|
1039 obj.set_from_list (default_properties); |
|
1040 } |
|
1041 |
|
1042 void set_from_list (property_list& plist) |
|
1043 { |
|
1044 xproperties.set_from_list (*this, plist); |
|
1045 } |
|
1046 |
|
1047 void set (const property_name& name, const octave_value& value) |
|
1048 { |
|
1049 if (name.compare ("default", 7)) |
|
1050 // strip "default", pass rest to function that will |
|
1051 // parse the remainder and add the element to the |
|
1052 // default_properties map. |
|
1053 default_properties.set (name.substr (7), value); |
|
1054 else |
|
1055 xproperties.set (name, value); |
|
1056 } |
|
1057 |
|
1058 octave_value get (void) const |
|
1059 { |
|
1060 return xproperties.get (); |
|
1061 } |
|
1062 |
|
1063 octave_value get (const property_name& name) const |
|
1064 { |
|
1065 octave_value retval; |
|
1066 |
|
1067 if (name.compare ("default", 7)) |
|
1068 retval = get_default (name.substr (7)); |
|
1069 else |
|
1070 retval = xproperties.get (name); |
|
1071 |
|
1072 return retval; |
|
1073 } |
|
1074 |
|
1075 octave_value get_default (const property_name& name) const; |
|
1076 |
|
1077 octave_value get_defaults (void) const |
|
1078 { |
|
1079 return default_properties.as_struct ("default"); |
|
1080 } |
|
1081 |
|
1082 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1083 |
|
1084 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1085 |
|
1086 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1087 |
|
1088 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
1089 |
|
1090 base_properties& get_properties (void) { return xproperties; } |
|
1091 |
6890
|
1092 void defaults (void) const { gripe_not_implemented ("figure::defaults"); } |
|
1093 |
6874
|
1094 bool valid_object (void) const { return true; } |
|
1095 |
|
1096 private: |
|
1097 property_list default_properties; |
|
1098 }; |
|
1099 |
|
1100 // --------------------------------------------------------------------- |
|
1101 |
|
1102 class axes : public base_graphics_object |
|
1103 { |
|
1104 public: |
|
1105 class properties : public base_properties |
|
1106 { |
|
1107 public: |
|
1108 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1109 |
|
1110 ~properties (void) { } |
|
1111 |
|
1112 void set (const property_name& name, const octave_value& val); |
|
1113 |
|
1114 void set_defaults (base_graphics_object& obj, const std::string& mode); |
|
1115 |
|
1116 octave_value get (void) const; |
|
1117 |
|
1118 octave_value get (const property_name& name) const; |
|
1119 |
|
1120 void remove_child (const graphics_handle& h); |
|
1121 |
|
1122 void delete_children (void); |
|
1123 |
|
1124 std::string graphics_object_name (void) const { return go_name; } |
|
1125 |
|
1126 static property_list::pval_map_type factory_defaults (void); |
|
1127 |
|
1128 // See the genprops.awk script for an explanation of the |
|
1129 // properties declarations. |
|
1130 |
|
1131 BEGIN_PROPERTIES |
|
1132 octave_value position |
|
1133 mutable graphics_handle title GSO |
|
1134 octave_value box |
|
1135 octave_value key |
|
1136 octave_value keybox |
|
1137 octave_value keypos |
6962
|
1138 octave_value colororder |
6874
|
1139 octave_value dataaspectratio m |
|
1140 octave_value dataaspectratiomode |
|
1141 octave_value xlim m |
|
1142 octave_value ylim m |
|
1143 octave_value zlim m |
|
1144 octave_value clim m |
|
1145 octave_value xlimmode |
|
1146 octave_value ylimmode |
|
1147 octave_value zlimmode |
|
1148 octave_value climmode |
|
1149 mutable graphics_handle xlabel GSO |
|
1150 mutable graphics_handle ylabel GSO |
|
1151 mutable graphics_handle zlabel GSO |
|
1152 octave_value xgrid |
|
1153 octave_value ygrid |
|
1154 octave_value zgrid |
|
1155 octave_value xminorgrid |
|
1156 octave_value yminorgrid |
|
1157 octave_value zminorgrid |
|
1158 octave_value xtick m |
|
1159 octave_value ytick m |
|
1160 octave_value ztick m |
|
1161 octave_value xtickmode |
|
1162 octave_value ytickmode |
|
1163 octave_value ztickmode |
|
1164 octave_value xticklabel m |
|
1165 octave_value yticklabel m |
|
1166 octave_value zticklabel m |
|
1167 octave_value xticklabelmode |
|
1168 octave_value yticklabelmode |
|
1169 octave_value zticklabelmode |
|
1170 octave_value xscale |
|
1171 octave_value yscale |
|
1172 octave_value zscale |
|
1173 octave_value xdir |
|
1174 octave_value ydir |
|
1175 octave_value zdir |
|
1176 octave_value xaxislocation |
|
1177 octave_value yaxislocation |
|
1178 octave_value view |
|
1179 octave_value visible |
|
1180 octave_value nextplot |
|
1181 octave_value outerposition |
|
1182 END_PROPERTIES |
|
1183 |
|
1184 static std::string go_name; |
|
1185 }; |
|
1186 |
|
1187 private: |
|
1188 properties xproperties; |
|
1189 |
|
1190 public: |
|
1191 axes (const graphics_handle& mh, const graphics_handle& p) |
|
1192 : base_graphics_object (), xproperties (mh, p), default_properties () |
|
1193 { |
|
1194 xproperties.override_defaults (*this); |
|
1195 } |
|
1196 |
|
1197 ~axes (void) { xproperties.delete_children (); } |
|
1198 |
|
1199 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1200 |
|
1201 void mark_modified (void) { xproperties.mark_modified (); } |
|
1202 |
|
1203 void override_defaults (base_graphics_object& obj) |
|
1204 { |
|
1205 // Allow parent (figure) to override first (properties knows how |
|
1206 // to find the parent object). |
|
1207 xproperties.override_defaults (obj); |
|
1208 |
|
1209 // Now override with our defaults. If the default_properties |
|
1210 // list includes the properties for all defaults (line, |
|
1211 // surface, etc.) then we don't have to know the type of OBJ |
|
1212 // here, we just call its set function and let it decide which |
|
1213 // properties from the list to use. |
|
1214 obj.set_from_list (default_properties); |
|
1215 } |
|
1216 |
|
1217 void set_from_list (property_list& plist) |
|
1218 { |
|
1219 xproperties.set_from_list (*this, plist); |
|
1220 } |
|
1221 |
|
1222 void set (const property_name& name, const octave_value& value) |
|
1223 { |
|
1224 if (name.compare ("default", 7)) |
|
1225 // strip "default", pass rest to function that will |
|
1226 // parse the remainder and add the element to the |
|
1227 // default_properties map. |
|
1228 default_properties.set (name.substr (7), value); |
|
1229 else |
|
1230 xproperties.set (name, value); |
|
1231 } |
|
1232 |
|
1233 void set_defaults (const std::string& mode) |
|
1234 { |
|
1235 xproperties.set_defaults (*this, mode); |
|
1236 } |
|
1237 |
|
1238 octave_value get (void) const |
|
1239 { |
|
1240 return xproperties.get (); |
|
1241 } |
|
1242 |
|
1243 octave_value get (const property_name& name) const |
|
1244 { |
|
1245 octave_value retval; |
|
1246 |
|
1247 // FIXME -- finish this. |
|
1248 if (name.compare ("default", 7)) |
|
1249 retval = get_default (name.substr (7)); |
|
1250 else |
|
1251 retval = xproperties.get (name); |
|
1252 |
|
1253 return retval; |
|
1254 } |
|
1255 |
|
1256 octave_value get_default (const property_name& name) const; |
|
1257 |
|
1258 octave_value get_defaults (void) const |
|
1259 { |
|
1260 return default_properties.as_struct ("default"); |
|
1261 } |
|
1262 |
|
1263 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1264 |
|
1265 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1266 |
|
1267 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1268 |
|
1269 void reparent (const graphics_handle& np) { xproperties.reparent (np); } |
|
1270 |
|
1271 base_properties& get_properties (void) { return xproperties; } |
|
1272 |
6890
|
1273 void defaults (void) const { gripe_not_implemented ("axes::defaults"); } |
|
1274 |
6874
|
1275 bool valid_object (void) const { return true; } |
|
1276 |
|
1277 private: |
|
1278 property_list default_properties; |
|
1279 }; |
|
1280 |
|
1281 // --------------------------------------------------------------------- |
|
1282 |
|
1283 class line : public base_graphics_object |
|
1284 { |
|
1285 public: |
|
1286 class properties : public base_properties |
|
1287 { |
|
1288 public: |
|
1289 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1290 |
|
1291 ~properties (void) { } |
|
1292 |
|
1293 void set (const property_name& name, const octave_value& val); |
|
1294 |
|
1295 octave_value get (void) const; |
|
1296 |
|
1297 octave_value get (const property_name& name) const; |
|
1298 |
|
1299 std::string graphics_object_name (void) const { return go_name; } |
|
1300 |
|
1301 static property_list::pval_map_type factory_defaults (void); |
|
1302 |
|
1303 // See the genprops.awk script for an explanation of the |
|
1304 // properties declarations. |
|
1305 |
|
1306 BEGIN_PROPERTIES |
|
1307 octave_value xdata |
|
1308 octave_value ydata |
|
1309 octave_value zdata |
|
1310 octave_value ldata |
|
1311 octave_value udata |
|
1312 octave_value xldata |
|
1313 octave_value xudata |
|
1314 color_property color |
|
1315 octave_value linestyle |
|
1316 octave_value linewidth |
|
1317 octave_value marker |
|
1318 octave_value markeredgecolor |
|
1319 octave_value markerfacecolor |
|
1320 octave_value markersize |
|
1321 octave_value keylabel |
|
1322 END_PROPERTIES |
|
1323 |
|
1324 static std::string go_name; |
|
1325 }; |
|
1326 |
|
1327 private: |
|
1328 properties xproperties; |
|
1329 |
|
1330 public: |
|
1331 line (const graphics_handle& mh, const graphics_handle& p) |
|
1332 : base_graphics_object (), xproperties (mh, p) |
|
1333 { |
|
1334 xproperties.override_defaults (*this); |
|
1335 } |
|
1336 |
|
1337 ~line (void) { xproperties.delete_children (); } |
|
1338 |
|
1339 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1340 |
|
1341 void mark_modified (void) { xproperties.mark_modified (); } |
|
1342 |
|
1343 void override_defaults (base_graphics_object& obj) |
|
1344 { |
|
1345 // Allow parent (figure) to override first (properties knows how |
|
1346 // to find the parent object). |
|
1347 xproperties.override_defaults (obj); |
|
1348 } |
|
1349 |
|
1350 void set_from_list (property_list& plist) |
|
1351 { |
|
1352 xproperties.set_from_list (*this, plist); |
|
1353 } |
|
1354 |
|
1355 void set (const property_name& name, const octave_value& val) |
|
1356 { |
|
1357 xproperties.set (name, val); |
|
1358 } |
|
1359 |
|
1360 octave_value get (void) const |
|
1361 { |
|
1362 return xproperties.get (); |
|
1363 } |
|
1364 |
|
1365 octave_value get (const property_name& name) const |
|
1366 { |
|
1367 return xproperties.get (name); |
|
1368 } |
|
1369 |
|
1370 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1371 |
|
1372 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1373 |
|
1374 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1375 |
|
1376 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1377 |
|
1378 base_properties& get_properties (void) { return xproperties; } |
|
1379 |
6890
|
1380 void defaults (void) const { gripe_not_implemented ("line::defaults"); } |
|
1381 |
6874
|
1382 bool valid_object (void) const { return true; } |
|
1383 }; |
|
1384 |
|
1385 // --------------------------------------------------------------------- |
|
1386 |
|
1387 class text : public base_graphics_object |
|
1388 { |
|
1389 public: |
|
1390 class properties : public base_properties |
|
1391 { |
|
1392 public: |
|
1393 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1394 |
|
1395 ~properties (void) { } |
|
1396 |
|
1397 void set (const property_name& name, const octave_value& val); |
|
1398 |
|
1399 octave_value get (void) const; |
|
1400 |
|
1401 octave_value get (const property_name& name) const; |
|
1402 |
|
1403 std::string graphics_object_name (void) const { return go_name; } |
|
1404 |
|
1405 static property_list::pval_map_type factory_defaults (void); |
|
1406 |
|
1407 // See the genprops.awk script for an explanation of the |
|
1408 // properties declarations. |
|
1409 |
|
1410 BEGIN_PROPERTIES |
|
1411 octave_value string |
|
1412 octave_value units |
|
1413 octave_value position |
|
1414 octave_value rotation |
|
1415 octave_value horizontalalignment |
6890
|
1416 color_property color |
6874
|
1417 END_PROPERTIES |
|
1418 |
|
1419 static std::string go_name; |
|
1420 }; |
|
1421 |
|
1422 private: |
|
1423 properties xproperties; |
|
1424 |
|
1425 public: |
|
1426 text (const graphics_handle& mh, const graphics_handle& p) |
|
1427 : base_graphics_object (), xproperties (mh, p) |
|
1428 { |
|
1429 xproperties.override_defaults (*this); |
|
1430 } |
|
1431 |
|
1432 ~text (void) { xproperties.delete_children (); } |
|
1433 |
|
1434 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1435 |
|
1436 void mark_modified (void) { xproperties.mark_modified (); } |
|
1437 |
|
1438 void override_defaults (base_graphics_object& obj) |
|
1439 { |
|
1440 // Allow parent (figure) to override first (properties knows how |
|
1441 // to find the parent object). |
|
1442 xproperties.override_defaults (obj); |
|
1443 } |
|
1444 |
|
1445 void set_from_list (property_list& plist) |
|
1446 { |
|
1447 xproperties.set_from_list (*this, plist); |
|
1448 } |
|
1449 |
|
1450 void set (const property_name& name, const octave_value& val) |
|
1451 { |
|
1452 xproperties.set (name, val); |
|
1453 } |
|
1454 |
|
1455 octave_value get (void) const |
|
1456 { |
|
1457 return xproperties.get (); |
|
1458 } |
|
1459 |
|
1460 octave_value get (const property_name& name) const |
|
1461 { |
|
1462 return xproperties.get (name); |
|
1463 } |
|
1464 |
|
1465 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1466 |
|
1467 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1468 |
|
1469 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1470 |
|
1471 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1472 |
|
1473 base_properties& get_properties (void) { return xproperties; } |
|
1474 |
6890
|
1475 void defaults (void) const { gripe_not_implemented ("text::defaults"); } |
|
1476 |
6874
|
1477 bool valid_object (void) const { return true; } |
|
1478 }; |
|
1479 |
|
1480 // --------------------------------------------------------------------- |
|
1481 |
|
1482 class image : public base_graphics_object |
|
1483 { |
|
1484 public: |
|
1485 class properties : public base_properties |
|
1486 { |
|
1487 public: |
|
1488 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1489 |
|
1490 ~properties (void) { } |
|
1491 |
|
1492 void set (const property_name& name, const octave_value& val); |
|
1493 |
|
1494 octave_value get (void) const; |
|
1495 |
|
1496 octave_value get (const property_name& name) const; |
|
1497 |
|
1498 std::string graphics_object_name (void) const { return go_name; } |
|
1499 |
|
1500 static property_list::pval_map_type factory_defaults (void); |
|
1501 |
|
1502 // See the genprops.awk script for an explanation of the |
|
1503 // properties declarations. |
|
1504 |
|
1505 BEGIN_PROPERTIES |
|
1506 octave_value cdata |
|
1507 octave_value xdata |
|
1508 octave_value ydata |
|
1509 END_PROPERTIES |
|
1510 |
|
1511 static std::string go_name; |
|
1512 }; |
|
1513 |
|
1514 private: |
|
1515 properties xproperties; |
|
1516 |
|
1517 public: |
|
1518 image (const graphics_handle& mh, const graphics_handle& p) |
|
1519 : base_graphics_object (), xproperties (mh, p) |
|
1520 { |
|
1521 xproperties.override_defaults (*this); |
|
1522 } |
|
1523 |
|
1524 ~image (void) { xproperties.delete_children (); } |
|
1525 |
|
1526 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1527 |
|
1528 void mark_modified (void) { xproperties.mark_modified (); } |
|
1529 |
|
1530 void override_defaults (base_graphics_object& obj) |
|
1531 { |
|
1532 // Allow parent (figure) to override first (properties knows how |
|
1533 // to find the parent object). |
|
1534 xproperties.override_defaults (obj); |
|
1535 } |
|
1536 |
|
1537 void set_from_list (property_list& plist) |
|
1538 { |
|
1539 xproperties.set_from_list (*this, plist); |
|
1540 } |
|
1541 |
|
1542 void set (const property_name& name, const octave_value& val) |
|
1543 { |
|
1544 xproperties.set (name, val); |
|
1545 } |
|
1546 |
|
1547 octave_value get (void) const |
|
1548 { |
|
1549 return xproperties.get (); |
|
1550 } |
|
1551 |
|
1552 octave_value get (const property_name& name) const |
|
1553 { |
|
1554 return xproperties.get (name); |
|
1555 } |
|
1556 |
|
1557 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1558 |
|
1559 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1560 |
|
1561 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1562 |
|
1563 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1564 |
|
1565 base_properties& get_properties (void) { return xproperties; } |
|
1566 |
6890
|
1567 void defaults (void) const { gripe_not_implemented ("image::defaults"); } |
|
1568 |
6874
|
1569 bool valid_object (void) const { return true; } |
|
1570 }; |
|
1571 |
|
1572 // --------------------------------------------------------------------- |
|
1573 |
|
1574 class patch : public base_graphics_object |
|
1575 { |
|
1576 public: |
|
1577 class properties : public base_properties |
|
1578 { |
|
1579 public: |
|
1580 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1581 |
|
1582 ~properties (void) { } |
|
1583 |
|
1584 void set (const property_name& name, const octave_value& val); |
|
1585 |
|
1586 octave_value get (void) const; |
|
1587 |
|
1588 octave_value get (const property_name& name) const; |
|
1589 |
|
1590 std::string graphics_object_name (void) const { return go_name; } |
|
1591 |
|
1592 static property_list::pval_map_type factory_defaults (void); |
|
1593 |
|
1594 // See the genprops.awk script for an explanation of the |
|
1595 // properties declarations. |
|
1596 |
|
1597 BEGIN_PROPERTIES |
|
1598 octave_value cdata |
|
1599 octave_value xdata |
|
1600 octave_value ydata |
|
1601 octave_value zdata |
7020
|
1602 octave_value faces |
|
1603 octave_value vertices |
6938
|
1604 color_property facecolor a |
6874
|
1605 octave_value facealpha |
6938
|
1606 color_property edgecolor a |
6874
|
1607 octave_value linestyle |
|
1608 octave_value linewidth |
|
1609 octave_value marker |
|
1610 octave_value markeredgecolor |
|
1611 octave_value markerfacecolor |
|
1612 octave_value markersize |
|
1613 END_PROPERTIES |
|
1614 |
|
1615 static std::string go_name; |
|
1616 }; |
|
1617 |
|
1618 private: |
|
1619 properties xproperties; |
|
1620 |
|
1621 public: |
|
1622 patch (const graphics_handle& mh, const graphics_handle& p) |
|
1623 : base_graphics_object (), xproperties (mh, p) |
|
1624 { |
|
1625 xproperties.override_defaults (*this); |
|
1626 } |
|
1627 |
|
1628 ~patch (void) { xproperties.delete_children (); } |
|
1629 |
|
1630 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1631 |
|
1632 void mark_modified (void) { xproperties.mark_modified (); } |
|
1633 |
|
1634 void override_defaults (base_graphics_object& obj) |
|
1635 { |
|
1636 // Allow parent (figure) to override first (properties knows how |
|
1637 // to find the parent object). |
|
1638 xproperties.override_defaults (obj); |
|
1639 } |
|
1640 |
|
1641 void set_from_list (property_list& plist) |
|
1642 { |
|
1643 xproperties.set_from_list (*this, plist); |
|
1644 } |
|
1645 |
|
1646 void set (const property_name& name, const octave_value& val) |
|
1647 { |
|
1648 xproperties.set (name, val); |
|
1649 } |
|
1650 |
|
1651 octave_value get (void) const |
|
1652 { |
|
1653 return xproperties.get (); |
|
1654 } |
|
1655 |
|
1656 octave_value get (const property_name& name) const |
|
1657 { |
|
1658 return xproperties.get (name); |
|
1659 } |
|
1660 |
|
1661 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1662 |
|
1663 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1664 |
|
1665 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1666 |
|
1667 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1668 |
|
1669 base_properties& get_properties (void) { return xproperties; } |
|
1670 |
6890
|
1671 void defaults (void) const { gripe_not_implemented ("patch::defaults"); } |
|
1672 |
6874
|
1673 bool valid_object (void) const { return true; } |
|
1674 }; |
|
1675 |
|
1676 // --------------------------------------------------------------------- |
|
1677 |
|
1678 class surface : public base_graphics_object |
|
1679 { |
|
1680 public: |
|
1681 class properties : public base_properties |
|
1682 { |
|
1683 public: |
|
1684 properties (const graphics_handle& mh, const graphics_handle& p); |
|
1685 |
|
1686 ~properties (void) { } |
|
1687 |
|
1688 void set (const property_name& name, const octave_value& val); |
|
1689 |
|
1690 octave_value get (void) const; |
|
1691 |
|
1692 octave_value get (const property_name& name) const; |
|
1693 |
|
1694 std::string graphics_object_name (void) const { return go_name; } |
|
1695 |
|
1696 static property_list::pval_map_type factory_defaults (void); |
|
1697 |
|
1698 // See the genprops.awk script for an explanation of the |
|
1699 // properties declarations. |
|
1700 |
|
1701 BEGIN_PROPERTIES |
|
1702 octave_value xdata |
|
1703 octave_value ydata |
|
1704 octave_value zdata |
|
1705 octave_value keylabel |
|
1706 END_PROPERTIES |
|
1707 |
|
1708 static std::string go_name; |
|
1709 }; |
|
1710 |
|
1711 private: |
|
1712 properties xproperties; |
|
1713 |
|
1714 public: |
|
1715 surface (const graphics_handle& mh, const graphics_handle& p) |
|
1716 : base_graphics_object (), xproperties (mh, p) |
|
1717 { |
|
1718 xproperties.override_defaults (*this); |
|
1719 } |
|
1720 |
|
1721 ~surface (void) { xproperties.delete_children (); } |
|
1722 |
|
1723 std::string type (void) const { return xproperties.graphics_object_name (); } |
|
1724 |
|
1725 void mark_modified (void) { xproperties.mark_modified (); } |
|
1726 |
|
1727 void override_defaults (base_graphics_object& obj) |
|
1728 { |
|
1729 // Allow parent (figure) to override first (properties knows how |
|
1730 // to find the parent object). |
|
1731 xproperties.override_defaults (obj); |
|
1732 } |
|
1733 |
|
1734 void set_from_list (property_list& plist) |
|
1735 { |
|
1736 xproperties.set_from_list (*this, plist); |
|
1737 } |
|
1738 |
|
1739 void set (const property_name& name, const octave_value& val) |
|
1740 { |
|
1741 xproperties.set (name, val); |
|
1742 } |
|
1743 |
|
1744 octave_value get (void) const |
|
1745 { |
|
1746 return xproperties.get (); |
|
1747 } |
|
1748 |
|
1749 octave_value get (const property_name& name) const |
|
1750 { |
|
1751 return xproperties.get (name); |
|
1752 } |
|
1753 |
|
1754 graphics_handle get_parent (void) const { return xproperties.get_parent (); } |
|
1755 |
|
1756 void remove_child (const graphics_handle& h) { xproperties.remove_child (h); } |
|
1757 |
|
1758 void adopt (const graphics_handle& h) { xproperties.adopt (h); } |
|
1759 |
|
1760 void reparent (const graphics_handle& h) { xproperties.reparent (h); } |
|
1761 |
|
1762 base_properties& get_properties (void) { return xproperties; } |
|
1763 |
6890
|
1764 void defaults (void) const { gripe_not_implemented ("surface::defaults"); } |
|
1765 |
6874
|
1766 bool valid_object (void) const { return true; } |
|
1767 }; |
|
1768 |
|
1769 octave_value |
|
1770 get_property_from_handle (double handle, const std::string &property, |
|
1771 const std::string &func); |
|
1772 bool |
|
1773 set_property_in_handle (double handle, const std::string &property, |
|
1774 const octave_value &arg, const std::string &func); |
|
1775 |
|
1776 // --------------------------------------------------------------------- |
|
1777 |
|
1778 class gh_manager |
|
1779 { |
|
1780 protected: |
|
1781 |
|
1782 gh_manager (void); |
|
1783 |
|
1784 public: |
|
1785 |
|
1786 static bool instance_ok (void) |
|
1787 { |
|
1788 bool retval = true; |
|
1789 |
|
1790 if (! instance) |
|
1791 instance = new gh_manager (); |
|
1792 |
|
1793 if (! instance) |
|
1794 { |
|
1795 ::error ("unable to create gh_manager!"); |
|
1796 |
|
1797 retval = false; |
|
1798 } |
|
1799 |
|
1800 return retval; |
|
1801 } |
|
1802 |
|
1803 static void free (const graphics_handle& h) |
|
1804 { |
|
1805 if (instance_ok ()) |
|
1806 instance->do_free (h); |
|
1807 } |
|
1808 |
|
1809 static graphics_handle lookup (double val) |
|
1810 { |
|
1811 return instance_ok () ? instance->do_lookup (val) : graphics_handle (); |
|
1812 } |
|
1813 |
|
1814 static graphics_object get_object (const graphics_handle& h) |
|
1815 { |
|
1816 return instance_ok () ? instance->do_get_object (h) : graphics_object (); |
|
1817 } |
|
1818 |
|
1819 static graphics_handle |
|
1820 make_graphics_handle (const std::string& go_name, |
|
1821 const graphics_handle& parent) |
|
1822 { |
|
1823 return instance_ok () |
|
1824 ? instance->do_make_graphics_handle (go_name, parent) |
|
1825 : graphics_handle (); |
|
1826 } |
|
1827 |
|
1828 static graphics_handle make_figure_handle (double val) |
|
1829 { |
|
1830 return instance_ok () |
|
1831 ? instance->do_make_figure_handle (val) : graphics_handle (); |
|
1832 } |
|
1833 |
|
1834 static void push_figure (const graphics_handle& h) |
|
1835 { |
|
1836 if (instance_ok ()) |
|
1837 instance->do_push_figure (h); |
|
1838 } |
|
1839 |
|
1840 static void pop_figure (const graphics_handle& h) |
|
1841 { |
|
1842 if (instance_ok ()) |
|
1843 instance->do_pop_figure (h); |
|
1844 } |
|
1845 |
|
1846 static graphics_handle current_figure (void) |
|
1847 { |
|
1848 return instance_ok () |
|
1849 ? instance->do_current_figure () : graphics_handle (); |
|
1850 } |
|
1851 |
|
1852 static Matrix handle_list (void) |
|
1853 { |
|
1854 return instance_ok () ? instance->do_handle_list () : Matrix (); |
|
1855 } |
|
1856 |
|
1857 static Matrix figure_handle_list (void) |
|
1858 { |
|
1859 return instance_ok () ? instance->do_figure_handle_list () : Matrix (); |
|
1860 } |
|
1861 |
|
1862 private: |
|
1863 |
|
1864 static gh_manager *instance; |
|
1865 |
|
1866 typedef std::map<graphics_handle, graphics_object>::iterator iterator; |
|
1867 typedef std::map<graphics_handle, graphics_object>::const_iterator const_iterator; |
|
1868 |
|
1869 typedef std::set<graphics_handle>::iterator free_list_iterator; |
|
1870 typedef std::set<graphics_handle>::const_iterator const_free_list_iterator; |
|
1871 |
|
1872 typedef std::list<graphics_handle>::iterator figure_list_iterator; |
|
1873 typedef std::list<graphics_handle>::const_iterator const_figure_list_iterator; |
|
1874 |
|
1875 // A map of handles to graphics objects. |
|
1876 std::map<graphics_handle, graphics_object> handle_map; |
|
1877 |
|
1878 // The available graphics handles. |
|
1879 std::set<graphics_handle> handle_free_list; |
|
1880 |
|
1881 // The next handle available if handle_free_list is empty. |
|
1882 graphics_handle next_handle; |
|
1883 |
|
1884 // The allocated figure handles. Top of the stack is most recently |
|
1885 // created. |
|
1886 std::list<graphics_handle> figure_list; |
|
1887 |
|
1888 graphics_handle get_handle (const std::string& go_name); |
|
1889 |
|
1890 void do_free (const graphics_handle& h); |
|
1891 |
|
1892 graphics_handle do_lookup (double val) |
|
1893 { |
|
1894 iterator p = handle_map.find (val); |
|
1895 |
|
1896 return (p != handle_map.end ()) ? p->first : graphics_handle (); |
|
1897 } |
|
1898 |
|
1899 graphics_object do_get_object (const graphics_handle& h) |
|
1900 { |
|
1901 iterator p = handle_map.find (h); |
|
1902 |
|
1903 return (p != handle_map.end ()) ? p->second : graphics_object (); |
|
1904 } |
|
1905 |
|
1906 graphics_handle do_make_graphics_handle (const std::string& go_name, |
|
1907 const graphics_handle& p); |
|
1908 |
|
1909 graphics_handle do_make_figure_handle (double val); |
|
1910 |
|
1911 Matrix do_handle_list (void) |
|
1912 { |
|
1913 Matrix retval (1, handle_map.size ()); |
|
1914 octave_idx_type i = 0; |
|
1915 for (const_iterator p = handle_map.begin (); p != handle_map.end (); p++) |
|
1916 retval(i++) = p->first; |
|
1917 return retval; |
|
1918 } |
|
1919 |
|
1920 Matrix do_figure_handle_list (void) |
|
1921 { |
|
1922 Matrix retval (1, figure_list.size ()); |
|
1923 octave_idx_type i = 0; |
|
1924 for (const_figure_list_iterator p = figure_list.begin (); |
|
1925 p != figure_list.end (); |
|
1926 p++) |
|
1927 retval(i++) = *p; |
|
1928 return retval; |
|
1929 } |
|
1930 |
|
1931 void do_push_figure (const graphics_handle& h); |
|
1932 |
|
1933 void do_pop_figure (const graphics_handle& h); |
|
1934 |
|
1935 graphics_handle do_current_figure (void) const |
|
1936 { |
|
1937 return figure_list.empty () ? graphics_handle () : figure_list.front (); |
|
1938 } |
|
1939 }; |
|
1940 |
|
1941 |
|
1942 // This function is NOT equivalent to the scripting language function gcf. |
|
1943 graphics_handle gcf (void); |
|
1944 |
|
1945 // This function is NOT equivalent to the scripting language function gca. |
|
1946 graphics_handle gca (void); |
|
1947 |
|
1948 #endif |
|
1949 |
|
1950 /* |
|
1951 ;;; Local Variables: *** |
|
1952 ;;; mode: C++ *** |
|
1953 ;;; End: *** |
|
1954 */ |