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