[3685] | 1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
| 2 | # ---------------------------------------------------------------------- |
---|
| 3 | # COMPONENT: vtkglyphviewer - Vtk 3D glyphs object viewer |
---|
| 4 | # |
---|
| 5 | # It connects to the Vtk server running on a rendering farm, |
---|
| 6 | # transmits data, and displays the results. |
---|
| 7 | # ====================================================================== |
---|
| 8 | # AUTHOR: Michael McLennan, Purdue University |
---|
[4481] | 9 | # Copyright (c) 2004-2014 HUBzero Foundation, LLC |
---|
[3685] | 10 | # |
---|
| 11 | # See the file "license.terms" for information on usage and |
---|
| 12 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 13 | # ====================================================================== |
---|
| 14 | package require Itk |
---|
| 15 | package require BLT |
---|
| 16 | #package require Img |
---|
| 17 | |
---|
| 18 | option add *VtkGlyphViewer.width 4i widgetDefault |
---|
| 19 | option add *VtkGlyphViewer*cursor crosshair widgetDefault |
---|
| 20 | option add *VtkGlyphViewer.height 4i widgetDefault |
---|
| 21 | option add *VtkGlyphViewer.foreground black widgetDefault |
---|
| 22 | option add *VtkGlyphViewer.controlBackground gray widgetDefault |
---|
| 23 | option add *VtkGlyphViewer.controlDarkBackground #999999 widgetDefault |
---|
| 24 | option add *VtkGlyphViewer.plotBackground black widgetDefault |
---|
| 25 | option add *VtkGlyphViewer.plotForeground white widgetDefault |
---|
| 26 | option add *VtkGlyphViewer.font \ |
---|
| 27 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
| 28 | |
---|
| 29 | # must use this name -- plugs into Rappture::resources::load |
---|
| 30 | proc VtkGlyphViewer_init_resources {} { |
---|
| 31 | Rappture::resources::register \ |
---|
| 32 | vtkvis_server Rappture::VtkGlyphViewer::SetServerList |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | itcl::class Rappture::VtkGlyphViewer { |
---|
| 36 | inherit Rappture::VisViewer |
---|
| 37 | |
---|
| 38 | itk_option define -plotforeground plotForeground Foreground "" |
---|
| 39 | itk_option define -plotbackground plotBackground Background "" |
---|
| 40 | |
---|
| 41 | constructor { hostlist args } { |
---|
| 42 | Rappture::VisViewer::constructor $hostlist |
---|
| 43 | } { |
---|
| 44 | # defined below |
---|
| 45 | } |
---|
| 46 | destructor { |
---|
| 47 | # defined below |
---|
| 48 | } |
---|
| 49 | public proc SetServerList { namelist } { |
---|
| 50 | Rappture::VisViewer::SetServerList "vtkvis" $namelist |
---|
| 51 | } |
---|
| 52 | public method add {dataobj {settings ""}} |
---|
| 53 | public method camera {option args} |
---|
| 54 | public method delete {args} |
---|
| 55 | public method disconnect {} |
---|
| 56 | public method download {option args} |
---|
| 57 | public method get {args} |
---|
| 58 | public method isconnected {} |
---|
| 59 | public method limits { colormap } |
---|
| 60 | public method parameters {title args} { |
---|
| 61 | # do nothing |
---|
| 62 | } |
---|
| 63 | public method scale {args} |
---|
| 64 | |
---|
| 65 | protected method Connect {} |
---|
| 66 | protected method CurrentDatasets {args} |
---|
| 67 | protected method Disconnect {} |
---|
| 68 | protected method DoResize {} |
---|
| 69 | protected method DoRotate {} |
---|
| 70 | protected method AdjustSetting {what {value ""}} |
---|
| 71 | protected method InitSettings { args } |
---|
| 72 | protected method Pan {option x y} |
---|
| 73 | protected method Pick {x y} |
---|
| 74 | protected method Rebuild {} |
---|
| 75 | protected method ReceiveDataset { args } |
---|
| 76 | protected method ReceiveImage { args } |
---|
| 77 | protected method ReceiveLegend { colormap title vmin vmax size } |
---|
| 78 | protected method Rotate {option x y} |
---|
| 79 | protected method Zoom {option} |
---|
| 80 | |
---|
| 81 | # The following methods are only used by this class. |
---|
| 82 | private method BuildAxisTab {} |
---|
| 83 | private method BuildCameraTab {} |
---|
| 84 | private method BuildColormap { name } |
---|
| 85 | private method BuildCutplaneTab {} |
---|
| 86 | private method BuildDownloadPopup { widget command } |
---|
| 87 | private method BuildGlyphTab {} |
---|
| 88 | private method DrawLegend {} |
---|
| 89 | private method Combo { option } |
---|
| 90 | private method EnterLegend { x y } |
---|
| 91 | private method EventuallyResize { w h } |
---|
| 92 | private method EventuallyRotate { q } |
---|
| 93 | private method EventuallyRequestLegend {} |
---|
| 94 | private method EventuallySetCutplane { axis args } |
---|
| 95 | private method GetImage { args } |
---|
| 96 | private method GetVtkData { args } |
---|
| 97 | private method IsValidObject { dataobj } |
---|
| 98 | private method LeaveLegend {} |
---|
| 99 | private method MotionLegend { x y } |
---|
| 100 | private method PanCamera {} |
---|
| 101 | private method RequestLegend {} |
---|
| 102 | private method SetLegendTip { x y } |
---|
| 103 | private method SetObjectStyle { dataobj comp } |
---|
| 104 | private method Slice {option args} |
---|
| 105 | private method SetCurrentColormap { color } |
---|
| 106 | private method SetOrientation { side } |
---|
| 107 | |
---|
| 108 | private variable _arcball "" |
---|
| 109 | |
---|
| 110 | private variable _dlist "" ; # list of data objects |
---|
| 111 | private variable _obj2datasets |
---|
| 112 | private variable _obj2ovride ; # maps dataobj => style override |
---|
| 113 | private variable _datasets ; # contains all the dataobj-component |
---|
| 114 | ; # datasets in the server |
---|
| 115 | private variable _colormaps ; # contains all the colormaps |
---|
| 116 | ; # in the server. |
---|
| 117 | # The name of the current colormap used. The colormap is global to all |
---|
| 118 | # heightmaps displayed. |
---|
| 119 | private variable _currentColormap "" |
---|
| 120 | |
---|
| 121 | private variable _dataset2style ;# maps dataobj-component to transfunc |
---|
| 122 | |
---|
| 123 | private variable _click ; # info used for rotate operations |
---|
| 124 | private variable _limits ; # autoscale min/max for all axes |
---|
| 125 | private variable _view ; # view params for 3D view |
---|
| 126 | private variable _settings |
---|
| 127 | private variable _style; # Array of current component styles. |
---|
| 128 | private variable _changed |
---|
| 129 | private variable _initialStyle; # Array of initial component styles. |
---|
| 130 | private variable _reset 1; # indicates if camera needs to be reset |
---|
| 131 | # to starting position. |
---|
| 132 | |
---|
| 133 | private variable _first "" ; # This is the topmost dataset. |
---|
| 134 | private variable _start 0 |
---|
| 135 | private variable _title "" |
---|
| 136 | |
---|
| 137 | common _downloadPopup; # download options from popup |
---|
| 138 | private common _hardcopy |
---|
| 139 | private variable _width 0 |
---|
| 140 | private variable _height 0 |
---|
| 141 | private variable _resizePending 0 |
---|
| 142 | private variable _rotatePending 0 |
---|
| 143 | private variable _cutplanePending 0 |
---|
| 144 | private variable _legendPending 0 |
---|
| 145 | private variable _field "" |
---|
| 146 | private variable _colorMode "vmag"; # Mode of colormap (vmag or scalar) |
---|
| 147 | private variable _fieldNames {} |
---|
| 148 | private variable _fields |
---|
| 149 | private variable _curFldName "" |
---|
| 150 | private variable _curFldLabel "" |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | itk::usual VtkGlyphViewer { |
---|
| 154 | keep -background -foreground -cursor -font |
---|
| 155 | keep -plotbackground -plotforeground |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | # ---------------------------------------------------------------------- |
---|
| 159 | # CONSTRUCTOR |
---|
| 160 | # ---------------------------------------------------------------------- |
---|
| 161 | itcl::body Rappture::VtkGlyphViewer::constructor {hostlist args} { |
---|
| 162 | package require vtk |
---|
| 163 | set _serverType "vtkvis" |
---|
| 164 | |
---|
| 165 | # Rebuild event |
---|
| 166 | $_dispatcher register !rebuild |
---|
| 167 | $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" |
---|
| 168 | |
---|
| 169 | # Resize event |
---|
| 170 | $_dispatcher register !resize |
---|
| 171 | $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list" |
---|
| 172 | |
---|
| 173 | # Rotate event |
---|
| 174 | $_dispatcher register !rotate |
---|
| 175 | $_dispatcher dispatch $this !rotate "[itcl::code $this DoRotate]; list" |
---|
| 176 | |
---|
| 177 | # Legend event |
---|
| 178 | $_dispatcher register !legend |
---|
| 179 | $_dispatcher dispatch $this !legend "[itcl::code $this RequestLegend]; list" |
---|
| 180 | |
---|
| 181 | # X-Cutplane event |
---|
| 182 | $_dispatcher register !xcutplane |
---|
| 183 | $_dispatcher dispatch $this !xcutplane \ |
---|
| 184 | "[itcl::code $this AdjustSetting cutplaneXPosition]; list" |
---|
| 185 | |
---|
| 186 | # Y-Cutplane event |
---|
| 187 | $_dispatcher register !ycutplane |
---|
| 188 | $_dispatcher dispatch $this !ycutplane \ |
---|
| 189 | "[itcl::code $this AdjustSetting cutplaneYPosition]; list" |
---|
| 190 | |
---|
| 191 | # Z-Cutplane event |
---|
| 192 | $_dispatcher register !zcutplane |
---|
| 193 | $_dispatcher dispatch $this !zcutplane \ |
---|
| 194 | "[itcl::code $this AdjustSetting cutplaneZPosition]; list" |
---|
| 195 | |
---|
| 196 | # |
---|
| 197 | # Populate parser with commands handle incoming requests |
---|
| 198 | # |
---|
| 199 | $_parser alias image [itcl::code $this ReceiveImage] |
---|
| 200 | $_parser alias dataset [itcl::code $this ReceiveDataset] |
---|
| 201 | $_parser alias legend [itcl::code $this ReceiveLegend] |
---|
| 202 | |
---|
| 203 | # Initialize the view to some default parameters. |
---|
| 204 | array set _view { |
---|
| 205 | qw 0.853553 |
---|
| 206 | qx -0.353553 |
---|
| 207 | qy 0.353553 |
---|
| 208 | qz 0.146447 |
---|
| 209 | zoom 1.0 |
---|
| 210 | xpan 0 |
---|
| 211 | ypan 0 |
---|
| 212 | ortho 0 |
---|
| 213 | } |
---|
| 214 | set _arcball [blt::arcball create 100 100] |
---|
| 215 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
| 216 | $_arcball quaternion $q |
---|
| 217 | |
---|
| 218 | array set _settings [subst { |
---|
| 219 | background black |
---|
| 220 | colormap BCGYR |
---|
| 221 | colormapVisible 1 |
---|
| 222 | field "Default" |
---|
| 223 | axesVisible 1 |
---|
| 224 | axisLabelsVisible 1 |
---|
| 225 | axisXGrid 0 |
---|
| 226 | axisYGrid 0 |
---|
| 227 | axisZGrid 0 |
---|
| 228 | cutplaneEdges 0 |
---|
| 229 | cutplaneLighting 1 |
---|
[4187] | 230 | cutplanePreinterp 1 |
---|
[3685] | 231 | cutplaneOpacity 100 |
---|
| 232 | cutplaneVisible 0 |
---|
| 233 | cutplaneWireframe 0 |
---|
| 234 | cutplaneXPosition 50 |
---|
| 235 | cutplaneXVisible 1 |
---|
| 236 | cutplaneYPosition 50 |
---|
| 237 | cutplaneYVisible 1 |
---|
| 238 | cutplaneZPosition 50 |
---|
| 239 | cutplaneZVisible 1 |
---|
| 240 | glyphEdges 0 |
---|
| 241 | glyphLighting 1 |
---|
[3694] | 242 | glyphOpacity 100 |
---|
| 243 | saveGlyphOpacity 100 |
---|
[3685] | 244 | glyphOutline 0 |
---|
| 245 | glyphVisible 1 |
---|
| 246 | glyphWireframe 0 |
---|
| 247 | legendVisible 1 |
---|
| 248 | }] |
---|
| 249 | array set _changed { |
---|
| 250 | glyphOpacity 0 |
---|
| 251 | colormap 0 |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | itk_component add view { |
---|
| 255 | canvas $itk_component(plotarea).view \ |
---|
| 256 | -highlightthickness 0 -borderwidth 0 |
---|
| 257 | } { |
---|
| 258 | usual |
---|
| 259 | ignore -highlightthickness -borderwidth -background |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | itk_component add fieldmenu { |
---|
| 263 | menu $itk_component(plotarea).menu -bg black -fg white -relief flat \ |
---|
| 264 | -tearoff no |
---|
| 265 | } { |
---|
| 266 | usual |
---|
| 267 | ignore -background -foreground -relief -tearoff |
---|
| 268 | } |
---|
| 269 | set c $itk_component(view) |
---|
| 270 | bind $c <Configure> [itcl::code $this EventuallyResize %w %h] |
---|
| 271 | bind $c <4> [itcl::code $this Zoom in 0.25] |
---|
| 272 | bind $c <5> [itcl::code $this Zoom out 0.25] |
---|
| 273 | bind $c <KeyPress-Left> [list %W xview scroll 10 units] |
---|
| 274 | bind $c <KeyPress-Right> [list %W xview scroll -10 units] |
---|
| 275 | bind $c <KeyPress-Up> [list %W yview scroll 10 units] |
---|
| 276 | bind $c <KeyPress-Down> [list %W yview scroll -10 units] |
---|
| 277 | bind $c <Enter> "focus %W" |
---|
| 278 | bind $c <Control-F1> [itcl::code $this ToggleConsole] |
---|
| 279 | |
---|
| 280 | # Fix the scrollregion in case we go off screen |
---|
| 281 | $c configure -scrollregion [$c bbox all] |
---|
| 282 | |
---|
| 283 | set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] |
---|
| 284 | set _map(cwidth) -1 |
---|
| 285 | set _map(cheight) -1 |
---|
| 286 | set _map(zoom) 1.0 |
---|
| 287 | set _map(original) "" |
---|
| 288 | |
---|
| 289 | set f [$itk_component(main) component controls] |
---|
| 290 | itk_component add reset { |
---|
| 291 | button $f.reset -borderwidth 1 -padx 1 -pady 1 \ |
---|
| 292 | -highlightthickness 0 \ |
---|
| 293 | -image [Rappture::icon reset-view] \ |
---|
| 294 | -command [itcl::code $this Zoom reset] |
---|
| 295 | } { |
---|
| 296 | usual |
---|
| 297 | ignore -highlightthickness |
---|
| 298 | } |
---|
| 299 | pack $itk_component(reset) -side top -padx 2 -pady 2 |
---|
| 300 | Rappture::Tooltip::for $itk_component(reset) \ |
---|
| 301 | "Reset the view to the default zoom level" |
---|
| 302 | |
---|
| 303 | itk_component add zoomin { |
---|
| 304 | button $f.zin -borderwidth 1 -padx 1 -pady 1 \ |
---|
| 305 | -highlightthickness 0 \ |
---|
| 306 | -image [Rappture::icon zoom-in] \ |
---|
| 307 | -command [itcl::code $this Zoom in] |
---|
| 308 | } { |
---|
| 309 | usual |
---|
| 310 | ignore -highlightthickness |
---|
| 311 | } |
---|
| 312 | pack $itk_component(zoomin) -side top -padx 2 -pady 2 |
---|
| 313 | Rappture::Tooltip::for $itk_component(zoomin) "Zoom in" |
---|
| 314 | |
---|
| 315 | itk_component add zoomout { |
---|
| 316 | button $f.zout -borderwidth 1 -padx 1 -pady 1 \ |
---|
| 317 | -highlightthickness 0 \ |
---|
| 318 | -image [Rappture::icon zoom-out] \ |
---|
| 319 | -command [itcl::code $this Zoom out] |
---|
| 320 | } { |
---|
| 321 | usual |
---|
| 322 | ignore -highlightthickness |
---|
| 323 | } |
---|
| 324 | pack $itk_component(zoomout) -side top -padx 2 -pady 2 |
---|
| 325 | Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" |
---|
| 326 | |
---|
| 327 | itk_component add glyphs { |
---|
| 328 | Rappture::PushButton $f.glyphs \ |
---|
| 329 | -onimage [Rappture::icon volume-on] \ |
---|
| 330 | -offimage [Rappture::icon volume-off] \ |
---|
| 331 | -variable [itcl::scope _settings(glyphVisible)] \ |
---|
| 332 | -command [itcl::code $this AdjustSetting glyphVisible] |
---|
| 333 | } |
---|
| 334 | $itk_component(glyphs) select |
---|
| 335 | Rappture::Tooltip::for $itk_component(glyphs) \ |
---|
| 336 | "Don't display the glyphs" |
---|
| 337 | pack $itk_component(glyphs) -padx 2 -pady 2 |
---|
| 338 | |
---|
[4340] | 339 | if {0} { |
---|
[3685] | 340 | itk_component add cutplane { |
---|
| 341 | Rappture::PushButton $f.cutplane \ |
---|
| 342 | -onimage [Rappture::icon cutbutton] \ |
---|
| 343 | -offimage [Rappture::icon cutbutton] \ |
---|
| 344 | -variable [itcl::scope _settings(cutplaneVisible)] \ |
---|
| 345 | -command [itcl::code $this AdjustSetting cutplaneVisible] |
---|
| 346 | } |
---|
| 347 | Rappture::Tooltip::for $itk_component(cutplane) \ |
---|
| 348 | "Show/Hide cutplanes" |
---|
| 349 | pack $itk_component(cutplane) -padx 2 -pady 2 |
---|
[4340] | 350 | } |
---|
[3685] | 351 | |
---|
| 352 | if { [catch { |
---|
| 353 | BuildGlyphTab |
---|
| 354 | #BuildCutplaneTab |
---|
| 355 | BuildAxisTab |
---|
| 356 | BuildCameraTab |
---|
| 357 | } errs] != 0 } { |
---|
| 358 | puts stderr errs=$errs |
---|
| 359 | } |
---|
| 360 | # Legend |
---|
| 361 | |
---|
| 362 | set _image(legend) [image create photo] |
---|
| 363 | itk_component add legend { |
---|
| 364 | canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 |
---|
| 365 | } { |
---|
| 366 | usual |
---|
| 367 | ignore -highlightthickness |
---|
| 368 | rename -background -plotbackground plotBackground Background |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | # Hack around the Tk panewindow. The problem is that the requested |
---|
| 372 | # size of the 3d view isn't set until an image is retrieved from |
---|
| 373 | # the server. So the panewindow uses the tiny size. |
---|
| 374 | set w 10000 |
---|
| 375 | pack forget $itk_component(view) |
---|
| 376 | blt::table $itk_component(plotarea) \ |
---|
| 377 | 0,0 $itk_component(view) -fill both -reqwidth $w |
---|
| 378 | blt::table configure $itk_component(plotarea) c1 -resize none |
---|
| 379 | |
---|
| 380 | # Bindings for rotation via mouse |
---|
| 381 | bind $itk_component(view) <ButtonPress-1> \ |
---|
| 382 | [itcl::code $this Rotate click %x %y] |
---|
| 383 | bind $itk_component(view) <B1-Motion> \ |
---|
| 384 | [itcl::code $this Rotate drag %x %y] |
---|
| 385 | bind $itk_component(view) <ButtonRelease-1> \ |
---|
| 386 | [itcl::code $this Rotate release %x %y] |
---|
| 387 | |
---|
| 388 | # Bindings for panning via mouse |
---|
| 389 | bind $itk_component(view) <ButtonPress-2> \ |
---|
| 390 | [itcl::code $this Pan click %x %y] |
---|
| 391 | bind $itk_component(view) <B2-Motion> \ |
---|
| 392 | [itcl::code $this Pan drag %x %y] |
---|
| 393 | bind $itk_component(view) <ButtonRelease-2> \ |
---|
| 394 | [itcl::code $this Pan release %x %y] |
---|
| 395 | |
---|
| 396 | #bind $itk_component(view) <ButtonRelease-3> \ |
---|
| 397 | # [itcl::code $this Pick %x %y] |
---|
| 398 | |
---|
| 399 | # Bindings for panning via keyboard |
---|
| 400 | bind $itk_component(view) <KeyPress-Left> \ |
---|
| 401 | [itcl::code $this Pan set -10 0] |
---|
| 402 | bind $itk_component(view) <KeyPress-Right> \ |
---|
| 403 | [itcl::code $this Pan set 10 0] |
---|
| 404 | bind $itk_component(view) <KeyPress-Up> \ |
---|
| 405 | [itcl::code $this Pan set 0 -10] |
---|
| 406 | bind $itk_component(view) <KeyPress-Down> \ |
---|
| 407 | [itcl::code $this Pan set 0 10] |
---|
| 408 | bind $itk_component(view) <Shift-KeyPress-Left> \ |
---|
| 409 | [itcl::code $this Pan set -2 0] |
---|
| 410 | bind $itk_component(view) <Shift-KeyPress-Right> \ |
---|
| 411 | [itcl::code $this Pan set 2 0] |
---|
| 412 | bind $itk_component(view) <Shift-KeyPress-Up> \ |
---|
| 413 | [itcl::code $this Pan set 0 -2] |
---|
| 414 | bind $itk_component(view) <Shift-KeyPress-Down> \ |
---|
| 415 | [itcl::code $this Pan set 0 2] |
---|
| 416 | |
---|
| 417 | # Bindings for zoom via keyboard |
---|
| 418 | bind $itk_component(view) <KeyPress-Prior> \ |
---|
| 419 | [itcl::code $this Zoom out] |
---|
| 420 | bind $itk_component(view) <KeyPress-Next> \ |
---|
| 421 | [itcl::code $this Zoom in] |
---|
| 422 | |
---|
| 423 | bind $itk_component(view) <Enter> "focus $itk_component(view)" |
---|
| 424 | |
---|
| 425 | if {[string equal "x11" [tk windowingsystem]]} { |
---|
| 426 | # Bindings for zoom via mouse |
---|
| 427 | bind $itk_component(view) <4> [itcl::code $this Zoom out] |
---|
| 428 | bind $itk_component(view) <5> [itcl::code $this Zoom in] |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | set _image(download) [image create photo] |
---|
| 432 | |
---|
| 433 | eval itk_initialize $args |
---|
| 434 | Connect |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | # ---------------------------------------------------------------------- |
---|
| 438 | # DESTRUCTOR |
---|
| 439 | # ---------------------------------------------------------------------- |
---|
| 440 | itcl::body Rappture::VtkGlyphViewer::destructor {} { |
---|
| 441 | Disconnect |
---|
| 442 | image delete $_image(plot) |
---|
| 443 | image delete $_image(download) |
---|
| 444 | catch { blt::arcball destroy $_arcball } |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | itcl::body Rappture::VtkGlyphViewer::DoResize {} { |
---|
| 448 | if { $_width < 2 } { |
---|
| 449 | set _width 500 |
---|
| 450 | } |
---|
| 451 | if { $_height < 2 } { |
---|
| 452 | set _height 500 |
---|
| 453 | } |
---|
| 454 | set _start [clock clicks -milliseconds] |
---|
| 455 | SendCmd "screen size $_width $_height" |
---|
| 456 | |
---|
| 457 | EventuallyRequestLegend |
---|
| 458 | set _resizePending 0 |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | itcl::body Rappture::VtkGlyphViewer::DoRotate {} { |
---|
| 462 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
| 463 | SendCmd "camera orient $q" |
---|
| 464 | set _rotatePending 0 |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | itcl::body Rappture::VtkGlyphViewer::EventuallyRequestLegend {} { |
---|
| 468 | if { !$_legendPending } { |
---|
| 469 | set _legendPending 1 |
---|
| 470 | $_dispatcher event -idle !legend |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | itcl::body Rappture::VtkGlyphViewer::EventuallyResize { w h } { |
---|
| 475 | set _width $w |
---|
| 476 | set _height $h |
---|
| 477 | $_arcball resize $w $h |
---|
| 478 | if { !$_resizePending } { |
---|
| 479 | set _resizePending 1 |
---|
| 480 | $_dispatcher event -after 400 !resize |
---|
| 481 | } |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | set rotate_delay 100 |
---|
| 485 | |
---|
| 486 | itcl::body Rappture::VtkGlyphViewer::EventuallyRotate { q } { |
---|
| 487 | foreach { _view(qw) _view(qx) _view(qy) _view(qz) } $q break |
---|
| 488 | if { !$_rotatePending } { |
---|
| 489 | set _rotatePending 1 |
---|
| 490 | global rotate_delay |
---|
| 491 | $_dispatcher event -after $rotate_delay !rotate |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | itcl::body Rappture::VtkGlyphViewer::EventuallySetCutplane { axis args } { |
---|
| 496 | if { !$_cutplanePending } { |
---|
| 497 | set _cutplanePending 1 |
---|
| 498 | $_dispatcher event -after 100 !${axis}cutplane |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | |
---|
| 502 | # ---------------------------------------------------------------------- |
---|
| 503 | # USAGE: add <dataobj> ?<settings>? |
---|
| 504 | # |
---|
| 505 | # Clients use this to add a data object to the plot. The optional |
---|
| 506 | # <settings> are used to configure the plot. Allowed settings are |
---|
| 507 | # -color, -brightness, -width, -linestyle, and -raise. |
---|
| 508 | # ---------------------------------------------------------------------- |
---|
| 509 | itcl::body Rappture::VtkGlyphViewer::add {dataobj {settings ""}} { |
---|
| 510 | if { ![$dataobj isvalid] } { |
---|
| 511 | return; # Object doesn't contain valid data. |
---|
| 512 | } |
---|
| 513 | array set params { |
---|
| 514 | -color auto |
---|
| 515 | -width 1 |
---|
| 516 | -linestyle solid |
---|
| 517 | -brightness 0 |
---|
| 518 | -raise 0 |
---|
| 519 | -description "" |
---|
| 520 | -param "" |
---|
| 521 | -type "" |
---|
| 522 | } |
---|
| 523 | array set params $settings |
---|
| 524 | set params(-description) "" |
---|
| 525 | set params(-param) "" |
---|
[3800] | 526 | array set params $settings |
---|
| 527 | |
---|
[3685] | 528 | if {$params(-color) == "auto" || $params(-color) == "autoreset"} { |
---|
| 529 | # can't handle -autocolors yet |
---|
| 530 | set params(-color) black |
---|
| 531 | } |
---|
[3844] | 532 | set pos [lsearch -exact $_dlist $dataobj] |
---|
[3685] | 533 | if {$pos < 0} { |
---|
| 534 | lappend _dlist $dataobj |
---|
| 535 | } |
---|
| 536 | set _obj2ovride($dataobj-color) $params(-color) |
---|
| 537 | set _obj2ovride($dataobj-width) $params(-width) |
---|
| 538 | set _obj2ovride($dataobj-raise) $params(-raise) |
---|
| 539 | $_dispatcher event -idle !rebuild |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | |
---|
| 543 | # ---------------------------------------------------------------------- |
---|
| 544 | # USAGE: delete ?<dataobj1> <dataobj2> ...? |
---|
| 545 | # |
---|
| 546 | # Clients use this to delete a dataobj from the plot. If no dataobjs |
---|
| 547 | # are specified, then all dataobjs are deleted. No data objects are |
---|
| 548 | # deleted. They are only removed from the display list. |
---|
| 549 | # |
---|
| 550 | # ---------------------------------------------------------------------- |
---|
| 551 | itcl::body Rappture::VtkGlyphViewer::delete {args} { |
---|
| 552 | if { [llength $args] == 0} { |
---|
| 553 | set args $_dlist |
---|
| 554 | } |
---|
| 555 | # Delete all specified dataobjs |
---|
| 556 | set changed 0 |
---|
| 557 | foreach dataobj $args { |
---|
| 558 | set pos [lsearch -exact $_dlist $dataobj] |
---|
| 559 | if { $pos < 0 } { |
---|
| 560 | continue; # Don't know anything about it. |
---|
| 561 | } |
---|
| 562 | # Remove it from the dataobj list. |
---|
| 563 | set _dlist [lreplace $_dlist $pos $pos] |
---|
| 564 | array unset _obj2ovride $dataobj-* |
---|
| 565 | array unset _settings $dataobj-* |
---|
| 566 | set changed 1 |
---|
| 567 | } |
---|
| 568 | # If anything changed, then rebuild the plot |
---|
| 569 | if { $changed } { |
---|
| 570 | $_dispatcher event -idle !rebuild |
---|
| 571 | } |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | # ---------------------------------------------------------------------- |
---|
| 575 | # USAGE: get ?-objects? |
---|
| 576 | # USAGE: get ?-visible? |
---|
| 577 | # USAGE: get ?-image view? |
---|
| 578 | # |
---|
| 579 | # Clients use this to query the list of objects being plotted, in |
---|
| 580 | # order from bottom to top of this result. The optional "-image" |
---|
| 581 | # flag can also request the internal images being shown. |
---|
| 582 | # ---------------------------------------------------------------------- |
---|
| 583 | itcl::body Rappture::VtkGlyphViewer::get {args} { |
---|
| 584 | if {[llength $args] == 0} { |
---|
| 585 | set args "-objects" |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | set op [lindex $args 0] |
---|
| 589 | switch -- $op { |
---|
| 590 | "-objects" { |
---|
| 591 | # put the dataobj list in order according to -raise options |
---|
| 592 | set dlist {} |
---|
| 593 | foreach dataobj $_dlist { |
---|
| 594 | if { ![IsValidObject $dataobj] } { |
---|
| 595 | continue |
---|
| 596 | } |
---|
| 597 | if {[info exists _obj2ovride($dataobj-raise)] && |
---|
| 598 | $_obj2ovride($dataobj-raise)} { |
---|
| 599 | set dlist [linsert $dlist 0 $dataobj] |
---|
| 600 | } else { |
---|
| 601 | lappend dlist $dataobj |
---|
| 602 | } |
---|
| 603 | } |
---|
| 604 | return $dlist |
---|
| 605 | } |
---|
| 606 | "-visible" { |
---|
| 607 | set dlist {} |
---|
| 608 | foreach dataobj $_dlist { |
---|
| 609 | if { ![IsValidObject $dataobj] } { |
---|
| 610 | continue |
---|
| 611 | } |
---|
| 612 | if { ![info exists _obj2ovride($dataobj-raise)] } { |
---|
| 613 | # No setting indicates that the object isn't visible. |
---|
| 614 | continue |
---|
| 615 | } |
---|
| 616 | # Otherwise use the -raise parameter to put the object to |
---|
| 617 | # the front of the list. |
---|
| 618 | if { $_obj2ovride($dataobj-raise) } { |
---|
| 619 | set dlist [linsert $dlist 0 $dataobj] |
---|
| 620 | } else { |
---|
| 621 | lappend dlist $dataobj |
---|
| 622 | } |
---|
| 623 | } |
---|
| 624 | return $dlist |
---|
| 625 | } |
---|
| 626 | -image { |
---|
| 627 | if {[llength $args] != 2} { |
---|
| 628 | error "wrong # args: should be \"get -image view\"" |
---|
| 629 | } |
---|
| 630 | switch -- [lindex $args end] { |
---|
| 631 | view { |
---|
| 632 | return $_image(plot) |
---|
| 633 | } |
---|
| 634 | default { |
---|
| 635 | error "bad image name \"[lindex $args end]\": should be view" |
---|
| 636 | } |
---|
| 637 | } |
---|
| 638 | } |
---|
| 639 | default { |
---|
| 640 | error "bad option \"$op\": should be -objects or -image" |
---|
| 641 | } |
---|
| 642 | } |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | # ---------------------------------------------------------------------- |
---|
| 646 | # USAGE: scale ?<data1> <data2> ...? |
---|
| 647 | # |
---|
| 648 | # Sets the default limits for the overall plot according to the |
---|
| 649 | # limits of the data for all of the given <data> objects. This |
---|
| 650 | # accounts for all objects--even those not showing on the screen. |
---|
| 651 | # Because of this, the limits are appropriate for all objects as |
---|
| 652 | # the user scans through data in the ResultSet viewer. |
---|
| 653 | # ---------------------------------------------------------------------- |
---|
| 654 | itcl::body Rappture::VtkGlyphViewer::scale { args } { |
---|
| 655 | foreach dataobj $args { |
---|
| 656 | if { ![$dataobj isvalid] } { |
---|
| 657 | continue; # Object doesn't contain valid data. |
---|
| 658 | } |
---|
| 659 | foreach axis { x y z } { |
---|
| 660 | set lim [$dataobj limits $axis] |
---|
| 661 | if { ![info exists _limits($axis)] } { |
---|
| 662 | set _limits($axis) $lim |
---|
| 663 | continue |
---|
| 664 | } |
---|
| 665 | foreach {min max} $lim break |
---|
| 666 | foreach {amin amax} $_limits($axis) break |
---|
| 667 | if { $amin > $min } { |
---|
| 668 | set amin $min |
---|
| 669 | } |
---|
| 670 | if { $amax < $max } { |
---|
| 671 | set amax $max |
---|
| 672 | } |
---|
| 673 | set _limits($axis) [list $amin $amax] |
---|
| 674 | } |
---|
| 675 | foreach { fname lim } [$dataobj fieldlimits] { |
---|
| 676 | if { ![info exists _limits($fname)] } { |
---|
| 677 | set _limits($fname) $lim |
---|
| 678 | continue |
---|
| 679 | } |
---|
| 680 | foreach {min max} $lim break |
---|
| 681 | foreach {fmin fmax} $_limits($fname) break |
---|
| 682 | if { $fmin > $min } { |
---|
| 683 | set fmin $min |
---|
| 684 | } |
---|
| 685 | if { $fmax < $max } { |
---|
| 686 | set fmax $max |
---|
| 687 | } |
---|
| 688 | set _limits($fname) [list $fmin $fmax] |
---|
| 689 | } |
---|
| 690 | } |
---|
| 691 | } |
---|
| 692 | |
---|
| 693 | # ---------------------------------------------------------------------- |
---|
| 694 | # USAGE: download coming |
---|
| 695 | # USAGE: download controls <downloadCommand> |
---|
| 696 | # USAGE: download now |
---|
| 697 | # |
---|
| 698 | # Clients use this method to create a downloadable representation |
---|
| 699 | # of the plot. Returns a list of the form {ext string}, where |
---|
| 700 | # "ext" is the file extension (indicating the type of data) and |
---|
| 701 | # "string" is the data itself. |
---|
| 702 | # ---------------------------------------------------------------------- |
---|
| 703 | itcl::body Rappture::VtkGlyphViewer::download {option args} { |
---|
| 704 | switch $option { |
---|
| 705 | coming { |
---|
| 706 | if {[catch { |
---|
| 707 | blt::winop snap $itk_component(plotarea) $_image(download) |
---|
| 708 | }]} { |
---|
| 709 | $_image(download) configure -width 1 -height 1 |
---|
| 710 | $_image(download) put #000000 |
---|
| 711 | } |
---|
| 712 | } |
---|
| 713 | controls { |
---|
| 714 | set popup .vtkviewerdownload |
---|
| 715 | if { ![winfo exists .vtkviewerdownload] } { |
---|
| 716 | set inner [BuildDownloadPopup $popup [lindex $args 0]] |
---|
| 717 | } else { |
---|
| 718 | set inner [$popup component inner] |
---|
| 719 | } |
---|
| 720 | set _downloadPopup(image_controls) $inner.image_frame |
---|
| 721 | set num [llength [get]] |
---|
| 722 | set num [expr {($num == 1) ? "1 result" : "$num results"}] |
---|
| 723 | set word [Rappture::filexfer::label downloadWord] |
---|
| 724 | $inner.summary configure -text "$word $num in the following format:" |
---|
| 725 | update idletasks ;# Fix initial sizes |
---|
| 726 | return $popup |
---|
| 727 | } |
---|
| 728 | now { |
---|
| 729 | set popup .vtkviewerdownload |
---|
| 730 | if {[winfo exists .vtkviewerdownload]} { |
---|
| 731 | $popup deactivate |
---|
| 732 | } |
---|
| 733 | switch -- $_downloadPopup(format) { |
---|
| 734 | "image" { |
---|
| 735 | return [$this GetImage [lindex $args 0]] |
---|
| 736 | } |
---|
| 737 | "vtk" { |
---|
| 738 | return [$this GetVtkData [lindex $args 0]] |
---|
| 739 | } |
---|
| 740 | } |
---|
| 741 | return "" |
---|
| 742 | } |
---|
| 743 | default { |
---|
| 744 | error "bad option \"$option\": should be coming, controls, now" |
---|
| 745 | } |
---|
| 746 | } |
---|
| 747 | } |
---|
| 748 | |
---|
| 749 | # ---------------------------------------------------------------------- |
---|
| 750 | # USAGE: Connect ?<host:port>,<host:port>...? |
---|
| 751 | # |
---|
| 752 | # Clients use this method to establish a connection to a new |
---|
| 753 | # server, or to reestablish a connection to the previous server. |
---|
| 754 | # Any existing connection is automatically closed. |
---|
| 755 | # ---------------------------------------------------------------------- |
---|
| 756 | itcl::body Rappture::VtkGlyphViewer::Connect {} { |
---|
| 757 | set _hosts [GetServerList "vtkvis"] |
---|
| 758 | if { "" == $_hosts } { |
---|
| 759 | return 0 |
---|
| 760 | } |
---|
| 761 | set result [VisViewer::Connect $_hosts] |
---|
| 762 | if { $result } { |
---|
| 763 | if { $_reportClientInfo } { |
---|
| 764 | # Tell the server the viewer, hub, user and session. |
---|
[4187] | 765 | # Do this immediately on connect before buffering any commands |
---|
[3685] | 766 | global env |
---|
| 767 | |
---|
| 768 | set info {} |
---|
| 769 | set user "???" |
---|
| 770 | if { [info exists env(USER)] } { |
---|
| 771 | set user $env(USER) |
---|
| 772 | } |
---|
| 773 | set session "???" |
---|
| 774 | if { [info exists env(SESSION)] } { |
---|
| 775 | set session $env(SESSION) |
---|
| 776 | } |
---|
| 777 | lappend info "hub" [exec hostname] |
---|
| 778 | lappend info "client" "vtkglyphviewer" |
---|
| 779 | lappend info "user" $user |
---|
| 780 | lappend info "session" $session |
---|
| 781 | SendCmd "clientinfo [list $info]" |
---|
| 782 | } |
---|
| 783 | |
---|
| 784 | set w [winfo width $itk_component(view)] |
---|
| 785 | set h [winfo height $itk_component(view)] |
---|
| 786 | EventuallyResize $w $h |
---|
| 787 | } |
---|
| 788 | return $result |
---|
| 789 | } |
---|
| 790 | |
---|
| 791 | # |
---|
| 792 | # isconnected -- |
---|
| 793 | # |
---|
| 794 | # Indicates if we are currently connected to the visualization server. |
---|
| 795 | # |
---|
| 796 | itcl::body Rappture::VtkGlyphViewer::isconnected {} { |
---|
| 797 | return [VisViewer::IsConnected] |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | # |
---|
| 801 | # disconnect -- |
---|
| 802 | # |
---|
| 803 | itcl::body Rappture::VtkGlyphViewer::disconnect {} { |
---|
| 804 | Disconnect |
---|
| 805 | set _reset 1 |
---|
| 806 | } |
---|
| 807 | |
---|
| 808 | # |
---|
| 809 | # Disconnect -- |
---|
| 810 | # |
---|
| 811 | # Clients use this method to disconnect from the current rendering |
---|
| 812 | # server. |
---|
| 813 | # |
---|
| 814 | itcl::body Rappture::VtkGlyphViewer::Disconnect {} { |
---|
| 815 | VisViewer::Disconnect |
---|
| 816 | |
---|
| 817 | $_dispatcher cancel !rebuild |
---|
| 818 | $_dispatcher cancel !resize |
---|
| 819 | $_dispatcher cancel !rotate |
---|
| 820 | $_dispatcher cancel !xcutplane |
---|
| 821 | $_dispatcher cancel !ycutplane |
---|
| 822 | $_dispatcher cancel !zcutplane |
---|
| 823 | $_dispatcher cancel !legend |
---|
| 824 | # disconnected -- no more data sitting on server |
---|
| 825 | set _outbuf "" |
---|
| 826 | array unset _datasets |
---|
| 827 | array unset _data |
---|
| 828 | array unset _colormaps |
---|
| 829 | array unset _seeds |
---|
| 830 | array unset _dataset2style |
---|
| 831 | array unset _obj2datasets |
---|
| 832 | } |
---|
| 833 | |
---|
| 834 | # ---------------------------------------------------------------------- |
---|
| 835 | # USAGE: ReceiveImage -bytes <size> -type <type> -token <token> |
---|
| 836 | # |
---|
| 837 | # Invoked automatically whenever the "image" command comes in from |
---|
| 838 | # the rendering server. Indicates that binary image data with the |
---|
| 839 | # specified <size> will follow. |
---|
| 840 | # ---------------------------------------------------------------------- |
---|
| 841 | itcl::body Rappture::VtkGlyphViewer::ReceiveImage { args } { |
---|
| 842 | array set info { |
---|
| 843 | -token "???" |
---|
| 844 | -bytes 0 |
---|
| 845 | -type image |
---|
| 846 | } |
---|
| 847 | array set info $args |
---|
| 848 | set bytes [ReceiveBytes $info(-bytes)] |
---|
| 849 | if { $info(-type) == "image" } { |
---|
| 850 | if 0 { |
---|
| 851 | set f [open "last.ppm" "w"] |
---|
| 852 | puts $f $bytes |
---|
| 853 | close $f |
---|
| 854 | } |
---|
| 855 | $_image(plot) configure -data $bytes |
---|
| 856 | set time [clock seconds] |
---|
| 857 | set date [clock format $time] |
---|
| 858 | #puts stderr "$date: received image [image width $_image(plot)]x[image height $_image(plot)] image>" |
---|
| 859 | if { $_start > 0 } { |
---|
| 860 | set finish [clock clicks -milliseconds] |
---|
| 861 | #puts stderr "round trip time [expr $finish -$_start] milliseconds" |
---|
| 862 | set _start 0 |
---|
| 863 | } |
---|
| 864 | } elseif { $info(type) == "print" } { |
---|
| 865 | set tag $this-print-$info(-token) |
---|
| 866 | set _hardcopy($tag) $bytes |
---|
| 867 | } |
---|
| 868 | } |
---|
| 869 | |
---|
| 870 | # |
---|
| 871 | # ReceiveDataset -- |
---|
| 872 | # |
---|
| 873 | itcl::body Rappture::VtkGlyphViewer::ReceiveDataset { args } { |
---|
| 874 | if { ![isconnected] } { |
---|
| 875 | return |
---|
| 876 | } |
---|
| 877 | set option [lindex $args 0] |
---|
| 878 | switch -- $option { |
---|
| 879 | "scalar" { |
---|
| 880 | set option [lindex $args 1] |
---|
| 881 | switch -- $option { |
---|
| 882 | "world" { |
---|
| 883 | foreach { x y z value tag } [lrange $args 2 end] break |
---|
| 884 | } |
---|
| 885 | "pixel" { |
---|
| 886 | foreach { x y value tag } [lrange $args 2 end] break |
---|
| 887 | } |
---|
| 888 | } |
---|
| 889 | } |
---|
| 890 | "vector" { |
---|
| 891 | set option [lindex $args 1] |
---|
| 892 | switch -- $option { |
---|
| 893 | "world" { |
---|
| 894 | foreach { x y z vx vy vz tag } [lrange $args 2 end] break |
---|
| 895 | } |
---|
| 896 | "pixel" { |
---|
| 897 | foreach { x y vx vy vz tag } [lrange $args 2 end] break |
---|
| 898 | } |
---|
| 899 | } |
---|
| 900 | } |
---|
| 901 | "names" { |
---|
| 902 | foreach { name } [lindex $args 1] { |
---|
| 903 | #puts stderr "Dataset: $name" |
---|
| 904 | } |
---|
| 905 | } |
---|
| 906 | default { |
---|
| 907 | error "unknown dataset option \"$option\" from server" |
---|
| 908 | } |
---|
| 909 | } |
---|
| 910 | } |
---|
| 911 | |
---|
| 912 | # ---------------------------------------------------------------------- |
---|
| 913 | # USAGE: Rebuild |
---|
| 914 | # |
---|
| 915 | # Called automatically whenever something changes that affects the |
---|
| 916 | # data in the widget. Clears any existing data and rebuilds the |
---|
| 917 | # widget to display new data. |
---|
| 918 | # ---------------------------------------------------------------------- |
---|
| 919 | itcl::body Rappture::VtkGlyphViewer::Rebuild {} { |
---|
| 920 | set w [winfo width $itk_component(view)] |
---|
| 921 | set h [winfo height $itk_component(view)] |
---|
| 922 | if { $w < 2 || $h < 2 } { |
---|
| 923 | $_dispatcher event -idle !rebuild |
---|
| 924 | return |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | # Turn on buffering of commands to the server. We don't want to |
---|
| 928 | # be preempted by a server disconnect/reconnect (which automatically |
---|
| 929 | # generates a new call to Rebuild). |
---|
| 930 | StartBufferingCommands |
---|
| 931 | |
---|
| 932 | if { $_reset } { |
---|
| 933 | set _width $w |
---|
| 934 | set _height $h |
---|
| 935 | $_arcball resize $w $h |
---|
| 936 | DoResize |
---|
| 937 | # |
---|
| 938 | # Reset the camera and other view parameters |
---|
| 939 | # |
---|
| 940 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
| 941 | $_arcball quaternion $q |
---|
| 942 | if {$_view(ortho)} { |
---|
| 943 | SendCmd "camera mode ortho" |
---|
| 944 | } else { |
---|
| 945 | SendCmd "camera mode persp" |
---|
| 946 | } |
---|
| 947 | DoRotate |
---|
| 948 | PanCamera |
---|
| 949 | set _first "" |
---|
| 950 | InitSettings axisXGrid axisYGrid axisZGrid axisMode \ |
---|
| 951 | axesVisible axisLabelsVisible |
---|
| 952 | foreach axis { x y z } { |
---|
| 953 | SendCmd "axis lformat $axis %g" |
---|
| 954 | } |
---|
| 955 | StopBufferingCommands |
---|
| 956 | SendCmd "imgflush" |
---|
| 957 | StartBufferingCommands |
---|
| 958 | } |
---|
| 959 | set _first "" |
---|
| 960 | SendCmd "dataset visible 0" |
---|
| 961 | foreach dataobj [get -objects] { |
---|
| 962 | if { [info exists _obj2ovride($dataobj-raise)] && $_first == "" } { |
---|
| 963 | set _first $dataobj |
---|
| 964 | } |
---|
| 965 | set _obj2datasets($dataobj) "" |
---|
| 966 | foreach comp [$dataobj components] { |
---|
| 967 | set tag $dataobj-$comp |
---|
| 968 | if { ![info exists _datasets($tag)] } { |
---|
| 969 | set bytes [$dataobj vtkdata $comp] |
---|
[4187] | 970 | if 0 { |
---|
[3685] | 971 | set f [open "/tmp/glyph.vtk" "w"] |
---|
| 972 | puts $f $bytes |
---|
| 973 | close $f |
---|
| 974 | } |
---|
| 975 | set length [string length $bytes] |
---|
| 976 | if { $_reportClientInfo } { |
---|
| 977 | set info {} |
---|
| 978 | lappend info "tool_id" [$dataobj hints toolId] |
---|
| 979 | lappend info "tool_name" [$dataobj hints toolName] |
---|
| 980 | lappend info "tool_version" [$dataobj hints toolRevision] |
---|
| 981 | lappend info "tool_title" [$dataobj hints toolTitle] |
---|
| 982 | lappend info "dataset_label" [$dataobj hints label] |
---|
| 983 | lappend info "dataset_size" $length |
---|
| 984 | lappend info "dataset_tag" $tag |
---|
| 985 | SendCmd "clientinfo [list $info]" |
---|
| 986 | } |
---|
| 987 | append _outbuf "dataset add $tag data follows $length\n" |
---|
| 988 | append _outbuf $bytes |
---|
| 989 | set _datasets($tag) 1 |
---|
| 990 | SetObjectStyle $dataobj $comp |
---|
| 991 | } |
---|
| 992 | lappend _obj2datasets($dataobj) $tag |
---|
| 993 | if { [info exists _obj2ovride($dataobj-raise)] } { |
---|
[3844] | 994 | # Setting dataset visible enables outline |
---|
[3685] | 995 | # and glyphs |
---|
| 996 | SendCmd "dataset visible 1 $tag" |
---|
| 997 | } |
---|
| 998 | } |
---|
| 999 | } |
---|
| 1000 | |
---|
| 1001 | if { $_first != "" } { |
---|
| 1002 | $itk_component(field) choices delete 0 end |
---|
| 1003 | $itk_component(fieldmenu) delete 0 end |
---|
| 1004 | array unset _fields |
---|
| 1005 | set _curFldName "" |
---|
| 1006 | foreach cname [$_first components] { |
---|
| 1007 | foreach fname [$_first fieldnames $cname] { |
---|
| 1008 | if { [info exists _fields($fname)] } { |
---|
| 1009 | continue |
---|
| 1010 | } |
---|
| 1011 | foreach { label units components } \ |
---|
| 1012 | [$_first fieldinfo $fname] break |
---|
| 1013 | $itk_component(field) choices insert end "$fname" "$label" |
---|
| 1014 | $itk_component(fieldmenu) add radiobutton -label "$label" \ |
---|
| 1015 | -value $label -variable [itcl::scope _curFldLabel] \ |
---|
| 1016 | -selectcolor red \ |
---|
| 1017 | -activebackground $itk_option(-plotbackground) \ |
---|
| 1018 | -activeforeground $itk_option(-plotforeground) \ |
---|
| 1019 | -font "Arial 8" \ |
---|
| 1020 | -command [itcl::code $this Combo invoke] |
---|
| 1021 | set _fields($fname) [list $label $units $components] |
---|
| 1022 | if { $_curFldName == "" } { |
---|
| 1023 | set _curFldName $fname |
---|
| 1024 | set _curFldLabel $label |
---|
| 1025 | } |
---|
| 1026 | } |
---|
| 1027 | } |
---|
| 1028 | $itk_component(field) value $_curFldLabel |
---|
| 1029 | } |
---|
[3844] | 1030 | InitSettings glyphOutline |
---|
| 1031 | #cutplaneVisible |
---|
[3685] | 1032 | if { $_reset } { |
---|
| 1033 | # These are settings that rely on a dataset being loaded. |
---|
| 1034 | InitSettings \ |
---|
| 1035 | glyphLighting \ |
---|
| 1036 | field \ |
---|
| 1037 | glyphEdges glyphLighting glyphOpacity \ |
---|
[3844] | 1038 | glyphWireframe |
---|
[3685] | 1039 | |
---|
| 1040 | #cutplaneXPosition cutplaneYPosition cutplaneZPosition \ |
---|
| 1041 | cutplaneXVisible cutplaneYVisible cutplaneZVisible \ |
---|
| 1042 | cutplanePreinterp |
---|
| 1043 | |
---|
| 1044 | Zoom reset |
---|
| 1045 | foreach axis { x y z } { |
---|
| 1046 | # Another problem fixed by a <view>. We looking into a data |
---|
| 1047 | # object for the name of the axes. This should be global to |
---|
| 1048 | # the viewer itself. |
---|
| 1049 | set label [$_first hints ${axis}label] |
---|
| 1050 | if { $label == "" } { |
---|
| 1051 | set label [string toupper $axis] |
---|
| 1052 | } |
---|
| 1053 | # May be a space in the axis label. |
---|
| 1054 | SendCmd [list axis name $axis $label] |
---|
| 1055 | } |
---|
| 1056 | if { [array size _fields] < 2 } { |
---|
| 1057 | blt::table forget $itk_component(field) $itk_component(field_l) |
---|
| 1058 | } |
---|
| 1059 | set _reset 0 |
---|
| 1060 | } |
---|
| 1061 | |
---|
| 1062 | # Actually write the commands to the server socket. If it fails, we don't |
---|
| 1063 | # care. We're finished here. |
---|
| 1064 | blt::busy hold $itk_component(hull) |
---|
| 1065 | StopBufferingCommands; # Turn off buffering and send commands. |
---|
| 1066 | blt::busy release $itk_component(hull) |
---|
| 1067 | } |
---|
| 1068 | |
---|
| 1069 | # ---------------------------------------------------------------------- |
---|
| 1070 | # USAGE: CurrentDatasets ?-all -visible? ?dataobjs? |
---|
| 1071 | # |
---|
| 1072 | # Returns a list of server IDs for the current datasets being displayed. This |
---|
| 1073 | # is normally a single ID, but it might be a list of IDs if the current data |
---|
| 1074 | # object has multiple components. |
---|
| 1075 | # ---------------------------------------------------------------------- |
---|
| 1076 | itcl::body Rappture::VtkGlyphViewer::CurrentDatasets {args} { |
---|
| 1077 | set flag [lindex $args 0] |
---|
| 1078 | switch -- $flag { |
---|
| 1079 | "-all" { |
---|
| 1080 | if { [llength $args] > 1 } { |
---|
| 1081 | error "CurrentDatasets: can't specify dataobj after \"-all\"" |
---|
| 1082 | } |
---|
| 1083 | set dlist [get -objects] |
---|
| 1084 | } |
---|
| 1085 | "-visible" { |
---|
| 1086 | if { [llength $args] > 1 } { |
---|
| 1087 | set dlist {} |
---|
| 1088 | set args [lrange $args 1 end] |
---|
| 1089 | foreach dataobj $args { |
---|
| 1090 | if { [info exists _obj2ovride($dataobj-raise)] } { |
---|
| 1091 | lappend dlist $dataobj |
---|
| 1092 | } |
---|
| 1093 | } |
---|
| 1094 | } else { |
---|
| 1095 | set dlist [get -visible] |
---|
| 1096 | } |
---|
| 1097 | } |
---|
| 1098 | default { |
---|
| 1099 | set dlist $args |
---|
| 1100 | } |
---|
| 1101 | } |
---|
| 1102 | set rlist "" |
---|
| 1103 | foreach dataobj $dlist { |
---|
| 1104 | foreach comp [$dataobj components] { |
---|
| 1105 | set tag $dataobj-$comp |
---|
| 1106 | if { [info exists _datasets($tag)] && $_datasets($tag) } { |
---|
| 1107 | lappend rlist $tag |
---|
| 1108 | } |
---|
| 1109 | } |
---|
| 1110 | } |
---|
| 1111 | return $rlist |
---|
| 1112 | } |
---|
| 1113 | |
---|
| 1114 | # ---------------------------------------------------------------------- |
---|
| 1115 | # USAGE: Zoom in |
---|
| 1116 | # USAGE: Zoom out |
---|
| 1117 | # USAGE: Zoom reset |
---|
| 1118 | # |
---|
| 1119 | # Called automatically when the user clicks on one of the zoom |
---|
| 1120 | # controls for this widget. Changes the zoom for the current view. |
---|
| 1121 | # ---------------------------------------------------------------------- |
---|
| 1122 | itcl::body Rappture::VtkGlyphViewer::Zoom {option} { |
---|
| 1123 | switch -- $option { |
---|
| 1124 | "in" { |
---|
| 1125 | set _view(zoom) [expr {$_view(zoom)*1.25}] |
---|
| 1126 | SendCmd "camera zoom $_view(zoom)" |
---|
| 1127 | } |
---|
| 1128 | "out" { |
---|
| 1129 | set _view(zoom) [expr {$_view(zoom)*0.8}] |
---|
| 1130 | SendCmd "camera zoom $_view(zoom)" |
---|
| 1131 | } |
---|
| 1132 | "reset" { |
---|
| 1133 | array set _view { |
---|
| 1134 | qw 0.853553 |
---|
| 1135 | qx -0.353553 |
---|
| 1136 | qy 0.353553 |
---|
| 1137 | qz 0.146447 |
---|
| 1138 | zoom 1.0 |
---|
| 1139 | xpan 0 |
---|
| 1140 | ypan 0 |
---|
| 1141 | } |
---|
| 1142 | if { $_first != "" } { |
---|
| 1143 | set location [$_first hints camera] |
---|
| 1144 | if { $location != "" } { |
---|
| 1145 | array set _view $location |
---|
| 1146 | } |
---|
| 1147 | } |
---|
| 1148 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
| 1149 | $_arcball quaternion $q |
---|
| 1150 | DoRotate |
---|
| 1151 | SendCmd "camera reset" |
---|
| 1152 | } |
---|
| 1153 | } |
---|
| 1154 | } |
---|
| 1155 | |
---|
| 1156 | itcl::body Rappture::VtkGlyphViewer::PanCamera {} { |
---|
| 1157 | set x $_view(xpan) |
---|
| 1158 | set y $_view(ypan) |
---|
| 1159 | SendCmd "camera pan $x $y" |
---|
| 1160 | } |
---|
| 1161 | |
---|
| 1162 | |
---|
| 1163 | # ---------------------------------------------------------------------- |
---|
| 1164 | # USAGE: Rotate click <x> <y> |
---|
| 1165 | # USAGE: Rotate drag <x> <y> |
---|
| 1166 | # USAGE: Rotate release <x> <y> |
---|
| 1167 | # |
---|
| 1168 | # Called automatically when the user clicks/drags/releases in the |
---|
| 1169 | # plot area. Moves the plot according to the user's actions. |
---|
| 1170 | # ---------------------------------------------------------------------- |
---|
| 1171 | itcl::body Rappture::VtkGlyphViewer::Rotate {option x y} { |
---|
| 1172 | switch -- $option { |
---|
| 1173 | "click" { |
---|
| 1174 | $itk_component(view) configure -cursor fleur |
---|
| 1175 | set _click(x) $x |
---|
| 1176 | set _click(y) $y |
---|
| 1177 | } |
---|
| 1178 | "drag" { |
---|
| 1179 | if {[array size _click] == 0} { |
---|
| 1180 | Rotate click $x $y |
---|
| 1181 | } else { |
---|
| 1182 | set w [winfo width $itk_component(view)] |
---|
| 1183 | set h [winfo height $itk_component(view)] |
---|
| 1184 | if {$w <= 0 || $h <= 0} { |
---|
| 1185 | return |
---|
| 1186 | } |
---|
| 1187 | |
---|
| 1188 | if {[catch { |
---|
| 1189 | # this fails sometimes for no apparent reason |
---|
| 1190 | set dx [expr {double($x-$_click(x))/$w}] |
---|
| 1191 | set dy [expr {double($y-$_click(y))/$h}] |
---|
| 1192 | }]} { |
---|
| 1193 | return |
---|
| 1194 | } |
---|
| 1195 | if { $dx == 0 && $dy == 0 } { |
---|
| 1196 | return |
---|
| 1197 | } |
---|
| 1198 | set q [$_arcball rotate $x $y $_click(x) $_click(y)] |
---|
| 1199 | EventuallyRotate $q |
---|
| 1200 | set _click(x) $x |
---|
| 1201 | set _click(y) $y |
---|
| 1202 | } |
---|
| 1203 | } |
---|
| 1204 | "release" { |
---|
| 1205 | Rotate drag $x $y |
---|
| 1206 | $itk_component(view) configure -cursor "" |
---|
| 1207 | catch {unset _click} |
---|
| 1208 | } |
---|
| 1209 | default { |
---|
| 1210 | error "bad option \"$option\": should be click, drag, release" |
---|
| 1211 | } |
---|
| 1212 | } |
---|
| 1213 | } |
---|
| 1214 | |
---|
| 1215 | itcl::body Rappture::VtkGlyphViewer::Pick {x y} { |
---|
| 1216 | foreach tag [CurrentDatasets -visible] { |
---|
| 1217 | SendCmdNoSplash "dataset getscalar pixel $x $y $tag" |
---|
| 1218 | } |
---|
| 1219 | } |
---|
| 1220 | |
---|
| 1221 | # ---------------------------------------------------------------------- |
---|
| 1222 | # USAGE: $this Pan click x y |
---|
| 1223 | # $this Pan drag x y |
---|
| 1224 | # $this Pan release x y |
---|
| 1225 | # |
---|
| 1226 | # Called automatically when the user clicks on one of the zoom |
---|
| 1227 | # controls for this widget. Changes the zoom for the current view. |
---|
| 1228 | # ---------------------------------------------------------------------- |
---|
| 1229 | itcl::body Rappture::VtkGlyphViewer::Pan {option x y} { |
---|
| 1230 | switch -- $option { |
---|
| 1231 | "set" { |
---|
| 1232 | set w [winfo width $itk_component(view)] |
---|
| 1233 | set h [winfo height $itk_component(view)] |
---|
| 1234 | set x [expr $x / double($w)] |
---|
| 1235 | set y [expr $y / double($h)] |
---|
| 1236 | set _view(xpan) [expr $_view(xpan) + $x] |
---|
| 1237 | set _view(ypan) [expr $_view(ypan) + $y] |
---|
| 1238 | PanCamera |
---|
| 1239 | return |
---|
| 1240 | } |
---|
| 1241 | "click" { |
---|
| 1242 | set _click(x) $x |
---|
| 1243 | set _click(y) $y |
---|
| 1244 | $itk_component(view) configure -cursor hand1 |
---|
| 1245 | } |
---|
| 1246 | "drag" { |
---|
| 1247 | if { ![info exists _click(x)] } { |
---|
| 1248 | set _click(x) $x |
---|
| 1249 | } |
---|
| 1250 | if { ![info exists _click(y)] } { |
---|
| 1251 | set _click(y) $y |
---|
| 1252 | } |
---|
| 1253 | set w [winfo width $itk_component(view)] |
---|
| 1254 | set h [winfo height $itk_component(view)] |
---|
| 1255 | set dx [expr ($_click(x) - $x)/double($w)] |
---|
| 1256 | set dy [expr ($_click(y) - $y)/double($h)] |
---|
| 1257 | set _click(x) $x |
---|
| 1258 | set _click(y) $y |
---|
| 1259 | set _view(xpan) [expr $_view(xpan) - $dx] |
---|
| 1260 | set _view(ypan) [expr $_view(ypan) - $dy] |
---|
| 1261 | PanCamera |
---|
| 1262 | } |
---|
| 1263 | "release" { |
---|
| 1264 | Pan drag $x $y |
---|
| 1265 | $itk_component(view) configure -cursor "" |
---|
| 1266 | } |
---|
| 1267 | default { |
---|
| 1268 | error "unknown option \"$option\": should set, click, drag, or release" |
---|
| 1269 | } |
---|
| 1270 | } |
---|
| 1271 | } |
---|
| 1272 | |
---|
| 1273 | # ---------------------------------------------------------------------- |
---|
| 1274 | # USAGE: InitSettings <what> ?<value>? |
---|
| 1275 | # |
---|
| 1276 | # Used internally to update rendering settings whenever parameters |
---|
| 1277 | # change in the popup settings panel. Sends the new settings off |
---|
| 1278 | # to the back end. |
---|
| 1279 | # ---------------------------------------------------------------------- |
---|
| 1280 | itcl::body Rappture::VtkGlyphViewer::InitSettings { args } { |
---|
| 1281 | foreach spec $args { |
---|
| 1282 | if { [info exists _settings($_first-$spec)] } { |
---|
| 1283 | # Reset global setting with dataobj specific setting |
---|
| 1284 | set _settings($spec) $_settings($_first-$spec) |
---|
| 1285 | } |
---|
| 1286 | AdjustSetting $spec |
---|
| 1287 | } |
---|
| 1288 | } |
---|
| 1289 | |
---|
| 1290 | # |
---|
| 1291 | # AdjustSetting -- |
---|
| 1292 | # |
---|
| 1293 | # Changes/updates a specific setting in the widget. There are |
---|
| 1294 | # usually user-setable option. Commands are sent to the render |
---|
| 1295 | # server. |
---|
| 1296 | # |
---|
| 1297 | itcl::body Rappture::VtkGlyphViewer::AdjustSetting {what {value ""}} { |
---|
| 1298 | if { ![isconnected] } { |
---|
| 1299 | return |
---|
| 1300 | } |
---|
| 1301 | switch -- $what { |
---|
| 1302 | "background" { |
---|
| 1303 | set bgcolor [$itk_component(background) value] |
---|
| 1304 | array set fgcolors { |
---|
| 1305 | "black" "white" |
---|
| 1306 | "white" "black" |
---|
| 1307 | "grey" "black" |
---|
| 1308 | } |
---|
| 1309 | configure -plotbackground $bgcolor \ |
---|
| 1310 | -plotforeground $fgcolors($bgcolor) |
---|
| 1311 | $itk_component(view) delete "legend" |
---|
| 1312 | DrawLegend |
---|
| 1313 | } |
---|
| 1314 | "axesVisible" { |
---|
| 1315 | set bool $_settings(axesVisible) |
---|
| 1316 | SendCmd "axis visible all $bool" |
---|
| 1317 | } |
---|
| 1318 | "axisLabelsVisible" { |
---|
| 1319 | set bool $_settings(axisLabelsVisible) |
---|
| 1320 | SendCmd "axis labels all $bool" |
---|
| 1321 | } |
---|
| 1322 | "axisXGrid" - "axisYGrid" - "axisZGrid" { |
---|
| 1323 | set axis [string tolower [string range $what 4 4]] |
---|
| 1324 | set bool $_settings($what) |
---|
| 1325 | SendCmd "axis grid $axis $bool" |
---|
| 1326 | } |
---|
| 1327 | "axisMode" { |
---|
| 1328 | set mode [$itk_component(axisMode) value] |
---|
| 1329 | set mode [$itk_component(axisMode) translate $mode] |
---|
| 1330 | set _settings($what) $mode |
---|
| 1331 | SendCmd "axis flymode $mode" |
---|
| 1332 | } |
---|
| 1333 | "cutplaneEdges" { |
---|
| 1334 | set bool $_settings($what) |
---|
| 1335 | SendCmd "cutplane edges $bool" |
---|
| 1336 | } |
---|
| 1337 | "cutplaneVisible" { |
---|
| 1338 | set bool $_settings($what) |
---|
| 1339 | SendCmd "cutplane visible $bool" |
---|
| 1340 | } |
---|
| 1341 | "cutplaneWireframe" { |
---|
| 1342 | set bool $_settings($what) |
---|
| 1343 | SendCmd "cutplane wireframe $bool" |
---|
| 1344 | } |
---|
| 1345 | "cutplaneLighting" { |
---|
| 1346 | set bool $_settings($what) |
---|
| 1347 | SendCmd "cutplane lighting $bool" |
---|
| 1348 | } |
---|
| 1349 | "cutplaneOpacity" { |
---|
| 1350 | set val $_settings($what) |
---|
| 1351 | set sval [expr { 0.01 * double($val) }] |
---|
| 1352 | SendCmd "cutplane opacity $sval" |
---|
| 1353 | } |
---|
| 1354 | "cutplanePreinterp" { |
---|
| 1355 | set bool $_settings($what) |
---|
| 1356 | SendCmd "cutplane preinterp $bool" |
---|
| 1357 | } |
---|
| 1358 | "cutplaneXVisible" - "cutplaneYVisible" - "cutplaneZVisible" { |
---|
| 1359 | set axis [string tolower [string range $what 8 8]] |
---|
| 1360 | set bool $_settings($what) |
---|
| 1361 | if { $bool } { |
---|
| 1362 | $itk_component(${axis}position) configure -state normal \ |
---|
| 1363 | -troughcolor white |
---|
| 1364 | } else { |
---|
| 1365 | $itk_component(${axis}position) configure -state disabled \ |
---|
| 1366 | -troughcolor grey82 |
---|
| 1367 | } |
---|
| 1368 | SendCmd "cutplane axis $axis $bool" |
---|
| 1369 | } |
---|
| 1370 | "cutplaneXPosition" - "cutplaneYPosition" - "cutplaneZPosition" { |
---|
| 1371 | set axis [string tolower [string range $what 8 8]] |
---|
| 1372 | set pos [expr $_settings($what) * 0.01] |
---|
| 1373 | SendCmd "cutplane slice ${axis} ${pos}" |
---|
| 1374 | set _cutplanePending 0 |
---|
| 1375 | } |
---|
| 1376 | "colormap" { |
---|
| 1377 | set _changed(colormap) 1 |
---|
| 1378 | StartBufferingCommands |
---|
| 1379 | set color [$itk_component(colormap) value] |
---|
| 1380 | set _settings(colormap) $color |
---|
| 1381 | if { $color == "none" } { |
---|
| 1382 | if { $_settings(colormapVisible) } { |
---|
[3843] | 1383 | SendCmd "glyphs colormode constant {}" |
---|
[3685] | 1384 | set _settings(colormapVisible) 0 |
---|
| 1385 | } |
---|
| 1386 | } else { |
---|
| 1387 | if { !$_settings(colormapVisible) } { |
---|
[3765] | 1388 | SendCmd "glyphs colormode $_colorMode $_curFldName" |
---|
[3685] | 1389 | set _settings(colormapVisible) 1 |
---|
| 1390 | } |
---|
| 1391 | SetCurrentColormap $color |
---|
| 1392 | } |
---|
| 1393 | StopBufferingCommands |
---|
| 1394 | EventuallyRequestLegend |
---|
| 1395 | } |
---|
| 1396 | "glyphWireframe" { |
---|
| 1397 | set bool $_settings(glyphWireframe) |
---|
| 1398 | SendCmd "glyphs wireframe $bool" |
---|
| 1399 | } |
---|
| 1400 | "glyphVisible" { |
---|
| 1401 | set bool $_settings(glyphVisible) |
---|
| 1402 | SendCmd "glyphs visible $bool" |
---|
| 1403 | if { $bool } { |
---|
| 1404 | Rappture::Tooltip::for $itk_component(glyphs) \ |
---|
| 1405 | "Hide the glyph" |
---|
| 1406 | } else { |
---|
| 1407 | Rappture::Tooltip::for $itk_component(glyphs) \ |
---|
| 1408 | "Show the glyph" |
---|
| 1409 | } |
---|
| 1410 | DrawLegend |
---|
| 1411 | } |
---|
| 1412 | "glyphLighting" { |
---|
| 1413 | set bool $_settings(glyphLighting) |
---|
| 1414 | SendCmd "glyphs lighting $bool" |
---|
| 1415 | } |
---|
| 1416 | "glyphEdges" { |
---|
| 1417 | set bool $_settings(glyphEdges) |
---|
| 1418 | SendCmd "glyphs edges $bool" |
---|
| 1419 | } |
---|
| 1420 | "glyphOutline" { |
---|
| 1421 | set bool $_settings(glyphOutline) |
---|
| 1422 | SendCmd "outline visible $bool" |
---|
| 1423 | } |
---|
| 1424 | "glyphOpacity" { |
---|
| 1425 | set val $_settings(glyphOpacity) |
---|
| 1426 | set sval [expr { 0.01 * double($val) }] |
---|
| 1427 | SendCmd "glyphs opacity $sval" |
---|
| 1428 | } |
---|
| 1429 | "field" { |
---|
| 1430 | set label [$itk_component(field) value] |
---|
| 1431 | set fname [$itk_component(field) translate $label] |
---|
| 1432 | set _settings(field) $fname |
---|
| 1433 | if { [info exists _fields($fname)] } { |
---|
| 1434 | foreach { label units components } $_fields($fname) break |
---|
| 1435 | if { $components > 1 } { |
---|
| 1436 | set _colorMode vmag |
---|
| 1437 | } else { |
---|
| 1438 | set _colorMode scalar |
---|
| 1439 | } |
---|
| 1440 | set _curFldName $fname |
---|
| 1441 | set _curFldLabel $label |
---|
| 1442 | } else { |
---|
| 1443 | puts stderr "unknown field \"$fname\"" |
---|
| 1444 | return |
---|
| 1445 | } |
---|
[3765] | 1446 | #SendCmd "dataset maprange explicit $_limits($_curFldName) $_curFldName" |
---|
[3685] | 1447 | #SendCmd "cutplane colormode $_colorMode $_curFldName" |
---|
| 1448 | SendCmd "glyphs colormode $_colorMode $_curFldName" |
---|
| 1449 | DrawLegend |
---|
| 1450 | } |
---|
| 1451 | "legendVisible" { |
---|
| 1452 | if { !$_settings(legendVisible) } { |
---|
| 1453 | $itk_component(view) delete legend |
---|
| 1454 | } |
---|
| 1455 | DrawLegend |
---|
| 1456 | } |
---|
| 1457 | default { |
---|
| 1458 | error "don't know how to fix $what" |
---|
| 1459 | } |
---|
| 1460 | } |
---|
| 1461 | } |
---|
| 1462 | |
---|
| 1463 | |
---|
| 1464 | # |
---|
| 1465 | # RequestLegend -- |
---|
| 1466 | # |
---|
| 1467 | # Request a new legend from the server. The size of the legend |
---|
| 1468 | # is determined from the height of the canvas. |
---|
| 1469 | # |
---|
| 1470 | # This should be called when |
---|
| 1471 | # 1. A new current colormap is set. |
---|
| 1472 | # 2. Window is resized. |
---|
| 1473 | # 3. The limits of the data have changed. (Just need a redraw). |
---|
| 1474 | # 4. Number of glyph have changed. (Just need a redraw). |
---|
| 1475 | # 5. Legend becomes visible (Just need a redraw). |
---|
| 1476 | # |
---|
| 1477 | itcl::body Rappture::VtkGlyphViewer::RequestLegend {} { |
---|
[3780] | 1478 | set _legendPending 0 |
---|
[3685] | 1479 | set font "Arial 8" |
---|
[4481] | 1480 | set w 12 |
---|
[3685] | 1481 | set lineht [font metrics $font -linespace] |
---|
[4481] | 1482 | # color ramp height = (canvas height) - (min and max value lines) - 2 |
---|
[3685] | 1483 | set h [expr {$_height - 2 * ($lineht + 2)}] |
---|
[4481] | 1484 | |
---|
| 1485 | set fname $_curFldName |
---|
[3685] | 1486 | if { [string match "component*" $fname] } { |
---|
| 1487 | set title "" |
---|
| 1488 | } else { |
---|
| 1489 | if { [info exists _fields($fname)] } { |
---|
| 1490 | foreach { title units } $_fields($fname) break |
---|
| 1491 | if { $units != "" } { |
---|
| 1492 | set title [format "%s (%s)" $title $units] |
---|
| 1493 | } |
---|
| 1494 | } else { |
---|
| 1495 | set title $fname |
---|
| 1496 | } |
---|
| 1497 | } |
---|
| 1498 | # If there's a title too, substract one more line |
---|
| 1499 | if { $title != "" } { |
---|
| 1500 | incr h -$lineht |
---|
| 1501 | } |
---|
[4481] | 1502 | if { $h < 1 } { |
---|
| 1503 | return |
---|
| 1504 | } |
---|
[3685] | 1505 | # Set the legend on the first heightmap dataset. |
---|
| 1506 | if { $_currentColormap != "" } { |
---|
| 1507 | set cmap $_currentColormap |
---|
[3765] | 1508 | SendCmdNoWait "legend $cmap $_colorMode $_curFldName {} $w $h 0" |
---|
[3685] | 1509 | } |
---|
| 1510 | } |
---|
| 1511 | |
---|
| 1512 | # ---------------------------------------------------------------------- |
---|
| 1513 | # CONFIGURATION OPTION: -plotbackground |
---|
| 1514 | # ---------------------------------------------------------------------- |
---|
| 1515 | itcl::configbody Rappture::VtkGlyphViewer::plotbackground { |
---|
| 1516 | if { [isconnected] } { |
---|
| 1517 | set rgb [Color2RGB $itk_option(-plotbackground)] |
---|
| 1518 | SendCmd "screen bgcolor $rgb" |
---|
| 1519 | } |
---|
| 1520 | } |
---|
| 1521 | |
---|
| 1522 | # ---------------------------------------------------------------------- |
---|
| 1523 | # CONFIGURATION OPTION: -plotforeground |
---|
| 1524 | # ---------------------------------------------------------------------- |
---|
| 1525 | itcl::configbody Rappture::VtkGlyphViewer::plotforeground { |
---|
| 1526 | if { [isconnected] } { |
---|
| 1527 | set rgb [Color2RGB $itk_option(-plotforeground)] |
---|
| 1528 | SendCmd "axis color all $rgb" |
---|
| 1529 | SendCmd "outline color $rgb" |
---|
[3843] | 1530 | #SendCmd "cutplane color $rgb" |
---|
[3685] | 1531 | } |
---|
| 1532 | } |
---|
| 1533 | |
---|
| 1534 | itcl::body Rappture::VtkGlyphViewer::limits { dataobj } { |
---|
| 1535 | foreach { limits(xmin) limits(xmax) } [$dataobj limits x] break |
---|
| 1536 | foreach { limits(ymin) limits(ymax) } [$dataobj limits y] break |
---|
| 1537 | foreach { limits(zmin) limits(zmax) } [$dataobj limits z] break |
---|
| 1538 | foreach { limits(vmin) limits(vmax) } [$dataobj limits v] break |
---|
| 1539 | return [array get limits] |
---|
| 1540 | } |
---|
| 1541 | |
---|
| 1542 | itcl::body Rappture::VtkGlyphViewer::BuildGlyphTab {} { |
---|
| 1543 | |
---|
| 1544 | set fg [option get $itk_component(hull) font Font] |
---|
| 1545 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
| 1546 | |
---|
| 1547 | set inner [$itk_component(main) insert end \ |
---|
| 1548 | -title "Glyph Settings" \ |
---|
| 1549 | -icon [Rappture::icon volume-on]] |
---|
| 1550 | $inner configure -borderwidth 4 |
---|
| 1551 | |
---|
| 1552 | checkbutton $inner.glyphs \ |
---|
| 1553 | -text "Glyphs" \ |
---|
| 1554 | -variable [itcl::scope _settings(glyphVisible)] \ |
---|
| 1555 | -command [itcl::code $this AdjustSetting glyphVisible] \ |
---|
| 1556 | -font "Arial 9" |
---|
| 1557 | |
---|
| 1558 | checkbutton $inner.wireframe \ |
---|
| 1559 | -text "Wireframe" \ |
---|
| 1560 | -variable [itcl::scope _settings(glyphWireframe)] \ |
---|
| 1561 | -command [itcl::code $this AdjustSetting glyphWireframe] \ |
---|
| 1562 | -font "Arial 9" |
---|
| 1563 | |
---|
| 1564 | checkbutton $inner.lighting \ |
---|
| 1565 | -text "Enable Lighting" \ |
---|
| 1566 | -variable [itcl::scope _settings(glyphLighting)] \ |
---|
| 1567 | -command [itcl::code $this AdjustSetting glyphLighting] \ |
---|
| 1568 | -font "Arial 9" |
---|
| 1569 | |
---|
| 1570 | checkbutton $inner.edges \ |
---|
| 1571 | -text "Edges" \ |
---|
| 1572 | -variable [itcl::scope _settings(glyphEdges)] \ |
---|
| 1573 | -command [itcl::code $this AdjustSetting glyphEdges] \ |
---|
| 1574 | -font "Arial 9" |
---|
| 1575 | |
---|
| 1576 | checkbutton $inner.outline \ |
---|
| 1577 | -text "Outline" \ |
---|
| 1578 | -variable [itcl::scope _settings(glyphOutline)] \ |
---|
| 1579 | -command [itcl::code $this AdjustSetting glyphOutline] \ |
---|
| 1580 | -font "Arial 9" |
---|
| 1581 | |
---|
| 1582 | checkbutton $inner.legend \ |
---|
| 1583 | -text "Legend" \ |
---|
| 1584 | -variable [itcl::scope _settings(legendVisible)] \ |
---|
| 1585 | -command [itcl::code $this AdjustSetting legendVisible] \ |
---|
| 1586 | -font "Arial 9" |
---|
| 1587 | |
---|
| 1588 | label $inner.background_l -text "Background" -font "Arial 9" |
---|
| 1589 | itk_component add background { |
---|
| 1590 | Rappture::Combobox $inner.background -width 10 -editable no |
---|
| 1591 | } |
---|
| 1592 | $inner.background choices insert end \ |
---|
| 1593 | "black" "black" \ |
---|
| 1594 | "white" "white" \ |
---|
| 1595 | "grey" "grey" |
---|
| 1596 | |
---|
| 1597 | $itk_component(background) value $_settings(background) |
---|
| 1598 | bind $inner.background <<Value>> [itcl::code $this AdjustSetting background] |
---|
| 1599 | |
---|
| 1600 | label $inner.opacity_l -text "Opacity" -font "Arial 9" |
---|
| 1601 | ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ |
---|
| 1602 | -variable [itcl::scope _settings(glyphOpacity)] \ |
---|
| 1603 | -width 10 \ |
---|
| 1604 | -showvalue off \ |
---|
| 1605 | -command [itcl::code $this AdjustSetting glyphOpacity] |
---|
| 1606 | |
---|
| 1607 | label $inner.scale_l -text "Scale" -font "Arial 9" |
---|
| 1608 | ::scale $inner.scale -from 1 -to 100 -orient horizontal \ |
---|
| 1609 | -variable [itcl::scope _settings(glyphs-scale)] \ |
---|
| 1610 | -width 10 \ |
---|
| 1611 | -showvalue off \ |
---|
| 1612 | -command [itcl::code $this AdjustSetting glyphs-scale] |
---|
| 1613 | |
---|
| 1614 | itk_component add field_l { |
---|
[3765] | 1615 | label $inner.field_l -text "Color By" -font "Arial 9" |
---|
[3685] | 1616 | } { |
---|
| 1617 | ignore -font |
---|
| 1618 | } |
---|
| 1619 | itk_component add field { |
---|
| 1620 | Rappture::Combobox $inner.field -width 10 -editable no |
---|
| 1621 | } |
---|
| 1622 | bind $inner.field <<Value>> \ |
---|
| 1623 | [itcl::code $this AdjustSetting field] |
---|
| 1624 | |
---|
| 1625 | label $inner.colormap_l -text "Colormap" -font "Arial 9" |
---|
| 1626 | itk_component add colormap { |
---|
| 1627 | Rappture::Combobox $inner.colormap -width 10 -editable no |
---|
| 1628 | } |
---|
| 1629 | |
---|
[4449] | 1630 | $inner.colormap choices insert end [GetColormapList] |
---|
[3685] | 1631 | $itk_component(colormap) value "BCGYR" |
---|
| 1632 | bind $inner.colormap <<Value>> \ |
---|
| 1633 | [itcl::code $this AdjustSetting colormap] |
---|
| 1634 | |
---|
| 1635 | blt::table $inner \ |
---|
| 1636 | 0,0 $inner.field_l -anchor w -pady 2 \ |
---|
| 1637 | 0,1 $inner.field -anchor w -pady 2 -fill x \ |
---|
| 1638 | 1,0 $inner.colormap_l -anchor w -pady 2 \ |
---|
| 1639 | 1,1 $inner.colormap -anchor w -pady 2 -fill x \ |
---|
| 1640 | 3,0 $inner.background_l -anchor w -pady 2 \ |
---|
| 1641 | 3,1 $inner.background -anchor w -pady 2 -fill x \ |
---|
| 1642 | 5,0 $inner.wireframe -anchor w -pady 2 -cspan 2 \ |
---|
| 1643 | 6,0 $inner.lighting -anchor w -pady 2 -cspan 2 \ |
---|
| 1644 | 7,0 $inner.edges -anchor w -pady 2 -cspan 2 \ |
---|
| 1645 | 8,0 $inner.outline -anchor w -pady 2 -cspan 2 \ |
---|
| 1646 | 9,0 $inner.legend -anchor w -pady 2 \ |
---|
| 1647 | 10,0 $inner.opacity_l -anchor w -pady 2 \ |
---|
| 1648 | 10,1 $inner.opacity -fill x -pady 2 -fill x \ |
---|
| 1649 | |
---|
| 1650 | blt::table configure $inner r* c* -resize none |
---|
| 1651 | blt::table configure $inner r11 c1 -resize expand |
---|
| 1652 | } |
---|
| 1653 | |
---|
| 1654 | itcl::body Rappture::VtkGlyphViewer::BuildAxisTab {} { |
---|
| 1655 | |
---|
| 1656 | set fg [option get $itk_component(hull) font Font] |
---|
| 1657 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
| 1658 | |
---|
| 1659 | set inner [$itk_component(main) insert end \ |
---|
| 1660 | -title "Axis Settings" \ |
---|
| 1661 | -icon [Rappture::icon axis2]] |
---|
| 1662 | $inner configure -borderwidth 4 |
---|
| 1663 | |
---|
| 1664 | checkbutton $inner.visible \ |
---|
| 1665 | -text "Show Axes" \ |
---|
| 1666 | -variable [itcl::scope _settings(axesVisible)] \ |
---|
| 1667 | -command [itcl::code $this AdjustSetting axesVisible] \ |
---|
| 1668 | -font "Arial 9" |
---|
| 1669 | |
---|
| 1670 | checkbutton $inner.labels \ |
---|
| 1671 | -text "Show Axis Labels" \ |
---|
| 1672 | -variable [itcl::scope _settings(axisLabelsVisible)] \ |
---|
| 1673 | -command [itcl::code $this AdjustSetting axisLabelsVisible] \ |
---|
| 1674 | -font "Arial 9" |
---|
| 1675 | |
---|
| 1676 | checkbutton $inner.gridx \ |
---|
| 1677 | -text "Show X Grid" \ |
---|
| 1678 | -variable [itcl::scope _settings(axisXGrid)] \ |
---|
| 1679 | -command [itcl::code $this AdjustSetting axisXGrid] \ |
---|
| 1680 | -font "Arial 9" |
---|
| 1681 | checkbutton $inner.gridy \ |
---|
| 1682 | -text "Show Y Grid" \ |
---|
| 1683 | -variable [itcl::scope _settings(axisYGrid)] \ |
---|
| 1684 | -command [itcl::code $this AdjustSetting axisYGrid] \ |
---|
| 1685 | -font "Arial 9" |
---|
| 1686 | checkbutton $inner.gridz \ |
---|
| 1687 | -text "Show Z Grid" \ |
---|
| 1688 | -variable [itcl::scope _settings(axisZGrid)] \ |
---|
| 1689 | -command [itcl::code $this AdjustSetting axisZGrid] \ |
---|
| 1690 | -font "Arial 9" |
---|
| 1691 | |
---|
| 1692 | label $inner.mode_l -text "Mode" -font "Arial 9" |
---|
| 1693 | |
---|
| 1694 | itk_component add axisMode { |
---|
| 1695 | Rappture::Combobox $inner.mode -width 10 -editable no |
---|
| 1696 | } |
---|
| 1697 | $inner.mode choices insert end \ |
---|
| 1698 | "static_triad" "static" \ |
---|
| 1699 | "closest_triad" "closest" \ |
---|
[4187] | 1700 | "furthest_triad" "farthest" \ |
---|
[3685] | 1701 | "outer_edges" "outer" |
---|
| 1702 | $itk_component(axisMode) value "static" |
---|
| 1703 | bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axisMode] |
---|
| 1704 | |
---|
| 1705 | blt::table $inner \ |
---|
| 1706 | 0,0 $inner.visible -anchor w -cspan 2 \ |
---|
| 1707 | 1,0 $inner.labels -anchor w -cspan 2 \ |
---|
| 1708 | 2,0 $inner.gridx -anchor w -cspan 2 \ |
---|
| 1709 | 3,0 $inner.gridy -anchor w -cspan 2 \ |
---|
| 1710 | 4,0 $inner.gridz -anchor w -cspan 2 \ |
---|
| 1711 | 5,0 $inner.mode_l -anchor w -cspan 2 -padx { 2 0 } \ |
---|
| 1712 | 6,0 $inner.mode -fill x -cspan 2 |
---|
| 1713 | |
---|
| 1714 | blt::table configure $inner r* c* -resize none |
---|
| 1715 | blt::table configure $inner r7 c1 -resize expand |
---|
| 1716 | } |
---|
| 1717 | |
---|
| 1718 | |
---|
| 1719 | itcl::body Rappture::VtkGlyphViewer::BuildCameraTab {} { |
---|
| 1720 | set inner [$itk_component(main) insert end \ |
---|
| 1721 | -title "Camera Settings" \ |
---|
| 1722 | -icon [Rappture::icon camera]] |
---|
| 1723 | $inner configure -borderwidth 4 |
---|
| 1724 | |
---|
| 1725 | label $inner.view_l -text "view" -font "Arial 9" |
---|
| 1726 | set f [frame $inner.view] |
---|
| 1727 | foreach side { front back left right top bottom } { |
---|
| 1728 | button $f.$side -image [Rappture::icon view$side] \ |
---|
| 1729 | -command [itcl::code $this SetOrientation $side] |
---|
| 1730 | Rappture::Tooltip::for $f.$side "Change the view to $side" |
---|
| 1731 | pack $f.$side -side left |
---|
| 1732 | } |
---|
| 1733 | |
---|
| 1734 | blt::table $inner \ |
---|
| 1735 | 0,0 $inner.view_l -anchor e -pady 2 \ |
---|
| 1736 | 0,1 $inner.view -anchor w -pady 2 |
---|
| 1737 | |
---|
| 1738 | set labels { qx qy qz qw xpan ypan zoom } |
---|
| 1739 | set row 1 |
---|
| 1740 | foreach tag $labels { |
---|
| 1741 | label $inner.${tag}label -text $tag -font "Arial 9" |
---|
| 1742 | entry $inner.${tag} -font "Arial 9" -bg white \ |
---|
| 1743 | -textvariable [itcl::scope _view($tag)] |
---|
| 1744 | bind $inner.${tag} <KeyPress-Return> \ |
---|
| 1745 | [itcl::code $this camera set ${tag}] |
---|
| 1746 | blt::table $inner \ |
---|
| 1747 | $row,0 $inner.${tag}label -anchor e -pady 2 \ |
---|
| 1748 | $row,1 $inner.${tag} -anchor w -pady 2 |
---|
| 1749 | blt::table configure $inner r$row -resize none |
---|
| 1750 | incr row |
---|
| 1751 | } |
---|
| 1752 | checkbutton $inner.ortho \ |
---|
| 1753 | -text "Orthographic Projection" \ |
---|
| 1754 | -variable [itcl::scope _view(ortho)] \ |
---|
| 1755 | -command [itcl::code $this camera set ortho] \ |
---|
| 1756 | -font "Arial 9" |
---|
| 1757 | blt::table $inner \ |
---|
| 1758 | $row,0 $inner.ortho -cspan 2 -anchor w -pady 2 |
---|
| 1759 | blt::table configure $inner r$row -resize none |
---|
| 1760 | incr row |
---|
| 1761 | |
---|
| 1762 | blt::table configure $inner c* r* -resize none |
---|
| 1763 | blt::table configure $inner c2 -resize expand |
---|
| 1764 | blt::table configure $inner r$row -resize expand |
---|
| 1765 | } |
---|
| 1766 | |
---|
| 1767 | itcl::body Rappture::VtkGlyphViewer::BuildCutplaneTab {} { |
---|
| 1768 | |
---|
| 1769 | set fg [option get $itk_component(hull) font Font] |
---|
| 1770 | |
---|
| 1771 | set inner [$itk_component(main) insert end \ |
---|
| 1772 | -title "Cutplane Settings" \ |
---|
| 1773 | -icon [Rappture::icon cutbutton]] |
---|
| 1774 | |
---|
| 1775 | $inner configure -borderwidth 4 |
---|
| 1776 | |
---|
| 1777 | checkbutton $inner.visible \ |
---|
| 1778 | -text "Cutplanes" \ |
---|
| 1779 | -variable [itcl::scope _settings(cutplaneVisible)] \ |
---|
| 1780 | -command [itcl::code $this AdjustSetting cutplaneVisible] \ |
---|
| 1781 | -font "Arial 9" |
---|
| 1782 | |
---|
| 1783 | checkbutton $inner.wireframe \ |
---|
| 1784 | -text "Wireframe" \ |
---|
| 1785 | -variable [itcl::scope _settings(cutplaneWireframe)] \ |
---|
| 1786 | -command [itcl::code $this AdjustSetting cutplaneWireframe] \ |
---|
| 1787 | -font "Arial 9" |
---|
| 1788 | |
---|
| 1789 | checkbutton $inner.lighting \ |
---|
| 1790 | -text "Enable Lighting" \ |
---|
| 1791 | -variable [itcl::scope _settings(cutplaneLighting)] \ |
---|
| 1792 | -command [itcl::code $this AdjustSetting cutplaneLighting] \ |
---|
| 1793 | -font "Arial 9" |
---|
| 1794 | |
---|
| 1795 | checkbutton $inner.edges \ |
---|
| 1796 | -text "Edges" \ |
---|
| 1797 | -variable [itcl::scope _settings(cutplaneEdges)] \ |
---|
| 1798 | -command [itcl::code $this AdjustSetting cutplaneEdges] \ |
---|
| 1799 | -font "Arial 9" |
---|
| 1800 | |
---|
| 1801 | checkbutton $inner.preinterp \ |
---|
| 1802 | -text "Interpolate Scalars" \ |
---|
| 1803 | -variable [itcl::scope _settings(cutplanePreinterp)] \ |
---|
| 1804 | -command [itcl::code $this AdjustSetting cutplanePreinterp] \ |
---|
| 1805 | -font "Arial 9" |
---|
| 1806 | |
---|
| 1807 | label $inner.opacity_l -text "Opacity" -font "Arial 9" |
---|
| 1808 | ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ |
---|
| 1809 | -variable [itcl::scope _settings(cutplaneOpacity)] \ |
---|
| 1810 | -width 10 \ |
---|
| 1811 | -showvalue off \ |
---|
| 1812 | -command [itcl::code $this AdjustSetting cutplaneOpacity] |
---|
| 1813 | $inner.opacity set $_settings(cutplaneOpacity) |
---|
| 1814 | |
---|
| 1815 | # X-value slicer... |
---|
| 1816 | itk_component add xbutton { |
---|
| 1817 | Rappture::PushButton $inner.xbutton \ |
---|
| 1818 | -onimage [Rappture::icon x-cutplane-red] \ |
---|
| 1819 | -offimage [Rappture::icon x-cutplane-red] \ |
---|
| 1820 | -command [itcl::code $this AdjustSetting cutplaneXVisible] \ |
---|
| 1821 | -variable [itcl::scope _settings(cutplaneXVisible)] \ |
---|
| 1822 | } |
---|
| 1823 | Rappture::Tooltip::for $itk_component(xbutton) \ |
---|
| 1824 | "Toggle the X-axis cutplane on/off" |
---|
| 1825 | $itk_component(xbutton) select |
---|
| 1826 | itk_component add xposition { |
---|
| 1827 | ::scale $inner.xval -from 100 -to 0 \ |
---|
| 1828 | -width 10 -orient vertical -showvalue yes \ |
---|
| 1829 | -borderwidth 1 -highlightthickness 0 \ |
---|
| 1830 | -command [itcl::code $this EventuallySetCutplane x] \ |
---|
| 1831 | -variable [itcl::scope _settings(cutplaneXPosition)] \ |
---|
| 1832 | -foreground red2 -font "Arial 9 bold" |
---|
| 1833 | } { |
---|
| 1834 | usual |
---|
| 1835 | ignore -borderwidth -highlightthickness -foreground -font -background |
---|
| 1836 | } |
---|
| 1837 | # Set the default cutplane value before disabling the scale. |
---|
| 1838 | $itk_component(xposition) set 50 |
---|
| 1839 | $itk_component(xposition) configure -state disabled |
---|
| 1840 | Rappture::Tooltip::for $itk_component(xposition) \ |
---|
| 1841 | "@[itcl::code $this Slice tooltip x]" |
---|
| 1842 | |
---|
| 1843 | # Y-value slicer... |
---|
| 1844 | itk_component add ybutton { |
---|
| 1845 | Rappture::PushButton $inner.ybutton \ |
---|
| 1846 | -onimage [Rappture::icon y-cutplane-green] \ |
---|
| 1847 | -offimage [Rappture::icon y-cutplane-green] \ |
---|
| 1848 | -command [itcl::code $this AdjustSetting cutplaneYVisible] \ |
---|
| 1849 | -variable [itcl::scope _settings(cutplaneYVisible)] \ |
---|
| 1850 | } |
---|
| 1851 | Rappture::Tooltip::for $itk_component(ybutton) \ |
---|
| 1852 | "Toggle the Y-axis cutplane on/off" |
---|
| 1853 | $itk_component(ybutton) select |
---|
| 1854 | |
---|
| 1855 | itk_component add yposition { |
---|
| 1856 | ::scale $inner.yval -from 100 -to 0 \ |
---|
| 1857 | -width 10 -orient vertical -showvalue yes \ |
---|
| 1858 | -borderwidth 1 -highlightthickness 0 \ |
---|
| 1859 | -command [itcl::code $this EventuallySetCutplane y] \ |
---|
| 1860 | -variable [itcl::scope _settings(cutplaneYPosition)] \ |
---|
| 1861 | -foreground green3 -font "Arial 9 bold" |
---|
| 1862 | } { |
---|
| 1863 | usual |
---|
| 1864 | ignore -borderwidth -highlightthickness -foreground -font |
---|
| 1865 | } |
---|
| 1866 | Rappture::Tooltip::for $itk_component(yposition) \ |
---|
| 1867 | "@[itcl::code $this Slice tooltip y]" |
---|
| 1868 | # Set the default cutplane value before disabling the scale. |
---|
| 1869 | $itk_component(yposition) set 50 |
---|
| 1870 | $itk_component(yposition) configure -state disabled |
---|
| 1871 | |
---|
| 1872 | # Z-value slicer... |
---|
| 1873 | itk_component add zbutton { |
---|
| 1874 | Rappture::PushButton $inner.zbutton \ |
---|
| 1875 | -onimage [Rappture::icon z-cutplane-blue] \ |
---|
| 1876 | -offimage [Rappture::icon z-cutplane-blue] \ |
---|
| 1877 | -command [itcl::code $this AdjustSetting cutplaneZVisible] \ |
---|
| 1878 | -variable [itcl::scope _settings(cutplaneZVisible)] \ |
---|
| 1879 | } { |
---|
| 1880 | usual |
---|
| 1881 | ignore -foreground |
---|
| 1882 | } |
---|
| 1883 | Rappture::Tooltip::for $itk_component(zbutton) \ |
---|
| 1884 | "Toggle the Z-axis cutplane on/off" |
---|
| 1885 | $itk_component(zbutton) select |
---|
| 1886 | |
---|
| 1887 | itk_component add zposition { |
---|
| 1888 | ::scale $inner.zval -from 100 -to 0 \ |
---|
| 1889 | -width 10 -orient vertical -showvalue yes \ |
---|
| 1890 | -borderwidth 1 -highlightthickness 0 \ |
---|
| 1891 | -command [itcl::code $this EventuallySetCutplane z] \ |
---|
| 1892 | -variable [itcl::scope _settings(cutplaneZPosition)] \ |
---|
| 1893 | -foreground blue3 -font "Arial 9 bold" |
---|
| 1894 | } { |
---|
| 1895 | usual |
---|
| 1896 | ignore -borderwidth -highlightthickness -foreground -font |
---|
| 1897 | } |
---|
| 1898 | $itk_component(zposition) set 50 |
---|
| 1899 | $itk_component(zposition) configure -state disabled |
---|
| 1900 | Rappture::Tooltip::for $itk_component(zposition) \ |
---|
| 1901 | "@[itcl::code $this Slice tooltip z]" |
---|
| 1902 | |
---|
| 1903 | blt::table $inner \ |
---|
| 1904 | 0,0 $inner.visible -anchor w -pady 2 -cspan 3 \ |
---|
| 1905 | 1,0 $inner.lighting -anchor w -pady 2 -cspan 3 \ |
---|
| 1906 | 2,0 $inner.wireframe -anchor w -pady 2 -cspan 3 \ |
---|
| 1907 | 3,0 $inner.edges -anchor w -pady 2 -cspan 3 \ |
---|
| 1908 | 4,0 $inner.preinterp -anchor w -pady 2 -cspan 3 \ |
---|
| 1909 | 5,0 $inner.opacity_l -anchor w -pady 2 -cspan 1 \ |
---|
| 1910 | 5,1 $inner.opacity -fill x -pady 2 -cspan 3 \ |
---|
| 1911 | 6,0 $inner.xbutton -anchor w -padx 2 -pady 2 \ |
---|
| 1912 | 7,0 $inner.ybutton -anchor w -padx 2 -pady 2 \ |
---|
| 1913 | 8,0 $inner.zbutton -anchor w -padx 2 -pady 2 \ |
---|
| 1914 | 6,1 $inner.xval -fill y -rspan 4 \ |
---|
| 1915 | 6,2 $inner.yval -fill y -rspan 4 \ |
---|
| 1916 | 6,3 $inner.zval -fill y -rspan 4 \ |
---|
| 1917 | |
---|
| 1918 | |
---|
| 1919 | blt::table configure $inner r* c* -resize none |
---|
| 1920 | blt::table configure $inner r9 c4 -resize expand |
---|
| 1921 | } |
---|
| 1922 | |
---|
| 1923 | |
---|
| 1924 | |
---|
| 1925 | # |
---|
| 1926 | # camera -- |
---|
| 1927 | # |
---|
| 1928 | itcl::body Rappture::VtkGlyphViewer::camera {option args} { |
---|
| 1929 | switch -- $option { |
---|
| 1930 | "show" { |
---|
| 1931 | puts [array get _view] |
---|
| 1932 | } |
---|
| 1933 | "set" { |
---|
| 1934 | set who [lindex $args 0] |
---|
| 1935 | set x $_view($who) |
---|
| 1936 | set code [catch { string is double $x } result] |
---|
| 1937 | if { $code != 0 || !$result } { |
---|
| 1938 | return |
---|
| 1939 | } |
---|
| 1940 | switch -- $who { |
---|
| 1941 | "ortho" { |
---|
| 1942 | if {$_view(ortho)} { |
---|
| 1943 | SendCmd "camera mode ortho" |
---|
| 1944 | } else { |
---|
| 1945 | SendCmd "camera mode persp" |
---|
| 1946 | } |
---|
| 1947 | } |
---|
| 1948 | "xpan" - "ypan" { |
---|
| 1949 | PanCamera |
---|
| 1950 | } |
---|
| 1951 | "qx" - "qy" - "qz" - "qw" { |
---|
| 1952 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
| 1953 | $_arcball quaternion $q |
---|
| 1954 | EventuallyRotate $q |
---|
| 1955 | } |
---|
| 1956 | "zoom" { |
---|
| 1957 | SendCmd "camera zoom $_view(zoom)" |
---|
| 1958 | } |
---|
| 1959 | } |
---|
| 1960 | } |
---|
| 1961 | } |
---|
| 1962 | } |
---|
| 1963 | |
---|
| 1964 | itcl::body Rappture::VtkGlyphViewer::GetVtkData { args } { |
---|
| 1965 | set bytes "" |
---|
| 1966 | foreach dataobj [get] { |
---|
| 1967 | foreach cname [$dataobj components] { |
---|
| 1968 | set tag $dataobj-$cname |
---|
| 1969 | set contents [$dataobj vtkdata $cname] |
---|
[3739] | 1970 | append bytes "$contents\n" |
---|
[3685] | 1971 | } |
---|
| 1972 | } |
---|
| 1973 | return [list .vtk $bytes] |
---|
| 1974 | } |
---|
| 1975 | |
---|
| 1976 | itcl::body Rappture::VtkGlyphViewer::GetImage { args } { |
---|
| 1977 | if { [image width $_image(download)] > 0 && |
---|
| 1978 | [image height $_image(download)] > 0 } { |
---|
| 1979 | set bytes [$_image(download) data -format "jpeg -quality 100"] |
---|
| 1980 | set bytes [Rappture::encoding::decode -as b64 $bytes] |
---|
| 1981 | return [list .jpg $bytes] |
---|
| 1982 | } |
---|
| 1983 | return "" |
---|
| 1984 | } |
---|
| 1985 | |
---|
| 1986 | itcl::body Rappture::VtkGlyphViewer::BuildDownloadPopup { popup command } { |
---|
| 1987 | Rappture::Balloon $popup \ |
---|
| 1988 | -title "[Rappture::filexfer::label downloadWord] as..." |
---|
| 1989 | set inner [$popup component inner] |
---|
| 1990 | label $inner.summary -text "" -anchor w |
---|
| 1991 | radiobutton $inner.vtk_button -text "VTK data file" \ |
---|
| 1992 | -variable [itcl::scope _downloadPopup(format)] \ |
---|
| 1993 | -font "Arial 9 " \ |
---|
| 1994 | -value vtk |
---|
| 1995 | Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." |
---|
| 1996 | radiobutton $inner.image_button -text "Image File" \ |
---|
| 1997 | -variable [itcl::scope _downloadPopup(format)] \ |
---|
| 1998 | -font "Arial 9 " \ |
---|
| 1999 | -value image |
---|
| 2000 | Rappture::Tooltip::for $inner.image_button \ |
---|
| 2001 | "Save as digital image." |
---|
| 2002 | |
---|
| 2003 | button $inner.ok -text "Save" \ |
---|
| 2004 | -highlightthickness 0 -pady 2 -padx 3 \ |
---|
| 2005 | -command $command \ |
---|
| 2006 | -compound left \ |
---|
| 2007 | -image [Rappture::icon download] |
---|
| 2008 | |
---|
| 2009 | button $inner.cancel -text "Cancel" \ |
---|
| 2010 | -highlightthickness 0 -pady 2 -padx 3 \ |
---|
| 2011 | -command [list $popup deactivate] \ |
---|
| 2012 | -compound left \ |
---|
| 2013 | -image [Rappture::icon cancel] |
---|
| 2014 | |
---|
| 2015 | blt::table $inner \ |
---|
| 2016 | 0,0 $inner.summary -cspan 2 \ |
---|
| 2017 | 1,0 $inner.vtk_button -anchor w -cspan 2 -padx { 4 0 } \ |
---|
| 2018 | 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ |
---|
| 2019 | 4,1 $inner.cancel -width .9i -fill y \ |
---|
| 2020 | 4,0 $inner.ok -padx 2 -width .9i -fill y |
---|
| 2021 | blt::table configure $inner r3 -height 4 |
---|
| 2022 | blt::table configure $inner r4 -pady 4 |
---|
| 2023 | raise $inner.image_button |
---|
| 2024 | $inner.vtk_button invoke |
---|
| 2025 | return $inner |
---|
| 2026 | } |
---|
| 2027 | |
---|
| 2028 | itcl::body Rappture::VtkGlyphViewer::SetObjectStyle { dataobj comp } { |
---|
| 2029 | # Parse style string. |
---|
| 2030 | set tag $dataobj-$comp |
---|
| 2031 | array set style { |
---|
| 2032 | -color BCGYR |
---|
[4187] | 2033 | -edgecolor black |
---|
[3685] | 2034 | -edges 0 |
---|
[4187] | 2035 | -gscale 1 |
---|
| 2036 | -lighting 1 |
---|
[3685] | 2037 | -linewidth 1.0 |
---|
[4187] | 2038 | -normscale 1 |
---|
[3694] | 2039 | -opacity 1.0 |
---|
[4187] | 2040 | -orientGlyphs 1 |
---|
| 2041 | -outline 0 |
---|
| 2042 | -ptsize 1.0 |
---|
| 2043 | -quality 1 |
---|
| 2044 | -scaleMode "vmag" |
---|
| 2045 | -shape "arrow" |
---|
[3685] | 2046 | -wireframe 0 |
---|
| 2047 | } |
---|
[4187] | 2048 | set numComponents [$dataobj numComponents $comp] |
---|
| 2049 | if {$numComponents == 3} { |
---|
| 2050 | set style(-shape) "arrow" |
---|
| 2051 | set style(-orientGlyphs) 1 |
---|
| 2052 | set style(-scaleMode) "vmag" |
---|
| 2053 | } else { |
---|
| 2054 | set style(-shape) "sphere" |
---|
| 2055 | set style(-orientGlyphs) 0 |
---|
| 2056 | set style(-scaleMode) "scalar" |
---|
| 2057 | } |
---|
[3685] | 2058 | array set style [$dataobj style $comp] |
---|
| 2059 | if { $dataobj != $_first } { |
---|
| 2060 | set style(-opacity) 1 |
---|
| 2061 | } |
---|
| 2062 | if 0 { |
---|
| 2063 | SendCmd "cutplane add $tag" |
---|
[4187] | 2064 | SendCmd "cutplane visible 0 $tag" |
---|
[3685] | 2065 | } |
---|
| 2066 | # This is too complicated. We want to set the colormap, number of |
---|
| 2067 | # glyph and opacity for the dataset. They can be the default values, |
---|
| 2068 | # the style hints loaded with the dataset, or set by user controls. As |
---|
| 2069 | # datasets get loaded, they first use the defaults that are overidden |
---|
| 2070 | # by the style hints. If the user changes the global controls, then that |
---|
| 2071 | # overrides everything else. I don't know what it means when global |
---|
| 2072 | # controls are specified as style hints by each dataset. It complicates |
---|
| 2073 | # the code to handle aberrant cases. |
---|
| 2074 | |
---|
| 2075 | if { $_changed(glyphOpacity) } { |
---|
[4431] | 2076 | set style(-opacity) [expr $_settings(glyphOpacity) * 0.01] |
---|
[3685] | 2077 | } |
---|
| 2078 | if { $_changed(colormap) } { |
---|
| 2079 | set style(-color) $_settings(colormap) |
---|
| 2080 | } |
---|
| 2081 | if { $_currentColormap == "" } { |
---|
| 2082 | $itk_component(colormap) value $style(-color) |
---|
| 2083 | } |
---|
[4187] | 2084 | SendCmd "glyphs add $style(-shape) $tag" |
---|
[3685] | 2085 | SendCmd "glyphs edges $style(-edges) $tag" |
---|
[3739] | 2086 | # normscale=1 and gscale=1 are defaults |
---|
[4187] | 2087 | if {$style(-normscale) != 1} { |
---|
| 2088 | SendCmd "glyphs normscale $style(-normscale) $tag" |
---|
| 2089 | } |
---|
| 2090 | if {$style(-gscale) != 1} { |
---|
| 2091 | SendCmd "glyphs gscale $style(-gscale) $tag" |
---|
| 2092 | } |
---|
[3685] | 2093 | SendCmd "outline add $tag" |
---|
| 2094 | SendCmd "outline color [Color2RGB $itk_option(-plotforeground)] $tag" |
---|
| 2095 | SendCmd "outline visible $style(-outline) $tag" |
---|
| 2096 | set _settings(glyphOutline) $style(-outline) |
---|
| 2097 | set _settings(glyphEdges) $style(-edges) |
---|
[4187] | 2098 | # constant color only used if colormode set to constant |
---|
| 2099 | SendCmd "glyphs color [Color2RGB $itk_option(-plotforeground)] $tag" |
---|
| 2100 | # Omitting field name for gorient and smode commands |
---|
| 2101 | # defaults to active scalars or vectors depending on mode |
---|
| 2102 | SendCmd "glyphs gorient $style(-orientGlyphs) {} $tag" |
---|
| 2103 | SendCmd "glyphs smode $style(-scaleMode) {} $tag" |
---|
| 2104 | SendCmd "glyphs quality $style(-quality) $tag" |
---|
[3685] | 2105 | SendCmd "glyphs lighting $style(-lighting) $tag" |
---|
| 2106 | set _settings(glyphLighting) $style(-lighting) |
---|
| 2107 | SendCmd "glyphs linecolor [Color2RGB $style(-edgecolor)] $tag" |
---|
| 2108 | SendCmd "glyphs linewidth $style(-linewidth) $tag" |
---|
[4187] | 2109 | SendCmd "glyphs ptsize $style(-ptsize) $tag" |
---|
[4431] | 2110 | SendCmd "glyphs opacity $style(-opacity) $tag" |
---|
| 2111 | set _settings(glyphOpacity) [expr $style(-opacity) * 100.0] |
---|
[3685] | 2112 | SetCurrentColormap $style(-color) |
---|
| 2113 | SendCmd "glyphs wireframe $style(-wireframe) $tag" |
---|
| 2114 | set _settings(glyphWireframe) $style(-wireframe) |
---|
| 2115 | } |
---|
| 2116 | |
---|
| 2117 | itcl::body Rappture::VtkGlyphViewer::IsValidObject { dataobj } { |
---|
| 2118 | if {[catch {$dataobj isa Rappture::Field} valid] != 0 || !$valid} { |
---|
| 2119 | return 0 |
---|
| 2120 | } |
---|
| 2121 | return 1 |
---|
| 2122 | } |
---|
| 2123 | |
---|
| 2124 | # |
---|
| 2125 | # EnterLegend -- |
---|
| 2126 | # |
---|
| 2127 | itcl::body Rappture::VtkGlyphViewer::EnterLegend { x y } { |
---|
| 2128 | SetLegendTip $x $y |
---|
| 2129 | } |
---|
| 2130 | |
---|
| 2131 | # |
---|
| 2132 | # MotionLegend -- |
---|
| 2133 | # |
---|
| 2134 | itcl::body Rappture::VtkGlyphViewer::MotionLegend { x y } { |
---|
| 2135 | Rappture::Tooltip::tooltip cancel |
---|
| 2136 | set c $itk_component(view) |
---|
| 2137 | set cw [winfo width $c] |
---|
| 2138 | set ch [winfo height $c] |
---|
| 2139 | if { $x >= 0 && $x < $cw && $y >= 0 && $y < $ch } { |
---|
| 2140 | SetLegendTip $x $y |
---|
| 2141 | } |
---|
| 2142 | } |
---|
| 2143 | |
---|
| 2144 | # |
---|
| 2145 | # LeaveLegend -- |
---|
| 2146 | # |
---|
| 2147 | itcl::body Rappture::VtkGlyphViewer::LeaveLegend { } { |
---|
| 2148 | Rappture::Tooltip::tooltip cancel |
---|
| 2149 | .rappturetooltip configure -icon "" |
---|
| 2150 | } |
---|
| 2151 | |
---|
| 2152 | # |
---|
| 2153 | # SetLegendTip -- |
---|
| 2154 | # |
---|
| 2155 | itcl::body Rappture::VtkGlyphViewer::SetLegendTip { x y } { |
---|
| 2156 | set fname $_curFldName |
---|
| 2157 | set c $itk_component(view) |
---|
| 2158 | set w [winfo width $c] |
---|
| 2159 | set h [winfo height $c] |
---|
| 2160 | |
---|
| 2161 | set font "Arial 8" |
---|
| 2162 | set lineht [font metrics $font -linespace] |
---|
| 2163 | |
---|
| 2164 | set ih [image height $_image(legend)] |
---|
| 2165 | set iy [expr $y - ($lineht + 2)] |
---|
| 2166 | |
---|
| 2167 | if { [string match "component*" $fname] } { |
---|
| 2168 | set title "" |
---|
| 2169 | } else { |
---|
| 2170 | if { [info exists _fields($fname)] } { |
---|
| 2171 | foreach { title units } $_fields($fname) break |
---|
| 2172 | if { $units != "" } { |
---|
| 2173 | set title [format "%s (%s)" $title $units] |
---|
| 2174 | } |
---|
| 2175 | } else { |
---|
| 2176 | set title $fname |
---|
| 2177 | } |
---|
| 2178 | } |
---|
| 2179 | # If there's a legend title, increase the offset by the line height. |
---|
| 2180 | if { $title != "" } { |
---|
| 2181 | incr iy -$lineht |
---|
| 2182 | } |
---|
| 2183 | # Make a swatch of the selected color |
---|
| 2184 | if { [catch { $_image(legend) get 10 $iy } pixel] != 0 } { |
---|
| 2185 | return |
---|
| 2186 | } |
---|
| 2187 | if { ![info exists _image(swatch)] } { |
---|
| 2188 | set _image(swatch) [image create photo -width 24 -height 24] |
---|
| 2189 | } |
---|
| 2190 | set color [eval format "\#%02x%02x%02x" $pixel] |
---|
| 2191 | $_image(swatch) put black -to 0 0 23 23 |
---|
| 2192 | $_image(swatch) put $color -to 1 1 22 22 |
---|
| 2193 | .rappturetooltip configure -icon $_image(swatch) |
---|
| 2194 | |
---|
| 2195 | # Compute the value of the point |
---|
| 2196 | if { [info exists _limits($_curFldName)] } { |
---|
| 2197 | foreach { vmin vmax } $_limits($_curFldName) break |
---|
| 2198 | set t [expr 1.0 - (double($iy) / double($ih-1))] |
---|
| 2199 | set value [expr $t * ($vmax - $vmin) + $vmin] |
---|
| 2200 | } else { |
---|
| 2201 | set value 0.0 |
---|
| 2202 | } |
---|
| 2203 | set tx [expr $x + 15] |
---|
| 2204 | set ty [expr $y - 5] |
---|
[3780] | 2205 | Rappture::Tooltip::text $c [format "$title %g" $value] |
---|
[3685] | 2206 | Rappture::Tooltip::tooltip show $c +$tx,+$ty |
---|
| 2207 | } |
---|
| 2208 | |
---|
| 2209 | |
---|
| 2210 | # ---------------------------------------------------------------------- |
---|
| 2211 | # USAGE: Slice move x|y|z <newval> |
---|
| 2212 | # |
---|
| 2213 | # Called automatically when the user drags the slider to move the |
---|
| 2214 | # cut plane that slices 3D data. Gets the current value from the |
---|
| 2215 | # slider and moves the cut plane to the appropriate point in the |
---|
| 2216 | # data set. |
---|
| 2217 | # ---------------------------------------------------------------------- |
---|
| 2218 | itcl::body Rappture::VtkGlyphViewer::Slice {option args} { |
---|
| 2219 | switch -- $option { |
---|
| 2220 | "move" { |
---|
| 2221 | set axis [lindex $args 0] |
---|
| 2222 | set newval [lindex $args 1] |
---|
| 2223 | if {[llength $args] != 2} { |
---|
| 2224 | error "wrong # args: should be \"Slice move x|y|z newval\"" |
---|
| 2225 | } |
---|
| 2226 | set newpos [expr {0.01*$newval}] |
---|
| 2227 | SendCmd "cutplane slice $axis $newpos" |
---|
| 2228 | } |
---|
| 2229 | "tooltip" { |
---|
| 2230 | set axis [lindex $args 0] |
---|
| 2231 | set val [$itk_component(${axis}position) get] |
---|
| 2232 | return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val%" |
---|
| 2233 | } |
---|
| 2234 | default { |
---|
| 2235 | error "bad option \"$option\": should be axis, move, or tooltip" |
---|
| 2236 | } |
---|
| 2237 | } |
---|
| 2238 | } |
---|
| 2239 | |
---|
| 2240 | # |
---|
| 2241 | # ReceiveLegend -- |
---|
| 2242 | # |
---|
| 2243 | # Invoked automatically whenever the "legend" command comes in from |
---|
| 2244 | # the rendering server. Indicates that binary image data with the |
---|
| 2245 | # specified <size> will follow. |
---|
| 2246 | # |
---|
| 2247 | itcl::body Rappture::VtkGlyphViewer::ReceiveLegend { colormap title min max size } { |
---|
| 2248 | #puts stderr "ReceiveLegend colormap=$colormap title=$title range=$min,$max size=$size" |
---|
| 2249 | set _title $title |
---|
| 2250 | regsub {\(mag\)} $title "" _title |
---|
| 2251 | if { [IsConnected] } { |
---|
| 2252 | set bytes [ReceiveBytes $size] |
---|
| 2253 | if { ![info exists _image(legend)] } { |
---|
| 2254 | set _image(legend) [image create photo] |
---|
| 2255 | } |
---|
| 2256 | $_image(legend) configure -data $bytes |
---|
| 2257 | #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" |
---|
| 2258 | if { [catch {DrawLegend} errs] != 0 } { |
---|
| 2259 | global errorInfo |
---|
| 2260 | puts stderr "errs=$errs errorInfo=$errorInfo" |
---|
| 2261 | } |
---|
| 2262 | } |
---|
| 2263 | } |
---|
| 2264 | |
---|
| 2265 | # |
---|
| 2266 | # DrawLegend -- |
---|
| 2267 | # |
---|
| 2268 | # Draws the legend in the own canvas on the right side of the plot area. |
---|
| 2269 | # |
---|
| 2270 | itcl::body Rappture::VtkGlyphViewer::DrawLegend {} { |
---|
| 2271 | set fname $_curFldName |
---|
| 2272 | set c $itk_component(view) |
---|
| 2273 | set w [winfo width $c] |
---|
| 2274 | set h [winfo height $c] |
---|
| 2275 | set font "Arial 8" |
---|
| 2276 | set lineht [font metrics $font -linespace] |
---|
| 2277 | |
---|
| 2278 | if { [string match "component*" $fname] } { |
---|
| 2279 | set title "" |
---|
| 2280 | } else { |
---|
| 2281 | if { [info exists _fields($fname)] } { |
---|
| 2282 | foreach { title units } $_fields($fname) break |
---|
| 2283 | if { $units != "" } { |
---|
| 2284 | set title [format "%s (%s)" $title $units] |
---|
| 2285 | } |
---|
| 2286 | } else { |
---|
| 2287 | set title $fname |
---|
| 2288 | } |
---|
| 2289 | } |
---|
| 2290 | set x [expr $w - 2] |
---|
| 2291 | if { !$_settings(legendVisible) } { |
---|
| 2292 | $c delete legend |
---|
| 2293 | return |
---|
| 2294 | } |
---|
| 2295 | if { [$c find withtag "legend"] == "" } { |
---|
| 2296 | set y 2 |
---|
| 2297 | # If there's a legend title, create a text item for the title. |
---|
| 2298 | $c create text $x $y \ |
---|
[4481] | 2299 | -anchor ne \ |
---|
| 2300 | -fill $itk_option(-plotforeground) -tags "title legend" \ |
---|
| 2301 | -font $font |
---|
| 2302 | if { $title != "" } { |
---|
| 2303 | incr y $lineht |
---|
| 2304 | } |
---|
[3685] | 2305 | $c create text $x $y \ |
---|
[4481] | 2306 | -anchor ne \ |
---|
| 2307 | -fill $itk_option(-plotforeground) -tags "vmax legend" \ |
---|
| 2308 | -font $font |
---|
[3685] | 2309 | incr y $lineht |
---|
| 2310 | $c create image $x $y \ |
---|
[4481] | 2311 | -anchor ne \ |
---|
| 2312 | -image $_image(legend) -tags "colormap legend" |
---|
[3685] | 2313 | $c create rectangle $x $y 1 1 \ |
---|
[4481] | 2314 | -fill "" -outline "" -tags "sensor legend" |
---|
[3685] | 2315 | $c create text $x [expr {$h-2}] \ |
---|
[4481] | 2316 | -anchor se \ |
---|
| 2317 | -fill $itk_option(-plotforeground) -tags "vmin legend" \ |
---|
| 2318 | -font $font |
---|
[3685] | 2319 | $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y] |
---|
| 2320 | $c bind sensor <Leave> [itcl::code $this LeaveLegend] |
---|
| 2321 | $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y] |
---|
| 2322 | } |
---|
| 2323 | set x2 $x |
---|
| 2324 | set iw [image width $_image(legend)] |
---|
| 2325 | set ih [image height $_image(legend)] |
---|
| 2326 | set x1 [expr $x2 - ($iw*12)/10] |
---|
| 2327 | |
---|
| 2328 | $c bind title <ButtonPress> [itcl::code $this Combo post] |
---|
| 2329 | $c bind title <Enter> [itcl::code $this Combo activate] |
---|
| 2330 | $c bind title <Leave> [itcl::code $this Combo deactivate] |
---|
| 2331 | # Reset the item coordinates according the current size of the plot. |
---|
| 2332 | $c itemconfigure title -text $title |
---|
| 2333 | if { [info exists _limits($_curFldName)] } { |
---|
| 2334 | foreach { vmin vmax } $_limits($_curFldName) break |
---|
[3780] | 2335 | $c itemconfigure vmin -text [format %g $vmin] |
---|
| 2336 | $c itemconfigure vmax -text [format %g $vmax] |
---|
[3685] | 2337 | } |
---|
| 2338 | set y 2 |
---|
| 2339 | # If there's a legend title, move the title to the correct position |
---|
| 2340 | if { $title != "" } { |
---|
| 2341 | $c itemconfigure title -text $title |
---|
| 2342 | $c coords title $x $y |
---|
| 2343 | incr y $lineht |
---|
| 2344 | $c raise title |
---|
| 2345 | } |
---|
[3780] | 2346 | $c coords vmax $x $y |
---|
[3685] | 2347 | incr y $lineht |
---|
| 2348 | $c coords colormap $x $y |
---|
| 2349 | $c coords sensor [expr $x - $iw] $y $x [expr $y + $ih] |
---|
| 2350 | $c raise sensor |
---|
[3780] | 2351 | $c coords vmin $x [expr {$h - 2}] |
---|
[3685] | 2352 | } |
---|
| 2353 | |
---|
| 2354 | # ---------------------------------------------------------------------- |
---|
| 2355 | # USAGE: _dropdown post |
---|
| 2356 | # USAGE: _dropdown unpost |
---|
| 2357 | # USAGE: _dropdown select |
---|
| 2358 | # |
---|
| 2359 | # Used internally to handle the dropdown list for this combobox. The |
---|
| 2360 | # post/unpost options are invoked when the list is posted or unposted |
---|
| 2361 | # to manage the relief of the controlling button. The select option |
---|
| 2362 | # is invoked whenever there is a selection from the list, to assign |
---|
| 2363 | # the value back to the gauge. |
---|
| 2364 | # ---------------------------------------------------------------------- |
---|
| 2365 | itcl::body Rappture::VtkGlyphViewer::Combo {option} { |
---|
| 2366 | set c $itk_component(view) |
---|
| 2367 | switch -- $option { |
---|
| 2368 | post { |
---|
| 2369 | foreach { x1 y1 x2 y2 } [$c bbox title] break |
---|
| 2370 | set cw [winfo width $itk_component(view)] |
---|
| 2371 | set mw [winfo reqwidth $itk_component(fieldmenu)] |
---|
| 2372 | set x1 [expr $cw - $mw] |
---|
| 2373 | set x [expr $x1 + [winfo rootx $itk_component(view)]] |
---|
| 2374 | set y [expr $y2 + [winfo rooty $itk_component(view)]] |
---|
| 2375 | tk_popup $itk_component(fieldmenu) $x $y |
---|
| 2376 | } |
---|
| 2377 | activate { |
---|
| 2378 | $c itemconfigure title -fill red |
---|
| 2379 | } |
---|
| 2380 | deactivate { |
---|
| 2381 | $c itemconfigure title -fill $itk_option(-plotforeground) |
---|
| 2382 | } |
---|
| 2383 | invoke { |
---|
| 2384 | $itk_component(field) value $_curFldLabel |
---|
| 2385 | AdjustSetting field |
---|
| 2386 | } |
---|
| 2387 | default { |
---|
| 2388 | error "bad option \"$option\": should be post, unpost, select" |
---|
| 2389 | } |
---|
| 2390 | } |
---|
| 2391 | } |
---|
| 2392 | |
---|
| 2393 | # |
---|
| 2394 | # SetCurrentColormap -- |
---|
| 2395 | # |
---|
| 2396 | itcl::body Rappture::VtkGlyphViewer::SetCurrentColormap { name } { |
---|
| 2397 | # Keep track of the colormaps that we build. |
---|
| 2398 | if { ![info exists _colormaps($name)] } { |
---|
| 2399 | BuildColormap $name |
---|
| 2400 | set _colormaps($name) 1 |
---|
| 2401 | } |
---|
| 2402 | set _currentColormap $name |
---|
| 2403 | SendCmd "glyphs colormap $_currentColormap" |
---|
| 2404 | } |
---|
| 2405 | |
---|
| 2406 | # |
---|
| 2407 | # BuildColormap -- |
---|
| 2408 | # |
---|
| 2409 | # Build the designated colormap on the server. |
---|
| 2410 | # |
---|
| 2411 | itcl::body Rappture::VtkGlyphViewer::BuildColormap { name } { |
---|
| 2412 | set cmap [ColorsToColormap $name] |
---|
| 2413 | if { [llength $cmap] == 0 } { |
---|
| 2414 | set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0" |
---|
| 2415 | } |
---|
| 2416 | set wmap "0.0 1.0 1.0 1.0" |
---|
| 2417 | SendCmd "colormap add $name { $cmap } { $wmap }" |
---|
| 2418 | } |
---|
| 2419 | |
---|
| 2420 | itcl::body Rappture::VtkGlyphViewer::SetOrientation { side } { |
---|
| 2421 | array set positions { |
---|
| 2422 | front "1 0 0 0" |
---|
| 2423 | back "0 0 1 0" |
---|
| 2424 | left "0.707107 0 -0.707107 0" |
---|
| 2425 | right "0.707107 0 0.707107 0" |
---|
| 2426 | top "0.707107 -0.707107 0 0" |
---|
| 2427 | bottom "0.707107 0.707107 0 0" |
---|
| 2428 | } |
---|
| 2429 | foreach name { qw qx qy qz } value $positions($side) { |
---|
| 2430 | set _view($name) $value |
---|
| 2431 | } |
---|
| 2432 | set q [list $_view(qw) $_view(qx) $_view(qy) $_view(qz)] |
---|
| 2433 | $_arcball quaternion $q |
---|
| 2434 | SendCmd "camera orient $q" |
---|
| 2435 | SendCmd "camera reset" |
---|
| 2436 | set _view(xpan) 0 |
---|
| 2437 | set _view(ypan) 0 |
---|
| 2438 | set _view(zoom) 1.0 |
---|
| 2439 | } |
---|
| 2440 | |
---|