Index: /trunk/gui/scripts/molvisviewer.tcl
===================================================================
--- /trunk/gui/scripts/molvisviewer.tcl	(revision 1710)
+++ /trunk/gui/scripts/molvisviewer.tcl	(revision 1711)
@@ -40,4 +40,48 @@
 
     itk_option define -device device Device ""
+
+    private variable _icon 0
+
+    private variable _mevent;		# info used for mouse event operations
+    private variable _rocker;		# info used for rock operations
+    private variable _dlist "";		# list of dataobj objects
+    private variable _dataobjs;		# data objects on server
+    private variable _dobj2transparency;# maps dataobj => transparency
+    private variable _dobj2raise;	# maps dataobj => raise flag 0/1
+
+    private variable _active;		# array of active models.
+    private variable _obj2models;	# array containing list of models 
+					# for each data object.
+
+    private variable _view
+    private variable _click
+
+    private variable _model
+    private variable _mlist
+    private variable _mrepresentation "ballnstick"
+
+    private variable _imagecache
+    private variable _state
+    private variable _labels  "default"
+    private variable _cacheid ""
+    private variable _cacheimage ""
+
+    private variable _delta1 10
+    private variable _delta2 2
+
+    private common _settings  ;		# Array of settings for all known 
+					# widgets
+    private variable _initialized
+
+    private common _downloadPopup;	# Download options from popup
+    private variable _pdbdata;		# PDB data from run file sent to pymol
+    private common _hardcopy
+    private variable _nextToken 0
+    private variable _outbuf "";
+    private variable _buffering 0;
+    private variable _resizePending 0;
+    private variable _width
+    private variable _height
+    private variable _restore 1;	# Restore camera settings
 
     constructor { hostlist args } {
@@ -92,46 +136,4 @@
     private method EnableDownload { popup what }
 
-    private variable _icon 0
-
-    private variable _mevent;		# info used for mouse event operations
-    private variable _rocker;		# info used for rock operations
-    private variable _dlist "";		# list of dataobj objects
-    private variable _dataobjs;		# data objects on server
-    private variable _dobj2transparency;# maps dataobj => transparency
-    private variable _dobj2raise;	# maps dataobj => raise flag 0/1
-
-    private variable _active;		# array of active models.
-    private variable _obj2models;	# array containing list of models 
-					# for each data object.
-
-    private variable _view
-    private variable _click
-
-    private variable _model
-    private variable _mlist
-    private variable _mrepresentation "ballnstick"
-
-    private variable _imagecache
-    private variable _state
-    private variable _labels  "default"
-    private variable _cacheid ""
-    private variable _cacheimage ""
-
-    private variable _delta1 10
-    private variable _delta2 2
-
-    private common _settings  ;		# Array of settings for all known 
-					# widgets
-    private variable _initialized
-
-    private common _downloadPopup;	# Download options from popup
-    private variable _pdbdata;		# PDB data from run file sent to pymol
-    private common _hardcopy
-    private variable _nextToken 0
-    private variable _outbuf "";
-    private variable _buffering 0;
-    private variable _resizePending 0;
-    private variable _width
-    private variable _height
 }
 
@@ -179,4 +181,5 @@
     set _state(client) 1
     set _hostlist $hostlist
+    set _restore 1
 
     array set _view {
@@ -595,4 +598,5 @@
 	return 0
     }
