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