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