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