- Timestamp:
- May 5, 2007 12:19:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/molvisviewer.tcl
r701 r704 42 42 public method download {option args} 43 43 protected method _rock {option} 44 protected method _sendit {args} 44 45 protected method _send {args} 45 protected method _receive { }46 protected method _receive { {sid ""} } 46 47 protected method _update { args } 47 48 protected method _rebuild { } … … 329 330 $_image(plot) blank 330 331 331 if ([isconnected]) { 332 disconnect 333 } 332 disconnect 334 333 335 334 if {"" == $hostlist} { … … 355 354 356 355 set hosts [lrange $hosts 1 end] 356 set result 0 357 357 358 358 while {1} { 359 359 if {[catch {socket $hostname $port} sid]} { 360 360 if {[llength $hosts] == 0} { 361 blt::busy release $itk_component(hull) 362 return 0 361 break; 363 362 } 364 363 foreach {hostname port} [split [lindex $hosts 0] :] break … … 385 384 386 385 if {[string equal $hostname "0.0.0.0"]} { 387 fileevent $sid readable [itcl::code $this _receive]388 386 set _sid $sid 389 390 387 set _rocker(server) 0 391 388 set _cacheid 0 392 389 390 fileevent $_sid readable [itcl::code $this _receive $_sid] 391 393 392 _send raw -defer set auto_color,0 394 393 _send raw -defer set auto_show_lines,0 395 blt::busy release $itk_component(hull) 396 return 1 394 395 set result 1 396 break 397 397 } 398 398 } … … 400 400 blt::busy release $itk_component(hull) 401 401 402 return 0402 return $result 403 403 } 404 404 … … 412 412 #puts stderr "MolvisViewer::disconnect()" 413 413 414 fileevent $_sid readable {}414 catch { fileevent $_sid readable {} } 415 415 catch { after cancel $_rocker(afterid) } 416 416 catch { after cancel $_mevent(afterid) } 417 418 catch { 419 close $_sid 420 unset _dataobjs 421 unset _model 422 unset _mlist 423 unset _imagecache 424 } 417 catch { close $_sid } 418 catch { unset _dataobjs } 419 catch { unset _model } 420 catch { unset _mlist } 421 catch { unset _imagecache } 422 425 423 set _sid "" 426 424 set _state(server) 1 … … 444 442 # Used internally to send commands off to the rendering server. 445 443 # ---------------------------------------------------------------------- 444 itcl::body Rappture::MolvisViewer::_sendit {args} { 445 #puts stderr "Rappture::MolvisViewer::_sendit($args)" 446 447 if { $_sid != "" } { 448 if { ![catch { puts $_sid $args }] } { 449 flush $_sid 450 return 0 451 } else { 452 catch { close $_sid } 453 set _sid "" 454 } 455 } 456 457 $_dispatcher event -after 1 !rebuild 458 459 return 1 460 } 461 446 462 itcl::body Rappture::MolvisViewer::_send {args} { 447 463 #puts stderr "Rappture::MolvisViewer::_send($args)" 448 464 465 if { $_state(server) != $_state(client) } { 466 if { [_sendit "frame -defer $_state(client)"] == 0 } { 467 set _state(server) $_state(client) 468 } 469 } 470 471 if { $_rocker(server) != $_rocker(client) } { 472 if { [_sendit "rock -defer $_rocker(client)"] == 0 } { 473 set _rocker(server) $_rocker(client) 474 } 475 } 476 477 eval _sendit $args 478 } 479 480 # ---------------------------------------------------------------------- 481 # USAGE: _receive 482 # 483 # Invoked automatically whenever a command is received from the 484 # rendering server. Reads the incoming command and executes it in 485 # a safe interpreter to handle the action. 486 # ---------------------------------------------------------------------- 487 itcl::body Rappture::MolvisViewer::_receive { {sid ""} } { 488 #puts stderr "Rappture::MolvisViewer::_receive($sid)" 489 490 if { $sid == "" } { 491 return 492 } 493 494 fileevent $sid readable {} 495 496 if { $sid != $_sid } { 497 return 498 } 499 500 fconfigure $_sid -buffering line -blocking 0 501 502 if {[gets $_sid line] < 0} { 503 504 if { ![fblocked $_sid] } { 505 catch { close $_sid } 506 set _sid "" 507 $_dispatcher event -after 750 !serverDown 508 } 509 510 } elseif {[regexp {^\s*nv>\s*image\s+(\d+)\s*(\d+)\s*,\s*(\d+)\s*,\s*(-{0,1}\d+)} $line whole match cacheid frame rock]} { 511 512 set tag "$frame,$rock" 513 514 if { $cacheid != $_cacheid } { 515 catch { unset _imagecache } 516 set _cacheid $cacheid 517 } 518 519 fconfigure $_sid -buffering none -blocking 1 520 set _imagecache($tag) [read $_sid $match] 521 #puts stderr "CACHED: $tag,$cacheid" 522 $_image(plot) put $_imagecache($tag) 523 set _image(id) $tag 524 525 if { $_busy } { 526 $itk_component(3dview) configure -cursor "" 527 set _busy 0 528 } 529 530 } else { 531 # this shows errors coming back from the engine 532 puts $line 533 } 534 535 if { $_sid != "" } { 536 fileevent $_sid readable [itcl::code $this _receive $_sid] 537 } 538 } 539 540 # ---------------------------------------------------------------------- 541 # USAGE: _rebuild 542 # 543 # Called automatically whenever something changes that affects the 544 # data in the widget. Clears any existing data and rebuilds the 545 # widget to display new data. 546 # ---------------------------------------------------------------------- 547 itcl::body Rappture::MolvisViewer::_rebuild {} { 548 #puts stderr "Rappture::MolvisViewer::_rebuild()" 549 550 if { $_inrebuild } { 551 # don't allow overlapping rebuild calls 552 return 553 } 554 555 set _inrebuild 1 556 449 557 if {"" == $_sid} { 450 558 $_dispatcher cancel !serverDown 559 451 560 set x [expr {[winfo rootx $itk_component(area)]+10}] 452 561 set y [expr {[winfo rooty $itk_component(area)]+10}] 562 453 563 Rappture::Tooltip::cue @$x,$y "Connecting..." 454 564 update idletasks … … 457 567 set w [winfo width $itk_component(3dview)] 458 568 set h [winfo height $itk_component(3dview)] 459 puts $_sid "screen -defer $w $h" 460 flush $_sid 461 $_dispatcher event -idle !rebuild 569 _send screen -defer $w $h 462 570 Rappture::Tooltip::cue hide 571 } else { 572 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." 573 set _inrebuild 0 574 set _busy 1 463 575 return 464 } 465 466 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." 467 468 return 469 } else { 470 471 if { $_state(server) != $_state(client) } { 472 puts $_sid "frame -defer $_state(client)" 473 set _state(server) $_state(client) 474 } 475 476 if { $_rocker(server) != $_rocker(client) } { 477 puts $_sid "rock -defer $_rocker(client)" 478 set _rocker(server) $_rocker(client) 479 } 480 481 puts $_sid $args 482 483 flush $_sid 484 } 485 } 486 487 # ---------------------------------------------------------------------- 488 # USAGE: _receive 489 # 490 # Invoked automatically whenever a command is received from the 491 # rendering server. Reads the incoming command and executes it in 492 # a safe interpreter to handle the action. 493 # ---------------------------------------------------------------------- 494 itcl::body Rappture::MolvisViewer::_receive {} { 495 #puts stderr "Rappture::MolvisViewer::_receive()" 496 497 if {"" != $_sid} { fileevent $_sid readable {} } 498 499 while {$_sid != ""} { 500 fconfigure $_sid -buffering line -blocking 0 501 502 if {[gets $_sid line] < 0} { 503 if { [fblocked $_sid] } { 504 break; 505 } 506 507 disconnect 508 509 $_dispatcher event -after 750 !serverDown 510 } elseif {[regexp {^\s*nv>\s*image\s+(\d+)\s*(\d+)\s*,\s*(\d+)\s*,\s*(-{0,1}\d+)} $line whole match cacheid frame rock]} { 511 set tag "$frame,$rock" 512 513 if { $cacheid != $_cacheid } { 514 catch { unset _imagecache } 515 set _cacheid $cacheid 516 } 517 518 fconfigure $_sid -buffering none -blocking 1 519 set _imagecache($tag) [read $_sid $match] 520 #puts stderr "CACHED: $tag,$cacheid" 521 $_image(plot) put $_imagecache($tag) 522 set _image(id) $tag 523 if { $_busy } { 524 $itk_component(3dview) configure -cursor "" 525 set _busy 0 526 } 527 update idletasks 528 break 529 } else { 530 # this shows errors coming back from the engine 531 puts $line 532 } 533 } 534 535 if { "" != $_sid } { fileevent $_sid readable [itcl::code $this _receive] } 536 } 537 538 # ---------------------------------------------------------------------- 539 # USAGE: _rebuild 540 # 541 # Called automatically whenever something changes that affects the 542 # data in the widget. Clears any existing data and rebuilds the 543 # widget to display new data. 544 # ---------------------------------------------------------------------- 545 itcl::body Rappture::MolvisViewer::_rebuild {} { 546 #puts stderr "Rappture::MolvisViewer::_rebuild()" 547 548 if { $_inrebuild } { 549 # don't allow overlapping rebuild calls 550 return 551 } 552 553 set _inrebuild 1 576 } 577 } 578 554 579 set changed 0 555 580 set _busy 1 … … 698 723 699 724 set _inrebuild 0 725 726 if { $_sid == "" } { 727 # connection failed during rebuild, don't attempt to reconnect/rebuild 728 # until user initiates some action 729 730 disconnect 731 $_dispatcher cancel !rebuild 732 $_dispatcher event -after 750 !serverDown 733 } 700 734 } 701 735 … … 938 972 set x [expr {[winfo rootx $itk_component(area)]+10}] 939 973 set y [expr {[winfo rooty $itk_component(area)]+10}] 974 975 if { $_busy } { 976 $itk_component(3dview) configure -cursor "" 977 set _busy 0 978 } 940 979 941 980 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."
Note: See TracChangeset
for help on using the changeset viewer.