Index: /tags/1.3.5/gui/scripts/vtkisosurfaceviewer.tcl
===================================================================
--- /tags/1.3.5/gui/scripts/vtkisosurfaceviewer.tcl	(revision 4751)
+++ /tags/1.3.5/gui/scripts/vtkisosurfaceviewer.tcl	(revision 4752)
@@ -57,5 +57,4 @@
     public method get {args}
     public method isconnected {}
-    public method limits { colormap }
     public method parameters {title args} { 
         # do nothing 
@@ -63,21 +62,7 @@
     public method scale {args}
 
-    protected method Connect {}
-    protected method CurrentDatasets {args}
-    protected method Disconnect {}
-    protected method DoResize {}
-    protected method DoRotate {}
-    protected method AdjustSetting {what {value ""}}
-    protected method InitSettings { args  }
-    protected method Pan {option x y}
-    protected method Pick {x y}
-    protected method Rebuild {}
-    protected method ReceiveDataset { args }
-    protected method ReceiveImage { args }
-    protected method ReceiveLegend { colormap title vmin vmax size }
-    protected method Rotate {option x y}
-    protected method Zoom {option}
-
     # The following methods are only used by this class.
+
+    private method AdjustSetting {what {value ""}}
     private method BuildAxisTab {}
     private method BuildCameraTab {}
@@ -87,23 +72,43 @@
     private method BuildIsosurfaceTab {}
     private method Combo { option }
+    private method Connect {}
+    private method CurrentDatasets {args}
+    private method Disconnect {}
+    private method DoChangeContourLevels {}
+    private method DoResize {}
+    private method DoRotate {}
     private method DrawLegend {}
     private method EnterLegend { x y } 
+    private method EventuallyChangeContourLevels {} 
+    private method EventuallyRequestLegend {} 
     private method EventuallyResize { w h } 
     private method EventuallyRotate { q } 
-    private method EventuallyRequestLegend {} 
     private method EventuallySetCutplane { axis args } 
+    private method GenerateContourList {}
     private method GetImage { args } 
     private method GetVtkData { args } 
+    private method InitSettings { args  }
     private method IsValidObject { dataobj } 
     private method LeaveLegend {}
     private method MotionLegend { x y } 
+    private method Pan {option x y}
     private method PanCamera {}
+    private method Pick {x y}
+    private method Rebuild {}
+    private method ReceiveDataset { args }
+    private method ReceiveImage { args }
+    private method ReceiveLegend { colormap title vmin vmax size }
     private method RequestLegend {}
+    private method Rotate {option x y}
+    private method SetCurrentColormap { color }
+    private method SetCurrentFieldName { dataobj }
     private method SetLegendTip { x y }
-    private method SetObjectStyle { dataobj comp } 
-    private method Slice {option args} 
-    private method SetCurrentColormap { color }
+    private method SetObjectStyle { dataobj comp }
     private method SetOrientation { side }
-    private method UpdateContourList {}
+    private method Slice {option args}
+    private method Zoom {option}
+    private method ViewToQuaternion {} { 
+        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
+    }
 
     private variable _arcball ""
@@ -120,5 +125,4 @@
     private variable _currentColormap ""
     private variable _currentNumContours -1
-    private variable _currentOpacity ""
 
     private variable _dataset2style    ;# maps dataobj-component to transfunc
@@ -138,5 +142,7 @@
     private variable _title ""
     private variable _isolines
-    private variable _contourList ""
+    private variable _contourList
+    private variable _currentLimits ""
+    private variable _widget
 
     common _downloadPopup;              # download options from popup
@@ -184,4 +190,9 @@
     $_dispatcher dispatch $this !legend "[itcl::code $this RequestLegend]; list"
 
+    # Contour levels event
+    $_dispatcher register !contours
+    $_dispatcher dispatch $this !contours \
+        "[itcl::code $this DoChangeContourLevels]; list"
+
     # X-Cutplane event
     $_dispatcher register !xcutplane
@@ -208,53 +219,65 @@
     # Initialize the view to some default parameters.
     array set _view {
-        qw              0.853553
-        qx              -0.353553
-        qy              0.353553
-        qz              0.146447
-        zoom            1.0 
-        xpan            0
-        ypan            0
-        ortho           0
+        -ortho           0
+        -qw              0.853553
+        -qx              -0.353553
+        -qy              0.353553
+        -qz              0.146447
+        -xpan            0
+        -ypan            0
+        -zoom            1.0 
     }
     set _arcball [blt::arcball create 100 100]
-    set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
-    $_arcball quaternion $q
-
+    $_arcball quaternion [ViewToQuaternion]
+
+    array set _contourList {
+        numLevels       10
+        reqValues       ""
+        updatePending   0
+        values          ""
+    }
     array set _settings {
         -axesvisible                    1
-        -axislabelsvisible              1
-	-background                     black
-	-colormap                       BCGYR
-	-colormapvisible                1
+        -axislabels                     1
+        -axisminorticks                 1
+        -axismode                       "static"
+        -background                     black
+        -colormap                       BCGYR
+        -colormapvisible                1
         -cutplaneedges                  0
         -cutplanelighting               1
-        -cutplaneopacity                100
+        -cutplaneopacity                1.0
         -cutplanepreinterp              1
         -cutplanesvisible               0
         -cutplanewireframe              0
-	-field                          "Default"
-	-isolinecolor                   white
+        -field                          "Default"
+        -isolinecolor                   white
         -isosurfaceedges                0
         -isosurfacelighting             1
-        -isosurfaceopacity              60
-        -isosurfaceoutline              0
+        -isosurfaceopacity              0.6
         -isosurfacevisible              1
         -isosurfacewireframe            0
         -legendvisible                  1
         -numcontours                    10
-        -xaxisgrid                      0
+        -outline                        0
         -xcutplaneposition              50
         -xcutplanevisible               1
-        -yaxisgrid                      0
+        -xgrid                          0
         -ycutplaneposition              50
         -ycutplanevisible               1
-        -zaxisgrid                      0
+        -ygrid                          0
         -zcutplaneposition              50
         -zcutplanevisible               1
+        -zgrid                          0
     }
     array set _changed {
+        -colormap                0
         -isosurfaceopacity       0
-        -colormap                0
+        -cutplaneopacity         0
         -numcontours             0
+    }
+    array set _widget {
+        -isosurfaceopacity       60
+        -cutplaneopacity         100
     }
 
@@ -341,5 +364,5 @@
     $itk_component(contour) select
     Rappture::Tooltip::for $itk_component(contour) \
-        "Don't display the isosurface"
+        "Hide the isosurface"
     pack $itk_component(contour) -padx 2 -pady 2
 
@@ -352,5 +375,5 @@
     }
     Rappture::Tooltip::for $itk_component(cutplane) \
