octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [changeset] - improve clf() compatibility


From: John W. Eaton
Subject: Re: [changeset] - improve clf() compatibility
Date: Mon, 20 Oct 2008 23:07:09 -0400

On 20-Oct-2008, Ben Abbott wrote:

| 
| On Oct 10, 2008, at 1:49 PM, Ben Abbott wrote:
| 
| > On Friday, October 10, 2008, at 01:31PM, "John W. Eaton" <address@hidden 
| > > wrote:
| >> On 10-Oct-2008, Ben Abbott wrote:
| >>
| >> |
| >> | On Oct 10, 2008, at 7:54 AM, Michael Goffioul wrote:
| >> |
| >> | > On Fri, Oct 10, 2008 at 1:46 PM, Ben Abbott <address@hidden>  
| >> wrote:
| >> | >>> What's missing here is probably "reset" function.
| >> | >>>
| >> | >>> Michael.
| >> | >>
| >> | >>
| >> | >> Agreed.
| >> | >>
| >> | >> If I had a method available to inquire as to what the defaults
| >> | >> were, that
| >> | >> would be easy enough to impement. Do you imply that I am already
| >> | >> able to
| >> | >> determine the default property values?
| >> | >
| >> | > get(0, 'defaultfigurecolor') for instance
| >> | >
| >> | > However, implementing this in m-code will probably be rather
| >> | > inefficient.
| >> | > I guess a C++ implementation (maybe with some autogenerated code)
| >> | > would be better suited.
| >> | >
| >> | > Michael.
| >> |
| >> | ok, that does work in Matlab, but not in Octave's 3.1.51+ branch.  
| >> Does
| >> | this functionality exist somewhere else?
| >>
| >> However, setting default properties does work.  For example
| >>
| >> figure (1);
| >> get (1, "color")
| >>   ==> [1, 1, 1]
| >>
| >> close ("all");
| >>
| >> set (0, "defaultfigurecolor", [0.1, 0.2, 0.3]);
| >> figure (1);
| >> get (1, "color")
| >>   ==> [0.1, 0.2, 0.3]
| >>
| >>
| >> I think getting defaults is just not completely implemented yet.   
| >> Some
| >> things do work.  For example, I see
| >>
| >> set (0, "defaultfigurecolor", [0.1, 0.2, 0.3]);
| >> get (0, "default")
| >> ans =
| >> {
| >>   defaultfigurecolor =
| >>
| >>      0.20000   0.20000   0.20000
| >>
| >> }
| >>
| >> get (0, "defaultfigurecolor")
| >> ans =
| >>
| >>    0.20000   0.20000   0.20000
| >>
| >>
| >> but as you noted, this fails when the default has not been explicitly
| >> set.  I guess that's just something that still needs to be done.
| >>
| >> jwe
| >
| > heck, it appears all of the defaults could be handled by the  
| > functions that create them. Is that what should be done, or should  
| > the defaults be handled at a lower level.
| >
| > Ben
| 
| My inference regarding access to default property values was wrong.  
| What is needed it a reset() function (likely built-in). I've requested  
| such on another thread.
| 
| Additionally, when writing the changeset I submitted, I confused the  
| "visible" property to be an indicator of handle visibility, rather  
| than the object's visibility.
| 
| If I understand the visibility of handles correctly, allchild(h)  
| returns all children, including those with hidden handles, and  
| get(h,"children") returns the children with visible handles. Please  
| correct me if I'm wrong.
| 
| If it is permissible to accept a changeset for clf() without the  
| capability to reset the default propery values, please commit this  
| one. Note that while I've included a call to reset(), it is not used  
| unless requested.

Before we apply this change, I think we need to fix the title, xlabel,
ylabel, and zlabel properties to be hidden children of the axes
object.  My best guess at how to do that is below, but it does not
quite work.  I don't have any more time to work on this problem, but I
thought I would post the diffs anyway to give anyone else who wants to
work on this a starting point.

jwe


diff --git a/src/ChangeLog b/src/ChangeLog
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,4 +1,23 @@
 2008-10-20  John W. Eaton  <address@hidden>
+
+       * graphics.h.in (gh_manager::is_handle_visible): New function.
+       (axes::properites): Move title property after label properties.
+       (graphics_object::is_handle_visible): New function.
+       (base_properties::is_handle_visible): New function.
+       (base_properties): Mark children property with G.
+       * graphics.cc (base_property::get_children): New function.  Only
+       return handles that are visible.
+       (axes::properties::delete_text_child): Set handlevisibility to
+       "off" for newly created object and add it to the list of children.
+       (axes::properties::set_defaults): Don't explicitly delete xlabel,
+       ylabel, zlabel, and title handles.  Don't explicitly set children
+       to empty matrix.
+       (axes::properties::remove_child): Don't explicitly delete xlabel,
+       ylabel, zlabel, and title handles.
+       (axes::properties::remove_child): Always call remove_child on handle.
+       (axes::properties::init): Move here from graphics.h.in.  Set
+       handlevisibility to "off" for xlabel, ylabel, zlabel, and title
+       and add them to the list of children.
 
        * genprops.awk: Allow whitespace between BEGIN_PROPERTIES and
        opening paren.  Accept optional second argument for graphics
