Changeset 5049


Ignore:
Timestamp:
Feb 26, 2015 1:10:41 PM (6 years ago)
Author:
dkearney
Message:

in the vtk isosurface viewer, fixing bugs related to trying to set the min and
max gauges at the same time with input validation.

included a SetMinMaxGauges? method to handle figuring out if we should set the
min value first or the max value first to avoid input validation errors. also
added the ToggleCustomRange? method to help handle syncing the min/max text in
the legend around the colormap and the gauge widgets in the Isosurface Settings
tab. the gauges can lag in being updated with switching between viewing fields.
added -customrangemin and -customrangemax temp variables to the settings array
to hold a backup of the custom range values set by the user, so they don't get
deleted after we turn off the -customrange flag.

removed checks to see if the custom range was within the range of the data when
the following methods are called:

AdjustSetting? -field
AdjustSetting? -range

I couldn't figure out why the checks were needed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/uiuc_vtk_viewers/gui/scripts/vtkisosurfaceviewer.tcl

    r5033 r5049  
    113113    private method SetCurrentFieldName { dataobj }
    114114    private method SetLegendTip { x y }
     115    private method SetMinMaxGauges { min max }
    115116    private method SetObjectStyle { dataobj comp }
    116117    private method SetOrientation { side }
     
    119120    private method SetupKeyboardBindings {}
    120121    private method Slice {option args}
     122    private method ToggleCustomRange { args }
    121123    private method ViewToQuaternion {} {
    122124        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
     
    174176
    175177    private variable _mouseOver "";     # what called LegendRangeAction, vmin or vmax
     178    private variable _customRangeClick 1;   # what called ToggleCustomRange
     179    private variable _ignoreRangeUpdate 0;  # update min/max gauges without redrawing
    176180}
    177181
     
    260264        -colormapvisible            1
    261265        -customrange                0
     266        -customrangemin             0
     267        -customrangemax             1
    262268        -cutplaneedges              0
    263269        -cutplanelighting           1
     
    775781                # customrangevmin and customrangevmax
    776782                foreach {min max} $lim break
    777                 $itk_component(min) value $min
    778                 $itk_component(max) value $max
     783                SetMinMaxGauges $min $max
     784                set _settings(-customrangemin) $min
     785                set _settings(-customrangemax) $max
    779786
    780787                continue
     
    783790            foreach {fmin fmax} $_limits($fname) break
    784791            if { ! $_settings(-customrange) } {
    785                 $itk_component(min) value $fmin
    786                 $itk_component(max) value $fmax
     792                SetMinMaxGauges $fmin $fmax
    787793            }
    788794            if { $fmin > $min } {
     
    14861492                SendCmd "dataset maprange all"
    14871493            } else {
    1488                 foreach { vmin vmax } $_limits($_curFldName) break
    14891494                if { $_settings(-customrange) } {
    1490                     if { [$itk_component(min) value] > $vmin } {
    1491                         set vmin [$itk_component(min) value]
    1492                     }
    1493                     if { [$itk_component(max) value] < $vmax } {
    1494                         set vmax [$itk_component(max) value]
    1495                     }
     1495                    set vmin [$itk_component(min) value]
     1496                    set vmax [$itk_component(max) value]
     1497                } else {
     1498                    foreach { vmin vmax } $_limits($_curFldName) break
     1499                    # set the min / max gauges with limits from the field
     1500                    # the legend's min and max text will be updated
     1501                    # when the legend is redrawn in DrawLegend
     1502                    set _ignoreRangeUpdate 1
     1503                    SetMinMaxGauges $vmin $vmax
    14961504                }
    14971505                SendCmd "dataset maprange explicit $vmin $vmax $_curFldName"
     
    15711579        }
    15721580        "-range" {
    1573             foreach { vmin vmax } $_limits($_curFldName) break
    1574             if { $_settings(-customrange) } {
    1575                 $itk_component(l_min) configure -state normal
    1576                 $itk_component(min) configure -state normal
    1577                 $itk_component(l_max) configure -state normal
    1578                 $itk_component(max) configure -state normal
    1579                 if { [$itk_component(min) value] > $vmin } {
     1581            if { ! $_ignoreRangeUpdate } {
     1582                if { $_settings(-customrange) } {
    15801583                    set vmin [$itk_component(min) value]
    1581                 }
    1582                 if { [$itk_component(max) value] < $vmax } {
    15831584                    set vmax [$itk_component(max) value]
    1584                 }
    1585             } else {
    1586                 $itk_component(l_min) configure -state disabled
    1587                 $itk_component(min) configure -state disabled
    1588                 $itk_component(l_max) configure -state disabled
    1589                 $itk_component(max) configure -state disabled
    1590             }
    1591             GenerateContourList
    1592             SendCmd [list contour3d contourlist $_contourList(values)]
    1593             SendCmd "dataset maprange explicit $vmin $vmax $_curFldName"
    1594             DrawLegend
     1585                } else {
     1586                    foreach { vmin vmax } $_limits($_curFldName) break
     1587                }
     1588                GenerateContourList
     1589                SendCmd [list contour3d contourlist $_contourList(values)]
     1590                SendCmd "dataset maprange explicit $vmin $vmax $_curFldName"
     1591                DrawLegend
     1592            }
     1593            set _ignoreRangeUpdate 0
    15951594        }
    15961595        "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" {
     
    18181817            -text "Use Custom Range:" \
    18191818            -variable [itcl::scope _settings(-customrange)] \
    1820             -command [itcl::code $this AdjustSetting -range] \
    18211819            -font "Arial 9"
    18221820    }
     1821    # use a trace so we can adjust the value of our variable
     1822    # and still have the ToggleCustomRange command called,
     1823    # which doesn't seem to happen when using -command.
     1824    trace add variable _settings(-customrange) write \
     1825        [itcl::code $this ToggleCustomRange]
    18231826
    18241827    itk_component add l_min {
     
    29142917            # only set custom range if value changed
    29152918            if {[$itk_component($which) value] != $value} {
     2919                # turn on crange first to enable and update the gauge,
     2920                # then change the value in the gauge
     2921                set _customRangeClick 0
     2922                $itk_component(crange) select
    29162923                $itk_component($which) value $value
    2917                 $itk_component(crange) select
    2918             }
    2919             AdjustSetting -range
     2924            }
    29202925        }
    29212926        default {
    29222927            error "bad option \"$option\": should be enter, leave, activate, validate, apply"
    29232928        }
     2929    }
     2930}
     2931
     2932
     2933# ----------------------------------------------------------------------
     2934# USAGE: ToggleCustomRange
     2935#
     2936# Called whenever the custom range is turned on or off. Used to save
     2937# the custom min and custom max set by the user. When the -customrange
     2938# setting is turned on, the range min and range max gauges are set
     2939# with the last value set by the user, or the default range if no
     2940# previous min and max were set.
     2941#
     2942# When the custom range is turned on, we check how it was turned on
     2943# by querying _customRangeClick. If the variable is 1, this means
     2944# the user clicked the crange checkbutton and we should pull the
     2945# custom range values from our backup variables. If the variable is 0,
     2946# the custom range was enabled through the user manipulating the
     2947# min and max value in the legend.
     2948#
     2949# ----------------------------------------------------------------------
     2950itcl::body Rappture::VtkIsosurfaceViewer::ToggleCustomRange {args} {
     2951
     2952    if { ! $_settings(-customrange) } {
     2953        # custom range was turned off
     2954
     2955        # disable the min/max labels and gauge widgets
     2956        $itk_component(l_min) configure -state disabled
     2957        $itk_component(min) configure -state disabled
     2958        $itk_component(l_max) configure -state disabled
     2959        $itk_component(max) configure -state disabled
     2960
     2961        # backup the custom range
     2962        set _settings(-customrangemin) [$itk_component(min) value]
     2963        set _settings(-customrangemax) [$itk_component(max) value]
     2964
     2965        # set the gauges to dataset's min and max
     2966        foreach { vmin vmax } $_limits($_curFldName) break
     2967        SetMinMaxGauges $vmin $vmax
     2968    } else {
     2969        # custom range was turned on
     2970
     2971        # enable the min/max labels and gauge widgets
     2972        $itk_component(l_min) configure -state normal
     2973        $itk_component(min) configure -state normal
     2974        $itk_component(l_max) configure -state normal
     2975        $itk_component(max) configure -state normal
     2976
     2977        # if the custom range is being turned on by clicking the
     2978        # checkbox, restore the min and max gauges from the backup
     2979        # variables. otherwise, new values for the min and max
     2980        # widgets will be set later from the legend's editor.
     2981        if { $_customRangeClick } {
     2982            SetMinMaxGauges $_settings(-customrangemin) $_settings(-customrangemax)
     2983        }
     2984
     2985        # reset the click flag
     2986        set _customRangeClick 1
     2987    }
     2988    AdjustSetting -range
     2989}
     2990
     2991
     2992# ----------------------------------------------------------------------
     2993# USAGE: SetMinMaxGauges <min> <max>
     2994#
     2995# Set the min and max gauges in the correct order, avoiding the
     2996# error where you try to set the min > max before updating the max or
     2997# set the max < min before updating the min.
     2998#
     2999# There are five range cases to consider with our current range validation.
     3000# For example:
     3001# [2,3] -> [0,1]       : update min first, max last
     3002# [2,3] -> [4,5]       : update max first, min last
     3003# [2,3] -> [0,2.5]     : update min or max first
     3004# [2,3] -> [2.5,5]     : update min or max first
     3005# [2,3] -> [2.25,2.75] : update min or max first
     3006#
     3007# In 4 of the cases we can update min first and max last, so we only
     3008# need to check the case where old max < new min, where we update
     3009# max first and min last.
     3010# ----------------------------------------------------------------------
     3011itcl::body Rappture::VtkIsosurfaceViewer::SetMinMaxGauges {min max} {
     3012
     3013    if { [$itk_component(max) value] < $min} {
     3014        # old max < new min
     3015        # shift range toward right
     3016        # extend max first, then update min
     3017        $itk_component(max) value $max
     3018        $itk_component(min) value $min
     3019    } else {
     3020        # extend min first, then update max
     3021        $itk_component(min) value $min
     3022        $itk_component(max) value $max
    29243023    }
    29253024}
Note: See TracChangeset for help on using the changeset viewer.