Index: branches/uq/gui/scripts/vtkimageviewer.tcl
===================================================================
--- branches/uq/gui/scripts/vtkimageviewer.tcl	(revision 4798)
+++ branches/uq/gui/scripts/vtkimageviewer.tcl	(revision 5121)
@@ -1,3 +1,3 @@
-# -*- mode: tcl; indent-tabs-mode: nil -*- 
+# -*- mode: tcl; indent-tabs-mode: nil -*-
 # ----------------------------------------------------------------------
 #  COMPONENT: vtkimageviewer - Vtk image viewer
@@ -58,50 +58,53 @@
     public method get {args}
     public method isconnected {}
-    public method limits3 { dataobj }
-    public method parameters {title args} { 
-        # do nothing 
+    public method parameters {title args} {
+        # do nothing
     }
     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 AdjustMode {}
-    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 min max 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 {}
     private method BuildColormap { name }
     private method BuildImageTab {}
-    private method BuildDownloadPopup { widget command } 
+    private method BuildDownloadPopup { widget command }
     private method Combo { option }
+    private method Connect {}
+    private method CurrentDatasets {args}
+    private method Disconnect {}
+    private method DoResize {}
+    private method DoRotate {}
     private method DrawLegend {}
-    private method EnterLegend { x y } 
-    private method EventuallyRequestLegend {} 
-    private method EventuallyResize { w h } 
-    private method EventuallyRotate { q } 
-    private method GetImage { args } 
-    private method GetVtkData { args } 
-    private method IsValidObject { dataobj } 
+    private method EnterLegend { x y }
+    private method EventuallyRequestLegend {}
+    private method EventuallyResize { w h }
+    private method EventuallyRotate { q }
+    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 MotionLegend { x y }
+    private method Pan {option x y}
     private method PanCamera {}
+    private method Pick {x y}
+    private method QuaternionToView { q } {
+        foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
+    }
+    private method Rebuild {}
+    private method ReceiveDataset { args }
+    private method ReceiveImage { args }
+    private method ReceiveLegend { colormap title min max size }
     private method RequestLegend {}
+    private method Rotate {option x y}
     private method SetCurrentColormap { color }
     private method SetLegendTip { x y }
-    private method SetObjectStyle { dataobj comp } 
+    private method SetObjectStyle { dataobj comp }
     private method SetOrientation { side }
+    private method ViewToQuaternion {} {
+        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
+    }
+    private method Zoom {option}
 
     private variable _arcball ""
@@ -109,5 +112,5 @@
     private variable _obj2datasets
     private variable _obj2ovride   ;    # maps dataobj => style override
-    private variable _datasets     ;    # contains all the dataobj-component 
+    private variable _datasets     ;    # contains all the dataobj-component
                                    ;    # datasets in the server
     private variable _colormaps    ;    # contains all the colormaps
@@ -125,5 +128,5 @@
 
     private variable _click        ;    # info used for rotate operations
-    private variable _limits       ;    # Holds overall limits for all dataobjs 
+    private variable _limits       ;    # Holds overall limits for all dataobjs
                                         # using the viewer.
     private variable _view         ;    # view params for 3D view
@@ -150,6 +153,6 @@
     private variable _rotatePending 0
     private variable _legendPending 0
-    private variable _fieldNames {} 
-    private variable _fields 
+    private variable _fieldNames {}
+    private variable _fields
     private variable _curFldName ""
     private variable _curFldLabel ""
@@ -197,42 +200,41 @@
     # Initialize the view to some default parameters.
     array set _view {
-        qw	0.36
-        qx	0.25
-        qy	0.50
-        qz	0.70
-        zoom	1.0 
-        xpan	0
-        ypan	0
-        ortho	0
+        -ortho           0
+        -qw              0.36
+        -qx              0.25
+        -qy              0.50
+        -qz              0.70
+        -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 _settings {
-        axisFlymode		"static"
-        axisLabels              1
-        axisMinorTicks		1
-        axisVisible		1
-        axisXGrid		0
-        axisYGrid		0
-        axisZGrid		0
-        backingColor            white
-        backingVisible          1
-        colormapDiscrete        0
-        field			"Default"
-        legendVisible           0
-        level                   127.5
-        numColors               256
-        opacity                 100
-        outline			0
-        saveOpacity		100
-        stretchToFit		0
-        view3D                  0
-        window                  255.0
+        -axisflymode            "static"
+        -axislabels             1
+        -axisminorticks         1
+        -axisvisible            1
+        -backingcolor           white
+        -backingvisible         1
+        -colormapdiscrete       0
+        -field                  "Default"
+        -legendvisible          0
+        -level                  127.5
+        -numcolors              256
+        -opacity                100
+        -outline                0
+        -saveopacity            100
+        -stretchtofit           0
+        -view3d                 0
+        -window                 255.0
+        -xgrid                  0
+        -ygrid                  0
+        -zgrid                  0
     }
     array set _changed {
-        opacity                 0
-        colormap                0
+        -colormap               0
+        -opacity                0
     }
     itk_component add view {
@@ -241,5 +243,5 @@
     } {
         usual
-        ignore -highlightthickness -borderwidth -background 
+        ignore -highlightthickness -borderwidth -background
     }
 
@@ -247,5 +249,5 @@
         menu $itk_component(plotarea).menu \
             -relief flat \
-            -tearoff no 
+            -tearoff no
     } {
         usual
@@ -267,6 +269,6 @@
 
     set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)]
-    set _map(cwidth) -1 
-    set _map(cheight) -1 
+    set _map(cwidth) -1
+    set _map(cheight) -1
     set _map(zoom) 1.0
     set _map(original) ""
@@ -313,6 +315,6 @@
             -onimage [Rappture::icon surface] \
             -offimage [Rappture::icon surface] \
-            -variable [itcl::scope _settings(view3D)] \
-            -command [itcl::code $this AdjustSetting view3D] \
+            -variable [itcl::scope _settings(-view3d)] \
+            -command [itcl::code $this AdjustSetting -view3d] \
     }
     Rappture::Tooltip::for $itk_component(mode) \
@@ -324,6 +326,6 @@
             -onimage [Rappture::icon stretchtofit] \
             -offimage [Rappture::icon stretchtofit] \
