Ignore:
Timestamp:
Sep 22, 2008, 3:26:05 PM (16 years ago)
Author:
dkearney
Message:

changing clock "ticks" to "clicks" because tcl claimed it was an error

File:
1 edited

Legend:

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

    r1152 r1158  
    1 
     1#!/usr/bin/wish
    22# ----------------------------------------------------------------------
     3
     4
    35#  VisViewer -
    46#
     
    2123
    2224    private common _servers          ;# array of visualization server lists
    23     set _servers(nanovis) "" 
    24     set _servers(pymol)   "" 
    25 
    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
     25    set _servers(nanovis) ""
     26    set _servers(pymol)   ""
     27
     28    protected variable _dispatcher ""   # dispatcher for !events
     29    protected variable _hosts ""    ;# list of hosts for server
     30    protected variable _sid ""      ;# socket connection to server
     31    protected variable _parser ""   ;# interpreter for incoming commands
    3032    protected variable _image
    31     private common _done                ;# Used to indicate status of send.
    32     private variable _buffer            ;# buffer for incoming/outgoing commands
    33 
    34     constructor { hostlist args } { 
    35         # defined below
    36     }
    37     destructor { 
    38         # defined below
     33    private common _done            ;# Used to indicate status of send.
     34    private variable _buffer        ;# buffer for incoming/outgoing commands
     35
     36    constructor { hostlist args } {
     37        # defined below
     38    }
     39    destructor {
     40        # defined below
    3941    }
    4042    # Used internally only.
    41     private method _Shuffle { hostlist } 
    42     private method _ReceiveHelper {} 
     43    private method _Shuffle { hostlist }
     44    private method _ReceiveHelper {}
    4345    private method _ServerDown {}
    4446    private method _SendHelper {}
     
    5759
    5860    private proc _CheckNameList { namelist }  {
    59         set pattern {^[a-zA-Z0-9\.]+:[0-9]+(,[a-zA-Z0-9\.]+:[0-9]+)*$}
    60         if { ![regexp $pattern $namelist match] } {
    61             error "bad visualization server address \"$namelist\": should be host:port,host:port,..."
    62         }
     61        set pattern {^[a-zA-Z0-9\.]+:[0-9]+(,[a-zA-Z0-9\.]+:[0-9]+)*$}
     62        if { ![regexp $pattern $namelist match] } {
     63            error "bad visualization server address \"$namelist\": should be host:port,host:port,..."
     64        }
    6365    }
    6466    public proc GetServerList { tag } {
    65         return $_servers($tag)
     67        return $_servers($tag)
    6668    }
    6769    public proc SetServerList { tag namelist } {
    68         _CheckNameList $namelist
    69         set _servers($tag) $namelist
     70        _CheckNameList $namelist
     71        set _servers($tag) $namelist
    7072    }
    7173    public proc SetPymolServerList { namelist } {
    72         SetServerList "pymol" $namelist
     74        SetServerList "pymol" $namelist
    7375    }
    7476    public proc SetNanovisServerList { namelist } {
    75         SetServerList "nanovis" $namelist
     77        SetServerList "nanovis" $namelist
    7678    }
    7779}
     
    133135}
    134136
    135 # 
     137#
    136138# destructor --
    137 # 
     139#
    138140itcl::body Rappture::VisViewer::destructor {} {
    139141    interp delete $_parser
     
    141143}
    142144
    143 # 
    144 # _Shuffle -- 
    145 #
    146 #       Shuffle the list of server hosts.
     145#
     146# _Shuffle --
     147#
     148#   Shuffle the list of server hosts.
    147149#
    148150itcl::body Rappture::VisViewer::_Shuffle { hostlist } {
    149151    set hosts [split $hostlist ,]
    150152    set random_hosts {}
    151     set ticks [clock ticks]
     153    set ticks [clock clicks]
    152154    expr {srand($ticks)}
    153155    for { set i [llength $hosts] } { $i > 0 } { incr i -1 } {
    154         set index [expr {round(rand()*$i - 0.5)}]
    155         if { $index == $i } {
    156             set index [expr $i - 1]
    157         }
    158         lappend random_hosts [lindex $hosts $index]
    159         set hosts [lreplace $hosts $index $index]
     156        set index [expr {round(rand()*$i - 0.5)}]
     157        if { $index == $i } {
     158            set index [expr $i - 1]
     159        }
     160        lappend random_hosts [lindex $hosts $index]
     161        set hosts [lreplace $hosts $index $index]
    160162    }
    161163    return $random_hosts
     
    171173itcl::body Rappture::VisViewer::_ServerDown {} {
    172174    if { [info exists itk_component(area)] } {
    173         set x [expr {[winfo rootx $itk_component(area)]+10}]
    174         set y [expr {[winfo rooty $itk_component(area)]+10}]
     175        set x [expr {[winfo rootx $itk_component(area)]+10}]
     176        set y [expr {[winfo rooty $itk_component(area)]+10}]
    175177    } else {
    176         set x 0; set y 0
     178        set x 0; set y 0
    177179    }
    178180    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."
     
    181183#
    182184# Connect --
    183 # 
     185#
    184186#    Connect to the visualization server (e.g. nanovis, pymolproxy).  Send
    185187#    the server some estimate of the size of our job.  If it's too busy, that
    186 #    server may forward us to another. 
     188#    server may forward us to another.
    187189#
    188190itcl::body Rappture::VisViewer::Connect { hostlist } {
     
    202204        if { [catch {socket $hostname $port} _sid] != 0 } {
    203205            if {[llength $servers] == 0} {
    204                 blt::busy release $itk_component(hull)
     206                blt::busy release $itk_component(hull)
    205207                return 0
    206208            }
    207             # Get the next server
     209            # Get the next server
    208210            foreach {hostname port} [split [lindex $servers 0] :] break
    209211            set servers [lrange $servers 1 end]
     
    215217        puts -nonewline $_sid [binary format I $memorySize]
    216218        flush $_sid
    217        
     219
    218220        # read back a reconnection order
    219221        set data [read $_sid 4]
    220222        if {[binary scan $data cccc b1 b2 b3 b4] != 4} {
    221             blt::busy release $itk_component(hull)
     223            blt::busy release $itk_component(hull)
    222224            error "couldn't read redirection request"
    223225        }
     
    229231
    230232        if { [string equal $addr "0.0.0.0"] } {
    231             # We're connected. Cancel any pending serverDown events and
    232             # release the busy window over the hull.
    233             $_dispatcher cancel !serverDown
    234             blt::busy release $itk_component(hull)
    235             fconfigure $_sid -buffering line
    236             fileevent $_sid readable [itcl::code $this _ReceiveHelper]
     233            # We're connected. Cancel any pending serverDown events and
     234            # release the busy window over the hull.
     235            $_dispatcher cancel !serverDown
     236            blt::busy release $itk_component(hull)
     237            fconfigure $_sid -buffering line
     238            fileevent $_sid readable [itcl::code $this _ReceiveHelper]
    237239            return 1
    238240        }
     
    255257        catch {close $_sid} err
    256258        set _sid ""
    257         $_dispatcher event -after 750 !serverDown
    258     }
    259     set _buffer(in) ""                 
     259        $_dispatcher event -after 750 !serverDown
     260    }
     261    set _buffer(in) ""
    260262}
    261263
     
    272274# _SendHelper --
    273275#
    274 #       Helper routine called from a file event to send data when the
    275 #       connection is writable (i.e. not blocked).  Sets a magic
    276 #       variable _done($this) when we're done.
     276#   Helper routine called from a file event to send data when the
     277#   connection is writable (i.e. not blocked).  Sets a magic
     278#   variable _done($this) when we're done.
    277279#
    278280itcl::body Rappture::VisViewer::_SendHelper {} {
    279281    puts $_sid $_buffer(out)
    280282    flush $_sid
    281     set _done($this) 1;         # Success
     283    set _done($this) 1;     # Success
    282284}
    283285
     
    285287# _SendHelper.old --
    286288#
    287 #       Helper routine called from a file event to send data when the
    288 #       connection is writable (i.e. not blocked).  Sends data in chunks
    289 #       of 8k (or less).  Sets magic variable _done($this) to indicate
    290 #       that we're either finished (success) or could not send bytes to
    291 #       the server (failure).
     289#   Helper routine called from a file event to send data when the
     290#   connection is writable (i.e. not blocked).  Sends data in chunks
     291#   of 8k (or less).  Sets magic variable _done($this) to indicate
     292#   that we're either finished (success) or could not send bytes to
     293#   the server (failure).
    292294#
    293295itcl::body Rappture::VisViewer::_SendHelper.old {} {
    294296    set bytesLeft [string length $_buffer(out)]
    295297    if { $bytesLeft > 0} {
    296         set chunk [string range $_buffer(out) 0 8095]
    297         set _buffer(out)  [string range $_buffer(out) 8096 end]
    298         incr bytesLeft -8096
    299         set code [catch {
    300             if { $bytesLeft > 0 } {
    301                 puts -nonewline $_sid $chunk
    302             } else {
    303                 puts $_sid $chunk
    304             }           
    305         } err]
    306         if { $code != 0 } {
    307             puts stderr "error sending data to $_sid: $err"
    308             Disconnect
    309             set _done($this) 0;         # Failure
    310         }
     298        set chunk [string range $_buffer(out) 0 8095]
     299        set _buffer(out)  [string range $_buffer(out) 8096 end]
     300        incr bytesLeft -8096
     301        set code [catch {
     302            if { $bytesLeft > 0 } {
     303                puts -nonewline $_sid $chunk
     304            } else {
     305                puts $_sid $chunk
     306            }
     307        } err]
     308        if { $code != 0 } {
     309            puts stderr "error sending data to $_sid: $err"
     310            Disconnect
     311            set _done($this) 0;     # Failure
     312        }
    311313    } else {
    312         set _done($this) 1;             # Success
     314        set _done($this) 1;     # Success
    313315    }
    314316}
     
    317319# SendBytes --
    318320#
    319 #       Send a a string to the visualization server. 
     321#   Send a a string to the visualization server.
    320322#
    321323itcl::body Rappture::VisViewer::SendBytes { bytes } {
     
    323325
    324326    if { ![IsConnected]} {
    325         # If we aren't connected, assume it's because the connection to the
    326         # visualization server broke. Try to open a connection and trigger a
    327         # rebuild.
     327        # If we aren't connected, assume it's because the connection to the
     328        # visualization server broke. Try to open a connection and trigger a
     329        # rebuild.
    328330        $_dispatcher cancel !serverDown
    329331        set x [expr {[winfo rootx $itk_component(area)]+10}]
    330332        set y [expr {[winfo rooty $itk_component(area)]+10}]
    331333        Rappture::Tooltip::cue @$x,$y "Connecting..."
    332         set code [catch { Connect } ok]
     334        set code [catch { Connect } ok]
    333335        if { $code == 0 && $ok} {
    334             $_dispatcher event -idle !rebuild
    335             Rappture::Tooltip::cue hide
    336             return 1
     336            $_dispatcher event -idle !rebuild
     337            Rappture::Tooltip::cue hide
     338            return 1
    337339       } else {
    338             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."
    339            return 0
    340         }
     340            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."
     341           return 0
     342        }
    341343    }
    342344    # Even though the data is sent in only 1 "puts", we need to verify that
     
    360362itcl::body Rappture::VisViewer::ReceiveBytes { size } {
    361363    if { [eof $_sid] } {
    362         error "unexpected eof on socket"
     364        error "unexpected eof on socket"
    363365    }
    364366    set bytes [read $_sid $size]
     
    367369}
    368370
    369 # 
     371#
    370372# _ReceiveHelper --
    371373#
    372 #       Helper routine called from a file event when the connection is
    373 #       readable (i.e. a command response has been sent by the rendering
    374 #       server.  Reads the incoming command and executes it in a safe
    375 #       interpreter to handle the action.
     374#   Helper routine called from a file event when the connection is
     375#   readable (i.e. a command response has been sent by the rendering
     376#   server.  Reads the incoming command and executes it in a safe
     377#   interpreter to handle the action.
    376378#
    377379#       Note: This routine currently only handles command responses from
    378 #             the visualization server.  It doesn't handle non-blocking
    379 #             reads from the visualization server.
    380 #
    381 #           nv>image -bytes 100000              yes
    382 #           ...following 100000 bytes...        no             
    383 # 
    384 #       Note: All commands from the render server are on one line.
    385 #             This is because the render server can send anything
    386 #             as an error message (restricted again to one line).
    387 #           
     380#         the visualization server.  It doesn't handle non-blocking
     381#         reads from the visualization server.
     382#
     383#       nv>image -bytes 100000      yes
     384#       ...following 100000 bytes...    no
     385#
     386#   Note: All commands from the render server are on one line.
     387#         This is because the render server can send anything
     388#         as an error message (restricted again to one line).
     389#
    388390itcl::body Rappture::VisViewer::_ReceiveHelper {} {
    389391    if { [IsConnected] } {
    390         if { [eof $_sid] } {
    391             error "_receive: unexpected eof on socket"
    392         }
     392        if { [eof $_sid] } {
     393            error "_receive: unexpected eof on socket"
     394        }
    393395        if { [gets $_sid line] < 0 } {
    394396            Disconnect
    395         } 
    396         set line [string trim $line]
    397         if { $line == "" } {
    398             return
    399         }
    400         if { [string equal [string range $line 0 2] "nv>"] } {
     397        }
     398        set line [string trim $line]
     399        if { $line == "" } {
     400            return
     401        }
     402        if { [string equal [string range $line 0 2] "nv>"] } {
    401403            ReceiveEcho <<line $line
    402404            append _buffer(in) [string range $line 3 end]
    403             append _buffer(in) "\n"
     405            append _buffer(in) "\n"
    404406            if {[info complete $_buffer(in)]} {
    405407                set request $_buffer(in)
     
    423425itcl::body Rappture::VisViewer::Flush {} {
    424426    if { [IsConnected] } {
    425         flush $_sid
     427        flush $_sid
    426428    }
    427429}
     
    431433# Color2RGB --
    432434#
    433 #       Converts a color name to a list of r,g,b values needed for the
    434 #       engine.  Each r/g/b component is scaled in the # range 0-1. 
     435#   Converts a color name to a list of r,g,b values needed for the
     436#   engine.  Each r/g/b component is scaled in the # range 0-1.
    435437#
    436438itcl::body Rappture::VisViewer::Color2RGB {color} {
     
    445447# Euler2XYZ --
    446448#
    447 #       Converts euler angles for the camera placement the to angles of
    448 #       rotation about the x/y/z axes, used by the engine.  Returns a list:
    449 #       {xangle, yangle, zangle}. 
     449#   Converts euler angles for the camera placement the to angles of
     450#   rotation about the x/y/z axes, used by the engine.  Returns a list:
     451#   {xangle, yangle, zangle}.
    450452#
    451453itcl::body Rappture::VisViewer::Euler2XYZ {theta phi psi} {
Note: See TracChangeset for help on using the changeset viewer.