Changeset 5054


Ignore:
Timestamp:
Mar 3, 2015 7:23:20 AM (9 years ago)
Author:
dkearney
Message:

merging vtkisosurface and gauge widget updates from uvv branch to trunk

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/gui/scripts/gauge.tcl

    r3733 r5054  
    4242    itk_option define -sampleheight sampleHeight SampleHeight 0
    4343    itk_option define -log log Log ""
     44    itk_option define -validatecommand validateCommand ValidateCommand ""
    4445
    4546    constructor {args} { # defined below }
     
    236237            }
    237238            real {
    238                 # "scan" will reject the number if the string is "NaN" or
    239                 # "Inf" or the empty string.  It also is accepts large numbers
    240                 # (e.g. 111111111111111111111) that "string is double"
    241                 # rejects.  The problem with "scan" is that it doesn't care if
    242                 # there are extra characters trailing the number (eg. "123a").
    243                 # The extra %s substitution is used to detect this case.
     239                # "scan" will reject the number if the string is "NaN" or
     240                # "Inf" or the empty string.  It also is accepts large numbers
     241                # (e.g. 111111111111111111111) that "string is double"
     242                # rejects.  The problem with "scan" is that it doesn't care if
     243                # there are extra characters trailing the number (eg. "123a").
     244                # The extra %s substitution is used to detect this case.
    244245                if { [scan $nv "%g%s" dummy1 dummy2] != 1 } {
    245246                    error "bad value \"$nv\": should be a real number"
     
    288289                error "maximum value allowed here is $convMaxVal"
    289290            }
     291        }
     292
     293        #
     294        # If there's a -validatecommand option, then invoke the code
     295        # now to check the new value.
     296        #
     297        if {[string length $itk_option(-validatecommand)] > 0} {
     298            set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $newval]]"
     299            set result [eval $cmd]
    290300        }
    291301
  • trunk/gui/scripts/vtkisosurfaceviewer.tcl

    r4993 r5054  
    9494    private method LegendProbeSingleContour { x y }
    9595    private method LegendRangeAction { option args }
     96    private method LegendRangeValidate { widget which value }
    9697    private method LegendTitleAction { option }
    9798    private method MotionLegend { x y }
     99    private method MouseOver2Which {}
    98100    private method Pan {option x y}
    99101    private method PanCamera {}
     
    111113    private method SetCurrentFieldName { dataobj }
    112114    private method SetLegendTip { x y }
     115    private method SetMinMaxGauges { min max }
    113116    private method SetObjectStyle { dataobj comp }
    114117    private method SetOrientation { side }
     
    117120    private method SetupKeyboardBindings {}
    118121    private method Slice {option args}
     122    private method ToggleCustomRange { args }
    119123    private method ViewToQuaternion {} {
    120124        return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)]
     
    172176
    173177    private variable _mouseOver "";     # what called LegendRangeAction, vmin or vmax
     178    private variable _customRangeClick 1;   # what called ToggleCustomRange
    174179}
    175180
     
    258263        -colormapvisible            1
    259264        -customrange                0
    260         -customrangevmin            0
    261         -customrangevmax            1
     265        -customrangemin             0
     266        -customrangemax             1
    262267        -cutplaneedges              0
    263268        -cutplanelighting           1
     
    775780                # customrangevmin and customrangevmax
    776781                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                 }
     782                SetMinMaxGauges $min $max
     783                set _settings(-customrangemin) $min
     784                set _settings(-customrangemax) $max
    783785
    784786                continue
     
    786788            foreach {min max} $lim break
    787789            foreach {fmin fmax} $_limits($fname) break
    788 #            if { $fname == $_curFldName && ! $_settings(-customrange) } {}
    789790            if { ! $_settings(-customrange) } {
    790                 set _settings(-customrangevmin) $fmin
    791                 set _settings(-customrangevmax) $fmax
     791                SetMinMaxGauges $fmin $fmax
    792792            }
    793793            if { $fmin > $min } {
     
    11171117            -isosurfacelighting \
    11181118            -field \
     1119            -range \
    11191120            -isosurfacevisible \
    11201121            -isosurfaceedges -isosurfacelighting -isosurfaceopacity \
     
    14911492                SendCmd "dataset maprange all"
    14921493            } else {
    1493                 foreach { vmin vmax } $_limits($_curFldName) break
    14941494                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                     }
     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                    SetMinMaxGauges $vmin $vmax
    15011503                }
    15021504                SendCmd "dataset maprange explicit $vmin $vmax $_curFldName"
     
    15761578        }
    15771579        "-range" {
    1578             foreach { vmin vmax } $_limits($_curFldName) break
    15791580            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                 }
     1581                set vmin [$itk_component(min) value]
     1582                set vmax [$itk_component(max) value]
    16041583            } 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
     1584                foreach { vmin vmax } $_limits($_curFldName) break
    16091585            }
    16101586            GenerateContourList
     
    18371813            -text "Use Custom Range:" \
    18381814            -variable [itcl::scope _settings(-customrange)] \
    1839             -command [itcl::code $this AdjustSetting -range] \
     1815            -command [itcl::code $this ToggleCustomRange] \
    18401816            -font "Arial 9"
    18411817    }
     
    18451821    }
    18461822    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> \
     1823        Rappture::Gauge $inner.min \
     1824            -validatecommand [itcl::code $this LegendRangeValidate "" vmin]
     1825    }
     1826    bind $itk_component(min) <<Value>> \
    18551827        [itcl::code $this AdjustSetting -range]
    18561828
     
    18591831    }
    18601832    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> \
     1833        Rappture::Gauge $inner.max \
     1834            -validatecommand [itcl::code $this LegendRangeValidate "" vmax]
     1835    }
     1836    bind $itk_component(max) <<Value>> \
    18691837        [itcl::code $this AdjustSetting -range]
    18701838
     
    24682436    if { [info exists _limits($fname)] } {
    24692437        if { $_settings(-customrange) } {
    2470             set vmin $_settings(-customrangevmin)
    2471             set vmax $_settings(-customrangevmax)
     2438            set vmin [$itk_component(min) value]
     2439            set vmax [$itk_component(max) value]
    24722440        } else {
    24732441            foreach { vmin vmax } $_limits($fname) break
     
    26682636        $c bind sensor <Leave> [itcl::code $this LeaveLegend]
    26692637        $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y]
    2670         $c bind sensor <ButtonPress-1>   [itcl::code $this LegendB1Motion press %x %y]
     2638#        $c bind sensor <ButtonPress-1>   [itcl::code $this LegendB1Motion press %x %y]
    26712639#        $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]
     2640#        $c bind sensor <ButtonRelease-1> [itcl::code $this LegendB1Motion release %x %y]
    26732641
    26742642    }
     
    26852653
    26862654        if { $_settings(-customrange) } {
    2687             set vmin $_settings(-customrangevmin)
    2688             set vmax $_settings(-customrangevmax)
     2655            set vmin [$itk_component(min) value]
     2656            set vmax [$itk_component(max) value]
    26892657        } else {
    26902658            foreach { vmin vmax } $_limits($_curFldName) break
     
    27172685    if { [info exists _limits($_curFldName)] } {
    27182686        if { $_settings(-customrange) } {
    2719             set vmin $_settings(-customrangevmin)
    2720             set vmax $_settings(-customrangevmax)
     2687            set vmin [$itk_component(min) value]
     2688            set vmax [$itk_component(max) value]
    27212689        } else {
    27222690            foreach { vmin vmax } $_limits($_curFldName) break
     
    27922760
    27932761# ----------------------------------------------------------------------
     2762# USAGE: LegendRangeValidate <widget> <which> <value>
     2763#
     2764# Used internally to validate a legend range min/max value.
     2765# Returns a boolean value telling if <value> was accepted (1) or rejected (0)
     2766# If the value is rejected, a tooltip/warning message is popped up
     2767# near the widget that asked for the validation, specified by <widget>
     2768#
     2769# <widget> is the widget where a tooltip/warning message should show up on
     2770# <which> is either "vmin" or "vmax".
     2771# <value> is the value to be validated.
     2772#
     2773# ----------------------------------------------------------------------
     2774itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeValidate {widget which value} {
     2775
     2776    #check for a valid value
     2777    if {[string is double $value] != 1} {
     2778        set msg "should be valid number"
     2779        if {$widget != ""} {
     2780            Rappture::Tooltip::cue $widget $msg
     2781        } else {
     2782            # error "bad value \"$value\": $msg"
     2783            error $msg
     2784        }
     2785        return 0
     2786    }
     2787
     2788    switch -- $which {
     2789        vmin {
     2790            # check for min > max
     2791            if {$value > [$itk_component(max) value]} {
     2792                set msg "min > max, change max first"
     2793                if {$widget != ""} {
     2794                    Rappture::Tooltip::cue $widget $msg
     2795                } else {
     2796                    # error "bad value \"$value\": $msg"
     2797                    error $msg
     2798                }
     2799                return 0
     2800            }
     2801        }
     2802        vmax {
     2803            # check for max < min
     2804            if {$value < [$itk_component(min) value]} {
     2805                set msg "max < min, change min first"
     2806                if {$widget != ""} {
     2807                    Rappture::Tooltip::cue $widget $msg
     2808                } else {
     2809                    # error "bad value \"$value\": $msg"
     2810                    error $msg
     2811                }
     2812                return 0
     2813            }
     2814        }
     2815        default {
     2816            error "bad option \"$which\": should be vmin, vmax"
     2817        }
     2818    }
     2819}
     2820
     2821
     2822itcl::body Rappture::VtkIsosurfaceViewer::MouseOver2Which {} {
     2823    switch -- $_mouseOver {
     2824        vmin {
     2825            set which min
     2826        }
     2827        vmax {
     2828            set which max
     2829        }
     2830        default {
     2831            error "bad _mouseOver \"$_mouseOver\": should be vmin, vmax"
     2832        }
     2833    }
     2834    return $which
     2835}
     2836
     2837
     2838# ----------------------------------------------------------------------
    27942839# USAGE: LegendRangeAction enter <which>
    27952840# USAGE: LegendRangeAction leave <which>
    27962841#
    2797 # USAGE: LegendTitleAction popup <which>
    2798 # USAGE: LegendTitleAction activate
    2799 # USAGE: LegendTitleAction validate <value>
    2800 # USAGE: LegendTitleAction apply <value>
     2842# USAGE: LegendRangeAction popup <which>
     2843# USAGE: LegendRangeAction activate
     2844# USAGE: LegendRangeAction validate <value>
     2845# USAGE: LegendRangeAction apply <value>
    28012846#
    28022847# Used internally to handle the mouseover and popup entry for the field range
     
    28142859itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeAction {option args} {
    28152860    set c $itk_component(view)
    2816 # FIXME: check $which for valid values
     2861
    28172862    switch -- $option {
    28182863        enter {
     
    28322877        activate {
    28332878            foreach { x1 y1 x2 y2 } [$c bbox $_mouseOver] break
    2834             set info(text) $_settings(-customrange$_mouseOver)
     2879            set which [MouseOver2Which]
     2880            set info(text) [$itk_component($which) value]
    28352881            set info(x) [expr $x1 + [winfo rootx $c]]
    28362882            set info(y) [expr $y1 + [winfo rooty $c]]
     
    28432889                error "wrong # args: should be \"editor validate value\""
    28442890            }
     2891
     2892            set value [lindex $args 0]
     2893            if {[LegendRangeValidate $itk_component(editor) $_mouseOver $value] == 0} {
     2894                return 0
     2895            }
     2896
     2897            # value was good, apply it
     2898            # reset the mouse rotation bindings
    28452899            SetupMouseRotationBindings
    28462900        }
     
    28492903                error "wrong # args: should be \"editor apply value\""
    28502904            }
    2851             set _settings(-customrange$_mouseOver) [lindex $args 0]
    2852             $itk_component(crange) select
    2853             AdjustSetting -range
     2905            set value [string trim [lindex $args 0]]
     2906
     2907            set which [MouseOver2Which]
     2908
     2909            # only set custom range if value changed
     2910            if {[$itk_component($which) value] != $value} {
     2911                # set the flag stating the custom range came from the legend
     2912                # change the value in the gauge
     2913                # turn on crange to enable the labels and gauges
     2914                # call AdjustSetting -range (inside ToggleCustomRange)
     2915                # to update drawing and legend
     2916                set _customRangeClick 0
     2917                $itk_component($which) value $value
     2918                $itk_component(crange) select
     2919                ToggleCustomRange
     2920            }
    28542921        }
    28552922        default {
     
    28582925    }
    28592926}
     2927
     2928
     2929# ----------------------------------------------------------------------
     2930# USAGE: ToggleCustomRange
     2931#
     2932# Called whenever the custom range is turned on or off. Used to save
     2933# the custom min and custom max set by the user. When the -customrange
     2934# setting is turned on, the range min and range max gauges are set
     2935# with the last value set by the user, or the default range if no
     2936# previous min and max were set.
     2937#
     2938# When the custom range is turned on, we check how it was turned on
     2939# by querying _customRangeClick. If the variable is 1, this means
     2940# the user clicked the crange checkbutton and we should pull the
     2941# custom range values from our backup variables. If the variable is 0,
     2942# the custom range was enabled through the user manipulating the
     2943# min and max value in the legend.
     2944#
     2945# ----------------------------------------------------------------------
     2946itcl::body Rappture::VtkIsosurfaceViewer::ToggleCustomRange {args} {
     2947    if { ! $_settings(-customrange) } {
     2948        # custom range was turned off
     2949
     2950        # disable the min/max labels and gauge widgets
     2951        $itk_component(l_min) configure -state disabled
     2952        $itk_component(min) configure -state disabled
     2953        $itk_component(l_max) configure -state disabled
     2954        $itk_component(max) configure -state disabled
     2955
     2956        # backup the custom range
     2957        set _settings(-customrangemin) [$itk_component(min) value]
     2958        set _settings(-customrangemax) [$itk_component(max) value]
     2959
     2960        # set the gauges to dataset's min and max
     2961        foreach { vmin vmax } $_limits($_curFldName) break
     2962        SetMinMaxGauges $vmin $vmax
     2963    } else {
     2964        # custom range was turned on
     2965
     2966        # enable the min/max labels and gauge widgets
     2967        $itk_component(l_min) configure -state normal
     2968        $itk_component(min) configure -state normal
     2969        $itk_component(l_max) configure -state normal
     2970        $itk_component(max) configure -state normal
     2971
     2972        # if the custom range is being turned on by clicking the
     2973        # checkbox, restore the min and max gauges from the backup
     2974        # variables. otherwise, new values for the min and max
     2975        # widgets will be set later from the legend's editor.
     2976        if { $_customRangeClick } {
     2977            SetMinMaxGauges $_settings(-customrangemin) $_settings(-customrangemax)
     2978        }
     2979
     2980        # reset the click flag
     2981        set _customRangeClick 1
     2982    }
     2983    AdjustSetting -range
     2984}
     2985
     2986
     2987# ----------------------------------------------------------------------
     2988# USAGE: SetMinMaxGauges <min> <max>
     2989#
     2990# Set the min and max gauges in the correct order, avoiding the
     2991# error where you try to set the min > max before updating the max or
     2992# set the max < min before updating the min.
     2993#
     2994# There are five range cases to consider with our current range validation.
     2995# For example:
     2996# [2,3] -> [0,1]       : update min first, max last
     2997# [2,3] -> [4,5]       : update max first, min last
     2998# [2,3] -> [0,2.5]     : update min or max first
     2999# [2,3] -> [2.5,5]     : update min or max first
     3000# [2,3] -> [2.25,2.75] : update min or max first
     3001#
     3002# In 4 of the cases we can update min first and max last, so we only
     3003# need to check the case where old max < new min, where we update
     3004# max first and min last.
     3005# ----------------------------------------------------------------------
     3006itcl::body Rappture::VtkIsosurfaceViewer::SetMinMaxGauges {min max} {
     3007
     3008    if { [$itk_component(max) value] < $min} {
     3009        # old max < new min
     3010        # shift range toward right
     3011        # extend max first, then update min
     3012        $itk_component(max) value $max
     3013        $itk_component(min) value $min
     3014    } else {
     3015        # extend min first, then update max
     3016        $itk_component(min) value $min
     3017        $itk_component(max) value $max
     3018    }
     3019}
     3020
    28603021
    28613022#
     
    29273088        # range, use the custom min and max to generate contour list values
    29283089        if { $_settings(-customrange) } {
    2929             if { $_settings(-customrangevmin) > $vmin } {
    2930                 set vmin $_settings(-customrangevmin)
    2931             }
    2932             if { $_settings(-customrangevmax) < $vmax } {
    2933                 set vmax $_settings(-customrangevmax)
     3090            if { [$itk_component(min) value] > $vmin } {
     3091                set vmin [$itk_component(min) value]
     3092            }
     3093            if { [$itk_component(max) value] < $vmax } {
     3094                set vmax [$itk_component(max) value]
    29343095            }
    29353096        }
Note: See TracChangeset for help on using the changeset viewer.