Changeset 924 for trunk/gui/scripts


Ignore:
Timestamp:
Mar 6, 2008 12:38:12 PM (16 years ago)
Author:
gah
Message:

fixes for visualization server resources definition

Location:
trunk/gui/scripts
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/heightmapviewer.tcl

    r921 r924  
    3131proc HeightmapViewer_init_resources {} {
    3232    Rappture::resources::register \
    33         nanovis_server [list Rappture::VisViewer::SetServerList "nanovis"]
     33        nanovis_server Rappture::VisViewer::SetNanovisServerList
    3434}
    3535
  • trunk/gui/scripts/molvisviewer.tcl

    r921 r924  
    2727proc MolvisViewer_init_resources {} {
    2828    Rappture::resources::register \
    29         molvis_server [list Rappture::VisViewer::SetServerList "pymol"]
     29        molvis_server Rappture::VisViewer::SetPymolServerList
    3030}
    3131
  • trunk/gui/scripts/nanovisviewer.tcl

    r921 r924  
    3232proc NanovisViewer_init_resources {} {
    3333    Rappture::resources::register \
    34         nanovis_server [list Rappture::VisViewer::SetServerList "nanovis"]
     34        nanovis_server Rappture::VisViewer::SetNanovisServerList
    3535}
    3636
  • trunk/gui/scripts/resources.tcl

    r909 r924  
    4545    variable optionParser
    4646    foreach {name proc} $args {
    47         eval $optionParser alias $name $proc
     47        $optionParser alias $name $proc
    4848    }
    4949}
  • trunk/gui/scripts/visviewer.tcl

    r921 r924  
    2424    set _servers(pymol)   ""
    2525
    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
     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
    3030    protected variable _image
    31     private common _done                ;# Used to indicate status of send.
    32     private variable _buffer            ;# buffer for incoming/outgoing commands
     31    private common _done                ;# Used to indicate status of send.
     32    private variable _buffer            ;# buffer for incoming/outgoing commands
    3333
    3434    constructor { hostlist args } {
    35         # defined below
     35        # defined below
    3636    }
    3737    destructor {
    38         # defined below
     38        # defined below
    3939    }
    4040    # Used internally only.
     
    5656    protected method Euler2XYZ {theta phi psi}
    5757
     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    }
    5870    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)
    6472    }
    6573}
     
    126134itcl::body Rappture::VisViewer::destructor {} {
    127135    interp delete $_parser
     136    array unset _done $this
    128137}
    129138
     
    131140# _Shuffle -- 
    132141#
    133 #       Shuffle the list of server hosts.
     142#       Shuffle the list of server hosts.
    134143#
    135144itcl::body Rappture::VisViewer::_Shuffle { hostlist } {
     
    137146    set random_hosts {}
    138147    for { set i [llength $hosts] } { $i > 0 } { incr i -1 } {
    139         set index [expr {round(rand()*$i - 0.5)}]
    140         if { $index == $i } {
    141             set index [expr $i - 1]
    142         }
    143         lappend random_hosts [lindex $hosts $index]
    144         set hosts [lreplace $hosts $index $index]
     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]
    145154    }
    146155    return $random_hosts
     
    156165    set pattern {^[a-zA-Z0-9\.]+:[0-9]+(,[a-zA-Z0-9\.]+:[0-9]+)*$}
    157166    if { ![regexp $pattern $namelist match] } {
    158         error "bad visualization server address \"$namelist\": should be host:port,host:port,..."
     167        error "bad visualization server address \"$namelist\": should be host:port,host:port,..."
    159168    }
    160169}
     
    169178itcl::body Rappture::VisViewer::_ServerDown {} {
    170179    if { [info exists itk_component(area)] } {
    171         set x [expr {[winfo rootx $itk_component(area)]+10}]
    172         set y [expr {[winfo rooty $itk_component(area)]+10}]
     180        set x [expr {[winfo rootx $itk_component(area)]+10}]
     181        set y [expr {[winfo rooty $itk_component(area)]+10}]
    173182    } else {
    174         set x 0; set y 0
     183        set x 0; set y 0
    175184    }
    176185    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."
     
    200209        if { [catch {socket $hostname $port} _sid] != 0 } {
    201210            if {[llength $servers] == 0} {
    202                 blt::busy release $itk_component(hull)
     211                blt::busy release $itk_component(hull)
    203212                return 0
    204213            }
    205             # Get the next server
     214            # Get the next server
    206215            foreach {hostname port} [split [lindex $servers 0] :] break
    207216            set servers [lrange $servers 1 end]
     
    213222        puts -nonewline $_sid [binary format I $memorySize]
    214223        flush $_sid
    215        
     224       
    216225        # read back a reconnection order
    217226        set data [read $_sid 4]
    218227        if {[binary scan $data cccc b1 b2 b3 b4] != 4} {
    219             blt::busy release $itk_component(hull)
     228            blt::busy release $itk_component(hull)
    220229            error "couldn't read redirection request"
    221230        }
     
    227236
    228237        if { [string equal $addr "0.0.0.0"] } {
    229             # We're connected. Cancel any pending serverDown events and
    230             # release the busy window over the hull.
    231             $_dispatcher cancel !serverDown
    232             blt::busy release $itk_component(hull)
    233             fconfigure $_sid -buffering line
    234             fileevent $_sid readable [itcl::code $this _ReceiveHelper]
     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]
    235244            return 1
    236245        }
     
    253262        catch {close $_sid} err
    254263        set _sid ""
    255         $_dispatcher event -after 750 !serverDown
    256     }
    257     set _buffer(in) ""                 
     264        $_dispatcher event -after 750 !serverDown
     265    }
     266    set _buffer(in) ""                 
    258267}
    259268
     
    270279# _SendHelper --
    271280#
    272 #       Helper routine called from a file event to send data when the
    273 #       connection is writable (i.e. not blocked).  Sends data in chunks
    274 #       of 8k (or less).  Sets magic variable _done($this) to indicate
    275 #       that we're either finished (success) or could not send bytes to
    276 #       the server (failure).
     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).
    277286#
    278287itcl::body Rappture::VisViewer::_SendHelper {} {
    279288    set bytesLeft [string length $_buffer(out)]
    280289    if { $bytesLeft > 0} {
    281         set chunk [string range $_buffer(out) 0 8095]
    282         set _buffer(out)  [string range $_buffer(out) 8096 end]
    283         incr bytesLeft -8096
    284         set code [catch {
    285             if { $bytesLeft > 0 } {
    286                 puts -nonewline $_sid $chunk
    287             } else {
    288                 puts $_sid $chunk
    289             }           
    290         } err]
    291         if { $code != 0 } {
    292             puts stderr "error sending data to $_sid: $err"
    293             Disconnect
    294             set _done($this) 0;         # Failure
    295         }
     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        }
    296305    } else {
    297         set _done($this) 1;             # Success
     306        set _done($this) 1;             # Success
    298307    }
    299308}
     
    302311# SendBytes --
    303312#
    304 #       Send a a string to the visualization server. 
     313#       Send a a string to the visualization server. 
    305314#
    306315itcl::body Rappture::VisViewer::SendBytes { bytes } {
     
    308317
    309318    if { ![IsConnected]} {
    310         # If we aren't connected, assume it's because the connection to the
    311         # visualization server broke. Try to open a connection and trigger a
    312         # rebuild.
     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.
    313322        $_dispatcher cancel !serverDown
    314323        set x [expr {[winfo rootx $itk_component(area)]+10}]
    315324        set y [expr {[winfo rooty $itk_component(area)]+10}]
    316325        Rappture::Tooltip::cue @$x,$y "Connecting..."
    317         set code [catch { Connect } ok]
     326        set code [catch { Connect } ok]
    318327        if { $code == 0 && $ok} {
    319             $_dispatcher event -idle !rebuild
    320             Rappture::Tooltip::cue hide
     328            $_dispatcher event -idle !rebuild
     329            Rappture::Tooltip::cue hide
    321330        } else {
    322             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."
    323         }
    324         return
     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
    325334    }
    326335    set _done($this) 1
     
    341350itcl::body Rappture::VisViewer::ReceiveBytes { size } {
    342351    if { [eof $_sid] } {
    343         error "unexpected eof on socket"
     352        error "unexpected eof on socket"
    344353    }
    345354    set bytes [read $_sid $size]
     
    351360# _ReceiveHelper --
    352361#
    353 #       Helper routine called from a file event when the connection is
    354 #       readable (i.e. a command response has been sent by the rendering
    355 #       server.  Reads the incoming command and executes it in a safe
    356 #       interpreter to handle the action.
     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.
    357366#
    358367#       Note: This routine currently only handles command responses from
    359 #             the visualization server.  It doesn't handle non-blocking
    360 #             reads from the visualization server.
    361 #
    362 #           nv>image -bytes 100000              yes
    363 #           ...following 100000 bytes...        no             
     368#             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             
    364373#
    365374itcl::body Rappture::VisViewer::_ReceiveHelper {} {
    366375    if { [IsConnected] } {
    367         if { [eof $_sid] } {
    368             error "_receive: unexpected eof on socket"
    369         }
     376        if { [eof $_sid] } {
     377            error "_receive: unexpected eof on socket"
     378        }
    370379        if { [gets $_sid line] < 0 } {
    371380            Disconnect
     
    373382            ReceiveEcho <<line $line
    374383            append _buffer(in) [string range $line 3 end]
    375             append _buffer(in) "\n"
     384            append _buffer(in) "\n"
    376385            if {[info complete $_buffer(in)]} {
    377386                set request $_buffer(in)
     
    395404itcl::body Rappture::VisViewer::Flush {} {
    396405    if { [IsConnected] } {
    397         flush $_sid
     406        flush $_sid
    398407    }
    399408}
     
    403412# Color2RGB --
    404413#
    405 #       Converts a color name to a list of r,g,b values needed for the
    406 #       engine.  Each r/g/b component is scaled in the # range 0-1. 
     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. 
    407416#
    408417itcl::body Rappture::VisViewer::Color2RGB {color} {
     
    417426# Euler2XYZ --
    418427#
    419 #       Converts euler angles for the camera placement the to angles of
    420 #       rotation about the x/y/z axes, used by the engine.  Returns a list:
    421 #       {xangle, yangle, zangle}. 
     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}. 
    422431#
    423432itcl::body Rappture::VisViewer::Euler2XYZ {theta phi psi} {
Note: See TracChangeset for help on using the changeset viewer.