Index: trunk/gui/scripts/vtkviewer.tcl
===================================================================
--- trunk/gui/scripts/vtkviewer.tcl	(revision 3707)
+++ trunk/gui/scripts/vtkviewer.tcl	(revision 3708)
@@ -224,5 +224,5 @@
     array set _settings [subst {
         legend          1
-	molecule-representation  "Ball and Stick"
+        molecule-representation  "Ball and Stick"
         molecule-edges           0
         molecule-labels          0
@@ -231,5 +231,5 @@
         molecule-visible         1
         molecule-wireframe       0
-	molecule-palette         elementDefault
+        molecule-palette         elementDefault
         mesh-edges           0
         mesh-lighting        1
@@ -237,5 +237,5 @@
         mesh-visible         1
         mesh-wireframe       0
-	mesh-palette         rainbow
+        mesh-palette         rainbow
     }]
 
@@ -280,5 +280,5 @@
     pack $itk_component(reset) -side top -padx 2 -pady 2
     Rappture::Tooltip::for $itk_component(reset) \
-	"Reset the view to the default zoom level"
+        "Reset the view to the default zoom level"
 
     itk_component add zoomin {
@@ -307,9 +307,9 @@
 
     if { [catch { BuildMeshTab } errs ]  != 0 } {
-	puts stderr "errs=$errs"
+        puts stderr "errs=$errs"
     }
     if { [catch { BuildMoleculeTab } errs ]  != 0 } {
-	global errorInfo
-	puts stderr "errs=$errs\nerrorInfo=$errorInfo"
+        global errorInfo
+        puts stderr "errs=$errs\nerrorInfo=$errorInfo"
     }
     BuildAxisTab
@@ -495,5 +495,4 @@
 }
 
-
 # ----------------------------------------------------------------------
 # USAGE: delete ?<dataobj1> <dataobj2> ...?
@@ -712,15 +711,15 @@
             # Tell the server the viewer, hub, user and session.
             # Do this immediately on connect before buffing any commands
-	    global env
+            global env
 
             set info {}
             set user "???"
-	    if { [info exists env(USER)] } {
+            if { [info exists env(USER)] } {
                 set user $env(USER)
-	    }
+            }
             set session "???"
-	    if { [info exists env(SESSION)] } {
+            if { [info exists env(SESSION)] } {
                 set session $env(SESSION)
-	    }
+            }
             lappend info "hub" [exec hostname]
             lappend info "client" "vtkviewer"
@@ -897,7 +896,7 @@
             if { ![info exists _datasets($tag)] } {
                 set bytes [$dataobj data $comp]
-		if { $bytes == "" } {
-		    continue
-		}
+                if { $bytes == "" } {
+                    continue
+                }
                 set length [string length $bytes]
                 if { $_reportClientInfo }  {
@@ -915,16 +914,5 @@
                 append _outbuf $bytes
                 set _datasets($tag) 1
-                switch -- [$dataobj type $comp] {
-                    "polydata" {
-                        SendCmd "polydata add $tag"
-                    }
-                    "glyphs" {
-                        set shape [$dataobj shape $comp]
-                        SendCmd "glyphs add $shape $tag"
-                    }
-                    "molecule" {
-                        SendCmd "molecule add $tag"
-                    }
-                }
+                SetObjectStyle $dataobj $comp
             }
             lappend _obj2datasets($dataobj) $tag
@@ -933,5 +921,4 @@
                 puts stderr "$count: dataset visible 1 $tag"
             }
-            SetObjectStyle $dataobj $comp
         }
     }
@@ -954,6 +941,6 @@
     }
     if { $_reset } {
-	set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
-	$_arcball quaternion $q 
+        set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]
+        $_arcball quaternion $q 
         SendCmd "camera reset"
         if { $_view(ortho)} {
@@ -961,7 +948,7 @@
         } else {
             SendCmd "camera mode persp"
-	}
-	DoRotate
-	PanCamera
+        }
+        DoRotate
+        PanCamera
         Zoom reset
     }
@@ -1074,5 +1061,4 @@
     SendCmd "camera pan $x $y"
 }
-
 
 # ----------------------------------------------------------------------
@@ -1215,9 +1201,9 @@
             set sval [expr { 0.01 * double($val) }]
             foreach dataset [CurrentDatasets -visible $_first] {
-		foreach { dataobj comp } [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "polydata" } {
-		    SendCmd "$type opacity $sval $dataset"
-		}
+                foreach { dataobj comp } [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "polydata" } {
+                    SendCmd "$type opacity $sval $dataset"
+                }
             }
         }
