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