Changeset 4954 for branches/uiuc_vtk_viewers/gui
- Timestamp:
- Jan 26, 2015 10:33:39 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uiuc_vtk_viewers/gui/scripts/vtkisosurfaceviewer.tcl
r4953 r4954 70 70 private method BuildDownloadPopup { widget command } 71 71 private method BuildIsosurfaceTab {} 72 private method Combo { option }73 72 private method Connect {} 74 73 private method CurrentDatasets {args} 74 private method DisableMouseRotationBindings {} 75 75 private method Disconnect {} 76 76 private method DoChangeContourLevels {} … … 90 90 private method IsValidObject { dataobj } 91 91 private method LeaveLegend {} 92 private method LegendB1Motion {status x y} 93 private method LegendPointToValue { x y } 94 private method LegendProbeSingleContour { x y } 95 private method LegendRangeAction { option args } 96 private method LegendTitleAction { option } 92 97 private method MotionLegend { x y } 93 98 private method Pan {option x y} … … 108 113 private method SetObjectStyle { dataobj comp } 109 114 private method SetOrientation { side } 115 private method SetupMouseRotationBindings {} 116 private method SetupMousePanningBindings {} 117 private method SetupKeyboardBindings {} 110 118 private method Slice {option args} 111 119 private method ViewToQuaternion {} { … … 162 170 private variable _curFldName "" 163 171 private variable _curFldLabel "" 172 173 private variable _mouseOver ""; # what called LegendRangeAction, vmin or vmax 164 174 } 165 175 … … 247 257 -colormap BCGYR 248 258 -colormapvisible 1 259 -customrange 0 260 -customrangevmin 0 261 -customrangevmax 1 249 262 -cutplaneedges 0 250 263 -cutplanelighting 1 … … 299 312 ignore -background -foreground -relief -tearoff 300 313 } 314 315 # add an editor for adjusting the legend min and max values 316 itk_component add editor { 317 Rappture::Editor $itk_interior.editor \ 318 -activatecommand [itcl::code $this LegendRangeAction activate] \ 319 -validatecommand [itcl::code $this LegendRangeAction validate] \ 320 -applycommand [itcl::code $this LegendRangeAction apply] 321 } 322 301 323 set c $itk_component(view) 302 324 bind $c <Configure> [itcl::code $this EventuallyResize %w %h] … … 409 431 blt::table configure $itk_component(plotarea) c1 -resize none 410 432 433 SetupMouseRotationBindings 434 SetupMousePanningBindings 435 SetupKeyboardBindings 436 437 438 #bind $itk_component(view) <ButtonRelease-3> \ 439 # [itcl::code $this Pick %x %y] 440 441 442 if {[string equal "x11" [tk windowingsystem]]} { 443 # Bindings for zoom via mouse 444 bind $itk_component(view) <4> [itcl::code $this Zoom out] 445 bind $itk_component(view) <5> [itcl::code $this Zoom in] 446 } 447 448 set _image(download) [image create photo] 449 450 eval itk_initialize $args 451 452 EnableWaitDialog 500 453 Connect 454 # FIXME: Removing this update breaks wizard mode (see examples/3D) 455 # However, it also allows an error in the initialization order 456 # where FieldResult::add is called from ResultViewer before this 457 # constructor is completed. 458 #update 459 } 460 461 # ---------------------------------------------------------------------- 462 # DESTRUCTOR 463 # ---------------------------------------------------------------------- 464 itcl::body Rappture::VtkIsosurfaceViewer::destructor {} { 465 Disconnect 466 image delete $_image(plot) 467 image delete $_image(download) 468 catch { blt::arcball destroy $_arcball } 469 } 470 471 itcl::body Rappture::VtkIsosurfaceViewer::SetupMouseRotationBindings {} { 411 472 # Bindings for rotation via mouse 412 473 bind $itk_component(view) <ButtonPress-1> \ … … 416 477 bind $itk_component(view) <ButtonRelease-1> \ 417 478 [itcl::code $this Rotate release %x %y] 418 479 } 480 481 itcl::body Rappture::VtkIsosurfaceViewer::DisableMouseRotationBindings {} { 482 # Bindings for rotation via mouse 483 bind $itk_component(view) <ButtonPress-1> "" 484 bind $itk_component(view) <B1-Motion> "" 485 bind $itk_component(view) <ButtonRelease-1> "" 486 } 487 488 itcl::body Rappture::VtkIsosurfaceViewer::SetupMousePanningBindings {} { 419 489 # Bindings for panning via mouse 420 490 bind $itk_component(view) <ButtonPress-2> \ … … 424 494 bind $itk_component(view) <ButtonRelease-2> \ 425 495 [itcl::code $this Pan release %x %y] 426 427 #bind $itk_component(view) <ButtonRelease-3> \ 428 # [itcl::code $this Pick %x %y] 429 496 } 497 498 itcl::body Rappture::VtkIsosurfaceViewer::SetupKeyboardBindings {} { 430 499 # Bindings for panning via keyboard 431 500 bind $itk_component(view) <KeyPress-Left> \ … … 453 522 454 523 bind $itk_component(view) <Enter> "focus $itk_component(view)" 455 456 if {[string equal "x11" [tk windowingsystem]]} {457 # Bindings for zoom via mouse458 bind $itk_component(view) <4> [itcl::code $this Zoom out]459 bind $itk_component(view) <5> [itcl::code $this Zoom in]460 }461 462 set _image(download) [image create photo]463 464 eval itk_initialize $args465 466 EnableWaitDialog 500467 Connect468 }469 470 # ----------------------------------------------------------------------471 # DESTRUCTOR472 # ----------------------------------------------------------------------473 itcl::body Rappture::VtkIsosurfaceViewer::destructor {} {474 Disconnect475 image delete $_image(plot)476 image delete $_image(download)477 catch { blt::arcball destroy $_arcball }478 524 } 479 525 … … 725 771 if { ![info exists _limits($fname)] } { 726 772 set _limits($fname) $lim 773 774 # set reasonable defaults for 775 # customrangevmin and customrangevmax 776 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 } 783 727 784 continue 728 785 } 729 786 foreach {min max} $lim break 730 787 foreach {fmin fmax} $_limits($fname) break 788 # if { $fname == $_curFldName && ! $_settings(-customrange) } {} 789 if { ! $_settings(-customrange) } { 790 set _settings(-customrangevmin) $fmin 791 set _settings(-customrangevmax) $fmax 792 } 731 793 if { $fmin > $min } { 732 794 set fmin $min … … 1429 1491 SendCmd "dataset maprange all" 1430 1492 } else { 1431 SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" 1493 foreach { vmin vmax } $_limits($_curFldName) break 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 } 1501 } 1502 SendCmd "dataset maprange explicit $vmin $vmax $_curFldName" 1432 1503 } 1433 1504 SendCmd "cutplane colormode $_colorMode $_curFldName" … … 1503 1574 } 1504 1575 } 1576 } 1577 "-range" { 1578 foreach { vmin vmax } $_limits($_curFldName) break 1579 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 } 1604 } 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 1609 } 1610 GenerateContourList 1611 SendCmd [list contour3d contourlist $_contourList(values)] 1612 SendCmd "dataset maprange explicit $vmin $vmax $_curFldName" 1613 DrawLegend 1505 1614 } 1506 1615 "-xcutplanevisible" - "-ycutplanevisible" - "-zcutplanevisible" { … … 1575 1684 incr h -$lineht 1576 1685 } 1577 # Set the legend on the first heightmapdataset.1686 # Set the legend on the first isosurface dataset. 1578 1687 if { $_currentColormap != "" } { 1579 1688 set cmap $_currentColormap … … 1720 1829 bind $itk_component(numcontours) <<Value>> \ 1721 1830 [itcl::code $this AdjustSetting -numcontours] 1831 1832 1833 # add widgets for setting a custom range on the legend 1834 1835 itk_component add crange { 1836 checkbutton $inner.crange \ 1837 -text "Use Custom Range:" \ 1838 -variable [itcl::scope _settings(-customrange)] \ 1839 -command [itcl::code $this AdjustSetting -range] \ 1840 -font "Arial 9" 1841 } 1842 1843 itk_component add l_min { 1844 label $inner.l_min -text "Min" -font "Arial 9" 1845 } 1846 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> \ 1855 [itcl::code $this AdjustSetting -range] 1856 1857 itk_component add l_max { 1858 label $inner.l_max -text "Max" -font "Arial 9" 1859 } 1860 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> \ 1869 [itcl::code $this AdjustSetting -range] 1870 1871 $itk_component(min) configure -state disabled 1872 $itk_component(max) configure -state disabled 1873 1722 1874 1723 1875 blt::table $inner \ … … 1739 1891 10,0 $inner.opacity_l -anchor w -pady 2 \ 1740 1892 10,1 $inner.opacity -fill x -pady 2 -fill x \ 1893 11,0 $inner.crange -anchor w -pady 2 -cspan 2 \ 1894 12,0 $inner.l_min -anchor w -pady 2 \ 1895 12,1 $inner.min -anchor w -pady 2 -fill x \ 1896 13,0 $inner.l_max -anchor w -pady 2 \ 1897 13,1 $inner.max -anchor w -pady 2 -fill x \ 1741 1898 1742 1899 blt::table configure $inner r* c* -resize none 1743 blt::table configure $inner r1 1c1 -resize expand1900 blt::table configure $inner r14 c1 -resize expand 1744 1901 } 1745 1902 … … 2256 2413 } 2257 2414 2415 # ---------------------------------------------------------------------- 2416 # USAGE: LegendB1Motion press <x> <y> 2417 # USAGE: LegendB1Motion motion <x> <y> 2418 # USAGE: LegendB1Motion release <x> <y> 2419 # 2420 # Manage actions for Button 1 presses that happen over the legend. 2421 # Pressing mouse Button 1 on the legend sends a command to the 2422 # visualization server to show a specific isosurface. 2423 # ---------------------------------------------------------------------- 2424 itcl::body Rappture::VtkIsosurfaceViewer::LegendB1Motion { status x y } { 2425 2426 switch -- $status { 2427 "press" { 2428 DisableMouseRotationBindings 2429 LegendProbeSingleContour $x $y 2430 } 2431 "motion" { 2432 DisableMouseRotationBindings 2433 LegendProbeSingleContour $x $y 2434 } 2435 "release" { 2436 AdjustSetting -range 2437 SetupMouseRotationBindings 2438 } 2439 default { 2440 error "bad option \"$option\": should be one of press, motion, release." 2441 } 2442 } 2443 } 2444 2445 2446 # ---------------------------------------------------------------------- 2447 # USAGE: LegendPointToValue <x> <y> 2448 # 2449 # Convert an x,y point on the legend to a numeric isosurface value. 2450 # ---------------------------------------------------------------------- 2451 itcl::body Rappture::VtkIsosurfaceViewer::LegendPointToValue { x y } { 2452 2453 set fname $_curFldName 2454 2455 set font "Arial 8" 2456 set lineht [font metrics $font -linespace] 2457 2458 set ih [image height $_image(legend)] 2459 set iy [expr $y - ($lineht + 2)] 2460 2461 # Compute the value of the point 2462 if { [info exists _limits($fname)] } { 2463 if { $_settings(-customrange) } { 2464 set vmin $_settings(-customrangevmin) 2465 set vmax $_settings(-customrangevmax) 2466 } else { 2467 foreach { vmin vmax } $_limits($fname) break 2468 } 2469 set t [expr 1.0 - (double($iy) / double($ih-1))] 2470 set value [expr $t * ($vmax - $vmin) + $vmin] 2471 } else { 2472 set value 0.0 2473 } 2474 return $value 2475 } 2476 2477 2478 # ---------------------------------------------------------------------- 2479 # USAGE: LegendProbeSingleContour <x> <y> 2480 # 2481 # Calculate the isosurface value for the x,y point and send a commands 2482 # to the visualization server to show that isosurface. 2483 # ---------------------------------------------------------------------- 2484 itcl::body Rappture::VtkIsosurfaceViewer::LegendProbeSingleContour { x y } { 2485 2486 set value [LegendPointToValue $x $y] 2487 SendCmd [list contour3d contourlist $value] 2488 } 2489 2490 2258 2491 # 2259 2492 # SetLegendTip -- … … 2300 2533 2301 2534 # Compute the value of the point 2302 if { [info exists _limits($_curFldName)] } { 2303 foreach { vmin vmax } $_limits($_curFldName) break 2304 set t [expr 1.0 - (double($iy) / double($ih-1))] 2305 set value [expr $t * ($vmax - $vmin) + $vmin] 2306 } else { 2307 set value 0.0 2308 } 2535 set value [LegendPointToValue $x $y] 2536 2309 2537 set tx [expr $x + 15] 2310 2538 set ty [expr $y - 5] … … 2375 2603 # DrawLegend -- 2376 2604 # 2377 # Draws the legend in theown canvas on the right side of the plot area.2605 # Draws the legend in its own canvas on the right side of the plot area. 2378 2606 # 2379 2607 itcl::body Rappture::VtkIsosurfaceViewer::DrawLegend {} { … … 2429 2657 $c bind sensor <Leave> [itcl::code $this LeaveLegend] 2430 2658 $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y] 2659 $c bind sensor <ButtonPress-1> [itcl::code $this LegendB1Motion press %x %y] 2660 $c bind sensor <B1-Motion> [itcl::code $this LegendB1Motion motion %x %y] 2661 $c bind sensor <ButtonRelease-1> [itcl::code $this LegendB1Motion release %x %y] 2662 2431 2663 } 2432 2664 $c delete isoline … … 2441 2673 $_settings(-numcontours) > 0 } { 2442 2674 2443 foreach { vmin vmax } $_limits($_curFldName) break 2675 if { $_settings(-customrange) } { 2676 set vmin $_settings(-customrangevmin) 2677 set vmax $_settings(-customrangevmax) 2678 } else { 2679 foreach { vmin vmax } $_limits($_curFldName) break 2680 } 2444 2681 set range [expr double($vmax - $vmin)] 2445 2682 if { $range <= 0.0 } { … … 2462 2699 } 2463 2700 2464 $c bind title <ButtonPress> [itcl::code $this Combopost]2465 $c bind title <Enter> [itcl::code $this Combo activate]2466 $c bind title <Leave> [itcl::code $this Combo deactivate]2701 $c bind title <ButtonPress> [itcl::code $this LegendTitleAction post] 2702 $c bind title <Enter> [itcl::code $this LegendTitleAction enter] 2703 $c bind title <Leave> [itcl::code $this LegendTitleAction leave] 2467 2704 # Reset the item coordinates according the current size of the plot. 2468 2705 $c itemconfigure title -text $title 2469 2706 if { [info exists _limits($_curFldName)] } { 2470 foreach { vmin vmax } $_limits($_curFldName) break 2707 if { $_settings(-customrange) } { 2708 set vmin $_settings(-customrangevmin) 2709 set vmax $_settings(-customrangevmax) 2710 } else { 2711 foreach { vmin vmax } $_limits($_curFldName) break 2712 } 2471 2713 $c itemconfigure vmin -text [format %g $vmin] 2472 2714 $c itemconfigure vmax -text [format %g $vmax] … … 2486 2728 $c raise sensor 2487 2729 $c coords vmin $x [expr {$h - 2}] 2488 } 2489 2490 # ---------------------------------------------------------------------- 2491 # USAGE: _dropdown post 2492 # USAGE: _dropdown unpost 2493 # USAGE: _dropdown select 2494 # 2495 # Used internally to handle the dropdown list for this combobox. The 2496 # post/unpost options are invoked when the list is posted or unposted 2497 # to manage the relief of the controlling button. The select option 2498 # is invoked whenever there is a selection from the list, to assign 2499 # the value back to the gauge. 2500 # ---------------------------------------------------------------------- 2501 itcl::body Rappture::VtkIsosurfaceViewer::Combo {option} { 2730 2731 $c bind vmin <ButtonPress> [itcl::code $this LegendRangeAction popup vmin] 2732 $c bind vmin <Enter> [itcl::code $this LegendRangeAction enter vmin] 2733 $c bind vmin <Leave> [itcl::code $this LegendRangeAction leave vmin] 2734 2735 $c bind vmax <ButtonPress> [itcl::code $this LegendRangeAction popup vmax] 2736 $c bind vmax <Enter> [itcl::code $this LegendRangeAction enter vmax] 2737 $c bind vmax <Leave> [itcl::code $this LegendRangeAction leave vmax] 2738 } 2739 2740 # ---------------------------------------------------------------------- 2741 # USAGE: LegendTitleAction post 2742 # USAGE: LegendTitleAction enter 2743 # USAGE: LegendTitleAction leave 2744 # USAGE: LegendTitleAction save 2745 # 2746 # Used internally to handle the dropdown list for the fields menu combobox. 2747 # The post option is invoked when the field title is pressed to launch the 2748 # dropdown. The enter option is invoked when the user mouses over the field 2749 # title. The leave option is invoked when the user moves the mouse away 2750 # from the field title. The save option is invoked whenever there is a 2751 # selection from the list, to alert the visualization server. 2752 # 2753 # ---------------------------------------------------------------------- 2754 itcl::body Rappture::VtkIsosurfaceViewer::LegendTitleAction {option} { 2502 2755 set c $itk_component(view) 2503 2756 switch -- $option { … … 2511 2764 tk_popup $itk_component(fieldmenu) $x $y 2512 2765 } 2513 activate{2766 enter { 2514 2767 $c itemconfigure title -fill red 2515 2768 } 2516 deactivate {2769 leave { 2517 2770 $c itemconfigure title -fill $itk_option(-plotforeground) 2518 2771 } 2519 invoke {2772 save { 2520 2773 $itk_component(field) value $_curFldLabel 2521 2774 AdjustSetting -field 2522 2775 } 2523 2776 default { 2524 error "bad option \"$option\": should be post, unpost, select" 2777 error "bad option \"$option\": should be post, enter, leave, save" 2778 } 2779 } 2780 } 2781 2782 # ---------------------------------------------------------------------- 2783 # USAGE: LegendRangeAction enter <which> 2784 # USAGE: LegendRangeAction leave <which> 2785 # 2786 # USAGE: LegendTitleAction popup <which> 2787 # USAGE: LegendTitleAction activate 2788 # USAGE: LegendTitleAction validate <value> 2789 # USAGE: LegendTitleAction apply <value> 2790 # 2791 # Used internally to handle the dropdown list for the field range text inputs. 2792 # The post option is invoked when a field range is pressed to launch a text 2793 # input field. The enter option is invoked when the user mouses over a field 2794 # range. The leave option is invoked when the user moves the mouse away from a 2795 # field range. The save option is invoked whenever a value is set for a field 2796 # range, and alerts the visualization server. 2797 # 2798 # ---------------------------------------------------------------------- 2799 itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeAction {option args} { 2800 set c $itk_component(view) 2801 # FIXME: check $which for valid values 2802 switch -- $option { 2803 enter { 2804 set which [lindex $args 0] 2805 $c itemconfigure $which -fill red 2806 } 2807 leave { 2808 set which [lindex $args 0] 2809 $c itemconfigure $which -fill $itk_option(-plotforeground) 2810 } 2811 popup { 2812 set which [lindex $args 0] 2813 set _mouseOver $which 2814 $itk_component(editor) activate 2815 } 2816 activate { 2817 foreach { x1 y1 x2 y2 } [$c bbox $_mouseOver] break 2818 set info(text) $_settings(-customrange$_mouseOver) 2819 set info(x) [expr $x1 + [winfo rootx $c]] 2820 set info(y) [expr $y1 + [winfo rooty $c]] 2821 set info(w) [expr $x2 - $x1] 2822 set info(h) [expr $y2 - $y1] 2823 puts "array: [array get info]" 2824 return [array get info] 2825 } 2826 validate { 2827 if {[llength $args] != 1} { 2828 error "wrong # args: should be \"editor validate value\"" 2829 } 2830 } 2831 apply { 2832 if {[llength $args] != 1} { 2833 error "wrong # args: should be \"editor apply value\"" 2834 } 2835 set _settings(-customrange$_mouseOver) [lindex $args 0] 2836 $itk_component(crange) select 2837 AdjustSetting -range 2838 } 2839 default { 2840 error "bad option \"$option\": should be enter, leave, activate, validate, apply" 2525 2841 } 2526 2842 } … … 2589 2905 set values $_contourList(reqValues) 2590 2906 } else { 2907 # use the field limits to calculate the contour list values 2591 2908 foreach { vmin vmax } $_limits($_curFldName) break 2909 2910 # if custom range has been set and are within the field's 2911 # range, use the custom min and max to generate contour list values 2912 if { $_settings(-customrange) } { 2913 if { $_settings(-customrangevmin) > $vmin } { 2914 set vmin $_settings(-customrangevmin) 2915 } 2916 if { $_settings(-customrangevmax) < $vmax } { 2917 set vmax $_settings(-customrangevmax) 2918 } 2919 } 2920 2592 2921 set v [blt::vector create \#auto] 2593 2922 $v seq $vmin $vmax [expr $_contourList(numLevels)+2] … … 2619 2948 -activeforeground $itk_option(-plotforeground) \ 2620 2949 -font "Arial 8" \ 2621 -command [itcl::code $this Combo invoke]2950 -command [itcl::code $this LegendTitleAction save] 2622 2951 set _fields($fname) [list $label $units $components] 2623 2952 if { $_curFldName == "" } {
Note: See TracChangeset
for help on using the changeset viewer.