Mercurial > hg > octave-lyh
comparison src/graphics.h.in @ 7363:c31e5dab4f85
[project @ 2008-01-12 08:21:57 by jwe]
author | jwe |
---|---|
date | Sat, 12 Jan 2008 08:21:57 +0000 |
parents | 28a9e3d3bf14 |
children | 0e07f78369d1 |
comparison
equal
deleted
inserted
replaced
7362:94f66d813b2d | 7363:c31e5dab4f85 |
---|---|
80 } | 80 } |
81 }; | 81 }; |
82 | 82 |
83 // --------------------------------------------------------------------- | 83 // --------------------------------------------------------------------- |
84 | 84 |
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 | |
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 | |
217 virtual void set (const octave_value& val) | |
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 | |
85 class radio_values | 277 class radio_values |
86 { | 278 { |
87 public: | 279 public: |
88 radio_values (const std::string& opt_string = std::string ()); | 280 OCTINTERP_API radio_values (const std::string& opt_string = std::string ()); |
89 | 281 |
90 radio_values (const radio_values& a) | 282 radio_values (const radio_values& a) |
91 : default_val (a.default_val), possible_vals (a.possible_vals) { } | 283 : default_val (a.default_val), possible_vals (a.possible_vals) { } |
92 | 284 |
93 radio_values& operator = (const radio_values& a) | 285 radio_values& operator = (const radio_values& a) |
125 // Might also want to cache | 317 // Might also want to cache |
126 std::string default_val; | 318 std::string default_val; |
127 std::set<caseless_str> possible_vals; | 319 std::set<caseless_str> possible_vals; |
128 }; | 320 }; |
129 | 321 |
130 class radio_property | 322 class radio_property : public base_property |
131 { | 323 { |
132 public: | 324 public: |
133 radio_property (const radio_values& v = radio_values ()) | 325 radio_property (const std::string& name, const graphics_handle& h, |
134 : vals (v), current_val (v.default_value ()) { } | 326 const radio_values& v = radio_values ()) |
135 | 327 : base_property (name, h), |
136 radio_property (const radio_property& a) | 328 vals (v), current_val (v.default_value ()) { } |
137 : vals (a.vals), current_val (a.current_val) { } | 329 |
138 | 330 radio_property (const std::string& name, const graphics_handle& h, |
139 radio_property& operator = (const radio_property& a) | 331 const std::string& v) |
140 { | 332 : base_property (name, h), |
141 if (&a != this) | 333 vals (v), current_val (vals.default_value ()) { } |
142 { | 334 |
143 vals = a.vals; | 335 radio_property (const std::string& name, const graphics_handle& h, |
144 current_val = a.current_val; | 336 const radio_values& v, const std::string& def) |
145 } | 337 : base_property (name, h), |
146 | 338 vals (v), current_val (def) { } |
147 return *this; | 339 |
148 } | 340 radio_property (const radio_property& p) |
149 | 341 : base_property (p), vals (p.vals), current_val (p.current_val) { } |
150 radio_property& operator = (const std::string& newval) | 342 |
151 { | 343 void set (const octave_value& newval) |
152 if (vals.validate (newval)) | |
153 current_val = newval; | |
154 else | |
155 error ("invalid value"); | |
156 | |
157 return *this; | |
158 } | |
159 | |
160 radio_property& operator = (const octave_value& newval) | |
161 { | 344 { |
162 if (newval.is_string ()) | 345 if (newval.is_string ()) |
163 { | 346 { |
164 std::string s = newval.string_value (); | 347 std::string s = newval.string_value (); |
165 if (vals.validate (s)) | 348 if (vals.validate (s)) |
166 current_val = s; | 349 current_val = s; |
167 else | 350 else |
168 error ("invalid value"); | 351 error ("set: invalid value for radio property \"%s\" (value = %s)", |
352 get_name ().c_str (), s.c_str ()); | |
169 } | 353 } |
170 else | 354 else |
171 error ("invalid value"); | 355 error ("set: invalid value for radio property \"%s\"", |
172 | 356 get_name ().c_str ()); |
173 return *this; | 357 } |
174 } | 358 |
175 | 359 octave_value get (void) const { return octave_value (current_val); } |
176 operator octave_value (void) const { return current_val; } | |
177 | 360 |
178 const std::string& current_value (void) const { return current_val; } | 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 } | |
179 | 371 |
180 private: | 372 private: |
181 radio_values vals; | 373 radio_values vals; |
182 std::string current_val; | 374 std::string current_val; |
183 }; | 375 }; |
184 | 376 |
377 // --------------------------------------------------------------------- | |
378 | |
185 class color_values | 379 class color_values |
186 { | 380 { |
187 public: | 381 public: |
188 color_values (double r = 0, double g = 0, double b = 1) | 382 color_values (double r = 0, double g = 0, double b = 1) |
189 { | 383 : xrgb (1, 3) |
190 xrgb[0] = r; | 384 { |
191 xrgb[1] = g; | 385 xrgb(0) = r; |
192 xrgb[2] = b; | 386 xrgb(1) = g; |
387 xrgb(2) = b; | |
193 | 388 |
194 validate (); | 389 validate (); |
195 } | 390 } |
196 | 391 |
197 color_values (std::string str) | 392 color_values (std::string str) |
393 : xrgb (1, 3) | |
198 { | 394 { |
199 if (! str2rgb (str)) | 395 if (! str2rgb (str)) |
200 error ("invalid color specification"); | 396 error ("invalid color specification: %s", str.c_str ()); |
201 } | 397 } |
202 | 398 |
203 color_values (const color_values& c) | 399 color_values (const color_values& c) |
204 { | 400 : xrgb (c.xrgb) |
205 xrgb[0] = c.xrgb[0]; | 401 { } |
206 xrgb[1] = c.xrgb[1]; | |
207 xrgb[2] = c.xrgb[2]; | |
208 } | |
209 | 402 |
210 color_values& operator = (const color_values& c) | 403 color_values& operator = (const color_values& c) |
211 { | 404 { |
212 if (&c != this) | 405 if (&c != this) |
213 { | 406 xrgb = c.xrgb; |
214 xrgb[0] = c.xrgb[0]; | |
215 xrgb[1] = c.xrgb[1]; | |
216 xrgb[2] = c.xrgb[2]; | |
217 | |
218 } | |
219 | 407 |
220 return *this; | 408 return *this; |
221 } | 409 } |
222 | 410 |
223 const double* rgb (void) const { return xrgb; } | 411 Matrix rgb (void) const { return xrgb; } |
412 | |
413 operator octave_value (void) const { return xrgb; } | |
224 | 414 |
225 void validate (void) const | 415 void validate (void) const |
226 { | 416 { |
227 for (int i = 0; i < 3; i++) | 417 for (int i = 0; i < 3; i++) |
228 { | 418 { |
229 if (xrgb[i] < 0 || xrgb[i] > 1) | 419 if (xrgb(i) < 0 || xrgb(i) > 1) |
230 { | 420 { |
231 error ("invalid RGB color specification"); | 421 error ("invalid RGB color specification"); |
232 break; | 422 break; |
233 } | 423 } |
234 } | 424 } |
235 } | 425 } |
236 | 426 |
237 private: | 427 private: |
238 double xrgb[3]; | 428 Matrix xrgb; |
239 | 429 |
240 bool str2rgb (std::string str); | 430 OCTINTERP_API bool str2rgb (std::string str); |
241 }; | 431 }; |
242 | 432 |
243 | 433 class color_property : public base_property |
244 class color_property | 434 { |
245 { | 435 public: |
246 public: | 436 color_property (const color_values& c, const radio_values& v) |
247 color_property (const color_values& c = color_values (), | 437 : base_property ("", graphics_handle ()), |
248 const radio_values& v = radio_values ()) | 438 current_type (color_t), color_val (c), radio_val (v), |
249 : current_type (color_t), color_val (c), radio_val (v), | |
250 current_val (v.default_value ()) | 439 current_val (v.default_value ()) |
251 { } | 440 { } |
252 | 441 |
253 color_property (const radio_values& v) | 442 color_property (const std::string& name, const graphics_handle& h, |
254 : current_type (radio_t), color_val (color_values ()), radio_val (v), | 443 const color_values& c = color_values (), |
444 const radio_values& v = radio_values ()) | |
445 : base_property (name, h), | |
446 current_type (color_t), color_val (c), radio_val (v), | |
255 current_val (v.default_value ()) | 447 current_val (v.default_value ()) |
256 { } | 448 { } |
257 | 449 |
258 color_property (const radio_values& v, const std::string& initial_value) | 450 color_property (const std::string& name, const graphics_handle& h, |
259 : current_type (radio_t), color_val (color_values ()), radio_val (v), | 451 const radio_values& v) |
260 current_val (initial_value) | 452 : base_property (name, h), |
453 current_type (radio_t), color_val (color_values ()), radio_val (v), | |
454 current_val (v.default_value ()) | |
261 { } | 455 { } |
262 | 456 |
263 color_property (const octave_value& val); | 457 color_property (const std::string& name, const graphics_handle& h, |
264 | 458 const std::string& v) |
265 operator octave_value (void) const | 459 : base_property (name, h), |
460 current_type (radio_t), color_val (color_values ()), radio_val (v), | |
461 current_val (radio_val.default_value ()) | |
462 { } | |
463 | |
464 color_property (const std::string& name, const graphics_handle& h, | |
465 const color_property& v) | |
466 : base_property (name, h), | |
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 | |
266 { | 477 { |
267 if (current_type == color_t) | 478 if (current_type == color_t) |
268 { | 479 return color_val.rgb (); |
269 Matrix retval (1, 3); | |
270 const double *xrgb = color_val.rgb (); | |
271 | |
272 for (int i = 0; i < 3 ; i++) | |
273 retval(i) = xrgb[i]; | |
274 | |
275 return retval; | |
276 } | |
277 | 480 |
278 return current_val; | 481 return current_val; |
279 } | 482 } |
280 | 483 |
281 color_property& operator = (const color_property& a) | 484 OCTINTERP_API void set (const octave_value& newval); |
282 { | |
283 if (&a != this) | |
284 { | |
285 current_type = a.current_type; | |
286 color_val = a.color_val; | |
287 radio_val = a.radio_val; | |
288 current_val = a.current_val; | |
289 } | |
290 | |
291 return *this; | |
292 } | |
293 | |
294 color_property& operator = (const std::string& newval) | |
295 { | |
296 if (radio_val.validate (newval)) | |
297 { | |
298 current_val = newval; | |
299 current_type = radio_t; | |
300 } | |
301 | |
302 return *this; | |
303 } | |
304 | |
305 color_property& operator = (const color_values& newval) | |
306 { | |
307 color_val = newval; | |
308 current_type = color_t; | |
309 | |
310 return *this; | |
311 } | |
312 | |
313 color_property& operator = (const octave_value& newval); | |
314 | 485 |
315 bool is_rgb (void) const { return (current_type == color_t); } | 486 bool is_rgb (void) const { return (current_type == color_t); } |
316 | 487 |
317 bool is_radio (void) const { return (current_type == radio_t); } | 488 bool is_radio (void) const { return (current_type == radio_t); } |
318 | 489 |
319 const double* rgb (void) const | 490 bool is (const std::string& v) const |
491 { return (is_radio () && current_val == v); } | |
492 | |
493 Matrix rgb (void) const | |
320 { | 494 { |
321 if (current_type != color_t) | 495 if (current_type != color_t) |
322 error ("color has no rgb value"); | 496 error ("color has no rgb value"); |
323 | 497 |
324 return color_val.rgb (); | 498 return color_val.rgb (); |
329 if (current_type != radio_t) | 503 if (current_type != radio_t) |
330 error ("color has no radio value"); | 504 error ("color has no radio value"); |
331 | 505 |
332 return current_val; | 506 return current_val; |
333 } | 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 (); } | |
334 | 516 |
335 private: | 517 private: |
336 enum current_enum { color_t, radio_t } current_type; | 518 enum current_enum { color_t, radio_t } current_type; |
337 color_values color_val; | 519 color_values color_val; |
338 radio_values radio_val; | 520 radio_values radio_val; |
339 std::string current_val; | 521 std::string current_val; |
340 }; | 522 }; |
341 | 523 |
342 class colormap_property | 524 // --------------------------------------------------------------------- |
343 { | 525 |
344 public: | 526 class double_property : public base_property |
345 colormap_property (const Matrix& m = Matrix ()) | 527 { |
346 : cmap (m) | 528 public: |
347 { | 529 double_property (const std::string& name, const graphics_handle& h, |
348 if (cmap.is_empty ()) | 530 double d = 0) |
349 { | 531 : base_property (name, h), |
350 cmap = Matrix (64, 3, 0.0); | 532 current_val (d) { } |
351 | 533 |
352 for (octave_idx_type i = 0; i < 64; i++) | 534 double_property (const double_property& p) |
353 { | 535 : base_property (p), current_val (p.current_val) { } |
354 // This is the jet colormap. It would be nice to be able | 536 |
355 // to feval the jet function but since there is a static | 537 void set (const octave_value& v) |
356 // property object that includes a colormap_property | 538 { |
357 // object, we need to initialize this before main is even | 539 if (v.is_scalar_type () && v.is_real_type ()) |
358 // called, so calling an interpreted function is not | 540 current_val = v.double_value (); |
359 // possible. | 541 else |
360 | 542 error ("set: invalid value for double property \"%s\"", |
361 double x = i / 63.0; | 543 get_name ().c_str ()); |
362 | 544 } |
363 if (x >= 3.0/8.0 && x < 5.0/8.0) | 545 |
364 cmap(i,0) = 4.0 * x - 3.0/2.0; | 546 octave_value get (void) const { return octave_value (current_val); } |
365 else if (x >= 5.0/8.0 && x < 7.0/8.0) | 547 |
366 cmap(i,0) = 1.0; | 548 double double_value (void) const { return current_val; } |
367 else if (x >= 7.0/8.0) | 549 |
368 cmap(i,0) = -4.0 * x + 9.0/2.0; | 550 double_property& operator = (const octave_value& val) |
369 | 551 { |
370 if (x >= 1.0/8.0 && x < 3.0/8.0) | 552 set (val); |
371 cmap(i,1) = 4.0 * x - 1.0/2.0; | 553 return *this; |
372 else if (x >= 3.0/8.0 && x < 5.0/8.0) | 554 } |
373 cmap(i,1) = 1.0; | 555 |
374 else if (x >= 5.0/8.0 && x < 7.0/8.0) | 556 private: |
375 cmap(i,1) = -4.0 * x + 7.0/2.0; | 557 double current_val; |
376 | 558 }; |
377 if (x < 1.0/8.0) | 559 |
378 cmap(i,2) = 4.0 * x + 1.0/2.0; | 560 // --------------------------------------------------------------------- |
379 else if (x >= 1.0/8.0 && x < 3.0/8.0) | 561 |
380 cmap(i,2) = 1.0; | 562 class array_property : public base_property |
381 else if (x >= 3.0/8.0 && x < 5.0/8.0) | 563 { |
382 cmap(i,2) = -4.0 * x + 5.0/2.0; | 564 public: |
383 } | 565 array_property (const std::string& name, const graphics_handle& h, |
384 } | 566 const octave_value& m) |
385 | 567 : base_property (), data (m) { } |
386 validate (); | 568 |
387 } | 569 octave_value get (void) const { return data; } |
388 | 570 |
389 colormap_property (const octave_value& val) | 571 void set (const octave_value& v) |
390 { | 572 { |
391 cmap = val.matrix_value (); | 573 if (validate (v)) |
392 | 574 data = v; |
393 validate (); | 575 else |
394 } | 576 error ("invalid value for array property \"%s\"", |
395 | 577 get_name ().c_str ()); |
396 void validate (void) const | 578 } |
397 { | 579 |
398 if (error_state || cmap.columns () != 3) | 580 void add_constraint (const std::string& type) |
399 error ("invalid colormap specification"); | 581 { type_constraints.push_back (type); } |
400 } | 582 |
401 | 583 void add_constraint (dim_vector dims) |
402 operator octave_value (void) const { return cmap; } | 584 { size_constraints.push_back (dims); } |
403 | 585 |
404 private: | 586 array_property& operator = (const octave_value& val) |
405 Matrix cmap; | 587 { |
406 }; | 588 set (val); |
407 | 589 return *this; |
408 class data_property | 590 } |
409 { | 591 |
410 public: | 592 private: |
411 data_property (const NDArray& m = NDArray ()) | 593 OCTINTERP_API bool validate (const octave_value& v); |
412 : data (m), xmin (octave_Inf), xmax (-octave_Inf), xminp (octave_Inf) | 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 | |
609 data_property (const std::string& name, const graphics_handle& h, | |
610 const NDArray& m = NDArray ()) | |
611 : base_property (name, h), | |
612 data (m), xmin (octave_Inf), xmax (-octave_Inf), xminp (octave_Inf) | |
413 { | 613 { |
414 get_data_limits (); | 614 get_data_limits (); |
415 } | 615 } |
416 | 616 |
417 data_property (const Matrix& m) | 617 data_property (const std::string& name, const graphics_handle& h, |
418 : data (m), xmin (octave_Inf), xmax (-octave_Inf), xminp (octave_Inf) | 618 const Matrix& m) |
619 : base_property (name, h), | |
620 data (m), xmin (octave_Inf), xmax (-octave_Inf), xminp (octave_Inf) | |
419 { | 621 { |
420 get_data_limits (); | 622 get_data_limits (); |
421 } | 623 } |
422 | 624 |
423 data_property (const octave_value& val) | 625 data_property (const data_property& p) |
424 : data (), xmin (octave_Inf), xmax (-octave_Inf), xminp (octave_Inf) | 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) | |
425 { | 630 { |
426 data = val.array_value (); | 631 data = val.array_value (); |
427 | 632 |
428 get_data_limits (); | 633 get_data_limits (); |
429 } | 634 } |
430 | 635 |
431 data_property& operator = (const data_property& a) | 636 octave_value get (void) const { return data; } |
432 { | 637 |
433 if (&a != this) | 638 NDArray array_value (void) const { return data; } |
434 { | 639 |
435 data = a.data; | 640 Matrix matrix_value (void) const { return data.matrix_value (); } |
436 xmin = a.xmin; | |
437 xmax = a.xmax; | |
438 xminp = a.xminp; | |
439 } | |
440 | |
441 return *this; | |
442 } | |
443 | |
444 operator octave_value (void) const { return data; } | |
445 | 641 |
446 double min_val (void) const { return xmin; } | 642 double min_val (void) const { return xmin; } |
447 double max_val (void) const { return xmax; } | 643 double max_val (void) const { return xmax; } |
448 double min_pos (void) const { return xminp; } | 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 } | |
449 | 651 |
450 private: | 652 private: |
451 NDArray data; | 653 NDArray data; |
452 double xmin; | 654 double xmin; |
453 double xmax; | 655 double xmax; |
479 } | 681 } |
480 } | 682 } |
481 } | 683 } |
482 }; | 684 }; |
483 | 685 |
686 // --------------------------------------------------------------------- | |
687 | |
688 class bool_property : public radio_property | |
689 { | |
690 public: | |
691 bool_property (const std::string& name, const graphics_handle& h, | |
692 bool val) | |
693 : radio_property (name, h, radio_values (val ? "{on}|off" : "on|{off}")) | |
694 { } | |
695 | |
696 bool_property (const std::string& name, const graphics_handle& h, | |
697 const char* val) | |
698 : radio_property (name, h, radio_values ("on|off"), val) | |
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: | |
726 handle_property (const std::string& name, const graphics_handle& h, | |
727 const graphics_handle& val = graphics_handle ()) | |
728 : base_property (name, h), | |
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: | |
761 any_property (const std::string& name, const graphics_handle& h, | |
762 const octave_value& m = Matrix ()) | |
763 : base_property (), data (m) { } | |
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: | |
784 callback_property (const std::string& name, const graphics_handle& h, | |
785 const octave_value& m) | |
786 : base_property (), callback (m) { } | |
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 | |
484 class property_list | 910 class property_list |
485 { | 911 { |
486 public: | 912 public: |
487 typedef std::map<std::string, octave_value> pval_map_type; | 913 typedef std::map<std::string, octave_value> pval_map_type; |
488 typedef std::map<std::string, pval_map_type> plist_map_type; | 914 typedef std::map<std::string, pval_map_type> plist_map_type; |
524 plist_map_type plist_map; | 950 plist_map_type plist_map; |
525 }; | 951 }; |
526 | 952 |
527 // --------------------------------------------------------------------- | 953 // --------------------------------------------------------------------- |
528 | 954 |
529 class graphics_handle | |
530 { | |
531 public: | |
532 graphics_handle (void) : val (octave_NaN) { } | |
533 | |
534 graphics_handle (const octave_value& a); | |
535 | |
536 graphics_handle (int a) : val (a) { } | |
537 | |
538 graphics_handle (double a) : val (a) { } | |
539 | |
540 graphics_handle (const graphics_handle& a) : val (a.val) { } | |
541 | |
542 graphics_handle& operator = (const graphics_handle& a) | |
543 { | |
544 if (&a != this) | |
545 val = a.val; | |
546 | |
547 return *this; | |
548 } | |
549 | |
550 ~graphics_handle (void) { } | |
551 | |
552 double value (void) const { return val; } | |
553 | |
554 octave_value as_octave_value (void) const | |
555 { | |
556 return ok () ? octave_value (val) : octave_value (Matrix ()); | |
557 } | |
558 | |
559 graphics_handle operator ++ (void) | |
560 { | |
561 ++val; | |
562 return *this; | |
563 } | |
564 | |
565 graphics_handle operator ++ (int) | |
566 { | |
567 graphics_handle h = *this; | |
568 ++val; | |
569 return h; | |
570 } | |
571 | |
572 graphics_handle operator -- (void) | |
573 { | |
574 --val; | |
575 return *this; | |
576 } | |
577 | |
578 graphics_handle operator -- (int) | |
579 { | |
580 graphics_handle h = *this; | |
581 --val; | |
582 return h; | |
583 } | |
584 | |
585 bool ok (void) const { return ! xisnan (val); } | |
586 | |
587 private: | |
588 double val; | |
589 }; | |
590 | |
591 inline bool | |
592 operator == (const graphics_handle& a, const graphics_handle& b) | |
593 { | |
594 return a.value () == b.value (); | |
595 } | |
596 | |
597 inline bool | |
598 operator != (const graphics_handle& a, const graphics_handle& b) | |
599 { | |
600 return a.value () != b.value (); | |
601 } | |
602 | |
603 inline bool | |
604 operator < (const graphics_handle& a, const graphics_handle& b) | |
605 { | |
606 return a.value () < b.value (); | |
607 } | |
608 | |
609 inline bool | |
610 operator <= (const graphics_handle& a, const graphics_handle& b) | |
611 { | |
612 return a.value () <= b.value (); | |
613 } | |
614 | |
615 inline bool | |
616 operator >= (const graphics_handle& a, const graphics_handle& b) | |
617 { | |
618 return a.value () >= b.value (); | |
619 } | |
620 | |
621 inline bool | |
622 operator > (const graphics_handle& a, const graphics_handle& b) | |
623 { | |
624 return a.value () > b.value (); | |
625 } | |
626 | |
627 // --------------------------------------------------------------------- | |
628 | |
629 class base_graphics_object; | 955 class base_graphics_object; |
630 | 956 |
631 class base_properties | 957 class base_properties |
632 { | 958 { |
633 public: | 959 public: |
634 base_properties (const std::string& ty = "unknown", | 960 base_properties (const std::string& ty = "unknown", |
635 const graphics_handle& mh = graphics_handle (), | 961 const graphics_handle& mh = graphics_handle (), |
636 const graphics_handle& p = graphics_handle ()) | 962 const graphics_handle& p = graphics_handle ()) |
637 : tag (), type (ty), __modified__ (true), __myhandle__ (mh), | 963 : tag ("tag", mh), |
638 parent (p), children () { } | 964 type ("type", mh, ty), |
965 __modified__ ("__modified__", mh, true), | |
966 __myhandle__ (mh), | |
967 parent ("parent", mh, p), children () | |
968 { } | |
639 | 969 |
640 virtual ~base_properties (void) { } | 970 virtual ~base_properties (void) { } |
641 | 971 |
642 virtual std::string graphics_object_name (void) const { return "unknonwn"; } | 972 virtual std::string graphics_object_name (void) const { return "unknonwn"; } |
643 | 973 |
648 // Look through DEFAULTS for properties with given CLASS_NAME, and | 978 // Look through DEFAULTS for properties with given CLASS_NAME, and |
649 // apply them to the current object with set (virtual method). | 979 // apply them to the current object with set (virtual method). |
650 | 980 |
651 void set_from_list (base_graphics_object& obj, property_list& defaults); | 981 void set_from_list (base_graphics_object& obj, property_list& defaults); |
652 | 982 |
653 virtual void set (const caseless_str&, const octave_value&) { } | 983 void insert_property (const std::string& name, property p) |
654 | 984 { |
655 std::string get_tag (void) const { return tag; } | 985 p.set_name (name); |
656 | 986 p.set_parent (__myhandle__); |
657 graphics_handle get_parent (void) const { return parent; } | 987 all_props[name] = p; |
658 | 988 } |
659 std::string get_type (void) const { return type; } | 989 |
660 | 990 virtual void set (const caseless_str&, const octave_value&); |
661 bool is_modified (void) const { return __modified__; } | 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 (); } | |
662 | 1005 |
663 graphics_handle get___myhandle__ (void) const { return __myhandle__; } | 1006 graphics_handle get___myhandle__ (void) const { return __myhandle__; } |
664 | 1007 |
665 void remove_child (const graphics_handle& h); | 1008 void remove_child (const graphics_handle& h); |
666 | 1009 |
669 octave_idx_type n = children.numel (); | 1012 octave_idx_type n = children.numel (); |
670 children.resize (1, n+1); | 1013 children.resize (1, n+1); |
671 children(n) = h.value (); | 1014 children(n) = h.value (); |
672 } | 1015 } |
673 | 1016 |
674 void set_tag (const octave_value& val); | 1017 void set_tag (const octave_value& val) { tag = val; } |
675 | 1018 |
676 void set_parent (const octave_value& val); | 1019 void set_parent (const octave_value& val); |
677 | 1020 |
678 void reparent (const graphics_handle& new_parent) { parent = new_parent; } | 1021 void reparent (const graphics_handle& new_parent) { parent = new_parent; } |
679 | 1022 |
688 | 1031 |
689 // FIXME -- these functions should be generated automatically by the | 1032 // FIXME -- these functions should be generated automatically by the |
690 // genprops.awk script. | 1033 // genprops.awk script. |
691 // | 1034 // |
692 // EMIT_BASE_PROPERTIES_GET_FUNCTIONS | 1035 // EMIT_BASE_PROPERTIES_GET_FUNCTIONS |
693 virtual data_property get_xdata (void) const | 1036 virtual data_property get_xdata_property (void) const |
694 { | 1037 { |
695 error ("get: invalid property \"xdata\""); | 1038 error ("get: invalid property \"xdata\""); |
696 return data_property (); | 1039 return data_property (); |
697 } | 1040 } |
698 | 1041 |
699 virtual data_property get_ydata (void) const | 1042 virtual data_property get_ydata_property (void) const |
700 { | 1043 { |
701 error ("get: invalid property \"ydata\""); | 1044 error ("get: invalid property \"ydata\""); |
702 return data_property (); | 1045 return data_property (); |
703 } | 1046 } |
704 | 1047 |
705 virtual data_property get_zdata (void) const | 1048 virtual data_property get_zdata_property (void) const |
706 { | 1049 { |
707 error ("get: invalid property \"zdata\""); | 1050 error ("get: invalid property \"zdata\""); |
708 return data_property (); | 1051 return data_property (); |
709 } | 1052 } |
710 | 1053 |
711 virtual data_property get_ldata (void) const | 1054 virtual data_property get_ldata_property (void) const |
712 { | 1055 { |
713 error ("get: invalid property \"ldata\""); | 1056 error ("get: invalid property \"ldata\""); |
714 return data_property (); | 1057 return data_property (); |
715 } | 1058 } |
716 | 1059 |
717 virtual data_property get_udata (void) const | 1060 virtual data_property get_udata_property (void) const |
718 { | 1061 { |
719 error ("get: invalid property \"udata\""); | 1062 error ("get: invalid property \"udata\""); |
720 return data_property (); | 1063 return data_property (); |
721 } | 1064 } |
722 | 1065 |
723 virtual data_property get_xldata (void) const | 1066 virtual data_property get_xldata_property (void) const |
724 { | 1067 { |
725 error ("get: invalid property \"xldata\""); | 1068 error ("get: invalid property \"xldata\""); |
726 return data_property (); | 1069 return data_property (); |
727 } | 1070 } |
728 | 1071 |
729 virtual data_property get_xudata (void) const | 1072 virtual data_property get_xudata_property (void) const |
730 { | 1073 { |
731 error ("get: invalid property \"xudata\""); | 1074 error ("get: invalid property \"xudata\""); |
732 return data_property (); | 1075 return data_property (); |
733 } | 1076 } |
734 | 1077 |
735 virtual data_property get_cdata (void) const | 1078 virtual data_property get_cdata_property (void) const |
736 { | 1079 { |
737 error ("get: invalid property \"cdata\""); | 1080 error ("get: invalid property \"cdata\""); |
738 return data_property (); | 1081 return data_property (); |
739 } | 1082 } |
740 | 1083 |
741 protected: | 1084 protected: |
742 std::string tag; | 1085 string_property tag; |
743 std::string type; | 1086 string_property type; |
744 bool __modified__; | 1087 bool_property __modified__; |
745 graphics_handle __myhandle__; | 1088 graphics_handle __myhandle__; |
746 graphics_handle parent; | 1089 handle_property parent; |
1090 // FIXME: use a property class for children | |
747 Matrix children; | 1091 Matrix children; |
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) { } | |
748 }; | 1101 }; |
749 | 1102 |
750 class base_graphics_object | 1103 class base_graphics_object |
751 { | 1104 { |
752 public: | 1105 public: |
979 | 1332 |
980 // FIXME -- these functions should be generated automatically by the | 1333 // FIXME -- these functions should be generated automatically by the |
981 // genprops.awk script. | 1334 // genprops.awk script. |
982 // | 1335 // |
983 // EMIT_GRAPHICS_OBJECT_GET_FUNCTIONS | 1336 // EMIT_GRAPHICS_OBJECT_GET_FUNCTIONS |
984 data_property get_xdata (void) const | 1337 data_property get_xdata_property (void) const |
985 { | 1338 { |
986 const base_properties& props = get_properties (); | 1339 const base_properties& props = get_properties (); |
987 return props.get_xdata (); | 1340 return props.get_xdata_property (); |
988 } | 1341 } |
989 | 1342 |
990 data_property get_ydata (void) const | 1343 data_property get_ydata_property (void) const |
991 { | 1344 { |
992 const base_properties& props = get_properties (); | 1345 const base_properties& props = get_properties (); |
993 return props.get_ydata (); | 1346 return props.get_ydata_property (); |
994 } | 1347 } |
995 | 1348 |
996 data_property get_zdata (void) const | 1349 data_property get_zdata_property (void) const |
997 { | 1350 { |
998 const base_properties& props = get_properties (); | 1351 const base_properties& props = get_properties (); |
999 return props.get_zdata (); | 1352 return props.get_zdata_property (); |
1000 } | 1353 } |
1001 | 1354 |
1002 data_property get_ldata (void) const | 1355 data_property get_ldata_property (void) const |
1003 { | 1356 { |
1004 const base_properties& props = get_properties (); | 1357 const base_properties& props = get_properties (); |
1005 return props.get_ldata (); | 1358 return props.get_ldata_property (); |
1006 } | 1359 } |
1007 | 1360 |
1008 data_property get_udata (void) const | 1361 data_property get_udata_property (void) const |
1009 { | 1362 { |
1010 const base_properties& props = get_properties (); | 1363 const base_properties& props = get_properties (); |
1011 return props.get_udata (); | 1364 return props.get_udata_property (); |
1012 } | 1365 } |
1013 | 1366 |
1014 data_property get_xldata (void) const | 1367 data_property get_xldata_property (void) const |
1015 { | 1368 { |
1016 const base_properties& props = get_properties (); | 1369 const base_properties& props = get_properties (); |
1017 return props.get_xldata (); | 1370 return props.get_xldata_property (); |
1018 } | 1371 } |
1019 | 1372 |
1020 data_property get_xudata (void) const | 1373 data_property get_xudata_property (void) const |
1021 { | 1374 { |
1022 const base_properties& props = get_properties (); | 1375 const base_properties& props = get_properties (); |
1023 return props.get_xudata (); | 1376 return props.get_xudata_property (); |
1024 } | 1377 } |
1025 | 1378 |
1026 data_property get_cdata (void) const | 1379 data_property get_cdata_property (void) const |
1027 { | 1380 { |
1028 const base_properties& props = get_properties (); | 1381 const base_properties& props = get_properties (); |
1029 return props.get_cdata (); | 1382 return props.get_cdata_property (); |
1030 } | 1383 } |
1031 | 1384 |
1032 private: | 1385 private: |
1033 base_graphics_object *rep; | 1386 base_graphics_object *rep; |
1034 }; | 1387 }; |
1039 { | 1392 { |
1040 public: | 1393 public: |
1041 class properties : public base_properties | 1394 class properties : public base_properties |
1042 { | 1395 { |
1043 public: | 1396 public: |
1044 properties (void) | |
1045 : base_properties ("root figure", 0, graphics_handle ()), | |
1046 currentfigure (), | |
1047 visible ("on") | |
1048 { } | |
1049 | |
1050 ~properties (void) { } | |
1051 | |
1052 void set (const caseless_str& name, const octave_value& val); | |
1053 | |
1054 octave_value get (void) const; | |
1055 | |
1056 octave_value get (const caseless_str& name) const; | |
1057 | |
1058 std::string graphics_object_name (void) const { return go_name; } | |
1059 | |
1060 // See the genprops.awk script for an explanation of the | 1397 // See the genprops.awk script for an explanation of the |
1061 // properties declarations. | 1398 // properties declarations. |
1062 | 1399 |
1063 BEGIN_PROPERTIES | 1400 BEGIN_PROPERTIES(root_figure) |
1064 graphics_handle currentfigure S | 1401 handle_property currentfigure S , graphics_handle () |
1065 octave_value visible | 1402 bool_property visible , "on" |
1066 END_PROPERTIES | 1403 END_PROPERTIES |
1067 | |
1068 static std::string go_name; | |
1069 }; | 1404 }; |
1070 | 1405 |
1071 private: | 1406 private: |
1072 properties xproperties; | 1407 properties xproperties; |
1073 | 1408 |
1074 public: | 1409 public: |
1075 | 1410 |
1076 root_figure (void) : xproperties (), default_properties () { } | 1411 root_figure (void) : xproperties (0, graphics_handle ()), default_properties () { } |
1077 | 1412 |
1078 ~root_figure (void) { xproperties.delete_children (); } | 1413 ~root_figure (void) { xproperties.delete_children (); } |
1079 | 1414 |
1080 std::string type (void) const { return xproperties.graphics_object_name (); } | 1415 std::string type (void) const { return xproperties.graphics_object_name (); } |
1081 | 1416 |
1189 { | 1524 { |
1190 public: | 1525 public: |
1191 class properties : public base_properties | 1526 class properties : public base_properties |
1192 { | 1527 { |
1193 public: | 1528 public: |
1194 properties (const graphics_handle& mh, const graphics_handle& p); | |
1195 | |
1196 ~properties (void) { } | |
1197 | |
1198 void set (const caseless_str& name, const octave_value& val); | |
1199 | |
1200 octave_value get (void) const; | |
1201 | |
1202 octave_value get (const caseless_str& name) const; | |
1203 | |
1204 void close (void); | 1529 void close (void); |
1205 | |
1206 std::string graphics_object_name (void) const { return go_name; } | |
1207 | |
1208 static property_list::pval_map_type factory_defaults (void); | |
1209 | 1530 |
1210 // See the genprops.awk script for an explanation of the | 1531 // See the genprops.awk script for an explanation of the |
1211 // properties declarations. | 1532 // properties declarations. |
1212 | 1533 |
1213 BEGIN_PROPERTIES | 1534 BEGIN_PROPERTIES(figure) |
1214 octave_value __plot_stream__ | 1535 any_property __plot_stream__ , Matrix () |
1215 octave_value __enhanced__ | 1536 bool_property __enhanced__ , "on" |
1216 octave_value nextplot | 1537 radio_property nextplot , "add|replace_children|{replace}" |
1217 octave_value closerequestfcn | 1538 callback_property closerequestfcn , "closereq" |
1218 graphics_handle currentaxes S | 1539 handle_property currentaxes S , graphics_handle () |
1219 colormap_property colormap | 1540 array_property colormap , jet_colormap () |
1220 octave_value visible S | 1541 bool_property visible S , "on" |
1221 octave_value paperorientation | 1542 radio_property paperorientation , "{portrait}|landscape" |
1222 color_property color | 1543 color_property color , color_values (1, 1, 1) |
1223 END_PROPERTIES | 1544 END_PROPERTIES |
1224 | 1545 |
1225 static std::string go_name; | 1546 protected: |
1547 void init (void) | |
1548 { | |
1549 colormap.add_constraint (dim_vector (-1, 3)); | |
1550 } | |
1551 | |
1226 }; | 1552 }; |
1227 | 1553 |
1228 private: | 1554 private: |
1229 properties xproperties; | 1555 properties xproperties; |
1230 | 1556 |
1325 { | 1651 { |
1326 public: | 1652 public: |
1327 class properties : public base_properties | 1653 class properties : public base_properties |
1328 { | 1654 { |
1329 public: | 1655 public: |
1330 properties (const graphics_handle& mh, const graphics_handle& p); | |
1331 | |
1332 ~properties (void) { } | |
1333 | |
1334 void set (const caseless_str& name, const octave_value& val); | |
1335 | |
1336 void set_defaults (base_graphics_object& obj, const std::string& mode); | 1656 void set_defaults (base_graphics_object& obj, const std::string& mode); |
1337 | 1657 |
1338 octave_value get (void) const; | |
1339 | |
1340 octave_value get (const caseless_str& name) const; | |
1341 | |
1342 void remove_child (const graphics_handle& h); | 1658 void remove_child (const graphics_handle& h); |
1343 | 1659 |
1344 void delete_children (void); | 1660 void delete_children (void); |
1345 | |
1346 std::string graphics_object_name (void) const { return go_name; } | |
1347 | |
1348 static property_list::pval_map_type factory_defaults (void); | |
1349 | 1661 |
1350 // See the genprops.awk script for an explanation of the | 1662 // See the genprops.awk script for an explanation of the |
1351 // properties declarations. | 1663 // properties declarations. |
1352 | 1664 |
1353 BEGIN_PROPERTIES | 1665 BEGIN_PROPERTIES(axes) |
1354 octave_value position | 1666 array_property position , Matrix () |
1355 mutable graphics_handle title GSO | 1667 mutable handle_property title GSO , graphics_handle () |
1356 octave_value box | 1668 bool_property box , "on" |
1357 octave_value key | 1669 bool_property key , "off" |
1358 octave_value keybox | 1670 bool_property keybox , "off" |
1359 octave_value keypos | 1671 double_property keypos , 1 |
1360 octave_value colororder | 1672 array_property colororder , default_colororder () |
1361 octave_value dataaspectratio m | 1673 array_property dataaspectratio m , Matrix (1, 3, 1.0) |
1362 octave_value dataaspectratiomode | 1674 radio_property dataaspectratiomode , "{auto}|manual" |
1363 radio_property layer a | 1675 radio_property layer a , "{bottom}|top" |
1364 octave_value xlim m | 1676 array_property xlim m , default_lim () |
1365 octave_value ylim m | 1677 array_property ylim m , default_lim () |
1366 octave_value zlim m | 1678 array_property zlim m , default_lim () |
1367 octave_value clim m | 1679 array_property clim m , default_lim () |
1368 radio_property xlimmode al | 1680 radio_property xlimmode al , "{auto}|manual" |
1369 radio_property ylimmode al | 1681 radio_property ylimmode al , "{auto}|manual" |
1370 radio_property zlimmode al | 1682 radio_property zlimmode al , "{auto}|manual" |
1371 radio_property climmode al | 1683 radio_property climmode al , "{auto}|manual" |
1372 mutable graphics_handle xlabel GSO | 1684 mutable handle_property xlabel GSO , graphics_handle () |
1373 mutable graphics_handle ylabel GSO | 1685 mutable handle_property ylabel GSO , graphics_handle () |
1374 mutable graphics_handle zlabel GSO | 1686 mutable handle_property zlabel GSO , graphics_handle () |
1375 octave_value xgrid | 1687 bool_property xgrid , "off" |
1376 octave_value ygrid | 1688 bool_property ygrid , "off" |
1377 octave_value zgrid | 1689 bool_property zgrid , "off" |
1378 octave_value xminorgrid | 1690 bool_property xminorgrid , "off" |
1379 octave_value yminorgrid | 1691 bool_property yminorgrid , "off" |
1380 octave_value zminorgrid | 1692 bool_property zminorgrid , "off" |
1381 octave_value xtick m | 1693 array_property xtick m , Matrix () |
1382 octave_value ytick m | 1694 array_property ytick m , Matrix () |
1383 octave_value ztick m | 1695 array_property ztick m , Matrix () |
1384 octave_value xtickmode | 1696 radio_property xtickmode , "{auto}|manual" |
1385 octave_value ytickmode | 1697 radio_property ytickmode , "{auto}|manual" |
1386 octave_value ztickmode | 1698 radio_property ztickmode , "{auto}|manual" |
1387 octave_value xticklabel m | 1699 any_property xticklabel m , "" |
1388 octave_value yticklabel m | 1700 any_property yticklabel m , "" |
1389 octave_value zticklabel m | 1701 any_property zticklabel m , "" |
1390 octave_value xticklabelmode | 1702 radio_property xticklabelmode , "{auto}|manual" |
1391 octave_value yticklabelmode | 1703 radio_property yticklabelmode , "{auto}|manual" |
1392 octave_value zticklabelmode | 1704 radio_property zticklabelmode , "{auto}|manual" |
1393 color_property color a | 1705 color_property color a , color_property (color_values (1, 1, 1), radio_values ("none")) |
1394 color_property xcolor | 1706 color_property xcolor , color_values (0, 0, 0) |
1395 color_property ycolor | 1707 color_property ycolor , color_values (0, 0, 0) |
1396 color_property zcolor | 1708 color_property zcolor , color_values (0, 0, 0) |
1397 radio_property xscale al | 1709 radio_property xscale al , "{linear}|log" |
1398 radio_property yscale al | 1710 radio_property yscale al , "{linear}|log" |
1399 radio_property zscale al | 1711 radio_property zscale al , "{linear}|log" |
1400 octave_value xdir | 1712 radio_property xdir , "{normal}|reverse" |
1401 octave_value ydir | 1713 radio_property ydir , "{normal}|reverse" |
1402 octave_value zdir | 1714 radio_property zdir , "{normal}|reverse" |
1403 octave_value xaxislocation | 1715 radio_property yaxislocation , "{left}|right" |
1404 octave_value yaxislocation | 1716 radio_property xaxislocation , "{bottom}|top" |
1405 octave_value view | 1717 array_property view , Matrix () |
1406 octave_value visible | 1718 bool_property visible , "on" |
1407 octave_value nextplot | 1719 radio_property nextplot , "add|replace_children|{replace}" |
1408 octave_value outerposition | 1720 array_property outerposition , Matrix () |
1409 radio_property activepositionproperty a | 1721 radio_property activepositionproperty a , "{outerposition}|position" |
1410 radio_property __colorbar__ a | 1722 radio_property __colorbar__ a , "{none}|north|south|east|west|northoutside|southoutside|eastoutside|westoutside" |
1411 END_PROPERTIES | 1723 END_PROPERTIES |
1412 | 1724 |
1413 static std::string go_name; | 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 } | |
1414 }; | 1745 }; |
1415 | 1746 |
1416 private: | 1747 private: |
1417 properties xproperties; | 1748 properties xproperties; |
1418 | 1749 |
1517 { | 1848 { |
1518 public: | 1849 public: |
1519 class properties : public base_properties | 1850 class properties : public base_properties |
1520 { | 1851 { |
1521 public: | 1852 public: |
1522 properties (const graphics_handle& mh, const graphics_handle& p); | |
1523 | |
1524 ~properties (void) { } | |
1525 | |
1526 void set (const caseless_str& name, const octave_value& val); | |
1527 | |
1528 octave_value get (void) const; | |
1529 | |
1530 octave_value get (const caseless_str& name) const; | |
1531 | |
1532 std::string graphics_object_name (void) const { return go_name; } | |
1533 | |
1534 static property_list::pval_map_type factory_defaults (void); | |
1535 | |
1536 // See the genprops.awk script for an explanation of the | 1853 // See the genprops.awk script for an explanation of the |
1537 // properties declarations. | 1854 // properties declarations. |
1538 | 1855 |
1539 BEGIN_PROPERTIES | 1856 BEGIN_PROPERTIES(line) |
1540 data_property xdata l | 1857 data_property xdata l , default_data () |
1541 data_property ydata l | 1858 data_property ydata l , default_data () |
1542 data_property zdata l | 1859 data_property zdata l , Matrix () |
1543 data_property ldata l | 1860 data_property ldata l , Matrix () |
1544 data_property udata l | 1861 data_property udata l , Matrix () |
1545 data_property xldata l | 1862 data_property xldata l , Matrix () |
1546 data_property xudata l | 1863 data_property xudata l , Matrix () |
1547 color_property color | 1864 color_property color , color_values (0, 0, 0) |
1548 octave_value linestyle | 1865 radio_property linestyle , "{-}|--|:|-.|none" |
1549 octave_value linewidth | 1866 double_property linewidth , 0.5 |
1550 octave_value marker | 1867 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
1551 octave_value markeredgecolor | 1868 color_property markeredgecolor , "{auto}|none" |
1552 octave_value markerfacecolor | 1869 color_property markerfacecolor , "auto|{none}" |
1553 octave_value markersize | 1870 double_property markersize , 6 |
1554 octave_value keylabel | 1871 string_property keylabel , "" |
1555 radio_property interpreter a | 1872 radio_property interpreter a , "{tex}|none|latex" |
1556 END_PROPERTIES | 1873 END_PROPERTIES |
1557 | |
1558 static std::string go_name; | |
1559 }; | 1874 }; |
1560 | 1875 |
1561 private: | 1876 private: |
1562 properties xproperties; | 1877 properties xproperties; |
1563 | 1878 |
1624 { | 1939 { |
1625 public: | 1940 public: |
1626 class properties : public base_properties | 1941 class properties : public base_properties |
1627 { | 1942 { |
1628 public: | 1943 public: |
1629 properties (const graphics_handle& mh, const graphics_handle& p); | |
1630 | |
1631 ~properties (void) { } | |
1632 | |
1633 void set (const caseless_str& name, const octave_value& val); | |
1634 | |
1635 octave_value get (void) const; | |
1636 | |
1637 octave_value get (const caseless_str& name) const; | |
1638 | |
1639 std::string graphics_object_name (void) const { return go_name; } | |
1640 | |
1641 static property_list::pval_map_type factory_defaults (void); | |
1642 | |
1643 // See the genprops.awk script for an explanation of the | 1944 // See the genprops.awk script for an explanation of the |
1644 // properties declarations. | 1945 // properties declarations. |
1645 | 1946 |
1646 BEGIN_PROPERTIES | 1947 BEGIN_PROPERTIES(text) |
1647 octave_value string | 1948 string_property string , "" |
1648 octave_value units | 1949 radio_property units , "{data}|pixels|normalized|inches|centimeters|points" |
1649 octave_value position | 1950 array_property position , Matrix (1, 3, 0.0) |
1650 octave_value rotation | 1951 double_property rotation , 0 |
1651 octave_value horizontalalignment | 1952 radio_property horizontalalignment , "{left}|center|right" |
1652 color_property color | 1953 color_property color , color_values (0, 0, 0) |
1653 octave_value fontname | 1954 string_property fontname , "Helvetica" |
1654 octave_value fontsize | 1955 double_property fontsize , 10 |
1655 radio_property fontangle a | 1956 radio_property fontangle a , "{normal}|italic|oblique" |
1656 radio_property fontweight a | 1957 radio_property fontweight a , "light|{normal}|demi|bold" |
1657 radio_property interpreter a | 1958 radio_property interpreter a , "{tex}|none|latex" |
1658 END_PROPERTIES | 1959 END_PROPERTIES |
1659 | 1960 |
1660 static std::string go_name; | 1961 protected: |
1962 void init (void) | |
1963 { | |
1964 position.add_constraint (dim_vector (1, 3)); | |
1965 } | |
1661 }; | 1966 }; |
1662 | 1967 |
1663 private: | 1968 private: |
1664 properties xproperties; | 1969 properties xproperties; |
1665 | 1970 |
1726 { | 2031 { |
1727 public: | 2032 public: |
1728 class properties : public base_properties | 2033 class properties : public base_properties |
1729 { | 2034 { |
1730 public: | 2035 public: |
1731 properties (const graphics_handle& mh, const graphics_handle& p); | |
1732 | |
1733 ~properties (void) { } | |
1734 | |
1735 void set (const caseless_str& name, const octave_value& val); | |
1736 | |
1737 octave_value get (void) const; | |
1738 | |
1739 octave_value get (const caseless_str& name) const; | |
1740 | |
1741 std::string graphics_object_name (void) const { return go_name; } | |
1742 | |
1743 static property_list::pval_map_type factory_defaults (void); | |
1744 | |
1745 // See the genprops.awk script for an explanation of the | 2036 // See the genprops.awk script for an explanation of the |
1746 // properties declarations. | 2037 // properties declarations. |
1747 | 2038 |
1748 BEGIN_PROPERTIES | 2039 BEGIN_PROPERTIES(image) |
1749 data_property xdata l | 2040 data_property xdata l , Matrix () |
1750 data_property ydata l | 2041 data_property ydata l , Matrix () |
1751 data_property cdata l | 2042 data_property cdata l , Matrix () |
1752 END_PROPERTIES | 2043 END_PROPERTIES |
1753 | 2044 |
1754 static std::string go_name; | 2045 protected: |
2046 void init (void) | |
2047 { | |
2048 } | |
1755 }; | 2049 }; |
1756 | 2050 |
1757 private: | 2051 private: |
1758 properties xproperties; | 2052 properties xproperties; |
1759 | 2053 |
1820 { | 2114 { |
1821 public: | 2115 public: |
1822 class properties : public base_properties | 2116 class properties : public base_properties |
1823 { | 2117 { |
1824 public: | 2118 public: |
1825 properties (const graphics_handle& mh, const graphics_handle& p); | |
1826 | |
1827 ~properties (void) { } | |
1828 | |
1829 void set (const caseless_str& name, const octave_value& val); | |
1830 | |
1831 octave_value get (void) const; | |
1832 | |
1833 octave_value get (const caseless_str& name) const; | |
1834 | |
1835 std::string graphics_object_name (void) const { return go_name; } | |
1836 | |
1837 static property_list::pval_map_type factory_defaults (void); | |
1838 | |
1839 // See the genprops.awk script for an explanation of the | 2119 // See the genprops.awk script for an explanation of the |
1840 // properties declarations. | 2120 // properties declarations. |
1841 | 2121 |
1842 BEGIN_PROPERTIES | 2122 BEGIN_PROPERTIES(patch) |
1843 data_property xdata l | 2123 data_property xdata l , Matrix () |
1844 data_property ydata l | 2124 data_property ydata l , Matrix () |
1845 data_property zdata l | 2125 data_property zdata l , Matrix () |
1846 data_property cdata l | 2126 data_property cdata l , Matrix () |
1847 octave_value faces | 2127 array_property faces , Matrix () |
1848 octave_value vertices | 2128 array_property vertices , Matrix () |
1849 color_property facecolor a | 2129 color_property facecolor a , "{flat}|none|interp" |
1850 octave_value facealpha | 2130 double_property facealpha , 1.0 |
1851 color_property edgecolor a | 2131 color_property edgecolor a , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
1852 octave_value linestyle | 2132 radio_property linestyle , "{-}|--|:|-.|none" |
1853 octave_value linewidth | 2133 double_property linewidth , 0.5 |
1854 octave_value marker | 2134 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
1855 octave_value markeredgecolor | 2135 color_property markeredgecolor , "{auto}|none" |
1856 octave_value markerfacecolor | 2136 color_property markerfacecolor , "auto|{none}" |
1857 octave_value markersize | 2137 double_property markersize , 6 |
1858 octave_value keylabel | 2138 string_property keylabel , "" |
1859 radio_property interpreter a | 2139 radio_property interpreter a , "{tex}|none|latex" |
1860 END_PROPERTIES | 2140 END_PROPERTIES |
1861 | 2141 |
1862 static std::string go_name; | 2142 protected: |
2143 void init (void) | |
2144 { | |
2145 vertices.add_constraint (dim_vector (-1, 2)); | |
2146 vertices.add_constraint (dim_vector (-1, 3)); | |
2147 } | |
1863 }; | 2148 }; |
1864 | 2149 |
1865 private: | 2150 private: |
1866 properties xproperties; | 2151 properties xproperties; |
1867 | 2152 |
1928 { | 2213 { |
1929 public: | 2214 public: |
1930 class properties : public base_properties | 2215 class properties : public base_properties |
1931 { | 2216 { |
1932 public: | 2217 public: |
1933 properties (const graphics_handle& mh, const graphics_handle& p); | |
1934 | |
1935 ~properties (void) { } | |
1936 | |
1937 void set (const caseless_str& name, const octave_value& val); | |
1938 | |
1939 octave_value get (void) const; | |
1940 | |
1941 octave_value get (const caseless_str& name) const; | |
1942 | |
1943 std::string graphics_object_name (void) const { return go_name; } | |
1944 | |
1945 static property_list::pval_map_type factory_defaults (void); | |
1946 | |
1947 // See the genprops.awk script for an explanation of the | 2218 // See the genprops.awk script for an explanation of the |
1948 // properties declarations. | 2219 // properties declarations. |
1949 | 2220 |
1950 BEGIN_PROPERTIES | 2221 BEGIN_PROPERTIES(surface) |
1951 data_property xdata l | 2222 data_property xdata l , Matrix () |
1952 data_property ydata l | 2223 data_property ydata l , Matrix () |
1953 data_property zdata l | 2224 data_property zdata l , Matrix () |
1954 data_property cdata l | 2225 data_property cdata l , Matrix () |
1955 color_property facecolor a | 2226 color_property facecolor a , "{flat}|none|interp" |
1956 octave_value facealpha | 2227 double_property facealpha , 1.0 |
1957 color_property edgecolor a | 2228 color_property edgecolor a , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) |
1958 octave_value linestyle | 2229 radio_property linestyle , "{-}|--|:|-.|none" |
1959 octave_value linewidth | 2230 double_property linewidth , 0.5 |
1960 octave_value marker | 2231 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" |
1961 octave_value markeredgecolor | 2232 color_property markeredgecolor , "{auto}|none" |
1962 octave_value markerfacecolor | 2233 color_property markerfacecolor , "auto|{none}" |
1963 octave_value markersize | 2234 double_property markersize , 6 |
1964 octave_value keylabel | 2235 string_property keylabel , "" |
1965 radio_property interpreter a | 2236 radio_property interpreter a , "{tex}|none|latex" |
1966 END_PROPERTIES | 2237 END_PROPERTIES |
1967 | 2238 |
1968 static std::string go_name; | 2239 protected: |
2240 void init (void) | |
2241 { | |
2242 } | |
1969 }; | 2243 }; |
1970 | 2244 |
1971 private: | 2245 private: |
1972 properties xproperties; | 2246 properties xproperties; |
1973 | 2247 |
2151 | 2425 |
2152 void do_free (const graphics_handle& h); | 2426 void do_free (const graphics_handle& h); |
2153 | 2427 |
2154 graphics_handle do_lookup (double val) | 2428 graphics_handle do_lookup (double val) |
2155 { | 2429 { |
2156 iterator p = handle_map.find (val); | 2430 iterator p = (xisnan (val) ? handle_map.end () : handle_map.find (val)); |
2157 | 2431 |
2158 return (p != handle_map.end ()) ? p->first : graphics_handle (); | 2432 return (p != handle_map.end ()) ? p->first : graphics_handle (); |
2159 } | 2433 } |
2160 | 2434 |
2161 graphics_object do_get_object (const graphics_handle& h) | 2435 graphics_object do_get_object (const graphics_handle& h) |