Index: trunk/gui/scripts/field.tcl
===================================================================
--- trunk/gui/scripts/field.tcl	(revision 5610)
+++ trunk/gui/scripts/field.tcl	(revision 5611)
@@ -152,6 +152,4 @@
     private variable _comp2vtk;         # cname => vtk file data
     private variable _comp2dx;          # cname => OpenDX data
-    private variable _comp2unirect2d;   # cname => unirect2d obj
-    private variable _comp2unirect3d;   # cname => unirect3d obj
     private variable _comp2style;       # cname => style settings
     private variable _comp2cntls;       # cname => x,y control points (1D only)
@@ -160,6 +158,4 @@
     private variable _comp2mesh;        # list: mesh obj, BLT vector of values
                                         # valid for cloud,mesh,unirect2d
-    private variable _values "";        # Only for unirect2d - list of values
-
     private common _alwaysConvertDX 0;  # If set, convert DX and store as VTK,
                                         # even if viewer is nanovis/flowvis
@@ -221,10 +217,4 @@
     foreach name [array names _comp2xy] {
         eval blt::vector destroy $_comp2xy($name)
-    }
-    foreach name [array names _comp2unirect2d] {
-        itcl::delete object $_comp2unirect2d($name)
-    }
-    foreach name [array names _comp2unirect3d] {
-        itcl::delete object $_comp2unirect3d($name)
     }
     foreach name [array names _comp2flowhints] {
@@ -324,10 +314,4 @@
         error "method \"mesh\" is not implemented for Rappture::Mesh"
     }
-    if {[info exists _comp2unirect2d($cname)]} {
-        error "method \"mesh\" is not implemented for unirect2d"
-    }
-    if {[info exists _comp2unirect3d($cname)]} {
-        error "method \"mesh\" is not implemented for unirect3d"
-    }
     error "can't get field mesh: Unknown component \"$cname\": should be one of [join [lsort [array names _comp2dims]] {, }]"
 }
@@ -357,10 +341,4 @@
         return [lindex $_comp2mesh($cname) 1] ;# return vector
     }
-    if {[info exists _comp2unirect2d($cname)]} {
-        error "method \"values\" is not implemented for unirect2d"
-    }
-    if {[info exists _comp2unirect3d($cname)]} {
-        error "method \"values\" is not implemented for unirect3d"
-    }
     error "can't get field values. Unknown component \"$cname\": should be one of [join [lsort [array names _comp2dims]] {, }]"
 }
@@ -378,16 +356,8 @@
         return $_comp2dx($cname)  ;# return gzipped, base64-encoded DX data
     }
-    if {[info exists _comp2unirect2d($cname)]} {
-        set blob [$_comp2unirect2d($cname) blob]
-        lappend blob "values" $_values
-        return $blob
-    }
-    if {[info exists _comp2unirect3d($cname)]} {
-        return [$_comp2unirect3d($cname) blob]
-    }
     if {[info exists _comp2mesh($cname)]} {
         error "method \"blob\" not implemented for Rappture::Mesh"
     }
-    if { [info exists _comp2vtk($cname)] } {
+    if {[info exists _comp2vtk($cname)]} {
         error "method \"blob\" not implemented for VTK file data"
     }
@@ -750,16 +720,8 @@
     }
     array unset _comp2vtk
-    foreach name [array names _comp2unirect2d] {
-        eval itcl::delete object $_comp2unirect2d($name)
-    }
-    foreach name [array names _comp2unirect3d] {
-        eval itcl::delete object $_comp2unirect3d($name)
-    }
     catch {unset _comp2xy}
     catch {unset _comp2dx}
     catch {unset _comp2dims}
     catch {unset _comp2style}
-    array unset _comp2unirect2d
-    array unset _comp2unirect3d
     array unset _dataobj2type
     #
@@ -1320,51 +1282,4 @@
         set data [Rappture::encoding::decode -as zb64 $data]
         return [Rappture::DxToVtk $data]