diff --git a/src/graphics.cc b/src/graphics.cc
--- a/src/graphics.cc
+++ b/src/graphics.cc
@@ -2133,6 +2133,54 @@
 
 // ---------------------------------------------------------------------
 
+void
+axes::properties::init (void)
+{
+  position.add_constraint (dim_vector (1, 4));
+  position.add_constraint (dim_vector (0, 0));
+  outerposition.add_constraint (dim_vector (1, 4));
+  colororder.add_constraint (dim_vector (-1, 3));
+  dataaspectratio.add_constraint (dim_vector (1, 3));
+  plotboxaspectratio.add_constraint (dim_vector (1, 3));
+  xlim.add_constraint (2);
+  ylim.add_constraint (2);
+  zlim.add_constraint (2);
+  clim.add_constraint (2);
+  alim.add_constraint (2);
+  xtick.add_constraint (dim_vector (1, -1));
+  ytick.add_constraint (dim_vector (1, -1));
+  ztick.add_constraint (dim_vector (1, -1));
+  Matrix vw (1, 2, 0);
+  vw(1) = 90;
+  view = vw;
+  view.add_constraint (dim_vector (1, 2));
+  cameraposition.add_constraint (dim_vector (1, 3));
+  Matrix upv (1, 3, 0.0);
+  upv(2) = 1.0;
+  cameraupvector = upv;
+  cameraupvector.add_constraint (dim_vector (1, 3));
+  currentpoint.add_constraint (dim_vector (2, 3));
+  ticklength.add_constraint (dim_vector (1, 2));
+  tightinset.add_constraint (dim_vector (1, 4));
+
+  x_zlim.resize (1, 2);
+  sx = "linear";
+  sy = "linear";
+  sz = "linear";
+
+  xset (xlabel.handle_value (), "handlevisibility", "off");
+  xset (ylabel.handle_value (), "handlevisibility", "off");
+  xset (zlabel.handle_value (), "handlevisibility", "off");
+
+  xset (title.handle_value (), "handlevisibility", "off");
+
+  adopt (xlabel.handle_value ());
+  adopt (ylabel.handle_value ());
+  adopt (zlabel.handle_value ());
+
+  adopt (title.handle_value ());
+}
+
 void 
 axes::properties::sync_positions (void)
 {
@@ -2219,8 +2267,6 @@
 axes::properties::set_defaults (base_graphics_object& obj,
                                const std::string& mode)
 {
-  delete_text_child (title);
-
   box = "on";
   key = "off";
   keybox = "off";
@@ -2244,10 +2290,6 @@
   ylimmode = "auto";
   zlimmode = "auto";
   climmode = "auto";
-
-  delete_text_child (xlabel);
-  delete_text_child (ylabel);
-  delete_text_child (zlabel);
 
   xgrid = "off";
   ygrid = "off";
@@ -2331,8 +2373,6 @@
 
   delete_children ();
 
-  children = Matrix ();
-
   update_transform ();
 
   override_defaults (obj);
@@ -2352,7 +2392,13 @@
     }
 
   if (! is_beingdeleted ())
-    hp = gh_manager::make_graphics_handle ("text", __myhandle__);
+    {
+      hp = gh_manager::make_graphics_handle ("text", __myhandle__);
+
+      xset (hp.handle_value (), "handlevisibility", "off");
+
+      adopt (hp.handle_value ());
+    }
 }
 
 void
@@ -2366,20 +2412,42 @@
     delete_text_child (ylabel);
   else if (zlabel.handle_value ().ok () && h == zlabel.handle_value ())
     delete_text_child (zlabel);
-  else
-    base_properties::remove_child (h);
+
+  base_properties::remove_child (h);
 }
 
 void
 axes::properties::delete_children (void)
 {
   base_properties::delete_children ();
-
-  delete_text_child (title);
-
-  delete_text_child (xlabel);
-  delete_text_child (ylabel);
-  delete_text_child (zlabel);
+}
+
+Matrix
+base_properties::get_children (void) const
+{
+  Matrix retval = children;
+  
+  graphics_object go = gh_manager::get_object (0);
+
+  root_figure::properties& props =
+      dynamic_cast<root_figure::properties&> (go.get_properties ());
+
+  if (! props.is_showhiddenhandles ())
+    {
+      octave_idx_type k = 0;
+
+      for (octave_idx_type i = 0; i < children.numel (); i++)
+       {
+         graphics_handle kid = children (i);
+
+         if (gh_manager::is_handle_visible (kid))
+           retval(k++) = children(i);
+       }
+
+      retval.resize (k, 1);
+    }
+
+  return retval;;
 }
 
 inline Matrix
