Changeset 5054
- Timestamp:
- Mar 3, 2015, 7:23:20 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/uiuc_vtk_viewers merged: 5032-5033,5049,5051-5053
- Property svn:mergeinfo changed
-
trunk/gui/scripts/gauge.tcl
r3733 r5054 42 42 itk_option define -sampleheight sampleHeight SampleHeight 0 43 43 itk_option define -log log Log "" 44 itk_option define -validatecommand validateCommand ValidateCommand "" 44 45 45 46 constructor {args} { # defined below } … … 236 237 } 237 238 real { 238 239 240 241 242 243 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. 244 245 if { [scan $nv "%g%s" dummy1 dummy2] != 1 } { 245 246 error "bad value \"$nv\": should be a real number" … … 288 289 error "maximum value allowed here is $convMaxVal" 289 290 } 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] 290 300 } 291 301 -
trunk/gui/scripts/vtkisosurfaceviewer.tcl
r4993 r5054 94 94 private method LegendProbeSingleContour { x y } 95 95 private method LegendRangeAction { option args } 96 private method LegendRangeValidate { widget which value } 96 97 private method LegendTitleAction { option } 97 98 private method MotionLegend { x y } 99 private method MouseOver2Which {} 98 100 private method Pan {option x y} 99 101 private method PanCamera {} … … 111 113 private method SetCurrentFieldName { dataobj } 112 114 private method SetLegendTip { x y } 115 private method SetMinMaxGauges { min max } 113 116 private method SetObjectStyle { dataobj comp } 114 117 private method SetOrientation { side } … … 117 120 private method SetupKeyboardBindings {} 118 121 private method Slice {option args} 122 private method ToggleCustomRange { args } 119 123 private method ViewToQuaternion {} { 120 124 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] … … 172 176 173 177 private variable _mouseOver ""; # what called LegendRangeAction, vmin or vmax 178 private variable _customRangeClick 1; # what called ToggleCustomRange 174 179 } 175 180 … … 258 263 -colormapvisible 1 259 264 -customrange 0 260 -customrange vmin0261 -customrange vmax1265 -customrangemin 0 266 -customrangemax 1 262 267 -cutplaneedges 0 263 268 -cutplanelighting 1 … … 775 780 # customrangevmin and customrangevmax 776 781 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 783 785 784 786 continue … … 786 788 foreach {min max} $lim break 787 789 foreach {fmin fmax} $_limits($fname) break 788 # if { $fname == $_curFldName && ! $_settings(-customrange) } {}789 790 if { ! $_settings(-customrange) } { 790 set _settings(-customrangevmin) $fmin 791 set _settings(-customrangevmax) $fmax 791 SetMinMaxGauges $fmin $fmax 792 792 } 793 793 if { $fmin > $min } { … … 1117 1117 -isosurfacelighting \ 1118 1118 -field \ 1119 -range \ 1119 1120 -isosurfacevisible \ 1120 1121 -isosurfaceedges -isosurfacelighting -isosurfaceopacity \ … … 1491 1492 SendCmd "dataset maprange all" 1492 1493 } else { 1493 foreach { vmin vmax } $_limits($_curFldName) break1494 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 } 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 1501 1503 } 1502 1504 SendCmd "dataset maprange explicit $vmin $vmax $_curFldName" … … 1576 1578 } 1577 1579 "-range" { 1578 foreach { vmin vmax } $_limits($_curFldName) break1579 1580 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] 1604 1583 } 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 1609 1585 } 1610 1586 GenerateContourList … … 1837 1813 -text "Use Custom Range:" \ 1838 1814 -variable [itcl::scope _settings(-customrange)] \ 1839 -command [itcl::code $this AdjustSetting -range] \1815 -command [itcl::code $this ToggleCustomRange] \ 1840 1816 -font "Arial 9" 1841 1817 } … … 1845 1821 } 1846 1822 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>> \ 1855 1827 [itcl::code $this AdjustSetting -range] 1856 1828 … … 1859 1831 } 1860 1832 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>> \ 1869 1837 [itcl::code $this AdjustSetting -range] 1870 1838 … … 2468 2436 if { [info exists _limits($fname)] } { 2469 2437 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] 2472 2440 } else { 2473 2441 foreach { vmin vmax } $_limits($fname) break … … 2668 2636 $c bind sensor <Leave> [itcl::code $this LeaveLegend] 2669 2637 $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] 2671 2639 # $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] 2673 2641 2674 2642 } … … 2685 2653 2686 2654 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] 2689 2657 } else { 2690 2658 foreach { vmin vmax } $_limits($_curFldName) break … … 2717 2685 if { [info exists _limits($_curFldName)] } { 2718 2686 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] 2721 2689 } else { 2722 2690 foreach { vmin vmax } $_limits($_curFldName) break … … 2792 2760 2793 2761 # ---------------------------------------------------------------------- 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 # ---------------------------------------------------------------------- 2774 itcl::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 2822 itcl::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 # ---------------------------------------------------------------------- 2794 2839 # USAGE: LegendRangeAction enter <which> 2795 2840 # USAGE: LegendRangeAction leave <which> 2796 2841 # 2797 # USAGE: Legend TitleAction popup <which>2798 # USAGE: Legend TitleAction activate2799 # USAGE: Legend TitleAction validate <value>2800 # USAGE: Legend TitleAction apply <value>2842 # USAGE: LegendRangeAction popup <which> 2843 # USAGE: LegendRangeAction activate 2844 # USAGE: LegendRangeAction validate <value> 2845 # USAGE: LegendRangeAction apply <value> 2801 2846 # 2802 2847 # Used internally to handle the mouseover and popup entry for the field range … … 2814 2859 itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeAction {option args} { 2815 2860 set c $itk_component(view) 2816 # FIXME: check $which for valid values 2861 2817 2862 switch -- $option { 2818 2863 enter { … … 2832 2877 activate { 2833 2878 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] 2835 2881 set info(x) [expr $x1 + [winfo rootx $c]] 2836 2882 set info(y) [expr $y1 + [winfo rooty $c]] … … 2843 2889 error "wrong # args: should be \"editor validate value\"" 2844 2890 } 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 2845 2899 SetupMouseRotationBindings 2846 2900 } … … 2849 2903 error "wrong # args: should be \"editor apply value\"" 2850 2904 } 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 } 2854 2921 } 2855 2922 default { … … 2858 2925 } 2859 2926 } 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 # ---------------------------------------------------------------------- 2946 itcl::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 # ---------------------------------------------------------------------- 3006 itcl::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 2860 3021 2861 3022 # … … 2927 3088 # range, use the custom min and max to generate contour list values 2928 3089 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] 2934 3095 } 2935 3096 }
Note: See TracChangeset
for help on using the changeset viewer.