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