Changeset 5012 for branches/1.3
- Timestamp:
- Feb 12, 2015, 12:51:16 PM (10 years ago)
- Location:
- branches/1.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3
-
branches/1.3/gui/scripts/vtkheightmapviewer.tcl
r4951 r5012 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: vtkheightmapviewer - Vtk heightmap viewer … … 7 7 # ====================================================================== 8 8 # AUTHOR: Michael McLennan, Purdue University 9 # Copyright (c) 2004-201 2HUBzero Foundation, LLC9 # Copyright (c) 2004-2014 HUBzero Foundation, LLC 10 10 # 11 11 # See the file "license.terms" for information on usage and … … 58 58 public method get {args} 59 59 public method isconnected {} 60 public method limits3 { dataobj } 61 public method parameters {title args} { 62 # do nothing 60 public method parameters {title args} { 61 # do nothing 63 62 } 64 63 public method scale {args} 65 64 66 protected method CameraReset {}67 protected method Connect {}68 protected method CurrentDatasets {args}69 protected method Disconnect {}70 protected method DoResize {}71 protected method DoRotate {}72 protected method AdjustSetting {what {value ""}}73 protected method AdjustMode {}74 protected method InitSettings { args }75 protected method Pan {option x y}76 protected method Pick {x y}77 protected method Rebuild {}78 protected method ReceiveDataset { args }79 protected method ReceiveImage { args }80 protected method ReceiveLegend { colormap title min max size }81 protected method Rotate {option x y}82 protected method Zoom {option}83 84 65 # The following methods are only used by this class. 66 private method AdjustSetting {what {value ""}} 85 67 private method BuildAxisTab {} 86 68 private method BuildCameraTab {} 87 69 private method BuildColormap { name } 88 70 private method BuildContourTab {} 89 private method BuildDownloadPopup { widget command } 71 private method BuildDownloadPopup { widget command } 72 private method CameraReset {} 90 73 private method Combo { option } 74 private method Connect {} 75 private method CurrentDatasets {args} 76 private method Disconnect {} 77 private method DoResize {} 78 private method DoRotate {} 91 79 private method DrawLegend {} 92 private method EnterLegend { x y } 93 private method EventuallyRequestLegend {} 94 private method EventuallyResize { w h } 95 private method EventuallyRotate { q } 96 private method GetImage { args } 97 private method GetVtkData { args } 98 private method IsValidObject { dataobj } 80 private method EnterLegend { x y } 81 private method EventuallyRequestLegend {} 82 private method EventuallyResize { w h } 83 private method EventuallyRotate { q } 84 private method GetHeightmapScale {} 85 private method GetImage { args } 86 private method GetVtkData { args } 87 private method InitSettings { args } 88 private method IsValidObject { dataobj } 99 89 private method LeaveLegend {} 100 private method MotionLegend { x y } 90 private method MotionLegend { x y } 91 private method Pan {option x y} 101 92 private method PanCamera {} 93 private method Pick {x y} 94 private method QuaternionToView { q } { 95 foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break 96 } 97 private method Rebuild {} 98 private method ReceiveDataset { args } 99 private method ReceiveImage { args } 100 private method ReceiveLegend { colormap title min max size } 102 101 private method RequestLegend {} 102 private method ResetAxes {} 103 private method Rotate {option x y} 103 104 private method SetCurrentColormap { color } 104 105 private method SetLegendTip { x y } 105 private method SetObjectStyle { dataobj comp } 106 private method GetHeightmapScale {} 107 private method ResetAxes {} 106 private method SetObjectStyle { dataobj comp } 108 107 private method SetOrientation { side } 109 108 private method UpdateContourList {} 109 private method ViewToQuaternion {} { 110 return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] 111 } 112 private method Zoom {option} 110 113 111 114 private variable _arcball "" … … 113 116 private variable _obj2datasets 114 117 private variable _obj2ovride ; # maps dataobj => style override 115 private variable _comp2scale; 116 private variable _datasets ; # contains all the dataobj-component 118 private variable _comp2scale; # maps dataset to the heightmap scale. 119 private variable _datasets ; # contains all the dataobj-component 117 120 ; # datasets in the server 118 121 private variable _colormaps ; # contains all the colormaps … … 123 126 private variable _currentColormap "" 124 127 private variable _currentNumIsolines -1 125 private variable _currentOpacity ""126 128 127 129 private variable _maxScale 100; # This is the # of times the x-axis … … 131 133 132 134 private variable _click ; # info used for rotate operations 133 private variable _limits ; # Holds overall limits for all dataobjs 135 private variable _limits ; # Holds overall limits for all dataobjs 134 136 # using the viewer. 135 137 private variable _view ; # view params for 3D view … … 156 158 private variable _rotatePending 0 157 159 private variable _legendPending 0 158 private variable _fieldNames {} 159 private variable _fields 160 private variable _fieldNames {} 161 private variable _fields 160 162 private variable _curFldName "" 161 163 private variable _curFldLabel "" … … 203 205 # Initialize the view to some default parameters. 204 206 array set _view { 205 qw 0.36206 qx 0.25207 qy 0.50208 qz 0.70209 zoom 1.0210 xpan0211 ypan0212 ortho0207 -ortho 0 208 -qw 0.36 209 -qx 0.25 210 -qy 0.50 211 -qz 0.70 212 -xpan 0 213 -ypan 0 214 -zoom 1.0 213 215 } 214 216 set _arcball [blt::arcball create 100 100] 215 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 216 $_arcball quaternion $q 217 $_arcball quaternion [ViewToQuaternion] 217 218 218 219 array set _settings { 219 axisFlymode "static" 220 axisMinorTicks 1 221 stretchToFit 0 222 axisLabels 1 223 axisVisible 1 224 axisXGrid 0 225 axisYGrid 0 226 axisZGrid 0 227 colormapVisible 1 228 colormapDiscrete 0 229 edges 0 230 field "Default" 231 heightmapScale 50 232 isHeightmap 0 233 isolineColor black 234 isolinesVisible 1 235 legendVisible 1 236 lighting 1 237 saveLighting 1 238 numIsolines 10 239 opacity 100 240 outline 0 241 wireframe 0 242 saveOpacity 100 243 saveOutline 0 220 -axisflymode "static" 221 -axislabels 1 222 -axisminorticks 1 223 -axisvisible 1 224 -colormap BCGYR 225 -colormapdiscrete 0 226 -colormapvisible 1 227 -edges 0 228 -field "Default" 229 -heightmapscale 50 230 -isheightmap 0 231 -isolinecolor black 232 -isolinesvisible 1 233 -legendvisible 1 234 -lighting 1 235 -numisolines 10 236 -opacity 100 237 -outline 0 238 -savelighting 1 239 -saveopacity 100 240 -saveoutline 0 241 -stretchtofit 0 242 -wireframe 0 243 -xgrid 0 244 -ygrid 0 245 -zgrid 0 244 246 } 245 247 array set _changed { 246 opacity0247 colormap0248 numIsolines0248 -colormap 0 249 -numisolines 0 250 -opacity 0 249 251 } 250 252 itk_component add view { … … 253 255 } { 254 256 usual 255 ignore -highlightthickness -borderwidth -background 257 ignore -highlightthickness -borderwidth -background 256 258 } 257 259 … … 259 261 menu $itk_component(plotarea).menu \ 260 262 -relief flat \ 261 -tearoff no 263 -tearoff no 262 264 } { 263 265 usual … … 279 281 280 282 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 281 set _map(cwidth) -1 282 set _map(cheight) -1 283 set _map(cwidth) -1 284 set _map(cheight) -1 283 285 set _map(zoom) 1.0 284 286 set _map(original) "" … … 325 327 -onimage [Rappture::icon surface] \ 326 328 -offimage [Rappture::icon surface] \ 327 -variable [itcl::scope _settings( isHeightmap)] \328 -command [itcl::code $this AdjustSetting isHeightmap] \329 -variable [itcl::scope _settings(-isheightmap)] \ 330 -command [itcl::code $this AdjustSetting -isheightmap] \ 329 331 } 330 332 Rappture::Tooltip::for $itk_component(mode) \ … … 336 338 -onimage [Rappture::icon stretchtofit] \ 337 339 -offimage [Rappture::icon stretchtofit] \ 338 -variable [itcl::scope _settings( stretchToFit)] \339 -command [itcl::code $this AdjustSetting stretchToFit] \340 -variable [itcl::scope _settings(-stretchtofit)] \ 341 -command [itcl::code $this AdjustSetting -stretchtofit] \ 340 342 } 341 343 Rappture::Tooltip::for $itk_component(stretchtofit) \ … … 348 350 BuildCameraTab 349 351 } errs] != 0 } { 350 352 global errorInfo 351 353 puts stderr "errs=$errs errorInfo=$errorInfo" 352 354 } 353 355 354 # Hack around the Tk panewindow. The problem is that the requested 356 # Hack around the Tk panewindow. The problem is that the requested 355 357 # size of the 3d view isn't set until an image is retrieved from 356 358 # the server. So the panewindow uses the tiny size. … … 358 360 pack forget $itk_component(view) 359 361 blt::table $itk_component(plotarea) \ 360 0,0 $itk_component(view) -fill both -reqwidth $w 362 0,0 $itk_component(view) -fill both -reqwidth $w 361 363 blt::table configure $itk_component(plotarea) c1 -resize none 362 364 … … 442 444 443 445 itcl::body Rappture::VtkHeightmapViewer::DoRotate {} { 444 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 445 SendCmd "camera orient $q" 446 SendCmd "camera orient [ViewToQuaternion]" 446 447 set _rotatePending 0 447 448 } … … 467 468 468 469 itcl::body Rappture::VtkHeightmapViewer::EventuallyRotate { q } { 469 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break470 QuaternionToView $q 470 471 if { !$_rotatePending } { 471 472 set _rotatePending 1 472 global rotate_delay 473 global rotate_delay 473 474 $_dispatcher event -after $rotate_delay !rotate 474 475 } … … 569 570 continue 570 571 } 571 if {[info exists _obj2ovride($dataobj-raise)] && 572 if {[info exists _obj2ovride($dataobj-raise)] && 572 573 $_obj2ovride($dataobj-raise)} { 573 574 set dlist [linsert $dlist 0 $dataobj] … … 597 598 } 598 599 return $dlist 599 } 600 } 600 601 -image { 601 602 if {[llength $args] != 2} { … … 617 618 } 618 619 619 # 620 # 620 621 # scale -- 621 622 # 622 623 # This gets called either incrementally as new simulations are 623 624 # added or all at once as a sequence of heightmaps. 624 # This accounts for all objects--even those not showing on the 625 # screen. Because of this, the limits are appropriate for all 625 # This accounts for all objects--even those not showing on the 626 # screen. Because of this, the limits are appropriate for all 626 627 # objects as the user scans through data in the ResultSet viewer. 627 628 # … … 666 667 } 667 668 if { [array size found] > 1 } { 668 set _settings( stretchToFit) 1669 set _settings(-stretchtofit) 1 669 670 } else { 670 671 # Check if the range of the x and y axes requires that we stretch … … 675 676 if { (($xmax - $xmin) > (($ymax -$ymin) * $_maxScale)) || 676 677 ((($xmax - $xmin) * $_maxScale) < ($ymax -$ymin)) } { 677 set _settings( stretchToFit) 1678 set _settings(-stretchtofit) 1 678 679 } 679 680 } … … 815 816 $_dispatcher cancel !legend 816 817 # disconnected -- no more data sitting on server 817 array unset _datasets 818 array unset _data 819 array unset _colormaps 820 array unset _obj2datasets 818 array unset _datasets 819 array unset _data 820 array unset _colormaps 821 array unset _obj2datasets 821 822 global readyForNextFrame 822 823 set readyForNextFrame 1 … … 842 843 if { $info(-type) == "image" } { 843 844 if 0 { 844 set f [open "last.ppm" "w"] 845 puts $f $bytes 845 set f [open "last.ppm" "w"] 846 fconfigure $f -encoding binary 847 puts -nonewline $f $bytes 846 848 close $f 847 849 } … … 849 851 set time [clock seconds] 850 852 set date [clock format $time] 851 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 853 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 852 854 if { $_start > 0 } { 853 855 set finish [clock clicks -milliseconds] … … 920 922 # Turn on buffering of commands to the server. We don't want to 921 923 # be preempted by a server disconnect/reconnect (which automatically 922 # generates a new call to Rebuild). 924 # generates a new call to Rebuild). 923 925 StartBufferingCommands 924 926 925 927 if { $_width != $w || $_height != $h || $_reset } { 926 927 928 929 930 if { $_settings(stretchToFit) } {931 AdjustSetting stretchToFit932 928 set _width $w 929 set _height $h 930 $_arcball resize $w $h 931 DoResize 932 if { $_settings(-stretchtofit) } { 933 AdjustSetting -stretchtofit 934 } 933 935 } 934 936 if { $_reset } { 935 # 936 # Reset the camera and other view parameters 937 # 938 InitSettings isHeightmap background 939 940 # Let's see how this goes. I think it's preferable to overloading the 941 # axis title with the exponent. 942 SendCmd "axis exp 0 0 0 1" 943 944 SendCmd "axis lrot z 90" 945 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 946 $_arcball quaternion $q 947 if {$_settings(isHeightmap) } { 948 if { $_view(ortho)} { 937 # 938 # Reset the camera and other view parameters 939 # 940 InitSettings -isheightmap -background 941 942 # Setting a custom exponent and label format for axes is causing 943 # a problem with rounding. Near zero ticks aren't rounded by 944 # the %g format. The VTK CubeAxes seem to currently work best 945 # when allowed to automatically set the exponent and precision 946 # based on the axis ranges. This does tend to result in less 947 # visual clutter, so I think it is best to use the automatic 948 # settings by default. We can test more fine-grained 949 # controls on the axis settings tab if necessary. 950 # -Leif 951 #SendCmd "axis exp 0 0 0 1" 952 953 SendCmd "axis lrot z 90" 954 $_arcball quaternion [ViewToQuaternion] 955 if {$_settings(-isheightmap) } { 956 if { $_view(-ortho)} { 949 957 SendCmd "camera mode ortho" 950 958 } else { … … 953 961 DoRotate 954 962 SendCmd "camera reset" 955 956 963 } 964 PanCamera 957 965 StopBufferingCommands 958 966 SendCmd "imgflush" … … 973 981 if { ![info exists _datasets($tag)] } { 974 982 set bytes [$dataobj vtkdata $comp] 975 if 0 { 983 if 0 { 976 984 set f [open /tmp/vtkheightmap.vtk "w"] 977 puts $f $bytes 985 fconfigure $f -translation binary -encoding binary 986 puts -nonewline $f $bytes 978 987 close $f 979 988 } 980 989 set length [string length $bytes] 981 990 if { $_reportClientInfo } { … … 989 998 lappend info "dataset_size" $length 990 999 lappend info "dataset_tag" $tag 991 SendCmd [list "clientinfo" $info]1000 SendCmd "clientinfo [list $info]" 992 1001 } 993 1002 SendCmd "dataset add $tag data follows $length" … … 1002 1011 SendCmd "dataset visible 1 $tag" 1003 1012 } 1004 if { ![info exists _comp2scale($tag)] || 1005 1006 1007 1008 1013 if { ![info exists _comp2scale($tag)] || 1014 $_comp2scale($tag) != $scale } { 1015 SendCmd "heightmap heightscale $scale $tag" 1016 set _comp2scale($tag) $scale 1017 } 1009 1018 } 1010 1019 } 1011 1020 if { $_first != "" } { 1012 1013 1014 1021 $itk_component(field) choices delete 0 end 1022 $itk_component(fieldmenu) delete 0 end 1023 array unset _fields 1015 1024 set _curFldName "" 1016 1025 foreach cname [$_first components] { … … 1038 1047 $itk_component(field) value $_curFldLabel 1039 1048 } 1040 InitSettings stretchToFitoutline1049 InitSettings -stretchtofit -outline 1041 1050 1042 1051 if { $_reset } { 1043 SendCmd "axis tickpos outside" 1044 foreach axis { x y z } { 1045 SendCmd "axis lformat $axis %g" 1046 } 1047 1048 foreach axis { x y z } { 1052 SendCmd "axis tickpos outside" 1053 #SendCmd "axis lformat all %g" 1054 1055 foreach axis { x y z } { 1049 1056 if { $axis == "z" } { 1050 1057 set label [$_first hints label] … … 1052 1059 set label [$_first hints ${axis}label] 1053 1060 } 1054 1055 1061 if { $label == "" } { 1062 if {$axis == "z"} { 1056 1063 if { [string match "component*" $_curFldName] } { 1057 1064 set label [string toupper $axis] … … 1059 1066 set label $_curFldLabel 1060 1067 } 1061 } else { 1062 set label [string toupper $axis] 1063 } 1064 } 1065 # May be a space in the axis label. 1066 SendCmd [list axis name $axis $label] 1067 1068 if {$axis == "z" && [$_first hints ${axis}units] == ""} { 1069 set units [lindex $_fields($_curFldName) 1] 1070 } else { 1071 set units [$_first hints ${axis}units] 1072 } 1073 if { $units != "" } { 1074 # May be a space in the axis units. 1075 SendCmd [list axis units $axis $units] 1076 } 1077 } 1078 # 1079 # Reset the camera and other view parameters 1080 # 1081 ResetAxes 1082 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1083 $_arcball quaternion $q 1084 if {$_settings(isHeightmap) } { 1085 if { $_view(ortho)} { 1068 } else { 1069 set label [string toupper $axis] 1070 } 1071 } 1072 # May be a space in the axis label. 1073 SendCmd [list axis name $axis $label] 1074 1075 set units "" 1076 if {$axis == "z" && [$_first hints ${axis}units] == ""} { 1077 if {$_curFldName != ""} { 1078 set units [lindex $_fields($_curFldName) 1] 1079 } 1080 } else { 1081 set units [$_first hints ${axis}units] 1082 } 1083 if { $units != "" } { 1084 # May be a space in the axis units. 1085 SendCmd [list axis units $axis $units] 1086 } 1087 } 1088 # 1089 # Reset the camera and other view parameters 1090 # 1091 ResetAxes 1092 $_arcball quaternion [ViewToQuaternion] 1093 if {$_settings(-isheightmap) } { 1094 if { $_view(-ortho)} { 1086 1095 SendCmd "camera mode ortho" 1087 1096 } else { … … 1091 1100 SendCmd "camera reset" 1092 1101 } 1093 1094 InitSettings axisXGrid axisYGrid axisZGrid \1095 axisVisible axisLabels heightmapScale field isHeightmap \1096 numIsolines1102 PanCamera 1103 InitSettings -xgrid -ygrid -zgrid \ 1104 -axisvisible -axislabels -heightmapscale -field -isheightmap \ 1105 -numisolines 1097 1106 if { [array size _fields] < 2 } { 1098 1107 catch {blt::table forget $itk_component(field) $itk_component(field_l)} … … 1102 1111 } 1103 1112 global readyForNextFrame 1104 set readyForNextFrame 0; 1113 set readyForNextFrame 0; # Don't advance to the next frame 1105 1114 1106 1115 # Actually write the commands to the server socket. If it fails, we don't … … 1120 1129 itcl::body Rappture::VtkHeightmapViewer::CurrentDatasets {args} { 1121 1130 set flag [lindex $args 0] 1122 switch -- $flag { 1131 switch -- $flag { 1123 1132 "-all" { 1124 1133 if { [llength $args] > 1 } { … … 1139 1148 set dlist [get -visible] 1140 1149 } 1141 } 1150 } 1142 1151 default { 1143 1152 set dlist $args … … 1158 1167 itcl::body Rappture::VtkHeightmapViewer::CameraReset {} { 1159 1168 array set _view { 1160 qw 0.361161 qx 0.251162 qy 0.501163 qz 0.701164 zoom 1.01165 xpan 01166 ypan 01169 -qw 0.36 1170 -qx 0.25 1171 -qy 0.50 1172 -qz 0.70 1173 -xpan 0 1174 -ypan 0 1175 -zoom 1.0 1167 1176 } 1168 1177 if { $_first != "" } { … … 1172 1181 } 1173 1182 } 1174 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1175 $_arcball quaternion $q 1176 if {$_settings(isHeightmap) } { 1183 $_arcball quaternion [ViewToQuaternion] 1184 if {$_settings(-isheightmap) } { 1177 1185 DoRotate 1178 1186 } … … 1191 1199 switch -- $option { 1192 1200 "in" { 1193 set _view( zoom) [expr {$_view(zoom)*1.25}]1194 SendCmd "camera zoom $_view( zoom)"1201 set _view(-zoom) [expr {$_view(-zoom)*1.25}] 1202 SendCmd "camera zoom $_view(-zoom)" 1195 1203 } 1196 1204 "out" { 1197 set _view( zoom) [expr {$_view(zoom)*0.8}]1198 SendCmd "camera zoom $_view( zoom)"1205 set _view(-zoom) [expr {$_view(-zoom)*0.8}] 1206 SendCmd "camera zoom $_view(-zoom)" 1199 1207 } 1200 1208 "reset" { 1201 1209 array set _view { 1202 zoom 1.01203 xpan 01204 ypan 01210 -xpan 0 1211 -ypan 0 1212 -zoom 1.0 1205 1213 } 1206 1214 SendCmd "camera reset" … … 1210 1218 1211 1219 itcl::body Rappture::VtkHeightmapViewer::PanCamera {} { 1212 set x $_view( xpan)1213 set y $_view( ypan)1220 set x $_view(-xpan) 1221 set y $_view(-ypan) 1214 1222 SendCmd "camera pan $x $y" 1215 1223 } … … 1271 1279 foreach tag [CurrentDatasets -visible] { 1272 1280 SendCmd "dataset getscalar pixel $x $y $tag" 1273 } 1281 } 1274 1282 } 1275 1283 … … 1289 1297 set x [expr $x / double($w)] 1290 1298 set y [expr $y / double($h)] 1291 set _view( xpan) [expr $_view(xpan) + $x]1292 set _view( ypan) [expr $_view(ypan) + $y]1299 set _view(-xpan) [expr $_view(-xpan) + $x] 1300 set _view(-ypan) [expr $_view(-ypan) + $y] 1293 1301 PanCamera 1294 1302 return … … 1312 1320 set _click(x) $x 1313 1321 set _click(y) $y 1314 set _view( xpan) [expr $_view(xpan) - $dx]1315 set _view( ypan) [expr $_view(ypan) - $dy]1322 set _view(-xpan) [expr $_view(-xpan) - $dx] 1323 set _view(-ypan) [expr $_view(-ypan) - $dy] 1316 1324 PanCamera 1317 1325 } … … 1335 1343 itcl::body Rappture::VtkHeightmapViewer::InitSettings { args } { 1336 1344 foreach spec $args { 1337 if { [info exists _settings($_first -$spec)] } {1345 if { [info exists _settings($_first${spec})] } { 1338 1346 # Reset global setting with dataobj specific setting 1339 set _settings($spec) $_settings($_first -$spec)1347 set _settings($spec) $_settings($_first${spec}) 1340 1348 } 1341 1349 AdjustSetting $spec … … 1355 1363 } 1356 1364 switch -- $what { 1357 " axisFlymode" {1365 "-axisflymode" { 1358 1366 set mode [$itk_component(axisflymode) value] 1359 1367 set mode [$itk_component(axisflymode) translate $mode] … … 1361 1369 SendCmd "axis flymode $mode" 1362 1370 } 1363 " axisLabels" {1364 set bool $_settings( axisLabels)1371 "-axislabels" { 1372 set bool $_settings($what) 1365 1373 SendCmd "axis labels all $bool" 1366 1374 } 1367 "axisMinorTicks" { 1368 set bool $_settings(axisMinorTicks) 1369 foreach axis { x y z } { 1370 SendCmd "axis minticks ${axis} $bool" 1371 } 1372 } 1373 "axisVisible" { 1374 set bool $_settings(axisVisible) 1375 "-axisminorticks" { 1376 set bool $_settings($what) 1377 SendCmd "axis minticks all $bool" 1378 } 1379 "-axisvisible" { 1380 set bool $_settings($what) 1375 1381 SendCmd "axis visible all $bool" 1376 1382 } 1377 "axisXGrid" - "axisYGrid" - "axisZGrid" { 1378 set axis [string tolower [string range $what 4 4]] 1379 set bool $_settings($what) 1380 SendCmd "axis grid $axis $bool" 1381 } 1382 "background" { 1383 "-background" { 1383 1384 set bg [$itk_component(background) value] 1384 1385 1386 1387 "grey""black"1388 1385 array set fgcolors { 1386 "black" "white" 1387 "white" "black" 1388 "grey" "black" 1389 } 1389 1390 set fg $fgcolors($bg) 1390 1391 configure -plotbackground $bg -plotforeground $fg 1391 1392 $itk_component(view) delete "legend" 1392 1393 SendCmd "screen bgcolor [Color2RGB $bg]" 1393 1394 SendCmd "outline color [Color2RGB $fg]" 1394 1395 SendCmd "axis color all [Color2RGB $fg]" 1395 1396 } 1397 " colormap" {1398 set _changed( colormap) 11396 DrawLegend 1397 } 1398 "-colormap" { 1399 set _changed($what) 1 1399 1400 StartBufferingCommands 1400 1401 set color [$itk_component(colormap) value] 1401 set _settings( colormap) $color1402 1403 if { $_settings(colormapVisible) } {1404 1405 set _settings(colormapVisible) 01406 1407 1408 if { !$_settings(colormapVisible) } {1409 1410 set _settings(colormapVisible) 11411 1412 1413 if {$_settings( colormapDiscrete)} {1414 set numColors [expr $_settings( numIsolines) + 1]1402 set _settings($what) $color 1403 if { $color == "none" } { 1404 if { $_settings(-colormapvisible) } { 1405 SendCmd "heightmap surface 0" 1406 set _settings(-colormapvisible) 0 1407 } 1408 } else { 1409 if { !$_settings(-colormapvisible) } { 1410 SendCmd "heightmap surface 1" 1411 set _settings(-colormapvisible) 1 1412 } 1413 SetCurrentColormap $color 1414 if {$_settings(-colormapdiscrete)} { 1415 set numColors [expr $_settings(-numisolines) + 1] 1415 1416 SendCmd "colormap res $numColors $color" 1416 1417 } 1417 1418 } 1418 1419 StopBufferingCommands 1419 1420 } 1421 " colormapVisible" {1420 EventuallyRequestLegend 1421 } 1422 "-colormapvisible" { 1422 1423 set bool $_settings($what) 1423 1424 SendCmd "heightmap surface $bool" 1424 1425 } 1425 " colormapDiscrete" {1426 "-colormapdiscrete" { 1426 1427 set bool $_settings($what) 1427 set numColors [expr $_settings( numIsolines) + 1]1428 set numColors [expr $_settings(-numisolines) + 1] 1428 1429 StartBufferingCommands 1429 1430 if {$bool} { … … 1439 1440 EventuallyRequestLegend 1440 1441 } 1441 " edges" {1442 set bool $_settings( edges)1442 "-edges" { 1443 set bool $_settings($what) 1443 1444 SendCmd "heightmap edges $bool" 1444 1445 } 1445 " field" {1446 "-field" { 1446 1447 set label [$itk_component(field) value] 1447 1448 set fname [$itk_component(field) translate $label] 1448 set _settings( field) $fname1449 set _settings($what) $fname 1449 1450 if { [info exists _fields($fname)] } { 1450 1451 foreach { label units components } $_fields($fname) break … … 1460 1461 return 1461 1462 } 1462 1463 1463 set label [$_first hints label] 1464 if { $label == "" } { 1464 1465 if { [string match "component*" $_curFldName] } { 1465 1466 set label Z … … 1467 1468 set label $_curFldLabel 1468 1469 } 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1470 } 1471 # May be a space in the axis label. 1472 SendCmd [list axis name z $label] 1473 1474 if { [$_first hints zunits] == "" } { 1475 set units [lindex $_fields($_curFldName) 1] 1476 } else { 1477 set units [$_first hints zunits] 1478 } 1479 if { $units != "" } { 1480 # May be a space in the axis units. 1481 SendCmd [list axis units z $units] 1482 } 1482 1483 # Get the new limits because the field changed. 1483 1484 ResetAxes … … 1488 1489 DrawLegend 1489 1490 } 1490 " heightmapScale" {1491 if { $_settings(isHeightmap) } {1492 1493 # Have to set the datasets individually because we are 1491 "-heightmapscale" { 1492 if { $_settings(-isheightmap) } { 1493 set scale [GetHeightmapScale] 1494 # Have to set the datasets individually because we are 1494 1495 # tracking them in _comp2scale. 1495 1496 foreach dataset [CurrentDatasets -all] { 1496 1497 1498 1499 1500 1501 } 1502 " isHeightmap" {1503 set bool $_settings(isHeightmap)1497 SendCmd "heightmap heightscale $scale $dataset" 1498 set _comp2scale($dataset) $scale 1499 } 1500 ResetAxes 1501 } 1502 } 1503 "-isheightmap" { 1504 set bool $_settings($what) 1504 1505 set c $itk_component(view) 1505 1506 StartBufferingCommands 1506 1507 # Fix heightmap scale: 0 for contours, 1 for heightmaps. 1507 1508 if { $bool } { 1508 set _settings( heightmapScale) 501509 set _settings( opacity) $_settings(saveOpacity)1510 set _settings( lighting) $_settings(saveLighting)1511 set _settings( outline) 01509 set _settings(-heightmapscale) 50 1510 set _settings(-opacity) $_settings(-saveopacity) 1511 set _settings(-lighting) $_settings(-savelighting) 1512 set _settings(-outline) 0 1512 1513 } else { 1513 set _settings(heightmapScale) 0 1514 set _settings(lighting) 0 1515 set _settings(opacity) 100 1516 set _settings(outline) $_settings(saveOutline) 1517 } 1518 AdjustSetting lighting 1519 AdjustSetting opacity 1520 AdjustSetting outline 1514 set _settings(-heightmapscale) 0 1515 set _settings(-lighting) 0 1516 set _settings(-opacity) 100 1517 set _settings(-outline) $_settings(-saveoutline) 1518 } 1519 InitSettings -lighting -opacity -outline 1521 1520 set scale [GetHeightmapScale] 1522 # Have to set the datasets individually because we are 1521 # Have to set the datasets individually because we are 1523 1522 # tracking them in _comp2scale. 1524 1523 foreach dataset [CurrentDatasets -all] { … … 1526 1525 set _comp2scale($dataset) $scale 1527 1526 } 1528 1529 1530 1531 1532 1533 1534 1535 if {$_view( ortho)} {1527 if { $bool } { 1528 $itk_component(lighting) configure -state normal 1529 $itk_component(opacity) configure -state normal 1530 $itk_component(scale) configure -state normal 1531 $itk_component(opacity_l) configure -state normal 1532 $itk_component(scale_l) configure -state normal 1533 $itk_component(outline) configure -state disabled 1534 if {$_view(-ortho)} { 1536 1535 SendCmd "camera mode ortho" 1537 1536 } else { 1538 1537 SendCmd "camera mode persp" 1539 1538 } 1540 1541 1542 1543 1544 1545 1546 1539 } else { 1540 $itk_component(lighting) configure -state disabled 1541 $itk_component(opacity) configure -state disabled 1542 $itk_component(scale) configure -state disabled 1543 $itk_component(opacity_l) configure -state disabled 1544 $itk_component(scale_l) configure -state disabled 1545 $itk_component(outline) configure -state normal 1547 1546 SendCmd "camera mode image" 1548 1547 } 1549 if {$_settings( stretchToFit)} {1548 if {$_settings(-stretchtofit)} { 1550 1549 if {$scale == 0} { 1551 1550 SendCmd "camera aspect window" … … 1556 1555 ResetAxes 1557 1556 if { $bool } { 1558 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]1557 set q [ViewToQuaternion] 1559 1558 $_arcball quaternion $q 1560 SendCmd "camera orient $q" 1559 SendCmd "camera orient $q" 1561 1560 } else { 1562 1561 bind $c <ButtonPress-1> {} … … 1565 1564 } 1566 1565 Zoom reset 1567 # Fix the mouse bindings for rotation/panning and the 1566 # Fix the mouse bindings for rotation/panning and the 1568 1567 # camera mode. Ideally we'd create a bindtag for these. 1569 1568 if { $bool } { … … 1578 1577 StopBufferingCommands 1579 1578 } 1580 " isolineColor" {1579 "-isolinecolor" { 1581 1580 set color [$itk_component(isolinecolor) value] 1582 1583 if { $_settings(isolinesVisible) } {1584 1585 set _settings(isolinesVisible) 01586 1587 1588 if { !$_settings(isolinesVisible) } {1589 1590 set _settings(isolinesVisible) 11591 1592 1593 1594 1595 } 1596 " isolinesVisible" {1597 1581 if { $color == "none" } { 1582 if { $_settings(-isolinesvisible) } { 1583 SendCmd "heightmap isolines 0" 1584 set _settings(-isolinesvisible) 0 1585 } 1586 } else { 1587 if { !$_settings(-isolinesvisible) } { 1588 SendCmd "heightmap isolines 1" 1589 set _settings(-isolinesvisible) 1 1590 } 1591 SendCmd "heightmap isolinecolor [Color2RGB $color]" 1592 } 1593 DrawLegend 1594 } 1595 "-isolinesvisible" { 1596 set bool $_settings($what) 1598 1597 SendCmd "heightmap isolines $bool" 1599 1600 } 1601 " legendVisible" {1598 DrawLegend 1599 } 1600 "-legendvisible" { 1602 1601 if { !$_settings($what) } { 1603 1604 1605 1606 } 1607 " lighting" {1608 if { $_settings(isHeightmap) } {1609 set _settings( saveLighting) $_settings(lighting)1610 1611 1612 1613 1614 1615 } 1616 " numIsolines" {1617 set _settings( numIsolines) [$itk_component(numisolines) value]1618 set _currentNumIsolines $_settings( numIsolines)1602 $itk_component(view) delete legend 1603 } 1604 DrawLegend 1605 } 1606 "-lighting" { 1607 if { $_settings(-isheightmap) } { 1608 set _settings(-savelighting) $_settings($what) 1609 set bool $_settings($what) 1610 SendCmd "heightmap lighting $bool" 1611 } else { 1612 SendCmd "heightmap lighting 0" 1613 } 1614 } 1615 "-numisolines" { 1616 set _settings($what) [$itk_component(numisolines) value] 1617 set _currentNumIsolines $_settings($what) 1619 1618 UpdateContourList 1620 set _changed( numIsolines) 11619 set _changed($what) 1 1621 1620 SendCmd "heightmap contourlist [list $_contourList]" 1622 if {$_settings( colormapDiscrete)} {1623 set numColors [expr $_settings( numIsolines) + 1]1621 if {$_settings(-colormapdiscrete)} { 1622 set numColors [expr $_settings($what) + 1] 1624 1623 SendCmd "colormap res $numColors" 1625 1624 EventuallyRequestLegend … … 1628 1627 } 1629 1628 } 1630 "opacity" { 1631 set _changed(opacity) 1 1632 if { $_settings(isHeightmap) } { 1633 set _settings(saveOpacity) $_settings(opacity) 1634 set val $_settings(opacity) 1635 set sval [expr { 0.01 * double($val) }] 1636 SendCmd "heightmap opacity $sval" 1629 "-opacity" { 1630 set _changed($what) 1 1631 set val [expr $_settings($what) * 0.01] 1632 if { $_settings(-isheightmap) } { 1633 set _settings(-saveopacity) $_settings($what) 1634 SendCmd "heightmap opacity $val" 1637 1635 } else { 1638 SendCmd "heightmap opacity 1"1639 } 1640 } 1641 " outline" {1642 if { $_settings(isHeightmap) } {1643 1636 SendCmd "heightmap opacity 1.0" 1637 } 1638 } 1639 "-outline" { 1640 if { $_settings(-isheightmap) } { 1641 SendCmd "outline visible 0" 1644 1642 } else { 1645 set _settings( saveOutline) $_settings(outline)1646 set bool $_settings( outline)1643 set _settings(-saveoutline) $_settings($what) 1644 set bool $_settings($what) 1647 1645 SendCmd "outline visible $bool" 1648 1646 } 1649 1650 " stretchToFit" {1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1647 } 1648 "-stretchtofit" { 1649 set bool $_settings($what) 1650 if { $bool } { 1651 set heightScale [GetHeightmapScale] 1652 if {$heightScale == 0} { 1653 SendCmd "camera aspect window" 1654 } else { 1655 SendCmd "camera aspect square" 1656 } 1657 } else { 1658 SendCmd "camera aspect native" 1659 } 1662 1660 Zoom reset 1663 1664 " wireframe" {1661 } 1662 "-wireframe" { 1665 1663 set bool $_settings($what) 1666 1664 SendCmd "heightmap wireframe $bool" 1667 1665 } 1668 default { 1666 "-xgrid" - "-ygrid" - "-zgrid" { 1667 set axis [string tolower [string range $what 1 1]] 1668 set bool $_settings($what) 1669 SendCmd "axis grid $axis $bool" 1670 } 1671 default { 1669 1672 error "don't know how to fix $what" 1670 1673 } … … 1676 1679 # 1677 1680 # Request a new legend from the server. The size of the legend 1678 # is determined from the height of the canvas. 1681 # is determined from the height of the canvas. 1679 1682 # 1680 1683 # This should be called when 1681 # 1682 # 1683 # 1684 # 1685 # 1684 # 1. A new current colormap is set. 1685 # 2. Window is resized. 1686 # 3. The limits of the data have changed. (Just need a redraw). 1687 # 4. Number of isolines have changed. (Just need a redraw). 1688 # 5. Legend becomes visible (Just need a redraw). 1686 1689 # 1687 1690 itcl::body Rappture::VtkHeightmapViewer::RequestLegend {} { … … 1690 1693 set w 12 1691 1694 set lineht [font metrics $font -linespace] 1692 # color ramp height = (canvas height) - (min and max value lines) - 2 1695 # color ramp height = (canvas height) - (min and max value lines) - 2 1693 1696 set h [expr {$_height - 2 * ($lineht + 2)}] 1694 1697 set _legendHeight $h … … 1696 1699 set fname $_curFldName 1697 1700 if { [string match "component*" $fname] } { 1698 1701 set title "" 1699 1702 } else { 1700 1701 1702 1703 1704 1705 1706 1707 1703 if { [info exists _fields($fname)] } { 1704 foreach { title units } $_fields($fname) break 1705 if { $units != "" } { 1706 set title [format "%s (%s)" $title $units] 1707 } 1708 } else { 1709 set title $fname 1710 } 1708 1711 } 1709 1712 # If there's a title too, substract one more line 1710 1713 if { $title != "" } { 1711 incr h -$lineht 1714 incr h -$lineht 1712 1715 } 1713 1716 if { $h < 1 } { … … 1716 1719 # Set the legend on the first heightmap dataset. 1717 1720 if { $_currentColormap != "" } { 1718 set cmap $_currentColormap 1719 SendCmd "legend $cmap scalar $_curFldName {} $w $h 0" 1721 set cmap $_currentColormap 1722 #SendCmd "legend $cmap scalar $_curFldName {} $w $h 0" 1723 SendCmd "legend2 $cmap $w $h" 1720 1724 } 1721 1725 } … … 1770 1774 # Keep track of the colormaps that we build. 1771 1775 if { $name != "none" && ![info exists _colormaps($name)] } { 1772 BuildColormap $name 1776 BuildColormap $name 1773 1777 set _colormaps($name) 1 1774 1778 } … … 1776 1780 SendCmd "heightmap colormap $_currentColormap" 1777 1781 } 1778 1779 1782 1780 1783 # … … 1797 1800 itcl::configbody Rappture::VtkHeightmapViewer::mode { 1798 1801 switch -- $itk_option(-mode) { 1799 1800 set _settings(isHeightmap) 11801 1802 1803 set _settings(isHeightmap) 01804 } 1805 1806 1807 1802 "heightmap" { 1803 set _settings(-isheightmap) 1 1804 } 1805 "contour" { 1806 set _settings(-isheightmap) 0 1807 } 1808 default { 1809 error "unknown mode settings \"$itk_option(-mode)\"" 1810 } 1808 1811 } 1809 1812 if { !$_reset } { 1810 AdjustSetting isHeightmap1813 AdjustSetting -isheightmap 1811 1814 } 1812 1815 } … … 1821 1824 SendCmd "screen bgcolor $rgb" 1822 1825 } 1823 1826 $itk_component(view) configure -background $itk_option(-plotbackground) 1824 1827 } 1825 1828 } … … 1832 1835 set rgb [Color2RGB $itk_option(-plotforeground)] 1833 1836 if { !$_reset } { 1837 SendCmd "axis color all $rgb" 1834 1838 SendCmd "outline color $rgb" 1835 SendCmd "axis color all $rgb" 1836 } 1837 } 1838 } 1839 1840 itcl::body Rappture::VtkHeightmapViewer::limits3 { dataobj } { 1841 lappend limits x [$dataobj limits x] 1842 lappend limits y [$dataobj limits y] 1843 if { [catch { $dataobj limits $_curFldName } vlim] != 0 } { 1844 set vlim [$dataobj limits v] 1845 } 1846 lappend limits v $vlim 1847 return $limits 1839 } 1840 } 1848 1841 } 1849 1842 … … 1860 1853 checkbutton $inner.legend \ 1861 1854 -text "Legend" \ 1862 -variable [itcl::scope _settings( legendVisible)] \1863 -command [itcl::code $this AdjustSetting legendVisible] \1855 -variable [itcl::scope _settings(-legendvisible)] \ 1856 -command [itcl::code $this AdjustSetting -legendvisible] \ 1864 1857 -font "Arial 9" 1865 1858 1866 1859 checkbutton $inner.wireframe \ 1867 1860 -text "Wireframe" \ 1868 -variable [itcl::scope _settings( wireframe)] \1869 -command [itcl::code $this AdjustSetting wireframe] \1861 -variable [itcl::scope _settings(-wireframe)] \ 1862 -command [itcl::code $this AdjustSetting -wireframe] \ 1870 1863 -font "Arial 9" 1871 1864 1872 1865 itk_component add lighting { 1873 1874 1875 -variable [itcl::scope _settings(lighting)] \1876 -command [itcl::code $this AdjustSettinglighting] \1877 1866 checkbutton $inner.lighting \ 1867 -text "Enable Lighting" \ 1868 -variable [itcl::scope _settings(-lighting)] \ 1869 -command [itcl::code $this AdjustSetting -lighting] \ 1870 -font "Arial 9" 1878 1871 } { 1879 1872 ignore -font 1880 1873 } 1881 1874 checkbutton $inner.edges \ 1882 1875 -text "Edges" \ 1883 -variable [itcl::scope _settings( edges)] \1884 -command [itcl::code $this AdjustSetting edges] \1876 -variable [itcl::scope _settings(-edges)] \ 1877 -command [itcl::code $this AdjustSetting -edges] \ 1885 1878 -font "Arial 9" 1886 1879 … … 1888 1881 checkbutton $inner.outline \ 1889 1882 -text "Outline" \ 1890 -variable [itcl::scope _settings( outline)] \1891 -command [itcl::code $this AdjustSetting outline] \1883 -variable [itcl::scope _settings(-outline)] \ 1884 -command [itcl::code $this AdjustSetting -outline] \ 1892 1885 -font "Arial 9" 1893 1886 } { … … 1896 1889 checkbutton $inner.stretch \ 1897 1890 -text "Stretch to fit" \ 1898 -variable [itcl::scope _settings( stretchToFit)] \1899 -command [itcl::code $this AdjustSetting stretchToFit] \1891 -variable [itcl::scope _settings(-stretchtofit)] \ 1892 -command [itcl::code $this AdjustSetting -stretchtofit] \ 1900 1893 -font "Arial 9" 1901 1894 1902 1895 checkbutton $inner.isolines \ 1903 1896 -text "Isolines" \ 1904 -variable [itcl::scope _settings( isolinesVisible)] \1905 -command [itcl::code $this AdjustSetting isolinesVisible] \1897 -variable [itcl::scope _settings(-isolinesvisible)] \ 1898 -command [itcl::code $this AdjustSetting -isolinesvisible] \ 1906 1899 -font "Arial 9" 1907 1900 1908 1901 checkbutton $inner.colormapDiscrete \ 1909 1902 -text "Discrete Colormap" \ 1910 -variable [itcl::scope _settings( colormapDiscrete)] \1911 -command [itcl::code $this AdjustSetting colormapDiscrete] \1903 -variable [itcl::scope _settings(-colormapdiscrete)] \ 1904 -command [itcl::code $this AdjustSetting -colormapdiscrete] \ 1912 1905 -font "Arial 9" 1913 1906 1914 1907 itk_component add field_l { 1915 label $inner.field_l -text "Field" -font "Arial 9" 1908 label $inner.field_l -text "Field" -font "Arial 9" 1916 1909 } { 1917 1910 ignore -font … … 1921 1914 } 1922 1915 bind $inner.field <<Value>> \ 1923 [itcl::code $this AdjustSetting field]1924 1925 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1916 [itcl::code $this AdjustSetting -field] 1917 1918 label $inner.colormap_l -text "Colormap" -font "Arial 9" 1926 1919 itk_component add colormap { 1927 1920 Rappture::Combobox $inner.colormap -width 10 -editable no 1928 1921 } 1929 $inner.colormap choices insert end \ 1930 "BCGYR" "BCGYR" \ 1931 "BGYOR" "BGYOR" \ 1932 "blue" "blue" \ 1933 "blue-to-brown" "blue-to-brown" \ 1934 "blue-to-orange" "blue-to-orange" \ 1935 "blue-to-grey" "blue-to-grey" \ 1936 "green-to-magenta" "green-to-magenta" \ 1937 "greyscale" "greyscale" \ 1938 "nanohub" "nanohub" \ 1939 "rainbow" "rainbow" \ 1940 "spectral" "spectral" \ 1941 "ROYGB" "ROYGB" \ 1942 "RYGCB" "RYGCB" \ 1943 "brown-to-blue" "brown-to-blue" \ 1944 "grey-to-blue" "grey-to-blue" \ 1945 "orange-to-blue" "orange-to-blue" \ 1946 "none" "none" 1947 1948 $itk_component(colormap) value "BCGYR" 1922 $inner.colormap choices insert end [GetColormapList -includeNone] 1923 $itk_component(colormap) value $_settings(-colormap) 1949 1924 bind $inner.colormap <<Value>> \ 1950 [itcl::code $this AdjustSetting colormap]1951 1952 label $inner.isolinecolor_l -text "Isolines Color" -font "Arial 9" 1925 [itcl::code $this AdjustSetting -colormap] 1926 1927 label $inner.isolinecolor_l -text "Isolines Color" -font "Arial 9" 1953 1928 itk_component add isolinecolor { 1954 1929 Rappture::Combobox $inner.isolinecolor -width 10 -editable no … … 1964 1939 "red" "red" \ 1965 1940 "white" "white" \ 1966 "none""none"1967 1968 $itk_component(isolinecolor) value "black"1941 "none" "none" 1942 1943 $itk_component(isolinecolor) value $_settings(-isolinecolor) 1969 1944 bind $inner.isolinecolor <<Value>> \ 1970 [itcl::code $this AdjustSetting isolineColor]1971 1972 label $inner.background_l -text "Background Color" -font "Arial 9" 1945 [itcl::code $this AdjustSetting -isolinecolor] 1946 1947 label $inner.background_l -text "Background Color" -font "Arial 9" 1973 1948 itk_component add background { 1974 1949 Rappture::Combobox $inner.background -width 10 -editable no … … 1977 1952 "black" "black" \ 1978 1953 "white" "white" \ 1979 "grey" "grey" 1954 "grey" "grey" 1980 1955 1981 1956 $itk_component(background) value "white" 1982 bind $inner.background <<Value>> [itcl::code $this AdjustSetting background] 1957 bind $inner.background <<Value>> \ 1958 [itcl::code $this AdjustSetting -background] 1983 1959 1984 1960 itk_component add opacity_l { … … 1989 1965 itk_component add opacity { 1990 1966 ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ 1991 -variable [itcl::scope _settings( opacity)] \1967 -variable [itcl::scope _settings(-opacity)] \ 1992 1968 -showvalue off \ 1993 -command [itcl::code $this AdjustSetting opacity]1969 -command [itcl::code $this AdjustSetting -opacity] 1994 1970 } 1995 1971 itk_component add scale_l { … … 2000 1976 itk_component add scale { 2001 1977 ::scale $inner.scale -from 0 -to 100 -orient horizontal \ 2002 -variable [itcl::scope _settings( heightmapScale)] \1978 -variable [itcl::scope _settings(-heightmapscale)] \ 2003 1979 -showvalue off \ 2004 -command [itcl::code $this AdjustSetting heightmapScale]1980 -command [itcl::code $this AdjustSetting -heightmapscale] 2005 1981 } 2006 1982 label $inner.numisolines_l -text "Number of Isolines" -font "Arial 9" … … 2009 1985 -min 0 -max 50 -font "arial 9" 2010 1986 } 2011 $itk_component(numisolines) value $_settings( numIsolines)1987 $itk_component(numisolines) value $_settings(-numisolines) 2012 1988 bind $itk_component(numisolines) <<Value>> \ 2013 [itcl::code $this AdjustSetting numIsolines]1989 [itcl::code $this AdjustSetting -numisolines] 2014 1990 2015 1991 frame $inner.separator1 -height 2 -relief sunken -bd 1 … … 2023 1999 2,0 $inner.isolinecolor_l -anchor w -pady 2 \ 2024 2000 2,1 $inner.isolinecolor -anchor w -pady 2 -fill x \ 2025 2026 2001 3,0 $inner.background_l -anchor w -pady 2 \ 2002 3,1 $inner.background -anchor w -pady 2 -fill x \ 2027 2003 4,0 $inner.numisolines_l -anchor w -pady 2 \ 2028 2004 4,1 $inner.numisolines -anchor w -pady 2 \ … … 2058 2034 checkbutton $inner.visible \ 2059 2035 -text "Axes" \ 2060 -variable [itcl::scope _settings( axisVisible)] \2061 -command [itcl::code $this AdjustSetting axisVisible] \2036 -variable [itcl::scope _settings(-axisvisible)] \ 2037 -command [itcl::code $this AdjustSetting -axisvisible] \ 2062 2038 -font "Arial 9" 2063 2039 checkbutton $inner.labels \ 2064 2040 -text "Axis Labels" \ 2065 -variable [itcl::scope _settings( axisLabels)] \2066 -command [itcl::code $this AdjustSetting axisLabels] \2041 -variable [itcl::scope _settings(-axislabels)] \ 2042 -command [itcl::code $this AdjustSetting -axislabels] \ 2067 2043 -font "Arial 9" 2068 label $inner.grid_l -text "Grid" -font "Arial 9" 2044 label $inner.grid_l -text "Grid" -font "Arial 9" 2069 2045 checkbutton $inner.xgrid \ 2070 2046 -text "X" \ 2071 -variable [itcl::scope _settings( axisXGrid)] \2072 -command [itcl::code $this AdjustSetting axisXGrid] \2047 -variable [itcl::scope _settings(-xgrid)] \ 2048 -command [itcl::code $this AdjustSetting -xgrid] \ 2073 2049 -font "Arial 9" 2074 2050 checkbutton $inner.ygrid \ 2075 2051 -text "Y" \ 2076 -variable [itcl::scope _settings( axisYGrid)] \2077 -command [itcl::code $this AdjustSetting axisYGrid] \2052 -variable [itcl::scope _settings(-ygrid)] \ 2053 -command [itcl::code $this AdjustSetting -ygrid] \ 2078 2054 -font "Arial 9" 2079 2055 checkbutton $inner.zgrid \ 2080 2056 -text "Z" \ 2081 -variable [itcl::scope _settings( axisZGrid)] \2082 -command [itcl::code $this AdjustSetting axisZGrid] \2057 -variable [itcl::scope _settings(-zgrid)] \ 2058 -command [itcl::code $this AdjustSetting -zgrid] \ 2083 2059 -font "Arial 9" 2084 2060 checkbutton $inner.minorticks \ 2085 2061 -text "Minor Ticks" \ 2086 -variable [itcl::scope _settings( axisMinorTicks)] \2087 -command [itcl::code $this AdjustSetting axisMinorTicks] \2062 -variable [itcl::scope _settings(-axisminorticks)] \ 2063 -command [itcl::code $this AdjustSetting -axisminorticks] \ 2088 2064 -font "Arial 9" 2089 2065 2090 2091 label $inner.mode_l -text "Mode" -font "Arial 9" 2066 label $inner.mode_l -text "Mode" -font "Arial 9" 2092 2067 2093 2068 itk_component add axisflymode { … … 2098 2073 "closest_triad" "closest" \ 2099 2074 "furthest_triad" "farthest" \ 2100 "outer_edges" "outer" 2101 $itk_component(axisflymode) value "static"2102 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axisFlymode]2075 "outer_edges" "outer" 2076 $itk_component(axisflymode) value $_settings(-axisflymode) 2077 bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axisflymode] 2103 2078 2104 2079 blt::table $inner \ … … 2106 2081 1,0 $inner.labels -anchor w -cspan 4 \ 2107 2082 2,0 $inner.minorticks -anchor w -cspan 4 \ 2108 2083 4,0 $inner.grid_l -anchor w \ 2109 2084 4,1 $inner.xgrid -anchor w \ 2110 2085 4,2 $inner.ygrid -anchor w \ 2111 2086 4,3 $inner.zgrid -anchor w \ 2112 2087 5,0 $inner.mode_l -anchor w -padx { 2 0 } \ 2113 5,1 $inner.mode -fill x -cspan 3 2088 5,1 $inner.mode -fill x -cspan 3 2114 2089 2115 2090 blt::table configure $inner r* c* -resize none … … 2117 2092 blt::table configure $inner r3 -height 0.125i 2118 2093 } 2119 2120 2094 2121 2095 itcl::body Rappture::VtkHeightmapViewer::BuildCameraTab {} { … … 2137 2111 0,0 $inner.view_l -anchor e -pady 2 \ 2138 2112 0,1 $inner.view -anchor w -pady 2 2113 blt::table configure $inner r0 -resize none 2139 2114 2140 2115 set labels { qx qy qz qw xpan ypan zoom } … … 2143 2118 label $inner.${tag}label -text $tag -font "Arial 9" 2144 2119 entry $inner.${tag} -font "Arial 9" -bg white \ 2145 -textvariable [itcl::scope _view( $tag)]2120 -textvariable [itcl::scope _view(-$tag)] 2146 2121 bind $inner.${tag} <Return> \ 2147 [itcl::code $this camera set ${tag}]2122 [itcl::code $this camera set -${tag}] 2148 2123 bind $inner.${tag} <KP_Enter> \ 2149 [itcl::code $this camera set ${tag}]2124 [itcl::code $this camera set -${tag}] 2150 2125 blt::table $inner \ 2151 2126 $row,0 $inner.${tag}label -anchor e -pady 2 \ … … 2156 2131 checkbutton $inner.ortho \ 2157 2132 -text "Orthographic Projection" \ 2158 -variable [itcl::scope _view( ortho)] \2159 -command [itcl::code $this camera set ortho] \2133 -variable [itcl::scope _view(-ortho)] \ 2134 -command [itcl::code $this camera set -ortho] \ 2160 2135 -font "Arial 9" 2161 2136 blt::table $inner \ … … 2164 2139 incr row 2165 2140 2166 blt::table configure $inner c* r*-resize none2141 blt::table configure $inner c* -resize none 2167 2142 blt::table configure $inner c2 -resize expand 2168 2143 blt::table configure $inner r$row -resize expand … … 2170 2145 2171 2146 # 2172 # camera -- 2147 # camera -- 2173 2148 # 2174 2149 itcl::body Rappture::VtkHeightmapViewer::camera {option args} { 2175 switch -- $option { 2150 switch -- $option { 2176 2151 "show" { 2177 2152 puts [array get _view] 2178 2153 } 2179 2154 "set" { 2180 set wh o[lindex $args 0]2181 set x $_view($wh o)2155 set what [lindex $args 0] 2156 set x $_view($what) 2182 2157 set code [catch { string is double $x } result] 2183 2158 if { $code != 0 || !$result } { 2184 2159 return 2185 2160 } 2186 switch -- $wh o{2187 " ortho" {2188 if {$_view( ortho)} {2161 switch -- $what { 2162 "-ortho" { 2163 if {$_view($what)} { 2189 2164 SendCmd "camera mode ortho" 2190 2165 } else { … … 2192 2167 } 2193 2168 } 2194 " xpan" - "ypan" {2169 "-xpan" - "-ypan" { 2195 2170 PanCamera 2196 2171 } 2197 " qx" - "qy" - "qz" - "qw" {2198 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2172 "-qx" - "-qy" - "-qz" - "-qw" { 2173 set q [ViewToQuaternion] 2199 2174 $_arcball quaternion $q 2200 2175 EventuallyRotate $q 2201 2176 } 2202 " zoom" {2203 SendCmd "camera zoom $_view( zoom)"2177 "-zoom" { 2178 SendCmd "camera zoom $_view($what)" 2204 2179 } 2205 2180 } … … 2221 2196 2222 2197 itcl::body Rappture::VtkHeightmapViewer::GetImage { args } { 2223 if { [image width $_image(download)] > 0 && 2198 if { [image width $_image(download)] > 0 && 2224 2199 [image height $_image(download)] > 0 } { 2225 2200 set bytes [$_image(download) data -format "jpeg -quality 100"] … … 2234 2209 -title "[Rappture::filexfer::label downloadWord] as..." 2235 2210 set inner [$popup component inner] 2236 label $inner.summary -text "" -anchor w 2211 label $inner.summary -text "" -anchor w 2237 2212 radiobutton $inner.vtk_button -text "VTK data file" \ 2238 2213 -variable [itcl::scope _downloadPopup(format)] \ 2239 2214 -font "Arial 9 " \ 2240 -value vtk 2215 -value vtk 2241 2216 Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." 2242 2217 radiobutton $inner.image_button -text "Image File" \ 2243 2218 -variable [itcl::scope _downloadPopup(format)] \ 2244 2219 -font "Arial 9 " \ 2245 -value image 2220 -value image 2246 2221 Rappture::Tooltip::for $inner.image_button \ 2247 2222 "Save as digital image." … … 2264 2239 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ 2265 2240 4,1 $inner.cancel -width .9i -fill y \ 2266 4,0 $inner.ok -padx 2 -width .9i -fill y 2241 4,0 $inner.ok -padx 2 -width .9i -fill y 2267 2242 blt::table configure $inner r3 -height 4 2268 2243 blt::table configure $inner r4 -pady 4 … … 2275 2250 # SetObjectStyle -- 2276 2251 # 2277 # Set the style of the heightmap/contour object. This gets calls 2252 # Set the style of the heightmap/contour object. This gets calls 2278 2253 # for each dataset once as it is loaded. It can overridden by 2279 2254 # the user controls. … … 2285 2260 array set style { 2286 2261 -color BCGYR 2287 -opacity 1002288 2262 -levels 10 2263 -opacity 1.0 2289 2264 } 2290 2265 set stylelist [$dataobj style $comp] … … 2301 2276 # the code to handle aberrant cases. 2302 2277 2303 if { $_changed( opacity) } {2304 set style(-opacity) $_settings(opacity)2305 } 2306 if { $_changed( numIsolines) } {2307 set style(-levels) $_settings( numIsolines)2308 } 2309 if { $_changed( colormap) } {2310 set style(-color) $_settings( colormap)2278 if { $_changed(-opacity) } { 2279 set style(-opacity) [expr $_settings(-opacity) * 0.01] 2280 } 2281 if { $_changed(-numisolines) } { 2282 set style(-levels) $_settings(-numisolines) 2283 } 2284 if { $_changed(-colormap) } { 2285 set style(-color) $_settings(-colormap) 2311 2286 } 2312 2287 if { $_currentColormap == "" } { … … 2314 2289 } 2315 2290 if { [info exists style(-stretchtofit)] } { 2316 set _settings(stretchToFit) $style(-stretchtofit) 2317 AdjustSetting stretchToFit 2318 } 2319 set _currentOpacity $style(-opacity) 2291 set _settings(-stretchtofit) $style(-stretchtofit) 2292 AdjustSetting -stretchtofit 2293 } 2320 2294 if { $_currentNumIsolines != $style(-levels) } { 2321 2295 set _currentNumIsolines $style(-levels) 2322 set _settings( numIsolines) $_currentNumIsolines2296 set _settings(-numisolines) $_currentNumIsolines 2323 2297 $itk_component(numisolines) value $_currentNumIsolines 2324 2298 UpdateContourList … … 2327 2301 SendCmd "outline add $tag" 2328 2302 SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag" 2329 SendCmd "outline visible $_settings( outline) $tag"2303 SendCmd "outline visible $_settings(-outline) $tag" 2330 2304 set scale [GetHeightmapScale] 2331 2305 SendCmd "[list heightmap add contourlist $_contourList $scale $tag]" 2332 set _comp2scale($tag) $_settings( heightmapScale)2333 SendCmd "heightmap edges $_settings( edges) $tag"2334 SendCmd "heightmap wireframe $_settings( wireframe) $tag"2335 SetCurrentColormap $style(-color) 2306 set _comp2scale($tag) $_settings(-heightmapscale) 2307 SendCmd "heightmap edges $_settings(-edges) $tag" 2308 SendCmd "heightmap wireframe $_settings(-wireframe) $tag" 2309 SetCurrentColormap $style(-color) 2336 2310 set color [$itk_component(isolinecolor) value] 2337 2311 SendCmd "heightmap isolinecolor [Color2RGB $color] $tag" 2338 SendCmd "heightmap lighting $_settings(isHeightmap) $tag" 2339 SendCmd "heightmap isolines $_settings(isolinesVisible) $tag" 2340 SendCmd "heightmap surface $_settings(colormapVisible) $tag" 2312 SendCmd "heightmap lighting $_settings(-isheightmap) $tag" 2313 SendCmd "heightmap isolines $_settings(-isolinesvisible) $tag" 2314 SendCmd "heightmap surface $_settings(-colormapvisible) $tag" 2315 SendCmd "heightmap opacity $style(-opacity) $tag" 2316 set _settings(-opacity) [expr $style(-opacity) * 100.0] 2341 2317 } 2342 2318 … … 2365 2341 #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" 2366 2342 if { [catch {DrawLegend} errs] != 0 } { 2367 2368 2343 global errorInfo 2344 puts stderr "errs=$errs errorInfo=$errorInfo" 2369 2345 } 2370 2346 } … … 2383 2359 set font "Arial 8" 2384 2360 set lineht [font metrics $font -linespace] 2385 2361 2386 2362 if { [string match "component*" $fname] } { 2387 2363 set title "" 2388 2364 } else { 2389 2390 2391 2392 2393 2394 2395 2396 2365 if { [info exists _fields($fname)] } { 2366 foreach { title units } $_fields($fname) break 2367 if { $units != "" } { 2368 set title [format "%s (%s)" $title $units] 2369 } 2370 } else { 2371 set title $fname 2372 } 2397 2373 } 2398 2374 set x [expr $w - 2] 2399 if { !$_settings( legendVisible) } {2400 2401 2402 } 2375 if { !$_settings(-legendvisible) } { 2376 $c delete legend 2377 return 2378 } 2403 2379 if { [$c find withtag "legend"] == "" } { 2404 set y 2 2405 2380 set y 2 2381 # If there's a legend title, create a text item for the title. 2406 2382 $c create text $x $y \ 2407 -anchor ne \ 2408 -fill $itk_option(-plotforeground) -tags "title legend" \ 2409 -font $font 2410 $c create text $x $y \ 2411 -anchor ne \ 2412 -fill $itk_option(-plotforeground) -tags "vmax legend" \ 2413 -font $font 2414 incr y $lineht 2415 $c create image $x $y \ 2416 -anchor ne \ 2417 -image $_image(legend) -tags "colormap legend" 2418 $c create rectangle $x $y 1 1 \ 2419 -fill "" -outline "" -tags "sensor legend" 2420 $c create text $x [expr {$h-2}] \ 2421 -anchor se \ 2422 -fill $itk_option(-plotforeground) -tags "vmin legend" \ 2423 -font $font 2424 $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y] 2425 $c bind sensor <Leave> [itcl::code $this LeaveLegend] 2426 $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y] 2383 -anchor ne \ 2384 -fill $itk_option(-plotforeground) -tags "title legend" \ 2385 -font $font 2386 if { $title != "" } { 2387 incr y $lineht 2388 } 2389 $c create text $x $y \ 2390 -anchor ne \ 2391 -fill $itk_option(-plotforeground) -tags "vmax legend" \ 2392 -font $font 2393 incr y $lineht 2394 $c create image $x $y \ 2395 -anchor ne \ 2396 -image $_image(legend) -tags "colormap legend" 2397 $c create rectangle $x $y 1 1 \ 2398 -fill "" -outline "" -tags "sensor legend" 2399 $c create text $x [expr {$h-2}] \ 2400 -anchor se \ 2401 -fill $itk_option(-plotforeground) -tags "vmin legend" \ 2402 -font $font 2403 $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y] 2404 $c bind sensor <Leave> [itcl::code $this LeaveLegend] 2405 $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y] 2427 2406 } 2428 2407 $c delete isoline … … 2435 2414 # Draw the isolines on the legend. 2436 2415 array unset _isolines 2437 if { $color != "none" && [info exists _limits($_curFldName)] && 2438 $_settings( isolinesVisible) && $_currentNumIsolines > 0 } {2416 if { $color != "none" && [info exists _limits($_curFldName)] && 2417 $_settings(-isolinesvisible) && $_currentNumIsolines > 0 } { 2439 2418 2440 2419 foreach { vmin vmax } $_limits($_curFldName) break … … 2444 2423 } 2445 2424 set tags "isoline legend" 2446 2447 2448 2449 2425 set offset [expr 2 + $lineht] 2426 if { $title != "" } { 2427 incr offset $lineht 2428 } 2450 2429 foreach value $_contourList { 2451 2430 set norm [expr 1.0 - (($value - $vmin) / $range)] … … 2455 2434 set _isolines([expr $y1 - $off]) $value 2456 2435 } 2457 2458 2436 $c create line $x1 $y1 $x2 $y1 -fill $color -tags $tags 2437 } 2459 2438 } 2460 2439 … … 2465 2444 if { [info exists _limits($_curFldName)] } { 2466 2445 foreach { vmin vmax } $_limits($_curFldName) break 2467 2468 2446 $c itemconfigure vmin -text [format %g $vmin] 2447 $c itemconfigure vmax -text [format %g $vmax] 2469 2448 } 2470 2449 set y 2 … … 2472 2451 if { $title != "" } { 2473 2452 $c itemconfigure title -text $title 2474 2475 2453 $c coords title $x $y 2454 incr y $lineht 2476 2455 } 2477 2456 $c coords vmax $x $y … … 2521 2500 set font "Arial 8" 2522 2501 set lineht [font metrics $font -linespace] 2523 2502 2524 2503 set ih [image height $_image(legend)] 2525 2504 # Subtract off the offset of the color ramp from the top of the canvas … … 2527 2506 2528 2507 if { [string match "component*" $fname] } { 2529 2508 set title "" 2530 2509 } else { 2531 2532 2533 2534 2535 2536 2537 2538 2510 if { [info exists _fields($fname)] } { 2511 foreach { title units } $_fields($fname) break 2512 if { $units != "" } { 2513 set title [format "%s (%s)" $title $units] 2514 } 2515 } else { 2516 set title $fname 2517 } 2539 2518 } 2540 2519 # If there's a legend title, increase the offset by the line height. … … 2552 2531 } 2553 2532 set color [eval format "\#%02x%02x%02x" $pixel] 2554 $_image(swatch) put black -to 0 0 23 23 2555 $_image(swatch) put $color -to 1 1 22 22 2533 $_image(swatch) put black -to 0 0 23 23 2534 $_image(swatch) put $color -to 1 1 22 22 2556 2535 2557 2536 # Compute the value of the point … … 2563 2542 set value 0.0 2564 2543 } 2565 set tipx [expr $x + 15] 2544 set tipx [expr $x + 15] 2566 2545 set tipy [expr $y - 5] 2567 2546 .rappturetooltip configure -icon $_image(swatch) … … 2571 2550 Rappture::Tooltip::text $c [format "$title %g" $value] 2572 2551 } 2573 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2552 Rappture::Tooltip::tooltip show $c +$tipx,+$tipy 2574 2553 } 2575 2554 … … 2586 2565 # ---------------------------------------------------------------------- 2587 2566 itcl::body Rappture::VtkHeightmapViewer::Combo {option} { 2588 set c $itk_component(view) 2567 set c $itk_component(view) 2589 2568 switch -- $option { 2590 2569 post { … … 2599 2578 } 2600 2579 deactivate { 2601 $c itemconfigure title -fill $itk_option(-plotforeground) 2580 $c itemconfigure title -fill $itk_option(-plotforeground) 2602 2581 } 2603 2582 invoke { 2604 2583 $itk_component(field) value $_curFldLabel 2605 AdjustSetting field2584 AdjustSetting -field 2606 2585 } 2607 2586 default { … … 2612 2591 2613 2592 itcl::body Rappture::VtkHeightmapViewer::GetHeightmapScale {} { 2614 if { $_settings( isHeightmap) } {2615 set val $_settings(heightmapScale)2616 2617 2618 } 2619 return 0 2620 } 2621 2622 itcl::body Rappture::VtkHeightmapViewer::SetOrientation { side } { 2593 if { $_settings(-isheightmap) } { 2594 set val $_settings(-heightmapscale) 2595 set sval [expr { $val >= 50 ? double($val)/50.0 : 1.0/(2.0-(double($val)/50.0)) }] 2596 return $sval 2597 } 2598 return 0 2599 } 2600 2601 itcl::body Rappture::VtkHeightmapViewer::SetOrientation { side } { 2623 2602 array set positions { 2624 2603 front "0.707107 0.707107 0 0" … … 2629 2608 bottom "0 1 0 0" 2630 2609 } 2631 foreach name { qw qx qyqz } value $positions($side) {2610 foreach name { -qw -qx -qy -qz } value $positions($side) { 2632 2611 set _view($name) $value 2633 } 2634 set q [ list $_view(qw) $_view(qx) $_view(qy) $_view(qz)]2612 } 2613 set q [ViewToQuaternion] 2635 2614 $_arcball quaternion $q 2636 2615 SendCmd "camera orient $q" 2637 2616 SendCmd "camera reset" 2638 set _view( xpan) 02639 set _view( ypan) 02640 set _view( zoom) 1.02641 } 2642 2643 itcl::body Rappture::VtkHeightmapViewer::UpdateContourList {} { 2617 set _view(-xpan) 0 2618 set _view(-ypan) 0 2619 set _view(-zoom) 1.0 2620 } 2621 2622 itcl::body Rappture::VtkHeightmapViewer::UpdateContourList {} { 2644 2623 if {$_currentNumIsolines == 0} { 2645 2624 set _contourList ""
Note: See TracChangeset
for help on using the changeset viewer.