-        "Show/Hide cutplanes"
+        "Show the cutplanes"
     pack $itk_component(cutplane) -padx 2 -pady 2
 
@@ -441,5 +464,4 @@
     EnableWaitDialog 500
     Connect
-    update
 }
 
@@ -468,7 +490,14 @@
 }
 
+itcl::body Rappture::VtkIsosurfaceViewer::DoChangeContourLevels {} {
+    GenerateContourList
+    SendCmd [list contour3d contourlist $_contourList(values)]
+    SendCmd [list camera reset]
+    DrawLegend
+    set _contourList(updatePending) 0
+}
+
 itcl::body Rappture::VtkIsosurfaceViewer::DoRotate {} {
-    set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
-    SendCmd "camera orient $q" 
+    SendCmd "camera orient [ViewToQuaternion]" 
     set _rotatePending 0
 }
@@ -494,5 +523,5 @@
 
 itcl::body Rappture::VtkIsosurfaceViewer::EventuallyRotate { q } {
-    foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
+    foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
     if { !$_rotatePending } {
         set _rotatePending 1
@@ -506,4 +535,14 @@
         set _cutplanePending 1
         $_dispatcher event -after 100 !${axis}cutplane
+    }
+}
+
+itcl::body Rappture::VtkIsosurfaceViewer::EventuallyChangeContourLevels {} {
+    set n $_contourList(numLevels)
+    set _contourList(values) ""
+    if { !$_contourList(updatePending) } {
+        set _contourList(updatePending) 1
+        global rotate_delay 
+        $_dispatcher event -after $rotate_delay !contours
     }
 }
@@ -784,4 +823,7 @@
                 set session $env(SESSION)
             }
+            lappend info "version" "$Rappture::version"
+            lappend info "build" "$Rappture::build"
+            lappend info "installdir" "$Rappture::installdir"
             lappend info "hub" [exec hostname]
             lappend info "client" "vtkisosurfaceviewer"
@@ -833,10 +875,9 @@
     # disconnected -- no more data sitting on server
     set _outbuf ""
-    array unset _datasets 
-    array unset _data 
-    array unset _colormaps 
-    array unset _seeds 
-    array unset _dataset2style 
-    array unset _obj2datasets 
+    array unset _datasets
+    array unset _data
+    array unset _colormaps
+    array unset _dataset2style
+    array unset _obj2datasets
 }
 
@@ -940,5 +981,4 @@
     # generates a new call to Rebuild).   
     StartBufferingCommands
-
     if { $_reset } {
         set _width $w
@@ -946,22 +986,15 @@
         $_arcball resize $w $h
         DoResize
-        #
+
         # Reset the camera and other view parameters
-        #
-        set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
-        $_arcball quaternion $q
-        if {$_view(ortho)} {
-            SendCmd "camera mode ortho"
-        } else {
-            SendCmd "camera mode persp"
-        }
+        $_arcball quaternion [ViewToQuaternion]
+        InitSettings -ortho
         DoRotate
         PanCamera
         set _first ""
-        InitSettings -xaxisgrid -yaxisgrid -zaxisgrid -axismode \
-            -axesvisible -axislabelsvisible 
-        foreach axis { x y z } {
-	    SendCmd "axis lformat $axis %g"
-	}
+        InitSettings -background \
+            -xgrid -ygrid -zgrid -axismode \
+            -axesvisible -axislabels -axisminorticks
+        #SendCmd "axis lformat all %g"
         StopBufferingCommands
         SendCmd "imgflush"
@@ -969,8 +1002,10 @@
     }
     set _first ""
