Changeset 4994


Ignore:
Timestamp:
Feb 10, 2015, 8:11:45 PM (10 years ago)
Author:
dkearney
Message:

merging uiuc's requested isosurfaceviewser changes into branch 1.3, it adds the ability to change the min and max displayed iso values for an object.

Location:
branches/1.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3

  • branches/1.3/gui/scripts/vtkisosurfaceviewer.tcl

    r4968 r4994  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*- 
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    22# ----------------------------------------------------------------------
    33#  COMPONENT: vtkisosurfaceviewer - Vtk 3D contour object viewer
     
    5757    public method get {args}
    5858    public method isconnected {}
    59     public method parameters {title args} { 
    60         # do nothing 
     59    public method parameters {title args} {
     60        # do nothing
    6161    }
    6262    public method scale {args}
     
    6868    private method BuildColormap { name }
    6969    private method BuildCutplaneTab {}
    70     private method BuildDownloadPopup { widget command } 
     70    private method BuildDownloadPopup { widget command }
    7171    private method BuildIsosurfaceTab {}
    72     private method Combo { option }
    7372    private method Connect {}
    7473    private method CurrentDatasets {args}
     74    private method DisableMouseRotationBindings {}
    7575    private method Disconnect {}
    7676    private method DoChangeContourLevels {}
     
    7878    private method DoRotate {}
    7979    private method DrawLegend {}
    80     private method EnterLegend { x y } 
    81     private method EventuallyChangeContourLevels {} 
    82     private method EventuallyRequestLegend {} 
    83     private method EventuallyResize { w h } 
    84     private method EventuallyRotate { q } 
    85     private method EventuallySetCutplane { axis args } 
     80    private method EnterLegend { x y }
     81    private method EventuallyChangeContourLevels {}
     82    private method EventuallyRequestLegend {}
     83    private method EventuallyResize { w h }
     84    private method EventuallyRotate { q }
     85    private method EventuallySetCutplane { axis args }
    8686    private method GenerateContourList {}
    87     private method GetImage { args } 
    88     private method GetVtkData { args } 
     87    private method GetImage { args }
     88    private method GetVtkData { args }
    8989    private method InitSettings { args  }
    90     private method IsValidObject { dataobj } 
     90    private method IsValidObject { dataobj }
    9191    private method LeaveLegend {}
    92     private method MotionLegend { x y }
     92    private method LegendB1Motion {status x y}
     93    private method LegendPointToValue { x y }
     94    private method LegendProbeSingleContour { x y }
     95    private method LegendRangeAction { option args }
     96    private method LegendTitleAction { option }
     97    private method MotionLegend { x y }
    9398    private method Pan {option x y}
    9499    private method PanCamera {}
    95100    private method Pick {x y}
    96     private method QuaternionToView { q } { 
     101    private method QuaternionToView { q } {
    97102        foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break
    98103    }
     
    108113    private method SetObjectStyle { dataobj comp }
    109114    private method SetOrientation { side }
     115    private method SetupMouseRotationBindings {}
     116    private method SetupMousePanningBindings {}
     117    private method SetupKeyboardBindings {}
    110118    private method Slice {option args}
    111     private method ViewToQuaternion {} { 
     119    private method ViewToQuaternion {} {
    112120        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
    113121    }
     
    119127    private variable _obj2datasets
    120128    private variable _obj2ovride   ;    # maps dataobj => style override
    121     private variable _datasets     ;    # contains all the dataobj-component 
     129    private variable _datasets     ;    # contains all the dataobj-component
    122130                                   ;    # datasets in the server
    123131    private variable _colormaps    ;    # contains all the colormaps
     
    157165    private variable _legendPending 0
    158166    private variable _field      ""
    159     private variable _colorMode "scalar";       #  Mode of colormap (vmag or scalar)
    160     private variable _fieldNames {} 
    161     private variable _fields 
     167    private variable _colorMode "scalar";   #  Mode of colormap (vmag or scalar)
     168    private variable _fieldNames {}
     169    private variable _fields
    162170    private variable _curFldName ""
    163171    private variable _curFldLabel ""
     172
     173    private variable _mouseOver "";     # what called LegendRangeAction, vmin or vmax
    164174}
    165175
     
    247257        -colormap                   BCGYR
    248258        -colormapvisible            1
     259        -customrange                0
     260        -customrangevmin            0
     261        -customrangevmax            1
    249262        -cutplaneedges              0
    250263        -cutplanelighting           1
     
    294307    itk_component add fieldmenu {
    295308        menu $itk_component(plotarea).menu -bg black -fg white -relief flat \
    296             -tearoff 0 
     309            -tearoff 0
    297310    } {
    298311        usual
    299312        ignore -background -foreground -relief -tearoff
    300313    }
     314
     315    # add an editor for adjusting the legend min and max values
     316    itk_component add editor {
     317        Rappture::Editor $itk_interior.editor \
     318            -activatecommand [itcl::code $this LegendRangeAction activate] \
     319            -validatecommand [itcl::code $this LegendRangeAction validate] \
     320            -applycommand [itcl::code $this LegendRangeAction apply]
     321    }
     322
    301323    set c $itk_component(view)
    302324    bind $c <Configure> [itcl::code $this EventuallyResize %w %h]
     
    314336
    315337    set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)]
    316     set _map(cwidth) -1 
    317     set _map(cheight) -1 
     338    set _map(cwidth) -1
     339    set _map(cheight) -1
    318340    set _map(zoom) 1.0
    319341    set _map(original) ""
     
    362384            -offimage [Rappture::icon volume-off] \
    363385            -variable [itcl::scope _settings(-isosurfacevisible)] \
    364             -command [itcl::code $this AdjustSetting -isosurfacevisible] 
     386            -command [itcl::code $this AdjustSetting -isosurfacevisible]
    365387    }
    366388    $itk_component(contour) select
     
    374396            -offimage [Rappture::icon cutbutton] \
    375397            -variable [itcl::scope _settings(-cutplanesvisible)] \
    376             -command [itcl::code $this AdjustSetting -cutplanesvisible] 
     398            -command [itcl::code $this AdjustSetting -cutplanesvisible]
    377399    }
    378400    Rappture::Tooltip::for $itk_component(cutplane) \
     
    393415    set _image(legend) [image create photo]
    394416    itk_component add legend {
    395         canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 
     417        canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0
    396418    } {
    397419        usual
     
    400422    }
    401423
    402     # Hack around the Tk panewindow.  The problem is that the requested 
     424    # Hack around the Tk panewindow.  The problem is that the requested
    403425    # size of the 3d view isn't set until an image is retrieved from
    404426    # the server.  So the panewindow uses the tiny size.
     
    406428    pack forget $itk_component(view)
    407429    blt::table $itk_component(plotarea) \
    408         0,0 $itk_component(view) -fill both -reqwidth $w 
     430        0,0 $itk_component(view) -fill both -reqwidth $w
    409431    blt::table configure $itk_component(plotarea) c1 -resize none
    410432
     433    SetupMouseRotationBindings
     434    SetupMousePanningBindings
     435    SetupKeyboardBindings
     436
     437
     438    #bind $itk_component(view) <ButtonRelease-3> \
     439    #    [itcl::code $this Pick %x %y]
     440
     441
     442    if {[string equal "x11" [tk windowingsystem]]} {
     443        # Bindings for zoom via mouse
     444        bind $itk_component(view) <4> [itcl::code $this Zoom out]
     445        bind $itk_component(view) <5> [itcl::code $this Zoom in]
     446    }
     447
     448    set _image(download) [image create photo]
     449
     450    eval itk_initialize $args
     451
     452    EnableWaitDialog 500
     453    Connect
     454    # FIXME: Removing this update breaks wizard mode (see examples/3D)
     455    # However, it also allows an error in the initialization order
     456    # where FieldResult::add is called from ResultViewer before this
     457    # constructor is completed.
     458    #update
     459}
     460
     461# ----------------------------------------------------------------------
     462# DESTRUCTOR
     463# ----------------------------------------------------------------------
     464itcl::body Rappture::VtkIsosurfaceViewer::destructor {} {
     465    Disconnect
     466    image delete $_image(plot)
     467    image delete $_image(download)
     468    catch { blt::arcball destroy $_arcball }
     469}
     470
     471itcl::body Rappture::VtkIsosurfaceViewer::SetupMouseRotationBindings {} {
    411472    # Bindings for rotation via mouse
    412473    bind $itk_component(view) <ButtonPress-1> \
     
    416477    bind $itk_component(view) <ButtonRelease-1> \
    417478        [itcl::code $this Rotate release %x %y]
    418 
     479}
     480
     481itcl::body Rappture::VtkIsosurfaceViewer::DisableMouseRotationBindings {} {
     482    # Bindings for rotation via mouse
     483    bind $itk_component(view) <ButtonPress-1> ""
     484    bind $itk_component(view) <B1-Motion> ""
     485    bind $itk_component(view) <ButtonRelease-1> ""
     486}
     487
     488itcl::body Rappture::VtkIsosurfaceViewer::SetupMousePanningBindings {} {
    419489    # Bindings for panning via mouse
    420490    bind $itk_component(view) <ButtonPress-2> \
     
    424494    bind $itk_component(view) <ButtonRelease-2> \
    425495        [itcl::code $this Pan release %x %y]
    426 
    427     #bind $itk_component(view) <ButtonRelease-3> \
    428     #    [itcl::code $this Pick %x %y]
    429 
     496}
     497
     498itcl::body Rappture::VtkIsosurfaceViewer::SetupKeyboardBindings {} {
    430499    # Bindings for panning via keyboard
    431500    bind $itk_component(view) <KeyPress-Left> \
     
    453522
    454523    bind $itk_component(view) <Enter> "focus $itk_component(view)"
    455 
    456     if {[string equal "x11" [tk windowingsystem]]} {
    457         # Bindings for zoom via mouse
    458         bind $itk_component(view) <4> [itcl::code $this Zoom out]
    459         bind $itk_component(view) <5> [itcl::code $this Zoom in]
    460     }
    461 
    462     set _image(download) [image create photo]
    463 
    464     eval itk_initialize $args
    465 
    466     EnableWaitDialog 500
    467     Connect
    468 }
    469 
    470 # ----------------------------------------------------------------------
    471 # DESTRUCTOR
    472 # ----------------------------------------------------------------------
    473 itcl::body Rappture::VtkIsosurfaceViewer::destructor {} {
    474     Disconnect
    475     image delete $_image(plot)
    476     image delete $_image(download)
    477     catch { blt::arcball destroy $_arcball }
    478524}
    479525
     
    501547
    502548itcl::body Rappture::VtkIsosurfaceViewer::DoRotate {} {
    503     SendCmd "camera orient [ViewToQuaternion]" 
     549    SendCmd "camera orient [ViewToQuaternion]"
    504550    set _rotatePending 0
    505551}
     
    528574    if { !$_rotatePending } {
    529575        set _rotatePending 1
    530         global rotate_delay 
     576        global rotate_delay
    531577        $_dispatcher event -after $rotate_delay !rotate
    532578    }
     
    545591    if { !$_contourList(updatePending) } {
    546592        set _contourList(updatePending) 1
    547         global rotate_delay 
     593        global rotate_delay
    548594        $_dispatcher event -after $rotate_delay !contours
    549595    }
     
    644690                    continue
    645691                }
    646                 if {[info exists _obj2ovride($dataobj-raise)] && 
     692                if {[info exists _obj2ovride($dataobj-raise)] &&
    647693                    $_obj2ovride($dataobj-raise)} {
    648694                    set dlist [linsert $dlist 0 $dataobj]
     
    672718            }
    673719            return $dlist
    674         }           
     720        }
    675721        -image {
    676722            if {[llength $args] != 2} {
     
    725771            if { ![info exists _limits($fname)] } {
    726772                set _limits($fname) $lim
     773
     774                # set reasonable defaults for
     775                # customrangevmin and customrangevmax
     776                foreach {min max} $lim break
     777                if { ![info exists _settings(-customrangevmin)] } {
     778                    set _settings(-customrangevmin) $min
     779                }
     780                if { ![info exists _settings(-customrangevmax)] } {
     781                    set _settings(-customrangevmax) $max
     782                }
     783
    727784                continue
    728785            }
    729786            foreach {min max} $lim break
    730787            foreach {fmin fmax} $_limits($fname) break
     788#            if { $fname == $_curFldName && ! $_settings(-customrange) } {}
     789            if { ! $_settings(-customrange) } {
     790                set _settings(-customrangevmin) $fmin
     791                set _settings(-customrangevmax) $fmax
     792            }
    731793            if { $fmin > $min } {
    732794                set fmin $min
     
    911973        #set w [image width $_image(plot)]
    912974        #set h [image height $_image(plot)]
    913         #puts stderr "$date: received image ${w}x${h} image"       
     975        #puts stderr "$date: received image ${w}x${h} image"
    914976        if { $_start > 0 } {
    915977            set finish [clock clicks -milliseconds]
     
    9821044    # Turn on buffering of commands to the server.  We don't want to
    9831045    # be preempted by a server disconnect/reconnect (which automatically
    984     # generates a new call to Rebuild).   
     1046    # generates a new call to Rebuild).
    9851047    StartBufferingCommands
    9861048
     
    10441106            lappend _obj2datasets($dataobj) $tag
    10451107            if { [info exists _obj2ovride($dataobj-raise)] } {
    1046                 SendCmd "contour3d visible 1 $tag"
     1108                SendCmd "contour3d visible 1 $tag"
    10471109            }
    10481110        }
     
    10511113    InitSettings -cutplanesvisible -isosurfacevisible -outline
    10521114    if { $_reset } {
    1053         # These are settings that rely on a dataset being loaded.
     1115        # These are settings that rely on a dataset being loaded.
    10541116        InitSettings \
    10551117            -isosurfacelighting \
     
    10571119            -isosurfacevisible \
    10581120            -isosurfaceedges -isosurfacelighting -isosurfaceopacity \
    1059             -isosurfacewireframe \
     1121            -isosurfacewireframe \
    10601122            -cutplanesvisible \
    1061             -xcutplaneposition -ycutplaneposition -zcutplaneposition \
    1062             -xcutplanevisible -ycutplanevisible -zcutplanevisible \
     1123            -xcutplaneposition -ycutplaneposition -zcutplaneposition \
     1124            -xcutplanevisible -ycutplanevisible -zcutplanevisible \
    10631125            -cutplanepreinterp -numcontours
    10641126
    10651127        Zoom reset
    1066         foreach axis { x y z } {
     1128        foreach axis { x y z } {
    10671129            # Another problem fixed by a <view>. We looking into a data
    10681130            # object for the name of the axes. This should be global to
    10691131            # the viewer itself.
    1070             set label [$_first hints ${axis}label]
    1071             if { $label == "" } {
     1132            set label [$_first hints ${axis}label]
     1133            if { $label == "" } {
    10721134                set label [string toupper $axis]
    1073             }
     1135            }
    10741136            # May be a space in the axis label
    1075             SendCmd [list axis name $axis $label]
     1137            SendCmd [list axis name $axis $label]
    10761138        }
    10771139        if { [array size _fields] < 2 } {
     
    11001162itcl::body Rappture::VtkIsosurfaceViewer::CurrentDatasets {args} {
    11011163    set flag [lindex $args 0]
    1102     switch -- $flag { 
     1164    switch -- $flag {
    11031165        "-all" {
    11041166            if { [llength $args] > 1 } {
     
    11191181                set dlist [get -visible]
    11201182            }
    1121         }           
     1183        }
    11221184        default {
    11231185            set dlist $args
     
    12381300    foreach tag [CurrentDatasets -visible] {
    12391301        SendCmd "dataset getscalar pixel $x $y $tag"
    1240     } 
     1302    }
    12411303}
    12421304
     
    13421404        "-background" {
    13431405            set bgcolor [$itk_component(background) value]
    1344             array set fgcolors {
    1345                 "black" "white"
    1346                 "white" "black"
    1347                 "grey"  "black"
    1348             }
     1406            array set fgcolors {
     1407                "black" "white"
     1408                "white" "black"
     1409                "grey"  "black"
     1410            }
    13491411            configure -plotbackground $bgcolor \
    1350                 -plotforeground $fgcolors($bgcolor)
    1351             $itk_component(view) delete "legend"
    1352             DrawLegend
     1412                -plotforeground $fgcolors($bgcolor)
     1413            $itk_component(view) delete "legend"
     1414            DrawLegend
    13531415        }
    13541416        "-cutplaneedges" {
     
    13701432        "-cutplanesvisible" {
    13711433            set bool $_settings($what)
    1372             SendCmd "cutplane visible 0"
     1434            SendCmd "cutplane visible 0"
    13731435            if { $bool } {
    13741436                foreach tag [CurrentDatasets -visible] {
     
    13931455            set color [$itk_component(colormap) value]
    13941456            set _settings($what) $color
    1395             if { $color == "none" } {
    1396                 if { $_settings(-colormapvisible) } {
    1397                     SendCmd "contour3d colormode constant {}"
    1398                     set _settings(-colormapvisible) 0
    1399                 }
    1400             } else {
    1401                 if { !$_settings(-colormapvisible) } {
    1402                     SendCmd "contour3d colormode $_colorMode $_curFldName"
    1403                     set _settings(-colormapvisible) 1
    1404                 }
    1405                 SetCurrentColormap $color
    1406             }
     1457            if { $color == "none" } {
     1458                if { $_settings(-colormapvisible) } {
     1459                    SendCmd "contour3d colormode constant {}"
     1460                    set _settings(-colormapvisible) 0
     1461                }
     1462            } else {
     1463                if { !$_settings(-colormapvisible) } {
     1464                    SendCmd "contour3d colormode $_colorMode $_curFldName"
     1465                    set _settings(-colormapvisible) 1
     1466                }
     1467                SetCurrentColormap $color
     1468            }
    14071469            StopBufferingCommands
    1408             EventuallyRequestLegend
     1470            EventuallyRequestLegend
    14091471        }
    14101472        "-field" {
     
    14291491                SendCmd "dataset maprange all"
    14301492            } else {
    1431                 SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName"
     1493                foreach { vmin vmax } $_limits($_curFldName) break
     1494                if { $_settings(-customrange) } {
     1495                    if { $_settings(-customrangevmin) > $vmin } {
     1496                        set vmin $_settings(-customrangevmin)
     1497                    }
     1498                    if { $_settings(-customrangevmax) < $vmax } {
     1499                        set vmax $_settings(-customrangevmax)
     1500                    }
     1501                }
     1502                SendCmd "dataset maprange explicit $vmin $vmax $_curFldName"
    14321503            }
    14331504            SendCmd "cutplane colormode $_colorMode $_curFldName"
     
    14391510        "-isolinecolor" {
    14401511            set color [$itk_component(isolineColor) value]
    1441             set _settings($what) $color
    1442             DrawLegend
     1512            set _settings($what) $color
     1513            DrawLegend
    14431514        }
    14441515        "-isosurfaceedges" {
    14451516            set bool $_settings($what)
    1446             SendCmd "contour3d edges $bool"
     1517            SendCmd "contour3d edges $bool"
    14471518        }
    14481519        "-isosurfacelighting" {
    14491520            set bool $_settings($what)
    1450             SendCmd "contour3d lighting $bool"
     1521            SendCmd "contour3d lighting $bool"
    14511522        }
    14521523        "-isosurfaceopacity" {
    14531524            set _settings($what) [expr $_widget($what) * 0.01]
    1454             SendCmd "contour3d opacity $_settings($what)"
     1525            SendCmd "contour3d opacity $_settings($what)"
    14551526        }
    14561527        "-isosurfacevisible" {
    14571528            set bool $_settings($what)
    1458             SendCmd "contour3d visible 0"
     1529            SendCmd "contour3d visible 0"
    14591530            if { $bool } {
    14601531                foreach tag [CurrentDatasets -visible] {
     
    14721543        "-isosurfacewireframe" {
    14731544            set bool $_settings($what)
    1474             SendCmd "contour3d wireframe $bool"
     1545            SendCmd "contour3d wireframe $bool"
    14751546        }
    14761547        "-legendvisible" {
    14771548            if { !$_settings($what) } {
    14781549                $itk_component(view) delete legend
    1479             }
    1480             DrawLegend
     1550            }
     1551            DrawLegend
    14811552        }
    14821553        "-numcontours" {
     
    14971568        "-outline" {
    14981569            set bool $_settings($what)
    1499             SendCmd "outline visible 0"
     1570            SendCmd "outline visible 0"
    15001571            if { $bool } {
    15011572                foreach tag [CurrentDatasets -visible] {
     
    15031574                }
    15041575            }
     1576        }
     1577        "-range" {
     1578            foreach { vmin vmax } $_limits($_curFldName) break
     1579            if { $_settings(-customrange) } {
     1580                $itk_component(l_min) configure -state normal
     1581                $itk_component(min) configure -state normal
     1582                $itk_component(l_max) configure -state normal
     1583                $itk_component(max) configure -state normal
     1584#                foreach { vmin vmax } $_limits($_curFldName) break
     1585#                if { $_settings(-customrangevmin) < $vmin } {
     1586#                    set _settings(-customrangevmin) $vmin
     1587#                }
     1588#                if { $_settings(-customrangevmin) > $vmax } {
     1589#                    set _settings(-customrangevmin) $vmax
     1590#                }
     1591#                if { $_settings(-customrangevmax) < $vmin } {
     1592#                    set _settings(-customrangevmax) $vmin
     1593#                }
     1594#                if { $_settings(-customrangevmax) > $vmax } {
     1595#                    set _settings(-customrangevmax) $vmax
     1596#                }
     1597#
     1598                if { $_settings(-customrangevmin) > $vmin } {
     1599                    set vmin $_settings(-customrangevmin)
     1600                }
     1601                if { $_settings(-customrangevmax) < $vmax } {
     1602                    set vmax $_settings(-customrangevmax)
     1603                }
     1604            } else {
     1605                $itk_component(l_min) configure -state disabled
     1606                $itk_component(min) configure -state disabled
     1607                $itk_component(l_max) configure -state disabled
     1608                $itk_component(max) configure -state disabled
     1609            }
     1610            GenerateContourList
     1611            SendCmd [list contour3d contourlist $_contourList(values)]
     1612            SendCmd "dataset maprange explicit $vmin $vmax $_curFldName"
     1613            DrawLegend
    15051614        }
    15061615        "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
     
    15141623                    -troughcolor grey82
    15151624            }
    1516             SendCmd "cutplane axis $axis $bool"
     1625            SendCmd "cutplane axis $axis $bool"
    15171626        }
    15181627        "-xcutplaneposition" - "-ycutplaneposition" - "-zcutplaneposition" {
     
    15371646#
    15381647#       Request a new legend from the server.  The size of the legend
    1539 #       is determined from the height of the canvas. 
     1648#       is determined from the height of the canvas.
    15401649#
    15411650# This should be called when
    1542 #       1.  A new current colormap is set.
    1543 #       2.  Window is resized.
    1544 #       3.  The limits of the data have changed.  (Just need a redraw).
    1545 #       4.  Number of isolines have changed. (Just need a redraw).
    1546 #       5.  Legend becomes visible (Just need a redraw).
     1651#   1.  A new current colormap is set.
     1652#   2.  Window is resized.
     1653#   3.  The limits of the data have changed.  (Just need a redraw).
     1654#   4.  Number of isolines have changed. (Just need a redraw).
     1655#   5.  Legend becomes visible (Just need a redraw).
    15471656#
    15481657itcl::body Rappture::VtkIsosurfaceViewer::RequestLegend {} {
     
    15601669    }
    15611670    if { [string match "component*" $fname] } {
    1562         set title ""
     1671        set title ""
    15631672    } else {
    1564         if { [info exists _fields($fname)] } {
    1565             foreach { title units } $_fields($fname) break
    1566             if { $units != "" } {
    1567                 set title [format "%s (%s)" $title $units]
    1568             }
    1569         } else {
    1570             set title $fname
    1571         }
     1673        if { [info exists _fields($fname)] } {
     1674            foreach { title units } $_fields($fname) break
     1675            if { $units != "" } {
     1676                set title [format "%s (%s)" $title $units]
     1677            }
     1678        } else {
     1679            set title $fname
     1680        }
    15721681    }
    15731682    # If there's a title too, subtract one more line
    15741683    if { $title != "" } {
    1575         incr h -$lineht 
    1576     }
    1577     # Set the legend on the first heightmap dataset.
     1684        incr h -$lineht
     1685    }
     1686    # Set the legend on the first isosurface dataset.
    15781687    if { $_currentColormap != ""  } {
    1579         set cmap $_currentColormap
    1580         SendCmdNoWait "legend $cmap scalar $_curFldName {} $w $h 0"
     1688        set cmap $_currentColormap
     1689        SendCmdNoWait "legend $cmap scalar $_curFldName {} $w $h 0"
    15811690    }
    15821691}
     
    15981707    if { [isconnected] } {
    15991708        set rgb [Color2RGB $itk_option(-plotforeground)]
    1600         SendCmd "axis color all $rgb"
     1709        SendCmd "axis color all $rgb"
    16011710        SendCmd "outline color $rgb"
    16021711        SendCmd "cutplane color $rgb"
     
    16501759        -font "Arial 9"
    16511760
    1652     label $inner.linecolor_l -text "Isolines" -font "Arial 9" 
     1761    label $inner.linecolor_l -text "Isolines" -font "Arial 9"
    16531762    itk_component add isolineColor {
    16541763        Rappture::Combobox $inner.linecolor -width 10 -editable 0
     
    16641773        "red"                "red"              \
    16651774        "white"              "white"            \
    1666         "none"               "none"
     1775        "none"               "none"
    16671776
    16681777    $itk_component(isolineColor) value "white"
    16691778    bind $inner.linecolor <<Value>> \
    1670         [itcl::code $this AdjustSetting -isolinecolor]
    1671 
    1672     label $inner.background_l -text "Background" -font "Arial 9" 
     1779        [itcl::code $this AdjustSetting -isolinecolor]
     1780
     1781    label $inner.background_l -text "Background" -font "Arial 9"
    16731782    itk_component add background {
    16741783        Rappture::Combobox $inner.background -width 10 -editable 0
     
    16771786        "black"              "black"            \
    16781787        "white"              "white"            \
    1679         "grey"               "grey"             
     1788        "grey"               "grey"
    16801789
    16811790    $itk_component(background) value $_settings(-background)
     
    16921801
    16931802    itk_component add field_l {
    1694         label $inner.field_l -text "Field" -font "Arial 9" 
     1803        label $inner.field_l -text "Field" -font "Arial 9"
    16951804    } {
    16961805        ignore -font
     
    17021811        [itcl::code $this AdjustSetting -field]
    17031812
    1704     label $inner.colormap_l -text "Colormap" -font "Arial 9" 
     1813    label $inner.colormap_l -text "Colormap" -font "Arial 9"
    17051814    itk_component add colormap {
    17061815        Rappture::Combobox $inner.colormap -width 10 -editable 0
     
    17201829    bind $itk_component(numcontours) <<Value>> \
    17211830        [itcl::code $this AdjustSetting -numcontours]
     1831
     1832
     1833    # add widgets for setting a custom range on the legend
     1834
     1835    itk_component add crange {
     1836        checkbutton $inner.crange \
     1837            -text "Use Custom Range:" \
     1838            -variable [itcl::scope _settings(-customrange)] \
     1839            -command [itcl::code $this AdjustSetting -range] \
     1840            -font "Arial 9"
     1841    }
     1842
     1843    itk_component add l_min {
     1844        label $inner.l_min -text "Min" -font "Arial 9"
     1845    }
     1846    itk_component add min {
     1847        entry $inner.min -font "Arial 9" -bg white \
     1848            -textvariable [itcl::scope _settings(-customrangevmin)]
     1849    } {
     1850        ignore -font -background
     1851    }
     1852    bind $inner.min <Return> \
     1853        [itcl::code $this AdjustSetting -range]
     1854    bind $inner.min <KP_Enter> \
     1855        [itcl::code $this AdjustSetting -range]
     1856
     1857    itk_component add l_max {
     1858        label $inner.l_max -text "Max" -font "Arial 9"
     1859    }
     1860    itk_component add max {
     1861        entry $inner.max -font "Arial 9" -bg white \
     1862            -textvariable [itcl::scope _settings(-customrangevmax)]
     1863    } {
     1864        ignore -font -background
     1865    }
     1866    bind $inner.max <Return> \
     1867        [itcl::code $this AdjustSetting -range]
     1868    bind $inner.max <KP_Enter> \
     1869        [itcl::code $this AdjustSetting -range]
     1870
     1871    $itk_component(min) configure -state disabled
     1872    $itk_component(max) configure -state disabled
     1873
    17221874
    17231875    blt::table $inner \
     
    17281880        2,0 $inner.linecolor_l  -anchor w -pady 2  \
    17291881        2,1 $inner.linecolor    -anchor w -pady 2 -fill x  \
    1730         3,0 $inner.background_l -anchor w -pady 2 \
    1731         3,1 $inner.background -anchor w -pady 2  -fill x \
     1882        3,0 $inner.background_l -anchor w -pady 2 \
     1883        3,1 $inner.background -anchor w -pady 2  -fill x \
    17321884        4,0 $inner.numcontours_l -anchor w -pady 2 \
    17331885        4,1 $inner.numcontours -anchor w -pady 2 \
     
    17391891        10,0 $inner.opacity_l -anchor w -pady 2 \
    17401892        10,1 $inner.opacity   -fill x   -pady 2 -fill x \
     1893        11,0 $inner.crange    -anchor w -pady 2 -cspan 2 \
     1894        12,0 $inner.l_min     -anchor w -pady 2 \
     1895        12,1 $inner.min       -anchor w -pady 2 -fill x \
     1896        13,0 $inner.l_max     -anchor w -pady 2 \
     1897        13,1 $inner.max       -anchor w -pady 2 -fill x \
    17411898
    17421899    blt::table configure $inner r* c* -resize none
    1743     blt::table configure $inner r11 c1 -resize expand
     1900    blt::table configure $inner r14 c1 -resize expand
    17441901}
    17451902
     
    17651922        -command [itcl::code $this AdjustSetting -axislabels] \
    17661923        -font "Arial 9"
    1767     label $inner.grid_l -text "Grid" -font "Arial 9" 
     1924    label $inner.grid_l -text "Grid" -font "Arial 9"
    17681925    checkbutton $inner.xgrid \
    17691926        -text "X" \
     
    17871944        -font "Arial 9"
    17881945
    1789     label $inner.mode_l -text "Mode" -font "Arial 9" 
     1946    label $inner.mode_l -text "Mode" -font "Arial 9"
    17901947
    17911948    itk_component add axisMode {
     
    17961953        "closest_triad"   "closest" \
    17971954        "furthest_triad"  "farthest" \
    1798         "outer_edges"     "outer"         
     1955        "outer_edges"     "outer"
    17991956    $itk_component(axisMode) value $_settings(-axismode)
    18001957    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode]
     
    18712028
    18722029    set fg [option get $itk_component(hull) font Font]
    1873    
     2030
    18742031    set inner [$itk_component(main) insert end \
    18752032        -title "Cutplane Settings" \
    1876         -icon [Rappture::icon cutbutton]] 
     2033        -icon [Rappture::icon cutbutton]]
    18772034
    18782035    $inner configure -borderwidth 4
     
    19332090            -command [itcl::code $this EventuallySetCutplane x] \
    19342091            -variable [itcl::scope _settings(-xcutplaneposition)] \
    1935             -foreground red2 -font "Arial 9 bold"
     2092            -foreground red2 -font "Arial 9 bold"
    19362093    } {
    19372094        usual
     
    19622119            -command [itcl::code $this EventuallySetCutplane y] \
    19632120            -variable [itcl::scope _settings(-ycutplaneposition)] \
    1964             -foreground green3 -font "Arial 9 bold"
     2121            -foreground green3 -font "Arial 9 bold"
    19652122    } {
    19662123        usual
     
    19812138            -variable [itcl::scope _settings(-zcutplanevisible)] \
    19822139    } {
    1983         usual
    1984         ignore -foreground
     2140        usual
     2141        ignore -foreground
    19852142    }
    19862143    Rappture::Tooltip::for $itk_component(zbutton) \
     
    19942151            -command [itcl::code $this EventuallySetCutplane z] \
    19952152            -variable [itcl::scope _settings(-zcutplaneposition)] \
    1996             -foreground blue3 -font "Arial 9 bold"
     2153            -foreground blue3 -font "Arial 9 bold"
    19972154    } {
    19982155        usual
     
    20122169        5,0 $inner.opacity_l            -anchor w -pady 2 -cspan 1 \
    20132170        5,1 $inner.opacity              -fill x   -pady 2 -cspan 3 \
    2014         6,0 $inner.xbutton              -anchor w -padx 2 -pady 2 \
    2015         7,0 $inner.ybutton              -anchor w -padx 2 -pady 2 \
    2016         8,0 $inner.zbutton              -anchor w -padx 2 -pady 2 \
    2017         6,1 $inner.xval                 -fill y -rspan 4 \
    2018         6,2 $inner.yval                 -fill y -rspan 4 \
    2019         6,3 $inner.zval                 -fill y -rspan 4 \
     2171        6,0 $inner.xbutton              -anchor w -padx 2 -pady 2 \
     2172        7,0 $inner.ybutton              -anchor w -padx 2 -pady 2 \
     2173        8,0 $inner.zbutton              -anchor w -padx 2 -pady 2 \
     2174        6,1 $inner.xval                 -fill y -rspan 4 \
     2175        6,2 $inner.yval                 -fill y -rspan 4 \
     2176        6,3 $inner.zval                 -fill y -rspan 4 \
    20202177
    20212178
     
    20252182
    20262183#
    2027 #  camera -- 
     2184#  camera --
    20282185#
    20292186itcl::body Rappture::VtkIsosurfaceViewer::camera {option args} {
    2030     switch -- $option { 
     2187    switch -- $option {
    20312188        "show" {
    20322189            puts [array get _view]
     
    20762233
    20772234itcl::body Rappture::VtkIsosurfaceViewer::GetImage { args } {
    2078     if { [image width $_image(download)] > 0 && 
     2235    if { [image width $_image(download)] > 0 &&
    20792236         [image height $_image(download)] > 0 } {
    20802237        set bytes [$_image(download) data -format "jpeg -quality 100"]
     
    20892246        -title "[Rappture::filexfer::label downloadWord] as..."
    20902247    set inner [$popup component inner]
    2091     label $inner.summary -text "" -anchor w 
     2248    label $inner.summary -text "" -anchor w
    20922249    radiobutton $inner.vtk_button -text "VTK data file" \
    20932250        -variable [itcl::scope _downloadPopup(format)] \
    20942251        -font "Arial 9 " \
    2095         -value vtk 
     2252        -value vtk
    20962253    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
    20972254    radiobutton $inner.image_button -text "Image File" \
    20982255        -variable [itcl::scope _downloadPopup(format)] \
    20992256        -font "Arial 9 " \
    2100         -value image 
     2257        -value image
    21012258    Rappture::Tooltip::for $inner.image_button \
    21022259        "Save as digital image."
     
    21192276        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
    21202277        4,1 $inner.cancel -width .9i -fill y \
    2121         4,0 $inner.ok -padx 2 -width .9i -fill y 
     2278        4,0 $inner.ok -padx 2 -width .9i -fill y
    21222279    blt::table configure $inner r3 -height 4
    21232280    blt::table configure $inner r4 -pady 4
     
    21322289    array set style {
    21332290        -color                  BCGYR
    2134         -cutplanesvisible       0 
     2291        -cutplanesvisible       0
    21352292        -edgecolor              black
    21362293        -edges                  0
     
    21842341            set _contourList(numLevels) $style(-levels)
    21852342        }
    2186         EventuallyChangeContourLevels 
     2343        EventuallyChangeContourLevels
    21872344    }
    21882345    set _settings(-isosurfacevisible) $style(-isosurfacevisible)
     
    21942351    set _settings(-ycutplaneposition) $style(-ycutplaneposition)
    21952352    set _settings(-zcutplaneposition) $style(-zcutplaneposition)
    2196  
     2353
    21972354    SendCmd "cutplane add $tag"
    21982355    SendCmd "cutplane color [Color2RGB $itk_option(-plotforeground)] $tag"
     
    22092366    SendCmd "outline visible $style(-outline) $tag"
    22102367    set _settings(-outline) $style(-outline)
    2211  
     2368
    22122369    GenerateContourList
    22132370    SendCmd [list contour3d add contourlist $_contourList(values) $tag]
     
    22222379    SendCmd "contour3d opacity $style(-opacity) $tag"
    22232380    set _settings(-isosurfaceopacity) $style(-opacity)
    2224     SetCurrentColormap $style(-color) 
     2381    SetCurrentColormap $style(-color)
    22252382    SendCmd "contour3d wireframe $style(-wireframe) $tag"
    22262383    set _settings(-isosurfacewireframe) $style(-wireframe)
     
    22622419}
    22632420
     2421# ----------------------------------------------------------------------
     2422# USAGE: LegendB1Motion press <x> <y>
     2423# USAGE: LegendB1Motion motion <x> <y>
     2424# USAGE: LegendB1Motion release <x> <y>
     2425#
     2426# Manage actions for Button 1 presses that happen over the legend.
     2427# Pressing mouse Button 1 on the legend sends a command to the
     2428# visualization server to show a specific isosurface.
     2429# ----------------------------------------------------------------------
     2430itcl::body Rappture::VtkIsosurfaceViewer::LegendB1Motion { status x y } {
     2431
     2432    switch -- $status {
     2433        "press" {
     2434            DisableMouseRotationBindings
     2435            LegendProbeSingleContour $x $y
     2436        }
     2437        "motion" {
     2438            DisableMouseRotationBindings
     2439            LegendProbeSingleContour $x $y
     2440        }
     2441        "release" {
     2442            AdjustSetting -range
     2443            SetupMouseRotationBindings
     2444        }
     2445        default {
     2446            error "bad option \"$option\": should be one of press, motion, release."
     2447        }
     2448    }
     2449}
     2450
     2451
     2452# ----------------------------------------------------------------------
     2453# USAGE: LegendPointToValue <x> <y>
     2454#
     2455# Convert an x,y point on the legend to a numeric isosurface value.
     2456# ----------------------------------------------------------------------
     2457itcl::body Rappture::VtkIsosurfaceViewer::LegendPointToValue { x y } {
     2458
     2459    set fname $_curFldName
     2460
     2461    set font "Arial 8"
     2462    set lineht [font metrics $font -linespace]
     2463
     2464    set ih [image height $_image(legend)]
     2465    set iy [expr $y - ($lineht + 2)]
     2466
     2467    # Compute the value of the point
     2468    if { [info exists _limits($fname)] } {
     2469        if { $_settings(-customrange) } {
     2470            set vmin $_settings(-customrangevmin)
     2471            set vmax $_settings(-customrangevmax)
     2472        } else {
     2473            foreach { vmin vmax } $_limits($fname) break
     2474        }
     2475        set t [expr 1.0 - (double($iy) / double($ih-1))]
     2476        set value [expr $t * ($vmax - $vmin) + $vmin]
     2477    } else {
     2478        set value 0.0
     2479    }
     2480    return $value
     2481}
     2482
     2483
     2484# ----------------------------------------------------------------------
     2485# USAGE: LegendProbeSingleContour <x> <y>
     2486#
     2487# Calculate the isosurface value for the x,y point and send a commands
     2488# to the visualization server to show that isosurface.
     2489# ----------------------------------------------------------------------
     2490itcl::body Rappture::VtkIsosurfaceViewer::LegendProbeSingleContour { x y } {
     2491
     2492    set value [LegendPointToValue $x $y]
     2493    SendCmd [list contour3d contourlist $value]
     2494}
     2495
     2496
    22642497#
    22652498# SetLegendTip --
     
    22732506    set font "Arial 8"
    22742507    set lineht [font metrics $font -linespace]
    2275    
     2508
    22762509    set ih [image height $_image(legend)]
    22772510    set iy [expr $y - ($lineht + 2)]
    22782511
    22792512    if { [string match "component*" $fname] } {
    2280         set title ""
     2513        set title ""
    22812514    } else {
    2282         if { [info exists _fields($fname)] } {
    2283             foreach { title units } $_fields($fname) break
    2284             if { $units != "" } {
    2285                 set title [format "%s (%s)" $title $units]
    2286             }
    2287         } else {
    2288             set title $fname
    2289         }
     2515        if { [info exists _fields($fname)] } {
     2516            foreach { title units } $_fields($fname) break
     2517            if { $units != "" } {
     2518                set title [format "%s (%s)" $title $units]
     2519            }
     2520        } else {
     2521            set title $fname
     2522        }
    22902523    }
    22912524    # If there's a legend title, increase the offset by the line height.
     
    23012534    }
    23022535    set color [eval format "\#%02x%02x%02x" $pixel]
    2303     $_image(swatch) put black  -to 0 0 23 23 
    2304     $_image(swatch) put $color -to 1 1 22 22 
     2536    $_image(swatch) put black  -to 0 0 23 23
     2537    $_image(swatch) put $color -to 1 1 22 22
    23052538    .rappturetooltip configure -icon $_image(swatch)
    23062539
    23072540    # Compute the value of the point
    2308     if { [info exists _limits($_curFldName)] } {
    2309         foreach { vmin vmax } $_limits($_curFldName) break
    2310         set t [expr 1.0 - (double($iy) / double($ih-1))]
    2311         set value [expr $t * ($vmax - $vmin) + $vmin]
    2312     } else {
    2313         set value 0.0
    2314     }
    2315     set tx [expr $x + 15]
     2541    set value [LegendPointToValue $x $y]
     2542
     2543    # Setup the location of the tooltip
     2544    set tx [expr $x + 15]
    23162545    set ty [expr $y - 5]
     2546
     2547    # Setup the text for the tooltip
    23172548    if { [info exists _isolines($y)] } {
    23182549        Rappture::Tooltip::text $c [format "$title %g (isosurface)" $_isolines($y)]
     
    23202551        Rappture::Tooltip::text $c [format "$title %g" $value]
    23212552    }
    2322     Rappture::Tooltip::tooltip show $c +$tx,+$ty   
     2553
     2554    # Show the tooltip
     2555    Rappture::Tooltip::tooltip show $c +$tx,+$ty
    23232556}
    23242557
     
    23542587
    23552588#
    2356 # ReceiveLegend -- 
    2357 #
    2358 #       Invoked automatically whenever the "legend" command comes in from
    2359 #       the rendering server.  Indicates that binary image data with the
    2360 #       specified <size> will follow.
     2589# ReceiveLegend --
     2590#
     2591#   Invoked automatically whenever the "legend" command comes in from
     2592#   the rendering server.  Indicates that binary image data with the
     2593#   specified <size> will follow.
    23612594#
    23622595itcl::body Rappture::VtkIsosurfaceViewer::ReceiveLegend { colormap title min max size } {
    2363     #puts stderr "ReceiveLegend colormap=$colormap title=$title range=$min,$max size=$size"
     2596    # puts stderr "ReceiveLegend colormap=$colormap title=$title range=$min,$max size=$size"
    23642597    set _title $title
    2365     regsub {\(mag\)} $title "" _title 
     2598    regsub {\(mag\)} $title "" _title
    23662599    if { [IsConnected] } {
    23672600        set bytes [ReceiveBytes $size]
     
    23722605        #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
    23732606        if { [catch {DrawLegend} errs] != 0 } {
    2374             global errorInfo
    2375             puts stderr "errs=$errs errorInfo=$errorInfo"
     2607            global errorInfo
     2608            puts stderr "errs=$errs errorInfo=$errorInfo"
    23762609        }
    23772610    }
     
    23812614# DrawLegend --
    23822615#
    2383 #       Draws the legend in the own canvas on the right side of the plot area.
     2616#       Draws the legend on the canvas on the right side of the plot area.
    23842617#
    23852618itcl::body Rappture::VtkIsosurfaceViewer::DrawLegend {} {
     
    23922625
    23932626    if { [string match "component*" $fname] } {
    2394         set title ""
     2627        set title ""
    23952628    } else {
    2396         if { [info exists _fields($fname)] } {
    2397             foreach { title units } $_fields($fname) break
    2398             if { $units != "" } {
    2399                 set title [format "%s (%s)" $title $units]
    2400             }
    2401         } else {
    2402             set title $fname
    2403         }
     2629        if { [info exists _fields($fname)] } {
     2630            foreach { title units } $_fields($fname) break
     2631            if { $units != "" } {
     2632                set title [format "%s (%s)" $title $units]
     2633            }
     2634        } else {
     2635            set title $fname
     2636        }
    24042637    }
    24052638    set x [expr $w - 2]
    24062639    if { !$_settings(-legendvisible) } {
    2407         $c delete legend
    2408         return
    2409     } 
     2640        $c delete legend
     2641        return
     2642    }
    24102643    if { [$c find withtag "legend"] == "" } {
    2411         set y 2
    2412         # If there's a legend title, create a text item for the title.
     2644        set y 2
     2645        # If there's a legend title, create a text item for the title.
    24132646        $c create text $x $y \
    2414             -anchor ne \
    2415             -fill $itk_option(-plotforeground) -tags "title legend" \
    2416             -font $font
     2647            -anchor ne \
     2648            -fill $itk_option(-plotforeground) -tags "title legend" \
     2649            -font $font
    24172650        if { $title != "" } {
    24182651            incr y $lineht
    24192652        }
    2420         $c create text $x $y \
    2421             -anchor ne \
    2422             -fill $itk_option(-plotforeground) -tags "vmax legend" \
    2423             -font $font
    2424         incr y $lineht
    2425         $c create image $x $y \
    2426             -anchor ne \
    2427             -image $_image(legend) -tags "colormap legend"
    2428         $c create rectangle $x $y 1 1 \
    2429             -fill "" -outline "" -tags "sensor legend"
    2430         $c create text $x [expr {$h-2}] \
    2431             -anchor se \
    2432             -fill $itk_option(-plotforeground) -tags "vmin legend" \
    2433             -font $font
    2434         $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y]
    2435         $c bind sensor <Leave> [itcl::code $this LeaveLegend]
    2436         $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y]
     2653        $c create text $x $y \
     2654            -anchor ne \
     2655            -fill $itk_option(-plotforeground) -tags "vmax legend" \
     2656            -font $font
     2657        incr y $lineht
     2658        $c create image $x $y \
     2659            -anchor ne \
     2660            -image $_image(legend) -tags "colormap legend"
     2661        $c create rectangle $x $y 1 1 \
     2662            -fill "" -outline "" -tags "sensor legend"
     2663        $c create text $x [expr {$h-2}] \
     2664            -anchor se \
     2665            -fill $itk_option(-plotforeground) -tags "vmin legend" \
     2666            -font $font
     2667        $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y]
     2668        $c bind sensor <Leave> [itcl::code $this LeaveLegend]
     2669        $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y]
     2670        $c bind sensor <ButtonPress-1>   [itcl::code $this LegendB1Motion press %x %y]
     2671#        $c bind sensor <B1-Motion>       [itcl::code $this LegendB1Motion motion %x %y]
     2672        $c bind sensor <ButtonRelease-1> [itcl::code $this LegendB1Motion release %x %y]
     2673
    24372674    }
    24382675    $c delete isoline
     
    24472684         $_settings(-numcontours) > 0 } {
    24482685
    2449         foreach { vmin vmax } $_limits($_curFldName) break
     2686        if { $_settings(-customrange) } {
     2687            set vmin $_settings(-customrangevmin)
     2688            set vmax $_settings(-customrangevmax)
     2689        } else {
     2690            foreach { vmin vmax } $_limits($_curFldName) break
     2691        }
    24502692        set range [expr double($vmax - $vmin)]
    24512693        if { $range <= 0.0 } {
     
    24532695        }
    24542696        set tags "isoline legend"
    2455         set offset [expr 2 + $lineht]
    2456         if { $title != "" } {
    2457             incr offset $lineht
    2458         }
     2697        set offset [expr 2 + $lineht]
     2698        if { $title != "" } {
     2699            incr offset $lineht
     2700        }
    24592701        foreach value $_contourList(values) {
    24602702            set norm [expr 1.0 - (($value - $vmin) / $range)]
     
    24682710    }
    24692711
    2470     $c bind title <ButtonPress> [itcl::code $this Combo post]
    2471     $c bind title <Enter> [itcl::code $this Combo activate]
    2472     $c bind title <Leave> [itcl::code $this Combo deactivate]
     2712    $c bind title <ButtonPress> [itcl::code $this LegendTitleAction post]
     2713    $c bind title <Enter> [itcl::code $this LegendTitleAction enter]
     2714    $c bind title <Leave> [itcl::code $this LegendTitleAction leave]
    24732715    # Reset the item coordinates according the current size of the plot.
    24742716    $c itemconfigure title -text $title
    24752717    if { [info exists _limits($_curFldName)] } {
    2476         foreach { vmin vmax } $_limits($_curFldName) break
    2477         $c itemconfigure vmin -text [format %g $vmin]
    2478         $c itemconfigure vmax -text [format %g $vmax]
     2718        if { $_settings(-customrange) } {
     2719            set vmin $_settings(-customrangevmin)
     2720            set vmax $_settings(-customrangevmax)
     2721        } else {
     2722            foreach { vmin vmax } $_limits($_curFldName) break
     2723        }
     2724        $c itemconfigure vmin -text [format %g $vmin]
     2725        $c itemconfigure vmax -text [format %g $vmax]
    24792726    }
    24802727    set y 2
     
    24822729    if { $title != "" } {
    24832730        $c itemconfigure title -text $title
    2484         $c coords title $x $y
    2485         incr y $lineht
     2731        $c coords title $x $y
     2732        incr y $lineht
    24862733        $c raise title
    24872734    }
     
    24922739    $c raise sensor
    24932740    $c coords vmin $x [expr {$h - 2}]
    2494 }
    2495 
    2496 # ----------------------------------------------------------------------
    2497 # USAGE: _dropdown post
    2498 # USAGE: _dropdown unpost
    2499 # USAGE: _dropdown select
    2500 #
    2501 # Used internally to handle the dropdown list for this combobox.  The
    2502 # post/unpost options are invoked when the list is posted or unposted
    2503 # to manage the relief of the controlling button.  The select option
    2504 # is invoked whenever there is a selection from the list, to assign
    2505 # the value back to the gauge.
    2506 # ----------------------------------------------------------------------
    2507 itcl::body Rappture::VtkIsosurfaceViewer::Combo {option} {
    2508     set c $itk_component(view)
     2741
     2742    $c bind vmin <ButtonPress> [itcl::code $this LegendRangeAction popup vmin]
     2743    $c bind vmin <Enter> [itcl::code $this LegendRangeAction enter vmin]
     2744    $c bind vmin <Leave> [itcl::code $this LegendRangeAction leave vmin]
     2745
     2746    $c bind vmax <ButtonPress> [itcl::code $this LegendRangeAction popup vmax]
     2747    $c bind vmax <Enter> [itcl::code $this LegendRangeAction enter vmax]
     2748    $c bind vmax <Leave> [itcl::code $this LegendRangeAction leave vmax]
     2749}
     2750
     2751# ----------------------------------------------------------------------
     2752# USAGE: LegendTitleAction post
     2753# USAGE: LegendTitleAction enter
     2754# USAGE: LegendTitleAction leave
     2755# USAGE: LegendTitleAction save
     2756#
     2757# Used internally to handle the dropdown list for the fields menu combobox.
     2758# The post option is invoked when the field title is pressed to launch the
     2759# dropdown. The enter option is invoked when the user mouses over the field
     2760# title. The leave option is invoked when the user moves the mouse away
     2761# from the field title.  The save option is invoked whenever there is a
     2762# selection from the list, to alert the visualization server.
     2763#
     2764# ----------------------------------------------------------------------
     2765itcl::body Rappture::VtkIsosurfaceViewer::LegendTitleAction {option} {
     2766    set c $itk_component(view)
    25092767    switch -- $option {
    25102768        post {
     
    25172775            tk_popup $itk_component(fieldmenu) $x $y
    25182776        }
    2519         activate {
     2777        enter {
    25202778            $c itemconfigure title -fill red
    25212779        }
    2522         deactivate {
    2523             $c itemconfigure title -fill $itk_option(-plotforeground) 
    2524         }
    2525         invoke {
     2780        leave {
     2781            $c itemconfigure title -fill $itk_option(-plotforeground)
     2782        }
     2783        save {
    25262784            $itk_component(field) value $_curFldLabel
    25272785            AdjustSetting -field
    25282786        }
    25292787        default {
    2530             error "bad option \"$option\": should be post, unpost, select"
     2788            error "bad option \"$option\": should be post, enter, leave, save"
     2789        }
     2790    }
     2791}
     2792
     2793# ----------------------------------------------------------------------
     2794# USAGE: LegendRangeAction enter <which>
     2795# USAGE: LegendRangeAction leave <which>
     2796#
     2797# USAGE: LegendTitleAction popup <which>
     2798# USAGE: LegendTitleAction activate
     2799# USAGE: LegendTitleAction validate <value>
     2800# USAGE: LegendTitleAction apply <value>
     2801#
     2802# Used internally to handle the mouseover and popup entry for the field range
     2803# inputs.  The enter option is invoked when the user moves the mouse over the
     2804# min or max field range. The leave option is invoked when the user moves the
     2805# mouse away from the min or max field range. The popup option is invoked when
     2806# the user click's on a field range. The popup option stores internally which
     2807# widget is requesting a popup ( in the _mouseOver variable) and calls the
     2808# activate command of the widget. The widget's activate command calls back to
     2809# this method to get the xywh dimensions of the popup editor. After the user
     2810# changes focus or sets the value in the editor, the editor calls this methods
     2811# validate and apply options to set the value.
     2812#
     2813# ----------------------------------------------------------------------
     2814itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeAction {option args} {
     2815    set c $itk_component(view)
     2816# FIXME: check $which for valid values
     2817    switch -- $option {
     2818        enter {
     2819            set which [lindex $args 0]
     2820            $c itemconfigure $which -fill red
     2821        }
     2822        leave {
     2823            set which [lindex $args 0]
     2824            $c itemconfigure $which -fill $itk_option(-plotforeground)
     2825        }
     2826        popup {
     2827            DisableMouseRotationBindings
     2828            set which [lindex $args 0]
     2829            set _mouseOver $which
     2830            $itk_component(editor) activate
     2831        }
     2832        activate {
     2833            foreach { x1 y1 x2 y2 } [$c bbox $_mouseOver] break
     2834            set info(text) $_settings(-customrange$_mouseOver)
     2835            set info(x) [expr $x1 + [winfo rootx $c]]
     2836            set info(y) [expr $y1 + [winfo rooty $c]]
     2837            set info(w) [expr $x2 - $x1]
     2838            set info(h) [expr $y2 - $y1]
     2839            return [array get info]
     2840        }
     2841        validate {
     2842            if {[llength $args] != 1} {
     2843                error "wrong # args: should be \"editor validate value\""
     2844            }
     2845            SetupMouseRotationBindings
     2846        }
     2847        apply {
     2848            if {[llength $args] != 1} {
     2849                error "wrong # args: should be \"editor apply value\""
     2850            }
     2851            set _settings(-customrange$_mouseOver) [lindex $args 0]
     2852            $itk_component(crange) select
     2853            AdjustSetting -range
     2854        }
     2855        default {
     2856            error "bad option \"$option\": should be enter, leave, activate, validate, apply"
    25312857        }
    25322858    }
     
    25392865    # Keep track of the colormaps that we build.
    25402866    if { ![info exists _colormaps($name)] } {
    2541         BuildColormap $name 
     2867        BuildColormap $name
    25422868        set _colormaps($name) 1
    25432869    }
     
    25612887}
    25622888
    2563 itcl::body Rappture::VtkIsosurfaceViewer::SetOrientation { side } { 
     2889itcl::body Rappture::VtkIsosurfaceViewer::SetOrientation { side } {
    25642890    array set positions {
    25652891        front "1 0 0 0"
     
    25822908}
    25832909
    2584 itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} { 
     2910itcl::body Rappture::VtkIsosurfaceViewer::GenerateContourList {} {
    25852911    if { ![info exists _limits($_curFldName)] } {
    25862912        puts stderr "no _curFldName"
     
    25952921        set values $_contourList(reqValues)
    25962922    } else {
     2923        # use the field limits to calculate the contour list values
    25972924        foreach { vmin vmax } $_limits($_curFldName) break
     2925
     2926        # if custom range has been set and are within the field's
     2927        # range, use the custom min and max to generate contour list values
     2928        if { $_settings(-customrange) } {
     2929            if { $_settings(-customrangevmin) > $vmin } {
     2930                set vmin $_settings(-customrangevmin)
     2931            }
     2932            if { $_settings(-customrangevmax) < $vmax } {
     2933                set vmax $_settings(-customrangevmax)
     2934            }
     2935        }
     2936
    25982937        set v [blt::vector create \#auto]
    25992938        $v seq $vmin $vmax [expr $_contourList(numLevels)+2]
     
    26052944}
    26062945
    2607 itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentFieldName { dataobj } { 
     2946itcl::body Rappture::VtkIsosurfaceViewer::SetCurrentFieldName { dataobj } {
    26082947    set _first $dataobj
    26092948    $itk_component(field) choices delete 0 end
     
    26252964                -activeforeground $itk_option(-plotforeground) \
    26262965                -font "Arial 8" \
    2627                 -command [itcl::code $this Combo invoke]
     2966                -command [itcl::code $this LegendTitleAction save]
    26282967            set _fields($fname) [list $label $units $components]
    26292968            if { $_curFldName == "" } {
Note: See TracChangeset for help on using the changeset viewer.