[5007] | 1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
[1920] | 2 | # ---------------------------------------------------------------------- |
---|
[2385] | 3 | # COMPONENT: vtkviewer - Vtk drawing object viewer |
---|
[1920] | 4 | # |
---|
[2385] | 5 | # It connects to the Vtk server running on a rendering farm, |
---|
| 6 | # transmits data, and displays the results. |
---|
[1920] | 7 | # ====================================================================== |
---|
| 8 | # AUTHOR: Michael McLennan, Purdue University |
---|
[4464] | 9 | # Copyright (c) 2004-2014 HUBzero Foundation, LLC |
---|
[1920] | 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 |
---|
[2397] | 17 | |
---|
[1920] | 18 | option add *VtkViewer.width 4i widgetDefault |
---|
[2385] | 19 | option add *VtkViewer*cursor crosshair widgetDefault |
---|
[1920] | 20 | option add *VtkViewer.height 4i widgetDefault |
---|
| 21 | option add *VtkViewer.foreground black widgetDefault |
---|
| 22 | option add *VtkViewer.controlBackground gray widgetDefault |
---|
| 23 | option add *VtkViewer.controlDarkBackground #999999 widgetDefault |
---|
| 24 | option add *VtkViewer.plotBackground black widgetDefault |
---|
| 25 | option add *VtkViewer.plotForeground white widgetDefault |
---|
| 26 | option add *VtkViewer.font \ |
---|
| 27 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
| 28 | |
---|
[2385] | 29 | # must use this name -- plugs into Rappture::resources::load |
---|
| 30 | proc VtkViewer_init_resources {} { |
---|
| 31 | Rappture::resources::register \ |
---|
| 32 | vtkvis_server Rappture::VtkViewer::SetServerList |
---|
| 33 | } |
---|
| 34 | |
---|
[1920] | 35 | itcl::class Rappture::VtkViewer { |
---|
[2385] | 36 | inherit Rappture::VisViewer |
---|
[1920] | 37 | |
---|
| 38 | itk_option define -plotforeground plotForeground Foreground "" |
---|
| 39 | itk_option define -plotbackground plotBackground Background "" |
---|
| 40 | |
---|
[2385] | 41 | constructor { hostlist args } { |
---|
| 42 | Rappture::VisViewer::constructor $hostlist |
---|
| 43 | } { |
---|
| 44 | # defined below |
---|
[1920] | 45 | } |
---|
[2385] | 46 | destructor { |
---|
| 47 | # defined below |
---|
[1920] | 48 | } |
---|
[2385] | 49 | public proc SetServerList { namelist } { |
---|
| 50 | Rappture::VisViewer::SetServerList "vtkvis" $namelist |
---|
| 51 | } |
---|
[1920] | 52 | public method add {dataobj {settings ""}} |
---|
[2385] | 53 | public method camera {option args} |
---|
[1920] | 54 | public method delete {args} |
---|
[2385] | 55 | public method disconnect {} |
---|
| 56 | public method download {option args} |
---|
| 57 | public method get {args} |
---|
| 58 | public method isconnected {} |
---|
[4706] | 59 | public method limits { dataobj } |
---|
[5007] | 60 | public method parameters {title args} { |
---|
| 61 | # do nothing |
---|
[1920] | 62 | } |
---|
[2385] | 63 | public method scale {args} |
---|
[1920] | 64 | |
---|
[2385] | 65 | # The following methods are only used by this class. |
---|
[4766] | 66 | private method AdjustSetting {what {value ""}} |
---|
[2466] | 67 | private method BuildAxisTab {} |
---|
[1920] | 68 | private method BuildCameraTab {} |
---|
[3093] | 69 | private method BuildColormap { name styles } |
---|
[2504] | 70 | private method BuildCutawayTab {} |
---|
[5007] | 71 | private method BuildDownloadPopup { widget command } |
---|
[4464] | 72 | private method BuildGlyphsTab {} |
---|
[3121] | 73 | private method BuildMoleculeTab {} |
---|
[3785] | 74 | private method BuildPolydataTab {} |
---|
| 75 | private method ChangeColormap { dataobj comp color } |
---|
[4766] | 76 | private method Connect {} |
---|
| 77 | private method CurrentDatasets {args} |
---|
| 78 | private method Disconnect {} |
---|
| 79 | private method DoResize {} |
---|
| 80 | private method DoRotate {} |
---|
[2466] | 81 | private method DrawLegend {} |
---|
[5007] | 82 | private method EnterLegend { x y } |
---|
| 83 | private method EventuallyResize { w h } |
---|
| 84 | private method EventuallyRotate { q } |
---|
| 85 | private method EventuallySetAtomScale { args } |
---|
| 86 | private method EventuallySetBondScale { args } |
---|
| 87 | private method EventuallySetGlyphsOpacity { args } |
---|
| 88 | private method EventuallySetMoleculeOpacity { args } |
---|
| 89 | private method EventuallySetMoleculeQuality { args } |
---|
| 90 | private method EventuallySetPolydataOpacity { args } |
---|
| 91 | private method GetImage { args } |
---|
| 92 | private method GetVtkData { args } |
---|
[4766] | 93 | private method InitSettings { args } |
---|
[5007] | 94 | private method IsValidObject { dataobj } |
---|
[2504] | 95 | private method LeaveLegend {} |
---|
[5007] | 96 | private method MotionLegend { x y } |
---|
[4766] | 97 | private method Pan {option x y} |
---|
[2466] | 98 | private method PanCamera {} |
---|
[4766] | 99 | private method Pick {x y} |
---|
[5007] | 100 | private method QuaternionToView { q } { |
---|
[4766] | 101 | foreach { _view(-qw) _view(-qx) _view(-qy) _view(-qz) } $q break |
---|
| 102 | } |
---|
| 103 | private method Rebuild {} |
---|
| 104 | private method ReceiveDataset { args } |
---|
| 105 | private method ReceiveImage { args } |
---|
| 106 | private method ReceiveLegend { colormap title vmin vmax size } |
---|
[2504] | 107 | private method RequestLegend {} |
---|
[4766] | 108 | private method Rotate {option x y} |
---|
[3785] | 109 | private method SetAtomScale {} |
---|
| 110 | private method SetBondScale {} |
---|
[2489] | 111 | private method SetColormap { dataobj comp } |
---|
[4478] | 112 | private method SetGlyphsOpacity {} |
---|
[2476] | 113 | private method SetLegendTip { x y } |
---|
[3785] | 114 | private method SetMoleculeOpacity {} |
---|
[3800] | 115 | private method SetMoleculeQuality {} |
---|
[5007] | 116 | private method SetObjectStyle { dataobj comp } |
---|
[3785] | 117 | private method SetOpacity { dataset } |
---|
| 118 | private method SetOrientation { side } |
---|
| 119 | private method SetPolydataOpacity {} |
---|
[5007] | 120 | private method Slice {option args} |
---|
| 121 | private method ViewToQuaternion {} { |
---|
[4766] | 122 | return [list $_view(-qw) $_view(-qx) $_view(-qy) $_view(-qz)] |
---|
| 123 | } |
---|
| 124 | private method Zoom {option} |
---|
[1920] | 125 | |
---|
[2385] | 126 | private variable _arcball "" |
---|
[5007] | 127 | private variable _dlist ""; # list of data objects |
---|
| 128 | private variable _obj2ovride; # maps dataobj => style override |
---|
| 129 | private variable _datasets; # contains all the dataobj-component |
---|
| 130 | # datasets in the server |
---|
| 131 | private variable _colormaps; # contains all the colormaps |
---|
| 132 | # in the server. |
---|
| 133 | private variable _dataset2style; # maps dataobj-component to transfunc |
---|
[3523] | 134 | private variable _click; # info used for rotate operations |
---|
| 135 | private variable _limits; # autoscale min/max for all axes |
---|
| 136 | private variable _view; # view params for 3D view |
---|
[2474] | 137 | private variable _settings |
---|
[3093] | 138 | private variable _style; # Array of current component styles. |
---|
| 139 | private variable _initialStyle; # Array of initial component styles. |
---|
[2474] | 140 | private variable _axis |
---|
[5172] | 141 | private variable _reset 1; # Connection to server has been reset. |
---|
[3067] | 142 | private variable _haveGlyphs 0 |
---|
[3081] | 143 | private variable _haveMolecules 0 |
---|
[3785] | 144 | private variable _havePolydata 0 |
---|
[2466] | 145 | |
---|
[5349] | 146 | private variable _first ""; # This is the topmost dataset. |
---|
[2385] | 147 | private variable _start 0 |
---|
[2474] | 148 | private variable _title "" |
---|
| 149 | |
---|
[5349] | 150 | private common _downloadPopup; # download options from popup |
---|
[2385] | 151 | private common _hardcopy |
---|
| 152 | private variable _width 0 |
---|
| 153 | private variable _height 0 |
---|
| 154 | private variable _resizePending 0 |
---|
[2484] | 155 | private variable _rotatePending 0 |
---|
[3785] | 156 | private variable _atomScalePending 0 |
---|
| 157 | private variable _bondScalePending 0 |
---|
| 158 | private variable _moleculeOpacityPending 0 |
---|
[3800] | 159 | private variable _moleculeQualityPending 0 |
---|
[3785] | 160 | private variable _polydataOpacityPending 0 |
---|
| 161 | private variable _glyphsOpacityPending 0 |
---|
| 162 | private variable _rotateDelay 150 |
---|
| 163 | private variable _scaleDelay 100 |
---|
[1920] | 164 | } |
---|
| 165 | |
---|
| 166 | itk::usual VtkViewer { |
---|
| 167 | keep -background -foreground -cursor -font |
---|
| 168 | keep -plotbackground -plotforeground |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | # ---------------------------------------------------------------------- |
---|
| 172 | # CONSTRUCTOR |
---|
| 173 | # ---------------------------------------------------------------------- |
---|
[2385] | 174 | itcl::body Rappture::VtkViewer::constructor {hostlist args} { |
---|
[2792] | 175 | package require vtk |
---|
[2743] | 176 | set _serverType "vtkvis" |
---|
| 177 | |
---|
[2385] | 178 | # Rebuild event |
---|
| 179 | $_dispatcher register !rebuild |
---|
| 180 | $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" |
---|
[2148] | 181 | |
---|
[2385] | 182 | # Resize event |
---|
| 183 | $_dispatcher register !resize |
---|
| 184 | $_dispatcher dispatch $this !resize "[itcl::code $this DoResize]; list" |
---|
| 185 | |
---|
[2484] | 186 | # Rotate event |
---|
| 187 | $_dispatcher register !rotate |
---|
| 188 | $_dispatcher dispatch $this !rotate "[itcl::code $this DoRotate]; list" |
---|
| 189 | |
---|
[3785] | 190 | # Atom scale event |
---|
| 191 | $_dispatcher register !atomscale |
---|
| 192 | $_dispatcher dispatch $this !atomscale \ |
---|
| 193 | "[itcl::code $this SetAtomScale]; list" |
---|
| 194 | |
---|
| 195 | # Bond scale event |
---|
| 196 | $_dispatcher register !bondscale |
---|
| 197 | $_dispatcher dispatch $this !bondscale \ |
---|
| 198 | "[itcl::code $this SetBondScale]; list" |
---|
| 199 | |
---|
| 200 | # Molecule opacity event |
---|
| 201 | $_dispatcher register !moleculeOpacity |
---|
| 202 | $_dispatcher dispatch $this !moleculeOpacity \ |
---|
| 203 | "[itcl::code $this SetMoleculeOpacity]; list" |
---|
| 204 | |
---|
[3800] | 205 | # Molecule quality event |
---|
| 206 | $_dispatcher register !moleculeQuality |
---|
| 207 | $_dispatcher dispatch $this !moleculeQuality \ |
---|
| 208 | "[itcl::code $this SetMoleculeQuality]; list" |
---|
| 209 | |
---|
[3785] | 210 | # Polydata opacity event |
---|
| 211 | $_dispatcher register !polydataOpacity |
---|
| 212 | $_dispatcher dispatch $this !polydataOpacity \ |
---|
| 213 | "[itcl::code $this SetPolydataOpacity]; list" |
---|
[4478] | 214 | |
---|
| 215 | # Glyphs opacity event |
---|
| 216 | $_dispatcher register !glyphsOpacity |
---|
| 217 | $_dispatcher dispatch $this !glyphsOpacity \ |
---|
| 218 | "[itcl::code $this SetGlyphsOpacity]; list" |
---|
| 219 | |
---|
[2385] | 220 | # |
---|
| 221 | # Populate parser with commands handle incoming requests |
---|
| 222 | # |
---|
[4766] | 223 | $_parser alias image [itcl::code $this ReceiveImage] |
---|
| 224 | $_parser alias dataset [itcl::code $this ReceiveDataset] |
---|
| 225 | $_parser alias legend [itcl::code $this ReceiveLegend] |
---|
[2385] | 226 | |
---|
| 227 | # Initialize the view to some default parameters. |
---|
| 228 | array set _view { |
---|
[4766] | 229 | -ortho 0 |
---|
| 230 | -qw 0.853553 |
---|
| 231 | -qx -0.353553 |
---|
| 232 | -qy 0.353553 |
---|
| 233 | -qz 0.146447 |
---|
| 234 | -xpan 0 |
---|
| 235 | -ypan 0 |
---|
| 236 | -zoom 1.0 |
---|
[1920] | 237 | } |
---|
[2385] | 238 | set _arcball [blt::arcball create 100 100] |
---|
[4766] | 239 | $_arcball quaternion [ViewToQuaternion] |
---|
[2385] | 240 | |
---|
[2466] | 241 | set _limits(zmin) 0.0 |
---|
| 242 | set _limits(zmax) 1.0 |
---|
[2385] | 243 | |
---|
[2474] | 244 | array set _axis [subst { |
---|
[4775] | 245 | labels 1 |
---|
| 246 | minorticks 1 |
---|
| 247 | visible 1 |
---|
[2744] | 248 | xgrid 0 |
---|
| 249 | ygrid 0 |
---|
| 250 | zgrid 0 |
---|
| 251 | xcutaway 0 |
---|
| 252 | ycutaway 0 |
---|
| 253 | zcutaway 0 |
---|
| 254 | xposition 0 |
---|
| 255 | yposition 0 |
---|
| 256 | zposition 0 |
---|
| 257 | xdirection -1 |
---|
| 258 | ydirection -1 |
---|
| 259 | zdirection -1 |
---|
[2474] | 260 | }] |
---|
[2385] | 261 | array set _settings [subst { |
---|
[4464] | 262 | glyphs-edges 0 |
---|
| 263 | glyphs-lighting 1 |
---|
[3800] | 264 | glyphs-opacity 100 |
---|
[4464] | 265 | glyphs-outline 0 |
---|
| 266 | glyphs-palette BCGYR |
---|
| 267 | glyphs-visible 1 |
---|
[3800] | 268 | glyphs-wireframe 0 |
---|
[4775] | 269 | legend 1 |
---|
| 270 | molecule-atoms-visible 1 |
---|
[3800] | 271 | molecule-atomscale 0.3 |
---|
[4775] | 272 | molecule-bonds-visible 1 |
---|
[3800] | 273 | molecule-bondscale 0.075 |
---|
[3877] | 274 | molecule-bondstyle "cylinder" |
---|
[3785] | 275 | molecule-edges 0 |
---|
| 276 | molecule-labels 0 |
---|
| 277 | molecule-lighting 1 |
---|
| 278 | molecule-opacity 100 |
---|
[4464] | 279 | molecule-outline 0 |
---|
[3785] | 280 | molecule-palette elementDefault |
---|
[3800] | 281 | molecule-quality 1.0 |
---|
[3785] | 282 | molecule-representation "Ball and Stick" |
---|
[3800] | 283 | molecule-rscale "covalent" |
---|
[3785] | 284 | molecule-visible 1 |
---|
| 285 | molecule-wireframe 0 |
---|
[4775] | 286 | polydata-edges 0 |
---|
| 287 | polydata-lighting 1 |
---|
| 288 | polydata-opacity 100 |
---|
| 289 | polydata-outline 0 |
---|
| 290 | polydata-palette BCGYR |
---|
| 291 | polydata-visible 1 |
---|
| 292 | polydata-wireframe 0 |
---|
[2385] | 293 | }] |
---|
| 294 | itk_component add view { |
---|
| 295 | canvas $itk_component(plotarea).view \ |
---|
| 296 | -highlightthickness 0 -borderwidth 0 |
---|
[1920] | 297 | } { |
---|
[1929] | 298 | usual |
---|
[2385] | 299 | ignore -highlightthickness -borderwidth -background |
---|
[1920] | 300 | } |
---|
| 301 | |
---|
[2385] | 302 | set c $itk_component(view) |
---|
| 303 | bind $c <Configure> [itcl::code $this EventuallyResize %w %h] |
---|
| 304 | bind $c <4> [itcl::code $this Zoom in 0.25] |
---|
| 305 | bind $c <5> [itcl::code $this Zoom out 0.25] |
---|
| 306 | bind $c <KeyPress-Left> [list %W xview scroll 10 units] |
---|
| 307 | bind $c <KeyPress-Right> [list %W xview scroll -10 units] |
---|
| 308 | bind $c <KeyPress-Up> [list %W yview scroll 10 units] |
---|
| 309 | bind $c <KeyPress-Down> [list %W yview scroll -10 units] |
---|
| 310 | bind $c <Enter> "focus %W" |
---|
[3330] | 311 | bind $c <Control-F1> [itcl::code $this ToggleConsole] |
---|
[2385] | 312 | |
---|
| 313 | # Fix the scrollregion in case we go off screen |
---|
| 314 | $c configure -scrollregion [$c bbox all] |
---|
| 315 | |
---|
| 316 | set _map(id) [$c create image 0 0 -anchor nw -image $_image(plot)] |
---|
[5007] | 317 | set _map(cwidth) -1 |
---|
| 318 | set _map(cheight) -1 |
---|
[2385] | 319 | set _map(zoom) 1.0 |
---|
| 320 | set _map(original) "" |
---|
| 321 | |
---|
| 322 | set f [$itk_component(main) component controls] |
---|
[1920] | 323 | itk_component add reset { |
---|
[2385] | 324 | button $f.reset -borderwidth 1 -padx 1 -pady 1 \ |
---|
| 325 | -highlightthickness 0 \ |
---|
| 326 | -image [Rappture::icon reset-view] \ |
---|
[1929] | 327 | -command [itcl::code $this Zoom reset] |
---|
[1920] | 328 | } { |
---|
[1929] | 329 | usual |
---|
[2385] | 330 | ignore -highlightthickness |
---|
[1920] | 331 | } |
---|
[2385] | 332 | pack $itk_component(reset) -side top -padx 2 -pady 2 |
---|
[3093] | 333 | Rappture::Tooltip::for $itk_component(reset) \ |
---|
[3708] | 334 | "Reset the view to the default zoom level" |
---|
[1920] | 335 | |
---|
| 336 | itk_component add zoomin { |
---|
[2385] | 337 | button $f.zin -borderwidth 1 -padx 1 -pady 1 \ |
---|
| 338 | -highlightthickness 0 \ |
---|
| 339 | -image [Rappture::icon zoom-in] \ |
---|
[1929] | 340 | -command [itcl::code $this Zoom in] |
---|
[1920] | 341 | } { |
---|
[1929] | 342 | usual |
---|
[2385] | 343 | ignore -highlightthickness |
---|
[1920] | 344 | } |
---|
[2385] | 345 | pack $itk_component(zoomin) -side top -padx 2 -pady 2 |
---|
[1920] | 346 | Rappture::Tooltip::for $itk_component(zoomin) "Zoom in" |
---|
[2385] | 347 | |
---|
[1920] | 348 | itk_component add zoomout { |
---|
[2385] | 349 | button $f.zout -borderwidth 1 -padx 1 -pady 1 \ |
---|
| 350 | -highlightthickness 0 \ |
---|
| 351 | -image [Rappture::icon zoom-out] \ |
---|
[1929] | 352 | -command [itcl::code $this Zoom out] |
---|
[1920] | 353 | } { |
---|
[1929] | 354 | usual |
---|
[2385] | 355 | ignore -highlightthickness |
---|
[1920] | 356 | } |
---|
[2385] | 357 | pack $itk_component(zoomout) -side top -padx 2 -pady 2 |
---|
[1920] | 358 | Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" |
---|
[2385] | 359 | |
---|
[4766] | 360 | if { [catch { |
---|
| 361 | BuildAxisTab |
---|
| 362 | #BuildCutawayTab |
---|
| 363 | BuildCameraTab |
---|
| 364 | } errs] != 0 } { |
---|
| 365 | puts stderr errs=$errs |
---|
| 366 | } |
---|
[3067] | 367 | |
---|
[2466] | 368 | # Legend |
---|
| 369 | set _image(legend) [image create photo] |
---|
| 370 | itk_component add legend { |
---|
[5007] | 371 | canvas $itk_component(plotarea).legend -width 50 -highlightthickness 0 |
---|
[2466] | 372 | } { |
---|
| 373 | usual |
---|
| 374 | ignore -highlightthickness |
---|
| 375 | rename -background -plotbackground plotBackground Background |
---|
[2464] | 376 | } |
---|
[2385] | 377 | |
---|
[5007] | 378 | # Hack around the Tk panewindow. The problem is that the requested |
---|
[2385] | 379 | # size of the 3d view isn't set until an image is retrieved from |
---|
| 380 | # the server. So the panewindow uses the tiny size. |
---|
| 381 | set w 10000 |
---|
| 382 | pack forget $itk_component(view) |
---|
| 383 | blt::table $itk_component(plotarea) \ |
---|
[5007] | 384 | 0,0 $itk_component(view) -fill both -reqwidth $w |
---|
[2385] | 385 | blt::table configure $itk_component(plotarea) c1 -resize none |
---|
| 386 | |
---|
| 387 | # Bindings for rotation via mouse |
---|
| 388 | bind $itk_component(view) <ButtonPress-1> \ |
---|
| 389 | [itcl::code $this Rotate click %x %y] |
---|
| 390 | bind $itk_component(view) <B1-Motion> \ |
---|
| 391 | [itcl::code $this Rotate drag %x %y] |
---|
| 392 | bind $itk_component(view) <ButtonRelease-1> \ |
---|
| 393 | [itcl::code $this Rotate release %x %y] |
---|
| 394 | |
---|
| 395 | # Bindings for panning via mouse |
---|
| 396 | bind $itk_component(view) <ButtonPress-2> \ |
---|
| 397 | [itcl::code $this Pan click %x %y] |
---|
| 398 | bind $itk_component(view) <B2-Motion> \ |
---|
| 399 | [itcl::code $this Pan drag %x %y] |
---|
| 400 | bind $itk_component(view) <ButtonRelease-2> \ |
---|
| 401 | [itcl::code $this Pan release %x %y] |
---|
| 402 | |
---|
[3443] | 403 | #bind $itk_component(view) <ButtonRelease-3> \ |
---|
| 404 | # [itcl::code $this Pick %x %y] |
---|
[2426] | 405 | |
---|
[2385] | 406 | # Bindings for panning via keyboard |
---|
| 407 | bind $itk_component(view) <KeyPress-Left> \ |
---|
| 408 | [itcl::code $this Pan set -10 0] |
---|
| 409 | bind $itk_component(view) <KeyPress-Right> \ |
---|
| 410 | [itcl::code $this Pan set 10 0] |
---|
| 411 | bind $itk_component(view) <KeyPress-Up> \ |
---|
| 412 | [itcl::code $this Pan set 0 -10] |
---|
| 413 | bind $itk_component(view) <KeyPress-Down> \ |
---|
| 414 | [itcl::code $this Pan set 0 10] |
---|
| 415 | bind $itk_component(view) <Shift-KeyPress-Left> \ |
---|
| 416 | [itcl::code $this Pan set -2 0] |
---|
| 417 | bind $itk_component(view) <Shift-KeyPress-Right> \ |
---|
| 418 | [itcl::code $this Pan set 2 0] |
---|
| 419 | bind $itk_component(view) <Shift-KeyPress-Up> \ |
---|
| 420 | [itcl::code $this Pan set 0 -2] |
---|
| 421 | bind $itk_component(view) <Shift-KeyPress-Down> \ |
---|
| 422 | [itcl::code $this Pan set 0 2] |
---|
| 423 | |
---|
| 424 | # Bindings for zoom via keyboard |
---|
| 425 | bind $itk_component(view) <KeyPress-Prior> \ |
---|
| 426 | [itcl::code $this Zoom out] |
---|
| 427 | bind $itk_component(view) <KeyPress-Next> \ |
---|
| 428 | [itcl::code $this Zoom in] |
---|
| 429 | |
---|
| 430 | bind $itk_component(view) <Enter> "focus $itk_component(view)" |
---|
| 431 | |
---|
| 432 | if {[string equal "x11" [tk windowingsystem]]} { |
---|
| 433 | # Bindings for zoom via mouse |
---|
| 434 | bind $itk_component(view) <4> [itcl::code $this Zoom out] |
---|
| 435 | bind $itk_component(view) <5> [itcl::code $this Zoom in] |
---|
[1920] | 436 | } |
---|
[2385] | 437 | |
---|
| 438 | set _image(download) [image create photo] |
---|
| 439 | |
---|
[1920] | 440 | eval itk_initialize $args |
---|
[5095] | 441 | |
---|
| 442 | EnableWaitDialog 900 |
---|
[2385] | 443 | Connect |
---|
[1920] | 444 | } |
---|
| 445 | |
---|
| 446 | # ---------------------------------------------------------------------- |
---|
| 447 | # DESTRUCTOR |
---|
| 448 | # ---------------------------------------------------------------------- |
---|
| 449 | itcl::body Rappture::VtkViewer::destructor {} { |
---|
[2385] | 450 | Disconnect |
---|
| 451 | $_dispatcher cancel !rebuild |
---|
| 452 | $_dispatcher cancel !resize |
---|
[2484] | 453 | $_dispatcher cancel !rotate |
---|
[2385] | 454 | image delete $_image(plot) |
---|
| 455 | image delete $_image(download) |
---|
[2466] | 456 | catch { blt::arcball destroy $_arcball } |
---|
[2385] | 457 | } |
---|
| 458 | |
---|
| 459 | itcl::body Rappture::VtkViewer::DoResize {} { |
---|
| 460 | if { $_width < 2 } { |
---|
[2744] | 461 | set _width 500 |
---|
[1920] | 462 | } |
---|
[2385] | 463 | if { $_height < 2 } { |
---|
[2744] | 464 | set _height 500 |
---|
[2385] | 465 | } |
---|
| 466 | set _start [clock clicks -milliseconds] |
---|
| 467 | SendCmd "screen size $_width $_height" |
---|
[3438] | 468 | |
---|
[2385] | 469 | set _resizePending 0 |
---|
[1920] | 470 | } |
---|
| 471 | |
---|
[2484] | 472 | itcl::body Rappture::VtkViewer::DoRotate {} { |
---|
[5007] | 473 | SendCmd "camera orient [ViewToQuaternion]" |
---|
[2484] | 474 | set _rotatePending 0 |
---|
| 475 | } |
---|
| 476 | |
---|
[2385] | 477 | itcl::body Rappture::VtkViewer::EventuallyResize { w h } { |
---|
| 478 | set _width $w |
---|
| 479 | set _height $h |
---|
| 480 | $_arcball resize $w $h |
---|
| 481 | if { !$_resizePending } { |
---|
| 482 | set _resizePending 1 |
---|
[2484] | 483 | $_dispatcher event -after 200 !resize |
---|
[2385] | 484 | } |
---|
| 485 | } |
---|
| 486 | |
---|
[2484] | 487 | itcl::body Rappture::VtkViewer::EventuallyRotate { q } { |
---|
[4766] | 488 | QuaternionToView $q |
---|
[2484] | 489 | if { !$_rotatePending } { |
---|
| 490 | set _rotatePending 1 |
---|
[3785] | 491 | $_dispatcher event -after $_rotateDelay !rotate |
---|
[2484] | 492 | } |
---|
| 493 | } |
---|
| 494 | |
---|
[3785] | 495 | itcl::body Rappture::VtkViewer::SetAtomScale {} { |
---|
| 496 | SendCmd "molecule ascale $_settings(molecule-atomscale)" |
---|
| 497 | set _atomScalePending 0 |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | itcl::body Rappture::VtkViewer::SetBondScale {} { |
---|
| 501 | SendCmd "molecule bscale $_settings(molecule-bondscale)" |
---|
| 502 | set _bondScalePending 0 |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | itcl::body Rappture::VtkViewer::SetMoleculeOpacity {} { |
---|
| 506 | set _moleculeOpacityPending 0 |
---|
| 507 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 508 | foreach { dataobj comp } [split $dataset -] break |
---|
| 509 | if { [$dataobj type $comp] == "molecule" } { |
---|
| 510 | SetOpacity $dataset |
---|
| 511 | } |
---|
| 512 | } |
---|
| 513 | } |
---|
| 514 | |
---|
[3800] | 515 | itcl::body Rappture::VtkViewer::SetMoleculeQuality {} { |
---|
| 516 | SendCmd [subst {molecule aquality $_settings(molecule-quality) |
---|
| 517 | molecule bquality $_settings(molecule-quality)}] |
---|
| 518 | set _moleculeQualityPending 0 |
---|
| 519 | } |
---|
| 520 | |
---|
[4478] | 521 | itcl::body Rappture::VtkViewer::SetGlyphsOpacity {} { |
---|
| 522 | set _glyphsOpacityPending 0 |
---|
| 523 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 524 | foreach { dataobj comp } [split $dataset -] break |
---|
| 525 | if { [$dataobj type $comp] == "glyphs" } { |
---|
| 526 | SetOpacity $dataset |
---|
| 527 | } |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
[3785] | 531 | itcl::body Rappture::VtkViewer::SetPolydataOpacity {} { |
---|
| 532 | set _polydataOpacityPending 0 |
---|
| 533 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 534 | foreach { dataobj comp } [split $dataset -] break |
---|
| 535 | if { [$dataobj type $comp] == "polydata" } { |
---|
| 536 | SetOpacity $dataset |
---|
| 537 | } |
---|
| 538 | } |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | itcl::body Rappture::VtkViewer::EventuallySetAtomScale { args } { |
---|
| 542 | if { !$_atomScalePending } { |
---|
| 543 | set _atomScalePending 1 |
---|
| 544 | $_dispatcher event -after $_scaleDelay !atomscale |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | itcl::body Rappture::VtkViewer::EventuallySetBondScale { args } { |
---|
| 549 | if { !$_bondScalePending } { |
---|
| 550 | set _bondScalePending 1 |
---|
| 551 | $_dispatcher event -after $_scaleDelay !bondscale |
---|
| 552 | } |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | itcl::body Rappture::VtkViewer::EventuallySetMoleculeOpacity { args } { |
---|
| 556 | if { !$_moleculeOpacityPending } { |
---|
| 557 | set _moleculeOpacityPending 1 |
---|
| 558 | $_dispatcher event -after $_scaleDelay !moleculeOpacity |
---|
| 559 | } |
---|
| 560 | } |
---|
| 561 | |
---|
[3800] | 562 | itcl::body Rappture::VtkViewer::EventuallySetMoleculeQuality { args } { |
---|
| 563 | if { !$_moleculeQualityPending } { |
---|
| 564 | set _moleculeQualityPending 1 |
---|
| 565 | $_dispatcher event -after $_scaleDelay !moleculeQuality |
---|
| 566 | } |
---|
| 567 | } |
---|
| 568 | |
---|
[3785] | 569 | itcl::body Rappture::VtkViewer::EventuallySetPolydataOpacity { args } { |
---|
| 570 | if { !$_polydataOpacityPending } { |
---|
| 571 | set _polydataOpacityPending 1 |
---|
| 572 | $_dispatcher event -after $_scaleDelay !polydataOpacity |
---|
| 573 | } |
---|
| 574 | } |
---|
| 575 | |
---|
[4478] | 576 | itcl::body Rappture::VtkViewer::EventuallySetGlyphsOpacity { args } { |
---|
| 577 | if { !$_glyphsOpacityPending } { |
---|
| 578 | set _glyphsOpacityPending 1 |
---|
| 579 | $_dispatcher event -after $_scaleDelay !glyphsOpacity |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | |
---|
[1920] | 583 | # ---------------------------------------------------------------------- |
---|
| 584 | # USAGE: add <dataobj> ?<settings>? |
---|
| 585 | # |
---|
| 586 | # Clients use this to add a data object to the plot. The optional |
---|
| 587 | # <settings> are used to configure the plot. Allowed settings are |
---|
| 588 | # -color, -brightness, -width, -linestyle, and -raise. |
---|
| 589 | # ---------------------------------------------------------------------- |
---|
| 590 | itcl::body Rappture::VtkViewer::add {dataobj {settings ""}} { |
---|
| 591 | array set params { |
---|
[1929] | 592 | -color auto |
---|
| 593 | -width 1 |
---|
| 594 | -linestyle solid |
---|
| 595 | -brightness 0 |
---|
| 596 | -raise 0 |
---|
| 597 | -description "" |
---|
| 598 | -param "" |
---|
[2744] | 599 | -type "" |
---|
[1920] | 600 | } |
---|
[2385] | 601 | array set params $settings |
---|
| 602 | set params(-description) "" |
---|
| 603 | set params(-param) "" |
---|
[3800] | 604 | array set params $settings |
---|
| 605 | |
---|
[1920] | 606 | if {$params(-color) == "auto" || $params(-color) == "autoreset"} { |
---|
[1929] | 607 | # can't handle -autocolors yet |
---|
| 608 | set params(-color) black |
---|
[1920] | 609 | } |
---|
[3844] | 610 | set pos [lsearch -exact $_dlist $dataobj] |
---|
[1920] | 611 | if {$pos < 0} { |
---|
[2744] | 612 | lappend _dlist $dataobj |
---|
[1920] | 613 | } |
---|
[2385] | 614 | set _obj2ovride($dataobj-color) $params(-color) |
---|
| 615 | set _obj2ovride($dataobj-width) $params(-width) |
---|
| 616 | set _obj2ovride($dataobj-raise) $params(-raise) |
---|
| 617 | $_dispatcher event -idle !rebuild |
---|
[1920] | 618 | } |
---|
| 619 | |
---|
| 620 | # ---------------------------------------------------------------------- |
---|
[2385] | 621 | # USAGE: delete ?<dataobj1> <dataobj2> ...? |
---|
[1920] | 622 | # |
---|
[2385] | 623 | # Clients use this to delete a dataobj from the plot. If no dataobjs |
---|
| 624 | # are specified, then all dataobjs are deleted. No data objects are |
---|
| 625 | # deleted. They are only removed from the display list. |
---|
| 626 | # |
---|
[1920] | 627 | # ---------------------------------------------------------------------- |
---|
[2385] | 628 | itcl::body Rappture::VtkViewer::delete {args} { |
---|
| 629 | if { [llength $args] == 0} { |
---|
| 630 | set args $_dlist |
---|
[1920] | 631 | } |
---|
[2385] | 632 | # Delete all specified dataobjs |
---|
| 633 | set changed 0 |
---|
| 634 | foreach dataobj $args { |
---|
| 635 | set pos [lsearch -exact $_dlist $dataobj] |
---|
[2744] | 636 | if { $pos < 0 } { |
---|
| 637 | continue; # Don't know anything about it. |
---|
| 638 | } |
---|
| 639 | # Remove it from the dataobj list. |
---|
| 640 | set _dlist [lreplace $_dlist $pos $pos] |
---|
| 641 | array unset _obj2ovride $dataobj-* |
---|
[3844] | 642 | array unset _settings $dataobj-* |
---|
[2744] | 643 | set changed 1 |
---|
[2385] | 644 | } |
---|
| 645 | # If anything changed, then rebuild the plot |
---|
| 646 | if { $changed } { |
---|
| 647 | $_dispatcher event -idle !rebuild |
---|
| 648 | } |
---|
[1920] | 649 | } |
---|
| 650 | |
---|
| 651 | # ---------------------------------------------------------------------- |
---|
[2385] | 652 | # USAGE: get ?-objects? |
---|
| 653 | # USAGE: get ?-visible? |
---|
| 654 | # USAGE: get ?-image view? |
---|
[1920] | 655 | # |
---|
[2385] | 656 | # Clients use this to query the list of objects being plotted, in |
---|
| 657 | # order from bottom to top of this result. The optional "-image" |
---|
| 658 | # flag can also request the internal images being shown. |
---|
[1920] | 659 | # ---------------------------------------------------------------------- |
---|
[2385] | 660 | itcl::body Rappture::VtkViewer::get {args} { |
---|
[1920] | 661 | if {[llength $args] == 0} { |
---|
[2385] | 662 | set args "-objects" |
---|
[1920] | 663 | } |
---|
| 664 | |
---|
[2385] | 665 | set op [lindex $args 0] |
---|
| 666 | switch -- $op { |
---|
[2744] | 667 | "-objects" { |
---|
| 668 | # put the dataobj list in order according to -raise options |
---|
| 669 | set dlist {} |
---|
| 670 | foreach dataobj $_dlist { |
---|
| 671 | if { ![IsValidObject $dataobj] } { |
---|
| 672 | continue |
---|
| 673 | } |
---|
[5007] | 674 | if {[info exists _obj2ovride($dataobj-raise)] && |
---|
[2744] | 675 | $_obj2ovride($dataobj-raise)} { |
---|
| 676 | set dlist [linsert $dlist 0 $dataobj] |
---|
| 677 | } else { |
---|
| 678 | lappend dlist $dataobj |
---|
| 679 | } |
---|
| 680 | } |
---|
| 681 | return $dlist |
---|
| 682 | } |
---|
| 683 | "-visible" { |
---|
| 684 | set dlist {} |
---|
| 685 | foreach dataobj $_dlist { |
---|
| 686 | if { ![IsValidObject $dataobj] } { |
---|
| 687 | continue |
---|
| 688 | } |
---|
| 689 | if { ![info exists _obj2ovride($dataobj-raise)] } { |
---|
[3844] | 690 | # No setting indicates that the object isn't visible. |
---|
[2744] | 691 | continue |
---|
| 692 | } |
---|
| 693 | # Otherwise use the -raise parameter to put the object to |
---|
| 694 | # the front of the list. |
---|
| 695 | if { $_obj2ovride($dataobj-raise) } { |
---|
| 696 | set dlist [linsert $dlist 0 $dataobj] |
---|
| 697 | } else { |
---|
| 698 | lappend dlist $dataobj |
---|
| 699 | } |
---|
| 700 | } |
---|
| 701 | return $dlist |
---|
[5007] | 702 | } |
---|
[2744] | 703 | -image { |
---|
| 704 | if {[llength $args] != 2} { |
---|
| 705 | error "wrong # args: should be \"get -image view\"" |
---|
| 706 | } |
---|
| 707 | switch -- [lindex $args end] { |
---|
| 708 | view { |
---|
| 709 | return $_image(plot) |
---|
| 710 | } |
---|
| 711 | default { |
---|
| 712 | error "bad image name \"[lindex $args end]\": should be view" |
---|
| 713 | } |
---|
| 714 | } |
---|
| 715 | } |
---|
| 716 | default { |
---|
| 717 | error "bad option \"$op\": should be -objects or -image" |
---|
| 718 | } |
---|
[1920] | 719 | } |
---|
| 720 | } |
---|
| 721 | |
---|
| 722 | # ---------------------------------------------------------------------- |
---|
| 723 | # USAGE: scale ?<data1> <data2> ...? |
---|
| 724 | # |
---|
| 725 | # Sets the default limits for the overall plot according to the |
---|
| 726 | # limits of the data for all of the given <data> objects. This |
---|
| 727 | # accounts for all objects--even those not showing on the screen. |
---|
| 728 | # Because of this, the limits are appropriate for all objects as |
---|
| 729 | # the user scans through data in the ResultSet viewer. |
---|
| 730 | # ---------------------------------------------------------------------- |
---|
| 731 | itcl::body Rappture::VtkViewer::scale {args} { |
---|
[2385] | 732 | foreach dataobj $args { |
---|
[3785] | 733 | foreach comp [$dataobj components] { |
---|
| 734 | set type [$dataobj type $comp] |
---|
| 735 | switch -- $type { |
---|
| 736 | "polydata" { |
---|
| 737 | set _havePolydata 1 |
---|
| 738 | } |
---|
| 739 | "glyphs" { |
---|
| 740 | set _haveGlyphs 1 |
---|
| 741 | } |
---|
| 742 | "molecule" { |
---|
| 743 | set _haveMolecules 1 |
---|
| 744 | } |
---|
| 745 | } |
---|
| 746 | } |
---|
[2385] | 747 | array set bounds [limits $dataobj] |
---|
[4528] | 748 | if {[info exists bounds(xmin)] && (![info exists _limits(xmin)] || $_limits(xmin) > $bounds(xmin))} { |
---|
[2744] | 749 | set _limits(xmin) $bounds(xmin) |
---|
| 750 | } |
---|
[4528] | 751 | if {[info exists bounds(xmax)] && (![info exists _limits(xmax)] || $_limits(xmax) < $bounds(xmax))} { |
---|
[2744] | 752 | set _limits(xmax) $bounds(xmax) |
---|
| 753 | } |
---|
[2385] | 754 | |
---|
[4528] | 755 | if {[info exists bounds(ymin)] && (![info exists _limits(ymin)] || $_limits(ymin) > $bounds(ymin))} { |
---|
[2744] | 756 | set _limits(ymin) $bounds(ymin) |
---|
| 757 | } |
---|
[4528] | 758 | if {[info exists bounds(ymax)] && (![info exists _limits(ymax)] || $_limits(ymax) < $bounds(ymax))} { |
---|
[2744] | 759 | set _limits(ymax) $bounds(ymax) |
---|
| 760 | } |
---|
[2385] | 761 | |
---|
[4528] | 762 | if {[info exists bounds(zmin)] && (![info exists _limits(zmin)] || $_limits(zmin) > $bounds(zmin))} { |
---|
[2744] | 763 | set _limits(zmin) $bounds(zmin) |
---|
| 764 | } |
---|
[4528] | 765 | if {[info exists bounds(zmax)] && (![info exists _limits(zmax)] || $_limits(zmax) < $bounds(zmax))} { |
---|
[2744] | 766 | set _limits(zmax) $bounds(zmax) |
---|
| 767 | } |
---|
[2385] | 768 | } |
---|
[4464] | 769 | if { $_haveGlyphs } { |
---|
| 770 | if { ![$itk_component(main) exists "Glyphs Settings"] } { |
---|
| 771 | if { [catch { BuildGlyphsTab } errs ] != 0 } { |
---|
| 772 | puts stderr "errs=$errs" |
---|
| 773 | } |
---|
| 774 | } |
---|
| 775 | } |
---|
[3785] | 776 | if { $_havePolydata } { |
---|
| 777 | if { ![$itk_component(main) exists "Mesh Settings"] } { |
---|
| 778 | if { [catch { BuildPolydataTab } errs ] != 0 } { |
---|
| 779 | puts stderr "errs=$errs" |
---|
| 780 | } |
---|
| 781 | } |
---|
| 782 | } |
---|
| 783 | if { $_haveMolecules } { |
---|
| 784 | if { ![$itk_component(main) exists "Molecule Settings"]} { |
---|
| 785 | if { [catch { BuildMoleculeTab } errs ] != 0 } { |
---|
| 786 | global errorInfo |
---|
| 787 | puts stderr "errs=$errs\nerrorInfo=$errorInfo" |
---|
| 788 | } |
---|
| 789 | } |
---|
| 790 | } |
---|
[1920] | 791 | } |
---|
| 792 | |
---|
| 793 | # ---------------------------------------------------------------------- |
---|
| 794 | # USAGE: download coming |
---|
| 795 | # USAGE: download controls <downloadCommand> |
---|
| 796 | # USAGE: download now |
---|
| 797 | # |
---|
| 798 | # Clients use this method to create a downloadable representation |
---|
| 799 | # of the plot. Returns a list of the form {ext string}, where |
---|
| 800 | # "ext" is the file extension (indicating the type of data) and |
---|
| 801 | # "string" is the data itself. |
---|
| 802 | # ---------------------------------------------------------------------- |
---|
| 803 | itcl::body Rappture::VtkViewer::download {option args} { |
---|
| 804 | switch $option { |
---|
[1929] | 805 | coming { |
---|
[2088] | 806 | if {[catch { |
---|
[2385] | 807 | blt::winop snap $itk_component(plotarea) $_image(download) |
---|
[2088] | 808 | }]} { |
---|
[2385] | 809 | $_image(download) configure -width 1 -height 1 |
---|
| 810 | $_image(download) put #000000 |
---|
[1929] | 811 | } |
---|
| 812 | } |
---|
| 813 | controls { |
---|
[2385] | 814 | set popup .vtkviewerdownload |
---|
| 815 | if { ![winfo exists .vtkviewerdownload] } { |
---|
| 816 | set inner [BuildDownloadPopup $popup [lindex $args 0]] |
---|
| 817 | } else { |
---|
| 818 | set inner [$popup component inner] |
---|
| 819 | } |
---|
| 820 | set _downloadPopup(image_controls) $inner.image_frame |
---|
| 821 | set num [llength [get]] |
---|
| 822 | set num [expr {($num == 1) ? "1 result" : "$num results"}] |
---|
| 823 | set word [Rappture::filexfer::label downloadWord] |
---|
| 824 | $inner.summary configure -text "$word $num in the following format:" |
---|
[2744] | 825 | update idletasks ;# Fix initial sizes |
---|
[2385] | 826 | return $popup |
---|
[1929] | 827 | } |
---|
| 828 | now { |
---|
[2385] | 829 | set popup .vtkviewerdownload |
---|
| 830 | if {[winfo exists .vtkviewerdownload]} { |
---|
| 831 | $popup deactivate |
---|
| 832 | } |
---|
| 833 | switch -- $_downloadPopup(format) { |
---|
| 834 | "image" { |
---|
| 835 | return [$this GetImage [lindex $args 0]] |
---|
| 836 | } |
---|
| 837 | "vtk" { |
---|
| 838 | return [$this GetVtkData [lindex $args 0]] |
---|
| 839 | } |
---|
| 840 | } |
---|
| 841 | return "" |
---|
[1929] | 842 | } |
---|
| 843 | default { |
---|
| 844 | error "bad option \"$option\": should be coming, controls, now" |
---|
| 845 | } |
---|
[1920] | 846 | } |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | # ---------------------------------------------------------------------- |
---|
[2385] | 850 | # USAGE: Connect ?<host:port>,<host:port>...? |
---|
[1920] | 851 | # |
---|
[2385] | 852 | # Clients use this method to establish a connection to a new |
---|
| 853 | # server, or to reestablish a connection to the previous server. |
---|
| 854 | # Any existing connection is automatically closed. |
---|
[1920] | 855 | # ---------------------------------------------------------------------- |
---|
[2385] | 856 | itcl::body Rappture::VtkViewer::Connect {} { |
---|
[3663] | 857 | global readyForNextFrame |
---|
| 858 | set readyForNextFrame 1 |
---|
[2385] | 859 | set _hosts [GetServerList "vtkvis"] |
---|
| 860 | if { "" == $_hosts } { |
---|
| 861 | return 0 |
---|
| 862 | } |
---|
[5172] | 863 | set _reset 1 |
---|
[2385] | 864 | set result [VisViewer::Connect $_hosts] |
---|
| 865 | if { $result } { |
---|
[3592] | 866 | if { $_reportClientInfo } { |
---|
| 867 | # Tell the server the viewer, hub, user and session. |
---|
[4439] | 868 | # Do this immediately on connect before buffering any commands |
---|
[3708] | 869 | global env |
---|
[3592] | 870 | |
---|
| 871 | set info {} |
---|
| 872 | set user "???" |
---|
[3708] | 873 | if { [info exists env(USER)] } { |
---|
[3592] | 874 | set user $env(USER) |
---|
[3708] | 875 | } |
---|
[3592] | 876 | set session "???" |
---|
[3708] | 877 | if { [info exists env(SESSION)] } { |
---|
[3592] | 878 | set session $env(SESSION) |
---|
[3708] | 879 | } |
---|
[4670] | 880 | lappend info "version" "$Rappture::version" |
---|
| 881 | lappend info "build" "$Rappture::build" |
---|
| 882 | lappend info "svnurl" "$Rappture::svnurl" |
---|
| 883 | lappend info "installdir" "$Rappture::installdir" |
---|
[3592] | 884 | lappend info "hub" [exec hostname] |
---|
| 885 | lappend info "client" "vtkviewer" |
---|
| 886 | lappend info "user" $user |
---|
| 887 | lappend info "session" $session |
---|
| 888 | SendCmd "clientinfo [list $info]" |
---|
| 889 | } |
---|
| 890 | |
---|
[2385] | 891 | set w [winfo width $itk_component(view)] |
---|
| 892 | set h [winfo height $itk_component(view)] |
---|
| 893 | EventuallyResize $w $h |
---|
| 894 | } |
---|
| 895 | return $result |
---|
| 896 | } |
---|
| 897 | |
---|
| 898 | # |
---|
| 899 | # isconnected -- |
---|
| 900 | # |
---|
| 901 | # Indicates if we are currently connected to the visualization server. |
---|
| 902 | # |
---|
| 903 | itcl::body Rappture::VtkViewer::isconnected {} { |
---|
| 904 | return [VisViewer::IsConnected] |
---|
| 905 | } |
---|
| 906 | |
---|
| 907 | # |
---|
| 908 | # disconnect -- |
---|
| 909 | # |
---|
| 910 | itcl::body Rappture::VtkViewer::disconnect {} { |
---|
| 911 | Disconnect |
---|
| 912 | set _reset 1 |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | # |
---|
| 916 | # Disconnect -- |
---|
| 917 | # |
---|
| 918 | # Clients use this method to disconnect from the current rendering |
---|
| 919 | # server. |
---|
| 920 | # |
---|
| 921 | itcl::body Rappture::VtkViewer::Disconnect {} { |
---|
| 922 | VisViewer::Disconnect |
---|
| 923 | |
---|
| 924 | # disconnected -- no more data sitting on server |
---|
[5007] | 925 | array unset _datasets |
---|
| 926 | array unset _colormaps |
---|
[3663] | 927 | global readyForNextFrame |
---|
| 928 | set readyForNextFrame 1 |
---|
[2385] | 929 | } |
---|
| 930 | |
---|
| 931 | # ---------------------------------------------------------------------- |
---|
| 932 | # USAGE: ReceiveImage -bytes <size> -type <type> -token <token> |
---|
| 933 | # |
---|
| 934 | # Invoked automatically whenever the "image" command comes in from |
---|
| 935 | # the rendering server. Indicates that binary image data with the |
---|
| 936 | # specified <size> will follow. |
---|
| 937 | # ---------------------------------------------------------------------- |
---|
| 938 | itcl::body Rappture::VtkViewer::ReceiveImage { args } { |
---|
[3663] | 939 | global readyForNextFrame |
---|
| 940 | set readyForNextFrame 1 |
---|
[2385] | 941 | array set info { |
---|
| 942 | -token "???" |
---|
| 943 | -bytes 0 |
---|
| 944 | -type image |
---|
| 945 | } |
---|
| 946 | array set info $args |
---|
| 947 | set bytes [ReceiveBytes $info(-bytes)] |
---|
| 948 | if { $info(-type) == "image" } { |
---|
[2744] | 949 | if 0 { |
---|
[4768] | 950 | set f [open "last.ppm" "w"] |
---|
[3863] | 951 | fconfigure $f -encoding binary |
---|
| 952 | puts -nonewline $f $bytes |
---|
[2744] | 953 | close $f |
---|
| 954 | } |
---|
[2385] | 955 | $_image(plot) configure -data $bytes |
---|
[2744] | 956 | set time [clock seconds] |
---|
| 957 | set date [clock format $time] |
---|
| 958 | if { $_start > 0 } { |
---|
| 959 | set finish [clock clicks -milliseconds] |
---|
| 960 | set _start 0 |
---|
| 961 | } |
---|
[2385] | 962 | } elseif { $info(type) == "print" } { |
---|
| 963 | set tag $this-print-$info(-token) |
---|
| 964 | set _hardcopy($tag) $bytes |
---|
| 965 | } |
---|
| 966 | } |
---|
| 967 | |
---|
| 968 | # |
---|
| 969 | # ReceiveDataset -- |
---|
| 970 | # |
---|
| 971 | itcl::body Rappture::VtkViewer::ReceiveDataset { args } { |
---|
| 972 | if { ![isconnected] } { |
---|
| 973 | return |
---|
| 974 | } |
---|
| 975 | set option [lindex $args 0] |
---|
| 976 | switch -- $option { |
---|
[2744] | 977 | "scalar" { |
---|
| 978 | set option [lindex $args 1] |
---|
| 979 | switch -- $option { |
---|
| 980 | "world" { |
---|
| 981 | foreach { x y z value tag } [lrange $args 2 end] break |
---|
| 982 | } |
---|
| 983 | "pixel" { |
---|
| 984 | foreach { x y value tag } [lrange $args 2 end] break |
---|
| 985 | } |
---|
| 986 | } |
---|
| 987 | } |
---|
| 988 | "vector" { |
---|
| 989 | set option [lindex $args 1] |
---|
| 990 | switch -- $option { |
---|
| 991 | "world" { |
---|
| 992 | foreach { x y z vx vy vz tag } [lrange $args 2 end] break |
---|
| 993 | } |
---|
| 994 | "pixel" { |
---|
| 995 | foreach { x y vx vy vz tag } [lrange $args 2 end] break |
---|
| 996 | } |
---|
| 997 | } |
---|
| 998 | } |
---|
| 999 | "names" { |
---|
[2426] | 1000 | foreach { name } [lindex $args 1] { |
---|
| 1001 | #puts stderr "Dataset: $name" |
---|
| 1002 | } |
---|
[2744] | 1003 | } |
---|
| 1004 | default { |
---|
| 1005 | error "unknown dataset option \"$option\" from server" |
---|
| 1006 | } |
---|
[2385] | 1007 | } |
---|
| 1008 | } |
---|
| 1009 | |
---|
| 1010 | # ---------------------------------------------------------------------- |
---|
| 1011 | # USAGE: Rebuild |
---|
| 1012 | # |
---|
| 1013 | # Called automatically whenever something changes that affects the |
---|
| 1014 | # data in the widget. Clears any existing data and rebuilds the |
---|
| 1015 | # widget to display new data. |
---|
| 1016 | # ---------------------------------------------------------------------- |
---|
| 1017 | itcl::body Rappture::VtkViewer::Rebuild {} { |
---|
| 1018 | set w [winfo width $itk_component(view)] |
---|
| 1019 | set h [winfo height $itk_component(view)] |
---|
| 1020 | if { $w < 2 || $h < 2 } { |
---|
[5095] | 1021 | update |
---|
[2744] | 1022 | $_dispatcher event -idle !rebuild |
---|
| 1023 | return |
---|
[2385] | 1024 | } |
---|
| 1025 | |
---|
| 1026 | # Turn on buffering of commands to the server. We don't want to |
---|
| 1027 | # be preempted by a server disconnect/reconnect (which automatically |
---|
[5007] | 1028 | # generates a new call to Rebuild). |
---|
[3421] | 1029 | StartBufferingCommands |
---|
[2385] | 1030 | |
---|
[3392] | 1031 | if { $_reset } { |
---|
| 1032 | set _width $w |
---|
| 1033 | set _height $h |
---|
| 1034 | $_arcball resize $w $h |
---|
| 1035 | DoResize |
---|
[4464] | 1036 | InitSettings axis-xgrid axis-ygrid axis-zgrid axis-mode \ |
---|
[4696] | 1037 | axis-visible axis-labels axis-minorticks |
---|
[3785] | 1038 | |
---|
[3844] | 1039 | StopBufferingCommands |
---|
[3418] | 1040 | SendCmd "imgflush" |
---|
[3844] | 1041 | StartBufferingCommands |
---|
[2484] | 1042 | } |
---|
| 1043 | |
---|
[2466] | 1044 | set _limits(zmin) "" |
---|
| 1045 | set _limits(zmax) "" |
---|
[2385] | 1046 | set _first "" |
---|
[3662] | 1047 | SendCmd "dataset visible 0" |
---|
| 1048 | set count 0 |
---|
[2385] | 1049 | foreach dataobj [get -objects] { |
---|
[2744] | 1050 | if { [info exists _obj2ovride($dataobj-raise)] && $_first == "" } { |
---|
| 1051 | set _first $dataobj |
---|
| 1052 | } |
---|
[2385] | 1053 | foreach comp [$dataobj components] { |
---|
| 1054 | set tag $dataobj-$comp |
---|
| 1055 | if { ![info exists _datasets($tag)] } { |
---|
| 1056 | set bytes [$dataobj data $comp] |
---|
[3708] | 1057 | if { $bytes == "" } { |
---|
| 1058 | continue |
---|
| 1059 | } |
---|
[4768] | 1060 | if 0 { |
---|
| 1061 | set f [open /tmp/vtkviewer.vtk "w"] |
---|
| 1062 | fconfigure $f -translation binary -encoding binary |
---|
| 1063 | puts -nonewline $f $bytes |
---|
| 1064 | close $f |
---|
| 1065 | } |
---|
[2385] | 1066 | set length [string length $bytes] |
---|
[3421] | 1067 | if { $_reportClientInfo } { |
---|
[3392] | 1068 | set info {} |
---|
[4750] | 1069 | lappend info "tool_id" [$dataobj hints toolid] |
---|
| 1070 | lappend info "tool_name" [$dataobj hints toolname] |
---|
| 1071 | lappend info "tool_title" [$dataobj hints tooltitle] |
---|
| 1072 | lappend info "tool_command" [$dataobj hints toolcommand] |
---|
| 1073 | lappend info "tool_revision" [$dataobj hints toolrevision] |
---|
[3392] | 1074 | lappend info "dataset_label" [$dataobj hints label] |
---|
| 1075 | lappend info "dataset_size" $length |
---|
[3394] | 1076 | lappend info "dataset_tag" $tag |
---|
[4766] | 1077 | SendCmd "clientinfo [list $info]" |
---|
[3392] | 1078 | } |
---|
[3421] | 1079 | SendCmd "dataset add $tag data follows $length" |
---|
[5143] | 1080 | SendData $bytes |
---|
[2385] | 1081 | set _datasets($tag) 1 |
---|
[3708] | 1082 | SetObjectStyle $dataobj $comp |
---|
[2744] | 1083 | } |
---|
[4464] | 1084 | set type [$dataobj type $comp] |
---|
[2744] | 1085 | if { [info exists _obj2ovride($dataobj-raise)] } { |
---|
[4464] | 1086 | SendCmd "$type visible 1 $tag" |
---|
[3785] | 1087 | SetOpacity $tag |
---|
[2744] | 1088 | } |
---|
[1929] | 1089 | } |
---|
[1920] | 1090 | } |
---|
[2385] | 1091 | if {"" != $_first} { |
---|
| 1092 | set location [$_first hints camera] |
---|
| 1093 | if { $location != "" } { |
---|
| 1094 | array set view $location |
---|
| 1095 | } |
---|
[2848] | 1096 | |
---|
| 1097 | foreach axis { x y z } { |
---|
| 1098 | set label [$_first hints ${axis}label] |
---|
| 1099 | if { $label != "" } { |
---|
[4464] | 1100 | SendCmd [list axis name $axis $label] |
---|
[2848] | 1101 | } |
---|
| 1102 | set units [$_first hints ${axis}units] |
---|
| 1103 | if { $units != "" } { |
---|
[4464] | 1104 | SendCmd [list axis units $axis $units] |
---|
[2848] | 1105 | } |
---|
[2744] | 1106 | } |
---|
[2497] | 1107 | } |
---|
[4464] | 1108 | if { $_haveGlyphs } { |
---|
| 1109 | InitSettings glyphs-outline |
---|
| 1110 | } |
---|
| 1111 | if { $_haveMolecules } { |
---|
| 1112 | InitSettings molecule-outline |
---|
| 1113 | } |
---|
| 1114 | if { $_havePolydata } { |
---|
| 1115 | InitSettings polydata-outline |
---|
| 1116 | } |
---|
[3414] | 1117 | if { $_reset } { |
---|
[4464] | 1118 | if { $_haveGlyphs } { |
---|
| 1119 | InitSettings glyphs-edges glyphs-lighting glyphs-opacity \ |
---|
[5007] | 1120 | glyphs-visible glyphs-wireframe |
---|
[4464] | 1121 | } |
---|
| 1122 | if { $_havePolydata } { |
---|
| 1123 | InitSettings polydata-edges polydata-lighting polydata-opacity \ |
---|
[5007] | 1124 | polydata-visible polydata-wireframe |
---|
[4464] | 1125 | } |
---|
| 1126 | if { $_haveMolecules } { |
---|
| 1127 | InitSettings molecule-edges molecule-lighting molecule-opacity \ |
---|
| 1128 | molecule-visible molecule-wireframe molecule-labels |
---|
| 1129 | } |
---|
| 1130 | |
---|
[4766] | 1131 | $_arcball quaternion [ViewToQuaternion] |
---|
[3414] | 1132 | SendCmd "camera reset" |
---|
[4766] | 1133 | if { $_view(-ortho)} { |
---|
[3414] | 1134 | SendCmd "camera mode ortho" |
---|
| 1135 | } else { |
---|
| 1136 | SendCmd "camera mode persp" |
---|
[3708] | 1137 | } |
---|
| 1138 | DoRotate |
---|
| 1139 | PanCamera |
---|
[3415] | 1140 | Zoom reset |
---|
[3414] | 1141 | } |
---|
[3139] | 1142 | |
---|
[3785] | 1143 | if { $_haveMolecules } { |
---|
[5007] | 1144 | #InitSettings molecule-representation |
---|
[3785] | 1145 | } |
---|
[3392] | 1146 | set _reset 0 |
---|
[3663] | 1147 | global readyForNextFrame |
---|
| 1148 | set readyForNextFrame 0; # Don't advance to the next frame |
---|
| 1149 | # until we get an image. |
---|
[2385] | 1150 | |
---|
| 1151 | # Actually write the commands to the server socket. If it fails, we don't |
---|
| 1152 | # care. We're finished here. |
---|
| 1153 | blt::busy hold $itk_component(hull) |
---|
[3421] | 1154 | StopBufferingCommands |
---|
[2385] | 1155 | blt::busy release $itk_component(hull) |
---|
| 1156 | } |
---|
| 1157 | |
---|
| 1158 | # ---------------------------------------------------------------------- |
---|
| 1159 | # USAGE: CurrentDatasets ?-all -visible? ?dataobjs? |
---|
| 1160 | # |
---|
| 1161 | # Returns a list of server IDs for the current datasets being displayed. This |
---|
| 1162 | # is normally a single ID, but it might be a list of IDs if the current data |
---|
| 1163 | # object has multiple components. |
---|
| 1164 | # ---------------------------------------------------------------------- |
---|
| 1165 | itcl::body Rappture::VtkViewer::CurrentDatasets {args} { |
---|
| 1166 | set flag [lindex $args 0] |
---|
[5007] | 1167 | switch -- $flag { |
---|
[2744] | 1168 | "-all" { |
---|
| 1169 | if { [llength $args] > 1 } { |
---|
| 1170 | error "CurrentDatasets: can't specify dataobj after \"-all\"" |
---|
| 1171 | } |
---|
| 1172 | set dlist [get -objects] |
---|
| 1173 | } |
---|
| 1174 | "-visible" { |
---|
| 1175 | if { [llength $args] > 1 } { |
---|
| 1176 | set dlist {} |
---|
| 1177 | set args [lrange $args 1 end] |
---|
| 1178 | foreach dataobj $args { |
---|
| 1179 | if { [info exists _obj2ovride($dataobj-raise)] } { |
---|
| 1180 | lappend dlist $dataobj |
---|
| 1181 | } |
---|
| 1182 | } |
---|
| 1183 | } else { |
---|
| 1184 | set dlist [get -visible] |
---|
| 1185 | } |
---|
[5007] | 1186 | } |
---|
[2744] | 1187 | default { |
---|
| 1188 | set dlist $args |
---|
| 1189 | } |
---|
[1920] | 1190 | } |
---|
[2385] | 1191 | set rlist "" |
---|
| 1192 | foreach dataobj $dlist { |
---|
[2744] | 1193 | foreach comp [$dataobj components] { |
---|
| 1194 | set tag $dataobj-$comp |
---|
| 1195 | if { [info exists _datasets($tag)] && $_datasets($tag) } { |
---|
| 1196 | lappend rlist $tag |
---|
| 1197 | } |
---|
| 1198 | } |
---|
[2385] | 1199 | } |
---|
| 1200 | return $rlist |
---|
[1920] | 1201 | } |
---|
| 1202 | |
---|
| 1203 | # ---------------------------------------------------------------------- |
---|
| 1204 | # USAGE: Zoom in |
---|
| 1205 | # USAGE: Zoom out |
---|
| 1206 | # USAGE: Zoom reset |
---|
| 1207 | # |
---|
| 1208 | # Called automatically when the user clicks on one of the zoom |
---|
| 1209 | # controls for this widget. Changes the zoom for the current view. |
---|
| 1210 | # ---------------------------------------------------------------------- |
---|
| 1211 | itcl::body Rappture::VtkViewer::Zoom {option} { |
---|
| 1212 | switch -- $option { |
---|
[2385] | 1213 | "in" { |
---|
[4766] | 1214 | set _view(-zoom) [expr {$_view(-zoom)*1.25}] |
---|
| 1215 | SendCmd "camera zoom $_view(-zoom)" |
---|
[1929] | 1216 | } |
---|
[2385] | 1217 | "out" { |
---|
[4766] | 1218 | set _view(-zoom) [expr {$_view(-zoom)*0.8}] |
---|
| 1219 | SendCmd "camera zoom $_view(-zoom)" |
---|
[1929] | 1220 | } |
---|
[2385] | 1221 | "reset" { |
---|
| 1222 | array set _view { |
---|
[4766] | 1223 | -qw 0.853553 |
---|
| 1224 | -qx -0.353553 |
---|
| 1225 | -qy 0.353553 |
---|
| 1226 | -qz 0.146447 |
---|
| 1227 | -xpan 0 |
---|
| 1228 | -ypan 0 |
---|
| 1229 | -zoom 1.0 |
---|
[2385] | 1230 | } |
---|
| 1231 | if { $_first != "" } { |
---|
| 1232 | set location [$_first hints camera] |
---|
| 1233 | if { $location != "" } { |
---|
| 1234 | array set _view $location |
---|
| 1235 | } |
---|
| 1236 | } |
---|
[4766] | 1237 | $_arcball quaternion [ViewToQuaternion] |
---|
[2744] | 1238 | DoRotate |
---|
[3550] | 1239 | SendCmd "camera reset" |
---|
[1929] | 1240 | } |
---|
[1920] | 1241 | } |
---|
| 1242 | } |
---|
| 1243 | |
---|
[2385] | 1244 | itcl::body Rappture::VtkViewer::PanCamera {} { |
---|
[4766] | 1245 | set x $_view(-xpan) |
---|
| 1246 | set y $_view(-ypan) |
---|
[2385] | 1247 | SendCmd "camera pan $x $y" |
---|
| 1248 | } |
---|
| 1249 | |
---|
[1920] | 1250 | # ---------------------------------------------------------------------- |
---|
[2385] | 1251 | # USAGE: Rotate click <x> <y> |
---|
| 1252 | # USAGE: Rotate drag <x> <y> |
---|
| 1253 | # USAGE: Rotate release <x> <y> |
---|
[1920] | 1254 | # |
---|
| 1255 | # Called automatically when the user clicks/drags/releases in the |
---|
| 1256 | # plot area. Moves the plot according to the user's actions. |
---|
| 1257 | # ---------------------------------------------------------------------- |
---|
[2385] | 1258 | itcl::body Rappture::VtkViewer::Rotate {option x y} { |
---|
[1920] | 1259 | switch -- $option { |
---|
[2385] | 1260 | "click" { |
---|
| 1261 | $itk_component(view) configure -cursor fleur |
---|
[1929] | 1262 | set _click(x) $x |
---|
| 1263 | set _click(y) $y |
---|
| 1264 | } |
---|
[2385] | 1265 | "drag" { |
---|
[1929] | 1266 | if {[array size _click] == 0} { |
---|
[2385] | 1267 | Rotate click $x $y |
---|
[1929] | 1268 | } else { |
---|
[2385] | 1269 | set w [winfo width $itk_component(view)] |
---|
| 1270 | set h [winfo height $itk_component(view)] |
---|
| 1271 | if {$w <= 0 || $h <= 0} { |
---|
| 1272 | return |
---|
| 1273 | } |
---|
[1920] | 1274 | |
---|
[2385] | 1275 | if {[catch { |
---|
| 1276 | # this fails sometimes for no apparent reason |
---|
| 1277 | set dx [expr {double($x-$_click(x))/$w}] |
---|
| 1278 | set dy [expr {double($y-$_click(y))/$h}] |
---|
| 1279 | }]} { |
---|
| 1280 | return |
---|
[1929] | 1281 | } |
---|
[2744] | 1282 | if { $dx == 0 && $dy == 0 } { |
---|
| 1283 | return |
---|
| 1284 | } |
---|
| 1285 | set q [$_arcball rotate $x $y $_click(x) $_click(y)] |
---|
| 1286 | EventuallyRotate $q |
---|
[1929] | 1287 | set _click(x) $x |
---|
| 1288 | set _click(y) $y |
---|
| 1289 | } |
---|
| 1290 | } |
---|
[2385] | 1291 | "release" { |
---|
| 1292 | Rotate drag $x $y |
---|
| 1293 | $itk_component(view) configure -cursor "" |
---|
[1929] | 1294 | catch {unset _click} |
---|
| 1295 | } |
---|
| 1296 | default { |
---|
| 1297 | error "bad option \"$option\": should be click, drag, release" |
---|
| 1298 | } |
---|
[1920] | 1299 | } |
---|
| 1300 | } |
---|
| 1301 | |
---|
[2426] | 1302 | itcl::body Rappture::VtkViewer::Pick {x y} { |
---|
| 1303 | foreach tag [CurrentDatasets -visible] { |
---|
| 1304 | SendCmd "dataset getscalar pixel $x $y $tag" |
---|
[5007] | 1305 | } |
---|
[2426] | 1306 | } |
---|
| 1307 | |
---|
[1920] | 1308 | # ---------------------------------------------------------------------- |
---|
[2385] | 1309 | # USAGE: $this Pan click x y |
---|
| 1310 | # $this Pan drag x y |
---|
| 1311 | # $this Pan release x y |
---|
[1920] | 1312 | # |
---|
[2385] | 1313 | # Called automatically when the user clicks on one of the zoom |
---|
| 1314 | # controls for this widget. Changes the zoom for the current view. |
---|
[1920] | 1315 | # ---------------------------------------------------------------------- |
---|
[2385] | 1316 | itcl::body Rappture::VtkViewer::Pan {option x y} { |
---|
| 1317 | switch -- $option { |
---|
[2744] | 1318 | "set" { |
---|
| 1319 | set w [winfo width $itk_component(view)] |
---|
| 1320 | set h [winfo height $itk_component(view)] |
---|
| 1321 | set x [expr $x / double($w)] |
---|
| 1322 | set y [expr $y / double($h)] |
---|
[4766] | 1323 | set _view(-xpan) [expr $_view(-xpan) + $x] |
---|
| 1324 | set _view(-ypan) [expr $_view(-ypan) + $y] |
---|
[2744] | 1325 | PanCamera |
---|
| 1326 | return |
---|
| 1327 | } |
---|
| 1328 | "click" { |
---|
| 1329 | set _click(x) $x |
---|
| 1330 | set _click(y) $y |
---|
| 1331 | $itk_component(view) configure -cursor hand1 |
---|
| 1332 | } |
---|
| 1333 | "drag" { |
---|
| 1334 | if { ![info exists _click(x)] } { |
---|
| 1335 | set _click(x) $x |
---|
| 1336 | } |
---|
| 1337 | if { ![info exists _click(y)] } { |
---|
| 1338 | set _click(y) $y |
---|
| 1339 | } |
---|
| 1340 | set w [winfo width $itk_component(view)] |
---|
| 1341 | set h [winfo height $itk_component(view)] |
---|
| 1342 | set dx [expr ($_click(x) - $x)/double($w)] |
---|
| 1343 | set dy [expr ($_click(y) - $y)/double($h)] |
---|
| 1344 | set _click(x) $x |
---|
| 1345 | set _click(y) $y |
---|
[4766] | 1346 | set _view(-xpan) [expr $_view(-xpan) - $dx] |
---|
| 1347 | set _view(-ypan) [expr $_view(-ypan) - $dy] |
---|
[2744] | 1348 | PanCamera |
---|
| 1349 | } |
---|
| 1350 | "release" { |
---|
| 1351 | Pan drag $x $y |
---|
| 1352 | $itk_component(view) configure -cursor "" |
---|
| 1353 | } |
---|
| 1354 | default { |
---|
| 1355 | error "unknown option \"$option\": should set, click, drag, or release" |
---|
| 1356 | } |
---|
[2385] | 1357 | } |
---|
[1920] | 1358 | } |
---|
| 1359 | |
---|
| 1360 | # ---------------------------------------------------------------------- |
---|
[4464] | 1361 | # USAGE: InitSettings <what> ?<value>? |
---|
[1920] | 1362 | # |
---|
[2385] | 1363 | # Used internally to update rendering settings whenever parameters |
---|
| 1364 | # change in the popup settings panel. Sends the new settings off |
---|
| 1365 | # to the back end. |
---|
[1920] | 1366 | # ---------------------------------------------------------------------- |
---|
[4464] | 1367 | itcl::body Rappture::VtkViewer::InitSettings { args } { |
---|
[2466] | 1368 | foreach setting $args { |
---|
[2744] | 1369 | AdjustSetting $setting |
---|
[2466] | 1370 | } |
---|
| 1371 | } |
---|
| 1372 | |
---|
| 1373 | # |
---|
| 1374 | # AdjustSetting -- |
---|
| 1375 | # |
---|
[2744] | 1376 | # Changes/updates a specific setting in the widget. There are |
---|
| 1377 | # usually user-setable option. Commands are sent to the render |
---|
| 1378 | # server. |
---|
[2466] | 1379 | # |
---|
| 1380 | itcl::body Rappture::VtkViewer::AdjustSetting {what {value ""}} { |
---|
[2464] | 1381 | if { ![isconnected] } { |
---|
[2744] | 1382 | return |
---|
[2464] | 1383 | } |
---|
[2385] | 1384 | switch -- $what { |
---|
[4464] | 1385 | "glyphs-opacity" { |
---|
| 1386 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1387 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1388 | if { [$dataobj type $comp] == "glyphs" } { |
---|
| 1389 | SetOpacity $dataset |
---|
| 1390 | } |
---|
| 1391 | } |
---|
| 1392 | } |
---|
| 1393 | "glyphs-outline" { |
---|
[4478] | 1394 | set bool $_settings($what) |
---|
[4464] | 1395 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1396 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1397 | set type [$dataobj type $comp] |
---|
| 1398 | if { $type == "glyphs" } { |
---|
| 1399 | SendCmd "outline visible $bool $dataset" |
---|
| 1400 | } |
---|
| 1401 | } |
---|
| 1402 | } |
---|
| 1403 | "glyphs-wireframe" { |
---|
[4478] | 1404 | set bool $_settings($what) |
---|
[4464] | 1405 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1406 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1407 | set type [$dataobj type $comp] |
---|
| 1408 | if { $type == "glyphs" } { |
---|
| 1409 | SendCmd "$type wireframe $bool $dataset" |
---|
| 1410 | } |
---|
| 1411 | } |
---|
| 1412 | } |
---|
| 1413 | "glyphs-visible" { |
---|
[4478] | 1414 | set bool $_settings($what) |
---|
[4464] | 1415 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1416 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1417 | set type [$dataobj type $comp] |
---|
| 1418 | if { $type == "glyphs" } { |
---|
| 1419 | SendCmd "$type visible $bool $dataset" |
---|
| 1420 | } |
---|
| 1421 | } |
---|
| 1422 | } |
---|
| 1423 | "glyphs-lighting" { |
---|
[4478] | 1424 | set bool $_settings($what) |
---|
[4464] | 1425 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1426 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1427 | set type [$dataobj type $comp] |
---|
| 1428 | if { $type == "glyphs" } { |
---|
| 1429 | SendCmd "$type lighting $bool $dataset" |
---|
| 1430 | } |
---|
| 1431 | } |
---|
| 1432 | } |
---|
| 1433 | "glyphs-edges" { |
---|
[4478] | 1434 | set bool $_settings($what) |
---|
[4464] | 1435 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1436 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1437 | set type [$dataobj type $comp] |
---|
| 1438 | if { $type == "glyphs" } { |
---|
| 1439 | SendCmd "$type edges $bool $dataset" |
---|
| 1440 | } |
---|
| 1441 | } |
---|
| 1442 | } |
---|
| 1443 | "glyphs-palette" { |
---|
| 1444 | set palette [$itk_component(glyphspalette) value] |
---|
[4478] | 1445 | set _settings($what) $palette |
---|
[4464] | 1446 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1447 | foreach {dataobj comp} [split $dataset -] break |
---|
| 1448 | set type [$dataobj type $comp] |
---|
| 1449 | if { $type == "glyphs" } { |
---|
| 1450 | ChangeColormap $dataobj $comp $palette |
---|
| 1451 | # FIXME: fill in current selected fieldname |
---|
| 1452 | #SendCmd "glyphs colormode scalar {} $dataset" |
---|
| 1453 | } |
---|
| 1454 | } |
---|
| 1455 | set _legendPending 1 |
---|
| 1456 | } |
---|
[3785] | 1457 | "polydata-opacity" { |
---|
[2744] | 1458 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[3708] | 1459 | foreach { dataobj comp } [split $dataset -] break |
---|
[3785] | 1460 | if { [$dataobj type $comp] == "polydata" } { |
---|
| 1461 | SetOpacity $dataset |
---|
[3708] | 1462 | } |
---|
[2744] | 1463 | } |
---|
[2385] | 1464 | } |
---|
[4464] | 1465 | "polydata-outline" { |
---|
[4478] | 1466 | set bool $_settings($what) |
---|
[4464] | 1467 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1468 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1469 | set type [$dataobj type $comp] |
---|
| 1470 | if { $type == "polydata" } { |
---|
| 1471 | SendCmd "outline visible $bool $dataset" |
---|
| 1472 | } |
---|
| 1473 | } |
---|
| 1474 | } |
---|
[3785] | 1475 | "polydata-wireframe" { |
---|
[4478] | 1476 | set bool $_settings($what) |
---|
[2744] | 1477 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[3708] | 1478 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1479 | set type [$dataobj type $comp] |
---|
| 1480 | if { $type == "polydata" } { |
---|
| 1481 | SendCmd "$type wireframe $bool $dataset" |
---|
| 1482 | } |
---|
[2385] | 1483 | } |
---|
| 1484 | } |
---|
[3785] | 1485 | "polydata-visible" { |
---|
[4478] | 1486 | set bool $_settings($what) |
---|
[2744] | 1487 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[3708] | 1488 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1489 | set type [$dataobj type $comp] |
---|
| 1490 | if { $type == "polydata" } { |
---|
| 1491 | SendCmd "$type visible $bool $dataset" |
---|
| 1492 | } |
---|
[2385] | 1493 | } |
---|
| 1494 | } |
---|
[3785] | 1495 | "polydata-lighting" { |
---|
[4478] | 1496 | set bool $_settings($what) |
---|
[2744] | 1497 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[3708] | 1498 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1499 | set type [$dataobj type $comp] |
---|
| 1500 | if { $type == "polydata" } { |
---|
| 1501 | SendCmd "$type lighting $bool $dataset" |
---|
| 1502 | } |
---|
[2385] | 1503 | } |
---|
| 1504 | } |
---|
[3785] | 1505 | "polydata-edges" { |
---|
[4478] | 1506 | set bool $_settings($what) |
---|
[2744] | 1507 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[3708] | 1508 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1509 | set type [$dataobj type $comp] |
---|
| 1510 | if { $type == "polydata" } { |
---|
| 1511 | SendCmd "$type edges $bool $dataset" |
---|
| 1512 | } |
---|
[2474] | 1513 | } |
---|
| 1514 | } |
---|
[3785] | 1515 | "polydata-palette" { |
---|
[3122] | 1516 | set palette [$itk_component(meshpalette) value] |
---|
[4478] | 1517 | set _settings($what) $palette |
---|
[3093] | 1518 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1519 | foreach {dataobj comp} [split $dataset -] break |
---|
[3708] | 1520 | set type [$dataobj type $comp] |
---|
| 1521 | if { $type == "polydata" } { |
---|
| 1522 | ChangeColormap $dataobj $comp $palette |
---|
[3843] | 1523 | # FIXME: fill in current selected fieldname |
---|
[3800] | 1524 | #SendCmd "polydata colormode scalar {} $dataset" |
---|
[3708] | 1525 | } |
---|
[3093] | 1526 | } |
---|
| 1527 | set _legendPending 1 |
---|
| 1528 | } |
---|
[3121] | 1529 | "molecule-opacity" { |
---|
| 1530 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[3708] | 1531 | foreach { dataobj comp } [split $dataset -] break |
---|
[3785] | 1532 | if { [$dataobj type $comp] == "molecule" } { |
---|
| 1533 | SetOpacity $dataset |
---|
[3708] | 1534 | } |
---|
[3121] | 1535 | } |
---|
| 1536 | } |
---|
[4464] | 1537 | "molecule-outline" { |
---|
[4478] | 1538 | set bool $_settings($what) |
---|
[4464] | 1539 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1540 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1541 | set type [$dataobj type $comp] |
---|
| 1542 | if { $type == "molecule" } { |
---|
| 1543 | SendCmd "outline visible $bool $dataset" |
---|
| 1544 | } |
---|
| 1545 | } |
---|
| 1546 | } |
---|
[3121] | 1547 | "molecule-wireframe" { |
---|
[4478] | 1548 | set bool $_settings($what) |
---|
[3121] | 1549 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[3708] | 1550 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1551 | set type [$dataobj type $comp] |
---|
| 1552 | if { $type == "molecule" } { |
---|
| 1553 | SendCmd "molecule wireframe $bool $dataset" |
---|
| 1554 | } |
---|
[3121] | 1555 | } |
---|
| 1556 | } |
---|
| 1557 | "molecule-visible" { |
---|
[4478] | 1558 | set bool $_settings($what) |
---|
[3121] | 1559 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[3708] | 1560 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1561 | set type [$dataobj type $comp] |
---|
| 1562 | if { $type == "molecule" } { |
---|
| 1563 | SendCmd "molecule visible $bool $dataset" |
---|
| 1564 | } |
---|
[3121] | 1565 | } |
---|
| 1566 | } |
---|
| 1567 | "molecule-lighting" { |
---|
[4478] | 1568 | set bool $_settings($what) |
---|
[3121] | 1569 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[3708] | 1570 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1571 | set type [$dataobj type $comp] |
---|
| 1572 | if { $type == "molecule" } { |
---|
| 1573 | SendCmd "molecule lighting $bool $dataset" |
---|
| 1574 | } |
---|
[3121] | 1575 | } |
---|
| 1576 | } |
---|
| 1577 | "molecule-edges" { |
---|
[4478] | 1578 | set bool $_settings($what) |
---|
[3121] | 1579 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
[3708] | 1580 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1581 | set type [$dataobj type $comp] |
---|
| 1582 | if { $type == "molecule" } { |
---|
| 1583 | SendCmd "molecule edges $bool $dataset" |
---|
| 1584 | } |
---|
[3121] | 1585 | } |
---|
| 1586 | } |
---|
| 1587 | "molecule-palette" { |
---|
| 1588 | set palette [$itk_component(moleculepalette) value] |
---|
[4478] | 1589 | set _settings($what) $palette |
---|
[3121] | 1590 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1591 | foreach {dataobj comp} [split $dataset -] break |
---|
[3708] | 1592 | set type [$dataobj type $comp] |
---|
| 1593 | if { $type == "molecule" } { |
---|
| 1594 | ChangeColormap $dataobj $comp $palette |
---|
| 1595 | if { $palette == "elementDefault" } { |
---|
| 1596 | SendCmd "molecule colormode by_elements element $dataset" |
---|
| 1597 | } else { |
---|
| 1598 | # FIXME: Set the chosen scalar field name here |
---|
| 1599 | SendCmd "molecule colormode scalar {} $dataset" |
---|
| 1600 | } |
---|
| 1601 | } |
---|
[3121] | 1602 | } |
---|
| 1603 | set _legendPending 1 |
---|
| 1604 | } |
---|
[3708] | 1605 | "molecule-representation" { |
---|
| 1606 | set value [$itk_component(representation) value] |
---|
| 1607 | set value [$itk_component(representation) translate $value] |
---|
| 1608 | switch -- $value { |
---|
| 1609 | "ballandstick" { |
---|
[3800] | 1610 | set _settings(molecule-rscale) covalent |
---|
[3785] | 1611 | set _settings(molecule-atoms-visible) 1 |
---|
| 1612 | set _settings(molecule-bonds-visible) 1 |
---|
[3877] | 1613 | set _settings(molecule-bondstyle) cylinder |
---|
[3785] | 1614 | set _settings(molecule-atomscale) 0.3 |
---|
| 1615 | set _settings(molecule-bondscale) 0.075 |
---|
[3708] | 1616 | } |
---|
| 1617 | "balls" - "spheres" { |
---|
[3800] | 1618 | set _settings(molecule-rscale) covalent |
---|
[3785] | 1619 | set _settings(molecule-atoms-visible) 1 |
---|
| 1620 | set _settings(molecule-bonds-visible) 0 |
---|
[3877] | 1621 | set _settings(molecule-bondstyle) cylinder |
---|
[3785] | 1622 | set _settings(molecule-atomscale) 0.3 |
---|
| 1623 | set _settings(molecule-bondscale) 0.075 |
---|
[3708] | 1624 | } |
---|
| 1625 | "sticks" { |
---|
[3800] | 1626 | set _settings(molecule-rscale) none |
---|
[3785] | 1627 | set _settings(molecule-atoms-visible) 1 |
---|
| 1628 | set _settings(molecule-bonds-visible) 1 |
---|
[3877] | 1629 | set _settings(molecule-bondstyle) cylinder |
---|
[3785] | 1630 | set _settings(molecule-atomscale) 0.075 |
---|
| 1631 | set _settings(molecule-bondscale) 0.075 |
---|
[3708] | 1632 | } |
---|
| 1633 | "spacefilling" { |
---|
[3800] | 1634 | set _settings(molecule-rscale) van_der_waals |
---|
[3785] | 1635 | set _settings(molecule-atoms-visible) 1 |
---|
| 1636 | set _settings(molecule-bonds-visible) 0 |
---|
[3877] | 1637 | set _settings(molecule-bondstyle) cylinder |
---|
[3785] | 1638 | set _settings(molecule-atomscale) 1.0 |
---|
| 1639 | set _settings(molecule-bondscale) 0.075 |
---|
[3708] | 1640 | } |
---|
| 1641 | "rods" { |
---|
[3800] | 1642 | set _settings(molecule-rscale) none |
---|
[3785] | 1643 | set _settings(molecule-atoms-visible) 1 |
---|
| 1644 | set _settings(molecule-bonds-visible) 1 |
---|
[3877] | 1645 | set _settings(molecule-bondstyle) cylinder |
---|
[3785] | 1646 | set _settings(molecule-atomscale) 0.1 |
---|
| 1647 | set _settings(molecule-bondscale) 0.1 |
---|
[3708] | 1648 | } |
---|
| 1649 | "wireframe" - "lines" { |
---|
[3800] | 1650 | set _settings(molecule-rscale) none |
---|
[3785] | 1651 | set _settings(molecule-atoms-visible) 0 |
---|
| 1652 | set _settings(molecule-bonds-visible) 1 |
---|
[4464] | 1653 | set _settings(molecule-bondstyle) line |
---|
[3785] | 1654 | set _settings(molecule-atomscale) 1.0 |
---|
| 1655 | set _settings(molecule-bondscale) 1.0 |
---|
[3708] | 1656 | } |
---|
| 1657 | default { |
---|
| 1658 | error "unknown representation $value" |
---|
| 1659 | } |
---|
| 1660 | } |
---|
[3800] | 1661 | $itk_component(rscale) value [$itk_component(rscale) label $_settings(molecule-rscale)] |
---|
| 1662 | switch -- $value { |
---|
| 1663 | "ballandstick" - "balls" - "spheres" { |
---|
| 1664 | $itk_component(rscale) configure -state normal |
---|
| 1665 | } |
---|
| 1666 | default { |
---|
| 1667 | $itk_component(rscale) configure -state disabled |
---|
| 1668 | } |
---|
| 1669 | } |
---|
[3877] | 1670 | foreach dataset [CurrentDatasets -all] { |
---|
[3708] | 1671 | foreach {dataobj comp} [split $dataset -] break |
---|
| 1672 | set type [$dataobj type $comp] |
---|
| 1673 | if { $type == "molecule" } { |
---|
[4696] | 1674 | StartBufferingCommands |
---|
| 1675 | SendCmd [subst {molecule rscale $_settings(molecule-rscale) $dataset}] |
---|
| 1676 | SendCmd [subst {molecule ascale $_settings(molecule-atomscale) $dataset}] |
---|
| 1677 | SendCmd [subst {molecule bscale $_settings(molecule-bondscale) $dataset}] |
---|
| 1678 | SendCmd [subst {molecule bstyle $_settings(molecule-bondstyle) $dataset}] |
---|
| 1679 | SendCmd [subst {molecule atoms $_settings(molecule-atoms-visible) $dataset}] |
---|
| 1680 | SendCmd [subst {molecule bonds $_settings(molecule-bonds-visible) $dataset}] |
---|
| 1681 | StopBufferingCommands |
---|
[3708] | 1682 | } |
---|
| 1683 | } |
---|
| 1684 | } |
---|
[3800] | 1685 | "molecule-rscale" { |
---|
| 1686 | set value [$itk_component(rscale) value] |
---|
| 1687 | set value [$itk_component(rscale) translate $value] |
---|
[4478] | 1688 | set _settings($what) $value |
---|
[3800] | 1689 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1690 | foreach {dataobj comp} [split $dataset -] break |
---|
| 1691 | set type [$dataobj type $comp] |
---|
| 1692 | if { $type == "molecule" } { |
---|
[4478] | 1693 | SendCmd [subst {molecule rscale $_settings($what) $dataset}] |
---|
[3800] | 1694 | } |
---|
| 1695 | } |
---|
| 1696 | } |
---|
[3137] | 1697 | "molecule-labels" { |
---|
[4478] | 1698 | set bool $_settings($what) |
---|
[3137] | 1699 | foreach dataset [CurrentDatasets -visible $_first] { |
---|
| 1700 | foreach { dataobj comp } [split $dataset -] break |
---|
| 1701 | set type [$dataobj type $comp] |
---|
| 1702 | if { $type == "molecule" } { |
---|
| 1703 | SendCmd "molecule labels $bool $dataset" |
---|
| 1704 | } |
---|
| 1705 | } |
---|
| 1706 | } |
---|
[2474] | 1707 | "axis-visible" { |
---|
[2744] | 1708 | set bool $_axis(visible) |
---|
| 1709 | SendCmd "axis visible all $bool" |
---|
[2474] | 1710 | } |
---|
[2497] | 1711 | "axis-labels" { |
---|
[2744] | 1712 | set bool $_axis(labels) |
---|
| 1713 | SendCmd "axis labels all $bool" |
---|
[2497] | 1714 | } |
---|
[4696] | 1715 | "axis-minorticks" { |
---|
| 1716 | set bool $_axis(minorticks) |
---|
| 1717 | SendCmd "axis minticks all $bool" |
---|
| 1718 | } |
---|
[2504] | 1719 | "axis-xgrid" { |
---|
[2744] | 1720 | set bool $_axis(xgrid) |
---|
| 1721 | SendCmd "axis grid x $bool" |
---|
[2385] | 1722 | } |
---|
[2504] | 1723 | "axis-ygrid" { |
---|
[2744] | 1724 | set bool $_axis(ygrid) |
---|
| 1725 | SendCmd "axis grid y $bool" |
---|
[2385] | 1726 | } |
---|
[2504] | 1727 | "axis-zgrid" { |
---|
[2744] | 1728 | set bool $_axis(zgrid) |
---|
| 1729 | SendCmd "axis grid z $bool" |
---|
[2385] | 1730 | } |
---|
[2474] | 1731 | "axis-mode" { |
---|
[2744] | 1732 | set mode [$itk_component(axismode) value] |
---|
| 1733 | set mode [$itk_component(axismode) translate $mode] |
---|
| 1734 | SendCmd "axis flymode $mode" |
---|
[2464] | 1735 | } |
---|
[2744] | 1736 | "axis-xcutaway" - "axis-ycutaway" - "axis-zcutaway" { |
---|
| 1737 | set axis [string range $what 5 5] |
---|
| 1738 | set bool $_axis(${axis}cutaway) |
---|
[2504] | 1739 | if { $bool } { |
---|
[2744] | 1740 | set pos [expr $_axis(${axis}position) * 0.01] |
---|
| 1741 | set dir $_axis(${axis}direction) |
---|
[2504] | 1742 | $itk_component(${axis}CutScale) configure -state normal \ |
---|
| 1743 | -troughcolor white |
---|
[2744] | 1744 | SendCmd "renderer clipplane $axis $pos $dir" |
---|
[2504] | 1745 | } else { |
---|
| 1746 | $itk_component(${axis}CutScale) configure -state disabled \ |
---|
| 1747 | -troughcolor grey82 |
---|
[2744] | 1748 | SendCmd "renderer clipplane $axis 1 -1" |
---|
[2385] | 1749 | } |
---|
[2744] | 1750 | } |
---|
[5007] | 1751 | "axis-xposition" - "axis-yposition" - "axis-zposition" - |
---|
[2744] | 1752 | "axis-xdirection" - "axis-ydirection" - "axis-zdirection" { |
---|
| 1753 | set axis [string range $what 5 5] |
---|
| 1754 | #set dir $_axis(${axis}direction) |
---|
| 1755 | set pos [expr $_axis(${axis}position) * 0.01] |
---|
| 1756 | SendCmd "renderer clipplane ${axis} $pos -1" |
---|
| 1757 | } |
---|
[2385] | 1758 | default { |
---|
| 1759 | error "don't know how to fix $what" |
---|
| 1760 | } |
---|
[1920] | 1761 | } |
---|
| 1762 | } |
---|
| 1763 | |
---|
| 1764 | # |
---|
[2466] | 1765 | # RequestLegend -- |
---|
| 1766 | # |
---|
[2744] | 1767 | # Request a new legend from the server. The size of the legend |
---|
| 1768 | # is determined from the height of the canvas. It will be rotated |
---|
| 1769 | # to be vertical when drawn. |
---|
[2466] | 1770 | # |
---|
| 1771 | itcl::body Rappture::VtkViewer::RequestLegend {} { |
---|
[2485] | 1772 | set font "Arial 8" |
---|
| 1773 | set lineht [font metrics $font -linespace] |
---|
[2489] | 1774 | set w 12 |
---|
[2485] | 1775 | set h [expr {$_height - 2 * ($lineht + 2)}] |
---|
[4464] | 1776 | if { $h < 1 } { |
---|
[2744] | 1777 | return |
---|
[2466] | 1778 | } |
---|
[2504] | 1779 | # Set the legend on the first dataset. |
---|
[2466] | 1780 | foreach dataset [CurrentDatasets -visible] { |
---|
[2744] | 1781 | foreach {dataobj comp} [split $dataset -] break |
---|
| 1782 | if { [info exists _dataset2style($dataset)] } { |
---|
[5143] | 1783 | #SendCmd "legend $_dataset2style($dataset) vmag {} {} $w $h 0" |
---|
| 1784 | SendCmd "legend2 $_dataset2style($dataset) $w $h" |
---|
[2744] | 1785 | break; |
---|
[2466] | 1786 | } |
---|
| 1787 | } |
---|
| 1788 | } |
---|
| 1789 | |
---|
| 1790 | # |
---|
[3093] | 1791 | # ChangeColormap -- |
---|
| 1792 | # |
---|
| 1793 | itcl::body Rappture::VtkViewer::ChangeColormap {dataobj comp color} { |
---|
| 1794 | set tag $dataobj-$comp |
---|
| 1795 | if { ![info exist _style($tag)] } { |
---|
| 1796 | error "no initial colormap" |
---|
| 1797 | } |
---|
| 1798 | array set style $_style($tag) |
---|
| 1799 | set style(-color) $color |
---|
| 1800 | set _style($tag) [array get style] |
---|
| 1801 | SetColormap $dataobj $comp |
---|
| 1802 | } |
---|
| 1803 | |
---|
| 1804 | # |
---|
[2489] | 1805 | # SetColormap -- |
---|
[2385] | 1806 | # |
---|
[2489] | 1807 | itcl::body Rappture::VtkViewer::SetColormap { dataobj comp } { |
---|
[2385] | 1808 | array set style { |
---|
[3093] | 1809 | -color BCGYR |
---|
[2385] | 1810 | -levels 6 |
---|
| 1811 | -opacity 1.0 |
---|
| 1812 | } |
---|
[3140] | 1813 | if {[$dataobj type $comp] == "molecule"} { |
---|
| 1814 | set style(-color) elementDefault |
---|
| 1815 | } |
---|
[2385] | 1816 | set tag $dataobj-$comp |
---|
[3093] | 1817 | if { ![info exists _initialStyle($tag)] } { |
---|
| 1818 | # Save the initial component style. |
---|
| 1819 | set _initialStyle($tag) [$dataobj style $comp] |
---|
[2385] | 1820 | } |
---|
[3093] | 1821 | |
---|
| 1822 | # Override defaults with initial style defined in xml. |
---|
| 1823 | array set style $_initialStyle($tag) |
---|
| 1824 | |
---|
| 1825 | if { ![info exists _style($tag)] } { |
---|
| 1826 | set _style($tag) [array get style] |
---|
[2385] | 1827 | } |
---|
[3093] | 1828 | # Override initial style with current style. |
---|
| 1829 | array set style $_style($tag) |
---|
| 1830 | |
---|
[3139] | 1831 | if { $style(-color) == "elementDefault" } { |
---|
[3708] | 1832 | set name "$style(-color)" |
---|
[3139] | 1833 | } else { |
---|
[3708] | 1834 | set name "$style(-color):$style(-levels):$style(-opacity)" |
---|
[3139] | 1835 | } |
---|
[3093] | 1836 | if { ![info exists _colormaps($name)] } { |
---|
| 1837 | BuildColormap $name [array get style] |
---|
| 1838 | set _colormaps($name) 1 |
---|
[2385] | 1839 | } |
---|
[3093] | 1840 | if { ![info exists _dataset2style($tag)] || |
---|
| 1841 | $_dataset2style($tag) != $name } { |
---|
| 1842 | set _dataset2style($tag) $name |
---|
[3708] | 1843 | switch -- [$dataobj type $comp] { |
---|
[3709] | 1844 | "polydata" { |
---|
[3843] | 1845 | SendCmd "polydata colormap $name $tag" |
---|
[3708] | 1846 | } |
---|
| 1847 | "glyphs" { |
---|
| 1848 | SendCmd "glyphs colormap $name $tag" |
---|
| 1849 | } |
---|
| 1850 | "molecule" { |
---|
| 1851 | SendCmd "molecule colormap $name $tag" |
---|
| 1852 | } |
---|
| 1853 | } |
---|
[3093] | 1854 | } |
---|
| 1855 | } |
---|
| 1856 | |
---|
| 1857 | # |
---|
| 1858 | # BuildColormap -- |
---|
| 1859 | # |
---|
| 1860 | itcl::body Rappture::VtkViewer::BuildColormap { name styles } { |
---|
[3139] | 1861 | if { $name == "elementDefault" } { |
---|
[3708] | 1862 | return |
---|
[3139] | 1863 | } |
---|
[3093] | 1864 | array set style $styles |
---|
| 1865 | set cmap [ColorsToColormap $style(-color)] |
---|
[2385] | 1866 | if { [llength $cmap] == 0 } { |
---|
[2744] | 1867 | set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0" |
---|
[2385] | 1868 | } |
---|
[3785] | 1869 | if { ![info exists _settings(polydata-opacity)] } { |
---|
| 1870 | set _settings(polydata-opacity) $style(-opacity) |
---|
[2385] | 1871 | } |
---|
[3785] | 1872 | set max $_settings(polydata-opacity) |
---|
[2385] | 1873 | |
---|
[5183] | 1874 | set amap "0.0 1.0 1.0 1.0" |
---|
| 1875 | SendCmd "colormap add $name { $cmap } { $amap }" |
---|
[2385] | 1876 | } |
---|
| 1877 | |
---|
[1920] | 1878 | # ---------------------------------------------------------------------- |
---|
| 1879 | # CONFIGURATION OPTION: -plotbackground |
---|
| 1880 | # ---------------------------------------------------------------------- |
---|
| 1881 | itcl::configbody Rappture::VtkViewer::plotbackground { |
---|
[2385] | 1882 | if { [isconnected] } { |
---|
[4766] | 1883 | set rgb [Color2RGB $itk_option(-plotbackground)] |
---|
| 1884 | SendCmd "screen bgcolor $rgb" |
---|
[1920] | 1885 | } |
---|
| 1886 | } |
---|
| 1887 | |
---|
| 1888 | # ---------------------------------------------------------------------- |
---|
| 1889 | # CONFIGURATION OPTION: -plotforeground |
---|
| 1890 | # ---------------------------------------------------------------------- |
---|
| 1891 | itcl::configbody Rappture::VtkViewer::plotforeground { |
---|
[2385] | 1892 | if { [isconnected] } { |
---|
[4766] | 1893 | set rgb [Color2RGB $itk_option(-plotforeground)] |
---|
| 1894 | SendCmd "axis color all $rgb" |
---|
| 1895 | SendCmd "outline color $rgb" |
---|
[1920] | 1896 | } |
---|
| 1897 | } |
---|
| 1898 | |
---|
[2385] | 1899 | itcl::body Rappture::VtkViewer::limits { dataobj } { |
---|
| 1900 | foreach comp [$dataobj components] { |
---|
[2744] | 1901 | set tag $dataobj-$comp |
---|
| 1902 | if { ![info exists _limits($tag)] } { |
---|
| 1903 | set data [$dataobj data $comp] |
---|
[3708] | 1904 | if { $data == "" } { |
---|
| 1905 | continue |
---|
| 1906 | } |
---|
[2744] | 1907 | set tmpfile file[pid].vtk |
---|
| 1908 | set f [open "$tmpfile" "w"] |
---|
| 1909 | fconfigure $f -translation binary -encoding binary |
---|
[5007] | 1910 | puts $f $data |
---|
[2744] | 1911 | close $f |
---|
| 1912 | set reader [vtkDataSetReader $tag-xvtkDataSetReader] |
---|
| 1913 | $reader SetFileName $tmpfile |
---|
[3708] | 1914 | set debug 0 |
---|
| 1915 | if {$debug} { |
---|
| 1916 | # Only needed for debug output below |
---|
| 1917 | $reader ReadAllNormalsOn |
---|
| 1918 | $reader ReadAllTCoordsOn |
---|
| 1919 | $reader ReadAllScalarsOn |
---|
| 1920 | $reader ReadAllColorScalarsOn |
---|
| 1921 | $reader ReadAllVectorsOn |
---|
| 1922 | $reader ReadAllTensorsOn |
---|
| 1923 | $reader ReadAllFieldsOn |
---|
| 1924 | } |
---|
[2744] | 1925 | $reader Update |
---|
[3708] | 1926 | file delete $tmpfile |
---|
[2744] | 1927 | set output [$reader GetOutput] |
---|
[4528] | 1928 | if { $output == "" } { |
---|
| 1929 | # Invalid VTK file -- loader failed to parse |
---|
| 1930 | continue |
---|
| 1931 | } |
---|
[2744] | 1932 | set _limits($tag) [$output GetBounds] |
---|
[3708] | 1933 | if {$debug} { |
---|
| 1934 | puts stderr "\#scalars=[$reader GetNumberOfScalarsInFile]" |
---|
| 1935 | puts stderr "\#vectors=[$reader GetNumberOfVectorsInFile]" |
---|
| 1936 | puts stderr "\#tensors=[$reader GetNumberOfTensorsInFile]" |
---|
| 1937 | puts stderr "\#normals=[$reader GetNumberOfNormalsInFile]" |
---|
| 1938 | puts stderr "\#tcoords=[$reader GetNumberOfTCoordsInFile]" |
---|
| 1939 | puts stderr "\#fielddata=[$reader GetNumberOfFieldDataInFile]" |
---|
| 1940 | puts stderr "fielddataname=[$reader GetFieldDataNameInFile 0]" |
---|
| 1941 | set pointData [$output GetPointData] |
---|
| 1942 | if { $pointData != ""} { |
---|
| 1943 | puts stderr "point \#arrays=[$pointData GetNumberOfArrays]" |
---|
| 1944 | puts stderr "point \#components=[$pointData GetNumberOfComponents]" |
---|
| 1945 | puts stderr "point \#tuples=[$pointData GetNumberOfTuples]" |
---|
| 1946 | puts stderr "point scalars=[$pointData GetScalars]" |
---|
| 1947 | puts stderr "point vectors=[$pointData GetVectors]" |
---|
| 1948 | } |
---|
| 1949 | set cellData [$output GetCellData] |
---|
| 1950 | if { $cellData != ""} { |
---|
| 1951 | puts stderr "cell \#arrays=[$cellData GetNumberOfArrays]" |
---|
| 1952 | puts stderr "cell \#components=[$cellData GetNumberOfComponents]" |
---|
| 1953 | puts stderr "cell \#tuples=[$cellData GetNumberOfTuples]" |
---|
| 1954 | puts stderr "cell scalars=[$cellData GetScalars]" |
---|
| 1955 | puts stderr "cell vectors=[$cellData GetVectors]" |
---|
| 1956 | } |
---|
| 1957 | set fieldData [$output GetFieldData] |
---|
| 1958 | if { $fieldData != ""} { |
---|
| 1959 | puts stderr "field \#arrays=[$fieldData GetNumberOfArrays]" |
---|
| 1960 | puts stderr "field \#components=[$fieldData GetNumberOfComponents]" |
---|
| 1961 | puts stderr "field \#tuples=[$fieldData GetNumberOfTuples]" |
---|
| 1962 | } |
---|
| 1963 | } |
---|
[2744] | 1964 | rename $output "" |
---|
| 1965 | rename $reader "" |
---|
| 1966 | } |
---|
[2385] | 1967 | foreach { xMin xMax yMin yMax zMin zMax} $_limits($tag) break |
---|
[2744] | 1968 | if {![info exists limits(xmin)] || $limits(xmin) > $xMin} { |
---|
| 1969 | set limits(xmin) $xMin |
---|
| 1970 | } |
---|
| 1971 | if {![info exists limits(xmax)] || $limits(xmax) < $xMax} { |
---|
| 1972 | set limits(xmax) $xMax |
---|
| 1973 | } |
---|
| 1974 | if {![info exists limits(ymin)] || $limits(ymin) > $yMin} { |
---|
| 1975 | set limits(ymin) $xMin |
---|
| 1976 | } |
---|
| 1977 | if {![info exists limits(ymax)] || $limits(ymax) < $yMax} { |
---|
| 1978 | set limits(ymax) $yMax |
---|
| 1979 | } |
---|
| 1980 | if {![info exists limits(zmin)] || $limits(zmin) > $zMin} { |
---|
| 1981 | set limits(zmin) $zMin |
---|
| 1982 | } |
---|
| 1983 | if {![info exists limits(zmax)] || $limits(zmax) < $zMax} { |
---|
| 1984 | set limits(zmax) $zMax |
---|
| 1985 | } |
---|
[2088] | 1986 | } |
---|
[2385] | 1987 | return [array get limits] |
---|
| 1988 | } |
---|
[2148] | 1989 | |
---|
[4464] | 1990 | itcl::body Rappture::VtkViewer::BuildGlyphsTab {} { |
---|
| 1991 | |
---|
| 1992 | set fg [option get $itk_component(hull) font Font] |
---|
| 1993 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
| 1994 | |
---|
| 1995 | set inner [$itk_component(main) insert 0 \ |
---|
| 1996 | -title "Glyph Settings" \ |
---|
| 1997 | -icon [Rappture::icon volume-on]] |
---|
| 1998 | $inner configure -borderwidth 4 |
---|
| 1999 | |
---|
| 2000 | checkbutton $inner.glyphs \ |
---|
| 2001 | -text "Show Glyphs" \ |
---|
| 2002 | -variable [itcl::scope _settings(glyphs-visible)] \ |
---|
| 2003 | -command [itcl::code $this AdjustSetting glyphs-visible] \ |
---|
[5007] | 2004 | -font "Arial 9" -anchor w |
---|
[4464] | 2005 | |
---|
| 2006 | checkbutton $inner.outline \ |
---|
| 2007 | -text "Show Outline" \ |
---|
| 2008 | -variable [itcl::scope _settings(glyphs-outline)] \ |
---|
| 2009 | -command [itcl::code $this AdjustSetting glyphs-outline] \ |
---|
[5007] | 2010 | -font "Arial 9" -anchor w |
---|
[4464] | 2011 | |
---|
| 2012 | checkbutton $inner.wireframe \ |
---|
| 2013 | -text "Show Wireframe" \ |
---|
| 2014 | -variable [itcl::scope _settings(glyphs-wireframe)] \ |
---|
| 2015 | -command [itcl::code $this AdjustSetting glyphs-wireframe] \ |
---|
[5007] | 2016 | -font "Arial 9" -anchor w |
---|
[4464] | 2017 | |
---|
| 2018 | checkbutton $inner.lighting \ |
---|
| 2019 | -text "Enable Lighting" \ |
---|
| 2020 | -variable [itcl::scope _settings(glyphs-lighting)] \ |
---|
| 2021 | -command [itcl::code $this AdjustSetting glyphs-lighting] \ |
---|
| 2022 | -font "Arial 9" -anchor w |
---|
| 2023 | |
---|
| 2024 | checkbutton $inner.edges \ |
---|
| 2025 | -text "Show Edges" \ |
---|
| 2026 | -variable [itcl::scope _settings(glyphs-edges)] \ |
---|
| 2027 | -command [itcl::code $this AdjustSetting glyphs-edges] \ |
---|
| 2028 | -font "Arial 9" -anchor w |
---|
| 2029 | |
---|
[5007] | 2030 | label $inner.palette_l -text "Palette" -font "Arial 9" -anchor w |
---|
[4464] | 2031 | itk_component add glyphspalette { |
---|
| 2032 | Rappture::Combobox $inner.palette -width 10 -editable no |
---|
| 2033 | } |
---|
| 2034 | $inner.palette choices insert end [GetColormapList] |
---|
| 2035 | $itk_component(glyphspalette) value "BCGYR" |
---|
| 2036 | bind $inner.palette <<Value>> \ |
---|
| 2037 | [itcl::code $this AdjustSetting glyphs-palette] |
---|
| 2038 | |
---|
[5007] | 2039 | label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w |
---|
[4464] | 2040 | ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ |
---|
| 2041 | -variable [itcl::scope _settings(glyphs-opacity)] \ |
---|
| 2042 | -width 10 \ |
---|
| 2043 | -showvalue off \ |
---|
[4478] | 2044 | -command [itcl::code $this EventuallySetGlyphsOpacity] |
---|
[4464] | 2045 | $inner.opacity set $_settings(glyphs-opacity) |
---|
| 2046 | |
---|
| 2047 | blt::table $inner \ |
---|
| 2048 | 0,0 $inner.glyphs -cspan 2 -anchor w -pady 2 \ |
---|
| 2049 | 1,0 $inner.outline -cspan 2 -anchor w -pady 2 \ |
---|
| 2050 | 2,0 $inner.wireframe -cspan 2 -anchor w -pady 2 \ |
---|
| 2051 | 3,0 $inner.lighting -cspan 2 -anchor w -pady 2 \ |
---|
| 2052 | 4,0 $inner.edges -cspan 2 -anchor w -pady 2 \ |
---|
| 2053 | 5,0 $inner.opacity_l -anchor w -pady 2 \ |
---|
| 2054 | 5,1 $inner.opacity -fill x -pady 2 \ |
---|
| 2055 | 6,0 $inner.palette_l -anchor w -pady 2 \ |
---|
[5007] | 2056 | 6,1 $inner.palette -fill x -pady 2 |
---|
[4464] | 2057 | |
---|
| 2058 | blt::table configure $inner r* c* -resize none |
---|
| 2059 | blt::table configure $inner r8 c1 -resize expand |
---|
| 2060 | } |
---|
| 2061 | |
---|
[3785] | 2062 | itcl::body Rappture::VtkViewer::BuildPolydataTab {} { |
---|
[1920] | 2063 | |
---|
| 2064 | set fg [option get $itk_component(hull) font Font] |
---|
| 2065 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
| 2066 | |
---|
[4464] | 2067 | set inner [$itk_component(main) insert 0 \ |
---|
[3122] | 2068 | -title "Mesh Settings" \ |
---|
| 2069 | -icon [Rappture::icon mesh]] |
---|
[1920] | 2070 | $inner configure -borderwidth 4 |
---|
[2385] | 2071 | |
---|
[3122] | 2072 | checkbutton $inner.mesh \ |
---|
| 2073 | -text "Show Mesh" \ |
---|
[3785] | 2074 | -variable [itcl::scope _settings(polydata-visible)] \ |
---|
| 2075 | -command [itcl::code $this AdjustSetting polydata-visible] \ |
---|
[5007] | 2076 | -font "Arial 9" -anchor w |
---|
[2464] | 2077 | |
---|
[4464] | 2078 | checkbutton $inner.outline \ |
---|
| 2079 | -text "Show Outline" \ |
---|
| 2080 | -variable [itcl::scope _settings(polydata-outline)] \ |
---|
| 2081 | -command [itcl::code $this AdjustSetting polydata-outline] \ |
---|
[5007] | 2082 | -font "Arial 9" -anchor w |
---|
[4464] | 2083 | |
---|
[2385] | 2084 | checkbutton $inner.wireframe \ |
---|
[2474] | 2085 | -text "Show Wireframe" \ |
---|
[3785] | 2086 | -variable [itcl::scope _settings(polydata-wireframe)] \ |
---|
| 2087 | -command [itcl::code $this AdjustSetting polydata-wireframe] \ |
---|
[5007] | 2088 | -font "Arial 9" -anchor w |
---|
[1920] | 2089 | |
---|
[2385] | 2090 | checkbutton $inner.lighting \ |
---|
[2474] | 2091 | -text "Enable Lighting" \ |
---|
[3785] | 2092 | -variable [itcl::scope _settings(polydata-lighting)] \ |
---|
| 2093 | -command [itcl::code $this AdjustSetting polydata-lighting] \ |
---|
[3174] | 2094 | -font "Arial 9" -anchor w |
---|
[2385] | 2095 | |
---|
[1920] | 2096 | checkbutton $inner.edges \ |
---|
[2474] | 2097 | -text "Show Edges" \ |
---|
[3785] | 2098 | -variable [itcl::scope _settings(polydata-edges)] \ |
---|
| 2099 | -command [itcl::code $this AdjustSetting polydata-edges] \ |
---|
[3174] | 2100 | -font "Arial 9" -anchor w |
---|
[1920] | 2101 | |
---|
[5007] | 2102 | label $inner.palette_l -text "Palette" -font "Arial 9" -anchor w |
---|
[3122] | 2103 | itk_component add meshpalette { |
---|
[3093] | 2104 | Rappture::Combobox $inner.palette -width 10 -editable no |
---|
| 2105 | } |
---|
[4449] | 2106 | $inner.palette choices insert end [GetColormapList] |
---|
[3122] | 2107 | $itk_component(meshpalette) value "BCGYR" |
---|
[3093] | 2108 | bind $inner.palette <<Value>> \ |
---|
[3785] | 2109 | [itcl::code $this AdjustSetting polydata-palette] |
---|
[3093] | 2110 | |
---|
[5007] | 2111 | label $inner.opacity_l -text "Opacity" -font "Arial 9" -anchor w |
---|
[2385] | 2112 | ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ |
---|
[3785] | 2113 | -variable [itcl::scope _settings(polydata-opacity)] \ |
---|
[2385] | 2114 | -width 10 \ |
---|
[2474] | 2115 | -showvalue off \ |
---|
[4478] | 2116 | -command [itcl::code $this EventuallySetPolydataOpacity] |
---|
[3800] | 2117 | $inner.opacity set $_settings(polydata-opacity) |
---|
[2097] | 2118 | |
---|
[1920] | 2119 | blt::table $inner \ |
---|
[3174] | 2120 | 0,0 $inner.mesh -cspan 2 -anchor w -pady 2 \ |
---|
[4464] | 2121 | 1,0 $inner.outline -cspan 2 -anchor w -pady 2 \ |
---|
| 2122 | 2,0 $inner.wireframe -cspan 2 -anchor w -pady 2 \ |
---|
| 2123 | 3,0 $inner.lighting -cspan 2 -anchor w -pady 2 \ |
---|
| 2124 | 4,0 $inner.edges -cspan 2 -anchor w -pady 2 \ |
---|
| 2125 | 5,0 $inner.opacity_l -anchor w -pady 2 \ |
---|
| 2126 | 5,1 $inner.opacity -fill x -pady 2 \ |
---|
| 2127 | 6,0 $inner.palette_l -anchor w -pady 2 \ |
---|
[5007] | 2128 | 6,1 $inner.palette -fill x -pady 2 |
---|
[1920] | 2129 | |
---|
[2474] | 2130 | blt::table configure $inner r* c* -resize none |
---|
[4464] | 2131 | blt::table configure $inner r8 c1 -resize expand |
---|
[1920] | 2132 | } |
---|
| 2133 | |
---|
[2385] | 2134 | itcl::body Rappture::VtkViewer::BuildAxisTab {} { |
---|
[1920] | 2135 | |
---|
| 2136 | set fg [option get $itk_component(hull) font Font] |
---|
| 2137 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
| 2138 | |
---|
[2385] | 2139 | set inner [$itk_component(main) insert end \ |
---|
| 2140 | -title "Axis Settings" \ |
---|
[4696] | 2141 | -icon [Rappture::icon axis2]] |
---|
[2385] | 2142 | $inner configure -borderwidth 4 |
---|
[1920] | 2143 | |
---|
[2474] | 2144 | checkbutton $inner.visible \ |
---|
[4696] | 2145 | -text "Axes" \ |
---|
[2474] | 2146 | -variable [itcl::scope _axis(visible)] \ |
---|
| 2147 | -command [itcl::code $this AdjustSetting axis-visible] \ |
---|
[2385] | 2148 | -font "Arial 9" |
---|
[1920] | 2149 | |
---|
[2497] | 2150 | checkbutton $inner.labels \ |
---|
[4696] | 2151 | -text "Axis Labels" \ |
---|
[2497] | 2152 | -variable [itcl::scope _axis(labels)] \ |
---|
| 2153 | -command [itcl::code $this AdjustSetting axis-labels] \ |
---|
| 2154 | -font "Arial 9" |
---|
[5007] | 2155 | label $inner.grid_l -text "Grid" -font "Arial 9" |
---|
[4696] | 2156 | checkbutton $inner.xgrid \ |
---|
| 2157 | -text "X" \ |
---|
[2504] | 2158 | -variable [itcl::scope _axis(xgrid)] \ |
---|
| 2159 | -command [itcl::code $this AdjustSetting axis-xgrid] \ |
---|
[2385] | 2160 | -font "Arial 9" |
---|
[4696] | 2161 | checkbutton $inner.ygrid \ |
---|
| 2162 | -text "Y" \ |
---|
[2504] | 2163 | -variable [itcl::scope _axis(ygrid)] \ |
---|
| 2164 | -command [itcl::code $this AdjustSetting axis-ygrid] \ |
---|
[2385] | 2165 | -font "Arial 9" |
---|
[4696] | 2166 | checkbutton $inner.zgrid \ |
---|
| 2167 | -text "Z" \ |
---|
[2504] | 2168 | -variable [itcl::scope _axis(zgrid)] \ |
---|
| 2169 | -command [itcl::code $this AdjustSetting axis-zgrid] \ |
---|
[2385] | 2170 | -font "Arial 9" |
---|
[4696] | 2171 | checkbutton $inner.minorticks \ |
---|
| 2172 | -text "Minor Ticks" \ |
---|
| 2173 | -variable [itcl::scope _axis(minorticks)] \ |
---|
| 2174 | -command [itcl::code $this AdjustSetting axis-minorticks] \ |
---|
| 2175 | -font "Arial 9" |
---|
[1920] | 2176 | |
---|
[5007] | 2177 | label $inner.mode_l -text "Mode" -font "Arial 9" |
---|
[1920] | 2178 | |
---|
[2385] | 2179 | itk_component add axismode { |
---|
[2744] | 2180 | Rappture::Combobox $inner.mode -width 10 -editable no |
---|
[2385] | 2181 | } |
---|
[2474] | 2182 | $inner.mode choices insert end \ |
---|
[2385] | 2183 | "static_triad" "static" \ |
---|
| 2184 | "closest_triad" "closest" \ |
---|
[4464] | 2185 | "furthest_triad" "farthest" \ |
---|
[5007] | 2186 | "outer_edges" "outer" |
---|
[2497] | 2187 | $itk_component(axismode) value "static" |
---|
[2474] | 2188 | bind $inner.mode <<Value>> [itcl::code $this AdjustSetting axis-mode] |
---|
[2385] | 2189 | |
---|
[1920] | 2190 | blt::table $inner \ |
---|
[4696] | 2191 | 0,0 $inner.visible -anchor w -cspan 4 \ |
---|
| 2192 | 1,0 $inner.labels -anchor w -cspan 4 \ |
---|
| 2193 | 2,0 $inner.minorticks -anchor w -cspan 4 \ |
---|
| 2194 | 4,0 $inner.grid_l -anchor w \ |
---|
| 2195 | 4,1 $inner.xgrid -anchor w \ |
---|
| 2196 | 4,2 $inner.ygrid -anchor w \ |
---|
| 2197 | 4,3 $inner.zgrid -anchor w \ |
---|
| 2198 | 5,0 $inner.mode_l -anchor w -padx { 2 0 } \ |
---|
| 2199 | 5,1 $inner.mode -fill x -cspan 3 |
---|
[1920] | 2200 | |
---|
[2474] | 2201 | blt::table configure $inner r* c* -resize none |
---|
[4696] | 2202 | blt::table configure $inner r7 c6 -resize expand |
---|
| 2203 | blt::table configure $inner r3 -height 0.125i |
---|
[1920] | 2204 | } |
---|
| 2205 | |
---|
[2148] | 2206 | itcl::body Rappture::VtkViewer::BuildCameraTab {} { |
---|
| 2207 | set inner [$itk_component(main) insert end \ |
---|
| 2208 | -title "Camera Settings" \ |
---|
[2385] | 2209 | -icon [Rappture::icon camera]] |
---|
[2148] | 2210 | $inner configure -borderwidth 4 |
---|
| 2211 | |
---|
[3517] | 2212 | label $inner.view_l -text "view" -font "Arial 9" |
---|
| 2213 | set f [frame $inner.view] |
---|
| 2214 | foreach side { front back left right top bottom } { |
---|
| 2215 | button $f.$side -image [Rappture::icon view$side] \ |
---|
| 2216 | -command [itcl::code $this SetOrientation $side] |
---|
| 2217 | Rappture::Tooltip::for $f.$side "Change the view to $side" |
---|
| 2218 | pack $f.$side -side left |
---|
| 2219 | } |
---|
| 2220 | |
---|
| 2221 | blt::table $inner \ |
---|
[3534] | 2222 | 0,0 $inner.view_l -anchor e -pady 2 \ |
---|
| 2223 | 0,1 $inner.view -anchor w -pady 2 |
---|
[4772] | 2224 | blt::table configure $inner r0 -resize none |
---|
[3517] | 2225 | |
---|
[2504] | 2226 | set labels { qx qy qz qw xpan ypan zoom } |
---|
[3517] | 2227 | set row 1 |
---|
[2385] | 2228 | foreach tag $labels { |
---|
| 2229 | label $inner.${tag}label -text $tag -font "Arial 9" |
---|
| 2230 | entry $inner.${tag} -font "Arial 9" -bg white \ |
---|
[4766] | 2231 | -textvariable [itcl::scope _view(-$tag)] |
---|
[4759] | 2232 | bind $inner.${tag} <Return> \ |
---|
[4766] | 2233 | [itcl::code $this camera set -${tag}] |
---|
[4759] | 2234 | bind $inner.${tag} <KP_Enter> \ |
---|
[4766] | 2235 | [itcl::code $this camera set -${tag}] |
---|
[2385] | 2236 | blt::table $inner \ |
---|
| 2237 | $row,0 $inner.${tag}label -anchor e -pady 2 \ |
---|
| 2238 | $row,1 $inner.${tag} -anchor w -pady 2 |
---|
| 2239 | blt::table configure $inner r$row -resize none |
---|
| 2240 | incr row |
---|
| 2241 | } |
---|
[2426] | 2242 | checkbutton $inner.ortho \ |
---|
[2474] | 2243 | -text "Orthographic Projection" \ |
---|
[4766] | 2244 | -variable [itcl::scope _view(-ortho)] \ |
---|
| 2245 | -command [itcl::code $this camera set -ortho] \ |
---|
[2426] | 2246 | -font "Arial 9" |
---|
| 2247 | blt::table $inner \ |
---|
[3441] | 2248 | $row,0 $inner.ortho -cspan 2 -anchor w -pady 2 |
---|
[2426] | 2249 | blt::table configure $inner r$row -resize none |
---|
| 2250 | incr row |
---|
| 2251 | |
---|
[4772] | 2252 | blt::table configure $inner c* -resize none |
---|
[2385] | 2253 | blt::table configure $inner c2 -resize expand |
---|
| 2254 | blt::table configure $inner r$row -resize expand |
---|
| 2255 | } |
---|
[2148] | 2256 | |
---|
[2504] | 2257 | itcl::body Rappture::VtkViewer::BuildCutawayTab {} { |
---|
[2148] | 2258 | |
---|
[2504] | 2259 | set fg [option get $itk_component(hull) font Font] |
---|
[5007] | 2260 | |
---|
[2504] | 2261 | set inner [$itk_component(main) insert end \ |
---|
| 2262 | -title "Cutaway Along Axis" \ |
---|
[5007] | 2263 | -icon [Rappture::icon cutbutton]] |
---|
[2504] | 2264 | |
---|
| 2265 | $inner configure -borderwidth 4 |
---|
| 2266 | |
---|
| 2267 | # X-value slicer... |
---|
| 2268 | itk_component add xCutButton { |
---|
| 2269 | Rappture::PushButton $inner.xbutton \ |
---|
| 2270 | -onimage [Rappture::icon x-cutplane] \ |
---|
| 2271 | -offimage [Rappture::icon x-cutplane] \ |
---|
| 2272 | -command [itcl::code $this AdjustSetting axis-xcutaway] \ |
---|
| 2273 | -variable [itcl::scope _axis(xcutaway)] |
---|
| 2274 | } |
---|
| 2275 | Rappture::Tooltip::for $itk_component(xCutButton) \ |
---|
| 2276 | "Toggle the X-axis cutaway on/off" |
---|
| 2277 | |
---|
| 2278 | itk_component add xCutScale { |
---|
[3330] | 2279 | ::scale $inner.xval -from 100 -to 0 \ |
---|
[2504] | 2280 | -width 10 -orient vertical -showvalue yes \ |
---|
| 2281 | -borderwidth 1 -highlightthickness 0 \ |
---|
| 2282 | -command [itcl::code $this Slice move x] \ |
---|
| 2283 | -variable [itcl::scope _axis(xposition)] |
---|
| 2284 | } { |
---|
| 2285 | usual |
---|
| 2286 | ignore -borderwidth -highlightthickness |
---|
| 2287 | } |
---|
| 2288 | # Set the default cutaway value before disabling the scale. |
---|
| 2289 | $itk_component(xCutScale) set 100 |
---|
| 2290 | $itk_component(xCutScale) configure -state disabled |
---|
| 2291 | Rappture::Tooltip::for $itk_component(xCutScale) \ |
---|
| 2292 | "@[itcl::code $this Slice tooltip x]" |
---|
| 2293 | |
---|
| 2294 | itk_component add xDirButton { |
---|
| 2295 | Rappture::PushButton $inner.xdir \ |
---|
| 2296 | -onimage [Rappture::icon arrow-down] \ |
---|
[2744] | 2297 | -onvalue -1 \ |
---|
[2504] | 2298 | -offimage [Rappture::icon arrow-up] \ |
---|
[2744] | 2299 | -offvalue 1 \ |
---|
[2504] | 2300 | -command [itcl::code $this AdjustSetting axis-xdirection] \ |
---|
| 2301 | -variable [itcl::scope _axis(xdirection)] |
---|
| 2302 | } |
---|
[5007] | 2303 | set _axis(xdirection) -1 |
---|
[2504] | 2304 | Rappture::Tooltip::for $itk_component(xDirButton) \ |
---|
| 2305 | "Toggle the direction of the X-axis cutaway" |
---|
| 2306 | |
---|
| 2307 | # Y-value slicer... |
---|
| 2308 | itk_component add yCutButton { |
---|
| 2309 | Rappture::PushButton $inner.ybutton \ |
---|
| 2310 | -onimage [Rappture::icon y-cutplane] \ |
---|
| 2311 | -offimage [Rappture::icon y-cutplane] \ |
---|
| 2312 | -command [itcl::code $this AdjustSetting axis-ycutaway] \ |
---|
| 2313 | -variable [itcl::scope _axis(ycutaway)] |
---|
| 2314 | } |
---|
| 2315 | Rappture::Tooltip::for $itk_component(yCutButton) \ |
---|
| 2316 | "Toggle the Y-axis cutaway on/off" |
---|
| 2317 | |
---|
| 2318 | itk_component add yCutScale { |
---|
[3330] | 2319 | ::scale $inner.yval -from 100 -to 0 \ |
---|
[2504] | 2320 | -width 10 -orient vertical -showvalue yes \ |
---|
| 2321 | -borderwidth 1 -highlightthickness 0 \ |
---|
| 2322 | -command [itcl::code $this Slice move y] \ |
---|
| 2323 | -variable [itcl::scope _axis(yposition)] |
---|
| 2324 | } { |
---|
| 2325 | usual |
---|
| 2326 | ignore -borderwidth -highlightthickness |
---|
| 2327 | } |
---|
| 2328 | Rappture::Tooltip::for $itk_component(yCutScale) \ |
---|
| 2329 | "@[itcl::code $this Slice tooltip y]" |
---|
| 2330 | # Set the default cutaway value before disabling the scale. |
---|
| 2331 | $itk_component(yCutScale) set 100 |
---|
| 2332 | $itk_component(yCutScale) configure -state disabled |
---|
| 2333 | |
---|
| 2334 | itk_component add yDirButton { |
---|
| 2335 | Rappture::PushButton $inner.ydir \ |
---|
| 2336 | -onimage [Rappture::icon arrow-down] \ |
---|
[2744] | 2337 | -onvalue -1 \ |
---|
[2504] | 2338 | -offimage [Rappture::icon arrow-up] \ |
---|
[2744] | 2339 | -offvalue 1 \ |
---|
[2504] | 2340 | -command [itcl::code $this AdjustSetting axis-ydirection] \ |
---|
| 2341 | -variable [itcl::scope _axis(ydirection)] |
---|
| 2342 | } |
---|
| 2343 | Rappture::Tooltip::for $itk_component(yDirButton) \ |
---|
| 2344 | "Toggle the direction of the Y-axis cutaway" |
---|
[5007] | 2345 | set _axis(ydirection) -1 |
---|
[2504] | 2346 | |
---|
| 2347 | # Z-value slicer... |
---|
| 2348 | itk_component add zCutButton { |
---|
| 2349 | Rappture::PushButton $inner.zbutton \ |
---|
| 2350 | -onimage [Rappture::icon z-cutplane] \ |
---|
| 2351 | -offimage [Rappture::icon z-cutplane] \ |
---|
| 2352 | -command [itcl::code $this AdjustSetting axis-zcutaway] \ |
---|
| 2353 | -variable [itcl::scope _axis(zcutaway)] |
---|
| 2354 | } |
---|
| 2355 | Rappture::Tooltip::for $itk_component(zCutButton) \ |
---|
| 2356 | "Toggle the Z-axis cutaway on/off" |
---|
| 2357 | |
---|
| 2358 | itk_component add zCutScale { |
---|
[3330] | 2359 | ::scale $inner.zval -from 100 -to 0 \ |
---|
[2504] | 2360 | -width 10 -orient vertical -showvalue yes \ |
---|
| 2361 | -borderwidth 1 -highlightthickness 0 \ |
---|
| 2362 | -command [itcl::code $this Slice move z] \ |
---|
| 2363 | -variable [itcl::scope _axis(zposition)] |
---|
| 2364 | } { |
---|
| 2365 | usual |
---|
| 2366 | ignore -borderwidth -highlightthickness |
---|
| 2367 | } |
---|
| 2368 | $itk_component(zCutScale) set 100 |
---|
| 2369 | $itk_component(zCutScale) configure -state disabled |
---|
| 2370 | Rappture::Tooltip::for $itk_component(zCutScale) \ |
---|
| 2371 | "@[itcl::code $this Slice tooltip z]" |
---|
| 2372 | |
---|
| 2373 | itk_component add zDirButton { |
---|
| 2374 | Rappture::PushButton $inner.zdir \ |
---|
| 2375 | -onimage [Rappture::icon arrow-down] \ |
---|
[2744] | 2376 | -onvalue -1 \ |
---|
[2504] | 2377 | -offimage [Rappture::icon arrow-up] \ |
---|
[2744] | 2378 | -offvalue 1 \ |
---|
[2504] | 2379 | -command [itcl::code $this AdjustSetting axis-zdirection] \ |
---|
| 2380 | -variable [itcl::scope _axis(zdirection)] |
---|
| 2381 | } |
---|
[5007] | 2382 | set _axis(zdirection) -1 |
---|
[2504] | 2383 | Rappture::Tooltip::for $itk_component(zDirButton) \ |
---|
| 2384 | "Toggle the direction of the Z-axis cutaway" |
---|
| 2385 | |
---|
| 2386 | blt::table $inner \ |
---|
| 2387 | 0,0 $itk_component(xCutButton) -anchor e -padx 2 -pady 2 \ |
---|
| 2388 | 1,0 $itk_component(xCutScale) -fill y \ |
---|
| 2389 | 0,1 $itk_component(yCutButton) -anchor e -padx 2 -pady 2 \ |
---|
| 2390 | 1,1 $itk_component(yCutScale) -fill y \ |
---|
| 2391 | 0,2 $itk_component(zCutButton) -anchor e -padx 2 -pady 2 \ |
---|
| 2392 | 1,2 $itk_component(zCutScale) -fill y \ |
---|
| 2393 | |
---|
| 2394 | blt::table configure $inner r* c* -resize none |
---|
| 2395 | blt::table configure $inner r1 c3 -resize expand |
---|
| 2396 | } |
---|
| 2397 | |
---|
[3121] | 2398 | itcl::body Rappture::VtkViewer::BuildMoleculeTab {} { |
---|
| 2399 | set fg [option get $itk_component(hull) font Font] |
---|
[2504] | 2400 | |
---|
[4464] | 2401 | set inner [$itk_component(main) insert 0 \ |
---|
[3121] | 2402 | -title "Molecule Settings" \ |
---|
| 2403 | -icon [Rappture::icon molecule]] |
---|
| 2404 | $inner configure -borderwidth 4 |
---|
[2504] | 2405 | |
---|
[3121] | 2406 | checkbutton $inner.molecule \ |
---|
| 2407 | -text "Show Molecule" \ |
---|
| 2408 | -variable [itcl::scope _settings(molecule-visible)] \ |
---|
| 2409 | -command [itcl::code $this AdjustSetting molecule-visible] \ |
---|
| 2410 | -font "Arial 9" |
---|
| 2411 | |
---|
[4464] | 2412 | checkbutton $inner.outline \ |
---|
| 2413 | -text "Show Outline" \ |
---|
| 2414 | -variable [itcl::scope _settings(molecule-outline)] \ |
---|
| 2415 | -command [itcl::code $this AdjustSetting molecule-outline] \ |
---|
| 2416 | -font "Arial 9" |
---|
| 2417 | |
---|
[3121] | 2418 | checkbutton $inner.label \ |
---|
| 2419 | -text "Show Atom Labels" \ |
---|
| 2420 | -variable [itcl::scope _settings(molecule-labels)] \ |
---|
[3137] | 2421 | -command [itcl::code $this AdjustSetting molecule-labels] \ |
---|
[3121] | 2422 | -font "Arial 9" |
---|
| 2423 | |
---|
| 2424 | checkbutton $inner.wireframe \ |
---|
| 2425 | -text "Show Wireframe" \ |
---|
| 2426 | -variable [itcl::scope _settings(molecule-wireframe)] \ |
---|
| 2427 | -command [itcl::code $this AdjustSetting molecule-wireframe] \ |
---|
| 2428 | -font "Arial 9" |
---|
| 2429 | |
---|
| 2430 | checkbutton $inner.lighting \ |
---|
| 2431 | -text "Enable Lighting" \ |
---|
| 2432 | -variable [itcl::scope _settings(molecule-lighting)] \ |
---|
| 2433 | -command [itcl::code $this AdjustSetting molecule-lighting] \ |
---|
| 2434 | -font "Arial 9" |
---|
| 2435 | |
---|
| 2436 | checkbutton $inner.edges \ |
---|
| 2437 | -text "Show Edges" \ |
---|
| 2438 | -variable [itcl::scope _settings(molecule-edges)] \ |
---|
| 2439 | -command [itcl::code $this AdjustSetting molecule-edges] \ |
---|
| 2440 | -font "Arial 9" |
---|
| 2441 | |
---|
| 2442 | label $inner.rep_l -text "Molecule Representation" \ |
---|
| 2443 | -font "Arial 9" |
---|
| 2444 | |
---|
| 2445 | itk_component add representation { |
---|
| 2446 | Rappture::Combobox $inner.rep -width 20 -editable no |
---|
| 2447 | } |
---|
| 2448 | $inner.rep choices insert end \ |
---|
[3139] | 2449 | "ballandstick" "Ball and Stick" \ |
---|
[5007] | 2450 | "spheres" "Spheres" \ |
---|
| 2451 | "sticks" "Sticks" \ |
---|
| 2452 | "rods" "Rods" \ |
---|
| 2453 | "wireframe" "Wireframe" \ |
---|
| 2454 | "spacefilling" "Space Filling" |
---|
[3121] | 2455 | |
---|
| 2456 | bind $inner.rep <<Value>> \ |
---|
[3708] | 2457 | [itcl::code $this AdjustSetting molecule-representation] |
---|
[3139] | 2458 | $inner.rep value "Ball and Stick" |
---|
[3121] | 2459 | |
---|
[3800] | 2460 | label $inner.rscale_l -text "Atom Radii" \ |
---|
| 2461 | -font "Arial 9" |
---|
| 2462 | |
---|
| 2463 | itk_component add rscale { |
---|
| 2464 | Rappture::Combobox $inner.rscale -width 20 -editable no |
---|
| 2465 | } |
---|
| 2466 | $inner.rscale choices insert end \ |
---|
[5007] | 2467 | "atomic" "Atomic" \ |
---|
| 2468 | "covalent" "Covalent" \ |
---|
| 2469 | "van_der_waals" "VDW" \ |
---|
| 2470 | "none" "Constant" |
---|
[3800] | 2471 | |
---|
| 2472 | bind $inner.rscale <<Value>> \ |
---|
| 2473 | [itcl::code $this AdjustSetting molecule-rscale] |
---|
| 2474 | $inner.rscale value "Covalent" |
---|
| 2475 | |
---|
[5007] | 2476 | label $inner.palette_l -text "Palette" -font "Arial 9" |
---|
[3121] | 2477 | itk_component add moleculepalette { |
---|
| 2478 | Rappture::Combobox $inner.palette -width 10 -editable no |
---|
| 2479 | } |
---|
[4449] | 2480 | $inner.palette choices insert end [GetColormapList -includeElementDefault] |
---|
[3140] | 2481 | $itk_component(moleculepalette) value "elementDefault" |
---|
[3121] | 2482 | bind $inner.palette <<Value>> \ |
---|
| 2483 | [itcl::code $this AdjustSetting molecule-palette] |
---|
| 2484 | |
---|
[3785] | 2485 | label $inner.atomscale_l -text "Atom Scale" -font "Arial 9" |
---|
| 2486 | ::scale $inner.atomscale -width 15 -font "Arial 7" \ |
---|
[3800] | 2487 | -from 0.025 -to 2.0 -resolution 0.025 -label "" \ |
---|
[3785] | 2488 | -showvalue true -orient horizontal \ |
---|
[3800] | 2489 | -command [itcl::code $this EventuallySetAtomScale] \ |
---|
[3785] | 2490 | -variable [itcl::scope _settings(molecule-atomscale)] |
---|
| 2491 | $inner.atomscale set $_settings(molecule-atomscale) |
---|
| 2492 | Rappture::Tooltip::for $inner.atomscale \ |
---|
[3800] | 2493 | "Adjust relative scale of atoms (spheres or balls)." |
---|
[3785] | 2494 | |
---|
| 2495 | label $inner.bondscale_l -text "Bond Scale" -font "Arial 9" |
---|
| 2496 | ::scale $inner.bondscale -width 15 -font "Arial 7" \ |
---|
[3800] | 2497 | -from 0.005 -to 0.3 -resolution 0.005 -label "" \ |
---|
[3785] | 2498 | -showvalue true -orient horizontal \ |
---|
[3800] | 2499 | -command [itcl::code $this EventuallySetBondScale] \ |
---|
[3785] | 2500 | -variable [itcl::scope _settings(molecule-bondscale)] |
---|
| 2501 | Rappture::Tooltip::for $inner.bondscale \ |
---|
| 2502 | "Adjust scale of bonds (sticks)." |
---|
| 2503 | $inner.bondscale set $_settings(molecule-bondscale) |
---|
| 2504 | |
---|
[3122] | 2505 | label $inner.opacity_l -text "Opacity" -font "Arial 9" |
---|
| 2506 | ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ |
---|
| 2507 | -variable [itcl::scope _settings(molecule-opacity)] \ |
---|
[3785] | 2508 | -width 15 -font "Arial 7" \ |
---|
| 2509 | -showvalue on \ |
---|
[3800] | 2510 | -command [itcl::code $this EventuallySetMoleculeOpacity] |
---|
[3122] | 2511 | |
---|
[3800] | 2512 | label $inner.quality_l -text "Quality" -font "Arial 9" |
---|
| 2513 | ::scale $inner.quality -width 15 -font "Arial 7" \ |
---|
| 2514 | -from 0.0 -to 10.0 -resolution 0.1 -label "" \ |
---|
| 2515 | -showvalue true -orient horizontal \ |
---|
| 2516 | -command [itcl::code $this EventuallySetMoleculeQuality] \ |
---|
| 2517 | -variable [itcl::scope _settings(molecule-quality)] |
---|
| 2518 | Rappture::Tooltip::for $inner.quality \ |
---|
| 2519 | "Adjust tesselation quality" |
---|
| 2520 | $inner.quality set $_settings(molecule-quality) |
---|
| 2521 | |
---|
[3121] | 2522 | blt::table $inner \ |
---|
[3800] | 2523 | 0,0 $inner.molecule -anchor w -pady {1 0} \ |
---|
[4464] | 2524 | 1,0 $inner.outline -anchor w -pady {1 0} \ |
---|
| 2525 | 2,0 $inner.label -anchor w -pady {1 0} \ |
---|
| 2526 | 3,0 $inner.edges -anchor w -pady {1 0} \ |
---|
| 2527 | 4,0 $inner.rep_l -anchor w -pady { 2 0 } \ |
---|
| 2528 | 5,0 $inner.rep -fill x -pady 2 \ |
---|
| 2529 | 6,0 $inner.rscale_l -anchor w -pady { 2 0 } \ |
---|
| 2530 | 7,0 $inner.rscale -fill x -pady 2 \ |
---|
| 2531 | 8,0 $inner.palette_l -anchor w -pady 0 \ |
---|
| 2532 | 9,0 $inner.palette -fill x -padx 2 \ |
---|
| 2533 | 10,0 $inner.atomscale_l -anchor w -pady {3 0} \ |
---|
| 2534 | 11,0 $inner.atomscale -fill x -padx 2 \ |
---|
| 2535 | 12,0 $inner.bondscale_l -anchor w -pady {3 0} \ |
---|
| 2536 | 13,0 $inner.bondscale -fill x -padx 2 \ |
---|
| 2537 | 14,0 $inner.opacity_l -anchor w -pady {3 0} \ |
---|
| 2538 | 15,0 $inner.opacity -fill x -padx 2 \ |
---|
| 2539 | 16,0 $inner.quality_l -anchor w -pady {3 0} \ |
---|
| 2540 | 17,0 $inner.quality -fill x -padx 2 |
---|
[5007] | 2541 | |
---|
[3121] | 2542 | blt::table configure $inner r* -resize none |
---|
[4464] | 2543 | blt::table configure $inner r18 -resize expand |
---|
[3121] | 2544 | } |
---|
| 2545 | |
---|
[1920] | 2546 | # |
---|
[5007] | 2547 | # camera -- |
---|
[2385] | 2548 | # |
---|
| 2549 | itcl::body Rappture::VtkViewer::camera {option args} { |
---|
[5007] | 2550 | switch -- $option { |
---|
[2385] | 2551 | "show" { |
---|
| 2552 | puts [array get _view] |
---|
[1920] | 2553 | } |
---|
[2385] | 2554 | "set" { |
---|
[4766] | 2555 | set what [lindex $args 0] |
---|
| 2556 | set x $_view($what) |
---|
[2385] | 2557 | set code [catch { string is double $x } result] |
---|
| 2558 | if { $code != 0 || !$result } { |
---|
| 2559 | return |
---|
[1929] | 2560 | } |
---|
[4766] | 2561 | switch -- $what { |
---|
| 2562 | "-ortho" { |
---|
| 2563 | if {$_view($what)} { |
---|
[2426] | 2564 | SendCmd "camera mode ortho" |
---|
| 2565 | } else { |
---|
| 2566 | SendCmd "camera mode persp" |
---|
| 2567 | } |
---|
| 2568 | } |
---|
[4766] | 2569 | "-xpan" - "-ypan" { |
---|
[2385] | 2570 | PanCamera |
---|
[1929] | 2571 | } |
---|
[4766] | 2572 | "-qx" - "-qy" - "-qz" - "-qw" { |
---|
| 2573 | set q [ViewToQuaternion] |
---|
[2744] | 2574 | $_arcball quaternion $q |
---|
| 2575 | EventuallyRotate $q |
---|
[1929] | 2576 | } |
---|
[4766] | 2577 | "-zoom" { |
---|
| 2578 | SendCmd "camera zoom $_view($what)" |
---|
[2385] | 2579 | } |
---|
[1929] | 2580 | } |
---|
[1920] | 2581 | } |
---|
| 2582 | } |
---|
| 2583 | } |
---|
| 2584 | |
---|
[2385] | 2585 | itcl::body Rappture::VtkViewer::GetVtkData { args } { |
---|
| 2586 | set bytes "" |
---|
| 2587 | foreach dataobj [get] { |
---|
| 2588 | foreach comp [$dataobj components] { |
---|
| 2589 | set tag $dataobj-$comp |
---|
[3172] | 2590 | set contents [$dataobj data $comp] |
---|
| 2591 | append bytes "$contents\n" |
---|
[1929] | 2592 | } |
---|
[1920] | 2593 | } |
---|
[3785] | 2594 | return [list .vtk $bytes] |
---|
[2385] | 2595 | } |
---|
| 2596 | |
---|
| 2597 | itcl::body Rappture::VtkViewer::GetImage { args } { |
---|
[5007] | 2598 | if { [image width $_image(download)] > 0 && |
---|
[2744] | 2599 | [image height $_image(download)] > 0 } { |
---|
| 2600 | set bytes [$_image(download) data -format "jpeg -quality 100"] |
---|
| 2601 | set bytes [Rappture::encoding::decode -as b64 $bytes] |
---|
| 2602 | return [list .jpg $bytes] |
---|
[1920] | 2603 | } |
---|
[2385] | 2604 | return "" |
---|
| 2605 | } |
---|
| 2606 | |
---|
| 2607 | itcl::body Rappture::VtkViewer::BuildDownloadPopup { popup command } { |
---|
| 2608 | Rappture::Balloon $popup \ |
---|
| 2609 | -title "[Rappture::filexfer::label downloadWord] as..." |
---|
| 2610 | set inner [$popup component inner] |
---|
[5007] | 2611 | label $inner.summary -text "" -anchor w |
---|
[2385] | 2612 | radiobutton $inner.vtk_button -text "VTK data file" \ |
---|
| 2613 | -variable [itcl::scope _downloadPopup(format)] \ |
---|
| 2614 | -font "Helvetica 9 " \ |
---|
[5007] | 2615 | -value vtk |
---|
[2385] | 2616 | Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file." |
---|
| 2617 | radiobutton $inner.image_button -text "Image File" \ |
---|
| 2618 | -variable [itcl::scope _downloadPopup(format)] \ |
---|
[5007] | 2619 | -value image |
---|
[2385] | 2620 | Rappture::Tooltip::for $inner.image_button \ |
---|
| 2621 | "Save as digital image." |
---|
| 2622 | |
---|
| 2623 | button $inner.ok -text "Save" \ |
---|
[2744] | 2624 | -highlightthickness 0 -pady 2 -padx 3 \ |
---|
[2385] | 2625 | -command $command \ |
---|
[2744] | 2626 | -compound left \ |
---|
| 2627 | -image [Rappture::icon download] |
---|
[2385] | 2628 | |
---|
| 2629 | button $inner.cancel -text "Cancel" \ |
---|
[2744] | 2630 | -highlightthickness 0 -pady 2 -padx 3 \ |
---|
| 2631 | -command [list $popup deactivate] \ |
---|
| 2632 | -compound left \ |
---|
| 2633 | -image [Rappture::icon cancel] |
---|
[2385] | 2634 | |
---|
| 2635 | blt::table $inner \ |
---|
| 2636 | 0,0 $inner.summary -cspan 2 \ |
---|
| 2637 | 1,0 $inner.vtk_button -anchor w -cspan 2 -padx { 4 0 } \ |
---|
| 2638 | 2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \ |
---|
| 2639 | 4,1 $inner.cancel -width .9i -fill y \ |
---|
[5007] | 2640 | 4,0 $inner.ok -padx 2 -width .9i -fill y |
---|
[2385] | 2641 | blt::table configure $inner r3 -height 4 |
---|
| 2642 | blt::table configure $inner r4 -pady 4 |
---|
| 2643 | raise $inner.image_button |
---|
| 2644 | $inner.vtk_button invoke |
---|
| 2645 | return $inner |
---|
| 2646 | } |
---|
| 2647 | |
---|
| 2648 | itcl::body Rappture::VtkViewer::SetObjectStyle { dataobj comp } { |
---|
| 2649 | # Parse style string. |
---|
[2464] | 2650 | set tag $dataobj-$comp |
---|
| 2651 | set type [$dataobj type $comp] |
---|
[2489] | 2652 | set style [$dataobj style $comp] |
---|
| 2653 | if { $dataobj != $_first } { |
---|
[2744] | 2654 | set settings(-wireframe) 1 |
---|
[2489] | 2655 | } |
---|
[3785] | 2656 | switch -- $type { |
---|
| 2657 | "glyphs" { |
---|
| 2658 | array set settings { |
---|
[4464] | 2659 | -color white |
---|
| 2660 | -edgecolor black |
---|
| 2661 | -edges 0 |
---|
[3785] | 2662 | -gscale 1 |
---|
[4464] | 2663 | -lighting 1 |
---|
[3785] | 2664 | -linewidth 1.0 |
---|
[4464] | 2665 | -normscale 0 |
---|
[3785] | 2666 | -opacity 1.0 |
---|
[4464] | 2667 | -orientGlyphs 0 |
---|
| 2668 | -outline 0 |
---|
| 2669 | -ptsize 1.0 |
---|
| 2670 | -quality 1 |
---|
| 2671 | -scaleMode "vcomp" |
---|
| 2672 | -shape "sphere" |
---|
| 2673 | -visible 1 |
---|
[3785] | 2674 | -wireframe 0 |
---|
| 2675 | } |
---|
[4464] | 2676 | array set settings $style |
---|
[3785] | 2677 | set shape [$dataobj shape $comp] |
---|
[4464] | 2678 | if {$shape != ""} { |
---|
| 2679 | set settings(-shape) $shape |
---|
| 2680 | } |
---|
| 2681 | SendCmd "outline add $tag" |
---|
| 2682 | SendCmd "outline color [Color2RGB $settings(-color)] $tag" |
---|
| 2683 | SendCmd "outline visible $settings(-outline) $tag" |
---|
| 2684 | set _settings(glyphs-outline) $settings(-outline) |
---|
| 2685 | |
---|
| 2686 | SendCmd "glyphs add $settings(-shape) $tag" |
---|
| 2687 | SendCmd "glyphs normscale $settings(-normscale) $tag" |
---|
[3785] | 2688 | SendCmd "glyphs gscale $settings(-gscale) $tag" |
---|
| 2689 | SendCmd "glyphs wireframe $settings(-wireframe) $tag" |
---|
[3843] | 2690 | SendCmd "glyphs color [Color2RGB $settings(-color)] $tag" |
---|
| 2691 | #SendCmd "glyphs colormode constant {} $tag" |
---|
[4464] | 2692 | # Omitting field name for gorient and smode commands |
---|
| 2693 | # defaults to active scalars or vectors depending on mode |
---|
| 2694 | SendCmd "glyphs gorient $settings(-orientGlyphs) {} $tag" |
---|
| 2695 | SendCmd "glyphs smode $settings(-scaleMode) {} $tag" |
---|
| 2696 | SendCmd "glyphs edges $settings(-edges) $tag" |
---|
| 2697 | SendCmd "glyphs linecolor [Color2RGB $settings(-edgecolor)] $tag" |
---|
| 2698 | SendCmd "glyphs linewidth $settings(-linewidth) $tag" |
---|
| 2699 | SendCmd "glyphs ptsize $settings(-ptsize) $tag" |
---|
| 2700 | SendCmd "glyphs quality $settings(-quality) $tag" |
---|
| 2701 | SendCmd "glyphs lighting $settings(-lighting) $tag" |
---|
[3785] | 2702 | SendCmd "glyphs opacity $settings(-opacity) $tag" |
---|
[4464] | 2703 | set _settings(glyphs-opacity) [expr 100.0 * $settings(-opacity)] |
---|
[3785] | 2704 | SendCmd "glyphs visible $settings(-visible) $tag" |
---|
| 2705 | set _settings(glyphs-wireframe) $settings(-wireframe) |
---|
[2744] | 2706 | } |
---|
[3785] | 2707 | "molecule" { |
---|
[4464] | 2708 | array set settings { |
---|
| 2709 | -atomscale 0.3 |
---|
| 2710 | -atomsvisible 1 |
---|
| 2711 | -bondscale 0.075 |
---|
| 2712 | -bondstyle "cylinder" |
---|
| 2713 | -bondsvisible 1 |
---|
[4706] | 2714 | -color "elementDefault" |
---|
[4464] | 2715 | -edgecolor black |
---|
| 2716 | -edges 0 |
---|
| 2717 | -labels 0 |
---|
| 2718 | -lighting 1 |
---|
| 2719 | -linewidth 1.0 |
---|
| 2720 | -opacity 1.0 |
---|
| 2721 | -outline 0 |
---|
| 2722 | -quality 1.0 |
---|
| 2723 | -representation "" |
---|
| 2724 | -rscale "covalent" |
---|
| 2725 | -visible 1 |
---|
| 2726 | -wireframe 0 |
---|
| 2727 | } |
---|
| 2728 | array set settings $style |
---|
| 2729 | |
---|
| 2730 | SendCmd "outline add $tag" |
---|
| 2731 | SendCmd "outline color [Color2RGB white] $tag" |
---|
| 2732 | SendCmd "outline visible $settings(-outline) $tag" |
---|
| 2733 | set _settings(molecule-outline) $settings(-outline) |
---|
| 2734 | |
---|
[3785] | 2735 | SendCmd "molecule add $tag" |
---|
[4464] | 2736 | if {$settings(-representation) != ""} { |
---|
| 2737 | switch -- $settings(-representation) { |
---|
| 2738 | "ballandstick" { |
---|
| 2739 | set _settings(molecule-rscale) covalent |
---|
| 2740 | set _settings(molecule-atoms-visible) 1 |
---|
| 2741 | set _settings(molecule-bonds-visible) 1 |
---|
| 2742 | set _settings(molecule-bondstyle) cylinder |
---|
| 2743 | set _settings(molecule-atomscale) 0.3 |
---|
| 2744 | set _settings(molecule-bondscale) 0.075 |
---|
| 2745 | } |
---|
| 2746 | "balls" - "spheres" { |
---|
| 2747 | set _settings(molecule-rscale) covalent |
---|
| 2748 | set _settings(molecule-atoms-visible) 1 |
---|
| 2749 | set _settings(molecule-bonds-visible) 0 |
---|
| 2750 | set _settings(molecule-bondstyle) cylinder |
---|
| 2751 | set _settings(molecule-atomscale) 0.3 |
---|
| 2752 | set _settings(molecule-bondscale) 0.075 |
---|
| 2753 | } |
---|
| 2754 | "sticks" { |
---|
| 2755 | set _settings(molecule-rscale) none |
---|
| 2756 | set _settings(molecule-atoms-visible) 1 |
---|
| 2757 | set _settings(molecule-bonds-visible) 1 |
---|
| 2758 | set _settings(molecule-bondstyle) cylinder |
---|
| 2759 | set _settings(molecule-atomscale) 0.075 |
---|
| 2760 | set _settings(molecule-bondscale) 0.075 |
---|
| 2761 | } |
---|
| 2762 | "spacefilling" { |
---|
| 2763 | set _settings(molecule-rscale) van_der_waals |
---|
| 2764 | set _settings(molecule-atoms-visible) 1 |
---|
| 2765 | set _settings(molecule-bonds-visible) 0 |
---|
| 2766 | set _settings(molecule-bondstyle) cylinder |
---|
| 2767 | set _settings(molecule-atomscale) 1.0 |
---|
| 2768 | set _settings(molecule-bondscale) 0.075 |
---|
| 2769 | } |
---|
| 2770 | "rods" { |
---|
| 2771 | set _settings(molecule-rscale) none |
---|
| 2772 | set _settings(molecule-atoms-visible) 1 |
---|
| 2773 | set _settings(molecule-bonds-visible) 1 |
---|
| 2774 | set _settings(molecule-bondstyle) cylinder |
---|
| 2775 | set _settings(molecule-atomscale) 0.1 |
---|
| 2776 | set _settings(molecule-bondscale) 0.1 |
---|
| 2777 | } |
---|
| 2778 | "wireframe" - "lines" { |
---|
| 2779 | set _settings(molecule-rscale) none |
---|
| 2780 | set _settings(molecule-atoms-visible) 0 |
---|
| 2781 | set _settings(molecule-bonds-visible) 1 |
---|
| 2782 | set _settings(molecule-bondstyle) line |
---|
| 2783 | set _settings(molecule-atomscale) 1.0 |
---|
| 2784 | set _settings(molecule-bondscale) 1.0 |
---|
| 2785 | } |
---|
| 2786 | default { |
---|
| 2787 | error "unknown representation $value" |
---|
| 2788 | } |
---|
| 2789 | } |
---|
| 2790 | SendCmd "molecule rscale $_settings(molecule-rscale) $tag" |
---|
| 2791 | SendCmd "molecule atoms $_settings(molecule-atoms-visible) $tag" |
---|
| 2792 | SendCmd "molecule bonds $_settings(molecule-bonds-visible) $tag" |
---|
| 2793 | SendCmd "molecule bstyle $_settings(molecule-bondstyle) $tag" |
---|
| 2794 | SendCmd "molecule ascale $_settings(molecule-atomscale) $tag" |
---|
| 2795 | SendCmd "molecule bscale $_settings(molecule-bondscale) $tag" |
---|
| 2796 | $itk_component(representation) value [$itk_component(representation) label $settings(-representation)] |
---|
| 2797 | $itk_component(rscale) value [$itk_component(rscale) label $_settings(molecule-rscale)] |
---|
| 2798 | switch -- $settings(-representation) { |
---|
| 2799 | "ballandstick" - "balls" - "spheres" { |
---|
| 2800 | $itk_component(rscale) configure -state normal |
---|
| 2801 | } |
---|
| 2802 | default { |
---|
| 2803 | $itk_component(rscale) configure -state disabled |
---|
| 2804 | } |
---|
| 2805 | } |
---|
| 2806 | } else { |
---|
| 2807 | SendCmd "molecule rscale $settings(-rscale) $tag" |
---|
| 2808 | set _settings(molecule-rscale) $settings(-rscale) |
---|
| 2809 | SendCmd "molecule atoms $settings(-atomsvisible) $tag" |
---|
| 2810 | set _settings(molecule-atoms-visible) $settings(-atomsvisible) |
---|
| 2811 | SendCmd "molecule bonds $settings(-bondsvisible) $tag" |
---|
| 2812 | set _settings(molecule-bonds-visible) $settings(-bondsvisible) |
---|
| 2813 | SendCmd "molecule bstyle $settings(-bondstyle) $tag" |
---|
| 2814 | set _settings(molecule-bondstyle) $settings(-bondstyle) |
---|
| 2815 | SendCmd "molecule ascale $settings(-atomscale) $tag" |
---|
| 2816 | set _settings(molecule-atomscale) $settings(-atomscale) |
---|
| 2817 | SendCmd "molecule bscale $settings(-bondscale) $tag" |
---|
| 2818 | set _settings(molecule-bondscale) $settings(-bondscale) |
---|
| 2819 | } |
---|
| 2820 | SendCmd "molecule labels $settings(-labels) $tag" |
---|
| 2821 | set _settings(molecule-labels) $settings(-labels) |
---|
| 2822 | SendCmd "molecule linecolor [Color2RGB $settings(-edgecolor)] $tag" |
---|
| 2823 | SendCmd "molecule linewidth $settings(-linewidth) $tag" |
---|
| 2824 | SendCmd "molecule edges $settings(-edges) $tag" |
---|
| 2825 | set _settings(molecule-edges) $settings(-edges) |
---|
| 2826 | SendCmd "molecule lighting $settings(-lighting) $tag" |
---|
| 2827 | set _settings(molecule-lighting) $settings(-lighting) |
---|
| 2828 | SendCmd "molecule aquality $settings(-quality) $tag" |
---|
| 2829 | SendCmd "molecule bquality $settings(-quality) $tag" |
---|
| 2830 | set _settings(molecule-quality) $settings(-quality) |
---|
| 2831 | SendCmd "molecule visible $settings(-visible) $tag" |
---|
| 2832 | set _settings(molecule-visible) $settings(-visible) |
---|
[3785] | 2833 | set _haveMolecules 1 |
---|
[2744] | 2834 | } |
---|
[3785] | 2835 | "polydata" { |
---|
| 2836 | array set settings { |
---|
[4464] | 2837 | -cloudstyle "mesh" |
---|
| 2838 | -color white |
---|
| 2839 | -edgecolor black |
---|
[3785] | 2840 | -edges 1 |
---|
[4464] | 2841 | -lighting 1 |
---|
[3785] | 2842 | -linewidth 1.0 |
---|
| 2843 | -opacity 1.0 |
---|
[4464] | 2844 | -outline 0 |
---|
| 2845 | -visible 1 |
---|
[3785] | 2846 | -wireframe 0 |
---|
| 2847 | } |
---|
| 2848 | array set settings $style |
---|
[4464] | 2849 | |
---|
| 2850 | SendCmd "outline add $tag" |
---|
| 2851 | SendCmd "outline color [Color2RGB $settings(-color)] $tag" |
---|
| 2852 | SendCmd "outline visible $settings(-outline) $tag" |
---|
| 2853 | set _settings(polydata-outline) $settings(-outline) |
---|
| 2854 | |
---|
[3785] | 2855 | SendCmd "polydata add $tag" |
---|
| 2856 | SendCmd "polydata visible $settings(-visible) $tag" |
---|
| 2857 | set _settings(polydata-visible) $settings(-visible) |
---|
| 2858 | SendCmd "polydata edges $settings(-edges) $tag" |
---|
| 2859 | set _settings(polydata-edges) $settings(-edges) |
---|
[4464] | 2860 | SendCmd "polydata cloudstyle $settings(-cloudstyle) $tag" |
---|
[3785] | 2861 | SendCmd "polydata color [Color2RGB $settings(-color)] $tag" |
---|
[3843] | 2862 | #SendCmd "polydata colormode constant {} $tag" |
---|
[3785] | 2863 | SendCmd "polydata lighting $settings(-lighting) $tag" |
---|
| 2864 | set _settings(polydata-lighting) $settings(-lighting) |
---|
| 2865 | SendCmd "polydata linecolor [Color2RGB $settings(-edgecolor)] $tag" |
---|
| 2866 | SendCmd "polydata linewidth $settings(-linewidth) $tag" |
---|
| 2867 | SendCmd "polydata opacity $settings(-opacity) $tag" |
---|
[3800] | 2868 | set _settings(polydata-opacity) [expr 100.0 * $settings(-opacity)] |
---|
[3785] | 2869 | SendCmd "polydata wireframe $settings(-wireframe) $tag" |
---|
| 2870 | set _settings(polydata-wireframe) $settings(-wireframe) |
---|
| 2871 | set havePolyData 1 |
---|
| 2872 | } |
---|
[1920] | 2873 | } |
---|
[2489] | 2874 | SetColormap $dataobj $comp |
---|
[1920] | 2875 | } |
---|
[2385] | 2876 | |
---|
| 2877 | itcl::body Rappture::VtkViewer::IsValidObject { dataobj } { |
---|
[2387] | 2878 | if {[catch {$dataobj isa Rappture::Drawing} valid] != 0 || !$valid} { |
---|
[2744] | 2879 | return 0 |
---|
[2385] | 2880 | } |
---|
| 2881 | return 1 |
---|
| 2882 | } |
---|
[2466] | 2883 | |
---|
| 2884 | # ---------------------------------------------------------------------- |
---|
[2472] | 2885 | # USAGE: ReceiveLegend <colormap> <title> <vmin> <vmax> <size> |
---|
[2466] | 2886 | # |
---|
| 2887 | # Invoked automatically whenever the "legend" command comes in from |
---|
| 2888 | # the rendering server. Indicates that binary image data with the |
---|
| 2889 | # specified <size> will follow. |
---|
| 2890 | # ---------------------------------------------------------------------- |
---|
[2472] | 2891 | itcl::body Rappture::VtkViewer::ReceiveLegend { colormap title vmin vmax size } { |
---|
[2474] | 2892 | set _limits(vmin) $vmin |
---|
| 2893 | set _limits(vmax) $vmax |
---|
| 2894 | set _title $title |
---|
[2466] | 2895 | if { [IsConnected] } { |
---|
| 2896 | set bytes [ReceiveBytes $size] |
---|
| 2897 | if { ![info exists _image(legend)] } { |
---|
| 2898 | set _image(legend) [image create photo] |
---|
| 2899 | } |
---|
[2484] | 2900 | $_image(legend) configure -data $bytes |
---|
[2744] | 2901 | DrawLegend |
---|
[2466] | 2902 | } |
---|
| 2903 | } |
---|
| 2904 | |
---|
| 2905 | # |
---|
| 2906 | # DrawLegend -- |
---|
| 2907 | # |
---|
[2744] | 2908 | # Draws the legend in it's own canvas which resides to the right |
---|
| 2909 | # of the contour plot area. |
---|
[2466] | 2910 | # |
---|
| 2911 | itcl::body Rappture::VtkViewer::DrawLegend {} { |
---|
| 2912 | set c $itk_component(view) |
---|
| 2913 | set w [winfo width $c] |
---|
| 2914 | set h [winfo height $c] |
---|
[2484] | 2915 | set font "Arial 8" |
---|
| 2916 | set lineht [font metrics $font -linespace] |
---|
[5007] | 2917 | |
---|
[2474] | 2918 | if { $_settings(legend) } { |
---|
[2744] | 2919 | set x [expr $w - 2] |
---|
| 2920 | if { [$c find withtag "legend"] == "" } { |
---|
| 2921 | $c create image $x [expr {$lineht+2}] \ |
---|
| 2922 | -anchor ne \ |
---|
| 2923 | -image $_image(legend) -tags "colormap legend" |
---|
| 2924 | $c create text $x 2 \ |
---|
| 2925 | -anchor ne \ |
---|
| 2926 | -fill $itk_option(-plotforeground) -tags "vmax legend" \ |
---|
| 2927 | -font $font |
---|
| 2928 | $c create text $x [expr {$h-2}] \ |
---|
| 2929 | -anchor se \ |
---|
| 2930 | -fill $itk_option(-plotforeground) -tags "vmin legend" \ |
---|
| 2931 | -font $font |
---|
| 2932 | #$c bind colormap <Enter> [itcl::code $this EnterLegend %x %y] |
---|
| 2933 | $c bind colormap <Leave> [itcl::code $this LeaveLegend] |
---|
| 2934 | $c bind colormap <Motion> [itcl::code $this MotionLegend %x %y] |
---|
| 2935 | } |
---|
| 2936 | # Reset the item coordinates according the current size of the plot. |
---|
| 2937 | $c coords colormap $x [expr {$lineht+2}] |
---|
| 2938 | if { $_limits(vmin) != "" } { |
---|
| 2939 | $c itemconfigure vmin -text [format %g $_limits(vmin)] |
---|
| 2940 | } |
---|
| 2941 | if { $_limits(vmax) != "" } { |
---|
| 2942 | $c itemconfigure vmax -text [format %g $_limits(vmax)] |
---|
| 2943 | } |
---|
| 2944 | $c coords vmin $x [expr {$h-2}] |
---|
| 2945 | $c coords vmax $x 2 |
---|
[2466] | 2946 | } |
---|
| 2947 | } |
---|
[2474] | 2948 | |
---|
| 2949 | # |
---|
| 2950 | # EnterLegend -- |
---|
| 2951 | # |
---|
| 2952 | itcl::body Rappture::VtkViewer::EnterLegend { x y } { |
---|
[2476] | 2953 | SetLegendTip $x $y |
---|
[2474] | 2954 | } |
---|
| 2955 | |
---|
| 2956 | # |
---|
| 2957 | # MotionLegend -- |
---|
| 2958 | # |
---|
| 2959 | itcl::body Rappture::VtkViewer::MotionLegend { x y } { |
---|
| 2960 | Rappture::Tooltip::tooltip cancel |
---|
| 2961 | set c $itk_component(view) |
---|
[2476] | 2962 | SetLegendTip $x $y |
---|
[2474] | 2963 | } |
---|
| 2964 | |
---|
| 2965 | # |
---|
| 2966 | # LeaveLegend -- |
---|
| 2967 | # |
---|
| 2968 | itcl::body Rappture::VtkViewer::LeaveLegend { } { |
---|
| 2969 | Rappture::Tooltip::tooltip cancel |
---|
[2476] | 2970 | .rappturetooltip configure -icon "" |
---|
[2474] | 2971 | } |
---|
| 2972 | |
---|
| 2973 | # |
---|
[2476] | 2974 | # SetLegendTip -- |
---|
[2474] | 2975 | # |
---|
[2476] | 2976 | itcl::body Rappture::VtkViewer::SetLegendTip { x y } { |
---|
[2474] | 2977 | set c $itk_component(view) |
---|
| 2978 | set w [winfo width $c] |
---|
| 2979 | set h [winfo height $c] |
---|
[2484] | 2980 | set font "Arial 8" |
---|
| 2981 | set lineht [font metrics $font -linespace] |
---|
[5007] | 2982 | |
---|
[2474] | 2983 | set imgHeight [image height $_image(legend)] |
---|
| 2984 | set coords [$c coords colormap] |
---|
| 2985 | set imgX [expr $w - [image width $_image(legend)] - 2] |
---|
[2484] | 2986 | set imgY [expr $y - $lineht - 2] |
---|
[2474] | 2987 | |
---|
| 2988 | # Make a swatch of the selected color |
---|
[2476] | 2989 | if { [catch { $_image(legend) get 10 $imgY } pixel] != 0 } { |
---|
[2744] | 2990 | return |
---|
[2474] | 2991 | } |
---|
[2476] | 2992 | if { ![info exists _image(swatch)] } { |
---|
[2744] | 2993 | set _image(swatch) [image create photo -width 24 -height 24] |
---|
[2476] | 2994 | } |
---|
| 2995 | set color [eval format "\#%02x%02x%02x" $pixel] |
---|
[5007] | 2996 | $_image(swatch) put black -to 0 0 23 23 |
---|
| 2997 | $_image(swatch) put $color -to 1 1 22 22 |
---|
[2476] | 2998 | .rappturetooltip configure -icon $_image(swatch) |
---|
[2474] | 2999 | |
---|
| 3000 | # Compute the value of the point |
---|
[2485] | 3001 | set t [expr 1.0 - (double($imgY) / double($imgHeight-1))] |
---|
[2474] | 3002 | set value [expr $t * ($_limits(vmax) - $_limits(vmin)) + $_limits(vmin)] |
---|
[5007] | 3003 | set tipx [expr $x + 15] |
---|
[2474] | 3004 | set tipy [expr $y - 5] |
---|
| 3005 | Rappture::Tooltip::text $c "$_title $value" |
---|
[5007] | 3006 | Rappture::Tooltip::tooltip show $c +$tipx,+$tipy |
---|
[2474] | 3007 | } |
---|
[2504] | 3008 | |
---|
| 3009 | # ---------------------------------------------------------------------- |
---|
| 3010 | # USAGE: Slice move x|y|z <newval> |
---|
| 3011 | # |
---|
| 3012 | # Called automatically when the user drags the slider to move the |
---|
| 3013 | # cut plane that slices 3D data. Gets the current value from the |
---|
| 3014 | # slider and moves the cut plane to the appropriate point in the |
---|
| 3015 | # data set. |
---|
| 3016 | # ---------------------------------------------------------------------- |
---|
| 3017 | itcl::body Rappture::VtkViewer::Slice {option args} { |
---|
| 3018 | switch -- $option { |
---|
| 3019 | "move" { |
---|
| 3020 | set axis [lindex $args 0] |
---|
| 3021 | set newval [lindex $args 1] |
---|
| 3022 | if {[llength $args] != 2} { |
---|
| 3023 | error "wrong # args: should be \"Slice move x|y|z newval\"" |
---|
| 3024 | } |
---|
| 3025 | set newpos [expr {0.01*$newval}] |
---|
| 3026 | SendCmd "renderer clipplane $axis $newpos -1" |
---|
| 3027 | } |
---|
[2744] | 3028 | "tooltip" { |
---|
| 3029 | set axis [lindex $args 0] |
---|
| 3030 | set val [$itk_component(${axis}CutScale) get] |
---|
| 3031 | return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val%" |
---|
| 3032 | } |
---|
[2504] | 3033 | default { |
---|
| 3034 | error "bad option \"$option\": should be axis, move, or tooltip" |
---|
| 3035 | } |
---|
| 3036 | } |
---|
| 3037 | } |
---|
[3121] | 3038 | |
---|
[5007] | 3039 | itcl::body Rappture::VtkViewer::SetOrientation { side } { |
---|
[3517] | 3040 | array set positions { |
---|
| 3041 | front "1 0 0 0" |
---|
| 3042 | back "0 0 1 0" |
---|
| 3043 | left "0.707107 0 -0.707107 0" |
---|
| 3044 | right "0.707107 0 0.707107 0" |
---|
| 3045 | top "0.707107 -0.707107 0 0" |
---|
| 3046 | bottom "0.707107 0.707107 0 0" |
---|
| 3047 | } |
---|
[4766] | 3048 | foreach name { -qw -qx -qy -qz } value $positions($side) { |
---|
[3517] | 3049 | set _view($name) $value |
---|
[5007] | 3050 | } |
---|
[4766] | 3051 | set q [ViewToQuaternion] |
---|
[3517] | 3052 | $_arcball quaternion $q |
---|
[3534] | 3053 | SendCmd "camera orient $q" |
---|
| 3054 | SendCmd "camera reset" |
---|
[4766] | 3055 | set _view(-xpan) 0 |
---|
| 3056 | set _view(-ypan) 0 |
---|
| 3057 | set _view(-zoom) 1.0 |
---|
[3517] | 3058 | } |
---|
[3785] | 3059 | |
---|
[5007] | 3060 | itcl::body Rappture::VtkViewer::SetOpacity { dataset } { |
---|
[3785] | 3061 | foreach {dataobj comp} [split $dataset -] break |
---|
| 3062 | set type [$dataobj type $comp] |
---|
| 3063 | set val $_settings($type-opacity) |
---|
| 3064 | set sval [expr { 0.01 * double($val) }] |
---|
| 3065 | if { !$_obj2ovride($dataobj-raise) } { |
---|
| 3066 | # This is wrong. Need to figure out why raise isn't set with 1 |
---|
| 3067 | #set sval [expr $sval * .6] |
---|
| 3068 | } |
---|
| 3069 | SendCmd "$type opacity $sval $dataset" |
---|
[3800] | 3070 | } |
---|