Ignore:
Timestamp:
Mar 19, 2014 9:43:25 AM (6 years ago)
Author:
mmc
Message:

Updated VMD server script from MD Showcase.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/vmd/vmdserver.tcl

    r4152 r4252  
    4141set DisplaySize(changed) 0
    4242
     43# capture initial display settings for later reset
     44display antialias on
     45
     46set DisplayProps(options) ""
     47foreach key {
     48    ambientocclusion antialias aoambient aodirect
     49    backgroundgradient
     50    culling cuestart cueend cuedensity cuemode
     51    depthcue distance
     52    eyesep
     53    farclip focallength
     54    height
     55    nearclip
     56    projection
     57    shadows stereo
     58} {
     59    if {$key eq "nearclip" || $key eq "farclip"} {
     60        append DisplayProps(options) [list display $key set [display get $key]] "\n"
     61    } else {
     62        append DisplayProps(options) [list display $key [display get $key]] "\n"
     63    }
     64}
     65
    4366# initialize work queue and epoch counter (see server_send_image)
    4467set Epoch 0
     
    5477  color
    5578  axes
    56   display
    5779  imd
    5880  vmdcollab
     
    90112
    91113# ----------------------------------------------------------------------
     114# USAGE: display option ?arg arg...?
     115#
     116# Executes the "command arg arg..." string in the server and substitutes
     117# the result into the template string in place of each "%v" field.
     118# Sends the result back to the client.
     119# ----------------------------------------------------------------------
     120proc cmd_display {args} {
     121    set option [lindex $args 0]
     122    if {[lsearch {resize reposition rendermode update fps} $option] >= 0} {
     123        # ignore these commands -- they cause trouble
     124        return ""
     125    }
     126    eval display $args
     127}
     128$parser alias display cmd_display
     129
     130# ----------------------------------------------------------------------
    92131# USAGE: tellme "command template with %v" command arg arg...
    93132#
     
    262301        set op "addfile"
    263302    }
     303
     304    # BE CAREFUL -- force a "display update" here
     305    # that triggers something in VMD that changes view matrices now,
     306    # so if we change them later, the new values stick
     307    display update
    264308}
    265309$parser alias load cmd_load
     
    267311# ----------------------------------------------------------------------
    268312# USAGE: scene define <name> <script>
    269 # USAGE: scene show <name> ?-send <initialViewCmd>?
     313# USAGE: scene show <name> ?-before <viewCmd>? ?-after <viewCmd>?
    270314# USAGE: scene clear
    271315# USAGE: scene forget ?<name> <name>...?
     
    293337        }
    294338        show {
    295             if {[llength $args] < 1 || [llength $args] > 3} {
    296                 error "wrong # args: should be \"scene show name ?-send cmd?\""
     339            if {[llength $args] < 1 || [llength $args] > 5} {
     340                error "wrong # args: should be \"scene show name ?-before cmd? ?-after cmd?\""
    297341            }
    298342            set name [lindex $args 0]
     
    301345            }
    302346
    303             set sendcmd ""
     347            set triggers(before) ""
     348            set triggers(after) ""
    304349            foreach {key val} [lrange $args 1 end] {
    305350                switch -- $key {
    306                     -send { set sendcmd $val }
    307                     default { error "bad option \"$key\": should be -send" }
     351                    -before { set triggers(before) $val }
     352                    -after { set triggers(after) $val }
     353                    default { error "bad option \"$key\": should be -before, -after" }
    308354                }
     355            }
     356
     357            # if -before arg was given, send back the view right now
     358            if {$triggers(before) ne "" && $Scenes(@CURRENT) ne ""} {
     359                cmd_tellme $triggers(before) getview
    309360            }
    310361
    311362            # clear the old scene
    312363            cmd_scene clear
     364            display resetview
    313365
    314366            # use a safe interp to keep things safe
    315             display resetview
     367            foreach val [$parser eval {info vars}] {
     368                # clear all variables created by previous scripts
     369                $parser eval [list catch [list unset $val]]
     370            }
    316371            if {[catch {$parser eval $Scenes($name)} result]} {
    317372                error "$result\nwhile loading scene \"$name\""
     
    333388            set Scenes(@CURRENT) $name
    334389
    335             # if -send arg was given, send back the view after the script
    336             if {$sendcmd ne ""} {
    337                 cmd_tellme $sendcmd getview
     390            # if -after arg was given, send back the view after the script
     391            if {$triggers(after) ne ""} {
     392                cmd_tellme $triggers(after) getview
    338393            }
    339394        }
     
    351406            axes location off
    352407            color Display Background black
    353             display backgroundgradient off
     408            eval $DisplayProps(options)
    354409        }
    355410        forget {
     
    605660# ----------------------------------------------------------------------
    606661proc server_accept {cid addr port} {
     662    global env
     663
    607664    fileevent $cid readable [list server_handle $cid $cid]
    608665    fconfigure $cid -buffering none -blocking 0
     666
     667    if {[info exists env(LOCAL)]} {
     668        # identify server type to this client
     669        # VMD on the hub has this built in, but stock versions can
     670        # set the environment variable as a work-around
     671        puts $cid "vmd 0.1"
     672    }
    609673}
    610674
     
    615679        # when client drops connection, we can exit
    616680        # nanoscale will spawn a new server next time we need it
    617         server_exit $cin $cout
     681        if {[eof $cin]} {
     682            server_exit $cin $cout
     683        }
    618684    } else {
    619685        append buffer($cin) $line "\n"
     
    645711
    646712        catch {unset data}; array set data $chunk
    647         if {$data(epoch) == $Epoch} {
     713        if {$data(epoch) < 0 || $data(epoch) == $Epoch} {
    648714            catch {puts $cout $data(cmd)}
    649715
     
    717783            molinfo top set rotate_matrix [list $item(rotate)]
    718784            # send rotation matrix back to the client so we can pause later
    719             server_send_result $client [list nv>rotatemtx $item(num) $item(rotate)]
     785            server_send_latest $client [list nv>rotatemtx $item(num) $item(rotate)]
    720786        } else {
    721787            puts "ERROR: bad work frame: [array get item]"
     
    737803
    738804    set data [SnapShot data -format PPM]
    739     server_send_result $client "nv>image epoch $item(epoch) frame $item(num) length [string length $data]" $data
     805    server_send_latest $client "nv>image epoch $item(epoch) frame $item(num) length [string length $data]" $data
    740806
    741807    # if there's more work in the queue, try again later
     
    746812
    747813proc server_send_result {cout cmd {data ""}} {
     814    global Sendqueue
     815
     816    # add this result to the output queue
     817    # use the epoch -1 to force the send even if the epoch has changed
     818    lappend Sendqueue [list epoch -1 cmd $cmd bytes $data]
     819    fileevent $cout writable [list server_send $cout]
     820}
     821
     822proc server_send_latest {cout cmd {data ""}} {
    748823    global Epoch Sendqueue
    749824
Note: See TracChangeset for help on using the changeset viewer.