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