Mercurial > hg > octave-thorsten
comparison src/graphics.h.in @ 11163:31e7e9f94850
Backed out changeset a981e2f56ec1
author | David Bateman <dbateman@free.fr> |
---|---|
date | Fri, 29 Oct 2010 00:28:01 +0200 |
parents | a981e2f56ec1 |
children | 51ac3a08e53c |
comparison
equal
deleted
inserted
replaced
11162:a981e2f56ec1 | 11163:31e7e9f94850 |
---|---|
1363 } | 1363 } |
1364 | 1364 |
1365 private: | 1365 private: |
1366 octave_value data; | 1366 octave_value data; |
1367 }; | 1367 }; |
1368 | |
1369 // --------------------------------------------------------------------- | |
1370 | |
1371 class children_property : public base_property | |
1372 { | |
1373 public: | |
1374 children_property (void) | |
1375 : base_property ("", graphics_handle ()) | |
1376 { | |
1377 do_init_children (Matrix ()); | |
1378 } | |
1379 | |
1380 children_property (const std::string& nm, const graphics_handle& h, | |
1381 const Matrix &val) | |
1382 : base_property (nm, h) | |
1383 { | |
1384 do_init_children (val); | |
1385 } | |
1386 | |
1387 children_property (const children_property& p) | |
1388 : base_property (p) | |
1389 { | |
1390 do_init_children (p.children_list); | |
1391 } | |
1392 | |
1393 children_property& operator = (const octave_value& val) | |
1394 { | |
1395 set (val); | |
1396 return *this; | |
1397 } | |
1398 | |
1399 base_property* clone (void) const { return new children_property (*this); } | |
1400 | |
1401 bool remove_child (const double &val) | |
1402 { | |
1403 return do_remove_child (val); | |
1404 } | |
1405 | |
1406 void adopt (const double &val) | |
1407 { | |
1408 do_adopt_child (val); | |
1409 } | |
1410 | |
1411 Matrix get_children (void) const | |
1412 { | |
1413 return do_get_children (false); | |
1414 } | |
1415 | |
1416 Matrix get_hidden (void) const | |
1417 { | |
1418 return do_get_children (true); | |
1419 } | |
1420 | |
1421 Matrix get_all (void) const | |
1422 { | |
1423 return do_get_all_children (); | |
1424 } | |
1425 | |
1426 octave_value get (void) const | |
1427 { | |
1428 return octave_value (get_children ()); | |
1429 } | |
1430 | |
1431 void delete_children (bool clear = false) | |
1432 { | |
1433 do_delete_children (clear); | |
1434 } | |
1435 | |
1436 private: | |
1437 typedef std::list<double>::iterator children_list_iterator; | |
1438 typedef std::list<double>::const_iterator const_children_list_iterator; | |
1439 std::list<double> children_list; | |
1440 | |
1441 protected: | |
1442 bool do_set (const octave_value& val) | |
1443 { | |
1444 const Matrix new_kids = val.matrix_value (); | |
1445 | |
1446 octave_idx_type nel = new_kids.numel (); | |
1447 | |
1448 const Matrix new_kids_column = new_kids.reshape (dim_vector (nel, 1)); | |
1449 | |
1450 bool is_ok = true; | |
1451 | |
1452 if (! error_state) | |
1453 { | |
1454 const Matrix visible_kids = do_get_children (false); | |
1455 | |
1456 if (visible_kids.numel () == new_kids.numel ()) | |
1457 { | |
1458 Matrix t1 = visible_kids.sort (); | |
1459 Matrix t2 = new_kids_column.sort (); | |
1460 | |
1461 if (t1 != t2) | |
1462 is_ok = false; | |
1463 } | |
1464 else | |
1465 is_ok = false; | |
1466 | |
1467 if (! is_ok) | |
1468 error ("set: new children must be a permutation of existing children"); | |
1469 } | |
1470 else | |
1471 { | |
1472 is_ok = false; | |
1473 error ("set: expecting children to be array of graphics handles"); | |
1474 } | |
1475 | |
1476 if (is_ok) | |
1477 { | |
1478 children_list.clear (); | |
1479 do_init_children (new_kids_column.stack (get_hidden ())); | |
1480 } | |
1481 | |
1482 return is_ok; | |
1483 } | |
1484 | |
1485 private: | |
1486 void do_init_children (const Matrix &val) | |
1487 { | |
1488 children_list.clear (); | |
1489 for (octave_idx_type i = 0; i < val.numel (); i++) | |
1490 children_list.push_front (val.xelem (i)); | |
1491 } | |
1492 | |
1493 void do_init_children (const std::list<double> &val) | |
1494 { | |
1495 children_list.clear (); | |
1496 for (const_children_list_iterator p = val.begin (); p != val.end (); p++) | |
1497 children_list.push_front (*p); | |
1498 } | |
1499 | |
1500 Matrix do_get_children (bool return_hidden) const; | |
1501 | |
1502 Matrix do_get_all_children (void) const | |
1503 { | |
1504 Matrix retval (children_list.size (), 1); | |
1505 octave_idx_type i = 0; | |
1506 | |
1507 for (const_children_list_iterator p = children_list.begin (); | |
1508 p != children_list.end (); p++) | |
1509 retval(i++) = *p; | |
1510 return retval; | |
1511 } | |
1512 | |
1513 bool do_remove_child (double child) | |
1514 { | |
1515 for (children_list_iterator p = children_list.begin (); | |
1516 p != children_list.end (); p++) | |
1517 { | |
1518 if (*p == child) | |
1519 { | |
1520 children_list.erase (p); | |
1521 return true; | |
1522 } | |
1523 } | |
1524 return false; | |
1525 } | |
1526 | |
1527 void do_adopt_child (const double &val) | |
1528 { | |
1529 children_list.push_front (val); | |
1530 } | |
1531 | |
1532 void do_delete_children (bool clear); | |
1533 }; | |
1534 | |
1535 | |
1536 | 1368 |
1537 // --------------------------------------------------------------------- | 1369 // --------------------------------------------------------------------- |
1538 | 1370 |
1539 class callback_property : public base_property | 1371 class callback_property : public base_property |
1540 { | 1372 { |
2014 return false; | 1846 return false; |
2015 } | 1847 } |
2016 | 1848 |
2017 bool is_modified (void) const { return is___modified__ (); } | 1849 bool is_modified (void) const { return is___modified__ (); } |
2018 | 1850 |
2019 virtual void remove_child (const graphics_handle& h) | 1851 virtual void remove_child (const graphics_handle& h); |
2020 { | |
2021 if (children.remove_child (h.value ())) | |
2022 mark_modified (); | |
2023 } | |
2024 | 1852 |
2025 virtual void adopt (const graphics_handle& h) | 1853 virtual void adopt (const graphics_handle& h) |
2026 { | 1854 { |
2027 children.adopt (h.value ()); | 1855 octave_idx_type n = children.numel (); |
1856 children.resize (n+1, 1); | |
1857 for (octave_idx_type i = n; i > 0; i--) | |
1858 children(i) = children(i-1); | |
1859 children(0) = h.value (); | |
2028 mark_modified (); | 1860 mark_modified (); |
2029 } | 1861 } |
2030 | 1862 |
2031 virtual graphics_backend get_backend (void) const; | 1863 virtual graphics_backend get_backend (void) const; |
2032 | 1864 |
2043 | 1875 |
2044 void set_tag (const octave_value& val) { tag = val; } | 1876 void set_tag (const octave_value& val) { tag = val; } |
2045 | 1877 |
2046 void set_parent (const octave_value& val); | 1878 void set_parent (const octave_value& val); |
2047 | 1879 |
2048 Matrix get_children (void) const | 1880 Matrix get_all_children (void) const { return children; } |
2049 { | 1881 |
2050 return children.get_children (); | 1882 Matrix get_hidden_children (void) const; |
2051 } | 1883 |
2052 | 1884 void set_children (const octave_value& val); |
2053 Matrix get_all_children (void) const | |
2054 { | |
2055 return children.get_all (); | |
2056 } | |
2057 | |
2058 Matrix get_hidden_children (void) const | |
2059 { | |
2060 return children.get_hidden (); | |
2061 } | |
2062 | 1885 |
2063 void set_modified (const octave_value& val) { set___modified__ (val); } | 1886 void set_modified (const octave_value& val) { set___modified__ (val); } |
2064 | 1887 |
2065 void set___modified__ (const octave_value& val) { __modified__ = val; } | 1888 void set___modified__ (const octave_value& val) { __modified__ = val; } |
2066 | 1889 |
2069 // Update data limits for AXIS_TYPE (xdata, ydata, etc.) in the parent | 1892 // Update data limits for AXIS_TYPE (xdata, ydata, etc.) in the parent |
2070 // axes object. | 1893 // axes object. |
2071 | 1894 |
2072 virtual void update_axis_limits (const std::string& axis_type) const; | 1895 virtual void update_axis_limits (const std::string& axis_type) const; |
2073 | 1896 |
2074 virtual void update_axis_limits (const std::string& axis_type, | 1897 virtual void delete_children (void); |
2075 const graphics_handle& h) const; | 1898 |
2076 | |
2077 virtual void delete_children (bool clear = false) | |
2078 { | |
2079 children.delete_children (clear); | |
2080 } | |
2081 | |
2082 static property_list::pval_map_type factory_defaults (void); | 1899 static property_list::pval_map_type factory_defaults (void); |
2083 | 1900 |
2084 // FIXME -- these functions should be generated automatically by the | 1901 // FIXME -- these functions should be generated automatically by the |
2085 // genprops.awk script. | 1902 // genprops.awk script. |
2086 // | 1903 // |
2121 BEGIN_BASE_PROPERTIES | 1938 BEGIN_BASE_PROPERTIES |
2122 // properties common to all objects | 1939 // properties common to all objects |
2123 bool_property beingdeleted , "off" | 1940 bool_property beingdeleted , "off" |
2124 radio_property busyaction , "{queue}|cancel" | 1941 radio_property busyaction , "{queue}|cancel" |
2125 callback_property buttondownfcn , Matrix () | 1942 callback_property buttondownfcn , Matrix () |
2126 children_property children gf , Matrix () | 1943 // FIXME -- use a property class for children. |
1944 Matrix children Gfs , Matrix () | |
2127 bool_property clipping , "on" | 1945 bool_property clipping , "on" |
2128 callback_property createfcn , Matrix () | 1946 callback_property createfcn , Matrix () |
2129 callback_property deletefcn , Matrix () | 1947 callback_property deletefcn , Matrix () |
2130 radio_property handlevisibility , "{on}|callback|off" | 1948 radio_property handlevisibility , "{on}|callback|off" |
2131 bool_property hittest , "on" | 1949 bool_property hittest , "on" |
2163 protected: | 1981 protected: |
2164 void insert_static_property (const std::string& name, base_property& p) | 1982 void insert_static_property (const std::string& name, base_property& p) |
2165 { insert_property (name, property (&p, true)); } | 1983 { insert_property (name, property (&p, true)); } |
2166 | 1984 |
2167 virtual void init (void) { } | 1985 virtual void init (void) { } |
1986 | |
1987 private: | |
1988 Matrix get_children_internal (bool return_hidden) const; | |
2168 }; | 1989 }; |
2169 | 1990 |
2170 class OCTINTERP_API base_graphics_object | 1991 class OCTINTERP_API base_graphics_object |
2171 { | 1992 { |
2172 public: | 1993 public: |
2327 error ("base_graphics_object::get_properties: invalid graphics object"); | 2148 error ("base_graphics_object::get_properties: invalid graphics object"); |
2328 return properties; | 2149 return properties; |
2329 } | 2150 } |
2330 | 2151 |
2331 virtual void update_axis_limits (const std::string& axis_type); | 2152 virtual void update_axis_limits (const std::string& axis_type); |
2332 | |
2333 virtual void update_axis_limits (const std::string& axis_type, | |
2334 const graphics_handle& h); | |
2335 | 2153 |
2336 virtual bool valid_object (void) const { return false; } | 2154 virtual bool valid_object (void) const { return false; } |
2337 | 2155 |
2338 virtual std::string type (void) const | 2156 virtual std::string type (void) const |
2339 { | 2157 { |
2514 } | 2332 } |
2515 | 2333 |
2516 void update_axis_limits (const std::string& axis_type) | 2334 void update_axis_limits (const std::string& axis_type) |
2517 { | 2335 { |
2518 rep->update_axis_limits (axis_type); | 2336 rep->update_axis_limits (axis_type); |
2519 } | |
2520 | |
2521 void update_axis_limits (const std::string& axis_type, | |
2522 const graphics_handle& h) | |
2523 { | |
2524 rep->update_axis_limits (axis_type, h); | |
2525 } | 2337 } |
2526 | 2338 |
2527 bool valid_object (void) const { return rep->valid_object (); } | 2339 bool valid_object (void) const { return rep->valid_object (); } |
2528 | 2340 |
2529 std::string type (void) const { return rep->type (); } | 2341 std::string type (void) const { return rep->type (); } |
3377 | 3189 |
3378 const base_properties& get_properties (void) const { return xproperties; } | 3190 const base_properties& get_properties (void) const { return xproperties; } |
3379 | 3191 |
3380 void update_axis_limits (const std::string& axis_type); | 3192 void update_axis_limits (const std::string& axis_type); |
3381 | 3193 |
3382 void update_axis_limits (const std::string& axis_type, | |
3383 const graphics_handle& h); | |
3384 | |
3385 bool valid_object (void) const { return true; } | 3194 bool valid_object (void) const { return true; } |
3386 | 3195 |
3387 void reset_default_properties (void); | 3196 void reset_default_properties (void); |
3388 | 3197 |
3389 private: | 3198 private: |
3985 update_limits (); | 3794 update_limits (); |
3986 } | 3795 } |
3987 | 3796 |
3988 void adopt (const graphics_handle& h) | 3797 void adopt (const graphics_handle& h) |
3989 { | 3798 { |
3990 | |
3991 base_properties::adopt (h); | 3799 base_properties::adopt (h); |
3992 update_limits (h); | 3800 update_limits (); |
3993 } | 3801 } |
3994 | 3802 |
3995 // See the genprops.awk script for an explanation of the | 3803 // See the genprops.awk script for an explanation of the |
3996 // properties declarations. | 3804 // properties declarations. |
3997 | 3805 |
4008 bool_property climinclude h , "on" | 3816 bool_property climinclude h , "on" |
4009 bool_property aliminclude h , "on" | 3817 bool_property aliminclude h , "on" |
4010 END_PROPERTIES | 3818 END_PROPERTIES |
4011 | 3819 |
4012 private: | 3820 private: |
4013 void update_limits (void) const; | 3821 void update_limits (void) |
4014 | 3822 { |
4015 void update_limits (const graphics_handle& h) const; | 3823 update_axis_limits ("xlim"); |
3824 update_axis_limits ("ylim"); | |
3825 update_axis_limits ("zlim"); | |
3826 update_axis_limits ("clim"); | |
3827 update_axis_limits ("alim"); | |
3828 } | |
4016 | 3829 |
4017 protected: | 3830 protected: |
4018 void init (void) | 3831 void init (void) |
4019 { } | 3832 { } |
4020 | |
4021 }; | 3833 }; |
4022 | 3834 |
4023 private: | 3835 private: |
4024 properties xproperties; | 3836 properties xproperties; |
4025 | 3837 |
4035 base_properties& get_properties (void) { return xproperties; } | 3847 base_properties& get_properties (void) { return xproperties; } |
4036 | 3848 |
4037 const base_properties& get_properties (void) const { return xproperties; } | 3849 const base_properties& get_properties (void) const { return xproperties; } |
4038 | 3850 |
4039 bool valid_object (void) const { return true; } | 3851 bool valid_object (void) const { return true; } |
4040 | 3852 |
4041 void update_axis_limits (const std::string& axis_type); | 3853 void update_axis_limits (const std::string& axis_type); |
4042 | |
4043 void update_axis_limits (const std::string& axis_type, | |
4044 const graphics_handle& h); | |
4045 | |
4046 }; | 3854 }; |
4047 | 3855 |
4048 // --------------------------------------------------------------------- | 3856 // --------------------------------------------------------------------- |
4049 | 3857 |
4050 class OCTINTERP_API uimenu : public base_graphics_object | 3858 class OCTINTERP_API uimenu : public base_graphics_object |