-            -variable [itcl::scope _settings(stretchToFit)] \
-            -command [itcl::code $this AdjustSetting stretchToFit] \
+            -variable [itcl::scope _settings(-stretchtofit)] \
+            -command [itcl::code $this AdjustSetting -stretchtofit] \
     }
     Rappture::Tooltip::for $itk_component(stretchtofit) \
@@ -336,9 +338,9 @@
         BuildCameraTab
     } errs] != 0 } {
-	global errorInfo
+        global errorInfo
         puts stderr "errs=$errs errorInfo=$errorInfo"
     }
 
-    # Hack around the Tk panewindow.  The problem is that the requested 
+    # Hack around the Tk panewindow.  The problem is that the requested
     # size of the 3d view isn't set until an image is retrieved from
     # the server.  So the panewindow uses the tiny size.
@@ -346,5 +348,5 @@
     pack forget $itk_component(view)
     blt::table $itk_component(plotarea) \
-        0,0 $itk_component(view) -fill both -reqwidth $w 
+        0,0 $itk_component(view) -fill both -reqwidth $w
     blt::table configure $itk_component(plotarea) c1 -resize none
 
@@ -430,6 +432,5 @@
 
 itcl::body Rappture::VtkImageViewer::DoRotate {} {
-    set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
-    SendCmd "camera orient $q" 
+    SendCmd "camera orient [ViewToQuaternion]"
     set _rotatePending 0
 }
@@ -455,8 +456,8 @@
 
 itcl::body Rappture::VtkImageViewer::EventuallyRotate { q } {
-    foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break
+    QuaternionToView $q
     if { !$_rotatePending } {
         set _rotatePending 1
-        global rotate_delay 
+        global rotate_delay
         $_dispatcher event -after $rotate_delay !rotate
     }
@@ -557,5 +558,5 @@
                     continue
                 }
-                if {[info exists _obj2ovride($dataobj-raise)] && 
+                if {[info exists _obj2ovride($dataobj-raise)] &&
                     $_obj2ovride($dataobj-raise)} {
                     set dlist [linsert $dlist 0 $dataobj]
@@ -585,5 +586,5 @@
             }
             return $dlist
-        }           
+        }
         -image {
             if {[llength $args] != 2} {
@@ -605,11 +606,11 @@
 }
 
-# 
+#
 # scale  --
 #
 #       This gets called either incrementally as new simulations are
 #       added or all at once as a sequence of images.
-#       This  accounts for all objects--even those not showing on the 
-#       screen.  Because of this, the limits are appropriate for all 
+#       This  accounts for all objects--even those not showing on the
+#       screen.  Because of this, the limits are appropriate for all
 #       objects as the user scans through data in the ResultSet viewer.
 #
@@ -654,5 +655,5 @@
     }
     if { [array size found] > 1 } {
-        set _settings(stretchToFit) 1
+        set _settings(-stretchtofit) 1
     } else {
         # Check if the range of the x and y axes requires that we stretch
@@ -663,5 +664,5 @@
         if { (($xmax - $xmin) > (($ymax -$ymin) * $_maxScale)) ||
              ((($xmax - $xmin) * $_maxScale) < ($ymax -$ymin)) } {
-            set _settings(stretchToFit) 1
+            set _settings(-stretchtofit) 1
         }
     }
@@ -803,8 +804,8 @@
     $_dispatcher cancel !legend
     # disconnected -- no more data sitting on server
-    array unset _datasets 
-    array unset _data 
-    array unset _colormaps 
-    array unset _obj2datasets 
+    array unset _datasets
+    array unset _data
+    array unset _colormaps
+    array unset _obj2datasets
     global readyForNextFrame
     set readyForNextFrame 1