-    SendCmd "contour3d visible 0"
+    SendCmd "dataset visible 0"
+    eval scale $_dlist
     foreach dataobj [get -objects] {
         if { [info exists _obj2ovride($dataobj-raise)] &&  $_first == "" } {
             set _first $dataobj
+            SetCurrentFieldName $dataobj
         }
         set _obj2datasets($dataobj) ""
@@ -987,8 +1022,9 @@
                 if { $_reportClientInfo }  {
                     set info {}
-                    lappend info "tool_id"       [$dataobj hints toolId]
-                    lappend info "tool_name"     [$dataobj hints toolName]
-                    lappend info "tool_version"  [$dataobj hints toolRevision]
-                    lappend info "tool_title"    [$dataobj hints toolTitle]
+                    lappend info "tool_id"       [$dataobj hints toolid]
+                    lappend info "tool_name"     [$dataobj hints toolname]
+                    lappend info "tool_title"    [$dataobj hints tooltitle]
+                    lappend info "tool_command"  [$dataobj hints toolcommand]
+                    lappend info "tool_revision" [$dataobj hints toolrevision]
                     lappend info "dataset_label" [$dataobj hints label]
                     lappend info "dataset_size"  $length
@@ -996,5 +1032,5 @@
                     SendCmd "clientinfo [list $info]"
                 }
-                append _outbuf "dataset add $tag data follows $length\n"
+                SendCmd "dataset add $tag data follows $length"
                 append _outbuf $bytes
                 set _datasets($tag) 1
@@ -1003,6 +1039,4 @@
             lappend _obj2datasets($dataobj) $tag
             if { [info exists _obj2ovride($dataobj-raise)] } {
-                # Setting dataset visible enables outline
-                # and contour3d
 		SendCmd "contour3d visible 1 $tag"
             }
@@ -1010,34 +1044,5 @@
     }
 
-    if { $_first != "" } {
-	$itk_component(field) choices delete 0 end
-	$itk_component(fieldmenu) delete 0 end
-	array unset _fields
-        set _curFldName ""
-        foreach cname [$_first components] {
-            foreach fname [$_first fieldnames $cname] {
-                if { [info exists _fields($fname)] } {
-                    continue
-                }
-                foreach { label units components } \
-                    [$_first fieldinfo $fname] break
-                $itk_component(field) choices insert end "$fname" "$label"
-                $itk_component(fieldmenu) add radiobutton -label "$label" \
-                    -value $label -variable [itcl::scope _curFldLabel] \
-                    -selectcolor red \
-                    -activebackground $itk_option(-plotbackground) \
-                    -activeforeground $itk_option(-plotforeground) \
-                    -font "Arial 8" \
-                    -command [itcl::code $this Combo invoke]
-                set _fields($fname) [list $label $units $components]
-                if { $_curFldName == "" } {
-                    set _curFldName $fname
-                    set _curFldLabel $label
-                }
-            }
-        }
-        $itk_component(field) value $_curFldLabel
-    }
-    InitSettings -cutplanesvisible -isosurfacevisible -isosurfaceoutline
+    InitSettings -cutplanesvisible -isosurfacevisible -outline
     if { $_reset } {
 	# These are settings that rely on a dataset being loaded.
@@ -1062,12 +1067,14 @@
                 set label [string toupper $axis]
 	    }
-	    # May be a space in the axis label.
 	    SendCmd [list axis name $axis $label]
         }
         if { [array size _fields] < 2 } {
-            blt::table forget $itk_component(field) $itk_component(field_l)
+            catch {blt::table forget $itk_component(field) $itk_component(field_l)}
         }
         set _reset 0
     }
+    # Redraw the legend even if we're using the same colormap. The position
+    # of the isolines may have changed because the range of data changed.
+    DrawLegend
 
     # Actually write the commands to the server socket.  If it fails, we don't
@@ -1134,20 +1141,20 @@
     switch -- $option {
         "in" {
-            set _view(zoom) [expr {$_view(zoom)*1.25}]
-            SendCmd "camera zoom $_view(zoom)"
+            set _view(-zoom) [expr {$_view(-zoom)*1.25}]
+            SendCmd "camera zoom $_view(-zoom)"
         }
         "out" {
-            set _view(zoom) [expr {$_view(zoom)*0.8}]
-            SendCmd "camera zoom $_view(zoom)"
+            set _view(-zoom) [expr {$_view(-zoom)*0.8}]
+            SendCmd "camera zoom $_view(-zoom)"
         }
         "reset" {
             array set _view {
-                qw     0.853553
-                qx     -0.353553
-                qy     0.353553
-                qz     0.146447
-                zoom   1.0
-                xpan   0
-                ypan   0
+                -qw     0.853553
+                -qx     -0.353553
+                -qy     0.353553
+                -qz     0.146447
+                -xpan   0
+                -ypan   0
+                -zoom   1.0
             }
             if { $_first != "" } {
@@ -1157,6 +1164,5 @@
                 }
             }
-            set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
-            $_arcball quaternion $q
+            $_arcball quaternion [ViewToQuaternion]
             DoRotate
             SendCmd "camera reset"
@@ -1166,6 +1172,6 @@
 
 itcl::body Rappture::VtkIsosurfaceViewer::PanCamera {} {
-    set x $_view(xpan)
-    set y $_view(ypan)
+    set x $_view(-xpan)
+    set y $_view(-ypan)
     SendCmd "camera pan $x $y"
 }
@@ -1245,6 +1251,6 @@
             set x [expr $x / double($w)]
             set y [expr $y / double($h)]
-            set _view(xpan) [expr $_view(xpan) + $x]
-            set _view(ypan) [expr $_view(ypan) + $y]
+            set _view(-xpan) [expr $_view(-xpan) + $x]
+            set _view(-ypan) [expr $_view(-ypan) + $y]
             PanCamera
             return
@@ -1268,6 +1274,6 @@
             set _click(x) $x
             set _click(y) $y
-            set _view(xpan) [expr $_view(xpan) - $dx]
-            set _view(ypan) [expr $_view(ypan) - $dy]
+            set _view(-xpan) [expr $_view(-xpan) - $dx]
+            set _view(-ypan) [expr $_view(-ypan) - $dy]
             PanCamera
         }