-    }
-    # unirect2d (deprecated)
-    # This can be removed when the nanovis server with support for loading VTK
-    # vector data is released
-    if {[info exists _comp2unirect2d($cname)]} {
-        set label $cname
-        regsub -all { } $label {_} label
-        set elemSize [numComponents $cname]
-        set numValues [$_comp2unirect2d($cname) numpoints]
-        append out "# vtk DataFile Version 3.0\n"
-        append out "[hints label]\n"
-        append out "ASCII\n"
-        append out [$_comp2unirect2d($cname) vtkdata]
-        append out "POINT_DATA $numValues\n"
-        if {$elemSize == 3} {
-            append out "VECTORS $label double\n"
-        } else {
-            append out "SCALARS $label double $elemSize\n"
-            append out "LOOKUP_TABLE default\n"
-        }
-        # values for VTK are x-fastest
-        append out $_values
-        append out "\n"
-        return $out
-    }
-    # unirect3d (deprecated)
-    if {[info exists _comp2unirect3d($cname)]} {
-        set vector [$_comp2unirect3d($cname) values]
-        set label $cname
-        regsub -all { } $label {_} label
-        set elemSize [numComponents $cname]
-        set numValues [expr [$vector length] / $elemSize]
-        append out "# vtk DataFile Version 3.0\n"
-        append out "[hints label]\n"
-        append out "ASCII\n"
-        append out [$_comp2unirect3d($cname) vtkdata]
-        append out "POINT_DATA $numValues\n"
-        if {$elemSize == 3} {
-            append out "VECTORS $label double\n"
-        } else {
-            append out "SCALARS $label double $elemSize\n"
-            append out "LOOKUP_TABLE default\n"
-        }
-        # values for VTK are x-fastest
-        append out [$vector range 0 end]
-        append out "\n"
-        return $out
     }
     # Points on mesh:  Construct VTK file output.
@@ -1458,63 +1373,4 @@
     lappend _comp2fldName($cname) $name
 
