Mercurial > hg > octave-nkf
changeset 7379:a78c7bccda91
[project @ 2008-01-15 18:42:29 by jwe]
author | jwe |
---|---|
date | Tue, 15 Jan 2008 18:42:30 +0000 |
parents | 3771971e8891 |
children | 2ba95a933d3e |
files | scripts/ChangeLog scripts/linear-algebra/__norm__.m scripts/plot/__go_draw_axes__.m scripts/plot/__go_draw_figure__.m scripts/plot/drawnow.m src/ChangeLog src/genprops.awk src/graphics.cc src/graphics.h.in |
diffstat | 9 files changed, 204 insertions(+), 66 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,14 @@ +2008-01-15 Michael Goffioul <michael.goffioul@gmail.com> + + * plot/drawnow.m, plot/__go_draw_figure__.m, plot/__go_draw_axes__.m: + Call __get__ instead of get. + +2008-01-15 Ben Abbott <bpabbott@mac.com> + + * linear-algebra/__norm__.m: Avoid divide by zero error for + Frobenius norm if matrix is all zeros. Use transpose instead of + hermitian operator. + 2008-01-14 Bill Denney <bill@denney.ws> * plot/axis.m: Correctly handle "tight" and "image" options.
--- a/scripts/linear-algebra/__norm__.m +++ b/scripts/linear-algebra/__norm__.m @@ -44,7 +44,11 @@ if (ischar (p)) if (strcmp (p, "fro")) inf_norm = norm (x, "inf"); - retval = inf_norm .* sqrt (sum (abs (x ./ inf_norm) .^ 2)); + if (inf_norm) + retval = inf_norm .* sqrt (sum (abs (x ./ inf_norm) .^ 2)); + else + retval = inf_norm; + endif elseif (strcmp (p, "inf")) retval = max (abs (x)); else @@ -56,7 +60,7 @@ elseif (p == -Inf) retval = min (abs (x)); elseif (p == 1) - retval = sum (abs (x)); + retval = sum (abs (x)); elseif (p == 2) if (iscomplex (x)) x = abs (x); @@ -70,9 +74,13 @@ if (ischar (p)) if (strcmp (p, "fro")) inf_norm = norm (x, "inf"); - retval = inf_norm .* sqrt (sum (sum (abs (x ./ inf_norm) .^ 2))); + if (inf_norm) + retval = inf_norm .* sqrt (sum (sum (abs (x ./ inf_norm) .^ 2))); + else + retval = inf_norm; + endif elseif (strcmp (p, "inf")) - retval = max (sum (abs (x'))); + retval = max (sum (abs (x.'))); else error ("norm: unrecognized vector norm"); endif @@ -83,11 +91,33 @@ s = svd (x); retval = s (1); elseif (p == Inf) - retval = max (sum (abs (x'))); + retval = max (sum (abs (x.'))); else - error ("norm: unrecognized matrix norm"); + error ("norm: unrecognized matrix norm"); endif endif endif endfunction + +%!test +%! x = __norm__ (zeros (5), "fro"); +%! assert (x, 0); +%! x = __norm__ (ones (5), "fro"); +%! assert (x, 5); +%! x = __norm__ (zeros (5,1), "fro"); +%! assert (x, 0); +%! x = __norm__ (2*ones (5,3), "fro"); +%! assert (x, sqrt (60)); + +%!test +%! x = __norm__ (zeros (5), "inf"); +%! assert (x, 0); +%! x = __norm__ (ones (5), "inf"); +%! assert (x, 5); +%! x = __norm__ (2*ones (5,1), "inf"); +%! assert (x, 0); +%! x = __norm__ (2*ones (5,3), "inf"); +%! assert (x, 6); + +
--- a/scripts/plot/__go_draw_axes__.m +++ b/scripts/plot/__go_draw_axes__.m @@ -24,7 +24,7 @@ if (nargin == 4) - axis_obj = get (h); + axis_obj = __get__ (h); parent_figure_obj = get (axis_obj.parent);
--- a/scripts/plot/__go_draw_figure__.m +++ b/scripts/plot/__go_draw_figure__.m @@ -33,7 +33,7 @@ if (nkids > 0) axes_count = 0; for i = 1:nkids - obj = get (kids(i)); + obj = __get__ (kids(i)); switch (obj.type) case "axes" axes_count++;
--- a/scripts/plot/drawnow.m +++ b/scripts/plot/drawnow.m @@ -49,7 +49,7 @@ endif h = get (0, "currentfigure"); if (h) - f = get (h); + f = __get__ (h); plot_stream = []; fid = []; unwind_protect @@ -74,7 +74,7 @@ elseif (nargin == 0) for h = __go_figure_handles__ () if (! (isnan (h) || h == 0)) - f = get (h); + f = __get__ (h); if (f.__modified__) plot_stream = f.__plot_stream__; figure_is_visible = strcmp (f.visible, "on");
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,27 @@ +2008-01-15 Michael Goffioul <michael.goffioul@gmail.com> + + * genprops.awk: Handle 'h' modifier for hidden properties. + Replace "get(void)" method with "get(bool all = false)" to allow + access to hidden properties. + + * graphics.h.in (base_properties::get, base_graphics_object::get, + graphics_object::get, root_figure::get, figure::get, axes::get, + line::get, text::get, patch::get, surface::get, image::get): + New arg, ALL, to access hidden properties. + (gh_manager::do_get_object): Do not look for invalid handles. + (figure::properties::__plot_stream__, + figure::properties::__enhanced__, axes::properties::__colorbar__): + Make properties hidden. + (axes::properties, line::properties, text::properties, + patch::properties, surface::properties): Remove obsolete 'a' + property modifier. + * graphics.cc (base_properties::get): New arg ALL, to access + hidden properties. + (base_properties::mark_modified): Call mark_modified only on valid + parent object. + (__get__): New internal function returning all properties, + including the hidden ones. + 2008-01-15 John W. Eaton <jwe@octave.org> * graphics.cc (properties::set_currentfigure,
--- a/src/genprops.awk +++ b/src/genprops.awk @@ -51,7 +51,7 @@ ## } ## ## If present, the QUALIFIERS string may include any of the characters -## g, G, m, s, S, o, O, which have the following meanings: +## g, G, m, s, S, o, O, h, which have the following meanings: ## ## g: There is a custom inline definition for the get function, ## so we don't emit one. @@ -106,6 +106,8 @@ ## ## to the type-specific set function. ## +## h: Make the property hidden +## ## The 'o' and 'O' qualifiers are only useful when the the property type ## is something other than octave_value. @@ -204,7 +206,7 @@ printf (" properties (const graphics_handle& mh, const graphics_handle& p);\n\n"); printf (" ~properties (void) { }\n\n"); printf (" void set (const caseless_str& name, const octave_value& val);\n\n"); - printf (" octave_value get (void) const;\n\n"); + printf (" octave_value get (bool all = false) const;\n\n"); printf (" octave_value get (const caseless_str& name) const;\n\n"); printf (" std::string graphics_object_name (void) const { return go_name; }\n\n"); printf (" static property_list::pval_map_type factory_defaults (void);\n\n"); @@ -322,12 +324,16 @@ printf ("\n") >> filename; } - printf ("{\n init ();\n") >> filename; + printf ("{\n") >> filename; -## for (i = 1; i <= idx; i++) -## printf (" insert_static_property (\"%s\", %s);\n", name[i], name[i]) >> filename; + for (i = 1; i <= idx; i++) + { +## printf (" insert_static_property (\"%s\", %s);\n", name[i], name[i]) >> filename; + if (hidden[i]) + printf (" %s.set_hidden (true);\n", name[i]) >> filename; + } - printf ("}\n\n") >> filename; + printf (" init ();\n}\n\n") >> filename; ## set method @@ -344,13 +350,17 @@ ## get "all" method - printf ("octave_value\n%s::properties::get (void) const\n{\n", class_name) >> filename; - printf (" Octave_map m = base_properties::get ().map_value ();\n\n") >> filename; + printf ("octave_value\n%s::properties::get (bool all) const\n{\n", class_name) >> filename; + printf (" Octave_map m = base_properties::get (all).map_value ();\n\n") >> filename; for (i = 1; i <= idx; i++) { - printf (" m.assign (\"%s\", get_%s ()%s);\n", name[i], name[i], - (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; + if (hidden[i]) + printf (" if (all)\n m.assign (\"%s\", get_%s ()%s);\n", name[i], name[i], + (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; + else + printf (" m.assign (\"%s\", get_%s ()%s);\n", name[i], name[i], + (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; } printf ("\n return m;\n}\n\n") >> filename; @@ -449,6 +459,7 @@ limits[idx] = 0; mode[idx] = 0; + hidden[idx] = 0; emit_get[idx] = "definition"; emit_set[idx] = "definition"; default[idx] = ""; @@ -488,6 +499,10 @@ ## but we still emit the declaration. if (index (quals, "S")) emit_set[idx] = "declaration"; + + ## The property is hidden + if (index (quals, "h")) + hidden[idx] = 1; ## ## emmit an asignment set function ## if (index (quals, "a"))
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -954,17 +954,19 @@ } octave_value -base_properties::get (void) const +base_properties::get (bool all) const { Octave_map m; for (std::map<caseless_str, property>::const_iterator it = all_props.begin (); it != all_props.end (); ++it) - m.assign (it->second.get_name (), it->second.get ()); + if (all || ! it->second.is_hidden ()) + m.assign (it->second.get_name (), it->second.get ()); m.assign ("tag", get_tag ()); m.assign ("type", get_type ()); - m.assign ("__modified__", is_modified ()); + if (all) + m.assign ("__modified__", is_modified ()); m.assign ("parent", get_parent ().as_octave_value ()); m.assign ("children", children); m.assign ("busyaction", get_busyaction ()); @@ -1107,7 +1109,8 @@ { __modified__ = "on"; graphics_object parent_obj = gh_manager::get_object (get_parent ()); - parent_obj.mark_modified (); + if (parent_obj) + parent_obj.mark_modified (); } void @@ -1970,6 +1973,61 @@ return retval; } +DEFUN (__get__, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} __get__ (@var{h})\n\ +Return all properties from the graphics handle @var{h}.\n\ +If @var{h} is a vector, return a cell array including the property\n\ +values or lists respectively.\n\ +@end deftypefn") +{ + octave_value retval; + octave_value_list vlist; + + int nargin = args.length (); + + if (nargin == 1) + { + ColumnVector hcv (args(0).vector_value ()); + + if (! error_state) + { + octave_idx_type len = hcv.length (); + + vlist.resize (len); + + for (octave_idx_type n = 0; n < len; n++) + { + graphics_object obj = gh_manager::get_object (hcv(n)); + + if (obj) + vlist(n) = obj.get (true); + else + { + error ("get: invalid handle (= %g)", hcv(n)); + break; + } + } + } + else + error ("get: expecting graphics handle as first argument"); + } + else + print_usage (); + + if (! error_state) + { + octave_idx_type len = vlist.length (); + + if (len > 1) + retval = Cell (vlist); + else if (len == 1) + retval = vlist(0); + } + + return retval; +} + static octave_value make_graphics_object (const std::string& go_name, const octave_value_list& args)
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -1005,7 +1005,7 @@ virtual octave_value get (const caseless_str&) const; - virtual octave_value get (void) const; + virtual octave_value get (bool all = false) const; property get_property (const caseless_str&) const; @@ -1314,7 +1314,7 @@ error ("base_graphics_object::set_defaults: invalid graphics object"); } - virtual octave_value get (void) const + virtual octave_value get (bool all = false) const { error ("base_graphics_object::get: invalid graphics object"); return octave_value (); @@ -1453,7 +1453,7 @@ void set_defaults (const std::string& mode) { rep->set_defaults (mode); } - octave_value get (void) const { return rep->get (); } + octave_value get (bool all = false) const { return rep->get (all); } octave_value get (const caseless_str& name) const { @@ -1619,9 +1619,9 @@ xproperties.set (name, value); } - octave_value get (void) const + octave_value get (bool all = false) const { - return xproperties.get (); + return xproperties.get (all); } octave_value get (const caseless_str& name) const @@ -1710,8 +1710,8 @@ // properties declarations. BEGIN_PROPERTIES(figure) - any_property __plot_stream__ , Matrix () - bool_property __enhanced__ , "on" + any_property __plot_stream__ h , Matrix () + bool_property __enhanced__ h , "on" radio_property nextplot , "add|replace_children|{replace}" callback_property closerequestfcn , "closereq" handle_property currentaxes S , graphics_handle () @@ -1777,9 +1777,9 @@ xproperties.set (name, value); } - octave_value get (void) const + octave_value get (bool all = false) const { - return xproperties.get (); + return xproperties.get (all); } octave_value get (const caseless_str& name) const @@ -1848,7 +1848,7 @@ array_property colororder , default_colororder () array_property dataaspectratio m , Matrix (1, 3, 1.0) radio_property dataaspectratiomode , "{auto}|manual" - radio_property layer a , "{bottom}|top" + radio_property layer , "{bottom}|top" array_property xlim m , default_lim () array_property ylim m , default_lim () array_property zlim m , default_lim () @@ -1878,7 +1878,7 @@ radio_property xticklabelmode , "{auto}|manual" radio_property yticklabelmode , "{auto}|manual" radio_property zticklabelmode , "{auto}|manual" - color_property color a , color_property (color_values (1, 1, 1), radio_values ("none")) + color_property color , color_property (color_values (1, 1, 1), radio_values ("none")) color_property xcolor , color_values (0, 0, 0) color_property ycolor , color_values (0, 0, 0) color_property zcolor , color_values (0, 0, 0) @@ -1893,8 +1893,8 @@ array_property view , Matrix () radio_property nextplot , "add|replace_children|{replace}" array_property outerposition , Matrix () - radio_property activepositionproperty a , "{outerposition}|position" - radio_property __colorbar__ a , "{none}|north|south|east|west|northoutside|southoutside|eastoutside|westoutside" + radio_property activepositionproperty , "{outerposition}|position" + radio_property __colorbar__ h , "{none}|north|south|east|west|northoutside|southoutside|eastoutside|westoutside" END_PROPERTIES protected: @@ -1970,9 +1970,9 @@ xproperties.set_defaults (*this, mode); } - octave_value get (void) const + octave_value get (bool all = false) const { - return xproperties.get (); + return xproperties.get (all); } octave_value get (const caseless_str& name) const @@ -2047,7 +2047,7 @@ color_property markerfacecolor , "auto|{none}" double_property markersize , 6 string_property keylabel , "" - radio_property interpreter a , "{tex}|none|latex" + radio_property interpreter , "{tex}|none|latex" string_property displayname , "" radio_property erase_mode , "{normal}|none|xor|background" END_PROPERTIES @@ -2086,9 +2086,9 @@ xproperties.set (name, val); } - octave_value get (void) const + octave_value get (bool all = false) const { - return xproperties.get (); + return xproperties.get (all); } octave_value get (const caseless_str& name) const @@ -2133,9 +2133,9 @@ color_property color , color_values (0, 0, 0) string_property fontname , "Helvetica" double_property fontsize , 10 - radio_property fontangle a , "{normal}|italic|oblique" - radio_property fontweight a , "light|{normal}|demi|bold" - radio_property interpreter a , "{tex}|none|latex" + radio_property fontangle , "{normal}|italic|oblique" + radio_property fontweight , "light|{normal}|demi|bold" + radio_property interpreter , "{tex}|none|latex" color_property backgroundcolor , "{none}" string_property displayname , "" color_property edgecolor , "{none}" @@ -2188,9 +2188,9 @@ xproperties.set (name, val); } - octave_value get (void) const + octave_value get (bool all = false) const { - return xproperties.get (); + return xproperties.get (all); } octave_value get (const caseless_str& name) const @@ -2271,9 +2271,9 @@ xproperties.set (name, val); } - octave_value get (void) const + octave_value get (bool all = false) const { - return xproperties.get (); + return xproperties.get (all); } octave_value get (const caseless_str& name) const @@ -2314,26 +2314,26 @@ data_property ydata l , Matrix () data_property zdata l , Matrix () data_property cdata l , Matrix () - radio_property cdatamapping a , "{scaled}|direct" + radio_property cdatamapping , "{scaled}|direct" array_property faces , Matrix () data_property facevertexalphadata , Matrix () data_property facevertexcdata , Matrix () array_property vertices , Matrix () array_property vertexnormals , Matrix () - radio_property normalmode a , "{auto}|manual" - color_property facecolor a , "{flat}|none|interp" + radio_property normalmode , "{auto}|manual" + color_property facecolor , "{flat}|none|interp" double_property facealpha , 1.0 - radio_property facelighting a , "{flat}|none|gouraud|phong" - color_property edgecolor a , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) + radio_property facelighting , "{flat}|none|gouraud|phong" + color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) double_property edgealpha , 1.0 - radio_property edgelighting a , "{none}|flat|gouraud|phong" - radio_property backfacelighting a , "{reverselit}|unlit|lit" + radio_property edgelighting , "{none}|flat|gouraud|phong" + radio_property backfacelighting , "{reverselit}|unlit|lit" double_property ambientstrength , 0.3 double_property diffusestrength , 0.6 double_property specularstrength , 0.6 double_property specularexponent , 10.0 double_property specularcolorreflectance , 1.0 - radio_property erasemode a , "{normal}|background|xor|none" + radio_property erasemode , "{normal}|background|xor|none" radio_property linestyle , "{-}|--|:|-.|none" double_property linewidth , 0.5 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" @@ -2341,7 +2341,7 @@ color_property markerfacecolor , "auto|{none}" double_property markersize , 6 string_property keylabel , "" - radio_property interpreter a , "{tex}|none|latex" + radio_property interpreter , "{tex}|none|latex" END_PROPERTIES protected: @@ -2385,9 +2385,9 @@ xproperties.set (name, val); } - octave_value get (void) const + octave_value get (bool all = false) const { - return xproperties.get (); + return xproperties.get (all); } octave_value get (const caseless_str& name) const @@ -2428,9 +2428,9 @@ data_property ydata l , Matrix () data_property zdata l , Matrix () data_property cdata l , Matrix () - color_property facecolor a , "{flat}|none|interp" + color_property facecolor , "{flat}|none|interp" double_property facealpha , 1.0 - color_property edgecolor a , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) + color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) radio_property linestyle , "{-}|--|:|-.|none" double_property linewidth , 0.5 radio_property marker , "{none}|s|o|x|+|.|*|<|>|v|^|d|p|h" @@ -2438,7 +2438,7 @@ color_property markerfacecolor , "auto|{none}" double_property markersize , 6 string_property keylabel , "" - radio_property interpreter a , "{tex}|none|latex" + radio_property interpreter , "{tex}|none|latex" END_PROPERTIES protected: @@ -2480,9 +2480,9 @@ xproperties.set (name, val); } - octave_value get (void) const + octave_value get (bool all = false) const { - return xproperties.get (); + return xproperties.get (all); } octave_value get (const caseless_str& name) const @@ -2639,7 +2639,7 @@ graphics_object do_get_object (const graphics_handle& h) { - iterator p = handle_map.find (h); + iterator p = (h.ok () ? handle_map.find (h) : handle_map.end ()); return (p != handle_map.end ()) ? p->second : graphics_object (); }