@@ -1311,4 +1317,22 @@
     }
     switch -- $what {
+        "-axesvisible" {
+            set bool $_settings($what)
+            SendCmd "axis visible all $bool"
+        }
+        "-axislabels" {
+            set bool $_settings($what)
+            SendCmd "axis labels all $bool"
+        }
+        "-axisminorticks" {
+            set bool $_settings($what)
+            SendCmd "axis minticks all $bool"
+        }
+        "-axismode" {
+            set mode [$itk_component(axisMode) value]
+            set mode [$itk_component(axisMode) translate $mode]
+            set _settings($what) $mode
+            SendCmd "axis flymode $mode"
+        }
         "-background" {
             set bgcolor [$itk_component(background) value]
@@ -1323,30 +1347,35 @@
 	    DrawLegend
         }
-        "-axesvisible" {
-            set bool $_settings(-axesvisible)
-            SendCmd "axis visible all $bool"
-        }
-        "-axislabelsvisible" {
-            set bool $_settings(-axislabelsvisible)
-            SendCmd "axis labels all $bool"
-        }
-        "-xaxisgrid" - "-yaxisgrid" - "-zaxisgrid" {
-            set axis [string tolower [string range $what 1 1]]
-            set bool $_settings($what)
-            SendCmd "axis grid $axis $bool"
-        }
-        "-axismode" {
-            set mode [$itk_component(axisMode) value]
-            set mode [$itk_component(axisMode) translate $mode]
-            set _settings($what) $mode
-            SendCmd "axis flymode $mode"
-        }
         "-cutplaneedges" {
             set bool $_settings($what)
             SendCmd "cutplane edges $bool"
         }
+        "-cutplanelighting" {
+            set bool $_settings($what)
+            SendCmd "cutplane lighting $bool"
+        }
+        "-cutplaneopacity" {
+            set _settings($what) [expr $_widget($what) * 0.01]
+            SendCmd "cutplane opacity $_settings($what)"
+        }
+        "-cutplanepreinterp" {
+            set bool $_settings($what)
+            SendCmd "cutplane preinterp $bool"
+        }
         "-cutplanesvisible" {
             set bool $_settings($what)
-            SendCmd "cutplane visible $bool"
+	    SendCmd "cutplane visible 0"
+            if { $bool } {
+                foreach tag [CurrentDatasets -visible] {
+                    SendCmd "cutplane visible $bool $tag"
+                }
+            }
+            if { $bool } {
+                Rappture::Tooltip::for $itk_component(cutplane) \
+                    "Hide the cutplanes"
+            } else {
+                Rappture::Tooltip::for $itk_component(cutplane) \
+                    "Show the cutplanes"
+            }
         }
         "-cutplanewireframe" {
@@ -1354,40 +1383,9 @@
             SendCmd "cutplane wireframe $bool"
         }
-        "-cutplanelighting" {
-            set bool $_settings($what)
-            SendCmd "cutplane lighting $bool"
-        }
-        "-cutplaneopacity" {
-            set val $_settings($what)
-            set sval [expr { 0.01 * double($val) }]
-            SendCmd "cutplane opacity $sval"
-        }
-        "-cutplanepreinterp" {
-            set bool $_settings($what)
-            SendCmd "cutplane preinterp $bool"
-        }
-        "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
-            set axis [string tolower [string range $what 1 1]]
-            set bool $_settings($what)
-            if { $bool } {
-                $itk_component(${axis}position) configure -state normal \
-                    -troughcolor white
-            } else {
-                $itk_component(${axis}position) configure -state disabled \
-                    -troughcolor grey82
-            }
-	    SendCmd "cutplane axis $axis $bool"
-        }
-        "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" {
-            set axis [string tolower [string range $what 1 1]]
-            set pos [expr $_settings($what) * 0.01]
-            SendCmd "cutplane slice ${axis} ${pos}"
-            set _cutplanePending 0
-        }
         "-colormap" {
-            set _changed(-colormap) 1
+            set _changed($what) 1
             StartBufferingCommands
             set color [$itk_component(colormap) value]
-            set _settings(-colormap) $color
+            set _settings($what) $color
 	    if { $color == "none" } {
 		if { $_settings(-colormapvisible) } {
@@ -1405,55 +1403,4 @@
 	    EventuallyRequestLegend
         }
-        "-numcontours" {
-            set _settings($what) [$itk_component(numcontours) value]
-            set _currentNumContours $_settings($what)
-            UpdateContourList
-            set _changed($what) 1
-            SendCmd "contour3d contourlist [list $_contourList]"
-            DrawLegend
-        }
-        "-isosurfacewireframe" {
-            set bool $_settings($what)
-	    SendCmd "contour3d wireframe $bool"
-        }
-        "-isosurfacevisible" {
-            set bool $_settings($what)
-	    SendCmd "contour3d visible 0"
-            if { $bool } {
-                foreach tag [CurrentDatasets -visible] {
-                    SendCmd "contour3d visible $bool $tag"
-                }
-            }
-            if { $bool } {
-                Rappture::Tooltip::for $itk_component(contour) \
-                    "Hide the isosurface"
-            } else {
-                Rappture::Tooltip::for $itk_component(contour) \
-                    "Show the isosurface"
-            }
-	    DrawLegend
-        }
-        "-isosurfacelighting" {
-            set bool $_settings($what)
-	    SendCmd "contour3d lighting $bool"
-        }
-        "-isosurfaceedges" {
-            set bool $_settings($what)
-	    SendCmd "contour3d edges $bool"
-        }
-        "-isosurfaceoutline" {
-            set bool $_settings($what)
-	    SendCmd "outline visible $bool"
-        }
-        "-isolinecolor" {
-            set color [$itk_component(isolineColor) value]
-	    set _settings($what) $color
-	    DrawLegend
-        }
-        "-isosurfaceopacity" {
-            set val $_settings($what)
-            set sval [expr { 0.01 * double($val) }]
-	    SendCmd "contour3d opacity $sval"
-        }
         "-field" {
             set label [$itk_component(field) value]
@@ -1482,6 +1429,43 @@
             SendCmd "contour3d colormode $_colorMode $_curFldName"
             SendCmd "camera reset"
-            UpdateContourList
+            GenerateContourList
             DrawLegend
+        }
+        "-isolinecolor" {
+            set color [$itk_component(isolineColor) value]
+	    set _settings($what) $color
+	    DrawLegend
+        }
+        "-isosurfaceedges" {
+            set bool $_settings($what)
+	    SendCmd "contour3d edges $bool"
+        }
+        "-isosurfacelighting" {
+            set bool $_settings($what)
+	    SendCmd "contour3d lighting $bool"
+        }
+        "-isosurfaceopacity" {
+            set _settings($what) [expr $_widget($what) * 0.01]
+	    SendCmd "contour3d opacity $_settings($what)"
+        }
+        "-isosurfacevisible" {
+            set bool $_settings($what)
+	    SendCmd "contour3d visible 0"
+            if { $bool } {
+                foreach tag [CurrentDatasets -visible] {
+                    SendCmd "contour3d visible $bool $tag"
+                }
+            }
+            if { $bool } {
+                Rappture::Tooltip::for $itk_component(contour) \
+                    "Hide the isosurface"
+            } else {
+                Rappture::Tooltip::for $itk_component(contour) \
+                    "Show the isosurface"
+            }
+        }
+        "-isosurfacewireframe" {
+            set bool $_settings($what)
+	    SendCmd "contour3d wireframe $bool"
         }
         "-legendvisible" {
@@ -1490,4 +1474,51 @@
 	    }
 	    DrawLegend
+        }
+        "-numcontours" {
+            set _settings($what) [$itk_component(numcontours) value]
+            if { $_contourList(numLevels) != $_settings($what) } {
+                set _contourList(numLevels) $_settings($what)
+                EventuallyChangeContourLevels
+            }
+        }
+        "-ortho" {
+            set bool $_view($what)
+            if { $bool } {
+                SendCmd "camera mode ortho"
+            } else {
+                SendCmd "camera mode persp"
+            }
+        }
+        "-outline" {
+            set bool $_settings($what)
+	    SendCmd "outline visible 0"
+            if { $bool } {
+                foreach tag [CurrentDatasets -visible] {
+                    SendCmd "outline visible $bool $tag"
+                }
+            }
+        }
+        "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
+            set axis [string tolower [string range $what 1 1]]
+            set bool $_settings($what)
+            if { $bool } {
+                $itk_component(${axis}position) configure -state normal \
+                    -troughcolor white
+            } else {
+                $itk_component(${axis}position) configure -state disabled \
+                    -troughcolor grey82
+            }
+	    SendCmd "cutplane axis $axis $bool"
+        }
+        "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" {
+            set axis [string tolower [string range $what 1 1]]
+            set pos [expr $_settings($what) * 0.01]
+            SendCmd "cutplane slice ${axis} ${pos}"
+            set _cutplanePending 0
+        }
+        "-xgrid" - "-ygrid" - "-zgrid" {
+            set axis [string tolower [string range $what 1 1]]
+            set bool $_settings($what)
+            SendCmd "axis grid $axis $bool"
         }
         default {
@@ -1569,12 +1600,4 @@
 }
 