-    # Handle bizarre cases that are due to be removed.
-    if { $element == "unirect3d" } {
-        # Special case: unirect3d (deprecated) + flow.
-        set vectorsize [numComponents $cname]
-        set _type unirect3d
-        set _dim 3
-        if { $_viewer == "" } {
-            set _viewer flowvis
-        }
-        set _comp2dims($cname) "3D"
-        set _comp2unirect3d($cname) \
-            [Rappture::Unirect3d \#auto $_xmlobj $_field $cname $vectorsize]
-        set _comp2style($cname) [$_field get $cname.style]
-        set limits {}
-        foreach axis { x y z } {
-            lappend limits $axis [$_comp2unirect3d($cname) limits $axis]
-        }
-        # Get the data limits
-        set vector [$_comp2unirect3d($cname) values]
-        set minmax [VectorLimits $vector $vectorsize]
-        lappend limits $cname $minmax
-        lappend limits v      $minmax
-        set _comp2limits($cname) $limits
-        if {[$_field element $cname.flow] != ""} {
-            set _comp2flowhints($cname) \
-                [Rappture::FlowHints ::\#auto $_field $cname $_units]
-        }
-        incr _counter
-        return 1
-    }
-    if { $element == "unirect2d" && [$_field element $cname.flow] != "" } {
-        # Special case: unirect2d (deprecated) + flow.
-        set vectorsize [numComponents $cname]
-        set _type unirect2d
-        set _dim 2
-        if { $_viewer == "" } {
-            set _viewer "flowvis"
-        }
-        set _comp2dims($cname) "2D"
-        set _comp2unirect2d($cname) \
-            [Rappture::Unirect2d \#auto $_xmlobj $path]
-        set _comp2style($cname) [$_field get $cname.style]
-        set _comp2flowhints($cname) \
-            [Rappture::FlowHints ::\#auto $_field $cname $_units]
-        set _values [$_field get $cname.values]
-        set limits {}
-        foreach axis { x y z } {
-            lappend limits $axis [$_comp2unirect2d($cname) limits $axis]
-        }
-        set xv [blt::vector create \#auto]
-        $xv set $_values
-        set minmax [VectorLimits $xv $vectorsize]
-        lappend limits $cname $minmax
-        lappend limits v $minmax
-        blt::vector destroy $xv
-        set _comp2limits($cname) $limits
-        incr _counter
-        return 1
-    }
     switch -- $element {
         "cloud" {
@@ -1532,4 +1388,8 @@
             set mesh [Rappture::Unirect2d::fetch $_xmlobj $path]
             set _type unirect2d
+        }
+        "unirect3d" {
+            set mesh [Rappture::Unirect3d::fetch $_xmlobj $path]
+            set _type unirect3d
         }
     }
Index: trunk/gui/scripts/unirect2d.tcl
===================================================================
--- trunk/gui/scripts/unirect2d.tcl	(revision 5610)
+++ trunk/gui/scripts/unirect2d.tcl	(revision 5611)
@@ -29,5 +29,4 @@
     public proc release {obj}
 
-    public method blob {}
     public method dimensions {} {
         return 2
@@ -49,5 +48,4 @@
     private method GetSize { obj path varName }
 
-    private variable _axisOrder  "x y"
     private variable _xMax       0
     private variable _xMin       0
@@ -125,9 +123,7 @@
     GetSize $m "yaxis.numpoints" _yNum
     foreach {key path} {
-        group   about.group
         label   about.label
         color   about.color
         style   about.style
-        type    about.type
         xlabel  xaxis.label
         xdesc   xaxis.description
@@ -182,16 +178,4 @@
 
 # ----------------------------------------------------------------------
-# method blob
-#       Returns a Tcl list that represents the Tcl command and data to
-#       recreate the uniform rectangular grid on the nanovis server.
-# ----------------------------------------------------------------------
-itcl::body Rappture::Unirect2d::blob {} {
-    set data "unirect2d"
-    lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum
-    lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum
-    return $data
-}
-
-# ----------------------------------------------------------------------
 # method limits <axis>
 #       Returns a list {min max} representing the limits for the
Index: trunk/gui/scripts/unirect3d.tcl
===================================================================
--- trunk/gui/scripts/unirect3d.tcl	(revision 5610)
+++ trunk/gui/scripts/unirect3d.tcl	(revision 5611)
@@ -2,5 +2,5 @@
 
 # ----------------------------------------------------------------------
-#  COMPONENT: unirect3d - represents a uniform rectangular 2-D mesh.
+#  COMPONENT: unirect3d - represents a uniform rectangular 3-D mesh.
 #
 #  This object represents one field in an XML description of a device.
@@ -20,5 +20,5 @@
 
 itcl::class Rappture::Unirect3d {
-    constructor {xmlobj field cname {numComponents 1}} {
+    constructor {xmlobj path} {
         # defined below
     }
@@ -26,6 +26,7 @@
         # defined below
     }
-
-    public method blob {}
+    public proc fetch {xmlobj path}
+    public proc release {obj}
+
     public method dimensions {} {
         return 3
@@ -40,9 +41,5 @@
         return $_numPoints
     }
-    public method order {} {
-        return _axisOrder;
-    }
     public method units { axis }
-    public method values {}
     public method vtkdata {{what -partial}} {}
 
@@ -51,5 +48,4 @@
     private method GetSize { obj path varName }
 
-    private variable _axisOrder  "x y z"
     private variable _xMax       0
     private variable _xMin       0
@@ -61,10 +57,56 @@
     private variable _zMin       0
     private variable _zNum       0;     # Number of points along z-axis
-    private variable _compNum    1;     # Number of components in values
-    private variable _values     "";    # BLT vector containing the values
     private variable _hints
     private variable _vtkdata    ""
     private variable _numPoints  0
     private variable _isValid    0;     # Indicates if the data is valid.
+
+    private common _xp2obj       ;      # used for fetch/release ref counting
+    private common _obj2ref      ;      # used for fetch/release ref counting
+}
+
+#
+# fetch <xmlobj> <path>
+#
+#    Clients use this instead of a constructor to fetch the Mesh for a
+#    particular <path> in the <xmlobj>.  When the client is done with the mesh,
+#    he calls "release" to decrement the reference count.  When the mesh is no
+#    longer needed, it is cleaned up automatically.
+#
+itcl::body Rappture::Unirect3d::fetch {xmlobj path} {
+    set handle "$xmlobj|$path"
+    if {[info exists _xp2obj($handle)]} {
+        set obj $_xp2obj($handle)
+        incr _obj2ref($obj)
+        return $obj
+    }
+    set obj [Rappture::Unirect3d ::#auto $xmlobj $path]
+    set _xp2obj($handle) $obj
+    set _obj2ref($obj) 1
+    return $obj
+}
+
+# ----------------------------------------------------------------------
+# USAGE: Rappture::Unirect3d::release <obj>
+#
+# Clients call this when they're no longer using a Mesh fetched
+# previously by the "fetch" proc.  This decrements the reference
+# count for the mesh and destroys the object when it is no longer
+# in use.
+# ----------------------------------------------------------------------
+itcl::body Rappture::Unirect3d::release { obj } {
+    if { ![info exists _obj2ref($obj)] } {
+        error "can't find reference count for $obj"
+    }
+    incr _obj2ref($obj) -1
+    if {$_obj2ref($obj) <= 0} {
+        unset _obj2ref($obj)
+        foreach handle [array names _xp2obj] {
+            if {$_xp2obj($handle) == $obj} {
+                unset _xp2obj($handle)
+            }
+        }
+        itcl::delete object $obj
+    }
 }
 
@@ -72,9 +114,8 @@
 # Constructor
 # ----------------------------------------------------------------------
-itcl::body Rappture::Unirect3d::constructor {xmlobj field cname {numComponents 1}} {
+itcl::body Rappture::Unirect3d::constructor {xmlobj path} {
     if {![Rappture::library isvalid $xmlobj]} {
         error "bad value \"$xmlobj\": should be Rappture::library"
     }
-    set path [$field get $cname.mesh]
     set m [$xmlobj element -as object $path]
     GetValue $m "xaxis.min" _xMin
@@ -87,11 +128,8 @@
     GetSize $m "yaxis.numpoints" _yNum
     GetSize $m "zaxis.numpoints" _zNum
-    set _compNum $numComponents
     foreach {key path} {
-        group   about.group
         label   about.label
         color   about.color
         style   about.style
-        type    about.type
         xlabel  xaxis.label
         xdesc   xaxis.description
@@ -112,13 +150,6 @@
         zmin    zaxis.min
         zmax    zaxis.max
-        order   about.axisorder
     } {
         set str [$m get $path]
-        if {"" != $str} {
-            set _hints($key) $str
-        }
-    }
-    foreach {key} { axisorder } {
-        set str [$field get $cname.$key]
         if {"" != $str} {
             set _hints($key) $str
@@ -130,10 +161,4 @@
         set _vtkdata ""
         return
-    }
-    set _values [blt::vector create #auto]
-    $_values set [$field get "$cname.values"]
-    set n [expr $_numPoints * $_compNum]
-    if { [$_values length] != $n } {
-        error "wrong \# of values in \"$cname.values\": expected $n values, got [$_values length]"
     }
     append out "DATASET STRUCTURED_POINTS\n"
@@ -165,32 +190,5 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::Unirect3d::destructor {} {
-    if { $_values != "" } {
-        blt::vector destroy $_values
-    }
-}
-
-# ----------------------------------------------------------------------
-# method blob
-#       Returns a Tcl list that represents the Tcl command and data to
-#       recreate the uniform rectangular grid on the nanovis server.
-# ----------------------------------------------------------------------
-itcl::body Rappture::Unirect3d::blob {} {
-    set data "unirect3d"
-    lappend data "xmin" $_xMin "xmax" $_xMax "xnum" $_xNum
-    lappend data "ymin" $_yMin "ymax" $_yMax "ynum" $_yNum
-    lappend data "zmin" $_zMin "zmax" $_zMax "znum" $_zNum
-    lappend data "axisorder" $_axisOrder
-    if { [$_values length] > 0 } {
-        lappend data "values" [$_values range 0 end]
-    }
-    return $data
-}
-
-# ----------------------------------------------------------------------
-# method values
-#       Returns a BLT vector that represents the field values
-# ----------------------------------------------------------------------
-itcl::body Rappture::Unirect3d::values {} {
-    return $_values
+    # empty
 }
 
@@ -217,13 +215,4 @@
             set max $_zMax
         }
-        v - vlin - vlog {
-            if { [$_values length] > 0 } {
-               set min [blt::vector expr min($_values)]
-               set max [blt::vector expr max($_values)]
-            } else {
-                set min 0.0
-                set max 1.0
-            }
-        }
         default {
             error "unknown axis description \"$which\""
@@ -277,5 +266,4 @@
         set _hints(ylabel) "$_hints(zlabel) ($_hints(zunits))"
     }
-
     if {[info exists _hints(group)] && [info exists _hints(label)]} {
         # pop-up help for each curve