@@ -1225,9 +1211,9 @@
             set bool $_settings(mesh-wireframe)
             foreach dataset [CurrentDatasets -visible $_first] {
-		foreach { dataobj comp } [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "polydata" } {
-		    SendCmd "$type wireframe $bool $dataset"
-		}
+                foreach { dataobj comp } [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "polydata" } {
+                    SendCmd "$type wireframe $bool $dataset"
+                }
             }
         }
@@ -1235,9 +1221,9 @@
             set bool $_settings(mesh-visible)
             foreach dataset [CurrentDatasets -visible $_first] {
-		foreach { dataobj comp } [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "polydata" } {
-		    SendCmd "$type visible $bool $dataset"
-		}
+                foreach { dataobj comp } [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "polydata" } {
+                    SendCmd "$type visible $bool $dataset"
+                }
             }
         }
@@ -1245,9 +1231,9 @@
             set bool $_settings(mesh-lighting)
             foreach dataset [CurrentDatasets -visible $_first] {
-		foreach { dataobj comp } [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "polydata" } {
-		    SendCmd "$type lighting $bool $dataset"
-		}
+                foreach { dataobj comp } [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "polydata" } {
+                    SendCmd "$type lighting $bool $dataset"
+                }
             }
         }
@@ -1255,9 +1241,9 @@
             set bool $_settings(mesh-edges)
             foreach dataset [CurrentDatasets -visible $_first] {
-		foreach { dataobj comp } [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "polydata" } {
-		    SendCmd "$type edges $bool $dataset"
-		}
+                foreach { dataobj comp } [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "polydata" } {
+                    SendCmd "$type edges $bool $dataset"
+                }
             }
         }
@@ -1267,8 +1253,8 @@
             foreach dataset [CurrentDatasets -visible $_first] {
                 foreach {dataobj comp} [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "polydata" } {
-		    ChangeColormap $dataobj $comp $palette
-		}
+                set type [$dataobj type $comp]
+                if { $type == "polydata" } {
+                    ChangeColormap $dataobj $comp $palette
+                }
             }
             set _legendPending 1
@@ -1278,9 +1264,9 @@
             set sval [expr { 0.01 * double($val) }]
             foreach dataset [CurrentDatasets -visible $_first] {
-		foreach { dataobj comp } [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "molecule" } {
-		    SendCmd "molecule opacity $sval $dataset"
-		}
+                foreach { dataobj comp } [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "molecule" } {
+                    SendCmd "molecule opacity $sval $dataset"
+                }
             }
         }
@@ -1288,9 +1274,9 @@
             set bool $_settings(molecule-wireframe)
             foreach dataset [CurrentDatasets -visible $_first] {
-		foreach { dataobj comp } [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "molecule" } {
-		    SendCmd "molecule wireframe $bool $dataset"
-		}
+                foreach { dataobj comp } [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "molecule" } {
+                    SendCmd "molecule wireframe $bool $dataset"
+                }
             }
         }
@@ -1298,9 +1284,9 @@
             set bool $_settings(molecule-visible)
             foreach dataset [CurrentDatasets -visible $_first] {
-		foreach { dataobj comp } [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "molecule" } {
-		    SendCmd "molecule visible $bool $dataset"
-		}
+                foreach { dataobj comp } [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "molecule" } {
+                    SendCmd "molecule visible $bool $dataset"
+                }
             }
         }
@@ -1308,9 +1294,9 @@
             set bool $_settings(molecule-lighting)
             foreach dataset [CurrentDatasets -visible $_first] {
-		foreach { dataobj comp } [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "molecule" } {
-		    SendCmd "molecule lighting $bool $dataset"
-		}
+                foreach { dataobj comp } [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "molecule" } {
+                    SendCmd "molecule lighting $bool $dataset"
+                }
             }
         }
@@ -1318,9 +1304,9 @@
             set bool $_settings(molecule-edges)
             foreach dataset [CurrentDatasets -visible $_first] {
-		foreach { dataobj comp } [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "molecule" } {
-		    SendCmd "molecule edges $bool $dataset"
-		}
+                foreach { dataobj comp } [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "molecule" } {
+                    SendCmd "molecule edges $bool $dataset"
+                }
             }
         }