+    set _restore 1 
     set result [VisViewer::Connect $hosts]
     if { $result } {
@@ -665,5 +669,4 @@
     global count
     incr count
-    debug "$count: cacheid=$cacheid frame=$frame\n"
     if { $cacheid != $_cacheid } {
 	array unset _imagecache 
@@ -702,9 +705,11 @@
     set _buffering 1
 
-    set _rocker(server) 0
-    set _cacheid 0
-    SendCmd "raw -defer {set auto_color,0}"
-    SendCmd "raw -defer {set auto_show_lines,0}"
-
+    if { $_restore } {
+	set _rocker(server) 0
+	set _cacheid 0
+	SendCmd "raw -defer {set auto_color,0}"
+	SendCmd "raw -defer {set auto_show_lines,0}"
+	SendCmd "raw -defer {set connect_mode,1}"
+    }
     set dlist [get]
     foreach dataobj $dlist {
@@ -797,5 +802,4 @@
 	    set _mlist($model) 1
 	}
-
 	if { $_mlist($model) == 1 } {
 	    if {  [info exists _model($model-newtransparency)] || 
@@ -842,25 +846,28 @@
 	Update
     }
-    # Reset viewing parameters
-    set w  [winfo width $itk_component(3dview)] 
-    set h  [winfo height $itk_component(3dview)] 
-    SendCmd [subst { 
-	reset
-	screen $w $h
-	rotate $_view(mx) $_view(my) $_view(mz)
-	pan $_view(x) $_view(y)
-	zoom $_view(zoom)
-    }]
-    debug "rebuild: rotate $_view(mx) $_view(my) $_view(mz)"
-
-    # foreach all models 
-    spherescale update 
-    stickradius update
-    labels update 
-    opacity update 
-    cartoontrace update 
-
-    projection update 
-    representation update 
+    if { $_restore } {
+	# Set or restore viewing parameters.  We do this for the first
+	# model and assume this works for everything else.
+	set w  [winfo width $itk_component(3dview)] 
+	set h  [winfo height $itk_component(3dview)] 
+	SendCmd [subst { 
+	    reset
+	    screen $w $h
+	    rotate $_view(mx) $_view(my) $_view(mz)
+	    pan $_view(x) $_view(y)
+	    zoom $_view(zoom)
+	}]
+	debug "rebuild: rotate $_view(mx) $_view(my) $_view(mz)"
+	# foreach all models 
+	spherescale update 
+	stickradius update
+	labels update 
+	opacity update 
+	cartoontrace update 
+	
+	projection update 
+	representation update 
+	set _restore 0
+    }
 
     set _buffering 0;			# Turn off buffering.
@@ -999,4 +1006,7 @@
 	after cancel $_rocker(afterid)
 	unset _rocker(afterid)
+    }
+    if { ![winfo viewable $itk_component(3dview)] } {
+	return
     }
     set _rocker(on) $_settings($this-rock) 
@@ -1356,6 +1366,8 @@
 	}
 	set _dobj2raise($dataobj) $params(-raise)
+	debug "setting parameters for $dataobj\n"
 
 	if { [isconnected] } {
+	    debug "calling rebuild\n"
 	    $_dispatcher event -idle !rebuild
 	}
@@ -1614,5 +1626,6 @@
     set _settings($this-spherescale) $radius
     if { $models == "all" } {
-	set models [array names _mlist] 
+	SendCmd "spherescale -model all $radius"
+	return
     }
     set overrideradius [expr $radius * 0.8]
@@ -1649,5 +1662,6 @@
     set _settings($this-stickradius) $radius
     if { $models == "all" } {
-	set models [array names _mlist] 
+	SendCmd "stickradius -model all $radius"
+	return
     }
     set overrideradius [expr $radius * 0.8]
@@ -1683,9 +1697,10 @@
     }
     set _settings($this-opacity) $opacity
+    set transparency [expr 1.0 - $opacity]
     if { $models == "all" } {
-	set models [array names _mlist] 
+	SendCmd "transparency -model all $transparency"
+	return
     }
     set overridetransparency 0.60
-    set transparency [expr 1.0 - $opacity]
     SendCmd "transparency -model all $overridetransparency"
     foreach model $models {
@@ -1714,5 +1729,6 @@
     set _settings($this-showlabels) $showlabels
     if { $models == "all" } {
-	set models [array names _mlist] 
+	SendCmd "label -model all $showlabels"
+	return
     }
     SendCmd "label -model all off"
@@ -1744,5 +1760,6 @@
     set _settings($this-cartoontrace) $trace
     if { $models == "all" } {
-	set models [array names _mlist] 
+	SendCmd "cartoontrace -model all $trace"
+	return
     }
     SendCmd "cartoontrace -model all off"
@@ -1849,2 +1866,3 @@
     }
 }
+
