Changeset 924 for trunk/gui/scripts/visviewer.tcl
- Timestamp:
- Mar 6, 2008, 12:38:12 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/visviewer.tcl
r921 r924 24 24 set _servers(pymol) "" 25 25 26 protected variable _dispatcher "" 27 protected variable _hosts "" 28 protected variable _sid "" 29 protected variable _parser "" 26 protected variable _dispatcher "" ;# dispatcher for !events 27 protected variable _hosts "" ;# list of hosts for server 28 protected variable _sid "" ;# socket connection to server 29 protected variable _parser "" ;# interpreter for incoming commands 30 30 protected variable _image 31 private common _done 32 private variable _buffer 31 private common _done ;# Used to indicate status of send. 32 private variable _buffer ;# buffer for incoming/outgoing commands 33 33 34 34 constructor { hostlist args } { 35 35 # defined below 36 36 } 37 37 destructor { 38 38 # defined below 39 39 } 40 40 # Used internally only. … … 56 56 protected method Euler2XYZ {theta phi psi} 57 57 58 public proc SetPymolServerList {namelist} { 59 _CheckNameList $namelist 60 set _servers(pymol) $namelist 61 } 62 public proc SetNanovisServerList {namelist} { 63 _CheckNameList $namelist 64 set _servers(nanovis) $namelist 65 } 66 public proc SetServerList {tag namelist} { 67 _CheckNameList $namelist 68 set _servers($tag) $namelist 69 } 58 70 public proc GetServerList { tag } { 59 return $_servers($tag) 60 } 61 public proc SetServerList {tag namelist} { 62 _CheckNameList $namelist 63 set _servers($tag) $namelist 71 return $_servers($tag) 64 72 } 65 73 } … … 126 134 itcl::body Rappture::VisViewer::destructor {} { 127 135 interp delete $_parser 136 array unset _done $this 128 137 } 129 138 … … 131 140 # _Shuffle -- 132 141 # 133 # 142 # Shuffle the list of server hosts. 134 143 # 135 144 itcl::body Rappture::VisViewer::_Shuffle { hostlist } { … … 137 146 set random_hosts {} 138 147 for { set i [llength $hosts] } { $i > 0 } { incr i -1 } { 139 140 141 142 143 144 148 set index [expr {round(rand()*$i - 0.5)}] 149 if { $index == $i } { 150 set index [expr $i - 1] 151 } 152 lappend random_hosts [lindex $hosts $index] 153 set hosts [lreplace $hosts $index $index] 145 154 } 146 155 return $random_hosts … … 156 165 set pattern {^[a-zA-Z0-9\.]+:[0-9]+(,[a-zA-Z0-9\.]+:[0-9]+)*$} 157 166 if { ![regexp $pattern $namelist match] } { 158 167 error "bad visualization server address \"$namelist\": should be host:port,host:port,..." 159 168 } 160 169 } … … 169 178 itcl::body Rappture::VisViewer::_ServerDown {} { 170 179 if { [info exists itk_component(area)] } { 171 172 180 set x [expr {[winfo rootx $itk_component(area)]+10}] 181 set y [expr {[winfo rooty $itk_component(area)]+10}] 173 182 } else { 174 183 set x 0; set y 0 175 184 } 176 185 Rappture::Tooltip::cue @$x,$y "Lost connection to visualization server. This happens sometimes when there are too many users and the system runs out of memory.\n\nTo reconnect, reset the view or press any other control. Your picture should come right back up." … … 200 209 if { [catch {socket $hostname $port} _sid] != 0 } { 201 210 if {[llength $servers] == 0} { 202 211 blt::busy release $itk_component(hull) 203 212 return 0 204 213 } 205 214 # Get the next server 206 215 foreach {hostname port} [split [lindex $servers 0] :] break 207 216 set servers [lrange $servers 1 end] … … 213 222 puts -nonewline $_sid [binary format I $memorySize] 214 223 flush $_sid 215 224 216 225 # read back a reconnection order 217 226 set data [read $_sid 4] 218 227 if {[binary scan $data cccc b1 b2 b3 b4] != 4} { 219 228 blt::busy release $itk_component(hull) 220 229 error "couldn't read redirection request" 221 230 } … … 227 236 228 237 if { [string equal $addr "0.0.0.0"] } { 229 230 231 232 233 234 238 # We're connected. Cancel any pending serverDown events and 239 # release the busy window over the hull. 240 $_dispatcher cancel !serverDown 241 blt::busy release $itk_component(hull) 242 fconfigure $_sid -buffering line 243 fileevent $_sid readable [itcl::code $this _ReceiveHelper] 235 244 return 1 236 245 } … … 253 262 catch {close $_sid} err 254 263 set _sid "" 255 256 } 257 set _buffer(in) "" 264 $_dispatcher event -after 750 !serverDown 265 } 266 set _buffer(in) "" 258 267 } 259 268 … … 270 279 # _SendHelper -- 271 280 # 272 # 273 # 274 # 275 # 276 # 281 # Helper routine called from a file event to send data when the 282 # connection is writable (i.e. not blocked). Sends data in chunks 283 # of 8k (or less). Sets magic variable _done($this) to indicate 284 # that we're either finished (success) or could not send bytes to 285 # the server (failure). 277 286 # 278 287 itcl::body Rappture::VisViewer::_SendHelper {} { 279 288 set bytesLeft [string length $_buffer(out)] 280 289 if { $bytesLeft > 0} { 281 282 283 284 285 286 287 288 289 } 290 291 292 293 294 set _done($this) 0;# Failure295 290 set chunk [string range $_buffer(out) 0 8095] 291 set _buffer(out) [string range $_buffer(out) 8096 end] 292 incr bytesLeft -8096 293 set code [catch { 294 if { $bytesLeft > 0 } { 295 puts -nonewline $_sid $chunk 296 } else { 297 puts $_sid $chunk 298 } 299 } err] 300 if { $code != 0 } { 301 puts stderr "error sending data to $_sid: $err" 302 Disconnect 303 set _done($this) 0; # Failure 304 } 296 305 } else { 297 set _done($this) 1;# Success306 set _done($this) 1; # Success 298 307 } 299 308 } … … 302 311 # SendBytes -- 303 312 # 304 # 313 # Send a a string to the visualization server. 305 314 # 306 315 itcl::body Rappture::VisViewer::SendBytes { bytes } { … … 308 317 309 318 if { ![IsConnected]} { 310 311 312 319 # If we aren't connected, assume it's because the connection to the 320 # visualization server broke. Try to open a connection and trigger a 321 # rebuild. 313 322 $_dispatcher cancel !serverDown 314 323 set x [expr {[winfo rootx $itk_component(area)]+10}] 315 324 set y [expr {[winfo rooty $itk_component(area)]+10}] 316 325 Rappture::Tooltip::cue @$x,$y "Connecting..." 317 326 set code [catch { Connect } ok] 318 327 if { $code == 0 && $ok} { 319 320 328 $_dispatcher event -idle !rebuild 329 Rappture::Tooltip::cue hide 321 330 } else { 322 323 324 331 Rappture::Tooltip::cue @$x,$y "Can't connect to visualization server. This may be a network problem. Wait a few moments and try resetting the view." 332 } 333 return 325 334 } 326 335 set _done($this) 1 … … 341 350 itcl::body Rappture::VisViewer::ReceiveBytes { size } { 342 351 if { [eof $_sid] } { 343 352 error "unexpected eof on socket" 344 353 } 345 354 set bytes [read $_sid $size] … … 351 360 # _ReceiveHelper -- 352 361 # 353 # 354 # 355 # 356 # 362 # Helper routine called from a file event when the connection is 363 # readable (i.e. a command response has been sent by the rendering 364 # server. Reads the incoming command and executes it in a safe 365 # interpreter to handle the action. 357 366 # 358 367 # Note: This routine currently only handles command responses from 359 # 360 # 361 # 362 # nv>image -bytes 100000yes363 # ...following 100000 bytes... no368 # the visualization server. It doesn't handle non-blocking 369 # reads from the visualization server. 370 # 371 # nv>image -bytes 100000 yes 372 # ...following 100000 bytes... no 364 373 # 365 374 itcl::body Rappture::VisViewer::_ReceiveHelper {} { 366 375 if { [IsConnected] } { 367 368 369 376 if { [eof $_sid] } { 377 error "_receive: unexpected eof on socket" 378 } 370 379 if { [gets $_sid line] < 0 } { 371 380 Disconnect … … 373 382 ReceiveEcho <<line $line 374 383 append _buffer(in) [string range $line 3 end] 375 384 append _buffer(in) "\n" 376 385 if {[info complete $_buffer(in)]} { 377 386 set request $_buffer(in) … … 395 404 itcl::body Rappture::VisViewer::Flush {} { 396 405 if { [IsConnected] } { 397 406 flush $_sid 398 407 } 399 408 } … … 403 412 # Color2RGB -- 404 413 # 405 # 406 # 414 # Converts a color name to a list of r,g,b values needed for the 415 # engine. Each r/g/b component is scaled in the # range 0-1. 407 416 # 408 417 itcl::body Rappture::VisViewer::Color2RGB {color} { … … 417 426 # Euler2XYZ -- 418 427 # 419 # 420 # 421 # 428 # Converts euler angles for the camera placement the to angles of 429 # rotation about the x/y/z axes, used by the engine. Returns a list: 430 # {xangle, yangle, zangle}. 422 431 # 423 432 itcl::body Rappture::VisViewer::Euler2XYZ {theta phi psi} {
Note: See TracChangeset
for help on using the changeset viewer.