-itcl::body Rappture::VtkIsosurfaceViewer::limits { dataobj } {
-    foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break
-    foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break
-    foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break
-    foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break
-    return [array get limits]
-}
-
 itcl::body Rappture::VtkIsosurfaceViewer::BuildIsosurfaceTab {} {
 
@@ -1613,6 +1636,6 @@
     checkbutton $inner.outline \
         -text "Outline" \
-        -variable [itcl::scope _settings(-isosurfaceoutline)] \
-        -command [itcl::code $this AdjustSetting -isosurfaceoutline] \
+        -variable [itcl::scope _settings(-outline)] \
+        -command [itcl::code $this AdjustSetting -outline] \
         -font "Arial 9"
 
@@ -1658,15 +1681,9 @@
     label $inner.opacity_l -text "Opacity" -font "Arial 9"
     ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
-        -variable [itcl::scope _settings(-isosurfaceopacity)] \
+        -variable [itcl::scope _widget(-isosurfaceopacity)] \
         -width 10 \
         -showvalue off \
         -command [itcl::code $this AdjustSetting -isosurfaceopacity]
-
-    label $inner.scale_l -text "Scale" -font "Arial 9"
-    ::scale $inner.scale -from 1 -to 100 -orient horizontal \
-        -variable [itcl::scope _settings(-contourscale)] \
-        -width 10 \
-        -showvalue off \
-        -command [itcl::code $this AdjustSetting -contourscale]
+    $inner.opacity set [expr $_settings(-isosurfaceopacity) * 100.0]
 
     itk_component add field_l {
@@ -1685,21 +1702,5 @@
         Rappture::Combobox $inner.colormap -width 10 -editable 0
     }
-    $inner.colormap choices insert end \
-        "BCGYR"              "BCGYR"            \
-        "BGYOR"              "BGYOR"            \
-        "blue"               "blue"             \
-        "blue-to-brown"      "blue-to-brown"    \
-        "blue-to-orange"     "blue-to-orange"   \
-        "blue-to-grey"       "blue-to-grey"     \
-        "green-to-magenta"   "green-to-magenta" \
-        "greyscale"          "greyscale"        \
-        "nanohub"            "nanohub"          \
-        "rainbow"            "rainbow"          \
-        "spectral"           "spectral"         \
-        "ROYGB"              "ROYGB"            \
-        "RYGCB"              "RYGCB"            \
-        "brown-to-blue"      "brown-to-blue"    \
-        "grey-to-blue"       "grey-to-blue"     \
-        "orange-to-blue"     "orange-to-blue"   
+    $inner.colormap choices insert end [GetColormapList]
 
     $itk_component(colormap) value "BCGYR"
@@ -1750,5 +1751,5 @@
 
     checkbutton $inner.visible \
-        -text "Show Axes" \
+        -text "Axes" \
         -variable [itcl::scope _settings(-axesvisible)] \
         -command [itcl::code $this AdjustSetting -axesvisible] \
@@ -1756,23 +1757,28 @@
 
     checkbutton $inner.labels \
-        -text "Show Axis Labels" \
-        -variable [itcl::scope _settings(-axislabelsvisible)] \
-        -command [itcl::code $this AdjustSetting -axislabelsvisible] \
+        -text "Axis Labels" \
+        -variable [itcl::scope _settings(-axislabels)] \
+        -command [itcl::code $this AdjustSetting -axislabels] \
         -font "Arial 9"
-
-    checkbutton $inner.gridx \
-        -text "Show X Grid" \
-        -variable [itcl::scope _settings(-xaxisgrid)] \
-        -command [itcl::code $this AdjustSetting -xaxisgrid] \
+    label $inner.grid_l -text "Grid" -font "Arial 9" 
+    checkbutton $inner.xgrid \
+        -text "X" \
+        -variable [itcl::scope _settings(-xgrid)] \
+        -command [itcl::code $this AdjustSetting -xgrid] \
         -font "Arial 9"
-    checkbutton $inner.gridy \
-        -text "Show Y Grid" \
-        -variable [itcl::scope _settings(-yaxisgrid)] \
-        -command [itcl::code $this AdjustSetting -yaxisgrid] \
+    checkbutton $inner.ygrid \
+        -text "Y" \
+        -variable [itcl::scope _settings(-ygrid)] \
+        -command [itcl::code $this AdjustSetting -ygrid] \
         -font "Arial 9"
-    checkbutton $inner.gridz \
-        -text "Show Z Grid" \
-        -variable [itcl::scope _settings(-zaxisgrid)] \
-        -command [itcl::code $this AdjustSetting -zaxisgrid] \
+    checkbutton $inner.zgrid \
+        -text "Z" \
+        -variable [itcl::scope _settings(-zgrid)] \
+        -command [itcl::code $this AdjustSetting -zgrid] \
+        -font "Arial 9"
+    checkbutton $inner.minorticks \
+        -text "Minor Ticks" \
+        -variable [itcl::scope _settings(-axisminorticks)] \
+        -command [itcl::code $this AdjustSetting -axisminorticks] \
         -font "Arial 9"
 
@@ -1787,18 +1793,21 @@
         "furthest_triad"  "farthest" \
         "outer_edges"     "outer"         
-    $itk_component(axisMode) value "static"
+    $itk_component(axisMode) value $_settings(-axismode)
     bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode]
 
     blt::table $inner \
