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