Ignore:
Timestamp:
May 18, 2009 11:45:37 AM (15 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

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

    r1444 r1448  
    1919package require Img
    2020
    21 option add *FlowvisViewer.width 4i widgetDefault
     21option add *FlowvisViewer.width 5i widgetDefault
    2222option add *FlowvisViewer*cursor crosshair widgetDefault
    2323option add *FlowvisViewer.height 4i widgetDefault
     
    7575    protected method Disconnect {}
    7676    protected method DoResize {}
    77     protected method FixLegend {}
     77    protected method ResizeLegend {}
    7878    protected method FixSettings {what {value ""}}
    7979    protected method Pan {option x y}
     
    128128    private variable _id2obj       ;# maps dataobj => volume ID in server
    129129    private variable _sendobjs ""  ;# list of data objs to send to server
    130     private variable _receiveIds   ;# list of data objs to send to server
     130    private variable _recvObjs  ;# list of data objs to send to server
    131131    private variable _obj2style    ;# maps dataobj-component to transfunc
    132132    private variable _style2objs   ;# maps tf back to list of
     
    152152    private variable _width 0
    153153    private variable _height 0
     154    private variable _resizePending 0
     155    private variable _resizeLegendPending 0
    154156}
    155157
     
    166168    # Draw legend event
    167169    $_dispatcher register !legend
    168     $_dispatcher dispatch $this !legend "[itcl::code $this FixLegend]; list"
     170    $_dispatcher dispatch $this !legend "[itcl::code $this ResizeLegend]; list"
    169171
    170172    # Send dataobjs event
     
    189191    $_dispatcher dispatch $this !play "[itcl::code $this flow next]; list"
    190192   
    191     set _flow(frame) 0
    192193    set _flow(state) 0
    193194
     
    226227        $this-psi               $_view(psi)
    227228        $this-speed             500
     229        $this-step              0
     230        $this-nsteps            100
    228231        $this-theta             $_view(theta)
    229232        $this-volume            1
     
    291294    BuildCameraTab
    292295
     296
     297    bind $itk_component(3dview) <Configure> \
     298        [itcl::code $this EventuallyResize %w %h]
     299
    293300    # Legend
    294 
    295301    set _image(legend) [image create photo]
    296302    itk_component add legend {
     
    315321    # Create flow controls...
    316322
    317     itk_component add flowcontrol {
    318         frame $itk_interior.flowcontrol
     323    itk_component add flowcontrols {
     324        frame $itk_interior.flowcontrols
    319325    } {
    320326        usual
     
    324330    blt::table $itk_interior \
    325331        0,0 $itk_component(main) -fill both  \
    326         1,0 $itk_component(flowcontrol) -fill x
     332        1,0 $itk_component(flowcontrols) -fill x
    327333    blt::table configure $itk_interior r1 -resize none
    328334
    329     # flow record button...
     335    # Rewind
    330336    itk_component add rewind {
    331         button $itk_component(flowcontrol).reset \
     337        button $itk_component(flowcontrols).reset \
    332338            -borderwidth 1 -padx 1 -pady 1 \
    333339            -image [Rappture::icon flow-rewind] \
     
    336342        usual
    337343        ignore -borderwidth
    338         rename -highlightbackground -controlbackground controlBackground Background
     344        rename -highlightbackground -controlbackground controlBackground \
     345            Background
    339346    }
    340347    Rappture::Tooltip::for $itk_component(rewind) \
    341348        "Rewind flow"
    342349
    343     # flow stop button...
     350    # Stop
    344351    itk_component add stop {
    345         button $itk_component(flowcontrol).stop \
     352        button $itk_component(flowcontrols).stop \
    346353            -borderwidth 1 -padx 1 -pady 1 \
    347354            -image [Rappture::icon flow-stop] \
     
    350357        usual
    351358        ignore -borderwidth
    352         rename -highlightbackground -controlbackground controlBackground Background
     359        rename -highlightbackground -controlbackground controlBackground \
     360            Background
    353361    }
    354362    Rappture::Tooltip::for $itk_component(stop) \
    355363        "Stop flow"
    356364
    357     #
    358     # flow play/pause button...
    359     #
     365    # Play
    360366    itk_component add play {
    361         Rappture::PushButton $itk_component(flowcontrol).play \
     367        Rappture::PushButton $itk_component(flowcontrols).play \
    362368            -onimage [Rappture::icon flow-pause] \
    363369            -offimage [Rappture::icon flow-play] \
     
    369375        "Play/Pause flow"
    370376
     377    # Loop
    371378    itk_component add loop {
    372         Rappture::PushButton $itk_component(flowcontrol).loop \
     379        Rappture::PushButton $itk_component(flowcontrols).loop \
    373380            -onimage [Rappture::icon loop] \
    374381            -offimage [Rappture::icon loop] \
     
    378385        "Play continuously"
    379386
    380     # how do we know when to make something an itk component?
    381 
    382     itk_component add numframes {
    383         Rappture::Spinint $itk_component(flowcontrol).numframes \
    384             -min 0 -max 10000
     387    # Frame
     388    itk_component add frame {
     389        ::scale $itk_component(flowcontrols).frame -from 1 -to 100 \
     390            -showvalue 0 -orient horizontal -width 14 \
     391            -state disabled \
     392            -variable [itcl::scope _settings($this-step)]  \
     393            -highlightthickness 0
     394    } {
     395        usual
     396        ignore -highlightthickness
     397        rename -background -controlbackground controlBackground Background
     398    }
     399    $itk_component(frame) set 1
     400
     401    # Number of steps
     402    itk_component add nsteps {
     403        Rappture::Spinint $itk_component(flowcontrols).nsteps \
     404            -min 0 -max 10000 -width 4
    385405    } {
    386406        usual
     
    388408        rename -background -controlbackground controlBackground Background
    389409    }
    390     $itk_component(numframes) value 100
    391 
    392     itk_component add numframeslabel {
    393         label $itk_component(flowcontrol).framel -text "# Steps:" -font $fg \
     410    $itk_component(nsteps) value 100
     411
     412    itk_component add nstepslabel {
     413        label $itk_component(flowcontrols).framel -text "# Steps:" -font $fg \
    394414            -highlightthickness 0
    395415    } {
     
    400420
    401421    itk_component add speedlabel {
    402         label $itk_component(flowcontrol).speedl -text "Speed:" -font $fg \
     422        label $itk_component(flowcontrols).speedl -text "Speed:" -font $fg \
    403423            -highlightthickness 0
    404424    } {
     
    408428    }
    409429
     430    # Speed
    410431    itk_component add speed {
    411         ::scale $itk_component(flowcontrol).speed -from 500 -to 50 \
    412             -showvalue 0 -orient horizontal -width 14 -length 150 \
    413             -variable [itcl::scope _settings(speed)]  \
    414             -highlightthickness 0
     432        Rappture::Spinint $itk_component(flowcontrols).speed \
     433            -min 1 -max 10 -width 2
    415434    } {
    416         usual
     435        usual
    417436        ignore -highlightthickness
    418437        rename -background -controlbackground controlBackground Background
    419438    }
    420     $itk_component(speed) set 500
    421 
    422     blt::table $itk_component(flowcontrol) \
     439    $itk_component(speed) value 1
     440    bind $itk_component(speed) <<Value>> [itcl::code $this flow speed]
     441
     442
     443    blt::table $itk_component(flowcontrols) \
    423444        0,0 $itk_component(rewind) -padx {3 0} \
    424445        0,1 $itk_component(stop) -padx {2 0} \
    425446        0,2 $itk_component(play) -padx {2 0} \
    426447        0,3 $itk_component(loop) -padx {2 0} \
     448        0,4 $itk_component(frame) -fill x -padx {2 0 } \
    427449        0,5 $itk_component(speedlabel) -padx {2 0} \
    428         0,6 $itk_component(speed) -fill x \
    429         0,7 $itk_component(numframeslabel) -padx {2 0} \
    430         0,8 $itk_component(numframes) -fill x -padx { 0 3}
    431     blt::table configure $itk_component(flowcontrol) c* -resize none
    432     blt::table configure $itk_component(flowcontrol) c4 c6 -resize both
    433     blt::table configure $itk_component(flowcontrol) r0 -pady 1
     450        0,6 $itk_component(speed) -padx {2 0} \
     451        0,7 $itk_component(nstepslabel) -padx {2 0} \
     452        0,8 $itk_component(nsteps) -padx { 2 3}
     453
     454    blt::table configure $itk_component(flowcontrols) c* -resize none
     455    blt::table configure $itk_component(flowcontrols) c4 -resize both
     456    blt::table configure $itk_component(flowcontrols) r0 -pady 1
    434457    # Bindings for rotation via mouse
    435458    bind $itk_component(3dview) <ButtonPress-1> \
     
    439462    bind $itk_component(3dview) <ButtonRelease-1> \
    440463        [itcl::code $this Rotate release %x %y]
     464
    441465    bind $itk_component(3dview) <Configure> \
    442466        [itcl::code $this EventuallyResize %w %h]
     
    609633# ----------------------------------------------------------------------
    610634itcl::body Rappture::FlowvisViewer::delete {args} {
     635     flow stop
    611636    if {[llength $args] == 0} {
    612637        set args $_dlist
     
    880905
    881906            NameTransferFunc $dataobj $comp
    882             set _receiveIds($ivol) 1
     907            set _recvObjs($dataobj-$comp) 1
    883908        }
    884909    }
     
    898923            SendCmd "up $axis"
    899924        }
     925
     926        if 0 {
     927        set location [$_first hints camera]
     928        if { $location != "" } {
     929            array set _view $location
     930        }
     931        set _settings($this-theta) $_view(theta)
     932        set _settings($this-phi)   $_view(phi)
     933        set _settings($this-psi)   $_view(psi)
     934        set _settings($this-pan-x) $_view(pan-x)
     935        set _settings($this-pan-y) $_view(pan-y)
     936        set _settings($this-zoom)  $_view(zoom)
     937        set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
     938        SendCmd "camera angle $xyz"
     939        PanCamera
     940        SendCmd "camera zoom $_view(zoom)"
     941        }
    900942        # The active transfer function is by default the first component of
    901943        # the first data object.  This assumes that the data is always
     
    943985itcl::body Rappture::FlowvisViewer::SendTransferFuncs {} {
    944986    if { $_activeTf == "" } {
     987        puts stderr "no active tf"
    945988        return
    946989    }
    947990    set tf $_activeTf
    948991    if { $_first == "" } {
     992        puts stderr "no first"
    949993        return
    950994    }
     
    9681012        }
    9691013    }
    970     FixLegend
     1014    ResizeLegend
    9711015}
    9721016
     
    9791023# ----------------------------------------------------------------------
    9801024itcl::body Rappture::FlowvisViewer::ReceiveImage { args } {
    981     if {![isconnected]} {
    982         return
    983     }
    9841025    array set info {
    9851026        -token "???"
     
    9911032    ReceiveEcho <<line "<read $info(-bytes) bytes"
    9921033    if { $info(-type) == "image" } {
    993         ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>"       
    9941034        $_image(plot) configure -data $bytes
    9951035    } elseif { $info(type) == "print" } {
     
    10661106#       doesn't parse 3D data formats, we rely on the server (flowvis) to
    10671107#       tell us what the limits are.  Once we've received the limits to all
    1068 #       the data we've sent (tracked by _receiveIds) we can then determine
     1108#       the data we've sent (tracked by _recvObjs) we can then determine
    10691109#       what the transfer functions are for these # volumes.
    10701110#
     
    11031143    set _limits(vmax)      $info(vmax); # Overall maximum value.
    11041144
    1105     unset _receiveIds($ivol)
    1106     if { [array size _receiveIds] == 0 } {
     1145    unset _recvObjs($tag)
     1146    if { [array size _recvObjs] == 0 } {
    11071147        updatetransferfuncs
    11081148    }
     
    11171157#
    11181158itcl::body Rappture::FlowvisViewer::Rebuild {} {
    1119     puts stderr "in Rebuild"
     1159    #puts stderr "in Rebuild"
    11201160    # Hide all the isomarkers. Can't remove them. Have to remember the
    11211161    # settings since the user may have created/deleted/moved markers.
     
    11291169    # in the midst of sending data? then bail out
    11301170    if {[llength $_sendobjs] > 0} {
     1171        $_dispatcher event -idle !rebuild
    11311172        return
    11321173    }
     
    11361177    # generates a new call to Rebuild).   
    11371178    set _buffering 1
     1179
     1180    set w [winfo width $itk_component(3dview)]
     1181    set h [winfo height $itk_component(3dview)]
     1182    EventuallyResize $w $h
    11381183
    11391184    # Find any new data that needs to be sent to the server.  Queue this up on
     
    11481193        }
    11491194    }
    1150     set w [winfo width $itk_component(3dview)]
    1151     set h [winfo height $itk_component(3dview)]
    1152     EventuallyResize $w $h
    11531195
    11541196    #
    11551197    # Reset the camera and other view parameters
    11561198    #
    1157     set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
    1158     SendCmd "camera angle $xyz"
    1159     PanCamera
    1160     SendCmd "camera zoom $_view(zoom)"
    1161 
     1199    FixSettings light
     1200    FixSettings transp
     1201    FixSettings isosurface
     1202    FixSettings grid
     1203    FixSettings axes
     1204    FixSettings outline
     1205    # nothing to send -- activate the proper ivol
     1206    set _first [lindex [get] 0]
     1207    if {"" != $_first} {
     1208        set axis [$_first hints updir]
     1209        if {"" != $axis} {
     1210            SendCmd "up $axis"
     1211        }
     1212        set location [$_first hints camera]
     1213        if { $location != "" } {
     1214            array set _view $location
     1215        }
     1216    }
    11621217    set _settings($this-theta) $_view(theta)
    11631218    set _settings($this-phi)   $_view(phi)
     
    11671222    set _settings($this-zoom)  $_view(zoom)
    11681223
    1169     FixSettings light
    1170     FixSettings transp
    1171     FixSettings isosurface
    1172     FixSettings grid
    1173     FixSettings axes
    1174     FixSettings outline
     1224    set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
     1225    SendCmd "camera angle $xyz"
     1226    PanCamera
     1227    SendCmd "camera zoom $_view(zoom)"
    11751228
    11761229    if {[llength $_sendobjs] > 0} {
    11771230        # send off new data objects
    11781231        $_dispatcher event -idle !send_dataobjs
     1232        puts stderr "more sendobjs "
    11791233        return
    11801234    }
     
    11871241            SendCmd "up $axis"
    11881242        }
     1243        set location [$_first hints camera]
     1244        if { $location != "" } {
     1245            array set _view $location
     1246        }
    11891247        if { 0 && $_settings($this-volume) }  {
    11901248            SendCmd "volume state 0"
     
    12241282    set _buffering 0;                   # Turn off buffering.
    12251283    set _outbuf "";                     # Clear the buffer.             
    1226     puts stderr "exit Rebuild"
     1284    #puts stderr "exit Rebuild"
    12271285}
    12281286
     
    14681526                        set inner $itk_component(settingsFrame)
    14691527                        set frames [$inner.framecnt value]
    1470                         set _settings(numframes) $frames
     1528                        set _settings(nsteps) $frames
    14711529                        set cmds "flow capture $frames"
    14721530                        SendCmd $cmds
     
    16371695
    16381696# ----------------------------------------------------------------------
    1639 # USAGE: FixLegend
     1697# USAGE: ResizeLegend
    16401698#
    16411699# Used internally to update the legend area whenever it changes size
     
    16431701# for the current field.
    16441702# ----------------------------------------------------------------------
    1645 itcl::body Rappture::FlowvisViewer::FixLegend {} {
     1703itcl::body Rappture::FlowvisViewer::ResizeLegend {} {
     1704    set _resizeLegendPending 0
    16461705    set lineht [font metrics $itk_option(-font) -linespace]
    16471706    set w [expr {$_width-20}]
     
    16811740    set tf "$style(-color):$style(-levels):$style(-opacity)"
    16821741    lappend _obj2style($dataobj-$comp) $tf
    1683     puts stderr "creating tf=$tf $dataobj-$comp"
    1684     parray _obj2style
    16851742    lappend _style2objs($tf) $dataobj $comp
    16861743    return $tf
     
    23112368            set _settings($this-particles-$name) $info(hide)
    23122369        }
    2313         checkbutton $inner.part$row -text $name \
     2370        checkbutton $inner.part$row -text $info(label) \
    23142371            -variable [itcl::scope _settings($this-particles-$name)] \
    23152372            -onvalue 0 -offvalue 1 \
     
    23342391            set _settings($this-box-$name) $info(hide)
    23352392        }
    2336         checkbutton $inner.box$row -text $info(name) \
     2393        checkbutton $inner.box$row -text $info(label) \
    23372394            -variable [itcl::scope _settings($this-box-$name)] \
    23382395            -onvalue 0 -offvalue 1 \
     
    23532410itcl::body Rappture::FlowvisViewer::particles { tag name } {
    23542411    set bool $_settings($this-particles-$name)
    2355     SendCmd "$tag particles configure $name -hide $bool"
     2412    SendCmd "$tag particles configure {$name} -hide $bool"
    23562413}
    23572414
    23582415itcl::body Rappture::FlowvisViewer::box { tag name } {
    23592416    set bool $_settings($this-box-$name)
    2360     SendCmd "$tag box configure $name -hide $bool"
     2417    SendCmd "$tag box configure {$name} -hide $bool"
    23612418}
    23622419
     
    24122469itcl::body Rappture::FlowvisViewer::DoResize {} {
    24132470    SendCmd "screen $_width $_height"
     2471    set _resizePending 0
    24142472}
    24152473
    24162474itcl::body Rappture::FlowvisViewer::EventuallyResize { w h } {
    2417     if { $_width != $w || $_height != $h } {
    2418         set _width $w
    2419         set _height $h
     2475    set _width $w
     2476    set _height $h
     2477    if { !$_resizePending } {
    24202478        $_dispatcher event -idle !resize
     2479        set _resizePending 1
    24212480    }
    24222481}
    24232482
    24242483itcl::body Rappture::FlowvisViewer::EventuallyResizeLegend {} {
    2425     $_dispatcher event -idle !legend
     2484    if { !$_resizeLegendPending } {
     2485        $_dispatcher event -idle !legend
     2486        set _resizeLegendPending 1
     2487    }
    24262488}
    24272489
     
    24832545        append cmd "-axis $info(axis) -color {$color}\n"
    24842546    }
    2485     puts stderr "boxes=[$flowobj boxes]"
    24862547    foreach box [$flowobj boxes] {
    24872548        array unset info
     
    25152576#       $this flow next
    25162577#
    2517 itcl::body Rappture::FlowvisViewer::flow {option} {
     2578itcl::body Rappture::FlowvisViewer::flow { args } {
     2579    set option [lindex $args 0]
    25182580    switch -- $option {
     2581        "speed" {
     2582            set speed [$itk_component(speed) value]
     2583            set _settings($this-speed) [expr int(round(500.0/$speed))]
     2584        }
     2585        "nsteps" {
     2586            set n [$itk_component(nsteps) value]
     2587            $itk_component(frame) configure -max $n
     2588            set settings($this-nsteps) $n
     2589        }
    25192590        "off" {
    25202591            set _flow(state) 0
     
    25422613                flow on
    25432614                # If we're at the end of the flow, reset the flow.
    2544                 set count [$itk_component(numframes) value]
    2545                 if { $_flow(frame) >= $count } {
    2546                     set _flow(frame) 1
     2615                set n $_settings($this-step)
     2616                if { $n >= $_settings($this-nsteps) } {
     2617                    set _settings($this-step) 1
    25472618                    SendCmd "flow reset"
    25482619                }
     
    25582629        }
    25592630        "reset" {
    2560             set _flow(frame) 0
     2631            set _settings($this-step) 0
    25612632            SendCmd "flow reset"
    25622633            if { !$_flow(state) } {
     
    25652636        }
    25662637        "next" {
    2567             set count [$itk_component(numframes) value]
    2568             incr _flow(frame)
    2569             if { $_flow(frame) >= $count } {
     2638            set w $itk_component(3dview)
     2639            while { $w != "" }  {
     2640                if { ![winfo ismapped $w] } {
     2641                    flow stop
     2642                    puts stderr "$w isn't mapped"
     2643                    return
     2644                }
     2645                set w [winfo parent $w]
     2646                if { [winfo toplevel $w] == $w } {
     2647                    break
     2648                }
     2649            }
     2650            set n [incr _settings($this-step)]
     2651            if { $n >= $_settings($this-nsteps) } {
    25702652                if { !$_settings($this-loop) } {
    25712653                    flow off
     
    25762658                SendCmd "flow next"
    25772659            }
    2578             set delay [expr {int(ceil(pow($_settings(speed)/10.0+2,2.0)*15))}]
    2579             set delay2 [expr round(log($_settings(speed)+0.00001)*100.0)]
    2580             $_dispatcher event -after $_settings(speed) !play
     2660            $_dispatcher event -after $_settings($this-speed) !play
    25812661        }
    25822662        default {
     
    26382718    focus $inner.cancel
    26392719
    2640     SendCmd "flow video $width $height $_settings(numframes) 2.0 1000"
     2720    SendCmd "flow video $width $height $_settings($this-nsteps) 2.0 1000"
    26412721   
    26422722    $popup activate $widget below
Note: See TracChangeset for help on using the changeset viewer.