-        0,0 $inner.visible -anchor w -cspan 2 \
-        1,0 $inner.labels  -anchor w -cspan 2 \
-        2,0 $inner.gridx   -anchor w -cspan 2 \
-        3,0 $inner.gridy   -anchor w -cspan 2 \
-        4,0 $inner.gridz   -anchor w -cspan 2 \
-        5,0 $inner.mode_l  -anchor w -cspan 2 -padx { 2 0 } \
-        6,0 $inner.mode    -fill x   -cspan 2 
+        0,0 $inner.visible -anchor w -cspan 4 \
+        1,0 $inner.labels  -anchor w -cspan 4 \
+        2,0 $inner.minorticks  -anchor w -cspan 4 \
+        4,0 $inner.grid_l  -anchor w \
+        4,1 $inner.xgrid   -anchor w \
+        4,2 $inner.ygrid   -anchor w \
+        4,3 $inner.zgrid   -anchor w \
+        5,0 $inner.mode_l  -anchor w -padx { 2 0 } \
+        5,1 $inner.mode    -fill x   -cspan 3
 
     blt::table configure $inner r* c* -resize none
-    blt::table configure $inner r7 c1 -resize expand
+    blt::table configure $inner r7 c6 -resize expand
+    blt::table configure $inner r3 -height 0.125i
 }
 
@@ -1822,4 +1831,5 @@
         0,0 $inner.view_l -anchor e -pady 2 \
         0,1 $inner.view -anchor w -pady 2
