Changeset 1435 for trunk/gui/scripts/nanovisviewer.tcl
- Timestamp:
- May 14, 2009 10:19:39 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/nanovisviewer.tcl
r1423 r1435 54 54 } 55 55 public method add {dataobj {settings ""}} 56 public method camera {option args} 57 public method delete {args} 58 public method download {option args} 56 59 public method get {args} 57 public method delete {args} 60 public method isconnected {} 61 public method limits { tf } 62 public method overmarker { m x } 63 public method parameters {title args} { 64 # do nothing 65 } 66 public method rmdupmarker { m x } 58 67 public method scale {args} 59 public method download {option args}60 public method parameters {title args} {61 # do nothing62 }63 public method limits { tf }64 public method isconnected {}65 68 public method updatetransferfuncs {} 66 public method rmdupmarker { m x }67 public method overmarker { m x }68 public method camera {option args}69 69 70 70 protected method Connect {} 71 protected method CurrentVolumeIds {{what -all}} 71 72 protected method Disconnect {} 72 73 protected method DoResize {} 74 protected method FixLegend {} 75 protected method FixSettings {what {value ""}} 76 protected method Pan {option x y} 77 protected method Rebuild {} 78 protected method ReceiveData { args } 79 protected method ReceiveImage { args } 80 protected method ReceiveLegend { tf vmin vmax size } 81 protected method Rotate {option x y} 73 82 protected method SendCmd {string} 74 83 protected method SendDataObjs {} 75 84 protected method SendTransferFuncs {} 76 77 protected method ReceiveImage { args }78 protected method ReceiveLegend { ivol vmin vmax size }79 protected method ReceiveData { args }80 81 protected method Rebuild {}82 protected method CurrentVolumeIds {{what -all}}83 protected method Zoom {option}84 protected method Pan {option x y}85 protected method Rotate {option x y}86 protected method Probe {option args}87 protected method Marker {index option args}88 85 protected method Slice {option args} 89 86 protected method SlicerTip {axis} 90 91 protected method State {comp} 92 protected method DoResize {} 93 protected method FixLegend {} 94 protected method FixSettings {what {value ""}} 87 protected method Zoom {option} 95 88 96 89 # The following methods are only used by this class. 97 private method NameTransferFunc { ivol }98 private method ComputeTransferFunc { tf }99 90 private method AddIsoMarker { x y } 100 private method ParseMarkersOption { tf ivol markers } 101 private method ParseLevelsOption { tf ivol levels } 102 private method EventuallyResize { w h } 103 private method EventuallyResizeLegend { } 104 91 private method BuildCameraTab {} 105 92 private method BuildCutplanesTab {} 106 93 private method BuildViewTab {} 107 94 private method BuildVolumeTab {} 108 private method BuildCameraTab {} 95 private method ComputeTransferFunc { tf } 96 private method EventuallyResize { w h } 97 private method EventuallyResizeLegend { } 98 private method NameTransferFunc { dataobj comp } 109 99 private method PanCamera {} 110 111 private variable outbuf_ ;# buffer for outgoing commands 112 113 private variable dlist_ "" ;# list of data objects 114 private variable allDataObjs_ 115 private variable id2style_ ;# maps id => style settings 116 private variable obj2ovride_ ;# maps dataobj => style override 117 private variable obj2id_ ;# maps dataobj => volume ID in server 118 private variable id2obj_ ;# maps dataobj => volume ID in server 119 private variable sendobjs_ "" ;# list of data objs to send to server 120 private variable receiveIds_ ;# list of data objs to send to server 121 private variable obj2styles_ ;# maps id => style settings 122 private variable style2ids_ ;# maps id => style settings 123 124 private variable click_ ;# info used for _rotate operations 125 private variable limits_ ;# autoscale min/max for all axes 126 private variable view_ ;# view params for 3D view 127 private variable isomarkers_ ;# array of isosurface level values 0..1 128 private common settings_ 129 private variable activeTf_ "" ;# The currently active transfer function. 100 private method ParseLevelsOption { tf levels } 101 private method ParseMarkersOption { tf markers } 102 103 private variable _outbuf ;# buffer for outgoing commands 104 105 private variable _dlist "" ;# list of data objects 106 private variable _allDataObjs 107 private variable _obj2ovride ;# maps dataobj => style override 108 private variable _obj2id ;# maps dataobj-component to volume ID 109 # in the server 110 private variable _id2obj ;# maps dataobj => volume ID in server 111 private variable _sendobjs "" ;# list of data objs to send to server 112 private variable _receiveIds ;# list of data objs to send to server 113 private variable _obj2style ;# maps dataobj-component to transfunc 114 private variable _style2objs ;# maps tf back to list of 115 # dataobj-components using the tf. 116 117 private variable _click ;# info used for rotate operations 118 private variable _limits ;# autoscale min/max for all axes 119 private variable _view ;# view params for 3D view 120 private variable _isomarkers ;# array of isosurface level values 0..1 121 private common _settings 122 private variable _activeTf "" ;# The currently active transfer function. 123 private variable _first "" ;# This is the topmost volume. 124 private variable _buffering 0 125 130 126 # This 131 127 # indicates which isomarkers and transfer 132 128 # function to use when changing markers, 133 129 # opacity, or thickness. 134 #common _downloadPopup ;# download options from popup135 private common hardcopy_136 private variable width_0137 private variable height_0130 common _downloadPopup ;# download options from popup 131 private common _hardcopy 132 private variable _width 0 133 private variable _height 0 138 134 } 139 135 … … 151 147 $_dispatcher register !legend 152 148 $_dispatcher dispatch $this !legend "[itcl::code $this FixLegend]; list" 149 153 150 # Send dataobjs event 154 151 $_dispatcher register !send_dataobjs 155 152 $_dispatcher dispatch $this !send_dataobjs \ 156 153 "[itcl::code $this SendDataObjs]; list" 154 157 155 # Send transfer functions event 158 156 $_dispatcher register !send_transfunc 159 157 $_dispatcher dispatch $this !send_transfunc \ 160 158 "[itcl::code $this SendTransferFuncs]; list" 159 161 160 # Rebuild event 162 161 $_dispatcher register !rebuild 163 162 $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" 164 163 165 # Draw legendevent164 # Resize event 166 165 $_dispatcher register !resize 167 166 $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list" 168 167 169 set outbuf_""168 set _outbuf "" 170 169 171 170 # … … 175 174 $_parser alias legend [itcl::code $this ReceiveLegend] 176 175 $_parser alias data [itcl::code $this ReceiveData] 177 #$_parser alias print [itcl::code $this ReceivePrint]178 176 179 177 # Initialize the view to some default parameters. 180 array set view_{178 array set _view { 181 179 theta 45 182 180 phi 45 … … 186 184 pan-y 0 187 185 } 188 set obj2id_(count) 0 189 set id2obj_(count) 0 190 set limits_(vmin) 0.0 191 set limits_(vmax) 1.0 192 193 set settings_($this-theta) $view_(theta) 194 set settings_($this-phi) $view_(phi) 195 set settings_($this-psi) $view_(psi) 196 set settings_($this-pan-x) $view_(pan-x) 197 set settings_($this-pan-y) $view_(pan-y) 198 set settings_($this-zoom) $view_(zoom) 186 set _obj2id(count) 0 187 set _id2obj(count) 0 188 set _limits(vmin) 0.0 189 set _limits(vmax) 1.0 190 191 array set _settings [subst { 192 $this-pan-x $_view(pan-x) 193 $this-pan-y $_view(pan-y) 194 $this-phi $_view(phi) 195 $this-psi $_view(psi) 196 $this-theta $_view(theta) 197 $this-volume 1 198 $this-xcutplane 0 199 $this-xcutposition 0 200 $this-ycutplane 0 201 $this-ycutposition 0 202 $this-zcutplane 0 203 $this-zcutposition 0 204 $this-zoom $_view(zoom) 205 }] 199 206 200 207 set f [$itk_component(main) component controls] … … 235 242 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" 236 243 237 #238 # Volume toggle...239 #240 244 itk_component add volume { 241 label $f.volume -borderwidth 1 -relief sunken \ 242 -image [Rappture::icon volume-on] 243 } 244 bind $itk_component(volume) <ButtonPress> \ 245 [itcl::code $this Slice volume toggle] 245 Rappture::PushButton $f.volume \ 246 -onimage [Rappture::icon volume-on] \ 247 -offimage [Rappture::icon volume-off] \ 248 -command [itcl::code $this FixSettings volume] \ 249 -variable [itcl::scope _settings($this-volume)] 250 } 251 $itk_component(volume) select 246 252 Rappture::Tooltip::for $itk_component(volume) \ 247 253 "Toggle the volume cloud on/off" 248 pack $itk_component(volume) - ipadx 1 -ipady 1 -padx 2 -pady 2254 pack $itk_component(volume) -padx 2 -pady 2 249 255 250 256 BuildViewTab … … 269 275 # size of the 3d view isn't set until an image is retrieved from 270 276 # the server. So the panewindow uses the tiny size. 271 set w [expr [winfo reqwidth $itk_component(hull)] - 80]277 set w 10000 272 278 pack forget $itk_component(3dview) 273 279 blt::table $itk_component(plotarea) \ 274 0,0 $itk_component(3dview) -fill both \280 0,0 $itk_component(3dview) -fill both -reqwidth $w \ 275 281 1,0 $itk_component(legend) -fill x 276 282 blt::table configure $itk_component(plotarea) r1 -resize none … … 337 343 # ---------------------------------------------------------------------- 338 344 itcl::body Rappture::NanovisViewer::destructor {} { 339 set sendobjs_"" ;# stop any send in progress345 set _sendobjs "" ;# stop any send in progress 340 346 $_dispatcher cancel !rebuild 341 347 $_dispatcher cancel !send_dataobjs … … 344 350 image delete $_image(legend) 345 351 image delete $_image(download) 346 array unset settings_$this-*352 array unset _settings $this-* 347 353 } 348 354 … … 375 381 } 376 382 377 set pos [lsearch -exact $dataobj $ dlist_]383 set pos [lsearch -exact $dataobj $_dlist] 378 384 if {$pos < 0} { 379 lappend dlist_$dataobj380 set allDataObjs_($dataobj) 1381 set obj2ovride_($dataobj-color) $params(-color)382 set obj2ovride_($dataobj-width) $params(-width)383 set obj2ovride_($dataobj-raise) $params(-raise)385 lappend _dlist $dataobj 386 set _allDataObjs($dataobj) 1 387 set _obj2ovride($dataobj-color) $params(-color) 388 set _obj2ovride($dataobj-width) $params(-width) 389 set _obj2ovride($dataobj-raise) $params(-raise) 384 390 $_dispatcher event -idle !rebuild 385 391 } … … 403 409 -objects { 404 410 # put the dataobj list in order according to -raise options 405 set dlist $ dlist_411 set dlist $_dlist 406 412 foreach obj $dlist { 407 if {[info exists obj2ovride_($obj-raise)] && $obj2ovride_($obj-raise)} {413 if {[info exists _obj2ovride($obj-raise)] && $_obj2ovride($obj-raise)} { 408 414 set i [lsearch -exact $dlist $obj] 409 415 if {$i >= 0} { … … 447 453 itcl::body Rappture::NanovisViewer::delete {args} { 448 454 if {[llength $args] == 0} { 449 set args $ dlist_455 set args $_dlist 450 456 } 451 457 # Delete all specified dataobjs 452 458 set changed 0 453 459 foreach dataobj $args { 454 set pos [lsearch -exact $ dlist_$dataobj]460 set pos [lsearch -exact $_dlist $dataobj] 455 461 if { $pos >= 0 } { 456 set dlist_ [lreplace $dlist_ $pos $pos] 457 foreach key [array names obj2ovride_ $dataobj-*] { 458 unset obj2ovride_($key) 459 } 462 foreach comp [$dataobj components] { 463 if { [info exists obj2id($dataobj-$comp)] } { 464 set ivol $_obj2id($dataobj-$comp) 465 array unset _limits $ivol-* 466 } 467 } 468 set _dlist [lreplace $_dlist $pos $pos] 469 array unset _obj2ovride $dataobj-* 470 array unset _obj2id $dataobj-* 471 array unset _obj2style $dataobj-* 460 472 set changed 1 461 473 } … … 463 475 # If anything changed, then rebuild the plot 464 476 if {$changed} { 477 # Repair the reverse lookup 478 foreach tf [array names _style2objs] { 479 set list {} 480 foreach {dataobj comp} $_style2objs($tf) break 481 if { [info exists _obj2id($dataobj-$comp)] } { 482 lappend list $dataobj $comp 483 } 484 if { $list == "" } { 485 array unset _style2objs $tf 486 } else { 487 set _style2objs($tf) $list 488 } 489 } 465 490 $_dispatcher event -idle !rebuild 466 491 } … … 478 503 itcl::body Rappture::NanovisViewer::scale {args} { 479 504 foreach val {xmin xmax ymin ymax zmin zmax vmin vmax} { 480 set limits_($val) ""505 set _limits($val) "" 481 506 } 482 507 foreach obj $args { … … 486 511 487 512 if {"" != $min && "" != $max} { 488 if {"" == $ limits_(${axis}min)} {489 set limits_(${axis}min) $min490 set limits_(${axis}max) $max513 if {"" == $_limits(${axis}min)} { 514 set _limits(${axis}min) $min 515 set _limits(${axis}max) $max 491 516 } else { 492 if {$min < $ limits_(${axis}min)} {493 set limits_(${axis}min) $min517 if {$min < $_limits(${axis}min)} { 518 set _limits(${axis}min) $min 494 519 } 495 if {$max > $ limits_(${axis}max)} {496 set limits_(${axis}max) $max520 if {$max > $_limits(${axis}max)} { 521 set _limits(${axis}max) $max 497 522 } 498 523 } … … 515 540 switch $option { 516 541 coming { 517 if {[catch {blt::winop snap $itk_component(plotarea) $_image(download)}]} { 542 if {[catch { 543 blt::winop snap $itk_component(plotarea) $_image(download) 544 }]} { 518 545 $_image(download) configure -width 1 -height 1 519 546 $_image(download) put #000000 … … 579 606 580 607 # disconnected -- no more data sitting on server 581 set outbuf_""582 catch {unset obj2id_}583 array unset id2obj_584 set obj2id_(count) 0585 set id2obj_(count) 0586 set sendobjs_""608 set _outbuf "" 609 catch {unset _obj2id} 610 array unset _id2obj 611 set _obj2id(count) 0 612 set _id2obj(count) 0 613 set _sendobjs "" 587 614 } 588 615 … … 595 622 # 596 623 itcl::body Rappture::NanovisViewer::SendCmd {string} { 597 if { [llength $sendobjs_] > 0} {598 append outbuf_$string "\n"624 if { $_buffering } { 625 append _outbuf $string "\n" 599 626 } else { 600 627 foreach line [split $string \n] { 601 628 SendEcho >>line $line 602 629 } 603 SendBytes $string630 SendBytes "$string\n" 604 631 } 605 632 } … … 614 641 itcl::body Rappture::NanovisViewer::SendDataObjs {} { 615 642 blt::busy hold $itk_component(hull); update idletasks 616 foreach dataobj $sendobjs_ { 643 644 foreach dataobj $_sendobjs { 617 645 foreach comp [$dataobj components] { 618 # send the data as one huge base64-encoded mess -- yuck!646 # Send the data as one huge base64-encoded mess -- yuck! 619 647 set data [$dataobj values $comp] 620 648 set nbytes [string length $data] 621 if { ![SendBytes "volume data follows $nbytes "] } {649 if { ![SendBytes "volume data follows $nbytes $dataobj-$comp\n"] } { 622 650 return 623 651 } … … 625 653 return 626 654 } 627 set ivol $obj2id_(count) 628 incr obj2id_(count) 629 630 set id2obj_($ivol) [list $dataobj $comp] 631 set obj2id_($dataobj-$comp) $ivol 632 NameTransferFunc $ivol 633 set receiveIds_($ivol) 1 634 } 635 } 636 set sendobjs_ "" 655 set ivol $_obj2id(count) 656 incr _obj2id(count) 657 NameTransferFunc $dataobj $comp 658 set _receiveIds($ivol) 1 659 } 660 } 661 set _sendobjs "" 637 662 blt::busy release $itk_component(hull) 638 663 664 # Turn on buffering of commands to the server. We don't want to 665 # be preempted by a server disconnect/reconnect (which automatically 666 # generates a new call to Rebuild). 667 set _buffering 1 668 639 669 # activate the proper volume 640 set first [lindex [get] 0]641 if {"" != $ first} {642 set axis [$ first hints updir]670 set _first [lindex [get] 0] 671 if {"" != $_first} { 672 set axis [$_first hints updir] 643 673 if {"" != $axis} { 644 674 SendCmd "up $axis" … … 647 677 # the first data object. This assumes that the data is always 648 678 # successfully transferred. 649 set comp [lindex [$first components] 0] 650 set activeTf_ $id2style_($obj2id_($first-$comp)) 651 } 652 foreach key [array names obj2id_ *-*] { 653 set state [string match $first-* $key] 654 set ivol $obj2id_($key) 655 SendCmd "volume state $state $ivol" 656 } 657 679 set comp [lindex [$_first components] 0] 680 set _activeTf [lindex $_obj2style($_first-$comp) 0] 681 } 682 SendCmd "volume state 0" 683 set vols {} 684 foreach key [array names _obj2id $_first-*] { 685 lappend vols $_obj2id($key) 686 } 687 if { $vols != "" && $_settings($this-volume) } { 688 SendCmd "volume state 1 $vols" 689 } 658 690 # sync the state of slicers 659 691 set vols [CurrentVolumeIds -cutplanes] 660 692 foreach axis {x y z} { 661 SendCmd "cutplane state [State ${axis}CutButton]$axis $vols"662 set pos [expr {0.01* [$itk_component(${axis}CutScale) get]}]693 SendCmd "cutplane state $_settings($this-${axis}cutplane) $axis $vols" 694 set pos [expr {0.01*$_settings($this-${axis}cutposition)}] 663 695 SendCmd "cutplane position $pos $axis $vols" 664 696 } 665 SendCmd "volume data state [State volume] $vols"666 697 667 698 if 0 { … … 674 705 SendCmd "grid axisname z Z eV" 675 706 } 676 # if there are any commands in the buffer, send them now that we're done 677 SendBytes $outbuf_ 678 set outbuf_ "" 707 708 # Actually write the commands to the server socket. If it fails, we don't 709 # care. We're finished here. 710 SendBytes $_outbuf; 711 set _buffering 0; # Turn off buffering. 712 set _outbuf ""; # Clear the buffer. 679 713 } 680 714 … … 683 717 # ---------------------------------------------------------------------- 684 718 itcl::body Rappture::NanovisViewer::SendTransferFuncs {} { 685 if { $ activeTf_== "" } {719 if { $_activeTf == "" } { 686 720 return 687 721 } 688 set tf $activeTf_ 689 set first [lindex [get] 0] 722 set tf $_activeTf 723 if { $_first == "" } { 724 return 725 } 690 726 691 727 # Insure that the global opacity and thickness settings (in the slider 692 728 # settings widgets) are used for the active transfer-function. Update the 693 # values in the settings_varible.694 set value $ settings_($this-opacity)729 # values in the _settings varible. 730 set value $_settings($this-opacity) 695 731 set opacity [expr { double($value) * 0.01 }] 696 set settings_($this-$tf-opacity) $opacity697 set value $ settings_($this-thickness)732 set _settings($this-$tf-opacity) $opacity 733 set value $_settings($this-thickness) 698 734 # Scale values between 0.00001 and 0.01000 699 735 set thickness [expr {double($value) * 0.0001}] 700 set settings_($this-$tf-thickness) $thickness 701 702 if { ![info exists $obj2styles_($first)] } { 703 foreach tf $obj2styles_($first) { 736 set _settings($this-$tf-thickness) $thickness 737 738 foreach key [array names _obj2style $_first-*] { 739 if { [info exists _obj2style($key)] } { 740 foreach tf $_obj2style($key) { 741 ComputeTransferFunc $tf 742 } 743 } 744 } 745 FixLegend 746 if 0 { 747 if { $first != "" && ![info exists _obj2style($_first)] } { 748 foreach tf $_obj2style($_first) { 704 749 ComputeTransferFunc $tf 705 750 } 706 751 $_dispatcher event -idle !legend 752 } 707 753 } 708 754 } … … 715 761 # specified <size> will follow. 716 762 # ---------------------------------------------------------------------- 717 set counter 0718 763 itcl::body Rappture::NanovisViewer::ReceiveImage { args } { 719 764 if { ![isconnected] } { 720 765 return 721 766 } 722 global counter723 incr counter724 767 array set info { 725 768 -token "???" … … 729 772 array set info $args 730 773 set bytes [ReceiveBytes $info(-bytes)] 731 ReceiveEcho <<line "<read $info(-bytes) bytes for [image width $_image(plot)]x[image height $_image(plot)] image>"774 ReceiveEcho <<line "<read $info(-bytes) bytes" 732 775 if { $info(-type) == "image" } { 776 ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>" 733 777 $_image(plot) configure -data $bytes 734 778 } elseif { $info(type) == "print" } { 735 779 set tag $this-print-$info(-token) 736 set hardcopy_($tag) $bytes780 set _hardcopy($tag) $bytes 737 781 } 738 782 } … … 762 806 set w [winfo width $c] 763 807 set h [winfo height $c] 764 #foreach { dataobj comp } $ id2obj_($ivol) break808 #foreach { dataobj comp } $_id2obj($ivol) break 765 809 set lx 10 766 810 set ly [expr {$h - 1}] … … 777 821 } 778 822 # Display the markers used by the active transfer function. 779 #set tf $ activeTf_823 #set tf $_activeTf 780 824 781 825 array set limits [limits $tf] … … 786 830 $c coords vmax [expr {$w-$lx}] $ly 787 831 788 if { [info exists isomarkers_($tf)] } {789 foreach m $ isomarkers_($tf) {832 if { [info exists _isomarkers($tf)] } { 833 foreach m $_isomarkers($tf) { 790 834 $m visible yes 791 835 } … … 802 846 # doesn't parse 3D data formats, we rely on the server (nanovis) to 803 847 # tell us what the limits are. Once we've received the limits to all 804 # the data we've sent (tracked by receiveIds_) we can then determine848 # the data we've sent (tracked by _receiveIds) we can then determine 805 849 # what the transfer functions are for these volumes. 806 850 # … … 822 866 823 867 set ivol $info(id); # Id of volume created by server. 824 825 set limits_($ivol-min) $info(min); # Minimum value of the volume. 826 set limits_($ivol-max) $info(max); # Maximum value of the volume. 827 set limits_(vmin) $info(vmin); # Overall minimum value. 828 set limits_(vmax) $info(vmax); # Overall maximum value. 829 830 unset receiveIds_($ivol) 831 if { [array size receiveIds_] == 0 } { 868 set tag $info(tag) 869 set parts [split $tag -] 870 871 # 872 # Volumes don't exist until we're told about them. 873 # 874 set _id2obj($ivol) $parts 875 set dataobj [lindex $parts 0] 876 set _obj2id($tag) $ivol 877 if { $_settings($this-volume) && $dataobj == $_first } { 878 SendCmd "volume state 1 $ivol" 879 } 880 set _limits($ivol-min) $info(min); # Minimum value of the volume. 881 set _limits($ivol-max) $info(max); # Maximum value of the volume. 882 set _limits(vmin) $info(vmin); # Overall minimum value. 883 set _limits(vmax) $info(vmax); # Overall maximum value. 884 885 unset _receiveIds($ivol) 886 if { [array size _receiveIds] == 0 } { 832 887 updatetransferfuncs 833 888 } … … 842 897 # ---------------------------------------------------------------------- 843 898 itcl::body Rappture::NanovisViewer::Rebuild {} { 899 844 900 # Hide all the isomarkers. Can't remove them. Have to remember the 845 901 # settings since the user may have created/deleted/moved markers. 846 902 847 foreach tf [array names isomarkers_] {848 foreach m $ isomarkers_($tf) {903 foreach tf [array names _isomarkers] { 904 foreach m $_isomarkers($tf) { 849 905 $m visible no 850 906 } … … 852 908 853 909 # in the midst of sending data? then bail out 854 if {[llength $ sendobjs_] > 0} {910 if {[llength $_sendobjs] > 0} { 855 911 return 856 912 } 857 913 914 # Turn on buffering of commands to the server. We don't want to 915 # be preempted by a server disconnect/reconnect (which automatically 916 # generates a new call to Rebuild). 917 set _buffering 1 918 858 919 # Find any new data that needs to be sent to the server. Queue this up on 859 # the sendobjs_list, and send it out a little at a time. Do this first,920 # the _sendobjs list, and send it out a little at a time. Do this first, 860 921 # before we rebuild the rest. 861 922 foreach dataobj [get] { 862 923 set comp [lindex [$dataobj components] 0] 863 if {![info exists obj2id_($dataobj-$comp)]} {864 set i [lsearch -exact $ sendobjs_$dataobj]924 if {![info exists _obj2id($dataobj-$comp)]} { 925 set i [lsearch -exact $_sendobjs $dataobj] 865 926 if {$i < 0} { 866 lappend sendobjs_$dataobj927 lappend _sendobjs $dataobj 867 928 } 868 929 } … … 875 936 # Reset the camera and other view parameters 876 937 # 877 set xyz [Euler2XYZ $ view_(theta) $view_(phi) $view_(psi)]938 set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] 878 939 SendCmd "camera angle $xyz" 879 SendCmd "camera zoom $view_(zoom)" 880 881 set settings_($this-theta) $view_(theta) 882 set settings_($this-phi) $view_(phi) 883 set settings_($this-psi) $view_(psi) 884 set settings_($this-pan-x) $view_(pan-x) 885 set settings_($this-pan-y) $view_(pan-y) 886 set settings_($this-zoom) $view_(zoom) 940 PanCamera 941 SendCmd "camera zoom $_view(zoom)" 942 943 set _settings($this-theta) $_view(theta) 944 set _settings($this-phi) $_view(phi) 945 set _settings($this-psi) $_view(psi) 946 set _settings($this-pan-x) $_view(pan-x) 947 set _settings($this-pan-y) $_view(pan-y) 948 set _settings($this-zoom) $_view(zoom) 887 949 888 950 FixSettings light … … 893 955 FixSettings outline 894 956 895 if {[llength $ sendobjs_] > 0} {957 if {[llength $_sendobjs] > 0} { 896 958 # send off new data objects 897 959 $_dispatcher event -idle !send_dataobjs … … 900 962 901 963 # nothing to send -- activate the proper ivol 902 set first [lindex [get] 0]903 if {"" != $ first} {904 set axis [$ first hints updir]964 set _first [lindex [get] 0] 965 if {"" != $_first} { 966 set axis [$_first hints updir] 905 967 if {"" != $axis} { 906 968 SendCmd "up $axis" 907 969 } 908 foreach key [array names obj2id_*-*] {909 set state [string match $ first-* $key]910 SendCmd "volume state $state $ obj2id_($key)"970 foreach key [array names _obj2id *-*] { 971 set state [string match $_first-* $key] 972 SendCmd "volume state $state $_obj2id($key)" 911 973 } 912 974 # 913 # The obj2id_ and id2style_arrays may or may not have the right975 # The _obj2id and _id2style arrays may or may not have the right 914 976 # information. It's possible for the server to know about volumes 915 977 # that the client has assumed it's deleted. We could add checks. 916 978 # But this problem needs to be fixed not bandaided. 917 set comp [lindex [$first components] 0] 918 set ivol $obj2id_($first-$comp) 919 920 foreach comp [$first components] { 921 foreach ivol $obj2id_($first-$comp) { 922 NameTransferFunc $ivol 923 } 979 set comp [lindex [$_first components] 0] 980 set ivol $_obj2id($_first-$comp) 981 982 foreach comp [$_first components] { 983 NameTransferFunc $_first $comp 924 984 } 925 985 } … … 928 988 set vols [CurrentVolumeIds -cutplanes] 929 989 foreach axis {x y z} { 930 SendCmd "cutplane state [State ${axis}CutButton]$axis $vols"931 set pos [expr {0.01* [$itk_component(${axis}CutScale) get]}]990 SendCmd "cutplane state $_settings($this-${axis}cutplane) $axis $vols" 991 set pos [expr {0.01*$_settings($this-${axis}cutposition)}] 932 992 SendCmd "cutplane position $pos $axis $vols" 933 993 } 934 SendCmd "volume data state [State volume]$vols"994 SendCmd "volume data state $_settings($this-volume) $vols" 935 995 $_dispatcher event -idle !legend 996 997 # Actually write the commands to the server socket. If it fails, we don't 998 # care. We're finished here. 999 SendBytes $_outbuf; 1000 set _buffering 0; # Turn off buffering. 1001 set _outbuf ""; # Clear the buffer. 936 1002 } 937 1003 … … 945 1011 itcl::body Rappture::NanovisViewer::CurrentVolumeIds {{what -all}} { 946 1012 set rlist "" 947 948 set first [lindex [get] 0] 949 foreach key [array names obj2id_ *-*] { 950 if {[string match $first-* $key]} { 1013 if { $_first == "" } { 1014 return 1015 } 1016 foreach key [array names _obj2id *-*] { 1017 if {[string match $_first-* $key]} { 951 1018 array set style { 952 1019 -cutplanes 1 … … 956 1023 957 1024 if {$what != "-cutplanes" || $style(-cutplanes)} { 958 lappend rlist $ obj2id_($key)1025 lappend rlist $_obj2id($key) 959 1026 } 960 1027 } … … 974 1041 switch -- $option { 975 1042 "in" { 976 set view_(zoom) [expr {$view_(zoom)*1.25}]977 set settings_($this-zoom) $view_(zoom)1043 set _view(zoom) [expr {$_view(zoom)*1.25}] 1044 set _settings($this-zoom) $_view(zoom) 978 1045 } 979 1046 "out" { 980 set view_(zoom) [expr {$view_(zoom)*0.8}]981 set settings_($this-zoom) $view_(zoom)1047 set _view(zoom) [expr {$_view(zoom)*0.8}] 1048 set _settings($this-zoom) $_view(zoom) 982 1049 } 983 1050 "reset" { 984 array set view_{1051 array set _view { 985 1052 theta 45 986 1053 phi 45 … … 990 1057 pan-y 0 991 1058 } 992 set first [lindex [get] 0] 993 if { $first != "" } { 994 set location [$first hints camera] 1059 if { $_first != "" } { 1060 set location [$_first hints camera] 995 1061 if { $location != "" } { 996 array set view_$location1062 array set _view $location 997 1063 } 998 1064 } 999 set xyz [Euler2XYZ $ view_(theta) $view_(phi) $view_(psi)]1065 set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] 1000 1066 SendCmd "camera angle $xyz" 1001 1067 PanCamera 1002 set settings_($this-theta) $view_(theta)1003 set settings_($this-phi) $view_(phi)1004 set settings_($this-psi) $view_(psi)1005 set settings_($this-pan-x) $view_(pan-x)1006 set settings_($this-pan-y) $view_(pan-y)1007 set settings_($this-zoom) $view_(zoom)1068 set _settings($this-theta) $_view(theta) 1069 set _settings($this-phi) $_view(phi) 1070 set _settings($this-psi) $_view(psi) 1071 set _settings($this-pan-x) $_view(pan-x) 1072 set _settings($this-pan-y) $_view(pan-y) 1073 set _settings($this-zoom) $_view(zoom) 1008 1074 } 1009 1075 } 1010 SendCmd "camera zoom $ view_(zoom)"1076 SendCmd "camera zoom $_view(zoom)" 1011 1077 } 1012 1078 1013 1079 itcl::body Rappture::NanovisViewer::PanCamera {} { 1014 #set x [expr ($ view_(pan-x)) / $limits_(xrange)]1015 #set y [expr ($ view_(pan-y)) / $limits_(yrange)]1016 set x $ view_(pan-x)1017 set y $ view_(pan-y)1080 #set x [expr ($_view(pan-x)) / $_limits(xrange)] 1081 #set y [expr ($_view(pan-y)) / $_limits(yrange)] 1082 set x $_view(pan-x) 1083 set y $_view(pan-y) 1018 1084 SendCmd "camera pan $x $y" 1019 1085 } … … 1032 1098 click { 1033 1099 $itk_component(3dview) configure -cursor fleur 1034 set click_(x) $x1035 set click_(y) $y1036 set click_(theta) $view_(theta)1037 set click_(phi) $view_(phi)1100 set _click(x) $x 1101 set _click(y) $y 1102 set _click(theta) $_view(theta) 1103 set _click(phi) $_view(phi) 1038 1104 } 1039 1105 drag { 1040 if {[array size click_] == 0} {1106 if {[array size _click] == 0} { 1041 1107 Rotate click $x $y 1042 1108 } else { … … 1049 1115 if {[catch { 1050 1116 # this fails sometimes for no apparent reason 1051 set dx [expr {double($x-$ click_(x))/$w}]1052 set dy [expr {double($y-$ click_(y))/$h}]1117 set dx [expr {double($x-$_click(x))/$w}] 1118 set dy [expr {double($y-$_click(y))/$h}] 1053 1119 }]} { 1054 1120 return … … 1058 1124 # Rotate the camera in 3D 1059 1125 # 1060 if {$ view_(psi) > 90 || $view_(psi) < -90} {1126 if {$_view(psi) > 90 || $_view(psi) < -90} { 1061 1127 # when psi is flipped around, theta moves backwards 1062 1128 set dy [expr {-$dy}] 1063 1129 } 1064 set theta [expr {$ view_(theta) - $dy*180}]1130 set theta [expr {$_view(theta) - $dy*180}] 1065 1131 while {$theta < 0} { set theta [expr {$theta+180}] } 1066 1132 while {$theta > 180} { set theta [expr {$theta-180}] } 1067 1133 1068 1134 if {abs($theta) >= 30 && abs($theta) <= 160} { 1069 set phi [expr {$ view_(phi) - $dx*360}]1135 set phi [expr {$_view(phi) - $dx*360}] 1070 1136 while {$phi < 0} { set phi [expr {$phi+360}] } 1071 1137 while {$phi > 360} { set phi [expr {$phi-360}] } 1072 set psi $ view_(psi)1138 set psi $_view(psi) 1073 1139 } else { 1074 set phi $ view_(phi)1075 set psi [expr {$ view_(psi) - $dx*360}]1140 set phi $_view(phi) 1141 set psi [expr {$_view(psi) - $dx*360}] 1076 1142 while {$psi < -180} { set psi [expr {$psi+360}] } 1077 1143 while {$psi > 180} { set psi [expr {$psi-360}] } 1078 1144 } 1079 1145 1080 set view_(theta) $theta1081 set view_(phi) $phi1082 set view_(psi) $psi1146 set _view(theta) $theta 1147 set _view(phi) $phi 1148 set _view(psi) $psi 1083 1149 set xyz [Euler2XYZ $theta $phi $psi] 1084 set settings_($this-theta) $view_(theta)1085 set settings_($this-phi) $view_(phi)1086 set settings_($this-psi) $view_(psi)1150 set _settings($this-theta) $_view(theta) 1151 set _settings($this-phi) $_view(phi) 1152 set _settings($this-psi) $_view(psi) 1087 1153 SendCmd "camera angle $xyz" 1088 set click_(x) $x1089 set click_(y) $y1154 set _click(x) $x 1155 set _click(y) $y 1090 1156 } 1091 1157 } … … 1093 1159 Rotate drag $x $y 1094 1160 $itk_component(3dview) configure -cursor "" 1095 catch {unset click_}1161 catch {unset _click} 1096 1162 } 1097 1163 default { … … 1116 1182 set x [expr $x / double($w)] 1117 1183 set y [expr $y / double($h)] 1118 set view_(pan-x) [expr $view_(pan-x) + $x]1119 set view_(pan-y) [expr $view_(pan-y) + $y]1184 set _view(pan-x) [expr $_view(pan-x) + $x] 1185 set _view(pan-y) [expr $_view(pan-y) + $y] 1120 1186 PanCamera 1121 set settings_($this-pan-x) $view_(pan-x)1122 set settings_($this-pan-y) $view_(pan-y)1187 set _settings($this-pan-x) $_view(pan-x) 1188 set _settings($this-pan-y) $_view(pan-y) 1123 1189 return 1124 1190 } 1125 1191 if { $option == "click" } { 1126 set click_(x) $x1127 set click_(y) $y1192 set _click(x) $x 1193 set _click(y) $y 1128 1194 $itk_component(3dview) configure -cursor hand1 1129 1195 } 1130 1196 if { $option == "drag" || $option == "release" } { 1131 set dx [expr ($ click_(x) - $x)/double($w)]1132 set dy [expr ($ click_(y) - $y)/double($h)]1133 set click_(x) $x1134 set click_(y) $y1135 set view_(pan-x) [expr $view_(pan-x) - $dx]1136 set view_(pan-y) [expr $view_(pan-y) - $dy]1197 set dx [expr ($_click(x) - $x)/double($w)] 1198 set dy [expr ($_click(y) - $y)/double($h)] 1199 set _click(x) $x 1200 set _click(y) $y 1201 set _view(pan-x) [expr $_view(pan-x) - $dx] 1202 set _view(pan-y) [expr $_view(pan-y) - $dy] 1137 1203 PanCamera 1138 set settings_($this-pan-x) $view_(pan-x)1139 set settings_($this-pan-y) $view_(pan-y)1204 set _settings($this-pan-x) $_view(pan-x) 1205 set _settings($this-pan-y) $_view(pan-y) 1140 1206 } 1141 1207 if { $option == "release" } { 1142 1208 $itk_component(3dview) configure -cursor "" 1143 1209 } 1144 }1145 1146 # ----------------------------------------------------------------------1147 # USAGE: State <component>1148 #1149 # Used internally to determine the state of a toggle button.1150 # The <component> is the itk component name of the button.1151 # Returns on/off for the state of the button.1152 # ----------------------------------------------------------------------1153 itcl::body Rappture::NanovisViewer::State { comp } {1154 if {[$itk_component(${comp}) cget -relief] == "sunken"} {1155 return "on"1156 }1157 return "off"1158 1210 } 1159 1211 … … 1169 1221 light { 1170 1222 if {[isconnected]} { 1171 set val $ settings_($this-light)1223 set val $_settings($this-light) 1172 1224 set sval [expr {0.1*$val}] 1173 1225 SendCmd "volume shading diffuse $sval" … … 1178 1230 transp { 1179 1231 if {[isconnected]} { 1180 set val $ settings_($this-transp)1232 set val $_settings($this-transp) 1181 1233 set sval [expr {0.2*$val+1}] 1182 1234 SendCmd "volume shading opacity $sval" … … 1184 1236 } 1185 1237 opacity { 1186 if {[isconnected] && $ activeTf_!= "" } {1187 set val $ settings_($this-opacity)1238 if {[isconnected] && $_activeTf != "" } { 1239 set val $_settings($this-opacity) 1188 1240 set sval [expr { 0.01 * double($val) }] 1189 set tf $ activeTf_1190 set settings_($this-$tf-opacity) $sval1241 set tf $_activeTf 1242 set _settings($this-$tf-opacity) $sval 1191 1243 updatetransferfuncs 1192 1244 } … … 1194 1246 1195 1247 thickness { 1196 if {[isconnected] && $ activeTf_!= "" } {1197 set val $ settings_($this-thickness)1248 if {[isconnected] && $_activeTf != "" } { 1249 set val $_settings($this-thickness) 1198 1250 # Scale values between 0.00001 and 0.01000 1199 1251 set sval [expr {0.0001*double($val)}] 1200 set tf $ activeTf_1201 set settings_($this-$tf-thickness) $sval1252 set tf $_activeTf 1253 set _settings($this-$tf-thickness) $sval 1202 1254 updatetransferfuncs 1203 1255 } … … 1205 1257 "outline" { 1206 1258 if {[isconnected]} { 1207 SendCmd "volume outline state $ settings_($this-outline)"1259 SendCmd "volume outline state $_settings($this-outline)" 1208 1260 } 1209 1261 } 1210 1262 "isosurface" { 1211 1263 if {[isconnected]} { 1212 SendCmd "volume shading isosurface $ settings_($this-isosurface)"1264 SendCmd "volume shading isosurface $_settings($this-isosurface)" 1213 1265 } 1214 1266 } 1215 1267 "grid" { 1216 1268 if { [isconnected] } { 1217 SendCmd "grid visible $ settings_($this-grid)"1269 SendCmd "grid visible $_settings($this-grid)" 1218 1270 } 1219 1271 } 1220 1272 "axes" { 1221 1273 if { [isconnected] } { 1222 SendCmd "axis visible $ settings_($this-axes)"1274 SendCmd "axis visible $_settings($this-axes)" 1223 1275 } 1224 1276 } 1225 1277 "legend" { 1226 if { $ settings_($this-legend) } {1278 if { $_settings($this-legend) } { 1227 1279 blt::table $itk_component(plotarea) \ 1228 1280 0,0 $itk_component(3dview) -fill both \ … … 1234 1286 } 1235 1287 "volume" { 1236 Slice volume $settings_($this-volume) 1288 if { [isconnected] } { 1289 set vols [CurrentVolumeIds -cutplanes] 1290 SendCmd "volume data state $_settings($this-volume) $vols" 1291 } 1292 } 1293 "xcutplane" - "ycutplane" - "zcutplane" { 1294 set axis [string range $what 0 1] 1295 set bool $_settings($this-$what) 1296 if { [isconnected] } { 1297 set vols [CurrentVolumeIds -cutplanes] 1298 SendCmd "cutplane state $bool $axis $vols" 1299 } 1300 if { $bool } { 1301 $itk_component(${axis}CutScale) configure -state normal \ 1302 -troughcolor white 1303 } else { 1304 $itk_component(${axis}CutScale) configure -state disabled \ 1305 -troughcolor grey82 1306 } 1237 1307 } 1238 1308 default { … … 1251 1321 itcl::body Rappture::NanovisViewer::FixLegend {} { 1252 1322 set lineht [font metrics $itk_option(-font) -linespace] 1253 set w [expr {$ width_-20}]1323 set w [expr {$_width-20}] 1254 1324 set h [expr {[winfo height $itk_component(legend)]-20-$lineht}] 1255 if {$w > 0 && $h > 0 && "" != $ activeTf_} {1256 SendCmd "legend $ activeTf_$w $h"1325 if {$w > 0 && $h > 0 && "" != $_activeTf} { 1326 SendCmd "legend $_activeTf $w $h" 1257 1327 } else { 1258 1328 # Can't do this as this will remove the items associated with the … … 1278 1348 # now. 1279 1349 # 1280 itcl::body Rappture::NanovisViewer::NameTransferFunc { ivol} {1350 itcl::body Rappture::NanovisViewer::NameTransferFunc { dataobj comp } { 1281 1351 array set style { 1282 1352 -color rainbow … … 1284 1354 -opacity 1.0 1285 1355 } 1286 foreach {dataobj comp} $id2obj_($ivol) break1287 1356 array set style [lindex [$dataobj components -style $comp] 0] 1288 1357 set tf "$style(-color):$style(-levels):$style(-opacity)" 1289 1290 set id2style_($ivol) $tf 1291 lappend obj2styles_($dataobj) $tf 1292 lappend style2ids_($tf) $ivol 1358 lappend _obj2style($dataobj-$comp) $tf 1359 lappend _style2objs($tf) $dataobj $comp 1360 return $tf 1293 1361 } 1294 1362 … … 1309 1377 } 1310 1378 set dataobj ""; set comp "" 1311 foreach ivol $style2ids_($tf) { 1312 if { [info exists id2obj_($ivol)] } { 1313 foreach {dataobj comp} $id2obj_($ivol) break 1314 break 1315 } 1316 } 1379 foreach {dataobj comp} $_style2objs($tf) break 1317 1380 if { $dataobj == "" } { 1318 1381 return 0 1319 1382 } 1320 1383 array set style [lindex [$dataobj components -style $comp] 0] … … 1334 1397 # barn on this one. 1335 1398 1336 if { ![info exists isomarkers_($tf)] } {1399 if { ![info exists _isomarkers($tf)] } { 1337 1400 # Have to defer creation of isomarkers until we have data limits 1338 1401 if { [info exists style(-markers)] } { 1339 ParseMarkersOption $tf $ ivol $style(-markers)1402 ParseMarkersOption $tf $style(-markers) 1340 1403 } else { 1341 ParseLevelsOption $tf $ ivol $style(-levels)1404 ParseLevelsOption $tf $style(-levels) 1342 1405 } 1343 1406 } … … 1355 1418 1356 1419 set tag $this-$tf 1357 if { ![info exists settings_($tag-opacity)] } {1358 set settings_($tag-opacity) $style(-opacity)1359 } 1360 set max $ settings_($tag-opacity)1420 if { ![info exists _settings($tag-opacity)] } { 1421 set _settings($tag-opacity) $style(-opacity) 1422 } 1423 set max $_settings($tag-opacity) 1361 1424 1362 1425 set isovalues {} 1363 foreach m $ isomarkers_($tf) {1426 foreach m $_isomarkers($tf) { 1364 1427 lappend isovalues [$m relval] 1365 1428 } … … 1367 1430 set isovalues [lsort -real $isovalues] 1368 1431 1369 if { ![info exists settings_($tag-thickness)]} {1370 set settings_($tag-thickness) 0.051371 } 1372 set delta $ settings_($tag-thickness)1432 if { ![info exists _settings($tag-thickness)]} { 1433 set _settings($tag-thickness) 0.05 1434 } 1435 set delta $_settings($tag-thickness) 1373 1436 1374 1437 set first [lindex $isovalues 0] … … 1413 1476 } 1414 1477 SendBytes "transfunc define $tf { $cmap } { $wmap }\n" 1415 return [SendBytes "volume shading transfunc $tf $style2ids_($tf)\n"] 1478 if { [info exists _obj2id($dataobj-$comp)] } { 1479 return [SendBytes "volume shading transfunc $tf $_obj2id($dataobj-$comp)\n"] 1480 } 1416 1481 } 1417 1482 … … 1461 1526 # marker is a relative value from 0.0 to 1.0. 1462 1527 # 1463 itcl::body Rappture::NanovisViewer::ParseLevelsOption { tf ivollevels } {1528 itcl::body Rappture::NanovisViewer::ParseLevelsOption { tf levels } { 1464 1529 set c $itk_component(legend) 1465 1530 regsub -all "," $levels " " levels … … 1467 1532 for {set i 1} { $i <= $levels } {incr i} { 1468 1533 set x [expr {double($i)/($levels+1)}] 1469 set m [ IsoMarker \#auto $c $this $tf]1534 set m [Rappture::IsoMarker \#auto $c $this $tf] 1470 1535 $m relval $x 1471 lappend isomarkers_($tf) $m1536 lappend _isomarkers($tf) $m 1472 1537 } 1473 1538 } else { 1474 1539 foreach x $levels { 1475 set m [ IsoMarker \#auto $c $this $tf]1540 set m [Rappture::IsoMarker \#auto $c $this $tf] 1476 1541 $m relval $x 1477 lappend isomarkers_($tf) $m1542 lappend _isomarkers($tf) $m 1478 1543 } 1479 1544 } … … 1492 1557 # not be seen. 1493 1558 # 1494 itcl::body Rappture::NanovisViewer::ParseMarkersOption { tf ivolmarkers } {1559 itcl::body Rappture::NanovisViewer::ParseMarkersOption { tf markers } { 1495 1560 set c $itk_component(legend) 1496 1561 regsub -all "," $markers " " markers … … 1500 1565 # ${n}% : Set relative value. 1501 1566 set value [expr {$value * 0.01}] 1502 set m [ IsoMarker \#auto $c $this $tf]1567 set m [Rappture::IsoMarker \#auto $c $this $tf] 1503 1568 $m relval $value 1504 lappend isomarkers_($tf) $m1569 lappend _isomarkers($tf) $m 1505 1570 } else { 1506 1571 # ${n} : Set absolute value. 1507 set m [ IsoMarker \#auto $c $this $tf]1572 set m [Rappture::IsoMarker \#auto $c $this $tf] 1508 1573 $m absval $value 1509 lappend isomarkers_($tf) $m 1510 } 1511 } 1512 } 1513 1514 # ---------------------------------------------------------------------- 1515 # USAGE: Marker start <x> <y> 1516 # USAGE: Marker update <x> <y> 1517 # USAGE: Marker end <x> <y> 1518 # 1519 # Used internally to handle the various marker operations performed 1520 # when the user clicks and drags on the legend area. The marker changes the 1521 # transfer function to highlight the area being selected in the 1522 # legend. 1574 lappend _isomarkers($tf) $m 1575 } 1576 } 1577 } 1578 1579 # ---------------------------------------------------------------------- 1580 # USAGE: UndateTransferFuncs 1523 1581 # ---------------------------------------------------------------------- 1524 1582 itcl::body Rappture::NanovisViewer::updatetransferfuncs {} { … … 1527 1585 1528 1586 itcl::body Rappture::NanovisViewer::AddIsoMarker { x y } { 1529 if { $ activeTf_== "" } {1587 if { $_activeTf == "" } { 1530 1588 error "active transfer function isn't set" 1531 1589 } 1532 set tf $ activeTf_1590 set tf $_activeTf 1533 1591 set c $itk_component(legend) 1534 set m [ IsoMarker \#auto $c $this $tf]1592 set m [Rappture::IsoMarker \#auto $c $this $tf] 1535 1593 set w [winfo width $c] 1536 1594 $m relval [expr {double($x-10)/($w-20)}] 1537 lappend isomarkers_($tf) $m1595 lappend _isomarkers($tf) $m 1538 1596 updatetransferfuncs 1539 1597 return 1 … … 1543 1601 set tf [$marker transferfunc] 1544 1602 set bool 0 1545 if { [info exists isomarkers_($tf)] } {1603 if { [info exists _isomarkers($tf)] } { 1546 1604 set list {} 1547 1605 set marker [namespace tail $marker] 1548 foreach m $ isomarkers_($tf) {1606 foreach m $_isomarkers($tf) { 1549 1607 set sx [$m screenpos] 1550 1608 if { $m != $marker } { … … 1559 1617 lappend list $m 1560 1618 } 1561 set isomarkers_($tf) $list1619 set _isomarkers($tf) $list 1562 1620 updatetransferfuncs 1563 1621 } … … 1567 1625 itcl::body Rappture::NanovisViewer::overmarker { marker x } { 1568 1626 set tf [$marker transferfunc] 1569 if { [info exists isomarkers_($tf)] } {1627 if { [info exists _isomarkers($tf)] } { 1570 1628 set marker [namespace tail $marker] 1571 foreach m $ isomarkers_($tf) {1629 foreach m $_isomarkers($tf) { 1572 1630 set sx [$m screenpos] 1573 1631 if { $m != $marker } { … … 1581 1639 1582 1640 itcl::body Rappture::NanovisViewer::limits { tf } { 1583 set limits_(min) "" 1584 set limits_(max) "" 1585 foreach ivol $style2ids_($tf) { 1586 if { ![info exists limits_($ivol-min)] } { 1587 # I assume this is after a clear. 1588 # error "can't find $ivol limits" 1641 set _limits(min) 0.0 1642 set _limits(max) 1.0 1643 if { ![info exists _style2objs($tf)] } { 1644 return [array get _limits] 1645 } 1646 set min ""; set max "" 1647 foreach {dataobj comp} $_style2objs($tf) { 1648 if { ![info exists _obj2id($dataobj-$comp)] } { 1589 1649 continue 1590 1650 } 1591 if { $limits_(min) == "" || $limits_(min) > $limits_($ivol-min) } { 1592 set limits_(min) $limits_($ivol-min) 1593 } 1594 if { $limits_(max) == "" || $limits_(max) < $limits_($ivol-max) } { 1595 set limits_(max) $limits_($ivol-max) 1596 } 1597 } 1598 return [array get limits_] 1651 set ivol $_obj2id($dataobj-$comp) 1652 if { ![info exists _limits($ivol-min)] } { 1653 continue 1654 } 1655 if { $min == "" || $min > $_limits($ivol-min) } { 1656 set min $_limits($ivol-min) 1657 } 1658 if { $max == "" || $max < $_limits($ivol-max) } { 1659 set max $_limits($ivol-max) 1660 } 1661 } 1662 if { $min != "" } { 1663 set _limits(min) $min 1664 } 1665 if { $max != "" } { 1666 set _limits(max) $max 1667 } 1668 return [array get _limits] 1599 1669 } 1600 1670 … … 1610 1680 lic 1 1611 1681 } { 1612 set settings_($this-$key) $value1682 set _settings($this-$key) $value 1613 1683 } 1614 1684 … … 1621 1691 $inner configure -borderwidth 4 1622 1692 1623 set ::Rappture::NanovisViewer:: settings_($this-isosurface) 01693 set ::Rappture::NanovisViewer::_settings($this-isosurface) 0 1624 1694 checkbutton $inner.isosurface \ 1625 1695 -text "Isosurface shading" \ 1626 -variable [itcl::scope settings_($this-isosurface)] \1696 -variable [itcl::scope _settings($this-isosurface)] \ 1627 1697 -command [itcl::code $this FixSettings isosurface] \ 1628 1698 -font "Arial 9" … … 1630 1700 checkbutton $inner.axes \ 1631 1701 -text "Axes" \ 1632 -variable [itcl::scope settings_($this-axes)] \1702 -variable [itcl::scope _settings($this-axes)] \ 1633 1703 -command [itcl::code $this FixSettings axes] \ 1634 1704 -font "Arial 9" … … 1636 1706 checkbutton $inner.grid \ 1637 1707 -text "Grid" \ 1638 -variable [itcl::scope settings_($this-grid)] \1708 -variable [itcl::scope _settings($this-grid)] \ 1639 1709 -command [itcl::code $this FixSettings grid] \ 1640 1710 -font "Arial 9" … … 1642 1712 checkbutton $inner.outline \ 1643 1713 -text "Outline" \ 1644 -variable [itcl::scope settings_($this-outline)] \1714 -variable [itcl::scope _settings($this-outline)] \ 1645 1715 -command [itcl::code $this FixSettings outline] \ 1646 1716 -font "Arial 9" … … 1648 1718 checkbutton $inner.legend \ 1649 1719 -text "Legend" \ 1650 -variable [itcl::scope settings_($this-legend)] \1720 -variable [itcl::scope _settings($this-legend)] \ 1651 1721 -command [itcl::code $this FixSettings legend] \ 1652 1722 -font "Arial 9" … … 1654 1724 checkbutton $inner.volume \ 1655 1725 -text "Volume" \ 1656 -variable [itcl::scope settings_($this-volume)] \1726 -variable [itcl::scope _settings($this-volume)] \ 1657 1727 -command [itcl::code $this FixSettings volume] \ 1658 1728 -font "Arial 9" … … 1676 1746 thickness 350 1677 1747 } { 1678 set settings_($this-$key) $value1748 set _settings($this-$key) $value 1679 1749 } 1680 1750 … … 1688 1758 1689 1759 checkbutton $inner.vol -text "Show volume" -font $fg \ 1690 -variable [itcl::scope settings_($this-volume)] \1760 -variable [itcl::scope _settings($this-volume)] \ 1691 1761 -command [itcl::code $this FixSettings volume] 1692 1762 label $inner.shading -text "Shading:" -font $fg … … 1694 1764 label $inner.dim -text "Dim" -font $fg 1695 1765 ::scale $inner.light -from 0 -to 100 -orient horizontal \ 1696 -variable [itcl::scope settings_($this-light)] \1766 -variable [itcl::scope _settings($this-light)] \ 1697 1767 -width 10 \ 1698 1768 -showvalue off -command [itcl::code $this FixSettings light] … … 1701 1771 label $inner.fog -text "Fog" -font $fg 1702 1772 ::scale $inner.transp -from 0 -to 100 -orient horizontal \ 1703 -variable [itcl::scope settings_($this-transp)] \1773 -variable [itcl::scope _settings($this-transp)] \ 1704 1774 -width 10 \ 1705 1775 -showvalue off -command [itcl::code $this FixSettings transp] … … 1708 1778 label $inner.clear -text "Clear" -font $fg 1709 1779 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1710 -variable [itcl::scope settings_($this-opacity)] \1780 -variable [itcl::scope _settings($this-opacity)] \ 1711 1781 -width 10 \ 1712 1782 -showvalue off -command [itcl::code $this FixSettings opacity] … … 1715 1785 label $inner.thin -text "Thin" -font $fg 1716 1786 ::scale $inner.thickness -from 0 -to 1000 -orient horizontal \ 1717 -variable [itcl::scope settings_($this-thickness)] \1787 -variable [itcl::scope _settings($this-thickness)] \ 1718 1788 -width 10 \ 1719 1789 -showvalue off -command [itcl::code $this FixSettings thickness] … … 1748 1818 # X-value slicer... 1749 1819 itk_component add xCutButton { 1750 label $inner.xbutton \ 1751 -borderwidth 1 -relief raised -padx 1 -pady 1 \ 1752 -image [Rappture::icon x-cutplane-off] \ 1753 -highlightthickness 0 1754 } { 1755 usual 1756 ignore -borderwidth -highlightthickness -font 1757 } 1758 bind $itk_component(xCutButton) <ButtonPress> \ 1759 [itcl::code $this Slice axis x toggle] 1820 Rappture::PushButton $inner.xbutton \ 1821 -onimage [Rappture::icon x-cutplane-on] \ 1822 -offimage [Rappture::icon x-cutplane-off] \ 1823 -command [itcl::code $this FixSettings xcutplane] \ 1824 -variable [itcl::scope _settings($this-xcutplane)] 1825 } 1760 1826 Rappture::Tooltip::for $itk_component(xCutButton) \ 1761 1827 "Toggle the X cut plane on/off" … … 1765 1831 -width 10 -orient vertical -showvalue off \ 1766 1832 -borderwidth 1 -highlightthickness 0 \ 1767 -command [itcl::code $this Slice move x] 1833 -command [itcl::code $this Slice move x] \ 1834 -variable [itcl::scope _settings($this-xcutposition)] 1768 1835 } { 1769 1836 usual … … 1778 1845 # Y-value slicer... 1779 1846 itk_component add yCutButton { 1780 label $inner.ybutton \ 1781 -borderwidth 1 -relief raised -padx 1 -pady 1 \ 1782 -image [Rappture::icon y-cutplane-off] \ 1783 -highlightthickness 0 1784 } { 1785 usual 1786 ignore -borderwidth -highlightthickness -font 1787 } 1788 bind $itk_component(yCutButton) <ButtonPress> \ 1789 [itcl::code $this Slice axis y toggle] 1847 Rappture::PushButton $inner.ybutton \ 1848 -onimage [Rappture::icon y-cutplane-on] \ 1849 -offimage [Rappture::icon y-cutplane-off] \ 1850 -command [itcl::code $this FixSettings ycutplane] \ 1851 -variable [itcl::scope _settings($this-ycutplane)] 1852 } 1790 1853 Rappture::Tooltip::for $itk_component(yCutButton) \ 1791 1854 "Toggle the Y cut plane on/off" … … 1795 1858 -width 10 -orient vertical -showvalue off \ 1796 1859 -borderwidth 1 -highlightthickness 0 \ 1797 -command [itcl::code $this Slice move y] 1860 -command [itcl::code $this Slice move y] \ 1861 -variable [itcl::scope _settings($this-ycutposition)] 1798 1862 } { 1799 1863 usual … … 1808 1872 # Z-value slicer... 1809 1873 itk_component add zCutButton { 1810 label $inner.zbutton \ 1811 -borderwidth 1 -relief raised -padx 1 -pady 1 \ 1812 -image [Rappture::icon z-cutplane-off] \ 1813 -highlightthickness 0 1814 } { 1815 usual 1816 ignore -borderwidth -highlightthickness -font 1817 } 1818 bind $itk_component(zCutButton) <ButtonPress> \ 1819 [itcl::code $this Slice axis z toggle] 1874 Rappture::PushButton $inner.zbutton \ 1875 -onimage [Rappture::icon z-cutplane-on] \ 1876 -offimage [Rappture::icon z-cutplane-off] \ 1877 -command [itcl::code $this FixSettings zcutplane] \ 1878 -variable [itcl::scope _settings($this-zcutplane)] 1879 } 1820 1880 Rappture::Tooltip::for $itk_component(zCutButton) \ 1821 1881 "Toggle the Z cut plane on/off" … … 1825 1885 -width 10 -orient vertical -showvalue off \ 1826 1886 -borderwidth 1 -highlightthickness 0 \ 1827 -command [itcl::code $this Slice move z] 1887 -command [itcl::code $this Slice move z] \ 1888 -variable [itcl::scope _settings($this-zcutposition)] 1828 1889 } { 1829 1890 usual … … 1861 1922 label $inner.${tag}label -text $tag -font "Arial 9" 1862 1923 entry $inner.${tag} -font "Arial 9" -bg white \ 1863 -textvariable [itcl::scope settings_($this-$tag)]1924 -textvariable [itcl::scope _settings($this-$tag)] 1864 1925 bind $inner.${tag} <KeyPress-Return> \ 1865 1926 [itcl::code $this camera set ${tag}] … … 1877 1938 1878 1939 # ---------------------------------------------------------------------- 1879 # USAGE: Slice axis x|y|z ?on|off|toggle?1880 1940 # USAGE: Slice move x|y|z <newval> 1881 # USAGE: Slice volume ?on|off|toggle?1882 1941 # 1883 1942 # Called automatically when the user drags the slider to move the … … 1888 1947 itcl::body Rappture::NanovisViewer::Slice {option args} { 1889 1948 switch -- $option { 1890 axis {1891 if {[llength $args] < 1 || [llength $args] > 2} {1892 error "wrong # args: should be \"Slice axis x|y|z ?on|off|toggle?\""1893 }1894 set axis [lindex $args 0]1895 set op [lindex $args 1]1896 if {$op == ""} {1897 set op "on"1898 }1899 set current [State ${axis}CutButton]1900 if {$op == "toggle"} {1901 if {$current == "on"} {1902 set op "off"1903 } else {1904 set op "on"1905 }1906 }1907 if {$op} {1908 $itk_component(${axis}CutButton) configure \1909 -relief sunken -image [Rappture::icon ${axis}-cutplane-on]1910 SendCmd "cutplane state 1 $axis [CurrentVolumeIds -cutplanes]"1911 $itk_component(${axis}CutScale) configure -state normal \1912 -troughcolor grey651913 } else {1914 $itk_component(${axis}CutButton) configure \1915 -relief raised -image [Rappture::icon ${axis}-cutplane-off]1916 SendCmd "cutplane state 0 $axis [CurrentVolumeIds -cutplanes]"1917 $itk_component(${axis}CutScale) configure -state disabled \1918 -troughcolor grey821919 }1920 }1921 1949 move { 1922 1950 if {[llength $args] != 2} { … … 1927 1955 1928 1956 set newpos [expr {0.01*$newval}] 1929 # set newval [expr {0.01*($newval-50)1930 # *($limits_(${axis}max)-$limits_(${axis}min))1931 # + 0.5*($limits_(${axis}max)+$limits_(${axis}min))}]1932 1933 # show the current value in the readout1934 #puts "readout: $axis = $newval"1935 1936 1957 set ids [CurrentVolumeIds -cutplanes] 1937 1958 SendCmd "cutplane position $newpos $axis $ids" 1938 }1939 volume {1940 if {[llength $args] > 1} {1941 error "wrong # args: should be \"Slice volume ?on|off|toggle?\""1942 }1943 set op [lindex $args 0]1944 if {$op == ""} { set op "on" }1945 1946 set current $settings_($this-volume)1947 if {$op == "toggle"} {1948 if {$current} {1949 set op "off"1950 } else {1951 set op "on"1952 }1953 }1954 1955 if {$op} {1956 SendCmd "volume data state on [CurrentVolumeIds]"1957 $itk_component(volume) configure -relief sunken \1958 -image [Rappture::icon volume-on]1959 set settings_($this-volume) 11960 } else {1961 SendCmd "volume data state off [CurrentVolumeIds]"1962 $itk_component(volume) configure -relief raised \1963 -image [Rappture::icon volume-off]1964 set settings_($this-volume) 01965 }1966 1959 } 1967 1960 default { … … 1980 1973 set val [$itk_component(${axis}CutScale) get] 1981 1974 # set val [expr {0.01*($val-50) 1982 # *($ limits_(${axis}max)-$limits_(${axis}min))1983 # + 0.5*($ limits_(${axis}max)+$limits_(${axis}min))}]1975 # *($_limits(${axis}max)-$_limits(${axis}min)) 1976 # + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}] 1984 1977 return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val%" 1985 1978 } … … 1987 1980 1988 1981 itcl::body Rappture::NanovisViewer::DoResize {} { 1989 SendCmd "screen $ width_ $height_"1982 SendCmd "screen $_width $_height" 1990 1983 } 1991 1984 1992 1985 itcl::body Rappture::NanovisViewer::EventuallyResize { w h } { 1993 if { $ width_ != $w || $height_!= $h } {1994 set width_$w1995 set height_$h1986 if { $_width != $w || $_height != $h } { 1987 set _width $w 1988 set _height $h 1996 1989 $_dispatcher event -idle !resize 1997 1990 } … … 2001 1994 $_dispatcher event -idle !legend 2002 1995 } 1996 2003 1997 2004 1998 # camera -- … … 2007 2001 switch -- $option { 2008 2002 "show" { 2009 puts [array get view_]2003 puts [array get _view] 2010 2004 } 2011 2005 "set" { 2012 2006 set who [lindex $args 0] 2013 set x $ settings_($this-$who)2007 set x $_settings($this-$who) 2014 2008 set code [catch { string is double $x } result] 2015 2009 if { $code != 0 || !$result } { 2016 set settings_($this-$who) $view_($who)2010 set _settings($this-$who) $_view($who) 2017 2011 return 2018 2012 } 2019 2013 switch -- $who { 2020 2014 "pan-x" - "pan-y" { 2021 set view_($who) $settings_($this-$who)2015 set _view($who) $_settings($this-$who) 2022 2016 PanCamera 2023 2017 } 2024 2018 "phi" - "theta" - "psi" { 2025 set view_($who) $settings_($this-$who)2026 set xyz [Euler2XYZ $ view_(theta) $view_(phi) $view_(psi)]2019 set _view($who) $_settings($this-$who) 2020 set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] 2027 2021 SendCmd "camera angle $xyz" 2028 2022 } 2029 2023 "zoom" { 2030 set view_($who) $settings_($this-$who)2031 SendCmd "camera zoom $ view_(zoom)"2024 set _view($who) $_settings($this-$who) 2025 SendCmd "camera zoom $_view(zoom)" 2032 2026 } 2033 2027 } … … 2035 2029 } 2036 2030 } 2037
Note: See TracChangeset
for help on using the changeset viewer.