Changeset 3652
- Timestamp:
- May 15, 2013, 12:51:40 PM (11 years ago)
- Location:
- branches/1.2/gui/scripts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.2/gui/scripts/sequencedial.tcl
r3330 r3652 1 # -*-mode: tcl; indent-tabs-mode: nil -*-1 mode: tcl; indent-tabs-mode: nil -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: Sequencedial - selector, like the dial on a car radio … … 78 78 private method EventuallyRedraw {} 79 79 private variable _redrawPending 0 80 80 private variable _afterId -1 81 81 private variable _values "" ;# list of all values on the dial 82 82 private variable _val2label ;# maps value => string label(s) … … 121 121 itcl::body Rappture::SequenceDial::destructor {} { 122 122 configure -variable "" ;# remove variable trace 123 EventuallyRedraw123 after cancel $_afterId 124 124 } 125 125 … … 155 155 itcl::body Rappture::SequenceDial::EventuallyRedraw {} { 156 156 if { !$_redrawPending } { 157 after 150 [itcl::code $this _redraw]157 set _afterId [after 150 [itcl::code $this _redraw]] 158 158 event generate $itk_component(hull) <<Value>> 159 159 set _resizePending 1 -
branches/1.2/gui/scripts/vtkheightmapviewer.tcl
r3587 r3652 25 25 option add *VtkHeightmapViewer.plotForeground white widgetDefault 26 26 option add *VtkHeightmapViewer.font \ 27 27 -*-helvetica-medium-r-normal-*-12-* widgetDefault 28 28 29 29 # must use this name -- plugs into Rappture::resources::load 30 30 proc VtkHeightmapViewer_init_resources {} { 31 32 31 Rappture::resources::register \ 32 vtkvis_server Rappture::VtkHeightmapViewer::SetServerList 33 33 } 34 34 35 35 itcl::class Rappture::VtkHeightmapViewer { 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 36 inherit Rappture::VisViewer 37 38 itk_option define -plotforeground plotForeground Foreground "" 39 itk_option define -plotbackground plotBackground Background "" 40 itk_option define -mode mode Mode "contour" 41 42 constructor { hostlist args } { 43 Rappture::VisViewer::constructor $hostlist 44 } { 45 # defined below 46 } 47 destructor { 48 # defined below 49 } 50 public proc SetServerList { namelist } { 51 Rappture::VisViewer::SetServerList "vtkvis" $namelist 52 } 53 public method add {dataobj {settings ""}} 54 public method camera {option args} 55 public method delete {args} 56 public method disconnect {} 57 public method download {option args} 58 public method get {args} 59 public method isconnected {} 60 public method limits3 { dataobj } 61 public method parameters {title args} { 62 # do nothing 63 } 64 public method scale {args} 65 66 protected method Connect {} 67 protected method CurrentDatasets {args} 68 protected method Disconnect {} 69 protected method DoResize {} 70 protected method DoRotate {} 71 protected method AdjustSetting {what {value ""}} 72 protected method AdjustMode {} 73 protected method InitSettings { args } 74 protected method Pan {option x y} 75 protected method Pick {x y} 76 protected method Rebuild {} 77 protected method ReceiveDataset { args } 78 protected method ReceiveImage { args } 79 protected method ReceiveLegend { colormap title min max size } 80 protected method Rotate {option x y} 81 protected method Zoom {option} 82 83 # The following methods are only used by this class. 84 private method BuildAxisTab {} 85 private method BuildCameraTab {} 86 private method BuildColormap { name } 87 private method BuildContourTab {} 88 private method BuildDownloadPopup { widget command } 89 private method Combo { option } 90 private method ConvertToVtkData { dataobj comp } 91 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 } 99 private method LeaveLegend {} 100 private method MotionLegend { x y } 101 private method PanCamera {} 102 private method RequestLegend {} 103 private method SetCurrentColormap { color } 104 private method SetLegendTip { x y } 105 private method SetObjectStyle { dataobj comp } 106 private method GetHeightmapScale {} 107 private method ResetAxes {} 108 private method SetOrientation { side } 109 110 private variable _arcball "" 111 private variable _dlist "" ; # list of data objects 112 private variable _obj2datasets 113 private variable _obj2ovride ; # maps dataobj => style override 114 private variable _comp2scale; # maps dataset to the heightmap scale. 115 private variable _datasets ; # contains all the dataobj-component 116 ; # datasets in the server 117 private variable _colormaps ; # contains all the colormaps 118 ; # in the server. 119 120 # The name of the current colormap used. The colormap is global to all 121 # heightmaps displayed. 122 private variable _currentColormap "" ; 123 private variable _currentNumIsolines "" ; 124 private variable _currentOpacity "" ; 125 126 private variable _click ; # info used for rotate operations 127 private variable _limits ; # Holds overall limits for all dataobjs 128 # using the viewer. 129 private variable _view ; # view params for 3D view 130 private variable _settings 131 private variable _changed 132 private variable _initialStyle ""; # First found style in dataobjects. 133 private variable _reset 1; # Indicates if camera needs to be reset 134 # to starting position. 135 private variable _beforeConnect 1; # Indicates if camera needs to be reset 136 # to starting position. 137 138 private variable _first "" ; # This is the topmost dataset. 139 private variable _start 0 140 private variable _isolines 141 142 common _downloadPopup; # download options from popup 143 private common _hardcopy 144 private variable _width 0 145 private variable _height 0 146 private variable _legendWidth 0 147 private variable _legendHeight 0 148 private variable _resizePending 0 149 private variable _rotatePending 0 150 private variable _legendPending 0 151 private variable _fieldNames {} 152 private variable _fields 153 private variable _curFldName "" 154 private variable _curFldLabel "" 155 private variable _colorMode "vmag";# Mode of colormap (vmag or scalar) 156 156 } 157 157 158 158 itk::usual VtkHeightmapViewer { 159 160 159 keep -background -foreground -cursor -font 160 keep -plotbackground -plotforeground -mode 161 161 } 162 162 … … 165 165 # ---------------------------------------------------------------------- 166 166 itcl::body Rappture::VtkHeightmapViewer::constructor {hostlist args} { 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 167 set _serverType "vtkvis" 168 169 EnableWaitDialog 900 170 # Rebuild event 171 $_dispatcher register !rebuild 172 $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" 173 174 # Resize event 175 $_dispatcher register !resize 176 $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list" 177 178 # Rotate event 179 $_dispatcher register !rotate 180 $_dispatcher dispatch $this !rotate "[itcl::code $this DoRotate]; list" 181 182 # Legend event 183 $_dispatcher register !legend 184 $_dispatcher dispatch $this !legend "[itcl::code $this RequestLegend]; list" 185 186 # 187 # Populate parser with commands handle incoming requests 188 # 189 $_parser alias image [itcl::code $this ReceiveImage] 190 $_parser alias dataset [itcl::code $this ReceiveDataset] 191 $_parser alias legend [itcl::code $this ReceiveLegend] 192 193 # Initialize the view to some default parameters. 194 array set _view { 195 qw 0.36 196 qx 0.25 197 qy 0.50 198 qz 0.70 199 zoom 1.0 200 xpan 0 201 ypan 0 202 ortho 1 203 } 204 set _arcball [blt::arcball create 100 100] 205 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 206 $_arcball quaternion $q 207 208 array set _settings { 209 axisFlymode "static" 210 axisMinorTicks 1 211 stretchToFit 0 212 axisLabels 1 213 axisVisible 1 214 axisXGrid 0 215 axisYGrid 0 216 axisZGrid 0 217 colormapVisible 1 218 colormapDiscrete 0 219 edges 0 220 field "Default" 221 heightmapScale 50 222 isHeightmap 0 223 isolineColor black 224 isolinesVisible 1 225 legendVisible 1 226 lighting 1 227 saveLighting 1 228 numIsolines 10 229 opacity 100 230 outline 0 231 wireframe 0 232 saveOpacity 100 233 saveOutline 0 234 } 235 array set _changed { 236 opacity 0 237 colormap 0 238 numIsolines 0 239 } 240 itk_component add view { 241 canvas $itk_component(plotarea).view \ 242 -highlightthickness 0 -borderwidth 0 243 } { 244 usual 245 ignore -highlightthickness -borderwidth -background 246 } 247 248 itk_component add fieldmenu { 249 menu $itk_component(plotarea).menu \ 250 -relief flat \ 251 -tearoff no 252 } { 253 usual 254 ignore -background -foreground -relief -tearoff 255 } 256 set c $itk_component(view) 257 bind $c <Configure> [itcl::code $this EventuallyResize %w %h] 258 bind $c <4> [itcl::code $this Zoom in 0.25] 259 bind $c <5> [itcl::code $this Zoom out 0.25] 260 bind $c <KeyPress-Left> [list %W xview scroll 10 units] 261 bind $c <KeyPress-Right> [list %W xview scroll -10 units] 262 bind $c <KeyPress-Up> [list %W yview scroll 10 units] 263 bind $c <KeyPress-Down> [list %W yview scroll -10 units] 264 bind $c <Enter> "focus %W" 265 bind $c <Control-F1> [itcl::code $this ToggleConsole] 266 267 # Fix the scrollregion in case we go off screen 268 $c configure -scrollregion [$c bbox all] 269 270 set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] 271 set _map(cwidth) -1 272 set _map(cheight) -1 273 set _map(zoom) 1.0 274 set _map(original) "" 275 276 set f [$itk_component(main) component controls] 277 itk_component add reset { 278 button $f.reset -borderwidth 1 -padx 1 -pady 1 \ 279 -highlightthickness 0 \ 280 -image [Rappture::icon reset-view] \ 281 -command [itcl::code $this Zoom reset] 282 } { 283 usual 284 ignore -highlightthickness 285 } 286 pack $itk_component(reset) -side top -padx 2 -pady 2 287 Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level" 288 289 itk_component add zoomin { 290 button $f.zin -borderwidth 1 -padx 1 -pady 1 \ 291 -highlightthickness 0 \ 292 -image [Rappture::icon zoom-in] \ 293 -command [itcl::code $this Zoom in] 294 } { 295 usual 296 ignore -highlightthickness 297 } 298 pack $itk_component(zoomin) -side top -padx 2 -pady 2 299 Rappture::Tooltip::for $itk_component(zoomin) "Zoom in" 300 301 itk_component add zoomout { 302 button $f.zout -borderwidth 1 -padx 1 -pady 1 \ 303 -highlightthickness 0 \ 304 -image [Rappture::icon zoom-out] \ 305 -command [itcl::code $this Zoom out] 306 } { 307 usual 308 ignore -highlightthickness 309 } 310 pack $itk_component(zoomout) -side top -padx 2 -pady 2 311 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" 312 313 itk_component add mode { 314 Rappture::PushButton $f.mode \ 315 -onimage [Rappture::icon surface] \ 316 -offimage [Rappture::icon surface] \ 317 -variable [itcl::scope _settings(isHeightmap)] \ 318 -command [itcl::code $this AdjustSetting isHeightmap] \ 319 } 320 Rappture::Tooltip::for $itk_component(mode) \ 321 "Toggle the surface/contour on/off" 322 pack $itk_component(mode) -padx 2 -pady 2 323 324 if { [catch { 325 BuildContourTab 326 BuildAxisTab 327 BuildCameraTab 328 } errs] != 0 } { 329 global errorInfo 330 puts stderr "errs=$errs errorInfo=$errorInfo" 331 } 332 set _image(legend) [image create photo] 333 334 # Hack around the Tk panewindow. The problem is that the requested 335 # size of the 3d view isn't set until an image is retrieved from 336 # the server. So the panewindow uses the tiny size. 337 set w 10000 338 pack forget $itk_component(view) 339 blt::table $itk_component(plotarea) \ 340 0,0 $itk_component(view) -fill both -reqwidth $w 341 blt::table configure $itk_component(plotarea) c1 -resize none 342 343 # Bindings for panning via mouse 344 bind $itk_component(view) <ButtonPress-2> \ 345 [itcl::code $this Pan click %x %y] 346 bind $itk_component(view) <B2-Motion> \ 347 [itcl::code $this Pan drag %x %y] 348 bind $itk_component(view) <ButtonRelease-2> \ 349 [itcl::code $this Pan release %x %y] 350 351 #bind $itk_component(view) <ButtonRelease-3> \ 352 # [itcl::code $this Pick %x %y] 353 354 # Bindings for panning via keyboard 355 bind $itk_component(view) <KeyPress-Left> \ 356 [itcl::code $this Pan set -10 0] 357 bind $itk_component(view) <KeyPress-Right> \ 358 [itcl::code $this Pan set 10 0] 359 bind $itk_component(view) <KeyPress-Up> \ 360 [itcl::code $this Pan set 0 -10] 361 bind $itk_component(view) <KeyPress-Down> \ 362 [itcl::code $this Pan set 0 10] 363 bind $itk_component(view) <Shift-KeyPress-Left> \ 364 [itcl::code $this Pan set -2 0] 365 bind $itk_component(view) <Shift-KeyPress-Right> \ 366 [itcl::code $this Pan set 2 0] 367 bind $itk_component(view) <Shift-KeyPress-Up> \ 368 [itcl::code $this Pan set 0 -2] 369 bind $itk_component(view) <Shift-KeyPress-Down> \ 370 [itcl::code $this Pan set 0 2] 371 372 # Bindings for zoom via keyboard 373 bind $itk_component(view) <KeyPress-Prior> \ 374 [itcl::code $this Zoom out] 375 bind $itk_component(view) <KeyPress-Next> \ 376 [itcl::code $this Zoom in] 377 378 bind $itk_component(view) <Enter> "focus $itk_component(view)" 379 380 if {[string equal "x11" [tk windowingsystem]]} { 381 # Bindings for zoom via mouse 382 bind $itk_component(view) <4> [itcl::code $this Zoom out] 383 bind $itk_component(view) <5> [itcl::code $this Zoom in] 384 } 385 386 set _image(download) [image create photo] 387 388 eval itk_initialize $args 389 Connect 390 set _beforeConnect 0 391 391 } 392 392 … … 395 395 # ---------------------------------------------------------------------- 396 396 itcl::body Rappture::VtkHeightmapViewer::destructor {} { 397 398 399 400 397 Disconnect 398 image delete $_image(plot) 399 image delete $_image(download) 400 catch { blt::arcball destroy $_arcball } 401 401 } 402 402 403 403 itcl::body Rappture::VtkHeightmapViewer::DoResize {} { 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 404 if { $_width < 2 } { 405 set _width 500 406 } 407 if { $_height < 2 } { 408 set _height 500 409 } 410 set _start [clock clicks -milliseconds] 411 SendCmd "screen size [expr $_width - 20] $_height" 412 413 set font "Arial 8" 414 set lh [font metrics $font -linespace] 415 set h [expr {$_height - 2 * ($lh + 2)}] 416 if { $h != $_legendHeight } { 417 EventuallyRequestLegend 418 } else { 419 DrawLegend 420 } 421 set _resizePending 0 422 422 } 423 423 424 424 itcl::body Rappture::VtkHeightmapViewer::DoRotate {} { 425 426 427 425 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 426 SendCmd "camera orient $q" 427 set _rotatePending 0 428 428 } 429 429 430 430 itcl::body Rappture::VtkHeightmapViewer::EventuallyRequestLegend {} { 431 432 433 434 431 if { !$_legendPending } { 432 set _legendPending 1 433 $_dispatcher event -idle !legend 434 } 435 435 } 436 436 437 437 itcl::body Rappture::VtkHeightmapViewer::EventuallyResize { w h } { 438 439 440 441 442 443 444 438 set _width $w 439 set _height $h 440 $_arcball resize $w $h 441 if { !$_resizePending } { 442 set _resizePending 1 443 $_dispatcher event -after 250 !resize 444 } 445 445 } 446 446 … … 448 448 449 449 itcl::body Rappture::VtkHeightmapViewer::EventuallyRotate { q } { 450 451 452 453 454 455 450 foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break 451 if { !$_rotatePending } { 452 set _rotatePending 1 453 global rotate_delay 454 $_dispatcher event -after $rotate_delay !rotate 455 } 456 456 } 457 457 … … 464 464 # ---------------------------------------------------------------------- 465 465 itcl::body Rappture::VtkHeightmapViewer::add {dataobj {settings ""}} { 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 466 if { ![$dataobj isvalid] } { 467 return; # Object doesn't contain valid data. 468 } 469 array set params { 470 -color auto 471 -width 1 472 -linestyle solid 473 -brightness 0 474 -raise 0 475 -description "" 476 -param "" 477 -type "" 478 } 479 array set params $settings 480 set params(-description) "" 481 set params(-param) "" 482 foreach {opt val} $settings { 483 if {![info exists params($opt)]} { 484 error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]" 485 } 486 set params($opt) $val 487 } 488 if {$params(-color) == "auto" || $params(-color) == "autoreset"} { 489 # can't handle -autocolors yet 490 set params(-color) white 491 } 492 set pos [lsearch -exact $dataobj $_dlist] 493 if {$pos < 0} { 494 lappend _dlist $dataobj 495 } 496 set _obj2ovride($dataobj-color) $params(-color) 497 set _obj2ovride($dataobj-width) $params(-width) 498 set _obj2ovride($dataobj-raise) $params(-raise) 499 $_dispatcher event -idle !rebuild 500 500 } 501 501 … … 510 510 # ---------------------------------------------------------------------- 511 511 itcl::body Rappture::VtkHeightmapViewer::delete {args} { 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 512 if { [llength $args] == 0} { 513 set args $_dlist 514 } 515 # Delete all specified dataobjs 516 set changed 0 517 foreach dataobj $args { 518 set pos [lsearch -exact $_dlist $dataobj] 519 if { $pos < 0 } { 520 continue; # Don't know anything about it. 521 } 522 # Remove it from the dataobj list. 523 set _dlist [lreplace $_dlist $pos $pos] 524 array unset _obj2ovride $dataobj-* 525 array unset _settings $dataobj-* 526 # Append to the end of the dataobj list. 527 #lappend _dlist $dataobj 528 set changed 1 529 } 530 # If anything changed, then rebuild the plot 531 if { $changed } { 532 $_dispatcher event -idle !rebuild 533 } 534 534 } 535 535 … … 544 544 # ---------------------------------------------------------------------- 545 545 itcl::body Rappture::VtkHeightmapViewer::get {args} { 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 546 if {[llength $args] == 0} { 547 set args "-objects" 548 } 549 set op [lindex $args 0] 550 switch -- $op { 551 "-objects" { 552 # put the dataobj list in order according to -raise options 553 set dlist {} 554 foreach dataobj $_dlist { 555 if { ![IsValidObject $dataobj] } { 556 continue 557 } 558 if {[info exists _obj2ovride($dataobj-raise)] && 559 $_obj2ovride($dataobj-raise)} { 560 set dlist [linsert $dlist 0 $dataobj] 561 } else { 562 lappend dlist $dataobj 563 } 564 } 565 return $dlist 566 } 567 "-visible" { 568 set dlist {} 569 foreach dataobj $_dlist { 570 if { ![IsValidObject $dataobj] } { 571 continue 572 } 573 if { ![info exists _obj2ovride($dataobj-raise)] } { 574 # No setting indicates that the object isn't visible. 575 continue 576 } 577 # Otherwise use the -raise parameter to put the object to 578 # the front of the list. 579 if { $_obj2ovride($dataobj-raise) } { 580 set dlist [linsert $dlist 0 $dataobj] 581 } else { 582 lappend dlist $dataobj 583 } 584 } 585 return $dlist 586 } 587 -image { 588 if {[llength $args] != 2} { 589 error "wrong # args: should be \"get -image view\"" 590 } 591 switch -- [lindex $args end] { 592 view { 593 return $_image(plot) 594 } 595 default { 596 error "bad image name \"[lindex $args end]\": should be view" 597 } 598 } 599 } 600 default { 601 error "bad option \"$op\": should be -objects or -image" 602 } 603 } 604 604 } 605 605 … … 614 614 # 615 615 itcl::body Rappture::VtkHeightmapViewer::scale {args} { 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 616 foreach dataobj $args { 617 if { ![$dataobj isvalid] } { 618 continue; # Object doesn't contain valid data. 619 } 620 foreach axis { x y } { 621 set lim [$dataobj limits $axis] 622 if { ![info exists _limits($axis)] } { 623 set _limits($axis) $lim 624 continue 625 } 626 foreach {min max} $lim break 627 foreach {amin amax} $_limits($axis) break 628 if { $amin > $min } { 629 set amin $min 630 } 631 if { $amax < $max } { 632 set amax $max 633 } 634 set _limits($axis) [list $amin $amax] 635 } 636 foreach { fname lim } [$dataobj fieldlimits] { 637 if { ![info exists _limits($fname)] } { 638 set _limits($fname) $lim 639 continue 640 } 641 foreach {min max} $lim break 642 foreach {fmin fmax} $_limits($fname) break 643 if { $fmin > $min } { 644 set fmin $min 645 } 646 if { $fmax < $max } { 647 set fmax $max 648 } 649 set _limits($fname) [list $fmin $fmax] 650 } 651 } 652 652 } 653 653 … … 663 663 # ---------------------------------------------------------------------- 664 664 itcl::body Rappture::VtkHeightmapViewer::download {option args} { 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 665 switch $option { 666 coming { 667 if {[catch { 668 blt::winop snap $itk_component(plotarea) $_image(download) 669 }]} { 670 $_image(download) configure -width 1 -height 1 671 $_image(download) put #000000 672 } 673 } 674 controls { 675 set popup .vtkviewerdownload 676 if { ![winfo exists .vtkviewerdownload] } { 677 set inner [BuildDownloadPopup $popup [lindex $args 0]] 678 } else { 679 set inner [$popup component inner] 680 } 681 set _downloadPopup(image_controls) $inner.image_frame 682 set num [llength [get]] 683 set num [expr {($num == 1) ? "1 result" : "$num results"}] 684 set word [Rappture::filexfer::label downloadWord] 685 $inner.summary configure -text "$word $num in the following format:" 686 update idletasks ;# Fix initial sizes 687 return $popup 688 } 689 now { 690 set popup .vtkviewerdownload 691 if {[winfo exists .vtkviewerdownload]} { 692 $popup deactivate 693 } 694 switch -- $_downloadPopup(format) { 695 "image" { 696 return [$this GetImage [lindex $args 0]] 697 } 698 "vtk" { 699 return [$this GetVtkData [lindex $args 0]] 700 } 701 } 702 return "" 703 } 704 default { 705 error "bad option \"$option\": should be coming, controls, now" 706 } 707 } 708 708 } 709 709 … … 716 716 # ---------------------------------------------------------------------- 717 717 itcl::body Rappture::VtkHeightmapViewer::Connect {} { 718 719 720 721 722 723 724 725 726 727 728 729 730 731 718 global readyForNextFrame 719 set readyForNextFrame 1 720 set _reset 1 721 set _hosts [GetServerList "vtkvis"] 722 if { "" == $_hosts } { 723 return 0 724 } 725 set result [VisViewer::Connect $_hosts] 726 if { $result } { 727 set w [winfo width $itk_component(view)] 728 set h [winfo height $itk_component(view)] 729 EventuallyResize $w $h 730 } 731 return $result 732 732 } 733 733 … … 738 738 # 739 739 itcl::body Rappture::VtkHeightmapViewer::isconnected {} { 740 740 return [VisViewer::IsConnected] 741 741 } 742 742 … … 745 745 # 746 746 itcl::body Rappture::VtkHeightmapViewer::disconnect {} { 747 748 747 Disconnect 748 set _reset 1 749 749 } 750 750 … … 756 756 # 757 757 itcl::body Rappture::VtkHeightmapViewer::Disconnect {} { 758 759 760 761 762 763 764 765 766 767 768 769 770 758 VisViewer::Disconnect 759 760 $_dispatcher cancel !rebuild 761 $_dispatcher cancel !resize 762 $_dispatcher cancel !rotate 763 $_dispatcher cancel !legend 764 # disconnected -- no more data sitting on server 765 array unset _datasets 766 array unset _data 767 array unset _colormaps 768 array unset _obj2datasets 769 global readyForNextFrame 770 set readyForNextFrame 1 771 771 } 772 772 … … 779 779 # ---------------------------------------------------------------------- 780 780 itcl::body Rappture::VtkHeightmapViewer::ReceiveImage { args } { 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 781 global readyForNextFrame 782 set readyForNextFrame 1 783 array set info { 784 -token "???" 785 -bytes 0 786 -type image 787 } 788 array set info $args 789 set bytes [ReceiveBytes $info(-bytes)] 790 if { $info(-type) == "image" } { 791 if 0 { 792 set f [open "last.ppm" "w"] 793 puts $f $bytes 794 close $f 795 } 796 $_image(plot) configure -data $bytes 797 set time [clock seconds] 798 set date [clock format $time] 799 #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" 800 if { $_start > 0 } { 801 set finish [clock clicks -milliseconds] 802 #puts stderr "round trip time [expr $finish -$_start] milliseconds" 803 set _start 0 804 } 805 } elseif { $info(type) == "print" } { 806 set tag $this-print-$info(-token) 807 set _hardcopy($tag) $bytes 808 } 809 809 } 810 810 … … 813 813 # 814 814 itcl::body Rappture::VtkHeightmapViewer::ReceiveDataset { args } { 815 if { ![isconnected] } { 816 return 817 } 818 set option [lindex $args 0] 815 if { ![isconnected] } { 816 return 817 } 818 set option [lindex $args 0] 819 switch -- $option { 820 "scalar" { 821 set option [lindex $args 1] 819 822 switch -- $option { 820 "scalar" { 821 set option [lindex $args 1] 822 switch -- $option { 823 "world" { 824 foreach { x y z value tag } [lrange $args 2 end] break 825 } 826 "pixel" { 827 foreach { x y value tag } [lrange $args 2 end] break 828 } 829 } 830 } 831 "vector" { 832 set option [lindex $args 1] 833 switch -- $option { 834 "world" { 835 foreach { x y z vx vy vz tag } [lrange $args 2 end] break 836 } 837 "pixel" { 838 foreach { x y vx vy vz tag } [lrange $args 2 end] break 839 } 840 } 841 } 842 "names" { 843 foreach { name } [lindex $args 1] { 844 #puts stderr "Dataset: $name" 845 } 846 } 847 default { 848 error "unknown dataset option \"$option\" from server" 849 } 850 } 823 "world" { 824 foreach { x y z value tag } [lrange $args 2 end] break 825 } 826 "pixel" { 827 foreach { x y value tag } [lrange $args 2 end] break 828 } 829 } 830 } 831 "vector" { 832 set option [lindex $args 1] 833 switch -- $option { 834 "world" { 835 foreach { x y z vx vy vz tag } [lrange $args 2 end] break 836 } 837 "pixel" { 838 foreach { x y vx vy vz tag } [lrange $args 2 end] break 839 } 840 } 841 } 842 "names" { 843 foreach { name } [lindex $args 1] { 844 #puts stderr "Dataset: $name" 845 } 846 } 847 default { 848 error "unknown dataset option \"$option\" from server" 849 } 850 } 851 851 } 852 852 … … 859 859 # ---------------------------------------------------------------------- 860 860 itcl::body Rappture::VtkHeightmapViewer::Rebuild {} { 861 set w [winfo width $itk_component(view)] 862 set h [winfo height $itk_component(view)] 863 if { $w < 2 || $h < 2 } { 864 $_dispatcher event -idle !rebuild 865 return 866 } 867 868 if { $_reset && $_reportClientInfo } { 869 # Tell the server the name of the tool, the version, and dataset 870 # that we are rendering. Have to do it here because we don't know 871 # what data objects are using the renderer until be get here. 872 global env 873 874 set info {} 875 set user "???" 876 if { [info exists env(USER)] } { 877 set user $env(USER) 878 } 879 set session "???" 880 if { [info exists env(SESSION)] } { 881 set session $env(SESSION) 882 } 883 lappend info "hub" [exec hostname] 884 lappend info "client" "vtkheightmapviewer" 885 lappend info "user" $user 886 lappend info "session" $session 887 SendCmd "clientinfo [list $info]" 888 } 889 890 # Turn on buffering of commands to the server. We don't want to 891 # be preempted by a server disconnect/reconnect (which automatically 892 # generates a new call to Rebuild). 893 StartBufferingCommands 894 895 if { $_width != $w || $_height != $h || $_reset } { 896 set _width $w 897 set _height $h 898 $_arcball resize $w $h 899 DoResize 900 if { $_settings(stretchToFit) } { 901 AdjustSetting stretchToFit 902 } 903 } 904 if { $_reset } { 905 InitSettings isHeightmap background 906 # 907 # Reset the camera and other view parameters 908 # 909 SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]" 910 911 # Let's see how this goes. I think it's preferable to overloading the 912 # axis title with the exponent. 913 SendCmd "axis exp 0 0 0 1" 914 915 SendCmd "axis lrot z 90" 916 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 917 $_arcball quaternion $q 918 if {$_settings(isHeightmap) } { 919 if { $_view(ortho)} { 920 SendCmd "camera mode ortho" 921 } else { 922 SendCmd "camera mode persp" 923 } 924 DoRotate 925 SendCmd "camera reset" 926 } 927 PanCamera 928 StopBufferingCommands 929 SendCmd "imgflush" 930 StartBufferingCommands 931 } 932 933 set _first "" 934 # Start off with no datasets are visible. 935 SendCmd "dataset visible 0" 936 set scale [GetHeightmapScale] 937 foreach dataobj [get -objects] { 938 if { [info exists _obj2ovride($dataobj-raise)] && $_first == "" } { 939 set _first $dataobj 940 } 941 set _obj2datasets($dataobj) "" 942 foreach comp [$dataobj components] { 943 set tag $dataobj-$comp 944 if { ![info exists _datasets($tag)] } { 945 set bytes [$dataobj vtkdata $comp] 946 if 0 { 947 set f [open /tmp/vtkheightmap.vtk "w"] 948 puts $f $bytes 949 close $f 950 } 951 set length [string length $bytes] 952 if { $_reportClientInfo } { 953 set info {} 954 lappend info "tool_id" [$dataobj hints toolId] 955 lappend info "tool_name" [$dataobj hints toolName] 956 lappend info "tool_version" [$dataobj hints toolRevision] 957 lappend info "tool_title" [$dataobj hints toolTitle] 958 lappend info "dataset_label" [$dataobj hints label] 959 lappend info "dataset_size" $length 960 lappend info "dataset_tag" $tag 961 SendCmd [list "clientinfo" $info] 962 } 963 SendCmd "dataset add $tag data follows $length" 964 append _outbuf $bytes 965 set _datasets($tag) 1 966 SetObjectStyle $dataobj $comp 967 } 968 lappend _obj2datasets($dataobj) $tag 969 if { [info exists _obj2ovride($dataobj-raise)] } { 970 # Setting dataset visible enables outline 971 # and heightmap 972 SendCmd "dataset visible 1 $tag" 973 } 974 if { ![info exists _comp2scale($tag)] || 975 $_comp2scale($tag) != $scale } { 976 SendCmd "heightmap heightscale $scale $tag" 977 set _comp2scale($tag) $scale 861 set w [winfo width $itk_component(view)] 862 set h [winfo height $itk_component(view)] 863 if { $w < 2 || $h < 2 } { 864 $_dispatcher event -idle !rebuild 865 return 866 } 867 868 if { $_reset && $_reportClientInfo } { 869 # Tell the server the name of the tool, the version, and dataset 870 # that we are rendering. Have to do it here because we don't know 871 # what data objects are using the renderer until be get here. 872 global env 873 874 set info {} 875 set user "???" 876 if { [info exists env(USER)] } { 877 set user $env(USER) 878 } 879 set session "???" 880 if { [info exists env(SESSION)] } { 881 set session $env(SESSION) 882 } 883 lappend info "hub" [exec hostname] 884 lappend info "client" "vtkheightmapviewer" 885 lappend info "user" $user 886 lappend info "session" $session 887 SendCmd "clientinfo [list $info]" 888 } 889 890 # Turn on buffering of commands to the server. We don't want to 891 # be preempted by a server disconnect/reconnect (which automatically 892 # generates a new call to Rebuild). 893 StartBufferingCommands 894 895 if { $_width != $w || $_height != $h || $_reset } { 896 set _width $w 897 set _height $h 898 $_arcball resize $w $h 899 DoResize 900 if { $_settings(stretchToFit) } { 901 AdjustSetting stretchToFit 902 } 903 } 904 if { $_reset } { 905 InitSettings isHeightmap background 906 # 907 # Reset the camera and other view parameters 908 # 909 SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]" 910 911 # Let's see how this goes. I think it's preferable to overloading the 912 # axis title with the exponent. 913 SendCmd "axis exp 0 0 0 1" 914 915 SendCmd "axis lrot z 90" 916 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 917 $_arcball quaternion $q 918 if {$_settings(isHeightmap) } { 919 if { $_view(ortho)} { 920 SendCmd "camera mode ortho" 921 } else { 922 SendCmd "camera mode persp" 923 } 924 DoRotate 925 SendCmd "camera reset" 926 } 927 PanCamera 928 StopBufferingCommands 929 SendCmd "imgflush" 930 StartBufferingCommands 931 } 932 933 set _first "" 934 # Start off with no datasets are visible. 935 SendCmd "dataset visible 0" 936 set scale [GetHeightmapScale] 937 foreach dataobj [get -objects] { 938 if { [info exists _obj2ovride($dataobj-raise)] && $_first == "" } { 939 set _first $dataobj 940 } 941 set _obj2datasets($dataobj) "" 942 foreach comp [$dataobj components] { 943 set tag $dataobj-$comp 944 if { ![info exists _datasets($tag)] } { 945 set bytes [$dataobj vtkdata $comp] 946 if 0 { 947 set f [open /tmp/vtkheightmap.vtk "w"] 948 puts $f $bytes 949 close $f 950 } 951 set length [string length $bytes] 952 if { $_reportClientInfo } { 953 set info {} 954 lappend info "tool_id" [$dataobj hints toolId] 955 lappend info "tool_name" [$dataobj hints toolName] 956 lappend info "tool_version" [$dataobj hints toolRevision] 957 lappend info "tool_title" [$dataobj hints toolTitle] 958 lappend info "dataset_label" [$dataobj hints label] 959 lappend info "dataset_size" $length 960 lappend info "dataset_tag" $tag 961 SendCmd [list "clientinfo" $info] 962 } 963 SendCmd "dataset add $tag data follows $length" 964 append _outbuf $bytes 965 set _datasets($tag) 1 966 SetObjectStyle $dataobj $comp 967 } 968 lappend _obj2datasets($dataobj) $tag 969 if { [info exists _obj2ovride($dataobj-raise)] } { 970 # Setting dataset visible enables outline 971 # and heightmap 972 SendCmd "dataset visible 1 $tag" 973 } 974 if { ![info exists _comp2scale($tag)] || 975 $_comp2scale($tag) != $scale } { 976 SendCmd "heightmap heightscale $scale $tag" 977 set _comp2scale($tag) $scale 978 } 979 } 980 } 981 if { $_first != "" } { 982 $itk_component(field) choices delete 0 end 983 $itk_component(fieldmenu) delete 0 end 984 array unset _fields 985 set _curFldName "" 986 foreach cname [$_first components] { 987 foreach fname [$_first fieldnames $cname] { 988 if { [info exists _fields($fname)] } { 989 continue 990 } 991 foreach { label units components } \ 992 [$_first fieldinfo $fname] break 993 $itk_component(field) choices insert end "$fname" "$label" 994 $itk_component(fieldmenu) add radiobutton -label "$label" \ 995 -value $label -variable [itcl::scope _curFldLabel] \ 996 -selectcolor red \ 997 -activebackground $itk_option(-plotbackground) \ 998 -activeforeground $itk_option(-plotforeground) \ 999 -font "Arial 8" \ 1000 -command [itcl::code $this Combo invoke] 1001 set _fields($fname) [list $label $units $components] 1002 if { $_curFldName == "" } { 1003 set _curFldName $fname 1004 set _curFldLabel $label 1005 } 1006 } 1007 } 1008 $itk_component(field) value $_curFldLabel 1009 } 1010 InitSettings stretchToFit outline 1011 1012 if { $_reset } { 1013 SendCmd "axis tickpos outside" 1014 foreach axis { x y z } { 1015 SendCmd "axis lformat $axis %g" 1016 } 1017 1018 foreach axis { x y z } { 1019 set label [$_first hints ${axis}label] 1020 if { $label == "" } { 1021 if {$axis == "z"} { 1022 if { [string match "component*" $_curFldName] } { 1023 set label [string toupper $axis] 1024 } else { 1025 set label $_curFldLabel 978 1026 } 979 } 980 } 981 if { $_first != "" } { 982 $itk_component(field) choices delete 0 end 983 $itk_component(fieldmenu) delete 0 end 984 array unset _fields 985 set _curFldName "" 986 foreach cname [$_first components] { 987 foreach fname [$_first fieldnames $cname] { 988 if { [info exists _fields($fname)] } { 989 continue 990 } 991 foreach { label units components } \ 992 [$_first fieldinfo $fname] break 993 $itk_component(field) choices insert end "$fname" "$label" 994 $itk_component(fieldmenu) add radiobutton -label "$label" \ 995 -value $label -variable [itcl::scope _curFldLabel] \ 996 -selectcolor red \ 997 -activebackground $itk_option(-plotbackground) \ 998 -activeforeground $itk_option(-plotforeground) \ 999 -font "Arial 8" \ 1000 -command [itcl::code $this Combo invoke] 1001 set _fields($fname) [list $label $units $components] 1002 if { $_curFldName == "" } { 1003 set _curFldName $fname 1004 set _curFldLabel $label 1005 } 1006 } 1007 } 1008 $itk_component(field) value $_curFldLabel 1009 } 1010 InitSettings stretchToFit outline 1011 1012 if { $_reset } { 1013 SendCmd "axis tickpos outside" 1014 foreach axis { x y z } { 1015 SendCmd "axis lformat $axis %g" 1016 } 1017 1018 foreach axis { x y z } { 1019 set label [$_first hints ${axis}label] 1020 if { $label == "" } { 1021 if {$axis == "z"} { 1022 if { [string match "component*" $_curFldName] } { 1023 set label [string toupper $axis] 1024 } else { 1025 set label $_curFldLabel 1026 } 1027 } else { 1028 set label [string toupper $axis] 1029 } 1030 } 1031 # May be a space in the axis label. 1032 SendCmd [list axis name $axis $label] 1033 1034 if {$axis == "z" && [$_first hints ${axis}units] == ""} { 1035 set units [lindex $_fields($_curFldName) 1] 1036 } else { 1037 set units [$_first hints ${axis}units] 1038 } 1039 if { $units != "" } { 1040 # May be a space in the axis units. 1041 SendCmd [list axis units $axis $units] 1042 } 1043 } 1044 # 1045 # Reset the camera and other view parameters 1046 # 1047 SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]" 1048 SendCmd "outline color [Color2RGB $itk_option(-plotforeground)]" 1049 ResetAxes 1050 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1051 $_arcball quaternion $q 1052 if {$_settings(isHeightmap) } { 1053 if { $_view(ortho)} { 1054 SendCmd "camera mode ortho" 1055 } else { 1056 SendCmd "camera mode persp" 1057 } 1058 DoRotate 1059 SendCmd "camera reset" 1060 } 1061 PanCamera 1062 InitSettings axisXGrid axisYGrid axisZGrid \ 1063 axisVisible axisLabels 1064 InitSettings heightmapScale field isHeightmap 1065 if { [array size _fields] < 2 } { 1066 blt::table forget $itk_component(field) $itk_component(field_l) 1067 } 1068 RequestLegend 1069 set _reset 0 1070 } 1071 global readyForNextFrame 1072 set readyForNextFrame 0; # Don't advance to the next frame 1073 1074 # Actually write the commands to the server socket. If it fails, we don't 1075 # care. We're finished here. 1076 blt::busy hold $itk_component(hull) 1077 StopBufferingCommands 1078 blt::busy release $itk_component(hull) 1027 } else { 1028 set label [string toupper $axis] 1029 } 1030 } 1031 # May be a space in the axis label. 1032 SendCmd [list axis name $axis $label] 1033 1034 if {$axis == "z" && [$_first hints ${axis}units] == ""} { 1035 set units [lindex $_fields($_curFldName) 1] 1036 } else { 1037 set units [$_first hints ${axis}units] 1038 } 1039 if { $units != "" } { 1040 # May be a space in the axis units. 1041 SendCmd [list axis units $axis $units] 1042 } 1043 } 1044 # 1045 # Reset the camera and other view parameters 1046 # 1047 SendCmd "axis color all [Color2RGB $itk_option(-plotforeground)]" 1048 SendCmd "outline color [Color2RGB $itk_option(-plotforeground)]" 1049 ResetAxes 1050 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1051 $_arcball quaternion $q 1052 if {$_settings(isHeightmap) } { 1053 if { $_view(ortho)} { 1054 SendCmd "camera mode ortho" 1055 } else { 1056 SendCmd "camera mode persp" 1057 } 1058 DoRotate 1059 SendCmd "camera reset" 1060 } 1061 PanCamera 1062 InitSettings axisXGrid axisYGrid axisZGrid \ 1063 axisVisible axisLabels 1064 InitSettings heightmapScale field isHeightmap 1065 if { [array size _fields] < 2 } { 1066 catch { 1067 blt::table forget $itk_component(field) $itk_component(field_l) 1068 } 1069 } 1070 RequestLegend 1071 set _reset 0 1072 } 1073 global readyForNextFrame 1074 set readyForNextFrame 0; # Don't advance to the next frame 1075 1076 # Actually write the commands to the server socket. If it fails, we don't 1077 # care. We're finished here. 1078 blt::busy hold $itk_component(hull) 1079 StopBufferingCommands 1080 blt::busy release $itk_component(hull) 1079 1081 } 1080 1082 … … 1087 1089 # ---------------------------------------------------------------------- 1088 1090 itcl::body Rappture::VtkHeightmapViewer::CurrentDatasets {args} { 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1091 set flag [lindex $args 0] 1092 switch -- $flag { 1093 "-all" { 1094 if { [llength $args] > 1 } { 1095 error "CurrentDatasets: can't specify dataobj after \"-all\"" 1096 } 1097 set dlist [get -objects] 1098 } 1099 "-visible" { 1100 if { [llength $args] > 1 } { 1101 set dlist {} 1102 set args [lrange $args 1 end] 1103 foreach dataobj $args { 1104 if { [info exists _obj2ovride($dataobj-raise)] } { 1105 lappend dlist $dataobj 1106 } 1107 } 1108 } else { 1109 set dlist [get -visible] 1110 } 1111 } 1112 default { 1113 set dlist $args 1114 } 1115 } 1116 set rlist "" 1117 foreach dataobj $dlist { 1118 foreach comp [$dataobj components] { 1119 set tag $dataobj-$comp 1120 if { [info exists _datasets($tag)] && $_datasets($tag) } { 1121 lappend rlist $tag 1122 } 1123 } 1124 } 1125 return $rlist 1124 1126 } 1125 1127 … … 1133 1135 # ---------------------------------------------------------------------- 1134 1136 itcl::body Rappture::VtkHeightmapViewer::Zoom {option} { 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1137 switch -- $option { 1138 "in" { 1139 set _view(zoom) [expr {$_view(zoom)*1.25}] 1140 SendCmd "camera zoom $_view(zoom)" 1141 } 1142 "out" { 1143 set _view(zoom) [expr {$_view(zoom)*0.8}] 1144 SendCmd "camera zoom $_view(zoom)" 1145 } 1146 "reset" { 1147 array set _view { 1148 qw 0.36 1149 qx 0.25 1150 qy 0.50 1151 qz 0.70 1152 zoom 1.0 1153 xpan 0 1154 ypan 0 1155 } 1156 if { $_first != "" } { 1157 set location [$_first hints camera] 1158 if { $location != "" } { 1159 array set _view $location 1160 } 1161 } 1162 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1163 $_arcball quaternion $q 1164 if {$_settings(isHeightmap) } { 1165 DoRotate 1166 } 1167 SendCmd "camera reset" 1168 } 1169 } 1168 1170 } 1169 1171 1170 1172 itcl::body Rappture::VtkHeightmapViewer::PanCamera {} { 1171 1172 1173 1173 set x $_view(xpan) 1174 set y $_view(ypan) 1175 SendCmd "camera pan $x $y" 1174 1176 } 1175 1177 … … 1184 1186 # ---------------------------------------------------------------------- 1185 1187 itcl::body Rappture::VtkHeightmapViewer::Rotate {option x y} { 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1188 switch -- $option { 1189 "click" { 1190 $itk_component(view) configure -cursor fleur 1191 set _click(x) $x 1192 set _click(y) $y 1193 } 1194 "drag" { 1195 if {[array size _click] == 0} { 1196 Rotate click $x $y 1197 } else { 1198 set w [winfo width $itk_component(view)] 1199 set h [winfo height $itk_component(view)] 1200 if {$w <= 0 || $h <= 0} { 1201 return 1202 } 1203 1204 if {[catch { 1205 # this fails sometimes for no apparent reason 1206 set dx [expr {double($x-$_click(x))/$w}] 1207 set dy [expr {double($y-$_click(y))/$h}] 1208 }]} { 1209 return 1210 } 1211 if { $dx == 0 && $dy == 0 } { 1212 return 1213 } 1214 set q [$_arcball rotate $x $y $_click(x) $_click(y)] 1215 EventuallyRotate $q 1216 set _click(x) $x 1217 set _click(y) $y 1218 } 1219 } 1220 "release" { 1221 Rotate drag $x $y 1222 $itk_component(view) configure -cursor "" 1223 catch {unset _click} 1224 } 1225 default { 1226 error "bad option \"$option\": should be click, drag, release" 1227 } 1228 } 1227 1229 } 1228 1230 1229 1231 itcl::body Rappture::VtkHeightmapViewer::Pick {x y} { 1230 1231 1232 1232 foreach tag [CurrentDatasets -visible] { 1233 SendCmd "dataset getscalar pixel $x $y $tag" 1234 } 1233 1235 } 1234 1236 … … 1242 1244 # ---------------------------------------------------------------------- 1243 1245 itcl::body Rappture::VtkHeightmapViewer::Pan {option x y} { 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1246 switch -- $option { 1247 "set" { 1248 set w [winfo width $itk_component(view)] 1249 set h [winfo height $itk_component(view)] 1250 set x [expr $x / double($w)] 1251 set y [expr $y / double($h)] 1252 set _view(xpan) [expr $_view(xpan) + $x] 1253 set _view(ypan) [expr $_view(ypan) + $y] 1254 PanCamera 1255 return 1256 } 1257 "click" { 1258 set _click(x) $x 1259 set _click(y) $y 1260 $itk_component(view) configure -cursor hand1 1261 } 1262 "drag" { 1263 if { ![info exists _click(x)] } { 1264 set _click(x) $x 1265 } 1266 if { ![info exists _click(y)] } { 1267 set _click(y) $y 1268 } 1269 set w [winfo width $itk_component(view)] 1270 set h [winfo height $itk_component(view)] 1271 set dx [expr ($_click(x) - $x)/double($w)] 1272 set dy [expr ($_click(y) - $y)/double($h)] 1273 set _click(x) $x 1274 set _click(y) $y 1275 set _view(xpan) [expr $_view(xpan) - $dx] 1276 set _view(ypan) [expr $_view(ypan) - $dy] 1277 PanCamera 1278 } 1279 "release" { 1280 Pan drag $x $y 1281 $itk_component(view) configure -cursor "" 1282 } 1283 default { 1284 error "unknown option \"$option\": should set, click, drag, or release" 1285 } 1286 } 1285 1287 } 1286 1288 … … 1293 1295 # ---------------------------------------------------------------------- 1294 1296 itcl::body Rappture::VtkHeightmapViewer::InitSettings { args } { 1295 1296 1297 1298 1299 1300 1301 1297 foreach spec $args { 1298 if { [info exists _settings($_first-$spec)] } { 1299 # Reset global setting with dataobj specific setting 1300 set _settings($spec) $_settings($_first-$spec) 1301 } 1302 AdjustSetting $spec 1303 } 1302 1304 } 1303 1305 … … 1310 1312 # 1311 1313 itcl::body Rappture::VtkHeightmapViewer::AdjustSetting {what {value ""}} { 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1314 if { $_beforeConnect } { 1315 return 1316 } 1317 switch -- $what { 1318 "axisFlymode" { 1319 set mode [$itk_component(axisflymode) value] 1320 set mode [$itk_component(axisflymode) translate $mode] 1321 set _settings($what) $mode 1322 SendCmd "axis flymode $mode" 1323 } 1324 "axisLabels" { 1325 set bool $_settings(axisLabels) 1326 SendCmd "axis labels all $bool" 1327 } 1328 "axisMinorTicks" { 1329 set bool $_settings(axisMinorTicks) 1330 foreach axis { x y z } { 1331 SendCmd "axis minticks ${axis} $bool" 1332 } 1333 } 1334 "axisVisible" { 1335 set bool $_settings(axisVisible) 1336 SendCmd "axis visible all $bool" 1337 } 1338 "axisXGrid" - "axisYGrid" - "axisZGrid" { 1339 set axis [string tolower [string range $what 4 4]] 1340 set bool $_settings($what) 1341 SendCmd "axis grid $axis $bool" 1342 } 1343 "background" { 1344 set bgcolor [$itk_component(background) value] 1345 array set fgcolors { 1346 "black" "white" 1347 "white" "black" 1348 "grey" "black" 1349 } 1350 configure -plotbackground $bgcolor \ 1351 -plotforeground $fgcolors($bgcolor) 1352 $itk_component(view) delete "legend" 1353 DrawLegend 1354 } 1355 "colormap" { 1356 set _changed(colormap) 1 1357 StartBufferingCommands 1358 set color [$itk_component(colormap) value] 1359 set _settings(colormap) $color 1360 if { $color == "none" } { 1361 if { $_settings(colormapVisible) } { 1362 SendCmd "heightmap surface 0" 1363 set _settings(colormapVisible) 0 1364 } 1365 } else { 1366 if { !$_settings(colormapVisible) } { 1367 SendCmd "heightmap surface 1" 1368 set _settings(colormapVisible) 1 1369 } 1370 SetCurrentColormap $color 1371 if {$_settings(colormapDiscrete)} { 1372 set numColors [expr $_settings(numIsolines) - 1] 1373 SendCmd "colormap res $numColors $color" 1374 } 1375 } 1376 StopBufferingCommands 1377 EventuallyRequestLegend 1378 } 1379 "colormapVisible" { 1380 set bool $_settings($what) 1381 SendCmd "heightmap surface $bool" 1382 } 1383 "colormapDiscrete" { 1384 set bool $_settings($what) 1385 set numColors [expr $_settings(numIsolines) - 1] 1386 StartBufferingCommands 1387 if {$bool} { 1388 SendCmd "colormap res $numColors" 1389 # Discrete colormap requires preinterp on 1390 SendCmd "heightmap preinterp on" 1391 } else { 1392 SendCmd "colormap res default" 1393 # FIXME: add setting for preinterp (default on) 1394 SendCmd "heightmap preinterp on" 1395 } 1396 StopBufferingCommands 1397 EventuallyRequestLegend 1398 } 1399 "edges" { 1400 set bool $_settings(edges) 1401 SendCmd "heightmap edges $bool" 1402 } 1403 "field" { 1404 set label [$itk_component(field) value] 1405 set fname [$itk_component(field) translate $label] 1406 set _settings(field) $fname 1407 if { [info exists _fields($fname)] } { 1408 foreach { label units components } $_fields($fname) break 1409 if { $components > 1 } { 1410 set _colorMode vmag 1411 } else { 1412 set _colorMode scalar 1413 } 1414 set _curFldName $fname 1415 set _curFldLabel $label 1416 } else { 1417 puts stderr "unknown field \"$fname\"" 1418 return 1419 } 1420 set label [$_first hints zlabel] 1421 if { $label == "" } { 1422 if { [string match "component*" $_curFldName] } { 1423 set label Z 1424 } else { 1425 set label $_curFldLabel 1426 } 1427 } 1428 # May be a space in the axis label. 1429 SendCmd [list axis name z $label] 1430 1431 if { [$_first hints zunits] == "" } { 1432 set units [lindex $_fields($_curFldName) 1] 1433 } else { 1434 set units [$_first hints zunits] 1435 } 1436 if { $units != "" } { 1437 # May be a space in the axis units. 1438 SendCmd [list axis units z $units] 1439 } 1440 # Get the new limits because the field changed. 1441 ResetAxes 1442 SendCmd "dataset scalar $_curFldName" 1443 SendCmd "heightmap colormode scalar $_curFldName" 1444 SendCmd "camera reset" 1445 DrawLegend 1446 } 1447 "heightmapScale" { 1448 if { $_settings(isHeightmap) } { 1449 set scale [GetHeightmapScale] 1450 # Have to set the datasets individually because we are 1451 # tracking them in _comp2scale. 1452 foreach dataset [CurrentDatasets -all] { 1453 SendCmd "heightmap heightscale $scale $dataset" 1454 set _comp2scale($dataset) $scale 1455 } 1456 ResetAxes 1457 } 1458 } 1459 "isHeightmap" { 1460 set bool $_settings(isHeightmap) 1461 set c $itk_component(view) 1462 StartBufferingCommands 1463 # Fix heightmap scale: 0 for contours, 1 for heightmaps. 1464 if { $bool } { 1465 set _settings(heightmapScale) 50 1466 set _settings(opacity) $_settings(saveOpacity) 1467 set _settings(lighting) $_settings(saveLighting) 1468 set _settings(outline) 0 1469 } else { 1470 set _settings(heightmapScale) 0 1471 set _settings(lighting) 0 1472 set _settings(opacity) 100 1473 set _settings(outline) $_settings(saveOutline) 1474 } 1475 AdjustSetting lighting 1476 AdjustSetting opacity 1477 AdjustSetting outline 1478 set scale [GetHeightmapScale] 1479 # Have to set the datasets individually because we are 1480 # tracking them in _comp2scale. 1481 foreach dataset [CurrentDatasets -all] { 1482 SendCmd "heightmap heightscale $scale $dataset" 1483 set _comp2scale($dataset) $scale 1484 } 1485 if { $bool } { 1486 $itk_component(lighting) configure -state normal 1487 $itk_component(opacity) configure -state normal 1488 $itk_component(scale) configure -state normal 1489 $itk_component(opacity_l) configure -state normal 1490 $itk_component(scale_l) configure -state normal 1491 $itk_component(outline) configure -state disabled 1492 if {$_view(ortho)} { 1493 SendCmd "camera mode ortho" 1494 } else { 1495 SendCmd "camera mode persp" 1496 } 1497 } else { 1498 $itk_component(lighting) configure -state disabled 1499 $itk_component(opacity) configure -state disabled 1500 $itk_component(scale) configure -state disabled 1501 $itk_component(opacity_l) configure -state disabled 1502 $itk_component(scale_l) configure -state disabled 1503 $itk_component(outline) configure -state normal 1504 SendCmd "camera mode image" 1505 } 1506 if {$_settings(stretchToFit)} { 1507 if {$scale == 0} { 1508 SendCmd "camera aspect window" 1509 } else { 1510 SendCmd "camera aspect square" 1511 } 1512 } 1513 ResetAxes 1514 if { $bool } { 1515 set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] 1516 $_arcball quaternion $q 1517 SendCmd "camera orient $q" 1518 } else { 1519 bind $c <ButtonPress-1> {} 1520 bind $c <B1-Motion> {} 1521 bind $c <ButtonRelease-1> {} 1522 } 1523 SendCmd "camera reset" 1524 # Fix the mouse bindings for rotation/panning and the 1525 # camera mode. Ideally we'd create a bindtag for these. 1526 if { $bool } { 1527 # Bindings for rotation via mouse 1528 bind $c <ButtonPress-1> \ 1529 [itcl::code $this Rotate click %x %y] 1530 bind $c <B1-Motion> \ 1531 [itcl::code $this Rotate drag %x %y] 1532 bind $c <ButtonRelease-1> \ 1533 [itcl::code $this Rotate release %x %y] 1534 } 1535 StopBufferingCommands 1536 } 1537 "isolineColor" { 1538 set color [$itk_component(isolinecolor) value] 1539 if { $color == "none" } { 1540 if { $_settings(isolinesVisible) } { 1541 SendCmd "heightmap isolines 0" 1542 set _settings(isolinesVisible) 0 1543 } 1544 } else { 1545 if { !$_settings(isolinesVisible) } { 1546 SendCmd "heightmap isolines 1" 1547 set _settings(isolinesVisible) 1 1548 } 1549 SendCmd "heightmap isolinecolor [Color2RGB $color]" 1550 } 1551 DrawLegend 1552 } 1553 "isolinesVisible" { 1554 set bool $_settings($what) 1555 SendCmd "heightmap isolines $bool" 1556 DrawLegend 1557 } 1558 "legendVisible" { 1559 if { !$_settings($what) } { 1560 $itk_component(view) delete legend 1561 } 1562 DrawLegend 1563 } 1564 "lighting" { 1565 if { $_settings(isHeightmap) } { 1566 set _settings(saveLighting) $_settings(lighting) 1567 set bool $_settings($what) 1568 SendCmd "heightmap lighting $bool" 1569 } else { 1570 SendCmd "heightmap lighting 0" 1571 } 1572 } 1573 "numIsolines" { 1574 set _changed(numIsolines) 1 1575 set _settings(numIsolines) [$itk_component(numisolines) value] 1576 set _currentNumIsolines $_settings(numIsolines) 1577 SendCmd "heightmap numcontours $_settings(numIsolines)" 1578 if {$_settings(colormapDiscrete)} { 1579 set numColors [expr $_settings(numIsolines) - 1] 1580 SendCmd "colormap res $numColors" 1581 EventuallyRequestLegend 1582 } else { 1583 DrawLegend 1584 } 1585 } 1586 "opacity" { 1587 set _changed(opacity) 1 1588 if { $_settings(isHeightmap) } { 1589 set _settings(saveOpacity) $_settings(opacity) 1590 set val $_settings(opacity) 1591 set sval [expr { 0.01 * double($val) }] 1592 SendCmd "heightmap opacity $sval" 1593 } else { 1594 SendCmd "heightmap opacity 1" 1595 } 1596 } 1597 "outline" { 1598 if { $_settings(isHeightmap) } { 1599 SendCmd "outline visible 0" 1600 } else { 1601 set _settings(saveOutline) $_settings(outline) 1602 set bool $_settings(outline) 1603 SendCmd "outline visible $bool" 1604 } 1605 } 1606 "stretchToFit" { 1607 set bool $_settings($what) 1608 if { $bool } { 1609 set heightScale [GetHeightmapScale] 1610 if {$heightScale == 0} { 1611 SendCmd "camera aspect window" 1612 } else { 1613 SendCmd "camera aspect square" 1614 } 1615 } else { 1616 SendCmd "camera aspect native" 1617 } 1618 } 1619 "wireframe" { 1620 set bool $_settings($what) 1621 SendCmd "heightmap wireframe $bool" 1622 } 1623 default { 1624 error "don't know how to fix $what" 1625 } 1626 } 1625 1627 } 1626 1628
Note: See TracChangeset
for help on using the changeset viewer.