@@ -830,6 +831,7 @@
     if { $info(-type) == "image" } {
         if 0 {
-            set f [open "last.ppm" "w"] 
-            puts $f $bytes
+            set f [open "last.ppm" "w"]
+            fconfigure $f -encoding binary
+            puts -nonewline $f $bytes
             close $f
         }
@@ -837,5 +839,5 @@
         set time [clock seconds]
         set date [clock format $time]
-        #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>"        
+        #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>"
         if { $_start > 0 } {
             set finish [clock clicks -milliseconds]
@@ -908,31 +910,26 @@
     # Turn on buffering of commands to the server.  We don't want to
     # be preempted by a server disconnect/reconnect (which automatically
-    # generates a new call to Rebuild).   
+    # generates a new call to Rebuild).
     StartBufferingCommands
 
     if { $_width != $w || $_height != $h || $_reset } {
-	set _width $w
-	set _height $h
-	$_arcball resize $w $h
-	DoResize
-	if { $_settings(stretchToFit) } {
-	    AdjustSetting stretchToFit
-	}
+        set _width $w
+        set _height $h
+        $_arcball resize $w $h
+        DoResize
+        if { $_settings(-stretchtofit) } {
+            AdjustSetting -stretchToFit
+        }
     }
     if { $_reset } {
-	#
-	# Reset the camera and other view parameters
-	#
-        InitSettings view3D background
-
-        # Let's see how this goes.  I think it's preferable to overloading the
-        # axis title with the exponent.
-        SendCmd "axis exp 0 0 0 1"
-
-	SendCmd "axis lrot z 90"
-	set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
-	$_arcball quaternion $q 
-        if {$_settings(view3D) } {
-            if { $_view(ortho)} {
+        #
+        # Reset the camera and other view parameters
+        #
+        InitSettings -view3d -background
+
+        SendCmd "axis lrot z 90"
+        $_arcball quaternion [ViewToQuaternion]
+        if {$_settings(-view3d) } {
+            if { $_view(-ortho)} {
                 SendCmd "camera mode ortho"
             } else {
@@ -941,6 +938,6 @@
             DoRotate
             SendCmd "camera reset"
-	}
-	PanCamera
+        }
+        PanCamera
         StopBufferingCommands
         SendCmd "imgflush"
@@ -960,20 +957,22 @@
             if { ![info exists _datasets($tag)] } {
                 set bytes [$dataobj vtkdata $comp]
-		if 0 { 
+                if 0 {
                     set f [open /tmp/vtkimage.vtk "w"]
-                    puts $f $bytes
+                    fconfigure $f -translation binary -encoding binary
+                    puts -nonewline $f $bytes
                     close $f
-		}
+                }
                 set length [string length $bytes]
                 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
                     lappend info "dataset_tag"   $tag
-                    SendCmd [list "clientinfo" $info]
+                    SendCmd "clientinfo [list $info]"
                 }
                 SendCmd "dataset add $tag data follows $length"
@@ -991,7 +990,7 @@
     }
     if { $_first != ""  } {
-	$itk_component(field) choices delete 0 end
-	$itk_component(fieldmenu) delete 0 end
-	array unset _fields
+        $itk_component(field) choices delete 0 end
+        $itk_component(fieldmenu) delete 0 end
+        array unset _fields
         set _curFldName ""
         foreach cname [$_first components] {
@@ -1019,35 +1018,36 @@
         $itk_component(field) value $_curFldLabel
     }
-    InitSettings stretchToFit outline
+    InitSettings -stretchtofit -outline
 
     if { $_reset } {
-	SendCmd "axis tickpos outside"
+        SendCmd "axis tickpos outside"
         #SendCmd "axis lformat all %g"
-        
-	foreach axis { x y z } {
+
+        foreach axis { x y z } {
             set label [$_first hints ${axis}label]
-	    if { $label == "" } {
-		set label [string toupper $axis]
-	    }
-	    # May be a space in the axis label.
-	    SendCmd [list axis name $axis $label]
-
-	    if {$axis == "z" && [$_first hints ${axis}units] == ""} {
-		set units [lindex $_fields($_curFldName) 1]
-	    } else {
-		set units [$_first hints ${axis}units]
-	    }
-	    if { $units != "" } {
-		# May be a space in the axis units.
-		SendCmd [list axis units $axis $units]
-	    }
-	}
-	#
-	# Reset the camera and other view parameters
-	#
-	set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
-	$_arcball quaternion $q 
-        if {$_settings(view3D) } {
-            if { $_view(ortho)} {
+            if { $label == "" } {
+                set label [string toupper $axis]
+            }
+            # May be a space in the axis label.
+            SendCmd [list axis name $axis $label]
+
+            if {$axis == "z" && [$_first hints ${axis}units] == ""} {
+                if {$_curFldName != ""} {
+                    set units [lindex $_fields($_curFldName) 1]
+                }
+            } else {
+                set units [$_first hints ${axis}units]
+            }
+            if { $units != "" } {
+                # May be a space in the axis units.
+                SendCmd [list axis units $axis $units]
+            }
+        }
+        #
+        # Reset the camera and other view parameters
+        #
+        $_arcball quaternion [ViewToQuaternion]
+        if {$_settings(-view3d) } {
+            if { $_view(-ortho)} {
                 SendCmd "camera mode ortho"
             } else {
@@ -1057,11 +1057,9 @@
             SendCmd "camera reset"
         }
-	PanCamera
-	InitSettings axisXGrid axisYGrid axisZGrid \
-	    axisVisible axisLabels field view3D
+        PanCamera
+        InitSettings -xgrid -ygrid -zgrid \
+            -axisvisible -axislabels -field -view3d
         if { [array size _fields] < 2 } {
-            catch {
-                blt::table forget $itk_component(field) $itk_component(field_l)
-            }
+            catch {blt::table forget $itk_component(field) $itk_component(field_l)}
         }
         RequestLegend
@@ -1069,5 +1067,5 @@
     }
     global readyForNextFrame
-    set readyForNextFrame 0;		# Don't advance to the next frame
+    set readyForNextFrame 0;                # Don't advance to the next frame
 
     # Actually write the commands to the server socket.  If it fails, we don't
@@ -1087,5 +1085,5 @@
 itcl::body Rappture::VtkImageViewer::CurrentDatasets {args} {
     set flag [lindex $args 0]
-    switch -- $flag { 
+    switch -- $flag {
         "-all" {
             if { [llength $args] > 1 } {
@@ -1106,5 +1104,5 @@
                 set dlist [get -visible]
             }
-        }           
+        }
         default {
             set dlist $args
@@ -1134,20 +1132,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.36
-                qx      0.25
-                qy      0.50
-                qz      0.70
-                zoom    1.0
-                xpan    0
-                ypan    0 
+                -qw      0.36
+                -qx      0.25
+                -qy      0.50
+                -qz      0.70
+                -xpan    0
+                -ypan    0
+                -zoom    1.0
             }
             if { $_first != "" } {
@@ -1157,7 +1155,6 @@
                 }
             }
-            set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
-            $_arcball quaternion $q
-            if {$_settings(view3D) } {
+            $_arcball quaternion [ViewToQuaternion]
+            if {$_settings(-view3d) } {
                 DoRotate
             }
@@ -1168,6 +1165,6 @@
 
 itcl::body Rappture::VtkImageViewer::PanCamera {} {
-    set x $_view(xpan)
-    set y $_view(ypan)
+    set x $_view(-xpan)
+    set y $_view(-ypan)
     SendCmd "camera pan $x $y"
 }
@@ -1229,5 +1226,5 @@
     foreach tag [CurrentDatasets -visible] {
         SendCmd "dataset getscalar pixel $x $y $tag"
-    } 
+    }
 }
 
@@ -1247,6 +1244,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
@@ -1270,6 +1267,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
         }
@@ -1293,7 +1290,7 @@
 itcl::body Rappture::VtkImageViewer::InitSettings { args } {
     foreach spec $args {
-        if { [info exists _settings($_first-$spec)] } {
+        if { [info exists _settings($_first${spec})] } {
             # Reset global setting with dataobj specific setting
-            set _settings($spec) $_settings($_first-$spec)
+            set _settings($spec) $_settings($_first${spec})
         }
         AdjustSetting $spec
@@ -1313,5 +1310,5 @@
     }
     switch -- $what {
-        "axisFlymode" {
+        "-axisflymode" {
             set mode [$itk_component(axisflymode) value]
             set mode [$itk_component(axisflymode) translate $mode]
@@ -1319,56 +1316,51 @@
             SendCmd "axis flymode $mode"
         }
-        "axisLabels" {
+        "-axislabels" {
             set bool $_settings($what)
             SendCmd "axis labels all $bool"
         }
-        "axisMinorTicks" {
+        "-axisminorticks" {
             set bool $_settings($what)
             SendCmd "axis minticks all $bool"
         }
-        "axisVisible" {
+        "-axisvisible" {
             set bool $_settings($what)
             SendCmd "axis visible all $bool"
         }
-        "axisXGrid" - "axisYGrid" - "axisZGrid" {
-            set axis [string tolower [string range $what 4 4]]
-            set bool $_settings($what)
-            SendCmd "axis grid $axis $bool"
-        }
-        "background" {
+        "-background" {
             set bg [$itk_component(background) value]
-	    array set fgcolors {
-		"black" "white"
-		"white" "black"
-		"grey"	"black"
-	    }
+            array set fgcolors {
+                "black" "white"
+                "white" "black"
+                "grey"  "black"
+            }
             set fg $fgcolors($bg)
             configure -plotbackground $bg -plotforeground $fg
-	    $itk_component(view) delete "legend"
+            $itk_component(view) delete "legend"
             SendCmd "screen bgcolor [Color2RGB $bg]"
             SendCmd "outline color [Color2RGB $fg]"
             SendCmd "axis color all [Color2RGB $fg]"
-	    DrawLegend
-        }
-        "backingColor" {
+            DrawLegend
+        }
+        "-backingcolor" {
             set color [$itk_component(backingcolor) value]
-	    if { $color == "none" } {
-		if { $_settings(backingVisible) } {
-		    SendCmd "image backing 0"
-		    set _settings(backingVisible) 0
-		}
-	    } else {
-		if { !$_settings(backingVisible) } {
-		    SendCmd "image backing 1"
-		    set _settings(backingVisible) 1
-		}
-		SendCmd "image color [Color2RGB $color]"
-	    }
-        }
-        "backingVisible" {
-	    set bool $_settings($what)
+            if { $color == "none" } {
+                if { $_settings(-backingvisible) } {
+                    SendCmd "image backing 0"
+                    set _settings(-backingvisible) 0
+                }
+            } else {
+                if { !$_settings(-backingvisible) } {
+                    SendCmd "image backing 1"
+                    set _settings(-backingvisible) 1
+                }
+                SendCmd "image color [Color2RGB $color]"
+            }
+        }
+        "-backingvisible" {
+            set bool $_settings($what)
             SendCmd "image backing $bool"
         }
-        "colormap" {
+        "-colormap" {
             set _changed($what) 1
             StartBufferingCommands
@@ -1376,15 +1368,15 @@
             set _settings($what) $color
             SetCurrentColormap $color
-            if {$_settings(colormapDiscrete)} {
-                 SendCmd "colormap res $_settings(numColors) $color"
+            if {$_settings(-colormapdiscrete)} {
+                 SendCmd "colormap res $_settings(-numcolors) $color"
             }
             StopBufferingCommands
-	    EventuallyRequestLegend
-        }
-        "colormapDiscrete" {
+            EventuallyRequestLegend
+        }
+        "-colormapdiscrete" {
             set bool $_settings($what)
             StartBufferingCommands
             if {$bool} {
-                SendCmd "colormap res $_settings(numColors)"
+                SendCmd "colormap res $_settings(-numcolors)"
             } else {
                 SendCmd "colormap res default"
@@ -1393,5 +1385,5 @@
             EventuallyRequestLegend
         }
-        "field" {
+        "-field" {
             set label [$itk_component(field) value]
             set fname [$itk_component(field) translate $label]
@@ -1417,19 +1409,19 @@
             DrawLegend
         }
-        "view3D" {
-	    set bool $_settings($what)
+        "-view3d" {
+            set bool $_settings($what)
             set c $itk_component(view)
             StartBufferingCommands
             # Fix image scale: 0 for contours, 1 for images.
             if { $bool } {
-                set _settings(opacity) $_settings(saveOpacity)
+                set _settings(-opacity) $_settings(-saveopacity)
             } else {
-                set _settings(opacity) 100
-            }
-            AdjustSetting opacity
- 	    if { $bool } {
-		$itk_component(opacity) configure -state normal
-		$itk_component(opacity_l) configure -state normal
-                if {$_view(ortho)} {
+                set _settings(-opacity) 100
+            }
+            AdjustSetting -opacity
+            if { $bool } {
+                $itk_component(opacity) configure -state normal
+                $itk_component(opacity_l) configure -state normal
+                if {$_view(-ortho)} {
                     SendCmd "camera mode ortho"
                 } else {
@@ -1437,16 +1429,16 @@
                 }
                 SendCmd "camera aspect native"
-	    } else {
-		$itk_component(opacity) configure -state disabled
-		$itk_component(opacity_l) configure -state disabled
+            } else {
+                $itk_component(opacity) configure -state disabled
+                $itk_component(opacity_l) configure -state disabled
                 SendCmd "camera mode image"
-                if {$_settings(stretchToFit)} {
+                if {$_settings(-stretchtofit)} {
                     SendCmd "camera aspect window"
                 }
             }
             if { $bool } {
-                set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
+                set q [ViewToQuaternion]
                 $_arcball quaternion $q
-                SendCmd "camera orient $q" 
+                SendCmd "camera orient $q"
             } else {
                 bind $c <ButtonPress-1> {}
@@ -1455,5 +1447,5 @@
             }
             SendCmd "camera reset"
-            # Fix the mouse bindings for rotation/panning and the 
+            # Fix the mouse bindings for rotation/panning and the
             # camera mode. Ideally we'd create a bindtag for these.
             if { $bool } {
@@ -1468,45 +1460,50 @@
             StopBufferingCommands
         }
-        "window" {
+        "-window" {
             set val $_settings($what)
             SendCmd "image window $val"
         }
-        "level" {
+        "-level" {
             set val $_settings($what)
             SendCmd "image level $val"
         }
-        "legendVisible" {
+        "-legendvisible" {
             if { !$_settings($what) } {
-		$itk_component(view) delete legend
-	    }
-	    DrawLegend
-        }
-        "opacity" {
+                $itk_component(view) delete legend
+            }
+            DrawLegend
+        }
+        "-opacity" {
             set _changed($what) 1
-	    if { $_settings(view3D) } {
-                set _settings(saveOpacity) $_settings($what)
+            if { $_settings(-view3d) } {
+                set _settings(-saveopacity) $_settings($what)
                 set val [expr $_settings($what) * 0.01]
                 SendCmd "image opacity $val"
             } else {
-		SendCmd "image opacity 1.0"
-            }
-        }
-        "outline" {
+                SendCmd "image opacity 1.0"
+            }
+        }
+        "-outline" {
             set bool $_settings($what)
             SendCmd "outline visible $bool"
-	}
-        "stretchToFit" {
-	    set bool $_settings($what)
-	    if { $bool } {
-		if { $_settings(view3D) } {
-		    SendCmd "camera aspect native"
-		} else {
-		    SendCmd "camera aspect window"
-		}
-	    } else {
-		SendCmd "camera aspect native"
-	    }
-	}
-	default {
+        }
+        "-stretchtofit" {
+            set bool $_settings($what)
+            if { $bool } {
+                if { $_settings(-view3d) } {
+                    SendCmd "camera aspect native"
+                } else {
+                    SendCmd "camera aspect window"
+                }
+            } else {
+                SendCmd "camera aspect native"
+            }
+        }
+        "-xgrid" - "-ygrid" - "-zgrid" {
+            set axis [string tolower [string range $what 1 1]]
+            set bool $_settings($what)
+            SendCmd "axis grid $axis $bool"
+        }
+        default {
             error "don't know how to fix $what"
         }
@@ -1518,12 +1515,12 @@
 #
 #       Request a new legend from the server.  The size of the legend
-#       is determined from the height of the canvas.  
+#       is determined from the height of the canvas.
 #
 # This should be called when
-#	1.  A new current colormap is set.
-#	2.  Window is resized.
-#	3.  The limits of the data have changed.  (Just need a redraw).
-#	4.  Number of isolines have changed. (Just need a redraw).
-#	5.  Legend becomes visible (Just need a redraw).
+#        1.  A new current colormap is set.
+#        2.  Window is resized.
+#        3.  The limits of the data have changed.  (Just need a redraw).
+#        4.  Number of isolines have changed. (Just need a redraw).
+#        5.  Legend becomes visible (Just need a redraw).
 #
 itcl::body Rappture::VtkImageViewer::RequestLegend {} {
@@ -1532,5 +1529,5 @@
     set w 12
     set lineht [font metrics $font -linespace]
-    # color ramp height = (canvas height) - (min and max value lines) - 2 
+    # color ramp height = (canvas height) - (min and max value lines) - 2
     set h [expr {$_height - 2 * ($lineht + 2)}]
     set _legendHeight $h
@@ -1538,18 +1535,18 @@
     set fname $_curFldName
     if { [string match "component*" $fname] } {
-	set title ""
+        set title ""
     } else {
-	if { [info exists _fields($fname)] } {
-	    foreach { title units } $_fields($fname) break
-	    if { $units != "" } {
-		set title [format "%s (%s)" $title $units]
-	    }
-	} else {
-	    set title $fname
-	}
+        if { [info exists _fields($fname)] } {
+            foreach { title units } $_fields($fname) break
+            if { $units != "" } {
+                set title [format "%s (%s)" $title $units]
+            }
+        } else {
+            set title $fname
+        }
     }
     # If there's a title too, substract one more line
     if { $title != "" } {
-        incr h -$lineht 
+        incr h -$lineht
     }
     if { $h < 1 } {
@@ -1558,5 +1555,6 @@
     # Set the legend on the first image dataset.
     if { $_currentColormap != "" && $_currentColormap != "none" } {
-	SendCmd "legend $_currentColormap scalar $_curFldName {} $w $h 0"
+        #SendCmd "legend $_currentColormap scalar $_curFldName {} $w $h 0"
+        SendCmd "legend2 $_currentColormap $w $h"
     }
 }
@@ -1568,5 +1566,5 @@
     # Keep track of the colormaps that we build.
     if { $name != "none" && ![info exists _colormaps($name)] } {
-        BuildColormap $name 
+        BuildColormap $name
         set _colormaps($name) 1
     }
@@ -1595,16 +1593,16 @@
 itcl::configbody Rappture::VtkImageViewer::mode {
     switch -- $itk_option(-mode) {
-	"volume" {
-	    set _settings(view3D) 1
-	}
-	"vtkimage" {
-	    set _settings(view3D) 0
-	} 
-	default {
-	    error "unknown mode settings \"$itk_option(-mode)\""
-	}
+        "volume" {
+            set _settings(-view3d) 1
+        }
+        "vtkimage" {
+            set _settings(-view3d) 0
+        }
+        default {
+            error "unknown mode settings \"$itk_option(-mode)\""
+        }
     }
     if { !$_reset } {
-        AdjustSetting view3D
+        AdjustSetting -view3d
     }
 }
@@ -1619,5 +1617,5 @@
             SendCmd "screen bgcolor $rgb"
         }
-	$itk_component(view) configure -background $itk_option(-plotbackground)
+        $itk_component(view) configure -background $itk_option(-plotbackground)
     }
 }
@@ -1630,18 +1628,8 @@
         set rgb [Color2RGB $itk_option(-plotforeground)]
         if { !$_reset } {
+            SendCmd "axis color all $rgb"
             SendCmd "outline color $rgb"
-            SendCmd "axis color all $rgb"
-        }
-    }
-}
-
-itcl::body Rappture::VtkImageViewer::limits3 { dataobj } {
-    lappend limits x [$dataobj limits x]
-    lappend limits y [$dataobj limits y] 
-    if { [catch { $dataobj limits $_curFldName } vlim] != 0 } {
-        set vlim [$dataobj limits v] 
-    }
-    lappend limits v $vlim
-    return $limits
+        }
+    }
 }
 
@@ -1658,34 +1646,34 @@
     checkbutton $inner.legend \
         -text "Legend" \
-        -variable [itcl::scope _settings(legendVisible)] \
-        -command [itcl::code $this AdjustSetting legendVisible] \
+        -variable [itcl::scope _settings(-legendvisible)] \
+        -command [itcl::code $this AdjustSetting -legendvisible] \
         -font "Arial 9"
 
     checkbutton $inner.outline \
         -text "Outline" \
-        -variable [itcl::scope _settings(outline)] \
-        -command [itcl::code $this AdjustSetting outline] \
+        -variable [itcl::scope _settings(-outline)] \
+        -command [itcl::code $this AdjustSetting -outline] \
         -font "Arial 9"
 
     checkbutton $inner.backing \
         -text "Backing" \
-        -variable [itcl::scope _settings(backingVisible)] \
-        -command [itcl::code $this AdjustSetting backingVisible] \
+        -variable [itcl::scope _settings(-backingvisible)] \
+        -command [itcl::code $this AdjustSetting -backingvisible] \
         -font "Arial 9"
 
     checkbutton $inner.stretch \
         -text "Stretch to fit" \
-        -variable [itcl::scope _settings(stretchToFit)] \
-        -command [itcl::code $this AdjustSetting stretchToFit] \
+        -variable [itcl::scope _settings(-stretchtofit)] \
+        -command [itcl::code $this AdjustSetting -stretchtofit] \
         -font "Arial 9"
 
     checkbutton $inner.colormapDiscrete \
         -text "Discrete Colormap" \
-        -variable [itcl::scope _settings(colormapDiscrete)] \
-        -command [itcl::code $this AdjustSetting colormapDiscrete] \
+        -variable [itcl::scope _settings(-colormapdiscrete)] \
+        -command [itcl::code $this AdjustSetting -colormapdiscrete] \
         -font "Arial 9"
 
     itk_component add field_l {
-        label $inner.field_l -text "Field" -font "Arial 9" 
+        label $inner.field_l -text "Field" -font "Arial 9"
     } {
         ignore -font
@@ -1695,7 +1683,7 @@
     }
     bind $inner.field <<Value>> \
-        [itcl::code $this AdjustSetting field]
-
-    label $inner.colormap_l -text "Colormap" -font "Arial 9" 
+        [itcl::code $this AdjustSetting -field]
+
+    label $inner.colormap_l -text "Colormap" -font "Arial 9"
     itk_component add colormap {
         Rappture::Combobox $inner.colormap -width 10 -editable no
@@ -1705,7 +1693,7 @@
     $itk_component(colormap) value "BCGYR"
     bind $inner.colormap <<Value>> \
-        [itcl::code $this AdjustSetting colormap]
-
-    label $inner.backingcolor_l -text "Backing Color" -font "Arial 9" 
+        [itcl::code $this AdjustSetting -colormap]
+
+    label $inner.backingcolor_l -text "Backing Color" -font "Arial 9"
     itk_component add backingcolor {
         Rappture::Combobox $inner.backingcolor -width 10 -editable no
@@ -1721,11 +1709,11 @@
         "red"                "red"              \
         "white"              "white"            \
-	"none"		     "none"
-
-    $itk_component(backingcolor) value "white"
+        "none"               "none"
+
+    $itk_component(backingcolor) value $_settings(-backingcolor)
     bind $inner.backingcolor <<Value>> \
-	[itcl::code $this AdjustSetting backingColor]
-
-    label $inner.background_l -text "Background Color" -font "Arial 9" 
+        [itcl::code $this AdjustSetting -backingcolor]
+
+    label $inner.background_l -text "Background Color" -font "Arial 9"
     itk_component add background {
         Rappture::Combobox $inner.background -width 10 -editable no
@@ -1734,8 +1722,9 @@
         "black"              "black"            \
         "white"              "white"            \
-        "grey"               "grey"             
+        "grey"               "grey"
 
     $itk_component(background) value "white"
-    bind $inner.background <<Value>> [itcl::code $this AdjustSetting background]
+    bind $inner.background <<Value>> \
+        [itcl::code $this AdjustSetting -background]
 
     itk_component add opacity_l {
@@ -1746,7 +1735,7 @@
     itk_component add opacity {
         ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
-            -variable [itcl::scope _settings(opacity)] \
+            -variable [itcl::scope _settings(-opacity)] \
             -showvalue off \
-            -command [itcl::code $this AdjustSetting opacity]
+            -command [itcl::code $this AdjustSetting -opacity]
     }
 
@@ -1758,7 +1747,7 @@
     itk_component add window {
         ::scale $inner.window -from 0 -to 255 -orient horizontal \
-            -variable [itcl::scope _settings(window)] \
+            -variable [itcl::scope _settings(-window)] \
             -showvalue off \
-            -command [itcl::code $this AdjustSetting window]
+            -command [itcl::code $this AdjustSetting -window]
     }
     itk_component add level_l {
@@ -1769,7 +1758,7 @@
     itk_component add level {
         ::scale $inner.level -from 0 -to 255 -orient horizontal \
-            -variable [itcl::scope _settings(level)] \
+            -variable [itcl::scope _settings(-level)] \
             -showvalue off \
-            -command [itcl::code $this AdjustSetting level]
+            -command [itcl::code $this AdjustSetting -level]
     }
 
@@ -1784,6 +1773,6 @@
         2,0 $inner.backingcolor_l  -anchor w -pady 2  \
         2,1 $inner.backingcolor    -anchor w -pady 2 -fill x  \
-	3,0 $inner.background_l -anchor w -pady 2 \
-	3,1 $inner.background -anchor w -pady 2  -fill x \
+        3,0 $inner.background_l -anchor w -pady 2 \
+        3,1 $inner.background -anchor w -pady 2  -fill x \
         4,0 $inner.backing -anchor w -pady 2 -cspan 2 \
         5,0 $inner.stretch    -anchor w -pady 2 -cspan 2 \
@@ -1798,5 +1787,5 @@
         16,1 $inner.window   -fill x   -pady 2 \
         17,0 $inner.level_l -anchor w -pady 2 \
-        17,1 $inner.level   -fill x   -pady 2 
+        17,1 $inner.level   -fill x   -pady 2
 
     blt::table configure $inner r* c* -resize none
@@ -1816,35 +1805,35 @@
     checkbutton $inner.visible \
         -text "Axes" \
-        -variable [itcl::scope _settings(axisVisible)] \
-        -command [itcl::code $this AdjustSetting axisVisible] \
+        -variable [itcl::scope _settings(-axisvisible)] \
+        -command [itcl::code $this AdjustSetting -axisvisible] \
         -font "Arial 9"
     checkbutton $inner.labels \
         -text "Axis Labels" \
-        -variable [itcl::scope _settings(axisLabels)] \
-        -command [itcl::code $this AdjustSetting axisLabels] \
+        -variable [itcl::scope _settings(-axislabels)] \
+        -command [itcl::code $this AdjustSetting -axislabels] \
         -font "Arial 9"
-    label $inner.grid_l -text "Grid" -font "Arial 9" 
+    label $inner.grid_l -text "Grid" -font "Arial 9"
     checkbutton $inner.xgrid \
         -text "X" \
-        -variable [itcl::scope _settings(axisXGrid)] \
-        -command [itcl::code $this AdjustSetting axisXGrid] \
+        -variable [itcl::scope _settings(-xgrid)] \
+        -command [itcl::code $this AdjustSetting -xgrid] \
         -font "Arial 9"
     checkbutton $inner.ygrid \
         -text "Y" \
-        -variable [itcl::scope _settings(axisYGrid)] \
-        -command [itcl::code $this AdjustSetting axisYGrid] \
+        -variable [itcl::scope _settings(-ygrid)] \
+        -command [itcl::code $this AdjustSetting -ygrid] \
         -font "Arial 9"
     checkbutton $inner.zgrid \
         -text "Z" \
-        -variable [itcl::scope _settings(axisZGrid)] \
-        -command [itcl::code $this AdjustSetting axisZGrid] \
+        -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] \
+        -variable [itcl::scope _settings(-axisminorticks)] \
+        -command [itcl::code $this AdjustSetting -axisminorticks] \
         -font "Arial 9"
 
-    label $inner.mode_l -text "Mode" -font "Arial 9" 
+    label $inner.mode_l -text "Mode" -font "Arial 9"
 
     itk_component add axisflymode {
@@ -1855,7 +1844,7 @@
         "closest_triad"   "closest" \
         "furthest_triad"  "farthest" \
-        "outer_edges"     "outer"         
-    $itk_component(axisflymode) value "static"
-    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axisFlymode]
+        "outer_edges"     "outer"
+    $itk_component(axisflymode) value $_settings(-axisflymode)
+    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axisflymode]
 
     blt::table $inner \
@@ -1863,10 +1852,10 @@
         1,0 $inner.labels  -anchor w -cspan 4 \
         2,0 $inner.minorticks  -anchor w -cspan 4 \
-	4,0 $inner.grid_l  -anchor w \
+        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 
+        5,1 $inner.mode    -fill x -cspan 3
 
     blt::table configure $inner r* c* -resize none
@@ -1874,5 +1863,4 @@
     blt::table configure $inner r3 -height 0.125i
 }
-
 
 itcl::body Rappture::VtkImageViewer::BuildCameraTab {} {
@@ -1894,4 +1882,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 }
@@ -1900,9 +1889,9 @@
         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} <Return> \
-            [itcl::code $this camera set ${tag}]
+            [itcl::code $this camera set -${tag}]
         bind $inner.${tag} <KP_Enter> \
-            [itcl::code $this camera set ${tag}]
+            [itcl::code $this camera set -${tag}]
         blt::table $inner \
             $row,0 $inner.${tag}label -anchor e -pady 2 \
@@ -1913,6 +1902,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 camera set -ortho] \
         -font "Arial 9"
     blt::table $inner \
@@ -1921,5 +1910,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
@@ -1927,21 +1916,21 @@
 
 #
-#  camera -- 
+#  camera --
 #
 itcl::body Rappture::VtkImageViewer::camera {option args} {
-    switch -- $option { 
+    switch -- $option {
         "show" {
             puts [array get _view]
         }
         "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 {
@@ -1949,14 +1938,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($what)"
                 }
             }
@@ -1978,5 +1967,5 @@
 
 itcl::body Rappture::VtkImageViewer::GetImage { args } {
-    if { [image width $_image(download)] > 0 && 
+    if { [image width $_image(download)] > 0 &&
          [image height $_image(download)] > 0 } {
         set bytes [$_image(download) data -format "jpeg -quality 100"]
@@ -1991,14 +1980,14 @@
         -title "[Rappture::filexfer::label downloadWord] as..."
     set inner [$popup component inner]
-    label $inner.summary -text "" -anchor w 
+    label $inner.summary -text "" -anchor w
     radiobutton $inner.vtk_button -text "VTK data file" \
         -variable [itcl::scope _downloadPopup(format)] \
         -font "Arial 9 " \
-        -value vtk  
+        -value vtk
     Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
     radiobutton $inner.image_button -text "Image File" \
         -variable [itcl::scope _downloadPopup(format)] \
         -font "Arial 9 " \
-        -value image 
+        -value image
     Rappture::Tooltip::for $inner.image_button \
         "Save as digital image."
@@ -2021,5 +2010,5 @@
         2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
         4,1 $inner.cancel -width .9i -fill y \
-        4,0 $inner.ok -padx 2 -width .9i -fill y 
+        4,0 $inner.ok -padx 2 -width .9i -fill y
     blt::table configure $inner r3 -height 4
     blt::table configure $inner r4 -pady 4
@@ -2032,5 +2021,5 @@
 # SetObjectStyle --
 #
-#       Set the style of the image/contour object.  This gets calls 
+#       Set the style of the image/contour object.  This gets calls
 #       for each dataset once as it is loaded.  It can overridden by
 #       the user controls.
@@ -2057,9 +2046,9 @@
     # the code to handle aberrant cases.
 
-    if { $_changed(opacity) } {
-        set style(-opacity) [expr $_settings(opacity) * 0.01]
-    }
-    if { $_changed(colormap) } {
-        set style(-color) $_settings(colormap)
+    if { $_changed(-opacity) } {
+        set style(-opacity) [expr $_settings(-opacity) * 0.01]
+    }
+    if { $_changed(-colormap) } {
+        set style(-color) $_settings(-colormap)
     }
     if { $_currentColormap == "" } {
@@ -2067,16 +2056,16 @@
     }
     if { [info exists style(-stretchtofit)] } {
-        set _settings(stretchToFit) $style(-stretchtofit)
-        AdjustSetting stretchToFit
+        set _settings(-stretchtofit) $style(-stretchtofit)
+        AdjustSetting -stretchToFit
     }
     SendCmd "outline add $tag"
     SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag"
-    SendCmd "outline visible $_settings(outline) $tag"
+    SendCmd "outline visible $_settings(-outline) $tag"
     SendCmd "image add $tag"
-    SetCurrentColormap $style(-color) 
+    SetCurrentColormap $style(-color)
     set color [$itk_component(backingcolor) value]
     SendCmd "image color [Color2RGB $color] $tag"
     SendCmd "image opacity $style(-opacity) $tag"
-    set _settings(opacity) [expr $style(-opacity) * 100.0]
+    set _settings(-opacity) [expr $style(-opacity) * 100.0]
 }
 
@@ -2105,6 +2094,6 @@
         #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
         if { [catch {DrawLegend} errs] != 0 } {
-	    global errorInfo
-	    puts stderr "errs=$errs errorInfo=$errorInfo"
+            global errorInfo
+            puts stderr "errs=$errs errorInfo=$errorInfo"
         }
     }
@@ -2123,49 +2112,49 @@
     set font "Arial 8"
     set lineht [font metrics $font -linespace]
-    
+
     if { [string match "component*" $fname] } {
-	set title ""
+        set title ""
     } else {
-	if { [info exists _fields($fname)] } {
-	    foreach { title units } $_fields($fname) break
-	    if { $units != "" } {
-		set title [format "%s (%s)" $title $units]
-	    }
-	} else {
-	    set title $fname
-	}
+        if { [info exists _fields($fname)] } {
+            foreach { title units } $_fields($fname) break
+            if { $units != "" } {
+                set title [format "%s (%s)" $title $units]
+            }
+        } else {
+            set title $fname
+        }
     }
     set x [expr $w - 2]
-    if { !$_settings(legendVisible) } {
-	$c delete legend
-	return
-    } 
+    if { !$_settings(-legendvisible) } {
+        $c delete legend
+        return
+    }
     if { [$c find withtag "legend"] == "" } {
-	set y 2 
-	# If there's a legend title, create a text item for the title.
+        set y 2
+        # If there's a legend title, create a text item for the title.
         $c create text $x $y \
-	    -anchor ne \
-	    -fill $itk_option(-plotforeground) -tags "title legend" \
-	    -font $font 
+            -anchor ne \
+            -fill $itk_option(-plotforeground) -tags "title legend" \
+            -font $font
         if { $title != "" } {
             incr y $lineht
         }
-	$c create text $x $y \
-	    -anchor ne \
-	    -fill $itk_option(-plotforeground) -tags "vmax legend" \
-	    -font $font
-	incr y $lineht
-	$c create image $x $y \
-	    -anchor ne \
-	    -image $_image(legend) -tags "colormap legend"
-	$c create rectangle $x $y 1 1 \
-	    -fill "" -outline "" -tags "sensor legend"
-	$c create text $x [expr {$h-2}] \
-	    -anchor se \
-	    -fill $itk_option(-plotforeground) -tags "vmin legend" \
-	    -font $font
-	$c bind sensor <Enter> [itcl::code $this EnterLegend %x %y]
-	$c bind sensor <Leave> [itcl::code $this LeaveLegend]
-	$c bind sensor <Motion> [itcl::code $this MotionLegend %x %y]
+        $c create text $x $y \
+            -anchor ne \
+            -fill $itk_option(-plotforeground) -tags "vmax legend" \
+            -font $font
+        incr y $lineht
+        $c create image $x $y \
+            -anchor ne \
+            -image $_image(legend) -tags "colormap legend"
+        $c create rectangle $x $y 1 1 \
+            -fill "" -outline "" -tags "sensor legend"
+        $c create text $x [expr {$h-2}] \
+            -anchor se \
+            -fill $itk_option(-plotforeground) -tags "vmin legend" \
+            -font $font
+        $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y]
+        $c bind sensor <Leave> [itcl::code $this LeaveLegend]
+        $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y]
     }
 
@@ -2181,6 +2170,6 @@
     if { [info exists _limits($_curFldName)] } {
         foreach { vmin vmax } $_limits($_curFldName) break
-	$c itemconfigure vmin -text [format %g $vmin]
-	$c itemconfigure vmax -text [format %g $vmax]
+        $c itemconfigure vmin -text [format %g $vmin]
+        $c itemconfigure vmax -text [format %g $vmax]
     }
     set y 2
@@ -2188,6 +2177,6 @@
     if { $title != "" } {
         $c itemconfigure title -text $title
-	$c coords title $x $y
-	incr y $lineht
+        $c coords title $x $y
+        incr y $lineht
     }
     $c coords vmax $x $y
@@ -2237,5 +2226,5 @@
     set font "Arial 8"
     set lineht [font metrics $font -linespace]
-    
+
     set ih [image height $_image(legend)]
     # Subtract off the offset of the color ramp from the top of the canvas
@@ -2243,14 +2232,14 @@
 
     if { [string match "component*" $fname] } {
-	set title ""
+        set title ""
     } else {
-	if { [info exists _fields($fname)] } {
-	    foreach { title units } $_fields($fname) break
-	    if { $units != "" } {
-		set title [format "%s (%s)" $title $units]
-	    }
-	} else {
-	    set title $fname
-	}
+        if { [info exists _fields($fname)] } {
+            foreach { title units } $_fields($fname) break
+            if { $units != "" } {
+                set title [format "%s (%s)" $title $units]
+            }
+        } else {
+            set title $fname
+        }
     }
     # If there's a legend title, increase the offset by the line height.
@@ -2268,6 +2257,6 @@
     }
     set color [eval format "\#%02x%02x%02x" $pixel]
-    $_image(swatch) put black  -to 0 0 23 23 
-    $_image(swatch) put $color -to 1 1 22 22 
+    $_image(swatch) put black  -to 0 0 23 23
+    $_image(swatch) put $color -to 1 1 22 22
 
     # Compute the value of the point
@@ -2279,5 +2268,5 @@
         set value 0.0
     }
-    set tipx [expr $x + 15] 
+    set tipx [expr $x + 15]
     set tipy [expr $y - 5]
     .rappturetooltip configure -icon $_image(swatch)
@@ -2287,5 +2276,5 @@
         Rappture::Tooltip::text $c [format "$title %g" $value]
     }
-    Rappture::Tooltip::tooltip show $c +$tipx,+$tipy    
+    Rappture::Tooltip::tooltip show $c +$tipx,+$tipy
 }
 
@@ -2302,5 +2291,5 @@
 # ----------------------------------------------------------------------
 itcl::body Rappture::VtkImageViewer::Combo {option} {
-    set c $itk_component(view) 
+    set c $itk_component(view)
     switch -- $option {
         post {
@@ -2315,9 +2304,9 @@
         }
         deactivate {
-            $c itemconfigure title -fill $itk_option(-plotforeground) 
+            $c itemconfigure title -fill $itk_option(-plotforeground)
         }
         invoke {
             $itk_component(field) value $_curFldLabel
-            AdjustSetting field
+            AdjustSetting -field
         }
         default {
@@ -2327,5 +2316,5 @@
 }
 
-itcl::body Rappture::VtkImageViewer::SetOrientation { side } { 
+itcl::body Rappture::VtkImageViewer::SetOrientation { side } {
     array set positions {
         front  "0.707107 0.707107 0 0"
@@ -2336,13 +2325,13 @@
         bottom "0 1 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
-}
+    set _view(-xpan) 0
+    set _view(-ypan) 0
+    set _view(-zoom) 1.0
+}
