- Timestamp:
- Mar 31, 2016, 12:31:35 PM (8 years ago)
- Location:
- branches/1.7
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.7
-
branches/1.7/gui/scripts/vtkglyphviewer.tcl
r6213 r6228 72 72 private method Connect {} 73 73 private method CurrentDatasets {args} 74 private method DisableMouseRotationBindings {} 74 75 private method Disconnect {} 75 76 private method DoResize {} … … 86 87 private method IsValidObject { dataobj } 87 88 private method LeaveLegend {} 89 private method LegendPointToValue { x y } 90 private method LegendRangeAction { option args } 91 private method LegendRangeValidate { widget which value } 88 92 private method LegendTitleAction { option } 89 93 private method MotionLegend { x y } 94 private method MouseOver2Which {} 90 95 private method Pan {option x y} 91 96 private method PanCamera {} … … 103 108 private method SetCurrentFieldName { dataobj } 104 109 private method SetLegendTip { x y } 110 private method SetMinMaxGauges { min max } 105 111 private method SetObjectStyle { dataobj comp } 106 112 private method SetOrientation { side } … … 110 116 private method SetupMouseZoomBindings {} 111 117 private method Slice {option args} 118 private method ToggleCustomRange { args } 112 119 private method ViewToQuaternion {} { 113 120 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] … … 149 156 private variable _curFldName "" 150 157 private variable _curFldLabel "" 158 private variable _curFldComp 3 159 private variable _mouseOver ""; # what called LegendRangeAction: 160 # vmin or vmax 161 private variable _customRangeClick 1; # what called ToggleCustomRange 151 162 152 163 private common _downloadPopup; # download options from popup … … 228 239 -colormap BCGYR 229 240 -colormapvisible 1 241 -customrange 0 242 -customrangemin 0 243 -customrangemax 1 230 244 -cutplaneedges 0 231 245 -cutplanelighting 1 … … 304 318 } 305 319 320 # add an editor for adjusting the legend min and max values 321 itk_component add editor { 322 Rappture::Editor $itk_interior.editor \ 323 -activatecommand [itcl::code $this LegendRangeAction activate] \ 324 -validatecommand [itcl::code $this LegendRangeAction validate] \ 325 -applycommand [itcl::code $this LegendRangeAction apply] 326 } 327 306 328 set c $itk_component(view) 307 329 bind $c <Configure> [itcl::code $this EventuallyResize %w %h] … … 441 463 bind $itk_component(view) <ButtonRelease-1> \ 442 464 [itcl::code $this Rotate release %x %y] 465 } 466 467 itcl::body Rappture::VtkGlyphViewer::DisableMouseRotationBindings {} { 468 # Bindings for rotation via mouse 469 bind $itk_component(view) <ButtonPress-1> "" 470 bind $itk_component(view) <B1-Motion> "" 471 bind $itk_component(view) <ButtonRelease-1> "" 443 472 } 444 473 … … 717 746 if { ![info exists _limits($fname)] } { 718 747 set _limits($fname) $lim 748 749 # set reasonable defaults for 750 # customrangevmin and customrangevmax 751 foreach {min max} $lim break 752 SetMinMaxGauges $min $max 753 set _settings(-customrangemin) $min 754 set _settings(-customrangemax) $max 755 719 756 continue 720 757 } 721 758 foreach {min max} $lim break 722 759 foreach {fmin fmax} $_limits($fname) break 760 if { ! $_settings(-customrange) } { 761 SetMinMaxGauges $fmin $fmax 762 } 723 763 if { $fmin > $min } { 724 764 set fmin $min … … 1041 1081 # These are settings that rely on a dataset being loaded. 1042 1082 InitSettings \ 1043 -field \1083 -field -range \ 1044 1084 -glyphedges -glyphlighting -glyphnormscale -glyphopacity \ 1045 1085 -glyphorient -glyphscale -glyphscalemode -glyphshape -glyphwireframe … … 1066 1106 set _reset 0 1067 1107 } 1108 #DrawLegend 1068 1109 1069 1110 # Actually write the commands to the server socket. If it fails, we don't … … 1412 1453 set _curFldName $fname 1413 1454 set _curFldLabel $label 1455 set _curFldComp $components 1414 1456 } else { 1415 1457 puts stderr "unknown field \"$fname\"" 1416 1458 return 1417 1459 } 1418 #if { ![info exists _limits($_curFldName)] } { 1419 # SendCmd "dataset maprange all" 1420 #} else { 1421 # SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" 1422 #} 1460 if { ![info exists _limits($_curFldName)] } { 1461 SendCmd "dataset maprange all" 1462 } else { 1463 if { $_settings(-customrange) } { 1464 set vmin [$itk_component(min) value] 1465 set vmax [$itk_component(max) value] 1466 } else { 1467 foreach { vmin vmax } $_limits($_curFldName) break 1468 # set the min / max gauges with limits from the field 1469 # the legend's min and max text will be updated 1470 # when the legend is redrawn in DrawLegend 1471 SetMinMaxGauges $vmin $vmax 1472 } 1473 SendCmd "dataset maprange explicit $vmin $vmax $_curFldName point_data $_curFldComp" 1474 } 1423 1475 #SendCmd "cutplane colormode $_colorMode $_curFldName" 1424 1476 SendCmd "glyphs colormode $_colorMode $_curFldName" … … 1515 1567 } 1516 1568 } 1569 } 1570 "-range" { 1571 if { $_settings(-customrange) } { 1572 set vmin [$itk_component(min) value] 1573 set vmax [$itk_component(max) value] 1574 } else { 1575 foreach { vmin vmax } $_limits($_curFldName) break 1576 } 1577 SendCmd "dataset maprange explicit $vmin $vmax $_curFldName point_data $_curFldComp" 1578 DrawLegend 1517 1579 } 1518 1580 "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" { … … 1776 1838 bind $inner.colormap <<Value>> \ 1777 1839 [itcl::code $this AdjustSetting -colormap] 1840 1841 # add widgets for setting a custom range on the legend 1842 1843 itk_component add crange { 1844 checkbutton $inner.crange \ 1845 -text "Use Custom Range:" \ 1846 -variable [itcl::scope _settings(-customrange)] \ 1847 -command [itcl::code $this ToggleCustomRange] \ 1848 -font "Arial 9" 1849 } 1850 1851 itk_component add l_min { 1852 label $inner.l_min -text "Min" -font "Arial 9" 1853 } 1854 itk_component add min { 1855 Rappture::Gauge $inner.min -font "Arial 9" \ 1856 -validatecommand [itcl::code $this LegendRangeValidate "" vmin] 1857 } 1858 bind $itk_component(min) <<Value>> \ 1859 [itcl::code $this AdjustSetting -range] 1860 1861 itk_component add l_max { 1862 label $inner.l_max -text "Max" -font "Arial 9" 1863 } 1864 itk_component add max { 1865 Rappture::Gauge $inner.max -font "Arial 9" \ 1866 -validatecommand [itcl::code $this LegendRangeValidate "" vmax] 1867 } 1868 bind $itk_component(max) <<Value>> \ 1869 [itcl::code $this AdjustSetting -range] 1870 1871 $itk_component(min) configure -state disabled 1872 $itk_component(max) configure -state disabled 1778 1873 1779 1874 blt::table $inner \ … … 1798 1893 12,0 $inner.legend -anchor w -pady 2 \ 1799 1894 13,0 $inner.opacity_l -anchor w -pady 2 \ 1800 13,1 $inner.opacity -anchor w -pady 2 -fill x 1895 13,1 $inner.opacity -anchor w -pady 2 -fill x \ 1896 14,0 $inner.crange -anchor w -pady 2 -cspan 2 \ 1897 15,0 $inner.l_min -anchor w -pady 2 \ 1898 15,1 $inner.min -anchor w -pady 2 -fill x \ 1899 16,0 $inner.l_max -anchor w -pady 2 \ 1900 16,1 $inner.max -anchor w -pady 2 -fill x \ 1801 1901 1802 1902 blt::table configure $inner r* c* -resize none 1803 blt::table configure $inner r1 4c1 -resize expand1903 blt::table configure $inner r17 c1 -resize expand 1804 1904 } 1805 1905 … … 2405 2505 } 2406 2506 2507 # ---------------------------------------------------------------------- 2508 # USAGE: LegendPointToValue <x> <y> 2509 # 2510 # Convert an x,y point on the legend to a numeric field value. 2511 # ---------------------------------------------------------------------- 2512 itcl::body Rappture::VtkGlyphViewer::LegendPointToValue { x y } { 2513 set fname $_curFldName 2514 2515 set font "Arial 8" 2516 set lineht [font metrics $font -linespace] 2517 2518 set ih [image height $_image(legend)] 2519 set iy [expr $y - ($lineht + 2)] 2520 2521 # Compute the value of the point 2522 if { [info exists _limits($fname)] } { 2523 if { $_settings(-customrange) } { 2524 set vmin [$itk_component(min) value] 2525 set vmax [$itk_component(max) value] 2526 } else { 2527 foreach { vmin vmax } $_limits($fname) break 2528 } 2529 set t [expr 1.0 - (double($iy) / double($ih-1))] 2530 set value [expr $t * ($vmax - $vmin) + $vmin] 2531 } else { 2532 set value 0.0 2533 } 2534 return $value 2535 } 2536 2407 2537 # 2408 2538 # SetLegendTip -- … … 2449 2579 2450 2580 # Compute the value of the point 2451 if { [info exists _limits($_curFldName)] } { 2452 foreach { vmin vmax } $_limits($_curFldName) break 2453 set t [expr 1.0 - (double($iy) / double($ih-1))] 2454 set value [expr $t * ($vmax - $vmin) + $vmin] 2455 } else { 2456 set value 0.0 2457 } 2581 set value [LegendPointToValue $x $y] 2582 2583 # Setup the location of the tooltip 2458 2584 set tx [expr $x + 15] 2459 2585 set ty [expr $y - 5] 2586 2587 # Setup the text for the tooltip 2460 2588 Rappture::Tooltip::text $c [format "$title %g" $value] 2589 2590 # Show the tooltip 2461 2591 Rappture::Tooltip::tooltip show $c +$tx,+$ty 2462 2592 } … … 2586 2716 $c itemconfigure title -text $title 2587 2717 if { [info exists _limits($_curFldName)] } { 2588 foreach { vmin vmax } $_limits($_curFldName) break 2718 if { $_settings(-customrange) } { 2719 set vmin [$itk_component(min) value] 2720 set vmax [$itk_component(max) value] 2721 } else { 2722 foreach { vmin vmax } $_limits($_curFldName) break 2723 } 2589 2724 $c itemconfigure vmin -text [format %g $vmin] 2590 2725 $c itemconfigure vmax -text [format %g $vmax] … … 2604 2739 $c raise sensor 2605 2740 $c coords vmin $x [expr {$h - 2}] 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] 2606 2749 } 2607 2750 … … 2644 2787 error "bad option \"$option\": should be post, enter, leave or save" 2645 2788 } 2789 } 2790 } 2791 2792 # ---------------------------------------------------------------------- 2793 # USAGE: LegendRangeValidate <widget> <which> <value> 2794 # 2795 # Used internally to validate a legend range min/max value. 2796 # Returns a boolean value telling if <value> was accepted (1) or rejected (0) 2797 # If the value is rejected, a tooltip/warning message is popped up 2798 # near the widget that asked for the validation, specified by <widget> 2799 # 2800 # <widget> is the widget where a tooltip/warning message should show up on 2801 # <which> is either "vmin" or "vmax". 2802 # <value> is the value to be validated. 2803 # ---------------------------------------------------------------------- 2804 itcl::body Rappture::VtkGlyphViewer::LegendRangeValidate {widget which value} { 2805 #check for a valid value 2806 if {[string is double $value] != 1} { 2807 set msg "should be valid number" 2808 if {$widget != ""} { 2809 Rappture::Tooltip::cue $widget $msg 2810 } else { 2811 # error "bad value \"$value\": $msg" 2812 error $msg 2813 } 2814 return 0 2815 } 2816 2817 switch -- $which { 2818 vmin { 2819 # check for min > max 2820 if {$value > [$itk_component(max) value]} { 2821 set msg "min > max, change max first" 2822 if {$widget != ""} { 2823 Rappture::Tooltip::cue $widget $msg 2824 } else { 2825 # error "bad value \"$value\": $msg" 2826 error $msg 2827 } 2828 return 0 2829 } 2830 } 2831 vmax { 2832 # check for max < min 2833 if {$value < [$itk_component(min) value]} { 2834 set msg "max < min, change min first" 2835 if {$widget != ""} { 2836 Rappture::Tooltip::cue $widget $msg 2837 } else { 2838 # error "bad value \"$value\": $msg" 2839 error $msg 2840 } 2841 return 0 2842 } 2843 } 2844 default { 2845 error "bad option \"$which\": should be vmin, vmax" 2846 } 2847 } 2848 } 2849 2850 itcl::body Rappture::VtkGlyphViewer::MouseOver2Which {} { 2851 switch -- $_mouseOver { 2852 vmin { 2853 set which min 2854 } 2855 vmax { 2856 set which max 2857 } 2858 default { 2859 error "bad _mouseOver \"$_mouseOver\": should be vmin, vmax" 2860 } 2861 } 2862 return $which 2863 } 2864 2865 # ---------------------------------------------------------------------- 2866 # USAGE: LegendRangeAction enter <which> 2867 # USAGE: LegendRangeAction leave <which> 2868 # 2869 # USAGE: LegendRangeAction popup <which> 2870 # USAGE: LegendRangeAction activate 2871 # USAGE: LegendRangeAction validate <value> 2872 # USAGE: LegendRangeAction apply <value> 2873 # 2874 # Used internally to handle the mouseover and popup entry for the field range 2875 # inputs. The enter option is invoked when the user moves the mouse over the 2876 # min or max field range. The leave option is invoked when the user moves the 2877 # mouse away from the min or max field range. The popup option is invoked when 2878 # the user click's on a field range. The popup option stores internally which 2879 # widget is requesting a popup ( in the _mouseOver variable) and calls the 2880 # activate command of the widget. The widget's activate command calls back to 2881 # this method to get the xywh dimensions of the popup editor. After the user 2882 # changes focus or sets the value in the editor, the editor calls this methods 2883 # validate and apply options to set the value. 2884 # ---------------------------------------------------------------------- 2885 itcl::body Rappture::VtkGlyphViewer::LegendRangeAction {option args} { 2886 set c $itk_component(view) 2887 2888 switch -- $option { 2889 enter { 2890 set which [lindex $args 0] 2891 $c itemconfigure $which -fill red 2892 } 2893 leave { 2894 set which [lindex $args 0] 2895 $c itemconfigure $which -fill $itk_option(-plotforeground) 2896 } 2897 popup { 2898 DisableMouseRotationBindings 2899 set which [lindex $args 0] 2900 set _mouseOver $which 2901 $itk_component(editor) activate 2902 } 2903 activate { 2904 foreach { x1 y1 x2 y2 } [$c bbox $_mouseOver] break 2905 set which [MouseOver2Which] 2906 set info(text) [$itk_component($which) value] 2907 set info(x) [expr $x1 + [winfo rootx $c]] 2908 set info(y) [expr $y1 + [winfo rooty $c]] 2909 set info(w) [expr $x2 - $x1] 2910 set info(h) [expr $y2 - $y1] 2911 return [array get info] 2912 } 2913 validate { 2914 if {[llength $args] != 1} { 2915 error "wrong # args: should be \"editor validate value\"" 2916 } 2917 2918 set value [lindex $args 0] 2919 if {[LegendRangeValidate $itk_component(editor) $_mouseOver $value] == 0} { 2920 return 0 2921 } 2922 2923 # value was good, apply it 2924 # reset the mouse rotation bindings 2925 SetupMouseRotationBindings 2926 } 2927 apply { 2928 if {[llength $args] != 1} { 2929 error "wrong # args: should be \"editor apply value\"" 2930 } 2931 set value [string trim [lindex $args 0]] 2932 2933 set which [MouseOver2Which] 2934 2935 # only set custom range if value changed 2936 if {[$itk_component($which) value] != $value} { 2937 # set the flag stating the custom range came from the legend 2938 # change the value in the gauge 2939 # turn on crange to enable the labels and gauges 2940 # call AdjustSetting -range (inside ToggleCustomRange) 2941 # to update drawing and legend 2942 set _customRangeClick 0 2943 $itk_component($which) value $value 2944 $itk_component(crange) select 2945 ToggleCustomRange 2946 } 2947 } 2948 default { 2949 error "bad option \"$option\": should be enter, leave, activate, validate, apply" 2950 } 2951 } 2952 } 2953 2954 # ---------------------------------------------------------------------- 2955 # USAGE: ToggleCustomRange 2956 # 2957 # Called whenever the custom range is turned on or off. Used to save 2958 # the custom min and custom max set by the user. When the -customrange 2959 # setting is turned on, the range min and range max gauges are set 2960 # with the last value set by the user, or the default range if no 2961 # previous min and max were set. 2962 # 2963 # When the custom range is turned on, we check how it was turned on 2964 # by querying _customRangeClick. If the variable is 1, this means 2965 # the user clicked the crange checkbutton and we should pull the 2966 # custom range values from our backup variables. If the variable is 0, 2967 # the custom range was enabled through the user manipulating the 2968 # min and max value in the legend. 2969 # ---------------------------------------------------------------------- 2970 itcl::body Rappture::VtkGlyphViewer::ToggleCustomRange {args} { 2971 if { ! $_settings(-customrange) } { 2972 # custom range was turned off 2973 2974 # disable the min/max labels and gauge widgets 2975 $itk_component(l_min) configure -state disabled 2976 $itk_component(min) configure -state disabled 2977 $itk_component(l_max) configure -state disabled 2978 $itk_component(max) configure -state disabled 2979 2980 # backup the custom range 2981 set _settings(-customrangemin) [$itk_component(min) value] 2982 set _settings(-customrangemax) [$itk_component(max) value] 2983 2984 # set the gauges to dataset's min and max 2985 foreach { vmin vmax } $_limits($_curFldName) break 2986 SetMinMaxGauges $vmin $vmax 2987 } else { 2988 # custom range was turned on 2989 2990 # enable the min/max labels and gauge widgets 2991 $itk_component(l_min) configure -state normal 2992 $itk_component(min) configure -state normal 2993 $itk_component(l_max) configure -state normal 2994 $itk_component(max) configure -state normal 2995 2996 # if the custom range is being turned on by clicking the 2997 # checkbox, restore the min and max gauges from the backup 2998 # variables. otherwise, new values for the min and max 2999 # widgets will be set later from the legend's editor. 3000 if { $_customRangeClick } { 3001 SetMinMaxGauges $_settings(-customrangemin) $_settings(-customrangemax) 3002 } 3003 3004 # reset the click flag 3005 set _customRangeClick 1 3006 } 3007 AdjustSetting -range 3008 } 3009 3010 # ---------------------------------------------------------------------- 3011 # USAGE: SetMinMaxGauges <min> <max> 3012 # 3013 # Set the min and max gauges in the correct order, avoiding the 3014 # error where you try to set the min > max before updating the max or 3015 # set the max < min before updating the min. 3016 # 3017 # There are five range cases to consider with our current range validation. 3018 # For example: 3019 # [2,3] -> [0,1] : update min first, max last 3020 # [2,3] -> [4,5] : update max first, min last 3021 # [2,3] -> [0,2.5] : update min or max first 3022 # [2,3] -> [2.5,5] : update min or max first 3023 # [2,3] -> [2.25,2.75] : update min or max first 3024 # 3025 # In 4 of the cases we can update min first and max last, so we only 3026 # need to check the case where old max < new min, where we update 3027 # max first and min last. 3028 # ---------------------------------------------------------------------- 3029 itcl::body Rappture::VtkGlyphViewer::SetMinMaxGauges {min max} { 3030 3031 if { [$itk_component(max) value] < $min} { 3032 # old max < new min 3033 # shift range toward right 3034 # extend max first, then update min 3035 $itk_component(max) value $max 3036 $itk_component(min) value $min 3037 } else { 3038 # extend min first, then update max 3039 $itk_component(min) value $min 3040 $itk_component(max) value $max 2646 3041 } 2647 3042 } … … 2721 3116 set _curFldName $fname 2722 3117 set _curFldLabel $label 3118 set _curFldComp $components 2723 3119 } 2724 3120 } 2725 3121 } 2726 3122 $itk_component(field) value $_curFldLabel 2727 } 3123 if { $_settings(-customrange) } { 3124 set limits [list [$itk_component(min) value] [$itk_component(max) value]] 3125 SendCmd "dataset maprange explicit $limits $_curFldName point_data $_curFldComp" 3126 } else { 3127 if { ![info exists _limits($_curFldName)] } { 3128 SendCmd "dataset maprange all" 3129 } else { 3130 set limits $_limits($_curFldName) 3131 SendCmd "dataset maprange explicit $limits $_curFldName point_data $_curFldComp" 3132 } 3133 } 3134 }
Note: See TracChangeset
for help on using the changeset viewer.