diff --git a/src/graphics.h.in b/src/graphics.h.in
--- a/src/graphics.h.in
+++ b/src/graphics.h.in
@@ -1669,6 +1669,11 @@
   virtual bool is_zliminclude (void) const { return false; }
   virtual bool is_climinclude (void) const { return false; }
   virtual bool is_aliminclude (void) const { return false; }
+
+  bool is_handle_visible (void) const
+  {
+    return ! handlevisibility.is ("off");
+  }
  
 protected:
   void set_dynamic (const caseless_str&, const octave_value&);
@@ -1685,7 +1690,7 @@
     radio_property busyaction , "{queue}|cancel"
     callback_property buttondownfcn , Matrix ()
     // FIXME: use a property class for children
-    Matrix children fs , Matrix ()
+    Matrix children Gfs , Matrix ()
     bool_property clipping , "on"
     callback_property createfcn , Matrix ()
     callback_property deletefcn , Matrix ()
@@ -2070,6 +2075,9 @@
   
   bool is_aliminclude (void) const
   { return get_properties ().is_aliminclude (); }
+
+  bool is_handle_visible (void) const
+  { return get_properties ().is_handle_visible (); }
   
   graphics_backend get_backend (void) const { return rep->get_backend (); }
 
@@ -2543,7 +2551,6 @@
 
     BEGIN_PROPERTIES (axes)
       array_property position u , default_axes_position ()
-      handle_property title SOf , gh_manager::make_graphics_handle ("text", 
__myhandle__)
       bool_property box , "on"
       bool_property key , "off"
       bool_property keybox , "off"
@@ -2565,6 +2572,7 @@
       handle_property xlabel SOf , gh_manager::make_graphics_handle ("text", 
__myhandle__)
       handle_property ylabel SOf , gh_manager::make_graphics_handle ("text", 
__myhandle__)
       handle_property zlabel SOf , gh_manager::make_graphics_handle ("text", 
__myhandle__)
+      handle_property title SOf , gh_manager::make_graphics_handle ("text", 
__myhandle__)
       bool_property xgrid , "off"
       bool_property ygrid , "off"
       bool_property zgrid , "off"
@@ -2643,40 +2651,7 @@
    END_PROPERTIES
 
   protected:
-    void init (void)
-      {
-        position.add_constraint (dim_vector (1, 4));
-       position.add_constraint (dim_vector (0, 0));
-        outerposition.add_constraint (dim_vector (1, 4));
-        colororder.add_constraint (dim_vector (-1, 3));
-        dataaspectratio.add_constraint (dim_vector (1, 3));
-        plotboxaspectratio.add_constraint (dim_vector (1, 3));
-       xlim.add_constraint (2);
-       ylim.add_constraint (2);
-       zlim.add_constraint (2);
-       clim.add_constraint (2);
-       alim.add_constraint (2);
-        xtick.add_constraint (dim_vector (1, -1));
-        ytick.add_constraint (dim_vector (1, -1));
-        ztick.add_constraint (dim_vector (1, -1));
-        Matrix vw (1, 2, 0);
-        vw(1) = 90;
-        view = vw;
-        view.add_constraint (dim_vector (1, 2));
-       cameraposition.add_constraint (dim_vector (1, 3));
-       Matrix upv (1, 3, 0.0);
-       upv(2) = 1.0;
-       cameraupvector = upv;
-       cameraupvector.add_constraint (dim_vector (1, 3));
-       currentpoint.add_constraint (dim_vector (2, 3));
-       ticklength.add_constraint (dim_vector (1, 2));
-       tightinset.add_constraint (dim_vector (1, 4));
-
-       x_zlim.resize (1, 2);
-       sx = "linear";
-       sy = "linear";
-       sz = "linear";
-      }
+    void init (void);
 
   private:
     void update_xscale (void) { sx = get_xscale (); }
@@ -3653,6 +3628,18 @@
     return (instance_ok () ?  instance->do_process_events (true) : 0);
   }
 
+  static bool is_handle_visible (const graphics_handle& h)
+  {
+    bool retval = false;
+
+    graphics_object go = get_object (h);
+
+    if (go.valid_object ())
+      retval = go.is_handle_visible ();
+
+    return retval;
+  }
+
 public:
   class autolock
   {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]