+    blt::table configure $inner r0 -resize none
 
     set labels { qx qy qz qw xpan ypan zoom }
@@ -1828,5 +1838,5 @@
         label $inner.${tag}label -text $tag -font "Arial 9"
         entry $inner.${tag} -font "Arial 9"  -bg white \
-            -textvariable [itcl::scope _view($tag)]
+            -textvariable [itcl::scope _view(-$tag)]
         bind $inner.${tag} <KeyPress-Return> \
             [itcl::code $this camera set ${tag}]
@@ -1839,6 +1849,6 @@
     checkbutton $inner.ortho \
         -text "Orthographic Projection" \
-        -variable [itcl::scope _view(ortho)] \
-        -command [itcl::code $this camera set ortho] \
+        -variable [itcl::scope _view(-ortho)] \
+        -command [itcl::code $this AdjustSetting -ortho] \
         -font "Arial 9"
     blt::table $inner \
@@ -1847,5 +1857,5 @@
     incr row
 
-    blt::table configure $inner c* r* -resize none
+    blt::table configure $inner c* -resize none
     blt::table configure $inner c2 -resize expand
     blt::table configure $inner r$row -resize expand
@@ -1894,9 +1904,9 @@
     label $inner.opacity_l -text "Opacity" -font "Arial 9"
     ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
-        -variable [itcl::scope _settings(-cutplaneopacity)] \
+        -variable [itcl::scope _widget(-cutplaneopacity)] \
         -width 10 \
         -showvalue off \
         -command [itcl::code $this AdjustSetting -cutplaneopacity]
-    $inner.opacity set $_settings(-cutplaneopacity)
+    $inner.opacity set [expr $_settings(-cutplaneopacity) * 100.0]
 
     # X-value slicer...
