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