Ignore:
Timestamp:
May 14, 2009 10:19:39 PM (15 years ago)
Author:
gah
Message:

fixes for multiple volumes in sequence

File:
1 edited

Legend:

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

    r1423 r1435  
    5454    }
    5555    public method add {dataobj {settings ""}}
     56    public method camera {option args}
     57    public method delete {args}
     58    public method download {option args}
    5659    public method get {args}
    57     public method delete {args}
     60    public method isconnected {}
     61    public method limits { tf }
     62    public method overmarker { m x }
     63    public method parameters {title args} {
     64        # do nothing
     65    }
     66    public method rmdupmarker { m x }
    5867    public method scale {args}
    59     public method download {option args}
    60     public method parameters {title args} {
    61         # do nothing
    62     }
    63     public method limits { tf }
    64     public method isconnected {}
    6568    public method updatetransferfuncs {}
    66     public method rmdupmarker { m x }
    67     public method overmarker { m x }
    68     public method camera {option args}
    6969
    7070    protected method Connect {}
     71    protected method CurrentVolumeIds {{what -all}}
    7172    protected method Disconnect {}
    72 
     73    protected method DoResize {}
     74    protected method FixLegend {}
     75    protected method FixSettings {what {value ""}}
     76    protected method Pan {option x y}
     77    protected method Rebuild {}
     78    protected method ReceiveData { args }
     79    protected method ReceiveImage { args }
     80    protected method ReceiveLegend { tf vmin vmax size }
     81    protected method Rotate {option x y}
    7382    protected method SendCmd {string}
    7483    protected method SendDataObjs {}
    7584    protected method SendTransferFuncs {}
    76 
    77     protected method ReceiveImage { args }
    78     protected method ReceiveLegend { ivol vmin vmax size }
    79     protected method ReceiveData { args }
    80 
    81     protected method Rebuild {}
    82     protected method CurrentVolumeIds {{what -all}}
    83     protected method Zoom {option}
    84     protected method Pan {option x y}
    85     protected method Rotate {option x y}
    86     protected method Probe {option args}
    87     protected method Marker {index option args}
    8885    protected method Slice {option args}
    8986    protected method SlicerTip {axis}
    90 
    91     protected method State {comp}
    92     protected method DoResize {}
    93     protected method FixLegend {}
    94     protected method FixSettings {what {value ""}}
     87    protected method Zoom {option}
    9588
    9689    # The following methods are only used by this class.
    97     private method NameTransferFunc { ivol }
    98     private method ComputeTransferFunc { tf }
    9990    private method AddIsoMarker { x y }
    100     private method ParseMarkersOption { tf ivol markers }
    101     private method ParseLevelsOption { tf ivol levels }
    102     private method EventuallyResize { w h }
    103     private method EventuallyResizeLegend { }
    104 
     91    private method BuildCameraTab {}
    10592    private method BuildCutplanesTab {}
    10693    private method BuildViewTab {}
    10794    private method BuildVolumeTab {}
    108     private method BuildCameraTab {}
     95    private method ComputeTransferFunc { tf }
     96    private method EventuallyResize { w h }
     97    private method EventuallyResizeLegend { }
     98    private method NameTransferFunc { dataobj comp }
    10999    private method PanCamera {}
    110 
    111     private variable outbuf_       ;# buffer for outgoing commands
    112 
    113     private variable dlist_ ""     ;# list of data objects
    114     private variable allDataObjs_
    115     private variable id2style_     ;# maps id => style settings
    116     private variable obj2ovride_   ;# maps dataobj => style override
    117     private variable obj2id_       ;# maps dataobj => volume ID in server
    118     private variable id2obj_       ;# maps dataobj => volume ID in server
    119     private variable sendobjs_ ""  ;# list of data objs to send to server
    120     private variable receiveIds_   ;# list of data objs to send to server
    121     private variable obj2styles_   ;# maps id => style settings
    122     private variable style2ids_    ;# maps id => style settings
    123 
    124     private variable click_        ;# info used for _rotate operations
    125     private variable limits_       ;# autoscale min/max for all axes
    126     private variable view_         ;# view params for 3D view
    127     private variable isomarkers_    ;# array of isosurface level values 0..1
    128     private common   settings_
    129     private variable activeTf_ ""  ;# The currently active transfer function.
     100    private method ParseLevelsOption { tf levels }
     101    private method ParseMarkersOption { tf markers }
     102
     103    private variable _outbuf       ;# buffer for outgoing commands
     104
     105    private variable _dlist ""     ;# list of data objects
     106    private variable _allDataObjs
     107    private variable _obj2ovride   ;# maps dataobj => style override
     108    private variable _obj2id       ;# maps dataobj-component to volume ID
     109                                    # in the server
     110    private variable _id2obj       ;# maps dataobj => volume ID in server
     111    private variable _sendobjs ""  ;# list of data objs to send to server
     112    private variable _receiveIds   ;# list of data objs to send to server
     113    private variable _obj2style    ;# maps dataobj-component to transfunc
     114    private variable _style2objs   ;# maps tf back to list of
     115                                    # dataobj-components using the tf.
     116
     117    private variable _click        ;# info used for rotate operations
     118    private variable _limits       ;# autoscale min/max for all axes
     119    private variable _view         ;# view params for 3D view
     120    private variable _isomarkers    ;# array of isosurface level values 0..1
     121    private common   _settings
     122    private variable _activeTf ""  ;# The currently active transfer function.
     123    private variable _first ""     ;# This is the topmost volume.
     124    private variable _buffering 0
     125
    130126    # This
    131127    # indicates which isomarkers and transfer
    132128    # function to use when changing markers,
    133129    # opacity, or thickness.
    134     #common _downloadPopup          ;# download options from popup
    135     private common hardcopy_
    136     private variable width_ 0
    137     private variable height_ 0
     130    common _downloadPopup          ;# download options from popup
     131    private common _hardcopy
     132    private variable _width 0
     133    private variable _height 0
    138134}
    139135
     
    151147    $_dispatcher register !legend
    152148    $_dispatcher dispatch $this !legend "[itcl::code $this FixLegend]; list"
     149
    153150    # Send dataobjs event
    154151    $_dispatcher register !send_dataobjs
    155152    $_dispatcher dispatch $this !send_dataobjs \
    156153        "[itcl::code $this SendDataObjs]; list"
     154
    157155    # Send transfer functions event
    158156    $_dispatcher register !send_transfunc
    159157    $_dispatcher dispatch $this !send_transfunc \
    160158        "[itcl::code $this SendTransferFuncs]; list"
     159
    161160    # Rebuild event
    162161    $_dispatcher register !rebuild
    163162    $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list"
    164163
    165     # Draw legend event
     164    # Resize event
    166165    $_dispatcher register !resize
    167166    $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list"
    168167
    169     set outbuf_ ""
     168    set _outbuf ""
    170169
    171170    #
     
    175174    $_parser alias legend [itcl::code $this ReceiveLegend]
    176175    $_parser alias data [itcl::code $this ReceiveData]
    177     #$_parser alias print [itcl::code $this ReceivePrint]
    178176
    179177    # Initialize the view to some default parameters.
    180     array set view_ {
     178    array set _view {
    181179        theta   45
    182180        phi     45
     
    186184        pan-y   0
    187185    }
    188     set obj2id_(count) 0
    189     set id2obj_(count) 0
    190     set limits_(vmin) 0.0
    191     set limits_(vmax) 1.0
    192 
    193     set settings_($this-theta) $view_(theta)
    194     set settings_($this-phi)   $view_(phi)
    195     set settings_($this-psi)   $view_(psi)
    196     set settings_($this-pan-x) $view_(pan-x)
    197     set settings_($this-pan-y) $view_(pan-y)
    198     set settings_($this-zoom)  $view_(zoom)
     186    set _obj2id(count) 0
     187    set _id2obj(count) 0
     188    set _limits(vmin) 0.0
     189    set _limits(vmax) 1.0
     190
     191    array set _settings [subst {
     192        $this-pan-x             $_view(pan-x)
     193        $this-pan-y             $_view(pan-y)
     194        $this-phi               $_view(phi)
     195        $this-psi               $_view(psi)
     196        $this-theta             $_view(theta)
     197        $this-volume            1
     198        $this-xcutplane         0
     199        $this-xcutposition      0
     200        $this-ycutplane         0
     201        $this-ycutposition      0
     202        $this-zcutplane         0
     203        $this-zcutposition      0
     204        $this-zoom              $_view(zoom)
     205    }]
    199206
    200207    set f [$itk_component(main) component controls]
     
    235242    Rappture::Tooltip::for $itk_component(zoomout) "Zoom out"
    236243
    237     #
    238     # Volume toggle...
    239     #
    240244    itk_component add volume {
    241         label $f.volume -borderwidth 1 -relief sunken \
    242             -image [Rappture::icon volume-on]
    243     }
    244     bind $itk_component(volume) <ButtonPress> \
    245         [itcl::code $this Slice volume toggle]
     245        Rappture::PushButton $f.volume \
     246            -onimage [Rappture::icon volume-on] \
     247            -offimage [Rappture::icon volume-off] \
     248            -command [itcl::code $this FixSettings volume] \
     249            -variable [itcl::scope _settings($this-volume)]
     250    }
     251    $itk_component(volume) select
    246252    Rappture::Tooltip::for $itk_component(volume) \
    247253        "Toggle the volume cloud on/off"
    248     pack $itk_component(volume) -ipadx 1 -ipady 1 -padx 2 -pady 2
     254    pack $itk_component(volume) -padx 2 -pady 2
    249255
    250256    BuildViewTab
     
    269275    # size of the 3d view isn't set until an image is retrieved from
    270276    # the server.  So the panewindow uses the tiny size.
    271     set w [expr [winfo reqwidth $itk_component(hull)] - 80]
     277    set w 10000
    272278    pack forget $itk_component(3dview)
    273279    blt::table $itk_component(plotarea) \
    274         0,0 $itk_component(3dview) -fill both \
     280        0,0 $itk_component(3dview) -fill both -reqwidth $w \
    275281        1,0 $itk_component(legend) -fill x
    276282    blt::table configure $itk_component(plotarea) r1 -resize none
     
    337343# ----------------------------------------------------------------------
    338344itcl::body Rappture::NanovisViewer::destructor {} {
    339     set sendobjs_ ""  ;# stop any send in progress
     345    set _sendobjs ""  ;# stop any send in progress
    340346    $_dispatcher cancel !rebuild
    341347    $_dispatcher cancel !send_dataobjs
     
    344350    image delete $_image(legend)
    345351    image delete $_image(download)
    346     array unset settings_ $this-*
     352    array unset _settings $this-*
    347353}
    348354
     
    375381    }
    376382
    377     set pos [lsearch -exact $dataobj $dlist_]
     383    set pos [lsearch -exact $dataobj $_dlist]
    378384    if {$pos < 0} {
    379         lappend dlist_ $dataobj
    380         set allDataObjs_($dataobj) 1
    381         set obj2ovride_($dataobj-color) $params(-color)
    382         set obj2ovride_($dataobj-width) $params(-width)
    383         set obj2ovride_($dataobj-raise) $params(-raise)
     385        lappend _dlist $dataobj
     386        set _allDataObjs($dataobj) 1
     387        set _obj2ovride($dataobj-color) $params(-color)
     388        set _obj2ovride($dataobj-width) $params(-width)
     389        set _obj2ovride($dataobj-raise) $params(-raise)
    384390        $_dispatcher event -idle !rebuild
    385391    }
     
    403409      -objects {
    404410        # put the dataobj list in order according to -raise options
    405         set dlist $dlist_
     411        set dlist $_dlist
    406412        foreach obj $dlist {
    407             if {[info exists obj2ovride_($obj-raise)] && $obj2ovride_($obj-raise)} {
     413            if {[info exists _obj2ovride($obj-raise)] && $_obj2ovride($obj-raise)} {
    408414                set i [lsearch -exact $dlist $obj]
    409415                if {$i >= 0} {
     
    447453itcl::body Rappture::NanovisViewer::delete {args} {
    448454    if {[llength $args] == 0} {
    449         set args $dlist_
     455        set args $_dlist
    450456    }
    451457    # Delete all specified dataobjs
    452458    set changed 0
    453459    foreach dataobj $args {
    454         set pos [lsearch -exact $dlist_ $dataobj]
     460        set pos [lsearch -exact $_dlist $dataobj]
    455461        if { $pos >= 0 } {
    456             set dlist_ [lreplace $dlist_ $pos $pos]
    457             foreach key [array names obj2ovride_ $dataobj-*] {
    458                 unset obj2ovride_($key)
    459             }
     462            foreach comp [$dataobj components] {
     463                if { [info exists obj2id($dataobj-$comp)] } {
     464                    set ivol $_obj2id($dataobj-$comp)
     465                    array unset _limits $ivol-*
     466                }
     467            }
     468            set _dlist [lreplace $_dlist $pos $pos]
     469            array unset _obj2ovride $dataobj-*
     470            array unset _obj2id $dataobj-*
     471            array unset _obj2style $dataobj-*
    460472            set changed 1
    461473        }
     
    463475    # If anything changed, then rebuild the plot
    464476    if {$changed} {
     477        # Repair the reverse lookup
     478        foreach tf [array names _style2objs] {
     479            set list {}
     480            foreach {dataobj comp} $_style2objs($tf) break
     481            if { [info exists _obj2id($dataobj-$comp)] } {
     482                lappend list $dataobj $comp
     483            }
     484            if { $list == "" } {
     485                array unset _style2objs $tf
     486            } else {
     487                set _style2objs($tf) $list
     488            }
     489        }
    465490        $_dispatcher event -idle !rebuild
    466491    }
     
    478503itcl::body Rappture::NanovisViewer::scale {args} {
    479504    foreach val {xmin xmax ymin ymax zmin zmax vmin vmax} {
    480         set limits_($val) ""
     505        set _limits($val) ""
    481506    }
    482507    foreach obj $args {
     
    486511
    487512            if {"" != $min && "" != $max} {
    488                 if {"" == $limits_(${axis}min)} {
    489                     set limits_(${axis}min) $min
    490                     set limits_(${axis}max) $max
     513                if {"" == $_limits(${axis}min)} {
     514                    set _limits(${axis}min) $min
     515                    set _limits(${axis}max) $max
    491516                } else {
    492                     if {$min < $limits_(${axis}min)} {
    493                         set limits_(${axis}min) $min
     517                    if {$min < $_limits(${axis}min)} {
     518                        set _limits(${axis}min) $min
    494519                    }
    495                     if {$max > $limits_(${axis}max)} {
    496                         set limits_(${axis}max) $max
     520                    if {$max > $_limits(${axis}max)} {
     521                        set _limits(${axis}max) $max
    497522                    }
    498523                }
     
    515540    switch $option {
    516541        coming {
    517             if {[catch {blt::winop snap $itk_component(plotarea) $_image(download)}]} {
     542            if {[catch {
     543                blt::winop snap $itk_component(plotarea) $_image(download)
     544            }]} {
    518545                $_image(download) configure -width 1 -height 1
    519546                $_image(download) put #000000
     
    579606
    580607    # disconnected -- no more data sitting on server
    581     set outbuf_ ""
    582     catch {unset obj2id_}
    583     array unset id2obj_
    584     set obj2id_(count) 0
    585     set id2obj_(count) 0
    586     set sendobjs_ ""
     608    set _outbuf ""
     609    catch {unset _obj2id}
     610    array unset _id2obj
     611    set _obj2id(count) 0
     612    set _id2obj(count) 0
     613    set _sendobjs ""
    587614}
    588615
     
    595622#
    596623itcl::body Rappture::NanovisViewer::SendCmd {string} {
    597     if {[llength $sendobjs_] > 0} {
    598         append outbuf_ $string "\n"
     624    if { $_buffering } {
     625        append _outbuf $string "\n"
    599626    } else {
    600627        foreach line [split $string \n] {
    601628            SendEcho >>line $line
    602629        }
    603         SendBytes $string
     630        SendBytes "$string\n"
    604631    }
    605632}
     
    614641itcl::body Rappture::NanovisViewer::SendDataObjs {} {
    615642    blt::busy hold $itk_component(hull); update idletasks
    616     foreach dataobj $sendobjs_ {
     643
     644    foreach dataobj $_sendobjs {
    617645        foreach comp [$dataobj components] {
    618             # send the data as one huge base64-encoded mess -- yuck!
     646            # Send the data as one huge base64-encoded mess -- yuck!
    619647            set data [$dataobj values $comp]
    620648            set nbytes [string length $data]
    621             if { ![SendBytes "volume data follows $nbytes"] } {
     649            if { ![SendBytes "volume data follows $nbytes $dataobj-$comp\n"] } {
    622650                return
    623651            }
     
    625653                return
    626654            }
    627             set ivol $obj2id_(count)
    628             incr obj2id_(count)
    629 
    630             set id2obj_($ivol) [list $dataobj $comp]
    631             set obj2id_($dataobj-$comp) $ivol
    632             NameTransferFunc $ivol
    633             set receiveIds_($ivol) 1
    634         }
    635     }
    636     set sendobjs_ ""
     655            set ivol $_obj2id(count)
     656            incr _obj2id(count)
     657            NameTransferFunc $dataobj $comp
     658            set _receiveIds($ivol) 1
     659        }
     660    }
     661    set _sendobjs ""
    637662    blt::busy release $itk_component(hull)
    638663
     664    # Turn on buffering of commands to the server.  We don't want to
     665    # be preempted by a server disconnect/reconnect (which automatically
     666    # generates a new call to Rebuild).   
     667    set _buffering 1
     668
    639669    # activate the proper volume
    640     set first [lindex [get] 0]
    641     if {"" != $first} {
    642         set axis [$first hints updir]
     670    set _first [lindex [get] 0]
     671    if {"" != $_first} {
     672        set axis [$_first hints updir]
    643673        if {"" != $axis} {
    644674            SendCmd "up $axis"
     
    647677        # the first data object.  This assumes that the data is always
    648678        # successfully transferred.
    649         set comp [lindex [$first components] 0]
    650         set activeTf_ $id2style_($obj2id_($first-$comp))
    651     }
    652     foreach key [array names obj2id_ *-*] {
    653         set state [string match $first-* $key]
    654         set ivol $obj2id_($key)
    655         SendCmd "volume state $state $ivol"
    656     }
    657 
     679        set comp [lindex [$_first components] 0]
     680        set _activeTf [lindex $_obj2style($_first-$comp) 0]
     681    }
     682    SendCmd "volume state 0"
     683    set vols {}
     684    foreach key [array names _obj2id $_first-*] {
     685        lappend vols $_obj2id($key)
     686    }
     687    if { $vols != ""  && $_settings($this-volume) } {
     688        SendCmd "volume state 1 $vols"
     689    }
    658690    # sync the state of slicers
    659691    set vols [CurrentVolumeIds -cutplanes]
    660692    foreach axis {x y z} {
    661         SendCmd "cutplane state [State ${axis}CutButton] $axis $vols"
    662         set pos [expr {0.01*[$itk_component(${axis}CutScale) get]}]
     693        SendCmd "cutplane state $_settings($this-${axis}cutplane) $axis $vols"
     694        set pos [expr {0.01*$_settings($this-${axis}cutposition)}]
    663695        SendCmd "cutplane position $pos $axis $vols"
    664696    }
    665     SendCmd "volume data state [State volume] $vols"
    666697
    667698    if 0 {
     
    674705    SendCmd "grid axisname z Z eV"
    675706    }
    676     # if there are any commands in the buffer, send them now that we're done
    677     SendBytes $outbuf_
    678     set outbuf_ ""
     707
     708    # Actually write the commands to the server socket.  If it fails, we don't
     709    # care.  We're finished here.
     710    SendBytes $_outbuf;                 
     711    set _buffering 0;                   # Turn off buffering.
     712    set _outbuf "";                     # Clear the buffer.             
    679713}
    680714
     
    683717# ----------------------------------------------------------------------
    684718itcl::body Rappture::NanovisViewer::SendTransferFuncs {} {
    685     if { $activeTf_ == "" } {
     719    if { $_activeTf == "" } {
    686720        return
    687721    }
    688     set tf $activeTf_
    689     set first [lindex [get] 0]
     722    set tf $_activeTf
     723    if { $_first == "" } {
     724        return
     725    }
    690726
    691727    # Insure that the global opacity and thickness settings (in the slider
    692728    # settings widgets) are used for the active transfer-function.  Update the
    693     # values in the settings_ varible.
    694     set value $settings_($this-opacity)
     729    # values in the _settings varible.
     730    set value $_settings($this-opacity)
    695731    set opacity [expr { double($value) * 0.01 }]
    696     set settings_($this-$tf-opacity) $opacity
    697     set value $settings_($this-thickness)
     732    set _settings($this-$tf-opacity) $opacity
     733    set value $_settings($this-thickness)
    698734    # Scale values between 0.00001 and 0.01000
    699735    set thickness [expr {double($value) * 0.0001}]
    700     set settings_($this-$tf-thickness) $thickness
    701 
    702     if { ![info exists $obj2styles_($first)] } {
    703         foreach tf $obj2styles_($first) {
     736    set _settings($this-$tf-thickness) $thickness
     737
     738    foreach key [array names _obj2style $_first-*] {
     739        if { [info exists _obj2style($key)] } {
     740            foreach tf $_obj2style($key) {
     741                ComputeTransferFunc $tf
     742            }
     743        }
     744    }
     745    FixLegend
     746    if 0 {
     747    if { $first != "" && ![info exists _obj2style($_first)] } {
     748        foreach tf $_obj2style($_first) {
    704749            ComputeTransferFunc $tf
    705750        }
    706751        $_dispatcher event -idle !legend
     752    }
    707753    }
    708754}
     
    715761# specified <size> will follow.
    716762# ----------------------------------------------------------------------
    717 set counter 0
    718763itcl::body Rappture::NanovisViewer::ReceiveImage { args } {
    719764    if { ![isconnected] } {
    720765        return
    721766    }
    722     global counter
    723     incr counter
    724767    array set info {
    725768        -token "???"
     
    729772    array set info $args
    730773    set bytes [ReceiveBytes $info(-bytes)]
    731     ReceiveEcho <<line "<read $info(-bytes) bytes for [image width $_image(plot)]x[image height $_image(plot)] image>"
     774    ReceiveEcho <<line "<read $info(-bytes) bytes"
    732775    if { $info(-type) == "image" } {
     776        ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>"       
    733777        $_image(plot) configure -data $bytes
    734778    } elseif { $info(type) == "print" } {
    735779        set tag $this-print-$info(-token)
    736         set hardcopy_($tag) $bytes
     780        set _hardcopy($tag) $bytes
    737781    }
    738782}
     
    762806    set w [winfo width $c]
    763807    set h [winfo height $c]
    764     #foreach { dataobj comp } $id2obj_($ivol) break
     808    #foreach { dataobj comp } $_id2obj($ivol) break
    765809    set lx 10
    766810    set ly [expr {$h - 1}]
     
    777821    }
    778822    # Display the markers used by the active transfer function.
    779     #set tf $activeTf_
     823    #set tf $_activeTf
    780824
    781825    array set limits [limits $tf]
     
    786830    $c coords vmax [expr {$w-$lx}] $ly
    787831
    788     if { [info exists isomarkers_($tf)] } {
    789         foreach m $isomarkers_($tf) {
     832    if { [info exists _isomarkers($tf)] } {
     833        foreach m $_isomarkers($tf) {
    790834            $m visible yes
    791835        }
     
    802846#       doesn't parse 3D data formats, we rely on the server (nanovis) to
    803847#       tell us what the limits are.  Once we've received the limits to all
    804 #       the data we've sent (tracked by receiveIds_) we can then determine
     848#       the data we've sent (tracked by _receiveIds) we can then determine
    805849#       what the transfer functions are for these volumes.
    806850#
     
    822866
    823867    set ivol $info(id);         # Id of volume created by server.
    824 
    825     set limits_($ivol-min) $info(min);  # Minimum value of the volume.
    826     set limits_($ivol-max) $info(max);  # Maximum value of the volume.
    827     set limits_(vmin)      $info(vmin); # Overall minimum value.
    828     set limits_(vmax)      $info(vmax); # Overall maximum value.
    829 
    830     unset receiveIds_($ivol)
    831     if { [array size receiveIds_] == 0 } {
     868    set tag $info(tag)
     869    set parts [split $tag -]
     870
     871    #
     872    # Volumes don't exist until we're told about them.
     873    #
     874    set _id2obj($ivol) $parts
     875    set dataobj [lindex $parts 0]
     876    set _obj2id($tag) $ivol
     877    if { $_settings($this-volume) && $dataobj == $_first } {
     878        SendCmd "volume state 1 $ivol"
     879    }
     880    set _limits($ivol-min) $info(min);  # Minimum value of the volume.
     881    set _limits($ivol-max) $info(max);  # Maximum value of the volume.
     882    set _limits(vmin)      $info(vmin); # Overall minimum value.
     883    set _limits(vmax)      $info(vmax); # Overall maximum value.
     884
     885    unset _receiveIds($ivol)
     886    if { [array size _receiveIds] == 0 } {
    832887        updatetransferfuncs
    833888    }
     
    842897# ----------------------------------------------------------------------
    843898itcl::body Rappture::NanovisViewer::Rebuild {} {
     899
    844900    # Hide all the isomarkers. Can't remove them. Have to remember the
    845901    # settings since the user may have created/deleted/moved markers.
    846902
    847     foreach tf [array names isomarkers_] {
    848         foreach m $isomarkers_($tf) {
     903    foreach tf [array names _isomarkers] {
     904        foreach m $_isomarkers($tf) {
    849905            $m visible no
    850906        }
     
    852908
    853909    # in the midst of sending data? then bail out
    854     if {[llength $sendobjs_] > 0} {
     910    if {[llength $_sendobjs] > 0} {
    855911        return
    856912    }
    857913
     914    # Turn on buffering of commands to the server.  We don't want to
     915    # be preempted by a server disconnect/reconnect (which automatically
     916    # generates a new call to Rebuild).   
     917    set _buffering 1
     918
    858919    # Find any new data that needs to be sent to the server.  Queue this up on
    859     # the sendobjs_ list, and send it out a little at a time.  Do this first,
     920    # the _sendobjs list, and send it out a little at a time.  Do this first,
    860921    # before we rebuild the rest.
    861922    foreach dataobj [get] {
    862923        set comp [lindex [$dataobj components] 0]
    863         if {![info exists obj2id_($dataobj-$comp)]} {
    864             set i [lsearch -exact $sendobjs_ $dataobj]
     924        if {![info exists _obj2id($dataobj-$comp)]} {
     925            set i [lsearch -exact $_sendobjs $dataobj]
    865926            if {$i < 0} {
    866                 lappend sendobjs_ $dataobj
     927                lappend _sendobjs $dataobj
    867928            }
    868929        }
     
    875936    # Reset the camera and other view parameters
    876937    #
    877     set xyz [Euler2XYZ $view_(theta) $view_(phi) $view_(psi)]
     938    set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
    878939    SendCmd "camera angle $xyz"
    879     SendCmd "camera zoom $view_(zoom)"
    880 
    881     set settings_($this-theta) $view_(theta)
    882     set settings_($this-phi)   $view_(phi)
    883     set settings_($this-psi)   $view_(psi)
    884     set settings_($this-pan-x) $view_(pan-x)
    885     set settings_($this-pan-y) $view_(pan-y)
    886     set settings_($this-zoom)  $view_(zoom)
     940    PanCamera
     941    SendCmd "camera zoom $_view(zoom)"
     942
     943    set _settings($this-theta) $_view(theta)
     944    set _settings($this-phi)   $_view(phi)
     945    set _settings($this-psi)   $_view(psi)
     946    set _settings($this-pan-x) $_view(pan-x)
     947    set _settings($this-pan-y) $_view(pan-y)
     948    set _settings($this-zoom)  $_view(zoom)
    887949
    888950    FixSettings light
     
    893955    FixSettings outline
    894956
    895     if {[llength $sendobjs_] > 0} {
     957    if {[llength $_sendobjs] > 0} {
    896958        # send off new data objects
    897959        $_dispatcher event -idle !send_dataobjs
     
    900962
    901963    # nothing to send -- activate the proper ivol
    902     set first [lindex [get] 0]
    903     if {"" != $first} {
    904         set axis [$first hints updir]
     964    set _first [lindex [get] 0]
     965    if {"" != $_first} {
     966        set axis [$_first hints updir]
    905967        if {"" != $axis} {
    906968            SendCmd "up $axis"
    907969        }
    908         foreach key [array names obj2id_ *-*] {
    909             set state [string match $first-* $key]
    910             SendCmd "volume state $state $obj2id_($key)"
     970        foreach key [array names _obj2id *-*] {
     971            set state [string match $_first-* $key]
     972            SendCmd "volume state $state $_obj2id($key)"
    911973        }
    912974        #
    913         # The obj2id_ and id2style_ arrays may or may not have the right
     975        # The _obj2id and _id2style arrays may or may not have the right
    914976        # information.  It's possible for the server to know about volumes
    915977        # that the client has assumed it's deleted.  We could add checks.
    916978        # But this problem needs to be fixed not bandaided.
    917         set comp [lindex [$first components] 0]
    918         set ivol $obj2id_($first-$comp)
    919 
    920         foreach comp [$first components] {
    921             foreach ivol $obj2id_($first-$comp) {
    922                 NameTransferFunc $ivol
    923             }
     979        set comp [lindex [$_first components] 0]
     980        set ivol $_obj2id($_first-$comp)
     981
     982        foreach comp [$_first components] {
     983            NameTransferFunc $_first $comp
    924984        }
    925985    }
     
    928988    set vols [CurrentVolumeIds -cutplanes]
    929989    foreach axis {x y z} {
    930         SendCmd "cutplane state [State ${axis}CutButton] $axis $vols"
    931         set pos [expr {0.01*[$itk_component(${axis}CutScale) get]}]
     990        SendCmd "cutplane state $_settings($this-${axis}cutplane) $axis $vols"
     991        set pos [expr {0.01*$_settings($this-${axis}cutposition)}]
    932992        SendCmd "cutplane position $pos $axis $vols"
    933993    }
    934     SendCmd "volume data state [State volume] $vols"
     994    SendCmd "volume data state $_settings($this-volume) $vols"
    935995    $_dispatcher event -idle !legend
     996
     997    # Actually write the commands to the server socket.  If it fails, we don't
     998    # care.  We're finished here.
     999    SendBytes $_outbuf;                 
     1000    set _buffering 0;                   # Turn off buffering.
     1001    set _outbuf "";                     # Clear the buffer.             
    9361002}
    9371003
     
    9451011itcl::body Rappture::NanovisViewer::CurrentVolumeIds {{what -all}} {
    9461012    set rlist ""
    947 
    948     set first [lindex [get] 0]
    949     foreach key [array names obj2id_ *-*] {
    950         if {[string match $first-* $key]} {
     1013    if { $_first == "" } {
     1014        return
     1015    }
     1016    foreach key [array names _obj2id *-*] {
     1017        if {[string match $_first-* $key]} {
    9511018            array set style {
    9521019                -cutplanes 1
     
    9561023
    9571024            if {$what != "-cutplanes" || $style(-cutplanes)} {
    958                 lappend rlist $obj2id_($key)
     1025                lappend rlist $_obj2id($key)
    9591026            }
    9601027        }
     
    9741041    switch -- $option {
    9751042        "in" {
    976             set view_(zoom) [expr {$view_(zoom)*1.25}]
    977             set settings_($this-zoom) $view_(zoom)
     1043            set _view(zoom) [expr {$_view(zoom)*1.25}]
     1044            set _settings($this-zoom) $_view(zoom)
    9781045        }
    9791046        "out" {
    980             set view_(zoom) [expr {$view_(zoom)*0.8}]
    981             set settings_($this-zoom) $view_(zoom)
     1047            set _view(zoom) [expr {$_view(zoom)*0.8}]
     1048            set _settings($this-zoom) $_view(zoom)
    9821049        }
    9831050        "reset" {
    984             array set view_ {
     1051            array set _view {
    9851052                theta   45
    9861053                phi     45
     
    9901057                pan-y   0
    9911058            }
    992             set first [lindex [get] 0]
    993             if { $first != "" } {
    994                 set location [$first hints camera]
     1059            if { $_first != "" } {
     1060                set location [$_first hints camera]
    9951061                if { $location != "" } {
    996                     array set view_ $location
     1062                    array set _view $location
    9971063                }
    9981064            }
    999             set xyz [Euler2XYZ $view_(theta) $view_(phi) $view_(psi)]
     1065            set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
    10001066            SendCmd "camera angle $xyz"
    10011067            PanCamera
    1002             set settings_($this-theta) $view_(theta)
    1003             set settings_($this-phi)   $view_(phi)
    1004             set settings_($this-psi)   $view_(psi)
    1005             set settings_($this-pan-x) $view_(pan-x)
    1006             set settings_($this-pan-y) $view_(pan-y)
    1007             set settings_($this-zoom)  $view_(zoom)
     1068            set _settings($this-theta) $_view(theta)
     1069            set _settings($this-phi)   $_view(phi)
     1070            set _settings($this-psi)   $_view(psi)
     1071            set _settings($this-pan-x) $_view(pan-x)
     1072            set _settings($this-pan-y) $_view(pan-y)
     1073            set _settings($this-zoom)  $_view(zoom)
    10081074        }
    10091075    }
    1010     SendCmd "camera zoom $view_(zoom)"
     1076    SendCmd "camera zoom $_view(zoom)"
    10111077}
    10121078
    10131079itcl::body Rappture::NanovisViewer::PanCamera {} {
    1014     #set x [expr ($view_(pan-x)) / $limits_(xrange)]
    1015     #set y [expr ($view_(pan-y)) / $limits_(yrange)]
    1016     set x $view_(pan-x)
    1017     set y $view_(pan-y)
     1080    #set x [expr ($_view(pan-x)) / $_limits(xrange)]
     1081    #set y [expr ($_view(pan-y)) / $_limits(yrange)]
     1082    set x $_view(pan-x)
     1083    set y $_view(pan-y)
    10181084    SendCmd "camera pan $x $y"
    10191085}
     
    10321098        click {
    10331099            $itk_component(3dview) configure -cursor fleur
    1034             set click_(x) $x
    1035             set click_(y) $y
    1036             set click_(theta) $view_(theta)
    1037             set click_(phi) $view_(phi)
     1100            set _click(x) $x
     1101            set _click(y) $y
     1102            set _click(theta) $_view(theta)
     1103            set _click(phi) $_view(phi)
    10381104        }
    10391105        drag {
    1040             if {[array size click_] == 0} {
     1106            if {[array size _click] == 0} {
    10411107                Rotate click $x $y
    10421108            } else {
     
    10491115                if {[catch {
    10501116                    # this fails sometimes for no apparent reason
    1051                     set dx [expr {double($x-$click_(x))/$w}]
    1052                     set dy [expr {double($y-$click_(y))/$h}]
     1117                    set dx [expr {double($x-$_click(x))/$w}]
     1118                    set dy [expr {double($y-$_click(y))/$h}]
    10531119                }]} {
    10541120                    return
     
    10581124                # Rotate the camera in 3D
    10591125                #
    1060                 if {$view_(psi) > 90 || $view_(psi) < -90} {
     1126                if {$_view(psi) > 90 || $_view(psi) < -90} {
    10611127                    # when psi is flipped around, theta moves backwards
    10621128                    set dy [expr {-$dy}]
    10631129                }
    1064                 set theta [expr {$view_(theta) - $dy*180}]
     1130                set theta [expr {$_view(theta) - $dy*180}]
    10651131                while {$theta < 0} { set theta [expr {$theta+180}] }
    10661132                while {$theta > 180} { set theta [expr {$theta-180}] }
    10671133
    10681134                if {abs($theta) >= 30 && abs($theta) <= 160} {
    1069                     set phi [expr {$view_(phi) - $dx*360}]
     1135                    set phi [expr {$_view(phi) - $dx*360}]
    10701136                    while {$phi < 0} { set phi [expr {$phi+360}] }
    10711137                    while {$phi > 360} { set phi [expr {$phi-360}] }
    1072                     set psi $view_(psi)
     1138                    set psi $_view(psi)
    10731139                } else {
    1074                     set phi $view_(phi)
    1075                     set psi [expr {$view_(psi) - $dx*360}]
     1140                    set phi $_view(phi)
     1141                    set psi [expr {$_view(psi) - $dx*360}]
    10761142                    while {$psi < -180} { set psi [expr {$psi+360}] }
    10771143                    while {$psi > 180} { set psi [expr {$psi-360}] }
    10781144                }
    10791145
    1080                 set view_(theta)        $theta
    1081                 set view_(phi)          $phi
    1082                 set view_(psi)          $psi
     1146                set _view(theta)        $theta
     1147                set _view(phi)          $phi
     1148                set _view(psi)          $psi
    10831149                set xyz [Euler2XYZ $theta $phi $psi]
    1084                 set settings_($this-theta) $view_(theta)
    1085                 set settings_($this-phi)   $view_(phi)
    1086                 set settings_($this-psi)   $view_(psi)
     1150                set _settings($this-theta) $_view(theta)
     1151                set _settings($this-phi)   $_view(phi)
     1152                set _settings($this-psi)   $_view(psi)
    10871153                SendCmd "camera angle $xyz"
    1088                 set click_(x) $x
    1089                 set click_(y) $y
     1154                set _click(x) $x
     1155                set _click(y) $y
    10901156            }
    10911157        }
     
    10931159            Rotate drag $x $y
    10941160            $itk_component(3dview) configure -cursor ""
    1095             catch {unset click_}
     1161            catch {unset _click}
    10961162        }
    10971163        default {
     
    11161182        set x [expr $x / double($w)]
    11171183        set y [expr $y / double($h)]
    1118         set view_(pan-x) [expr $view_(pan-x) + $x]
    1119         set view_(pan-y) [expr $view_(pan-y) + $y]
     1184        set _view(pan-x) [expr $_view(pan-x) + $x]
     1185        set _view(pan-y) [expr $_view(pan-y) + $y]
    11201186        PanCamera
    1121         set settings_($this-pan-x) $view_(pan-x)
    1122         set settings_($this-pan-y) $view_(pan-y)
     1187        set _settings($this-pan-x) $_view(pan-x)
     1188        set _settings($this-pan-y) $_view(pan-y)
    11231189        return
    11241190    }
    11251191    if { $option == "click" } {
    1126         set click_(x) $x
    1127         set click_(y) $y
     1192        set _click(x) $x
     1193        set _click(y) $y
    11281194        $itk_component(3dview) configure -cursor hand1
    11291195    }
    11301196    if { $option == "drag" || $option == "release" } {
    1131         set dx [expr ($click_(x) - $x)/double($w)]
    1132         set dy [expr ($click_(y) - $y)/double($h)]
    1133         set click_(x) $x
    1134         set click_(y) $y
    1135         set view_(pan-x) [expr $view_(pan-x) - $dx]
    1136         set view_(pan-y) [expr $view_(pan-y) - $dy]
     1197        set dx [expr ($_click(x) - $x)/double($w)]
     1198        set dy [expr ($_click(y) - $y)/double($h)]
     1199        set _click(x) $x
     1200        set _click(y) $y
     1201        set _view(pan-x) [expr $_view(pan-x) - $dx]
     1202        set _view(pan-y) [expr $_view(pan-y) - $dy]
    11371203        PanCamera
    1138         set settings_($this-pan-x) $view_(pan-x)
    1139         set settings_($this-pan-y) $view_(pan-y)
     1204        set _settings($this-pan-x) $_view(pan-x)
     1205        set _settings($this-pan-y) $_view(pan-y)
    11401206    }
    11411207    if { $option == "release" } {
    11421208        $itk_component(3dview) configure -cursor ""
    11431209    }
    1144 }
    1145 
    1146 # ----------------------------------------------------------------------
    1147 # USAGE: State <component>
    1148 #
    1149 # Used internally to determine the state of a toggle button.
    1150 # The <component> is the itk component name of the button.
    1151 # Returns on/off for the state of the button.
    1152 # ----------------------------------------------------------------------
    1153 itcl::body Rappture::NanovisViewer::State { comp } {
    1154     if {[$itk_component(${comp}) cget -relief] == "sunken"} {
    1155         return "on"
    1156     }
    1157     return "off"
    11581210}
    11591211
     
    11691221        light {
    11701222            if {[isconnected]} {
    1171                 set val $settings_($this-light)
     1223                set val $_settings($this-light)
    11721224                set sval [expr {0.1*$val}]
    11731225                SendCmd "volume shading diffuse $sval"
     
    11781230        transp {
    11791231            if {[isconnected]} {
    1180                 set val $settings_($this-transp)
     1232                set val $_settings($this-transp)
    11811233                set sval [expr {0.2*$val+1}]
    11821234                SendCmd "volume shading opacity $sval"
     
    11841236        }
    11851237        opacity {
    1186             if {[isconnected] && $activeTf_ != "" } {
    1187                 set val $settings_($this-opacity)
     1238            if {[isconnected] && $_activeTf != "" } {
     1239                set val $_settings($this-opacity)
    11881240                set sval [expr { 0.01 * double($val) }]
    1189                 set tf $activeTf_
    1190                 set settings_($this-$tf-opacity) $sval
     1241                set tf $_activeTf
     1242                set _settings($this-$tf-opacity) $sval
    11911243                updatetransferfuncs
    11921244            }
     
    11941246
    11951247        thickness {
    1196             if {[isconnected] && $activeTf_ != "" } {
    1197                 set val $settings_($this-thickness)
     1248            if {[isconnected] && $_activeTf != "" } {
     1249                set val $_settings($this-thickness)
    11981250                # Scale values between 0.00001 and 0.01000
    11991251                set sval [expr {0.0001*double($val)}]
    1200                 set tf $activeTf_
    1201                 set settings_($this-$tf-thickness) $sval
     1252                set tf $_activeTf
     1253                set _settings($this-$tf-thickness) $sval
    12021254                updatetransferfuncs
    12031255            }
     
    12051257        "outline" {
    12061258            if {[isconnected]} {
    1207                 SendCmd "volume outline state $settings_($this-outline)"
     1259                SendCmd "volume outline state $_settings($this-outline)"
    12081260            }
    12091261        }
    12101262        "isosurface" {
    12111263            if {[isconnected]} {
    1212                 SendCmd "volume shading isosurface $settings_($this-isosurface)"
     1264                SendCmd "volume shading isosurface $_settings($this-isosurface)"
    12131265            }
    12141266        }
    12151267        "grid" {
    12161268            if { [isconnected] } {
    1217                 SendCmd "grid visible $settings_($this-grid)"
     1269                SendCmd "grid visible $_settings($this-grid)"
    12181270            }
    12191271        }
    12201272        "axes" {
    12211273            if { [isconnected] } {
    1222                 SendCmd "axis visible $settings_($this-axes)"
     1274                SendCmd "axis visible $_settings($this-axes)"
    12231275            }
    12241276        }
    12251277        "legend" {
    1226             if { $settings_($this-legend) } {
     1278            if { $_settings($this-legend) } {
    12271279                blt::table $itk_component(plotarea) \
    12281280                    0,0 $itk_component(3dview) -fill both \
     
    12341286        }
    12351287        "volume" {
    1236             Slice volume $settings_($this-volume)
     1288            if { [isconnected] } {
     1289                set vols [CurrentVolumeIds -cutplanes]
     1290                SendCmd "volume data state $_settings($this-volume) $vols"
     1291            }
     1292        }
     1293        "xcutplane" - "ycutplane" - "zcutplane" {
     1294            set axis [string range $what 0 1]
     1295            set bool $_settings($this-$what)
     1296            if { [isconnected] } {
     1297                set vols [CurrentVolumeIds -cutplanes]
     1298                SendCmd "cutplane state $bool $axis $vols"
     1299            }
     1300            if { $bool } {
     1301                $itk_component(${axis}CutScale) configure -state normal \
     1302                    -troughcolor white
     1303            } else {
     1304                $itk_component(${axis}CutScale) configure -state disabled \
     1305                    -troughcolor grey82
     1306            }
    12371307        }
    12381308        default {
     
    12511321itcl::body Rappture::NanovisViewer::FixLegend {} {
    12521322    set lineht [font metrics $itk_option(-font) -linespace]
    1253     set w [expr {$width_-20}]
     1323    set w [expr {$_width-20}]
    12541324    set h [expr {[winfo height $itk_component(legend)]-20-$lineht}]
    1255     if {$w > 0 && $h > 0 && "" != $activeTf_} {
    1256         SendCmd "legend $activeTf_ $w $h"
     1325    if {$w > 0 && $h > 0 && "" != $_activeTf} {
     1326        SendCmd "legend $_activeTf $w $h"
    12571327    } else {
    12581328        # Can't do this as this will remove the items associated with the
     
    12781348#              now.
    12791349#
    1280 itcl::body Rappture::NanovisViewer::NameTransferFunc { ivol } {
     1350itcl::body Rappture::NanovisViewer::NameTransferFunc { dataobj comp } {
    12811351    array set style {
    12821352        -color rainbow
     
    12841354        -opacity 1.0
    12851355    }
    1286     foreach {dataobj comp} $id2obj_($ivol) break
    12871356    array set style [lindex [$dataobj components -style $comp] 0]
    12881357    set tf "$style(-color):$style(-levels):$style(-opacity)"
    1289 
    1290     set id2style_($ivol) $tf
    1291     lappend obj2styles_($dataobj) $tf
    1292     lappend style2ids_($tf) $ivol
     1358    lappend _obj2style($dataobj-$comp) $tf
     1359    lappend _style2objs($tf) $dataobj $comp
     1360    return $tf
    12931361}
    12941362
     
    13091377    }
    13101378    set dataobj ""; set comp ""
    1311     foreach ivol $style2ids_($tf) {
    1312         if { [info exists id2obj_($ivol)] } {
    1313             foreach {dataobj comp} $id2obj_($ivol) break
    1314             break
    1315         }
    1316     }
     1379    foreach {dataobj comp} $_style2objs($tf) break
    13171380    if { $dataobj == "" } {
    1318         return 0
     1381        return 0
    13191382    }
    13201383    array set style [lindex [$dataobj components -style $comp] 0]
     
    13341397    #        barn on this one.
    13351398
    1336     if { ![info exists isomarkers_($tf)] } {
     1399    if { ![info exists _isomarkers($tf)] } {
    13371400        # Have to defer creation of isomarkers until we have data limits
    13381401        if { [info exists style(-markers)] } {
    1339             ParseMarkersOption $tf $ivol $style(-markers)
     1402            ParseMarkersOption $tf $style(-markers)
    13401403        } else {
    1341             ParseLevelsOption $tf $ivol $style(-levels)
     1404            ParseLevelsOption $tf $style(-levels)
    13421405        }
    13431406    }
     
    13551418
    13561419    set tag $this-$tf
    1357     if { ![info exists settings_($tag-opacity)] } {
    1358         set settings_($tag-opacity) $style(-opacity)
    1359     }
    1360     set max $settings_($tag-opacity)
     1420    if { ![info exists _settings($tag-opacity)] } {
     1421        set _settings($tag-opacity) $style(-opacity)
     1422    }
     1423    set max $_settings($tag-opacity)
    13611424
    13621425    set isovalues {}
    1363     foreach m $isomarkers_($tf) {
     1426    foreach m $_isomarkers($tf) {
    13641427        lappend isovalues [$m relval]
    13651428    }
     
    13671430    set isovalues [lsort -real $isovalues]
    13681431
    1369     if { ![info exists settings_($tag-thickness)]} {
    1370         set settings_($tag-thickness) 0.05
    1371     }
    1372     set delta $settings_($tag-thickness)
     1432    if { ![info exists _settings($tag-thickness)]} {
     1433        set _settings($tag-thickness) 0.05
     1434    }
     1435    set delta $_settings($tag-thickness)
    13731436
    13741437    set first [lindex $isovalues 0]
     
    14131476    }
    14141477    SendBytes "transfunc define $tf { $cmap } { $wmap }\n"
    1415     return [SendBytes "volume shading transfunc $tf $style2ids_($tf)\n"]
     1478    if { [info exists _obj2id($dataobj-$comp)] } {
     1479        return [SendBytes "volume shading transfunc $tf $_obj2id($dataobj-$comp)\n"]
     1480    }
    14161481}
    14171482
     
    14611526# marker is a relative value from 0.0 to 1.0.
    14621527#
    1463 itcl::body Rappture::NanovisViewer::ParseLevelsOption { tf ivol levels } {
     1528itcl::body Rappture::NanovisViewer::ParseLevelsOption { tf levels } {
    14641529    set c $itk_component(legend)
    14651530    regsub -all "," $levels " " levels
     
    14671532        for {set i 1} { $i <= $levels } {incr i} {
    14681533            set x [expr {double($i)/($levels+1)}]
    1469             set m [IsoMarker \#auto $c $this $tf]
     1534            set m [Rappture::IsoMarker \#auto $c $this $tf]
    14701535            $m relval $x
    1471             lappend isomarkers_($tf) $m
     1536            lappend _isomarkers($tf) $m
    14721537        }
    14731538    } else {
    14741539        foreach x $levels {
    1475             set m [IsoMarker \#auto $c $this $tf]
     1540            set m [Rappture::IsoMarker \#auto $c $this $tf]
    14761541            $m relval $x
    1477             lappend isomarkers_($tf) $m
     1542            lappend _isomarkers($tf) $m
    14781543        }
    14791544    }
     
    14921557#       not be seen.
    14931558#
    1494 itcl::body Rappture::NanovisViewer::ParseMarkersOption { tf ivol markers } {
     1559itcl::body Rappture::NanovisViewer::ParseMarkersOption { tf markers } {
    14951560    set c $itk_component(legend)
    14961561    regsub -all "," $markers " " markers
     
    15001565            # ${n}% : Set relative value.
    15011566            set value [expr {$value * 0.01}]
    1502             set m [IsoMarker \#auto $c $this $tf]
     1567            set m [Rappture::IsoMarker \#auto $c $this $tf]
    15031568            $m relval $value
    1504             lappend isomarkers_($tf) $m
     1569            lappend _isomarkers($tf) $m
    15051570        } else {
    15061571            # ${n} : Set absolute value.
    1507             set m [IsoMarker \#auto $c $this $tf]
     1572            set m [Rappture::IsoMarker \#auto $c $this $tf]
    15081573            $m absval $value
    1509             lappend isomarkers_($tf) $m
    1510         }
    1511     }
    1512 }
    1513 
    1514 # ----------------------------------------------------------------------
    1515 # USAGE: Marker start <x> <y>
    1516 # USAGE: Marker update <x> <y>
    1517 # USAGE: Marker end <x> <y>
    1518 #
    1519 # Used internally to handle the various marker operations performed
    1520 # when the user clicks and drags on the legend area.  The marker changes the
    1521 # transfer function to highlight the area being selected in the
    1522 # legend.
     1574            lappend _isomarkers($tf) $m
     1575        }
     1576    }
     1577}
     1578
     1579# ----------------------------------------------------------------------
     1580# USAGE: UndateTransferFuncs
    15231581# ----------------------------------------------------------------------
    15241582itcl::body Rappture::NanovisViewer::updatetransferfuncs {} {
     
    15271585
    15281586itcl::body Rappture::NanovisViewer::AddIsoMarker { x y } {
    1529     if { $activeTf_ == "" } {
     1587    if { $_activeTf == "" } {
    15301588        error "active transfer function isn't set"
    15311589    }
    1532     set tf $activeTf_
     1590    set tf $_activeTf
    15331591    set c $itk_component(legend)
    1534     set m [IsoMarker \#auto $c $this $tf]
     1592    set m [Rappture::IsoMarker \#auto $c $this $tf]
    15351593    set w [winfo width $c]
    15361594    $m relval [expr {double($x-10)/($w-20)}]
    1537     lappend isomarkers_($tf) $m
     1595    lappend _isomarkers($tf) $m
    15381596    updatetransferfuncs
    15391597    return 1
     
    15431601    set tf [$marker transferfunc]
    15441602    set bool 0
    1545     if { [info exists isomarkers_($tf)] } {
     1603    if { [info exists _isomarkers($tf)] } {
    15461604        set list {}
    15471605        set marker [namespace tail $marker]
    1548         foreach m $isomarkers_($tf) {
     1606        foreach m $_isomarkers($tf) {
    15491607            set sx [$m screenpos]
    15501608            if { $m != $marker } {
     
    15591617            lappend list $m
    15601618        }
    1561         set isomarkers_($tf) $list
     1619        set _isomarkers($tf) $list
    15621620        updatetransferfuncs
    15631621    }
     
    15671625itcl::body Rappture::NanovisViewer::overmarker { marker x } {
    15681626    set tf [$marker transferfunc]
    1569     if { [info exists isomarkers_($tf)] } {
     1627    if { [info exists _isomarkers($tf)] } {
    15701628        set marker [namespace tail $marker]
    1571         foreach m $isomarkers_($tf) {
     1629        foreach m $_isomarkers($tf) {
    15721630            set sx [$m screenpos]
    15731631            if { $m != $marker } {
     
    15811639
    15821640itcl::body Rappture::NanovisViewer::limits { tf } {
    1583     set limits_(min) ""
    1584     set limits_(max) ""
    1585     foreach ivol $style2ids_($tf) {
    1586         if { ![info exists limits_($ivol-min)] } {
    1587             # I assume this is after a clear.
    1588             # error "can't find $ivol limits"       
     1641    set _limits(min) 0.0
     1642    set _limits(max) 1.0
     1643    if { ![info exists _style2objs($tf)] } {
     1644        return [array get _limits]
     1645    }
     1646    set min ""; set max ""
     1647    foreach {dataobj comp} $_style2objs($tf) {
     1648        if { ![info exists _obj2id($dataobj-$comp)] } {
    15891649            continue
    15901650        }
    1591         if { $limits_(min) == "" || $limits_(min) > $limits_($ivol-min) } {
    1592             set limits_(min) $limits_($ivol-min)
    1593         }
    1594         if { $limits_(max) == "" || $limits_(max) < $limits_($ivol-max) } {
    1595             set limits_(max) $limits_($ivol-max)
    1596         }
    1597     }
    1598     return [array get limits_]
     1651        set ivol $_obj2id($dataobj-$comp)
     1652        if { ![info exists _limits($ivol-min)] } {
     1653            continue
     1654        }
     1655        if { $min == "" || $min > $_limits($ivol-min) } {
     1656            set min $_limits($ivol-min)
     1657        }
     1658        if { $max == "" || $max < $_limits($ivol-max) } {
     1659            set max $_limits($ivol-max)
     1660        }
     1661    }
     1662    if { $min != "" } {
     1663        set _limits(min) $min
     1664    }
     1665    if { $max != "" } {
     1666        set _limits(max) $max
     1667    }
     1668    return [array get _limits]
    15991669}
    16001670
     
    16101680        lic             1
    16111681    } {
    1612         set settings_($this-$key) $value
     1682        set _settings($this-$key) $value
    16131683    }
    16141684
     
    16211691    $inner configure -borderwidth 4
    16221692
    1623     set ::Rappture::NanovisViewer::settings_($this-isosurface) 0
     1693    set ::Rappture::NanovisViewer::_settings($this-isosurface) 0
    16241694    checkbutton $inner.isosurface \
    16251695        -text "Isosurface shading" \
    1626         -variable [itcl::scope settings_($this-isosurface)] \
     1696        -variable [itcl::scope _settings($this-isosurface)] \
    16271697        -command [itcl::code $this FixSettings isosurface] \
    16281698        -font "Arial 9"
     
    16301700    checkbutton $inner.axes \
    16311701        -text "Axes" \
    1632         -variable [itcl::scope settings_($this-axes)] \
     1702        -variable [itcl::scope _settings($this-axes)] \
    16331703        -command [itcl::code $this FixSettings axes] \
    16341704        -font "Arial 9"
     
    16361706    checkbutton $inner.grid \
    16371707        -text "Grid" \
    1638         -variable [itcl::scope settings_($this-grid)] \
     1708        -variable [itcl::scope _settings($this-grid)] \
    16391709        -command [itcl::code $this FixSettings grid] \
    16401710        -font "Arial 9"
     
    16421712    checkbutton $inner.outline \
    16431713        -text "Outline" \
    1644         -variable [itcl::scope settings_($this-outline)] \
     1714        -variable [itcl::scope _settings($this-outline)] \
    16451715        -command [itcl::code $this FixSettings outline] \
    16461716        -font "Arial 9"
     
    16481718    checkbutton $inner.legend \
    16491719        -text "Legend" \
    1650         -variable [itcl::scope settings_($this-legend)] \
     1720        -variable [itcl::scope _settings($this-legend)] \
    16511721        -command [itcl::code $this FixSettings legend] \
    16521722        -font "Arial 9"
     
    16541724    checkbutton $inner.volume \
    16551725        -text "Volume" \
    1656         -variable [itcl::scope settings_($this-volume)] \
     1726        -variable [itcl::scope _settings($this-volume)] \
    16571727        -command [itcl::code $this FixSettings volume] \
    16581728        -font "Arial 9"
     
    16761746        thickness       350
    16771747    } {
    1678         set settings_($this-$key) $value
     1748        set _settings($this-$key) $value
    16791749    }
    16801750
     
    16881758
    16891759    checkbutton $inner.vol -text "Show volume" -font $fg \
    1690         -variable [itcl::scope settings_($this-volume)] \
     1760        -variable [itcl::scope _settings($this-volume)] \
    16911761        -command [itcl::code $this FixSettings volume]
    16921762    label $inner.shading -text "Shading:" -font $fg
     
    16941764    label $inner.dim -text "Dim" -font $fg
    16951765    ::scale $inner.light -from 0 -to 100 -orient horizontal \
    1696         -variable [itcl::scope settings_($this-light)] \
     1766        -variable [itcl::scope _settings($this-light)] \
    16971767        -width 10 \
    16981768        -showvalue off -command [itcl::code $this FixSettings light]
     
    17011771    label $inner.fog -text "Fog" -font $fg
    17021772    ::scale $inner.transp -from 0 -to 100 -orient horizontal \
    1703         -variable [itcl::scope settings_($this-transp)] \
     1773        -variable [itcl::scope _settings($this-transp)] \
    17041774        -width 10 \
    17051775        -showvalue off -command [itcl::code $this FixSettings transp]
     
    17081778    label $inner.clear -text "Clear" -font $fg
    17091779    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
    1710         -variable [itcl::scope settings_($this-opacity)] \
     1780        -variable [itcl::scope _settings($this-opacity)] \
    17111781        -width 10 \
    17121782        -showvalue off -command [itcl::code $this FixSettings opacity]
     
    17151785    label $inner.thin -text "Thin" -font $fg
    17161786    ::scale $inner.thickness -from 0 -to 1000 -orient horizontal \
    1717         -variable [itcl::scope settings_($this-thickness)] \
     1787        -variable [itcl::scope _settings($this-thickness)] \
    17181788        -width 10 \
    17191789        -showvalue off -command [itcl::code $this FixSettings thickness]
     
    17481818    # X-value slicer...
    17491819    itk_component add xCutButton {
    1750         label $inner.xbutton \
    1751             -borderwidth 1 -relief raised -padx 1 -pady 1 \
    1752             -image [Rappture::icon x-cutplane-off] \
    1753             -highlightthickness 0
    1754     } {
    1755         usual
    1756         ignore -borderwidth -highlightthickness -font
    1757     }
    1758     bind $itk_component(xCutButton) <ButtonPress> \
    1759         [itcl::code $this Slice axis x toggle]
     1820        Rappture::PushButton $inner.xbutton \
     1821            -onimage [Rappture::icon x-cutplane-on] \
     1822            -offimage [Rappture::icon x-cutplane-off] \
     1823            -command [itcl::code $this FixSettings xcutplane] \
     1824            -variable [itcl::scope _settings($this-xcutplane)]
     1825    }
    17601826    Rappture::Tooltip::for $itk_component(xCutButton) \
    17611827        "Toggle the X cut plane on/off"
     
    17651831            -width 10 -orient vertical -showvalue off \
    17661832            -borderwidth 1 -highlightthickness 0 \
    1767             -command [itcl::code $this Slice move x]
     1833            -command [itcl::code $this Slice move x] \
     1834            -variable [itcl::scope _settings($this-xcutposition)]
    17681835    } {
    17691836        usual
     
    17781845    # Y-value slicer...
    17791846    itk_component add yCutButton {
    1780         label $inner.ybutton \
    1781             -borderwidth 1 -relief raised -padx 1 -pady 1 \
    1782             -image [Rappture::icon y-cutplane-off] \
    1783             -highlightthickness 0
    1784     } {
    1785         usual
    1786         ignore -borderwidth -highlightthickness -font
    1787     }
    1788     bind $itk_component(yCutButton) <ButtonPress> \
    1789         [itcl::code $this Slice axis y toggle]
     1847        Rappture::PushButton $inner.ybutton \
     1848            -onimage [Rappture::icon y-cutplane-on] \
     1849            -offimage [Rappture::icon y-cutplane-off] \
     1850            -command [itcl::code $this FixSettings ycutplane] \
     1851            -variable [itcl::scope _settings($this-ycutplane)]
     1852    }
    17901853    Rappture::Tooltip::for $itk_component(yCutButton) \
    17911854        "Toggle the Y cut plane on/off"
     
    17951858            -width 10 -orient vertical -showvalue off \
    17961859            -borderwidth 1 -highlightthickness 0 \
    1797             -command [itcl::code $this Slice move y]
     1860            -command [itcl::code $this Slice move y] \
     1861            -variable [itcl::scope _settings($this-ycutposition)]
    17981862    } {
    17991863        usual
     
    18081872    # Z-value slicer...
    18091873    itk_component add zCutButton {
    1810         label $inner.zbutton \
    1811             -borderwidth 1 -relief raised -padx 1 -pady 1 \
    1812             -image [Rappture::icon z-cutplane-off] \
    1813             -highlightthickness 0
    1814     } {
    1815         usual
    1816         ignore -borderwidth -highlightthickness -font
    1817     }
    1818     bind $itk_component(zCutButton) <ButtonPress> \
    1819         [itcl::code $this Slice axis z toggle]
     1874        Rappture::PushButton $inner.zbutton \
     1875            -onimage [Rappture::icon z-cutplane-on] \
     1876            -offimage [Rappture::icon z-cutplane-off] \
     1877            -command [itcl::code $this FixSettings zcutplane] \
     1878            -variable [itcl::scope _settings($this-zcutplane)]
     1879    }
    18201880    Rappture::Tooltip::for $itk_component(zCutButton) \
    18211881        "Toggle the Z cut plane on/off"
     
    18251885            -width 10 -orient vertical -showvalue off \
    18261886            -borderwidth 1 -highlightthickness 0 \
    1827             -command [itcl::code $this Slice move z]
     1887            -command [itcl::code $this Slice move z] \
     1888            -variable [itcl::scope _settings($this-zcutposition)]
    18281889    } {
    18291890        usual
     
    18611922        label $inner.${tag}label -text $tag -font "Arial 9"
    18621923        entry $inner.${tag} -font "Arial 9"  -bg white \
    1863             -textvariable [itcl::scope settings_($this-$tag)]
     1924            -textvariable [itcl::scope _settings($this-$tag)]
    18641925        bind $inner.${tag} <KeyPress-Return> \
    18651926            [itcl::code $this camera set ${tag}]
     
    18771938
    18781939# ----------------------------------------------------------------------
    1879 # USAGE: Slice axis x|y|z ?on|off|toggle?
    18801940# USAGE: Slice move x|y|z <newval>
    1881 # USAGE: Slice volume ?on|off|toggle?
    18821941#
    18831942# Called automatically when the user drags the slider to move the
     
    18881947itcl::body Rappture::NanovisViewer::Slice {option args} {
    18891948    switch -- $option {
    1890         axis {
    1891             if {[llength $args] < 1 || [llength $args] > 2} {
    1892                 error "wrong # args: should be \"Slice axis x|y|z ?on|off|toggle?\""
    1893             }
    1894             set axis [lindex $args 0]
    1895             set op [lindex $args 1]
    1896             if {$op == ""} {
    1897                 set op "on"
    1898             }
    1899             set current [State ${axis}CutButton]
    1900             if {$op == "toggle"} {
    1901                 if {$current == "on"} {
    1902                     set op "off"
    1903                 } else {
    1904                     set op "on"
    1905                 }
    1906             }
    1907             if {$op} {
    1908                 $itk_component(${axis}CutButton) configure \
    1909                     -relief sunken -image [Rappture::icon ${axis}-cutplane-on]
    1910                 SendCmd "cutplane state 1 $axis [CurrentVolumeIds -cutplanes]"
    1911                 $itk_component(${axis}CutScale) configure -state normal \
    1912                     -troughcolor grey65
    1913             } else {
    1914                 $itk_component(${axis}CutButton) configure \
    1915                     -relief raised -image [Rappture::icon ${axis}-cutplane-off]
    1916                 SendCmd "cutplane state 0 $axis [CurrentVolumeIds -cutplanes]"
    1917                 $itk_component(${axis}CutScale) configure -state disabled \
    1918                     -troughcolor grey82
    1919             }
    1920         }
    19211949        move {
    19221950            if {[llength $args] != 2} {
     
    19271955
    19281956            set newpos [expr {0.01*$newval}]
    1929 #            set newval [expr {0.01*($newval-50)
    1930 #                *($limits_(${axis}max)-$limits_(${axis}min))
    1931 #                  + 0.5*($limits_(${axis}max)+$limits_(${axis}min))}]
    1932 
    1933             # show the current value in the readout
    1934             #puts "readout: $axis = $newval"
    1935 
    19361957            set ids [CurrentVolumeIds -cutplanes]
    19371958            SendCmd "cutplane position $newpos $axis $ids"
    1938         }
    1939         volume {
    1940             if {[llength $args] > 1} {
    1941                 error "wrong # args: should be \"Slice volume ?on|off|toggle?\""
    1942             }
    1943             set op [lindex $args 0]
    1944             if {$op == ""} { set op "on" }
    1945 
    1946             set current $settings_($this-volume)
    1947             if {$op == "toggle"} {
    1948                 if {$current} {
    1949                     set op "off"
    1950                 } else {
    1951                     set op "on"
    1952                 }
    1953             }
    1954            
    1955             if {$op} {
    1956                 SendCmd "volume data state on [CurrentVolumeIds]"
    1957                 $itk_component(volume) configure -relief sunken \
    1958                     -image [Rappture::icon volume-on]
    1959                 set settings_($this-volume) 1
    1960             } else {
    1961                 SendCmd "volume data state off [CurrentVolumeIds]"
    1962                 $itk_component(volume) configure -relief raised \
    1963                     -image [Rappture::icon volume-off]
    1964                 set settings_($this-volume) 0
    1965             }
    19661959        }
    19671960        default {
     
    19801973    set val [$itk_component(${axis}CutScale) get]
    19811974#    set val [expr {0.01*($val-50)
    1982 #        *($limits_(${axis}max)-$limits_(${axis}min))
    1983 #          + 0.5*($limits_(${axis}max)+$limits_(${axis}min))}]
     1975#        *($_limits(${axis}max)-$_limits(${axis}min))
     1976#          + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}]
    19841977    return "Move the [string toupper $axis] cut plane.\nCurrently:  $axis = $val%"
    19851978}
     
    19871980
    19881981itcl::body Rappture::NanovisViewer::DoResize {} {
    1989     SendCmd "screen $width_ $height_"
     1982    SendCmd "screen $_width $_height"
    19901983}
    19911984
    19921985itcl::body Rappture::NanovisViewer::EventuallyResize { w h } {
    1993     if { $width_ != $w || $height_ != $h } {
    1994         set width_ $w
    1995         set height_ $h
     1986    if { $_width != $w || $_height != $h } {
     1987        set _width $w
     1988        set _height $h
    19961989        $_dispatcher event -idle !resize
    19971990    }
     
    20011994    $_dispatcher event -idle !legend
    20021995}
     1996
    20031997
    20041998#  camera --
     
    20072001    switch -- $option {
    20082002        "show" {
    2009             puts [array get view_]
     2003            puts [array get _view]
    20102004        }
    20112005        "set" {
    20122006            set who [lindex $args 0]
    2013             set x $settings_($this-$who)
     2007            set x $_settings($this-$who)
    20142008            set code [catch { string is double $x } result]
    20152009            if { $code != 0 || !$result } {
    2016                 set settings_($this-$who) $view_($who)
     2010                set _settings($this-$who) $_view($who)
    20172011                return
    20182012            }
    20192013            switch -- $who {
    20202014                "pan-x" - "pan-y" {
    2021                     set view_($who) $settings_($this-$who)
     2015                    set _view($who) $_settings($this-$who)
    20222016                    PanCamera
    20232017                }
    20242018                "phi" - "theta" - "psi" {
    2025                     set view_($who) $settings_($this-$who)
    2026                     set xyz [Euler2XYZ $view_(theta) $view_(phi) $view_(psi)]
     2019                    set _view($who) $_settings($this-$who)
     2020                    set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)]
    20272021                    SendCmd "camera angle $xyz"
    20282022                }
    20292023                "zoom" {
    2030                     set view_($who) $settings_($this-$who)
    2031                     SendCmd "camera zoom $view_(zoom)"
     2024                    set _view($who) $_settings($this-$who)
     2025                    SendCmd "camera zoom $_view(zoom)"
    20322026                }
    20332027            }
     
    20352029    }
    20362030}
    2037 
Note: See TracChangeset for help on using the changeset viewer.