@@ -2019,13 +2029,13 @@
         }
         "set" {
-            set who [lindex $args 0]
-            set x $_view($who)
+            set what [lindex $args 0]
+            set x $_view($what)
             set code [catch { string is double $x } result]
             if { $code != 0 || !$result } {
                 return
             }
-            switch -- $who {
-                "ortho" {
-                    if {$_view(ortho)} {
+            switch -- $what {
+                "-ortho" {
+                    if {$_view($what)} {
                         SendCmd "camera mode ortho"
                     } else {
@@ -2033,14 +2043,14 @@
                     }
                 }
-                "xpan" - "ypan" {
+                "-xpan" - "-ypan" {
                     PanCamera
                 }
-                "qx" - "qy" - "qz" - "qw" {
-                    set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
+                "-qx" - "-qy" - "-qz" - "-qw" {
+                    set q [ViewToQuaternion]
                     $_arcball quaternion $q
                     EventuallyRotate $q
                 }
-                "zoom" {
-                    SendCmd "camera zoom $_view(zoom)"
+                "-zoom" {
+                    SendCmd "camera zoom $_view(-zoom)"
                 }
              }
@@ -2117,28 +2127,26 @@
     set tag $dataobj-$comp
     array set style {
-        -color BCGYR
-        -cutplanesvisible 0 
-        -edgecolor black
-        -edges 0
-        -isosurfacevisible 1
-        -levels 10
-        -lighting 1
-        -linewidth 1.0
-        -opacity 0.6
-        -outline 0
-        -wireframe 0
-        -xcutplaneposition 50
-        -xcutplanevisible 1
-        -ycutplaneposition 50
-        -ycutplanevisible 1
-        -zcutplaneposition 50
-        -zcutplanevisible 1
+        -color                  BCGYR
+        -cutplanesvisible       0 
+        -edgecolor              black
+        -edges                  0
+        -isosurfacevisible      1
+        -levels                 10
+        -lighting               1
+        -linewidth              1.0
+        -opacity                0.6
+        -outline                0
+        -wireframe              0
+        -xcutplaneposition      50
+        -xcutplanevisible       1
+        -ycutplaneposition      50
+        -ycutplanevisible       1
+        -zcutplaneposition      50
+        -zcutplanevisible       1
     }
     array set style [$dataobj style $comp]
     if { $dataobj != $_first || $style(-levels) == 1 } {
-        set style(-opacity) 1
-    }
-    SendCmd "cutplane add $tag"
-    SendCmd "cutplane visible 0 $tag"
+        set style(-opacity) 1.0
+    }
 
     # This is too complicated.  We want to set the colormap, number of
@@ -2164,11 +2172,13 @@
         $itk_component(colormap) value $style(-color)
     }
-    set _currentOpacity $style(-opacity)
-    if { $_currentNumContours != $style(-levels) } {
-        set _currentNumContours $style(-levels)
-        set _settings(-numcontours) $_currentNumContours
-        $itk_component(numcontours) value $_currentNumContours
-        UpdateContourList
-        DrawLegend
+    if { $_contourList(numLevels) != $style(-levels) } {
+        if { [llength $style(-levels)] > 1 } {
+            set _contourList(reqValues) [lsort -real $style(-levels)]
+        } else {
+            set _settings(-numcontours) $style(-levels)
+            $itk_component(numcontours) value $style(-levels)
+            set _contourList(numLevels) $style(-levels)
+        }
+        EventuallyChangeContourLevels 
     }
     set _settings(-isosurfacevisible) $style(-isosurfacevisible)
@@ -2181,10 +2191,17 @@
     set _settings(-zcutplaneposition) $style(-zcutplaneposition)
  
-    SendCmd [list contour3d add contourlist $_contourList $tag]
-    SendCmd "contour3d edges $style(-edges) $tag"
+    SendCmd "cutplane add $tag"
+    SendCmd "cutplane color [Color2RGB $itk_option(-plotforeground)] $tag"
+    SendCmd "cutplane visible $style(-cutplanesvisible) $tag"
+
     SendCmd "outline add $tag"
     SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag"
     SendCmd "outline visible $style(-outline) $tag"
-    set _settings(-isosurfaceoutline) $style(-outline)
+    set _settings(-outline) $style(-outline)
+ 
+    GenerateContourList
+    SendCmd [list contour3d add contourlist $_contourList(values) $tag]
+    SendCmd "contour3d visible $style(-isosurfacevisible) $tag"
+    SendCmd "contour3d edges $style(-edges) $tag"
     set _settings(-isosurfaceedges) $style(-edges)
     #SendCmd "contour3d color [Color2RGB $settings(-color)] $tag"
@@ -2193,10 +2210,9 @@
     SendCmd "contour3d linecolor [Color2RGB $style(-edgecolor)] $tag"
     SendCmd "contour3d linewidth $style(-linewidth) $tag"
-    SendCmd "contour3d opacity $_currentOpacity $tag"
+    SendCmd "contour3d opacity $style(-opacity) $tag"
     set _settings(-isosurfaceopacity) $style(-opacity)
     SetCurrentColormap $style(-color) 
     SendCmd "contour3d wireframe $style(-wireframe) $tag"
     set _settings(-isosurfacewireframe) $style(-wireframe)
-    set _settings(-isosurfaceopacity) [expr $style(-opacity) * 100.0]
 }
 
@@ -2432,5 +2448,5 @@
 	    incr offset $lineht
 	}
-        foreach value $_contourList {
+        foreach value $_contourList(values) {
             set norm [expr 1.0 - (($value - $vmin) / $range)]
             set y1 [expr int(round(($norm * $ih) + $offset))]
@@ -2545,30 +2561,77 @@
         bottom "0.707107 0.707107 0 0"
     }
-    foreach name { qw qx qy qz } value $positions($side) {
+    foreach name { -qw -qx -qy -qz } value $positions($side) {
         set _view($name) $value
     } 
-    set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
+    set q [ViewToQuaternion]
     $_arcball quaternion $q
     SendCmd "camera orient $q"
     SendCmd "camera reset"
-    set _view(xpan) 0
-    set _view(ypan) 0
-    set _view(zoom) 1.0
-}
-
-itcl::body Rappture::VtkIsosurfaceViewer::UpdateContourList {} { 
+    set _view(-xpan) 0
+    set _view(-ypan) 0
+    set _view(-zoom) 1.0
+}
+
+itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} { 
     if { ![info exists _limits($_curFldName)] } {
-        return
-    }
-    if { $_currentNumContours < 1 } {
-        set _contourList ""
-        return
-    }
-    foreach { vmin vmax } $_limits($_curFldName) break
-    set v [blt::vector create \#auto]
-    $v seq $vmin $vmax [expr $_currentNumContours+2]
-    $v delete end 0
-    set _contourList [$v range 0 end]
-    blt::vector destroy $v
-}
-
+        puts stderr "no _curFldName"
+        return ""
+    }
+    if { $_contourList(numLevels) < 1 } {
+        # There are tools that set 0 levels to get cutplanes only
+        #puts stderr "numLevels < 1"
+        return ""
+    }
+    if { [llength $_contourList(reqValues)] > 1 } {
+        set values $_contourList(reqValues)
+    } else {
+        foreach { vmin vmax } $_limits($_curFldName) break
+        set v [blt::vector create \#auto]
+        $v seq $vmin $vmax [expr $_contourList(numLevels)+2]
+        $v delete end 0
+        set values [$v range 0 end]
+        blt::vector destroy $v
+    }
+    set _contourList(values) $values
+}
+
+itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentFieldName { dataobj } { 
+    set _first $dataobj
+    $itk_component(field) choices delete 0 end
+    $itk_component(fieldmenu) delete 0 end
+    array unset _fields
+    set _curFldName ""
+    foreach cname [$_first components] {
+        foreach fname [$_first fieldnames $cname] {
+            if { [info exists _fields($fname)] } {
+                continue
+            }
+            foreach { label units components } \
+                [$_first fieldinfo $fname] break
+            $itk_component(field) choices insert end "$fname" "$label"
+            $itk_component(fieldmenu) add radiobutton -label "$label" \
+                -value $label -variable [itcl::scope _curFldLabel] \
+                -selectcolor red \
+                -activebackground $itk_option(-plotbackground) \
+                -activeforeground $itk_option(-plotforeground) \
+                -font "Arial 8" \
+                -command [itcl::code $this Combo invoke]
+            set _fields($fname) [list $label $units $components]
+            if { $_curFldName == "" } {
+                set _curFldName $fname
+                set _curFldLabel $label
+            }
+        }
+    }
+    $itk_component(field) value $_curFldLabel
+    if { ![info exists _limits($_curFldName)] } {
+        SendCmd "dataset maprange all"
+    } else {
+        set limits $_limits($_curFldName)
+        SendCmd "dataset maprange explicit $limits $_curFldName"
+        if { $limits != $_currentLimits } {
+            set _currentLimits $limits
+            EventuallyChangeContourLevels
+        }
+    }
+}
