Changeset 5033


Ignore:
Timestamp:
Feb 19, 2015 8:33:41 AM (6 years ago)
Author:
dkearney
Message:

adding a -validatecommand to gauge.tcl so people can add their own validation
to the widget

using gauge widgets for the min/max fields in the settings tab of the
isosurface viewer instead of entry widgets so we can take advantage of input
validation and tooltip cues. tied the min/max editor values, that are above and
below the legend colormap, to the min/max gauge widgets so they all change at
the same time and read the same values. I think there is still a problem if the
min equals the max value, the legend will still show the same value above and
below the colormap. there may also be a race condition when first setting the
min and max gauge widget values because validation occurs. if the data's min is
greater than the default max of 1 (not sure where this comes from yet) or if
the data max is less than the default min of 0 (not sure where this comes from
either) then an error will be raised.

Location:
branches/uiuc_vtk_viewers/gui/scripts
Files:
2 edited

Legend:

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

    r5032 r5033  
    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 }
     
    290291        }
    291292
     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]
     300        }
     301
    292302        if {$onlycheck} {
    293303            return
  • branches/uiuc_vtk_viewers/gui/scripts/vtkisosurfaceviewer.tcl

    r4992 r5033  
    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 {}
     
    258260        -colormapvisible            1
    259261        -customrange                0
    260         -customrangevmin            0
    261         -customrangevmax            1
    262262        -cutplaneedges              0
    263263        -cutplanelighting           1
     
    775775                # customrangevmin and customrangevmax
    776776                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                 }
     777                $itk_component(min) value $min
     778                $itk_component(max) value $max
    783779
    784780                continue
     
    786782            foreach {min max} $lim break
    787783            foreach {fmin fmax} $_limits($fname) break
    788 #            if { $fname == $_curFldName && ! $_settings(-customrange) } {}
    789784            if { ! $_settings(-customrange) } {
    790                 set _settings(-customrangevmin) $fmin
    791                 set _settings(-customrangevmax) $fmax
     785                $itk_component(min) value $fmin
     786                $itk_component(max) value $fmax
    792787            }
    793788            if { $fmin > $min } {
     
    14931488                foreach { vmin vmax } $_limits($_curFldName) break
    14941489                if { $_settings(-customrange) } {
    1495                     if { $_settings(-customrangevmin) > $vmin } {
    1496                         set vmin $_settings(-customrangevmin)
     1490                    if { [$itk_component(min) value] > $vmin } {
     1491                        set vmin [$itk_component(min) value]
    14971492                    }
    1498                     if { $_settings(-customrangevmax) < $vmax } {
    1499                         set vmax $_settings(-customrangevmax)
     1493                    if { [$itk_component(max) value] < $vmax } {
     1494                        set vmax [$itk_component(max) value]
    15001495                    }
    15011496                }
     
    15821577                $itk_component(l_max) configure -state normal
    15831578                $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)
     1579                if { [$itk_component(min) value] > $vmin } {
     1580                    set vmin [$itk_component(min) value]
     1581                }
     1582                if { [$itk_component(max) value] < $vmax } {
     1583                    set vmax [$itk_component(max) value]
    16031584                }
    16041585            } else {
     
    18451826    }
    18461827    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> \
     1828        Rappture::Gauge $inner.min \
     1829            -validatecommand [itcl::code $this LegendRangeValidate "" vmin]
     1830    }
     1831    bind $itk_component(min) <<Value>> \
    18551832        [itcl::code $this AdjustSetting -range]
    18561833
     
    18591836    }
    18601837    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> \
     1838        Rappture::Gauge $inner.max \
     1839            -validatecommand [itcl::code $this LegendRangeValidate "" vmax]
     1840    }
     1841    bind $itk_component(max) <<Value>> \
    18691842        [itcl::code $this AdjustSetting -range]
    18701843
     
    24682441    if { [info exists _limits($fname)] } {
    24692442        if { $_settings(-customrange) } {
    2470             set vmin $_settings(-customrangevmin)
    2471             set vmax $_settings(-customrangevmax)
     2443            set vmin [$itk_component(min) value]
     2444            set vmax [$itk_component(max) value]
    24722445        } else {
    24732446            foreach { vmin vmax } $_limits($fname) break
     
    26852658
    26862659        if { $_settings(-customrange) } {
    2687             set vmin $_settings(-customrangevmin)
    2688             set vmax $_settings(-customrangevmax)
     2660            set vmin [$itk_component(min) value]
     2661            set vmax [$itk_component(max) value]
    26892662        } else {
    26902663            foreach { vmin vmax } $_limits($_curFldName) break
     
    27172690    if { [info exists _limits($_curFldName)] } {
    27182691        if { $_settings(-customrange) } {
    2719             set vmin $_settings(-customrangevmin)
    2720             set vmax $_settings(-customrangevmax)
     2692            set vmin [$itk_component(min) value]
     2693            set vmax [$itk_component(max) value]
    27212694        } else {
    27222695            foreach { vmin vmax } $_limits($_curFldName) break
     
    27922765
    27932766# ----------------------------------------------------------------------
     2767# USAGE: LegendRangeValidate <widget> <which> <value>
     2768#
     2769# Used internally to validate a legend range min/max value.
     2770# Returns a boolean value telling if <value> was accepted (1) or rejected (0)
     2771# If the value is rejected, a tooltip/warning message is popped up
     2772# near the widget that asked for the validation, specified by <widget>
     2773#
     2774# <widget> is the widget where a tooltip/warning message should show up on
     2775# <which> is either "vmin" or "vmax".
     2776# <value> is the value to be validated.
     2777#
     2778# ----------------------------------------------------------------------
     2779itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeValidate {widget which value} {
     2780
     2781    #check for a valid value
     2782    if {[string is double $value] != 1} {
     2783        set msg "should be valid number"
     2784        if {$widget != ""} {
     2785            Rappture::Tooltip::cue $widget $msg
     2786        } else {
     2787            # error "bad value \"$value\": $msg"
     2788            error $msg
     2789        }
     2790        return 0
     2791    }
     2792
     2793    switch -- $which {
     2794        vmin {
     2795            # check for min > max
     2796            if {$value > [$itk_component(max) value]} {
     2797                set msg "min > max, change max first"
     2798                if {$widget != ""} {
     2799                    Rappture::Tooltip::cue $widget $msg
     2800                } else {
     2801                    # error "bad value \"$value\": $msg"
     2802                    error $msg
     2803                }
     2804                return 0
     2805            }
     2806        }
     2807        vmax {
     2808            # check for max < min
     2809            if {$value < [$itk_component(min) value]} {
     2810                set msg "max < min, change min first"
     2811                if {$widget != ""} {
     2812                    Rappture::Tooltip::cue $widget $msg
     2813                } else {
     2814                    # error "bad value \"$value\": $msg"
     2815                    error $msg
     2816                }
     2817                return 0
     2818            }
     2819        }
     2820        default {
     2821            error "bad option \"$which\": should be vmin, vmax"
     2822        }
     2823    }
     2824}
     2825
     2826
     2827itcl::body Rappture::VtkIsosurfaceViewer::MouseOver2Which {} {
     2828    switch -- $_mouseOver {
     2829        vmin {
     2830            set which min
     2831        }
     2832        vmax {
     2833            set which max
     2834        }
     2835        default {
     2836            error "bad _mouseOver \"$_mouseOver\": should be vmin, vmax"
     2837        }
     2838    }
     2839    return $which
     2840}
     2841
     2842
     2843# ----------------------------------------------------------------------
    27942844# USAGE: LegendRangeAction enter <which>
    27952845# USAGE: LegendRangeAction leave <which>
    27962846#
    2797 # USAGE: LegendTitleAction popup <which>
    2798 # USAGE: LegendTitleAction activate
    2799 # USAGE: LegendTitleAction validate <value>
    2800 # USAGE: LegendTitleAction apply <value>
     2847# USAGE: LegendRangeAction popup <which>
     2848# USAGE: LegendRangeAction activate
     2849# USAGE: LegendRangeAction validate <value>
     2850# USAGE: LegendRangeAction apply <value>
    28012851#
    28022852# Used internally to handle the mouseover and popup entry for the field range
     
    28142864itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeAction {option args} {
    28152865    set c $itk_component(view)
    2816 # FIXME: check $which for valid values
     2866
    28172867    switch -- $option {
    28182868        enter {
     
    28322882        activate {
    28332883            foreach { x1 y1 x2 y2 } [$c bbox $_mouseOver] break
    2834             set info(text) $_settings(-customrange$_mouseOver)
     2884            set which [MouseOver2Which]
     2885            set info(text) [$itk_component($which) value]
    28352886            set info(x) [expr $x1 + [winfo rootx $c]]
    28362887            set info(y) [expr $y1 + [winfo rooty $c]]
     
    28432894                error "wrong # args: should be \"editor validate value\""
    28442895            }
     2896
     2897            set value [lindex $args 0]
     2898            if {[LegendRangeValidate $itk_component(editor) $_mouseOver $value] == 0} {
     2899                return 0
     2900            }
     2901
     2902            # value was good, apply it
     2903            # reset the mouse rotation bindings
    28452904            SetupMouseRotationBindings
    28462905        }
     
    28492908                error "wrong # args: should be \"editor apply value\""
    28502909            }
    2851             set _settings(-customrange$_mouseOver) [lindex $args 0]
    2852             $itk_component(crange) select
     2910            set value [string trim [lindex $args 0]]
     2911
     2912            set which [MouseOver2Which]
     2913
     2914            # only set custom range if value changed
     2915            if {[$itk_component($which) value] != $value} {
     2916                $itk_component($which) value $value
     2917                $itk_component(crange) select
     2918            }
    28532919            AdjustSetting -range
    28542920        }
     
    28582924    }
    28592925}
     2926
    28602927
    28612928#
     
    29272994        # range, use the custom min and max to generate contour list values
    29282995        if { $_settings(-customrange) } {
    2929             if { $_settings(-customrangevmin) > $vmin } {
    2930                 set vmin $_settings(-customrangevmin)
    2931             }
    2932             if { $_settings(-customrangevmax) < $vmax } {
    2933                 set vmax $_settings(-customrangevmax)
     2996            if { [$itk_component(min) value] > $vmin } {
     2997                set vmin [$itk_component(min) value]
     2998            }
     2999            if { [$itk_component(max) value] < $vmax } {
     3000                set vmax [$itk_component(max) value]
    29343001            }
    29353002        }
Note: See TracChangeset for help on using the changeset viewer.