@@ -1330,78 +1316,78 @@
             foreach dataset [CurrentDatasets -visible $_first] {
                 foreach {dataobj comp} [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "molecule" } {
-		    ChangeColormap $dataobj $comp $palette
-		    if { $palette == "elementDefault" } {
-			SendCmd "molecule colormode by_elements element $dataset"
-		    } else {
-			# FIXME: Set the chosen scalar field name here
-			SendCmd "molecule colormode scalar {} $dataset"
-		    }
-		}
+                set type [$dataobj type $comp]
+                if { $type == "molecule" } {
+                    ChangeColormap $dataobj $comp $palette
+                    if { $palette == "elementDefault" } {
+                        SendCmd "molecule colormode by_elements element $dataset"
+                    } else {
+                        # FIXME: Set the chosen scalar field name here
+                        SendCmd "molecule colormode scalar {} $dataset"
+                    }
+                }
             }
             set _legendPending 1
         }
-	"molecule-representation" {
-	    set value [$itk_component(representation) value]
-	    set value [$itk_component(representation) translate $value]
-	    switch -- $value {
-		"ballandstick" {
-		    set rscale covalent
-		    set ashow 1
-		    set bshow 1
-		    set bstyle cylinder
-		    set ascale 0.3
-		    set bscale 0.075
-		}
-		"balls" - "spheres" {
-		    set rscale covalent
-		    set ashow 1
-		    set bshow 0
-		    set bstyle cylinder
-		    set ascale 0.3
-		    set bscale 0.075
-		}
-		"sticks" {
-		    set rscale none
-		    set ashow 1
-		    set bshow 1
-		    set bstyle cylinder
-		    set ascale 0.075
-		    set bscale 0.075
-		}
-		"spacefilling" {
-		    set rscale van_der_waals
-		    set ashow 1
-		    set bshow 0
-		    set bstyle cylinder
-		    set ascale 1.0
-		    set bscale 0.075
-		}
-		"rods"  {
-		    set rscale none
-		    set ashow 1
-		    set bshow 1
-		    set bstyle cylinder
-		    set ascale 0.1
-		    set bscale 0.1
-		}
-		"wireframe" - "lines" {
-		    set rscale none
-		    set ashow 0
-		    set bshow 1
-		    set bstyle line
-		    set ascale 1.0
-		    set bscale 1.0
-		}
-		default {
-		    error "unknown representation $value"
-		}
-	    }
-	    foreach dataset [CurrentDatasets -visible $_first] {
-		foreach {dataobj comp} [split $dataset -] break
-		set type [$dataobj type $comp]
-		if { $type == "molecule" } {
-		    SendCmd [subst {molecule rscale $rscale $dataset
+        "molecule-representation" {
+            set value [$itk_component(representation) value]
+            set value [$itk_component(representation) translate $value]
+            switch -- $value {
+                "ballandstick" {
+                    set rscale covalent
+                    set ashow 1
+                    set bshow 1
+                    set bstyle cylinder
+                    set ascale 0.3
+                    set bscale 0.075
+                }
+                "balls" - "spheres" {
+                    set rscale covalent
+                    set ashow 1
+                    set bshow 0
+                    set bstyle cylinder
+                    set ascale 0.3
+                    set bscale 0.075
+                }
+                "sticks" {
+                    set rscale none
+                    set ashow 1
+                    set bshow 1
+                    set bstyle cylinder
+                    set ascale 0.075
+                    set bscale 0.075
+                }
+                "spacefilling" {
+                    set rscale van_der_waals
+                    set ashow 1
+                    set bshow 0
+                    set bstyle cylinder
+                    set ascale 1.0
+                    set bscale 0.075
+                }
+                "rods"  {
+                    set rscale none
+                    set ashow 1
+                    set bshow 1
+                    set bstyle cylinder
+                    set ascale 0.1
+                    set bscale 0.1
+                }
+                "wireframe" - "lines" {
+                    set rscale none
+                    set ashow 0
+                    set bshow 1
+                    set bstyle line
+                    set ascale 1.0
+                    set bscale 1.0
+                }
+                default {
+                    error "unknown representation $value"
+                }
+            }
+            foreach dataset [CurrentDatasets -visible $_first] {
+                foreach {dataobj comp} [split $dataset -] break
+                set type [$dataobj type $comp]
+                if { $type == "molecule" } {
+                    SendCmd [subst {molecule rscale $rscale $dataset
 molecule atoms $ashow $dataset
 molecule bonds $bshow $dataset
@@ -1409,7 +1395,7 @@
 molecule ascale $ascale $dataset
 molecule bscale $bscale $dataset}]
-		}
-	    }
-	}
+                }
+            }
+        }
         "molecule-labels" {
             set bool $_settings(molecule-labels)
@@ -1543,7 +1529,7 @@
 
     if { $style(-color) == "elementDefault" } {
-	set name "$style(-color)"
+        set name "$style(-color)"
     } else {
-	set name "$style(-color):$style(-levels):$style(-opacity)"
+        set name "$style(-color):$style(-levels):$style(-opacity)"
     }
     if { ![info exists _colormaps($name)] } {
@@ -1554,15 +1540,15 @@
          $_dataset2style($tag) != $name } {
         set _dataset2style($tag) $name
-	switch -- [$dataobj type $comp] {
-	    "polygon" {
-		SendCmd "pseudocolor colormap $name $tag"
-	    }
-	    "glyphs" {
-		SendCmd "glyphs colormap $name $tag"
-	    }
-	    "molecule" {
-		SendCmd "molecule colormap $name $tag"
-	    }
-	}
+        switch -- [$dataobj type $comp] {
+            "polygon" {
+                SendCmd "pseudocolor colormap $name $tag"
+            }
+            "glyphs" {
+                SendCmd "glyphs colormap $name $tag"
+            }
+            "molecule" {
+                SendCmd "molecule colormap $name $tag"
+            }
+        }
     }
 }
@@ -1573,5 +1559,5 @@
 itcl::body Rappture::VtkViewer::BuildColormap { name styles } {
     if { $name ==  "elementDefault" } {
-	return
+        return
     }
     array set style $styles
@@ -1588,5 +1574,4 @@
     SendCmd "colormap add $name { $cmap } { $wmap }"
 }
-
 
 # ----------------------------------------------------------------------
@@ -1617,7 +1602,7 @@
         if { ![info exists _limits($tag)] } {
             set data [$dataobj data $comp]
-	    if { $data == "" } {
-		continue
-	    }
+            if { $data == "" } {
+                continue
+            }
             set tmpfile file[pid].vtk
             set f [open "$tmpfile" "w"]
@@ -1627,32 +1612,52 @@
             set reader [vtkDataSetReader $tag-xvtkDataSetReader]
             $reader SetFileName $tmpfile
-            $reader ReadAllNormalsOn
-            $reader ReadAllScalarsOn
-            $reader ReadAllVectorsOn
-            $reader ReadAllFieldsOn
+set debug 0
+            if {$debug} {
+                # Only needed for debug output below
+                $reader ReadAllNormalsOn
+                $reader ReadAllTCoordsOn
+                $reader ReadAllScalarsOn
+                $reader ReadAllColorScalarsOn
+                $reader ReadAllVectorsOn
+                $reader ReadAllTensorsOn
+                $reader ReadAllFieldsOn
+            }
             $reader Update
+            file delete $tmpfile
             set output [$reader GetOutput]
             set _limits($tag) [$output GetBounds]
-            set pointData [$output GetPointData]
-            set fieldData [$output GetFieldData]
-	    if 1 {
-		puts stderr "\#scalars=[$reader GetNumberOfScalarsInFile]"
-		puts stderr "\#vectors=[$reader GetNumberOfVectorsInFile]"
-		puts stderr "\#tensors=[$reader GetNumberOfTensorsInFile]"
-		puts stderr "\#normals=[$reader GetNumberOfNormalsInFile]"
-		puts stderr "\#fielddata=[$reader GetNumberOfFieldDataInFile]"
-		puts stderr "fielddataname=[$reader GetFieldDataNameInFile 0]"
-		puts stderr "field \#arrays=[$fieldData GetNumberOfArrays]"
-		puts stderr "point \#arrays=[$pointData GetNumberOfArrays]"
-		puts stderr "field \#components=[$fieldData GetNumberOfComponents]"
-		puts stderr "point \#components=[$pointData GetNumberOfComponents]"
-		puts stderr "field \#tuples=[$fieldData GetNumberOfTuples]"
-		puts stderr "point \#tuples=[$pointData GetNumberOfTuples]"
-		puts stderr "point \#scalars=[$pointData GetScalars]"
-		puts stderr vectors=[$pointData GetVectors]
-	    }
+            if {$debug} {
+                puts stderr "\#scalars=[$reader GetNumberOfScalarsInFile]"
+                puts stderr "\#vectors=[$reader GetNumberOfVectorsInFile]"
+                puts stderr "\#tensors=[$reader GetNumberOfTensorsInFile]"
+                puts stderr "\#normals=[$reader GetNumberOfNormalsInFile]"
+                puts stderr "\#tcoords=[$reader GetNumberOfTCoordsInFile]"
+                puts stderr "\#fielddata=[$reader GetNumberOfFieldDataInFile]"
+                puts stderr "fielddataname=[$reader GetFieldDataNameInFile 0]"
+                set pointData [$output GetPointData]
+                if { $pointData != ""} {
+                    puts stderr "point \#arrays=[$pointData GetNumberOfArrays]"
+                    puts stderr "point \#components=[$pointData GetNumberOfComponents]"
+                    puts stderr "point \#tuples=[$pointData GetNumberOfTuples]"
+                    puts stderr "point scalars=[$pointData GetScalars]"
+                    puts stderr "point vectors=[$pointData GetVectors]"
+                }
+                set cellData [$output GetCellData]
+                if { $cellData != ""} {
+                    puts stderr "cell \#arrays=[$cellData GetNumberOfArrays]"
+                    puts stderr "cell \#components=[$cellData GetNumberOfComponents]"
+                    puts stderr "cell \#tuples=[$cellData GetNumberOfTuples]"
+                    puts stderr "cell scalars=[$cellData GetScalars]"
+                    puts stderr "cell vectors=[$cellData GetVectors]"
+                }
+                set fieldData [$output GetFieldData]
+                if { $fieldData != ""} {
+                    puts stderr "field \#arrays=[$fieldData GetNumberOfArrays]"
+                    puts stderr "field \#components=[$fieldData GetNumberOfComponents]"
+                    puts stderr "field \#tuples=[$fieldData GetNumberOfTuples]"
+                }
+            }
             rename $output ""
             rename $reader ""
-            file delete $tmpfile
         }
         foreach { xMin xMax yMin yMax zMin zMax} $_limits($tag) break
@@ -1824,5 +1829,4 @@
 }
 
-
 itcl::body Rappture::VtkViewer::BuildCameraTab {} {
     set inner [$itk_component(main) insert end \
@@ -2061,12 +2065,12 @@
     $inner.rep choices insert end \
         "ballandstick"  "Ball and Stick" \
-        "spheres"	"Spheres"	\
-        "sticks"	"Sticks"	\
-        "rods"		"Rods"          \
-        "wireframe"     "Wireframe"	\
+        "spheres"	"Spheres"        \
+        "sticks"	"Sticks"	 \
+        "rods"		"Rods"           \
+        "wireframe"     "Wireframe"	 \
         "spacefilling"  "Space Filling" 
 
     bind $inner.rep <<Value>> \
-	[itcl::code $this AdjustSetting molecule-representation]
+        [itcl::code $this AdjustSetting molecule-representation]
     $inner.rep value "Ball and Stick"
 
@@ -2076,5 +2080,5 @@
     }
     $inner.palette choices insert end \
-	"elementDefault"	     "elementDefault" \
+        "elementDefault"     "elementDefault"   \
         "BCGYR"              "BCGYR"            \
         "BGYOR"              "BGYOR"            \
@@ -2194,5 +2198,4 @@
 }
 
-
 itcl::body Rappture::VtkViewer::GetVtkData { args } {
     set bytes ""
@@ -2202,5 +2205,5 @@
             set contents [$dataobj data $comp]
             append bytes "$contents\n"
-	    append bytes "\# End of VTK file\n\n"
+            append bytes "\# End of VTK file\n\n"
         }
     }
@@ -2279,6 +2282,7 @@
             -visible 1
         }
-	set shape [$dataobj shape $comp]
+        set shape [$dataobj shape $comp]
         array set settings $style
+        SendCmd "glyphs add $shape $tag"
         SendCmd "glyphs normscale 0 $tag"
         SendCmd "glyphs gscale $settings(-gscale) $tag"
@@ -2293,4 +2297,5 @@
         set _haveGlyphs 1
     } elseif { $type == "molecule" } {
+        SendCmd "molecule add $tag"
         SendCmd "molecule rscale van_der_waals $tag"
         set _haveMolecules 1
@@ -2307,4 +2312,5 @@
         }
         array set settings $style
+        SendCmd "polydata add $tag"
         SendCmd "polydata visible $settings(-visible) $tag"
         set _settings(mesh-visible) $settings(-visible)
@@ -2456,5 +2462,4 @@
 }
 
-
 # ----------------------------------------------------------------------
 # USAGE: Slice move x|y|z <newval>
@@ -2508,3 +2513,2 @@
     set _view(zoom) 1.0
 }
-
