1 | |
---|
2 | # ---------------------------------------------------------------------- |
---|
3 | # COMPONENT: nanovisviewer - 3D volume rendering |
---|
4 | # |
---|
5 | # This widget performs volume rendering on 3D scalar/vector datasets. |
---|
6 | # It connects to the Nanovis server running on a rendering farm, |
---|
7 | # transmits data, and displays the results. |
---|
8 | # ====================================================================== |
---|
9 | # AUTHOR: Michael McLennan, Purdue University |
---|
10 | # Copyright (c) 2004-2005 Purdue Research Foundation |
---|
11 | # |
---|
12 | # See the file "license.terms" for information on usage and |
---|
13 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
14 | # ====================================================================== |
---|
15 | package require Itk |
---|
16 | package require BLT |
---|
17 | package require Img |
---|
18 | |
---|
19 | # |
---|
20 | # FIXME: |
---|
21 | # Need to Add DX readers this client to examine the data before |
---|
22 | # it's sent to the server. This will eliminate 90% of the insanity in |
---|
23 | # computing the limits of all the volumes. I can rip out all the |
---|
24 | # "receive data" "send transfer function" event crap. |
---|
25 | # |
---|
26 | # This means we can compute the transfer function (relative values) and |
---|
27 | # draw the legend min/max values without waiting for the information to |
---|
28 | # come from the server. This will also prevent the flashing that occurs |
---|
29 | # when a new volume is drawn (using the default transfer function) and |
---|
30 | # then when the correct transfer function has been sent and linked to |
---|
31 | # the volume. |
---|
32 | # |
---|
33 | option add *NanovisViewer.width 4i widgetDefault |
---|
34 | option add *NanovisViewer*cursor crosshair widgetDefault |
---|
35 | option add *NanovisViewer.height 4i widgetDefault |
---|
36 | option add *NanovisViewer.foreground black widgetDefault |
---|
37 | option add *NanovisViewer.controlBackground gray widgetDefault |
---|
38 | option add *NanovisViewer.controlDarkBackground #999999 widgetDefault |
---|
39 | option add *NanovisViewer.plotBackground black widgetDefault |
---|
40 | option add *NanovisViewer.plotForeground white widgetDefault |
---|
41 | option add *NanovisViewer.plotOutline gray widgetDefault |
---|
42 | option add *NanovisViewer.font \ |
---|
43 | -*-helvetica-medium-r-normal-*-12-* widgetDefault |
---|
44 | |
---|
45 | # must use this name -- plugs into Rappture::resources::load |
---|
46 | proc NanovisViewer_init_resources {} { |
---|
47 | Rappture::resources::register \ |
---|
48 | nanovis_server Rappture::NanovisViewer::SetServerList |
---|
49 | } |
---|
50 | |
---|
51 | itcl::class Rappture::NanovisViewer { |
---|
52 | inherit Rappture::VisViewer |
---|
53 | |
---|
54 | itk_option define -plotforeground plotForeground Foreground "" |
---|
55 | itk_option define -plotbackground plotBackground Background "" |
---|
56 | itk_option define -plotoutline plotOutline PlotOutline "" |
---|
57 | |
---|
58 | constructor { hostlist args } { |
---|
59 | Rappture::VisViewer::constructor $hostlist |
---|
60 | } { |
---|
61 | # defined below |
---|
62 | } |
---|
63 | destructor { |
---|
64 | # defined below |
---|
65 | } |
---|
66 | public proc SetServerList { namelist } { |
---|
67 | Rappture::VisViewer::SetServerList "nanovis" $namelist |
---|
68 | } |
---|
69 | public method add {dataobj {settings ""}} |
---|
70 | public method camera {option args} |
---|
71 | public method delete {args} |
---|
72 | public method disconnect {} |
---|
73 | public method download {option args} |
---|
74 | public method get {args} |
---|
75 | public method isconnected {} |
---|
76 | public method limits { tf } |
---|
77 | public method overmarker { m x } |
---|
78 | public method sendto { string } |
---|
79 | public method parameters {title args} { |
---|
80 | # do nothing |
---|
81 | } |
---|
82 | public method rmdupmarker { m x } |
---|
83 | public method scale {args} |
---|
84 | public method updatetransferfuncs {} |
---|
85 | |
---|
86 | protected method Connect {} |
---|
87 | protected method CurrentVolumes {{what -all}} |
---|
88 | protected method Disconnect {} |
---|
89 | protected method DoResize {} |
---|
90 | protected method FixLegend {} |
---|
91 | protected method FixSettings {what {value ""}} |
---|
92 | protected method Pan {option x y} |
---|
93 | protected method Rebuild {} |
---|
94 | protected method ReceiveData { args } |
---|
95 | protected method ReceiveImage { args } |
---|
96 | protected method ReceiveLegend { tf vmin vmax size } |
---|
97 | protected method Rotate {option x y} |
---|
98 | protected method SendCmd {string} |
---|
99 | protected method SendTransferFuncs {} |
---|
100 | protected method Slice {option args} |
---|
101 | protected method SlicerTip {axis} |
---|
102 | protected method Zoom {option} |
---|
103 | |
---|
104 | # The following methods are only used by this class. |
---|
105 | private method AddIsoMarker { x y } |
---|
106 | private method BuildCameraTab {} |
---|
107 | private method BuildCutplanesTab {} |
---|
108 | private method BuildViewTab {} |
---|
109 | private method BuildVolumeTab {} |
---|
110 | private method ComputeTransferFunc { tf } |
---|
111 | private method EventuallyResize { w h } |
---|
112 | private method EventuallyResizeLegend { } |
---|
113 | private method NameTransferFunc { dataobj comp } |
---|
114 | private method PanCamera {} |
---|
115 | private method ParseLevelsOption { tf levels } |
---|
116 | private method ParseMarkersOption { tf markers } |
---|
117 | private method volume { tag name } |
---|
118 | private method GetVolumeInfo { w } |
---|
119 | |
---|
120 | private variable _outbuf ;# buffer for outgoing commands |
---|
121 | |
---|
122 | private variable _dlist "" ;# list of data objects |
---|
123 | private variable _allDataObjs |
---|
124 | private variable _obj2ovride ;# maps dataobj => style override |
---|
125 | private variable _serverVols ;# contains all the dataobj-component |
---|
126 | ;# to volumes in the server |
---|
127 | private variable _serverTfs ;# contains all the transfer functions |
---|
128 | ;# in the server. |
---|
129 | private variable _recvdVols ;# list of data objs to send to server |
---|
130 | private variable _vol2style ;# maps dataobj-component to transfunc |
---|
131 | private variable _style2vols ;# maps tf back to list of |
---|
132 | # dataobj-components using the tf. |
---|
133 | |
---|
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 _isomarkers ;# array of isosurface level values 0..1 |
---|
138 | private common _settings |
---|
139 | # Array of transfer functions in server. If 0 the transfer has been |
---|
140 | # defined but not loaded. If 1 the transfer function has been named |
---|
141 | # and loaded. |
---|
142 | private variable _activeTfs |
---|
143 | private variable _first "" ;# This is the topmost volume. |
---|
144 | private variable _buffering 0 |
---|
145 | |
---|
146 | # This |
---|
147 | # indicates which isomarkers and transfer |
---|
148 | # function to use when changing markers, |
---|
149 | # opacity, or thickness. |
---|
150 | common _downloadPopup ;# download options from popup |
---|
151 | private common _hardcopy |
---|
152 | private variable _width 0 |
---|
153 | private variable _height 0 |
---|
154 | private variable _resizePending 0 |
---|
155 | private variable _resizeLegendPending 0 |
---|
156 | } |
---|
157 | |
---|
158 | itk::usual NanovisViewer { |
---|
159 | keep -background -foreground -cursor -font |
---|
160 | keep -plotbackground -plotforeground |
---|
161 | } |
---|
162 | |
---|
163 | # ---------------------------------------------------------------------- |
---|
164 | # CONSTRUCTOR |
---|
165 | # ---------------------------------------------------------------------- |
---|
166 | itcl::body Rappture::NanovisViewer::constructor {hostlist args} { |
---|
167 | set _serverType "nanovis" |
---|
168 | |
---|
169 | # Draw legend event |
---|
170 | $_dispatcher register !legend |
---|
171 | $_dispatcher dispatch $this !legend "[itcl::code $this FixLegend]; list" |
---|
172 | |
---|
173 | # Send transfer functions event |
---|
174 | $_dispatcher register !send_transfunc |
---|
175 | $_dispatcher dispatch $this !send_transfunc \ |
---|
176 | "[itcl::code $this SendTransferFuncs]; list" |
---|
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 | set _outbuf "" |
---|
187 | |
---|
188 | # |
---|
189 | # Populate parser with commands handle incoming requests |
---|
190 | # |
---|
191 | $_parser alias image [itcl::code $this ReceiveImage] |
---|
192 | $_parser alias legend [itcl::code $this ReceiveLegend] |
---|
193 | $_parser alias data [itcl::code $this ReceiveData] |
---|
194 | |
---|
195 | # Initialize the view to some default parameters. |
---|
196 | array set _view { |
---|
197 | theta 45 |
---|
198 | phi 45 |
---|
199 | psi 0 |
---|
200 | zoom 1.0 |
---|
201 | pan-x 0 |
---|
202 | pan-y 0 |
---|
203 | } |
---|
204 | set _limits(vmin) 0.0 |
---|
205 | set _limits(vmax) 1.0 |
---|
206 | |
---|
207 | array set _settings [subst { |
---|
208 | $this-pan-x $_view(pan-x) |
---|
209 | $this-pan-y $_view(pan-y) |
---|
210 | $this-phi $_view(phi) |
---|
211 | $this-psi $_view(psi) |
---|
212 | $this-theta $_view(theta) |
---|
213 | $this-volume 1 |
---|
214 | $this-xcutplane 0 |
---|
215 | $this-xcutposition 0 |
---|
216 | $this-ycutplane 0 |
---|
217 | $this-ycutposition 0 |
---|
218 | $this-zcutplane 0 |
---|
219 | $this-zcutposition 0 |
---|
220 | $this-zoom $_view(zoom) |
---|
221 | }] |
---|
222 | |
---|
223 | itk_component add 3dview { |
---|
224 | label $itk_component(plotarea).view -image $_image(plot) \ |
---|
225 | -highlightthickness 0 -borderwidth 0 |
---|
226 | } { |
---|
227 | usual |
---|
228 | ignore -highlightthickness -borderwidth -background |
---|
229 | } |
---|
230 | |
---|
231 | set f [$itk_component(main) component controls] |
---|
232 | itk_component add reset { |
---|
233 | button $f.reset -borderwidth 1 -padx 1 -pady 1 \ |
---|
234 | -highlightthickness 0 \ |
---|
235 | -image [Rappture::icon reset-view] \ |
---|
236 | -command [itcl::code $this Zoom reset] |
---|
237 | } { |
---|
238 | usual |
---|
239 | ignore -highlightthickness |
---|
240 | } |
---|
241 | pack $itk_component(reset) -side top -padx 2 -pady 2 |
---|
242 | Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level" |
---|
243 | |
---|
244 | itk_component add zoomin { |
---|
245 | button $f.zin -borderwidth 1 -padx 1 -pady 1 \ |
---|
246 | -highlightthickness 0 \ |
---|
247 | -image [Rappture::icon zoom-in] \ |
---|
248 | -command [itcl::code $this Zoom in] |
---|
249 | } { |
---|
250 | usual |
---|
251 | ignore -highlightthickness |
---|
252 | } |
---|
253 | pack $itk_component(zoomin) -side top -padx 2 -pady 2 |
---|
254 | Rappture::Tooltip::for $itk_component(zoomin) "Zoom in" |
---|
255 | |
---|
256 | itk_component add zoomout { |
---|
257 | button $f.zout -borderwidth 1 -padx 1 -pady 1 \ |
---|
258 | -highlightthickness 0 \ |
---|
259 | -image [Rappture::icon zoom-out] \ |
---|
260 | -command [itcl::code $this Zoom out] |
---|
261 | } { |
---|
262 | usual |
---|
263 | ignore -highlightthickness |
---|
264 | } |
---|
265 | pack $itk_component(zoomout) -side top -padx 2 -pady 2 |
---|
266 | Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" |
---|
267 | |
---|
268 | itk_component add volume { |
---|
269 | Rappture::PushButton $f.volume \ |
---|
270 | -onimage [Rappture::icon volume-on] \ |
---|
271 | -offimage [Rappture::icon volume-off] \ |
---|
272 | -command [itcl::code $this FixSettings volume] \ |
---|
273 | -variable [itcl::scope _settings($this-volume)] |
---|
274 | } |
---|
275 | $itk_component(volume) select |
---|
276 | Rappture::Tooltip::for $itk_component(volume) \ |
---|
277 | "Toggle the volume cloud on/off" |
---|
278 | pack $itk_component(volume) -padx 2 -pady 2 |
---|
279 | |
---|
280 | BuildViewTab |
---|
281 | BuildVolumeTab |
---|
282 | BuildCutplanesTab |
---|
283 | BuildCameraTab |
---|
284 | |
---|
285 | # Legend |
---|
286 | |
---|
287 | set _image(legend) [image create photo] |
---|
288 | itk_component add legend { |
---|
289 | canvas $itk_component(plotarea).legend -height 50 -highlightthickness 0 |
---|
290 | } { |
---|
291 | usual |
---|
292 | ignore -highlightthickness |
---|
293 | rename -background -plotbackground plotBackground Background |
---|
294 | } |
---|
295 | bind $itk_component(legend) <Configure> \ |
---|
296 | [itcl::code $this EventuallyResizeLegend] |
---|
297 | |
---|
298 | # Hack around the Tk panewindow. The problem is that the requested |
---|
299 | # size of the 3d view isn't set until an image is retrieved from |
---|
300 | # the server. So the panewindow uses the tiny size. |
---|
301 | set w 10000 |
---|
302 | pack forget $itk_component(3dview) |
---|
303 | blt::table $itk_component(plotarea) \ |
---|
304 | 0,0 $itk_component(3dview) -fill both -reqwidth $w \ |
---|
305 | 1,0 $itk_component(legend) -fill x |
---|
306 | blt::table configure $itk_component(plotarea) r1 -resize none |
---|
307 | |
---|
308 | # Bindings for rotation via mouse |
---|
309 | bind $itk_component(3dview) <ButtonPress-1> \ |
---|
310 | [itcl::code $this Rotate click %x %y] |
---|
311 | bind $itk_component(3dview) <B1-Motion> \ |
---|
312 | [itcl::code $this Rotate drag %x %y] |
---|
313 | bind $itk_component(3dview) <ButtonRelease-1> \ |
---|
314 | [itcl::code $this Rotate release %x %y] |
---|
315 | bind $itk_component(3dview) <Configure> \ |
---|
316 | [itcl::code $this EventuallyResize %w %h] |
---|
317 | |
---|
318 | # Bindings for panning via mouse |
---|
319 | bind $itk_component(3dview) <ButtonPress-2> \ |
---|
320 | [itcl::code $this Pan click %x %y] |
---|
321 | bind $itk_component(3dview) <B2-Motion> \ |
---|
322 | [itcl::code $this Pan drag %x %y] |
---|
323 | bind $itk_component(3dview) <ButtonRelease-2> \ |
---|
324 | [itcl::code $this Pan release %x %y] |
---|
325 | |
---|
326 | # Bindings for panning via keyboard |
---|
327 | bind $itk_component(3dview) <KeyPress-Left> \ |
---|
328 | [itcl::code $this Pan set -10 0] |
---|
329 | bind $itk_component(3dview) <KeyPress-Right> \ |
---|
330 | [itcl::code $this Pan set 10 0] |
---|
331 | bind $itk_component(3dview) <KeyPress-Up> \ |
---|
332 | [itcl::code $this Pan set 0 -10] |
---|
333 | bind $itk_component(3dview) <KeyPress-Down> \ |
---|
334 | [itcl::code $this Pan set 0 10] |
---|
335 | bind $itk_component(3dview) <Shift-KeyPress-Left> \ |
---|
336 | [itcl::code $this Pan set -2 0] |
---|
337 | bind $itk_component(3dview) <Shift-KeyPress-Right> \ |
---|
338 | [itcl::code $this Pan set 2 0] |
---|
339 | bind $itk_component(3dview) <Shift-KeyPress-Up> \ |
---|
340 | [itcl::code $this Pan set 0 -2] |
---|
341 | bind $itk_component(3dview) <Shift-KeyPress-Down> \ |
---|
342 | [itcl::code $this Pan set 0 2] |
---|
343 | |
---|
344 | # Bindings for zoom via keyboard |
---|
345 | bind $itk_component(3dview) <KeyPress-Prior> \ |
---|
346 | [itcl::code $this Zoom out] |
---|
347 | bind $itk_component(3dview) <KeyPress-Next> \ |
---|
348 | [itcl::code $this Zoom in] |
---|
349 | |
---|
350 | bind $itk_component(3dview) <Enter> "focus $itk_component(3dview)" |
---|
351 | |
---|
352 | if {[string equal "x11" [tk windowingsystem]]} { |
---|
353 | # Bindings for zoom via mouse |
---|
354 | bind $itk_component(3dview) <4> [itcl::code $this Zoom out] |
---|
355 | bind $itk_component(3dview) <5> [itcl::code $this Zoom in] |
---|
356 | } |
---|
357 | |
---|
358 | set _image(download) [image create photo] |
---|
359 | |
---|
360 | eval itk_initialize $args |
---|
361 | |
---|
362 | Connect |
---|
363 | } |
---|
364 | |
---|
365 | # ---------------------------------------------------------------------- |
---|
366 | # DESTRUCTOR |
---|
367 | # ---------------------------------------------------------------------- |
---|
368 | itcl::body Rappture::NanovisViewer::destructor {} { |
---|
369 | $_dispatcher cancel !rebuild |
---|
370 | $_dispatcher cancel !send_transfunc |
---|
371 | $_dispatcher cancel !resize |
---|
372 | image delete $_image(plot) |
---|
373 | image delete $_image(legend) |
---|
374 | image delete $_image(download) |
---|
375 | array unset _settings $this-* |
---|
376 | } |
---|
377 | |
---|
378 | # ---------------------------------------------------------------------- |
---|
379 | # USAGE: add <dataobj> ?<settings>? |
---|
380 | # |
---|
381 | # Clients use this to add a data object to the plot. The optional |
---|
382 | # <settings> are used to configure the plot. Allowed settings are |
---|
383 | # -color, -brightness, -width, -linestyle, and -raise. |
---|
384 | # ---------------------------------------------------------------------- |
---|
385 | itcl::body Rappture::NanovisViewer::add {dataobj {settings ""}} { |
---|
386 | array set params { |
---|
387 | -color auto |
---|
388 | -width 1 |
---|
389 | -linestyle solid |
---|
390 | -brightness 0 |
---|
391 | -raise 0 |
---|
392 | -description "" |
---|
393 | -param "" |
---|
394 | } |
---|
395 | foreach {opt val} $settings { |
---|
396 | if {![info exists params($opt)]} { |
---|
397 | error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]" |
---|
398 | } |
---|
399 | set params($opt) $val |
---|
400 | } |
---|
401 | if {$params(-color) == "auto" || $params(-color) == "autoreset"} { |
---|
402 | # can't handle -autocolors yet |
---|
403 | set params(-color) black |
---|
404 | } |
---|
405 | set pos [lsearch -exact $dataobj $_dlist] |
---|
406 | if {$pos < 0} { |
---|
407 | lappend _dlist $dataobj |
---|
408 | set _allDataObjs($dataobj) 1 |
---|
409 | set _obj2ovride($dataobj-color) $params(-color) |
---|
410 | set _obj2ovride($dataobj-width) $params(-width) |
---|
411 | set _obj2ovride($dataobj-raise) $params(-raise) |
---|
412 | $_dispatcher event -idle !rebuild |
---|
413 | } |
---|
414 | } |
---|
415 | |
---|
416 | # ---------------------------------------------------------------------- |
---|
417 | # USAGE: get ?-objects? |
---|
418 | # USAGE: get ?-image 3dview|legend? |
---|
419 | # |
---|
420 | # Clients use this to query the list of objects being plotted, in |
---|
421 | # order from bottom to top of this result. The optional "-image" |
---|
422 | # flag can also request the internal images being shown. |
---|
423 | # ---------------------------------------------------------------------- |
---|
424 | itcl::body Rappture::NanovisViewer::get {args} { |
---|
425 | if {[llength $args] == 0} { |
---|
426 | set args "-objects" |
---|
427 | } |
---|
428 | |
---|
429 | set op [lindex $args 0] |
---|
430 | switch -- $op { |
---|
431 | -objects { |
---|
432 | # put the dataobj list in order according to -raise options |
---|
433 | set dlist $_dlist |
---|
434 | foreach obj $dlist { |
---|
435 | if {[info exists _obj2ovride($obj-raise)] && $_obj2ovride($obj-raise)} { |
---|
436 | set i [lsearch -exact $dlist $obj] |
---|
437 | if {$i >= 0} { |
---|
438 | set dlist [lreplace $dlist $i $i] |
---|
439 | lappend dlist $obj |
---|
440 | } |
---|
441 | } |
---|
442 | } |
---|
443 | return $dlist |
---|
444 | } |
---|
445 | -image { |
---|
446 | if {[llength $args] != 2} { |
---|
447 | error "wrong # args: should be \"get -image 3dview|legend\"" |
---|
448 | } |
---|
449 | switch -- [lindex $args end] { |
---|
450 | 3dview { |
---|
451 | return $_image(plot) |
---|
452 | } |
---|
453 | legend { |
---|
454 | return $_image(legend) |
---|
455 | } |
---|
456 | default { |
---|
457 | error "bad image name \"[lindex $args end]\": should be 3dview or legend" |
---|
458 | } |
---|
459 | } |
---|
460 | } |
---|
461 | default { |
---|
462 | error "bad option \"$op\": should be -objects or -image" |
---|
463 | } |
---|
464 | } |
---|
465 | } |
---|
466 | |
---|
467 | # ---------------------------------------------------------------------- |
---|
468 | # USAGE: delete ?<dataobj1> <dataobj2> ...? |
---|
469 | # |
---|
470 | # Clients use this to delete a dataobj from the plot. If no dataobjs |
---|
471 | # are specified, then all dataobjs are deleted. No data objects are |
---|
472 | # deleted. They are only removed from the display list. |
---|
473 | # |
---|
474 | # ---------------------------------------------------------------------- |
---|
475 | itcl::body Rappture::NanovisViewer::delete {args} { |
---|
476 | if {[llength $args] == 0} { |
---|
477 | set args $_dlist |
---|
478 | } |
---|
479 | # Delete all specified dataobjs |
---|
480 | set changed 0 |
---|
481 | foreach dataobj $args { |
---|
482 | set pos [lsearch -exact $_dlist $dataobj] |
---|
483 | if { $pos >= 0 } { |
---|
484 | set _dlist [lreplace $_dlist $pos $pos] |
---|
485 | array unset _limits $dataobj* |
---|
486 | array unset _obj2ovride $dataobj-* |
---|
487 | array unset _vol2style $dataobj-* |
---|
488 | set changed 1 |
---|
489 | } |
---|
490 | } |
---|
491 | # If anything changed, then rebuild the plot |
---|
492 | if {$changed} { |
---|
493 | $_dispatcher event -idle !rebuild |
---|
494 | } |
---|
495 | } |
---|
496 | |
---|
497 | # ---------------------------------------------------------------------- |
---|
498 | # USAGE: scale ?<data1> <data2> ...? |
---|
499 | # |
---|
500 | # Sets the default limits for the overall plot according to the |
---|
501 | # limits of the data for all of the given <data> objects. This |
---|
502 | # accounts for all objects--even those not showing on the screen. |
---|
503 | # Because of this, the limits are appropriate for all objects as |
---|
504 | # the user scans through data in the ResultSet viewer. |
---|
505 | # ---------------------------------------------------------------------- |
---|
506 | itcl::body Rappture::NanovisViewer::scale {args} { |
---|
507 | foreach val {xmin xmax ymin ymax zmin zmax vmin vmax} { |
---|
508 | set _limits($val) "" |
---|
509 | } |
---|
510 | foreach obj $args { |
---|
511 | foreach axis {x y z v} { |
---|
512 | |
---|
513 | foreach { min max } [$obj limits $axis] break |
---|
514 | |
---|
515 | if {"" != $min && "" != $max} { |
---|
516 | if {"" == $_limits(${axis}min)} { |
---|
517 | set _limits(${axis}min) $min |
---|
518 | set _limits(${axis}max) $max |
---|
519 | } else { |
---|
520 | if {$min < $_limits(${axis}min)} { |
---|
521 | set _limits(${axis}min) $min |
---|
522 | } |
---|
523 | if {$max > $_limits(${axis}max)} { |
---|
524 | set _limits(${axis}max) $max |
---|
525 | } |
---|
526 | } |
---|
527 | } |
---|
528 | } |
---|
529 | } |
---|
530 | } |
---|
531 | |
---|
532 | # ---------------------------------------------------------------------- |
---|
533 | # USAGE: download coming |
---|
534 | # USAGE: download controls <downloadCommand> |
---|
535 | # USAGE: download now |
---|
536 | # |
---|
537 | # Clients use this method to create a downloadable representation |
---|
538 | # of the plot. Returns a list of the form {ext string}, where |
---|
539 | # "ext" is the file extension (indicating the type of data) and |
---|
540 | # "string" is the data itself. |
---|
541 | # ---------------------------------------------------------------------- |
---|
542 | itcl::body Rappture::NanovisViewer::download {option args} { |
---|
543 | switch $option { |
---|
544 | coming { |
---|
545 | if {[catch { |
---|
546 | blt::winop snap $itk_component(plotarea) $_image(download) |
---|
547 | }]} { |
---|
548 | $_image(download) configure -width 1 -height 1 |
---|
549 | $_image(download) put #000000 |
---|
550 | } |
---|
551 | } |
---|
552 | controls { |
---|
553 | # no controls for this download yet |
---|
554 | return "" |
---|
555 | } |
---|
556 | now { |
---|
557 | # Get the image data (as base64) and decode it back to binary. |
---|
558 | # This is better than writing to temporary files. When we switch |
---|
559 | # to the BLT picture image it won't be necessary to decode the |
---|
560 | # image data. |
---|
561 | if { [image width $_image(plot)] > 0 && |
---|
562 | [image height $_image(plot)] > 0 } { |
---|
563 | set bytes [$_image(plot) data -format "jpeg -quality 100"] |
---|
564 | set bytes [Rappture::encoding::decode -as b64 $bytes] |
---|
565 | return [list .jpg $bytes] |
---|
566 | } |
---|
567 | return "" |
---|
568 | } |
---|
569 | default { |
---|
570 | error "bad option \"$option\": should be coming, controls, now" |
---|
571 | } |
---|
572 | } |
---|
573 | } |
---|
574 | |
---|
575 | # ---------------------------------------------------------------------- |
---|
576 | # USAGE: Connect ?<host:port>,<host:port>...? |
---|
577 | # |
---|
578 | # Clients use this method to establish a connection to a new |
---|
579 | # server, or to reestablish a connection to the previous server. |
---|
580 | # Any existing connection is automatically closed. |
---|
581 | # ---------------------------------------------------------------------- |
---|
582 | itcl::body Rappture::NanovisViewer::Connect {} { |
---|
583 | set _hosts [GetServerList "nanovis"] |
---|
584 | if { "" == $_hosts } { |
---|
585 | return 0 |
---|
586 | } |
---|
587 | set result [VisViewer::Connect $_hosts] |
---|
588 | if { $result } { |
---|
589 | set w [winfo width $itk_component(3dview)] |
---|
590 | set h [winfo height $itk_component(3dview)] |
---|
591 | EventuallyResize $w $h |
---|
592 | } |
---|
593 | return $result |
---|
594 | } |
---|
595 | |
---|
596 | # |
---|
597 | # isconnected -- |
---|
598 | # |
---|
599 | # Indicates if we are currently connected to the visualization server. |
---|
600 | # |
---|
601 | itcl::body Rappture::NanovisViewer::isconnected {} { |
---|
602 | return [VisViewer::IsConnected] |
---|
603 | } |
---|
604 | |
---|
605 | # |
---|
606 | # disconnect -- |
---|
607 | # |
---|
608 | itcl::body Rappture::NanovisViewer::disconnect {} { |
---|
609 | Disconnect |
---|
610 | } |
---|
611 | |
---|
612 | # |
---|
613 | # Disconnect -- |
---|
614 | # |
---|
615 | # Clients use this method to disconnect from the current rendering |
---|
616 | # server. |
---|
617 | # |
---|
618 | itcl::body Rappture::NanovisViewer::Disconnect {} { |
---|
619 | VisViewer::Disconnect |
---|
620 | |
---|
621 | # disconnected -- no more data sitting on server |
---|
622 | set _outbuf "" |
---|
623 | array unset _serverVols |
---|
624 | } |
---|
625 | |
---|
626 | # |
---|
627 | # sendto -- |
---|
628 | # |
---|
629 | itcl::body Rappture::NanovisViewer::sendto { bytes } { |
---|
630 | SendBytes "$bytes\n" |
---|
631 | } |
---|
632 | |
---|
633 | # |
---|
634 | # SendCmd |
---|
635 | # |
---|
636 | # Send commands off to the rendering server. If we're currently |
---|
637 | # sending data objects to the server, buffer the commands to be |
---|
638 | # sent later. |
---|
639 | # |
---|
640 | itcl::body Rappture::NanovisViewer::SendCmd {string} { |
---|
641 | if { $_buffering } { |
---|
642 | append _outbuf $string "\n" |
---|
643 | } else { |
---|
644 | foreach line [split $string \n] { |
---|
645 | SendEcho >>line $line |
---|
646 | } |
---|
647 | SendBytes "$string\n" |
---|
648 | } |
---|
649 | } |
---|
650 | |
---|
651 | |
---|
652 | # ---------------------------------------------------------------------- |
---|
653 | # USAGE: SendTransferFuncs |
---|
654 | # ---------------------------------------------------------------------- |
---|
655 | itcl::body Rappture::NanovisViewer::SendTransferFuncs {} { |
---|
656 | if { $_first == "" } { |
---|
657 | puts stderr "first not set" |
---|
658 | return |
---|
659 | } |
---|
660 | # Insure that the global opacity and thickness settings (in the slider |
---|
661 | # settings widgets) are used for the active transfer-function. Update |
---|
662 | # the values in the _settings varible. |
---|
663 | set opacity [expr { double($_settings($this-opacity)) * 0.01 }] |
---|
664 | # Scale values between 0.00001 and 0.01000 |
---|
665 | set thickness [expr {double($_settings($this-thickness)) * 0.0001}] |
---|
666 | |
---|
667 | foreach vol [CurrentVolumes] { |
---|
668 | if { ![info exists _serverVols($vol)] || !$_serverVols($vol) } { |
---|
669 | # The volume hasn't reached the server yet. How did we get |
---|
670 | # here? |
---|
671 | continue |
---|
672 | } |
---|
673 | if { ![info exists _vol2style($vol)] } { |
---|
674 | puts stderr "unknown volume $vol" |
---|
675 | continue; # How does this happen? |
---|
676 | } |
---|
677 | set tf $_vol2style($vol) |
---|
678 | set _settings($this-$tf-opacity) $opacity |
---|
679 | set _settings($this-$tf-thickness) $thickness |
---|
680 | ComputeTransferFunc $tf |
---|
681 | # FIXME: Need to the send information as to what transfer functions |
---|
682 | # to update so that we only update the transfer function |
---|
683 | # as necessary. Right now, all transfer functions are |
---|
684 | # updated. This makes moving the isomarker slider chunky. |
---|
685 | if { ![info exists _activeTfs($tf)] || !$_activeTfs($tf) } { |
---|
686 | set _activeTfs($tf) 1 |
---|
687 | } |
---|
688 | SendCmd "volume shading transfunc $tf $vol" |
---|
689 | } |
---|
690 | FixLegend |
---|
691 | } |
---|
692 | |
---|
693 | # ---------------------------------------------------------------------- |
---|
694 | # USAGE: ReceiveImage -bytes <size> -type <type> -token <token> |
---|
695 | # |
---|
696 | # Invoked automatically whenever the "image" command comes in from |
---|
697 | # the rendering server. Indicates that binary image data with the |
---|
698 | # specified <size> will follow. |
---|
699 | # ---------------------------------------------------------------------- |
---|
700 | itcl::body Rappture::NanovisViewer::ReceiveImage { args } { |
---|
701 | array set info { |
---|
702 | -token "???" |
---|
703 | -bytes 0 |
---|
704 | -type image |
---|
705 | } |
---|
706 | array set info $args |
---|
707 | set bytes [ReceiveBytes $info(-bytes)] |
---|
708 | ReceiveEcho <<line "<read $info(-bytes) bytes" |
---|
709 | if { $info(-type) == "image" } { |
---|
710 | ReceiveEcho "for [image width $_image(plot)]x[image height $_image(plot)] image>" |
---|
711 | $_image(plot) configure -data $bytes |
---|
712 | } elseif { $info(type) == "print" } { |
---|
713 | set tag $this-print-$info(-token) |
---|
714 | set _hardcopy($tag) $bytes |
---|
715 | } |
---|
716 | } |
---|
717 | |
---|
718 | # |
---|
719 | # ReceiveLegend -- |
---|
720 | # |
---|
721 | # The procedure is the response from the render server to each "legend" |
---|
722 | # command. The server sends back a "legend" command invoked our |
---|
723 | # the slave interpreter. The purpose is to collect data of the image |
---|
724 | # representing the legend in the canvas. In addition, the isomarkers |
---|
725 | # of the active transfer function are displayed. |
---|
726 | # |
---|
727 | # I don't know is this is the right place to display the isomarkers. |
---|
728 | # I don't know all the different paths used to draw the plot. There's |
---|
729 | # "Rebuild", "add", etc. |
---|
730 | # |
---|
731 | itcl::body Rappture::NanovisViewer::ReceiveLegend { tf vmin vmax size } { |
---|
732 | if { ![isconnected] } { |
---|
733 | return |
---|
734 | } |
---|
735 | set bytes [ReceiveBytes $size] |
---|
736 | $_image(legend) configure -data $bytes |
---|
737 | ReceiveEcho <<line "<read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>" |
---|
738 | |
---|
739 | set c $itk_component(legend) |
---|
740 | set w [winfo width $c] |
---|
741 | set h [winfo height $c] |
---|
742 | set lx 10 |
---|
743 | set ly [expr {$h - 1}] |
---|
744 | if {"" == [$c find withtag transfunc]} { |
---|
745 | $c create image 10 10 -anchor nw \ |
---|
746 | -image $_image(legend) -tags transfunc |
---|
747 | $c create text $lx $ly -anchor sw \ |
---|
748 | -fill $itk_option(-plotforeground) -tags "limits vmin" |
---|
749 | $c create text [expr {$w-$lx}] $ly -anchor se \ |
---|
750 | -fill $itk_option(-plotforeground) -tags "limits vmax" |
---|
751 | $c lower transfunc |
---|
752 | $c bind transfunc <ButtonRelease-1> \ |
---|
753 | [itcl::code $this AddIsoMarker %x %y] |
---|
754 | } |
---|
755 | # Display the markers used by the active transfer function. |
---|
756 | |
---|
757 | array set limits [limits $tf] |
---|
758 | $c itemconfigure vmin -text [format %.2g $limits(min)] |
---|
759 | $c coords vmin $lx $ly |
---|
760 | |
---|
761 | $c itemconfigure vmax -text [format %.2g $limits(max)] |
---|
762 | $c coords vmax [expr {$w-$lx}] $ly |
---|
763 | |
---|
764 | if { [info exists _isomarkers($tf)] } { |
---|
765 | foreach m $_isomarkers($tf) { |
---|
766 | $m visible yes |
---|
767 | } |
---|
768 | } |
---|
769 | |
---|
770 | # The colormap may have changed. Resync the slicers with the colormap. |
---|
771 | set vols [CurrentVolumes -cutplanes] |
---|
772 | SendCmd "volume data state $_settings($this-volume) $vols" |
---|
773 | |
---|
774 | # Adjust the cutplane for only the first component in the topmost volume |
---|
775 | # (i.e. the first volume designated in the field). |
---|
776 | set vol [lindex $vols 0] |
---|
777 | foreach axis {x y z} { |
---|
778 | # Turn off cutplanes for all volumes |
---|
779 | SendCmd "cutplane state 0 $axis" |
---|
780 | if { $_settings($this-${axis}cutplane) } { |
---|
781 | # Turn on cutplane for this particular volume and set the position |
---|
782 | SendCmd "cutplane state 1 $axis $vol" |
---|
783 | set pos [expr {0.01*$_settings($this-${axis}cutposition)}] |
---|
784 | SendCmd "cutplane position $pos $axis $vol" |
---|
785 | } |
---|
786 | } |
---|
787 | } |
---|
788 | |
---|
789 | # |
---|
790 | # ReceiveData -- |
---|
791 | # |
---|
792 | # The procedure is the response from the render server to each "data |
---|
793 | # follows" command. The server sends back a "data" command invoked our |
---|
794 | # the slave interpreter. The purpose is to collect the min/max of the |
---|
795 | # volume sent to the render server. Since the client (nanovisviewer) |
---|
796 | # doesn't parse 3D data formats, we rely on the server (nanovis) to |
---|
797 | # tell us what the limits are. Once we've received the limits to all |
---|
798 | # the data we've sent (tracked by _recvdVols) we can then determine |
---|
799 | # what the transfer functions are for these volumes. |
---|
800 | # |
---|
801 | # |
---|
802 | # Note: There is a considerable tradeoff in having the server report |
---|
803 | # back what the data limits are. It means that much of the code |
---|
804 | # having to do with transfer-functions has to wait for the data |
---|
805 | # to come back, since the isomarkers are calculated based upon |
---|
806 | # the data limits. The client code is much messier because of |
---|
807 | # this. The alternative is to parse any of the 3D formats on the |
---|
808 | # client side. |
---|
809 | # |
---|
810 | itcl::body Rappture::NanovisViewer::ReceiveData { args } { |
---|
811 | if { ![isconnected] } { |
---|
812 | return |
---|
813 | } |
---|
814 | # Arguments from server are name value pairs. Stuff them in an array. |
---|
815 | array set info $args |
---|
816 | |
---|
817 | set tag $info(tag) |
---|
818 | set parts [split $tag -] |
---|
819 | |
---|
820 | # |
---|
821 | # Volumes don't exist until we're told about them. |
---|
822 | # |
---|
823 | set dataobj [lindex $parts 0] |
---|
824 | set _serverVols($tag) 1 |
---|
825 | if { $_settings($this-volume) && $dataobj == $_first } { |
---|
826 | SendCmd "volume state 1 $tag" |
---|
827 | } |
---|
828 | set _limits($tag-min) $info(min); # Minimum value of the volume. |
---|
829 | set _limits($tag-max) $info(max); # Maximum value of the volume. |
---|
830 | set _limits(vmin) $info(vmin); # Overall minimum value. |
---|
831 | set _limits(vmax) $info(vmax); # Overall maximum value. |
---|
832 | |
---|
833 | unset _recvdVols($tag) |
---|
834 | if { [array size _recvdVols] == 0 } { |
---|
835 | # The active transfer function is by default the first component of |
---|
836 | # the first data object. This assumes that the data is always |
---|
837 | # successfully transferred. |
---|
838 | updatetransferfuncs |
---|
839 | } |
---|
840 | } |
---|
841 | |
---|
842 | # ---------------------------------------------------------------------- |
---|
843 | # USAGE: Rebuild |
---|
844 | # |
---|
845 | # Called automatically whenever something changes that affects the |
---|
846 | # data in the widget. Clears any existing data and rebuilds the |
---|
847 | # widget to display new data. |
---|
848 | # ---------------------------------------------------------------------- |
---|
849 | itcl::body Rappture::NanovisViewer::Rebuild {} { |
---|
850 | |
---|
851 | # Turn on buffering of commands to the server. We don't want to |
---|
852 | # be preempted by a server disconnect/reconnect (which automatically |
---|
853 | # generates a new call to Rebuild). |
---|
854 | set _buffering 1 |
---|
855 | |
---|
856 | # Hide all the isomarkers. Can't remove them. Have to remember the |
---|
857 | # settings since the user may have created/deleted/moved markers. |
---|
858 | |
---|
859 | foreach tf [array names _isomarkers] { |
---|
860 | foreach m $_isomarkers($tf) { |
---|
861 | $m visible no |
---|
862 | } |
---|
863 | } |
---|
864 | |
---|
865 | set w [winfo width $itk_component(3dview)] |
---|
866 | set h [winfo height $itk_component(3dview)] |
---|
867 | EventuallyResize $w $h |
---|
868 | |
---|
869 | foreach dataobj [get] { |
---|
870 | foreach comp [$dataobj components] { |
---|
871 | set vol $dataobj-$comp |
---|
872 | if { ![info exists _serverVols($vol)] } { |
---|
873 | # Send the data as one huge base64-encoded mess -- yuck! |
---|
874 | set data [$dataobj values $comp] |
---|
875 | set nbytes [string length $data] |
---|
876 | append _outbuf "volume data follows $nbytes $vol\n" |
---|
877 | append _outbuf $data |
---|
878 | set _recvdVols($vol) 1 |
---|
879 | set _serverVols($vol) 0 |
---|
880 | } |
---|
881 | NameTransferFunc $dataobj $comp |
---|
882 | } |
---|
883 | } |
---|
884 | # |
---|
885 | # Reset the camera and other view parameters |
---|
886 | # |
---|
887 | |
---|
888 | set _settings($this-theta) $_view(theta) |
---|
889 | set _settings($this-phi) $_view(phi) |
---|
890 | set _settings($this-psi) $_view(psi) |
---|
891 | set _settings($this-pan-x) $_view(pan-x) |
---|
892 | set _settings($this-pan-y) $_view(pan-y) |
---|
893 | set _settings($this-zoom) $_view(zoom) |
---|
894 | |
---|
895 | set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] |
---|
896 | SendCmd "camera angle $xyz" |
---|
897 | PanCamera |
---|
898 | SendCmd "camera zoom $_view(zoom)" |
---|
899 | FixSettings light |
---|
900 | FixSettings transp |
---|
901 | FixSettings isosurface |
---|
902 | FixSettings grid |
---|
903 | FixSettings axes |
---|
904 | FixSettings outline |
---|
905 | |
---|
906 | # nothing to send -- activate the proper ivol |
---|
907 | SendCmd "volume state 0" |
---|
908 | set _first [lindex [get] 0] |
---|
909 | if {"" != $_first} { |
---|
910 | set axis [$_first hints updir] |
---|
911 | if { "" != $axis } { |
---|
912 | SendCmd "up $axis" |
---|
913 | } |
---|
914 | set location [$_first hints camera] |
---|
915 | if { $location != "" } { |
---|
916 | array set _view $location |
---|
917 | } |
---|
918 | set vols [array names _serverVols $_first-*] |
---|
919 | if { $vols != "" } { |
---|
920 | SendCmd "volume state 1 $vols" |
---|
921 | } |
---|
922 | } |
---|
923 | # If the first volume already exists on the server, then make sure we |
---|
924 | # display the proper transfer function in the legend. |
---|
925 | set comp [lindex [$_first components] 0] |
---|
926 | if { [info exists _serverVols($_first-$comp)] } { |
---|
927 | updatetransferfuncs |
---|
928 | } |
---|
929 | foreach axis {x y z} { |
---|
930 | # Turn off cutplanes for all volumes |
---|
931 | SendCmd "cutplane state 0 $axis" |
---|
932 | } |
---|
933 | set _buffering 0; # Turn off buffering. |
---|
934 | # Actually write the commands to the server socket. If it fails, we don't |
---|
935 | # care. We're finished here. |
---|
936 | blt::busy hold $itk_component(hull) |
---|
937 | SendBytes $_outbuf; |
---|
938 | blt::busy release $itk_component(hull) |
---|
939 | set _outbuf ""; # Clear the buffer. |
---|
940 | } |
---|
941 | |
---|
942 | # ---------------------------------------------------------------------- |
---|
943 | # USAGE: CurrentVolumes ?-cutplanes? |
---|
944 | # |
---|
945 | # Returns a list of volume server IDs for the current volume being |
---|
946 | # displayed. This is normally a single ID, but it might be a list |
---|
947 | # of IDs if the current data object has multiple components. |
---|
948 | # ---------------------------------------------------------------------- |
---|
949 | itcl::body Rappture::NanovisViewer::CurrentVolumes {{what -all}} { |
---|
950 | set rlist "" |
---|
951 | if { $_first == "" } { |
---|
952 | return |
---|
953 | } |
---|
954 | foreach comp [$_first components] { |
---|
955 | set vol $_first-$comp |
---|
956 | if { [info exists _serverVols($vol)] && $_serverVols($vol) } { |
---|
957 | array set style { |
---|
958 | -cutplanes 1 |
---|
959 | } |
---|
960 | array set style [lindex [$_first components -style $comp] 0] |
---|
961 | if { $what != "-cutplanes" || $style(-cutplanes) } { |
---|
962 | lappend rlist $vol |
---|
963 | } |
---|
964 | } |
---|
965 | } |
---|
966 | return $rlist |
---|
967 | } |
---|
968 | |
---|
969 | # ---------------------------------------------------------------------- |
---|
970 | # USAGE: Zoom in |
---|
971 | # USAGE: Zoom out |
---|
972 | # USAGE: Zoom reset |
---|
973 | # |
---|
974 | # Called automatically when the user clicks on one of the zoom |
---|
975 | # controls for this widget. Changes the zoom for the current view. |
---|
976 | # ---------------------------------------------------------------------- |
---|
977 | itcl::body Rappture::NanovisViewer::Zoom {option} { |
---|
978 | switch -- $option { |
---|
979 | "in" { |
---|
980 | set _view(zoom) [expr {$_view(zoom)*1.25}] |
---|
981 | set _settings($this-zoom) $_view(zoom) |
---|
982 | } |
---|
983 | "out" { |
---|
984 | set _view(zoom) [expr {$_view(zoom)*0.8}] |
---|
985 | set _settings($this-zoom) $_view(zoom) |
---|
986 | } |
---|
987 | "reset" { |
---|
988 | array set _view { |
---|
989 | theta 45 |
---|
990 | phi 45 |
---|
991 | psi 0 |
---|
992 | zoom 1.0 |
---|
993 | pan-x 0 |
---|
994 | pan-y 0 |
---|
995 | } |
---|
996 | if { $_first != "" } { |
---|
997 | set location [$_first hints camera] |
---|
998 | if { $location != "" } { |
---|
999 | array set _view $location |
---|
1000 | } |
---|
1001 | } |
---|
1002 | set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] |
---|
1003 | SendCmd "camera angle $xyz" |
---|
1004 | PanCamera |
---|
1005 | set _settings($this-theta) $_view(theta) |
---|
1006 | set _settings($this-phi) $_view(phi) |
---|
1007 | set _settings($this-psi) $_view(psi) |
---|
1008 | set _settings($this-pan-x) $_view(pan-x) |
---|
1009 | set _settings($this-pan-y) $_view(pan-y) |
---|
1010 | set _settings($this-zoom) $_view(zoom) |
---|
1011 | } |
---|
1012 | } |
---|
1013 | SendCmd "camera zoom $_view(zoom)" |
---|
1014 | } |
---|
1015 | |
---|
1016 | itcl::body Rappture::NanovisViewer::PanCamera {} { |
---|
1017 | #set x [expr ($_view(pan-x)) / $_limits(xrange)] |
---|
1018 | #set y [expr ($_view(pan-y)) / $_limits(yrange)] |
---|
1019 | set x $_view(pan-x) |
---|
1020 | set y $_view(pan-y) |
---|
1021 | SendCmd "camera pan $x $y" |
---|
1022 | } |
---|
1023 | |
---|
1024 | |
---|
1025 | # ---------------------------------------------------------------------- |
---|
1026 | # USAGE: Rotate click <x> <y> |
---|
1027 | # USAGE: Rotate drag <x> <y> |
---|
1028 | # USAGE: Rotate release <x> <y> |
---|
1029 | # |
---|
1030 | # Called automatically when the user clicks/drags/releases in the |
---|
1031 | # plot area. Moves the plot according to the user's actions. |
---|
1032 | # ---------------------------------------------------------------------- |
---|
1033 | itcl::body Rappture::NanovisViewer::Rotate {option x y} { |
---|
1034 | switch -- $option { |
---|
1035 | click { |
---|
1036 | $itk_component(3dview) configure -cursor fleur |
---|
1037 | set _click(x) $x |
---|
1038 | set _click(y) $y |
---|
1039 | set _click(theta) $_view(theta) |
---|
1040 | set _click(phi) $_view(phi) |
---|
1041 | } |
---|
1042 | drag { |
---|
1043 | if {[array size _click] == 0} { |
---|
1044 | Rotate click $x $y |
---|
1045 | } else { |
---|
1046 | set w [winfo width $itk_component(3dview)] |
---|
1047 | set h [winfo height $itk_component(3dview)] |
---|
1048 | if {$w <= 0 || $h <= 0} { |
---|
1049 | return |
---|
1050 | } |
---|
1051 | |
---|
1052 | if {[catch { |
---|
1053 | # this fails sometimes for no apparent reason |
---|
1054 | set dx [expr {double($x-$_click(x))/$w}] |
---|
1055 | set dy [expr {double($y-$_click(y))/$h}] |
---|
1056 | }]} { |
---|
1057 | return |
---|
1058 | } |
---|
1059 | |
---|
1060 | # |
---|
1061 | # Rotate the camera in 3D |
---|
1062 | # |
---|
1063 | if {$_view(psi) > 90 || $_view(psi) < -90} { |
---|
1064 | # when psi is flipped around, theta moves backwards |
---|
1065 | set dy [expr {-$dy}] |
---|
1066 | } |
---|
1067 | set theta [expr {$_view(theta) - $dy*180}] |
---|
1068 | while {$theta < 0} { set theta [expr {$theta+180}] } |
---|
1069 | while {$theta > 180} { set theta [expr {$theta-180}] } |
---|
1070 | |
---|
1071 | if {abs($theta) >= 30 && abs($theta) <= 160} { |
---|
1072 | set phi [expr {$_view(phi) - $dx*360}] |
---|
1073 | while {$phi < 0} { set phi [expr {$phi+360}] } |
---|
1074 | while {$phi > 360} { set phi [expr {$phi-360}] } |
---|
1075 | set psi $_view(psi) |
---|
1076 | } else { |
---|
1077 | set phi $_view(phi) |
---|
1078 | set psi [expr {$_view(psi) - $dx*360}] |
---|
1079 | while {$psi < -180} { set psi [expr {$psi+360}] } |
---|
1080 | while {$psi > 180} { set psi [expr {$psi-360}] } |
---|
1081 | } |
---|
1082 | |
---|
1083 | set _view(theta) $theta |
---|
1084 | set _view(phi) $phi |
---|
1085 | set _view(psi) $psi |
---|
1086 | set xyz [Euler2XYZ $theta $phi $psi] |
---|
1087 | set _settings($this-theta) $_view(theta) |
---|
1088 | set _settings($this-phi) $_view(phi) |
---|
1089 | set _settings($this-psi) $_view(psi) |
---|
1090 | SendCmd "camera angle $xyz" |
---|
1091 | set _click(x) $x |
---|
1092 | set _click(y) $y |
---|
1093 | } |
---|
1094 | } |
---|
1095 | release { |
---|
1096 | Rotate drag $x $y |
---|
1097 | $itk_component(3dview) configure -cursor "" |
---|
1098 | catch {unset _click} |
---|
1099 | } |
---|
1100 | default { |
---|
1101 | error "bad option \"$option\": should be click, drag, release" |
---|
1102 | } |
---|
1103 | } |
---|
1104 | } |
---|
1105 | |
---|
1106 | # ---------------------------------------------------------------------- |
---|
1107 | # USAGE: $this Pan click x y |
---|
1108 | # $this Pan drag x y |
---|
1109 | # $this Pan release x y |
---|
1110 | # |
---|
1111 | # Called automatically when the user clicks on one of the zoom |
---|
1112 | # controls for this widget. Changes the zoom for the current view. |
---|
1113 | # ---------------------------------------------------------------------- |
---|
1114 | itcl::body Rappture::NanovisViewer::Pan {option x y} { |
---|
1115 | # Experimental stuff |
---|
1116 | set w [winfo width $itk_component(3dview)] |
---|
1117 | set h [winfo height $itk_component(3dview)] |
---|
1118 | if { $option == "set" } { |
---|
1119 | set x [expr $x / double($w)] |
---|
1120 | set y [expr $y / double($h)] |
---|
1121 | set _view(pan-x) [expr $_view(pan-x) + $x] |
---|
1122 | set _view(pan-y) [expr $_view(pan-y) + $y] |
---|
1123 | PanCamera |
---|
1124 | set _settings($this-pan-x) $_view(pan-x) |
---|
1125 | set _settings($this-pan-y) $_view(pan-y) |
---|
1126 | return |
---|
1127 | } |
---|
1128 | if { $option == "click" } { |
---|
1129 | set _click(x) $x |
---|
1130 | set _click(y) $y |
---|
1131 | $itk_component(3dview) configure -cursor hand1 |
---|
1132 | } |
---|
1133 | if { $option == "drag" || $option == "release" } { |
---|
1134 | set dx [expr ($_click(x) - $x)/double($w)] |
---|
1135 | set dy [expr ($_click(y) - $y)/double($h)] |
---|
1136 | set _click(x) $x |
---|
1137 | set _click(y) $y |
---|
1138 | set _view(pan-x) [expr $_view(pan-x) - $dx] |
---|
1139 | set _view(pan-y) [expr $_view(pan-y) - $dy] |
---|
1140 | PanCamera |
---|
1141 | set _settings($this-pan-x) $_view(pan-x) |
---|
1142 | set _settings($this-pan-y) $_view(pan-y) |
---|
1143 | } |
---|
1144 | if { $option == "release" } { |
---|
1145 | $itk_component(3dview) configure -cursor "" |
---|
1146 | } |
---|
1147 | } |
---|
1148 | |
---|
1149 | # ---------------------------------------------------------------------- |
---|
1150 | # USAGE: FixSettings <what> ?<value>? |
---|
1151 | # |
---|
1152 | # Used internally to update rendering settings whenever parameters |
---|
1153 | # change in the popup settings panel. Sends the new settings off |
---|
1154 | # to the back end. |
---|
1155 | # ---------------------------------------------------------------------- |
---|
1156 | itcl::body Rappture::NanovisViewer::FixSettings {what {value ""}} { |
---|
1157 | switch -- $what { |
---|
1158 | light { |
---|
1159 | if {[isconnected]} { |
---|
1160 | set val $_settings($this-light) |
---|
1161 | set sval [expr {0.1*$val}] |
---|
1162 | SendCmd "volume shading diffuse $sval" |
---|
1163 | set sval [expr {sqrt($val+1.0)}] |
---|
1164 | SendCmd "volume shading specular $sval" |
---|
1165 | } |
---|
1166 | } |
---|
1167 | transp { |
---|
1168 | if {[isconnected]} { |
---|
1169 | set val $_settings($this-transp) |
---|
1170 | set sval [expr {0.2*$val+1}] |
---|
1171 | SendCmd "volume shading opacity $sval" |
---|
1172 | } |
---|
1173 | } |
---|
1174 | opacity { |
---|
1175 | if {[isconnected] && [array size _activeTfs] > 0 } { |
---|
1176 | set val $_settings($this-opacity) |
---|
1177 | set sval [expr { 0.01 * double($val) }] |
---|
1178 | foreach tf [array names _activeTfs] { |
---|
1179 | set _settings($this-$tf-opacity) $sval |
---|
1180 | set _activeTfs($tf) 0 |
---|
1181 | } |
---|
1182 | updatetransferfuncs |
---|
1183 | } |
---|
1184 | } |
---|
1185 | |
---|
1186 | thickness { |
---|
1187 | if {[isconnected] && [array names _activeTfs] > 0 } { |
---|
1188 | set val $_settings($this-thickness) |
---|
1189 | # Scale values between 0.00001 and 0.01000 |
---|
1190 | set sval [expr {0.0001*double($val)}] |
---|
1191 | foreach tf [array names _activeTfs] { |
---|
1192 | set _settings($this-$tf-thickness) $sval |
---|
1193 | set _activeTfs($tf) 0 |
---|
1194 | } |
---|
1195 | updatetransferfuncs |
---|
1196 | } |
---|
1197 | } |
---|
1198 | "outline" { |
---|
1199 | if {[isconnected]} { |
---|
1200 | SendCmd "volume outline state $_settings($this-outline)" |
---|
1201 | } |
---|
1202 | } |
---|
1203 | "isosurface" { |
---|
1204 | if {[isconnected]} { |
---|
1205 | SendCmd "volume shading isosurface $_settings($this-isosurface)" |
---|
1206 | } |
---|
1207 | } |
---|
1208 | "grid" { |
---|
1209 | if { [isconnected] } { |
---|
1210 | SendCmd "grid visible $_settings($this-grid)" |
---|
1211 | } |
---|
1212 | } |
---|
1213 | "axes" { |
---|
1214 | if { [isconnected] } { |
---|
1215 | SendCmd "axis visible $_settings($this-axes)" |
---|
1216 | } |
---|
1217 | } |
---|
1218 | "legend" { |
---|
1219 | if { $_settings($this-legend) } { |
---|
1220 | blt::table $itk_component(plotarea) \ |
---|
1221 | 0,0 $itk_component(3dview) -fill both \ |
---|
1222 | 1,0 $itk_component(legend) -fill x |
---|
1223 | blt::table configure $itk_component(plotarea) r1 -resize none |
---|
1224 | } else { |
---|
1225 | blt::table forget $itk_component(legend) |
---|
1226 | } |
---|
1227 | } |
---|
1228 | "volume" { |
---|
1229 | if { [isconnected] } { |
---|
1230 | set vols [CurrentVolumes -cutplanes] |
---|
1231 | SendCmd "volume data state $_settings($this-volume) $vols" |
---|
1232 | } |
---|
1233 | } |
---|
1234 | "xcutplane" - "ycutplane" - "zcutplane" { |
---|
1235 | set axis [string range $what 0 0] |
---|
1236 | set bool $_settings($this-$what) |
---|
1237 | if { [isconnected] } { |
---|
1238 | set vols [CurrentVolumes -cutplanes] |
---|
1239 | set vol [lindex $vols 0] |
---|
1240 | SendCmd "cutplane state $bool $axis $vol" |
---|
1241 | } |
---|
1242 | if { $bool } { |
---|
1243 | $itk_component(${axis}CutScale) configure -state normal \ |
---|
1244 | -troughcolor white |
---|
1245 | } else { |
---|
1246 | $itk_component(${axis}CutScale) configure -state disabled \ |
---|
1247 | -troughcolor grey82 |
---|
1248 | } |
---|
1249 | } |
---|
1250 | default { |
---|
1251 | error "don't know how to fix $what" |
---|
1252 | } |
---|
1253 | } |
---|
1254 | } |
---|
1255 | |
---|
1256 | # ---------------------------------------------------------------------- |
---|
1257 | # USAGE: FixLegend |
---|
1258 | # |
---|
1259 | # Used internally to update the legend area whenever it changes size |
---|
1260 | # or when the field changes. Asks the server to send a new legend |
---|
1261 | # for the current field. |
---|
1262 | # ---------------------------------------------------------------------- |
---|
1263 | itcl::body Rappture::NanovisViewer::FixLegend {} { |
---|
1264 | set _resizeLegendPending 0 |
---|
1265 | set lineht [font metrics $itk_option(-font) -linespace] |
---|
1266 | set w [expr {$_width-20}] |
---|
1267 | set h [expr {[winfo height $itk_component(legend)]-20-$lineht}] |
---|
1268 | if {$w > 0 && $h > 0 && [array names _activeTfs] > 0 && $_first != "" } { |
---|
1269 | set vol [lindex [CurrentVolumes] 0] |
---|
1270 | if { [info exists _vol2style($vol)] } { |
---|
1271 | SendCmd "legend $_vol2style($vol) $w $h" |
---|
1272 | } |
---|
1273 | } else { |
---|
1274 | # Can't do this as this will remove the items associated with the |
---|
1275 | # isomarkers. |
---|
1276 | |
---|
1277 | #$itk_component(legend) delete all |
---|
1278 | } |
---|
1279 | } |
---|
1280 | |
---|
1281 | # |
---|
1282 | # NameTransferFunc -- |
---|
1283 | # |
---|
1284 | # Creates a transfer function name based on the <style> settings in the |
---|
1285 | # library run.xml file. This placeholder will be used later to create |
---|
1286 | # and send the actual transfer function once the data info has been sent |
---|
1287 | # to us by the render server. [We won't know the volume limits until the |
---|
1288 | # server parses the 3D data and sends back the limits via ReceiveData.] |
---|
1289 | # |
---|
1290 | # FIXME: The current way we generate transfer-function names completely |
---|
1291 | # ignores the -markers option. The problem is that we are forced |
---|
1292 | # to compute the name from an increasing complex set of values: |
---|
1293 | # color, levels, marker, opacity. I think we're stuck doing it |
---|
1294 | # now. |
---|
1295 | # |
---|
1296 | itcl::body Rappture::NanovisViewer::NameTransferFunc { dataobj comp } { |
---|
1297 | array set style { |
---|
1298 | -color rainbow |
---|
1299 | -levels 6 |
---|
1300 | -opacity 1.0 |
---|
1301 | } |
---|
1302 | array set style [lindex [$dataobj components -style $comp] 0] |
---|
1303 | set tf "$style(-color):$style(-levels):$style(-opacity)" |
---|
1304 | set _vol2style($dataobj-$comp) $tf |
---|
1305 | lappend _style2vols($tf) $dataobj-$comp |
---|
1306 | return $tf |
---|
1307 | } |
---|
1308 | |
---|
1309 | # |
---|
1310 | # ComputeTransferFunc -- |
---|
1311 | # |
---|
1312 | # Computes and sends the transfer function to the render server. It's |
---|
1313 | # assumed that the volume data limits are known and that the global |
---|
1314 | # transfer-functions slider values have be setup. Both parts are |
---|
1315 | # needed to compute the relative value (location) of the marker, and |
---|
1316 | # the alpha map of the transfer function. |
---|
1317 | # |
---|
1318 | itcl::body Rappture::NanovisViewer::ComputeTransferFunc { tf } { |
---|
1319 | array set style { |
---|
1320 | -color rainbow |
---|
1321 | -levels 6 |
---|
1322 | -opacity 1.0 |
---|
1323 | } |
---|
1324 | foreach {dataobj comp} [split $_style2vols($tf) -] break |
---|
1325 | array set style [lindex [$dataobj components -style $comp] 0] |
---|
1326 | |
---|
1327 | |
---|
1328 | # We have to parse the style attributes for a volume using this |
---|
1329 | # transfer-function *once*. This sets up the initial isomarkers for the |
---|
1330 | # transfer function. The user may add/delete markers, so we have to |
---|
1331 | # maintain a list of markers for each transfer-function. We use the one |
---|
1332 | # of the volumes (the first in the list) using the transfer-function as a |
---|
1333 | # reference. |
---|
1334 | # |
---|
1335 | # FIXME: The current way we generate transfer-function names completely |
---|
1336 | # ignores the -markers option. The problem is that we are forced |
---|
1337 | # to compute the name from an increasing complex set of values: |
---|
1338 | # color, levels, marker, opacity. I think the cow's out of the |
---|
1339 | # barn on this one. |
---|
1340 | |
---|
1341 | if { ![info exists _isomarkers($tf)] } { |
---|
1342 | # Have to defer creation of isomarkers until we have data limits |
---|
1343 | if { [info exists style(-markers)] } { |
---|
1344 | ParseMarkersOption $tf $style(-markers) |
---|
1345 | } else { |
---|
1346 | ParseLevelsOption $tf $style(-levels) |
---|
1347 | } |
---|
1348 | } |
---|
1349 | if {$style(-color) == "rainbow"} { |
---|
1350 | set style(-color) "white:yellow:green:cyan:blue:magenta" |
---|
1351 | } |
---|
1352 | set clist [split $style(-color) :] |
---|
1353 | set cmap "0.0 [Color2RGB white] " |
---|
1354 | for {set i 0} {$i < [llength $clist]} {incr i} { |
---|
1355 | set x [expr {double($i+1)/([llength $clist]+1)}] |
---|
1356 | set color [lindex $clist $i] |
---|
1357 | append cmap "$x [Color2RGB $color] " |
---|
1358 | } |
---|
1359 | append cmap "1.0 [Color2RGB $color]" |
---|
1360 | |
---|
1361 | set tag $this-$tf |
---|
1362 | if { ![info exists _settings($tag-opacity)] } { |
---|
1363 | set _settings($tag-opacity) $style(-opacity) |
---|
1364 | } |
---|
1365 | set max $_settings($tag-opacity) |
---|
1366 | |
---|
1367 | set isovalues {} |
---|
1368 | foreach m $_isomarkers($tf) { |
---|
1369 | lappend isovalues [$m relval] |
---|
1370 | } |
---|
1371 | # Sort the isovalues |
---|
1372 | set isovalues [lsort -real $isovalues] |
---|
1373 | |
---|
1374 | if { ![info exists _settings($tag-thickness)]} { |
---|
1375 | set _settings($tag-thickness) 0.05 |
---|
1376 | } |
---|
1377 | set delta $_settings($tag-thickness) |
---|
1378 | |
---|
1379 | set first [lindex $isovalues 0] |
---|
1380 | set last [lindex $isovalues end] |
---|
1381 | set wmap "" |
---|
1382 | if { $first == "" || $first != 0.0 } { |
---|
1383 | lappend wmap 0.0 0.0 |
---|
1384 | } |
---|
1385 | foreach x $isovalues { |
---|
1386 | set x1 [expr {$x-$delta-0.00001}] |
---|
1387 | set x2 [expr {$x-$delta}] |
---|
1388 | set x3 [expr {$x+$delta}] |
---|
1389 | set x4 [expr {$x+$delta+0.00001}] |
---|
1390 | if { $x1 < 0.0 } { |
---|
1391 | set x1 0.0 |
---|
1392 | } elseif { $x1 > 1.0 } { |
---|
1393 | set x1 1.0 |
---|
1394 | } |
---|
1395 | if { $x2 < 0.0 } { |
---|
1396 | set x2 0.0 |
---|
1397 | } elseif { $x2 > 1.0 } { |
---|
1398 | set x2 1.0 |
---|
1399 | } |
---|
1400 | if { $x3 < 0.0 } { |
---|
1401 | set x3 0.0 |
---|
1402 | } elseif { $x3 > 1.0 } { |
---|
1403 | set x3 1.0 |
---|
1404 | } |
---|
1405 | if { $x4 < 0.0 } { |
---|
1406 | set x4 0.0 |
---|
1407 | } elseif { $x4 > 1.0 } { |
---|
1408 | set x4 1.0 |
---|
1409 | } |
---|
1410 | # add spikes in the middle |
---|
1411 | lappend wmap $x1 0.0 |
---|
1412 | lappend wmap $x2 $max |
---|
1413 | lappend wmap $x3 $max |
---|
1414 | lappend wmap $x4 0.0 |
---|
1415 | } |
---|
1416 | if { $last == "" || $last != 1.0 } { |
---|
1417 | lappend wmap 1.0 0.0 |
---|
1418 | } |
---|
1419 | SendCmd "transfunc define $tf { $cmap } { $wmap }" |
---|
1420 | } |
---|
1421 | |
---|
1422 | # ---------------------------------------------------------------------- |
---|
1423 | # CONFIGURATION OPTION: -plotbackground |
---|
1424 | # ---------------------------------------------------------------------- |
---|
1425 | itcl::configbody Rappture::NanovisViewer::plotbackground { |
---|
1426 | if { [isconnected] } { |
---|
1427 | foreach {r g b} [Color2RGB $itk_option(-plotbackground)] break |
---|
1428 | #fix this! |
---|
1429 | #SendCmd "color background $r $g $b" |
---|
1430 | } |
---|
1431 | } |
---|
1432 | |
---|
1433 | # ---------------------------------------------------------------------- |
---|
1434 | # CONFIGURATION OPTION: -plotforeground |
---|
1435 | # ---------------------------------------------------------------------- |
---|
1436 | itcl::configbody Rappture::NanovisViewer::plotforeground { |
---|
1437 | if { [isconnected] } { |
---|
1438 | foreach {r g b} [Color2RGB $itk_option(-plotforeground)] break |
---|
1439 | #fix this! |
---|
1440 | #SendCmd "color background $r $g $b" |
---|
1441 | } |
---|
1442 | } |
---|
1443 | |
---|
1444 | # ---------------------------------------------------------------------- |
---|
1445 | # CONFIGURATION OPTION: -plotoutline |
---|
1446 | # ---------------------------------------------------------------------- |
---|
1447 | itcl::configbody Rappture::NanovisViewer::plotoutline { |
---|
1448 | # Must check if we are connected because this routine is called from the |
---|
1449 | # class body when the -plotoutline itk_option is defined. At that point |
---|
1450 | # the NanovisViewer class constructor hasn't been called, so we can't |
---|
1451 | # start sending commands to visualization server. |
---|
1452 | if { [isconnected] } { |
---|
1453 | if {"" == $itk_option(-plotoutline)} { |
---|
1454 | SendCmd "volume outline state off" |
---|
1455 | } else { |
---|
1456 | SendCmd "volume outline state on" |
---|
1457 | SendCmd "volume outline color [Color2RGB $itk_option(-plotoutline)]" |
---|
1458 | } |
---|
1459 | } |
---|
1460 | } |
---|
1461 | |
---|
1462 | # |
---|
1463 | # The -levels option takes a single value that represents the number |
---|
1464 | # of evenly distributed markers based on the current data range. Each |
---|
1465 | # marker is a relative value from 0.0 to 1.0. |
---|
1466 | # |
---|
1467 | itcl::body Rappture::NanovisViewer::ParseLevelsOption { tf levels } { |
---|
1468 | set c $itk_component(legend) |
---|
1469 | regsub -all "," $levels " " levels |
---|
1470 | if {[string is int $levels]} { |
---|
1471 | for {set i 1} { $i <= $levels } {incr i} { |
---|
1472 | set x [expr {double($i)/($levels+1)}] |
---|
1473 | set m [Rappture::IsoMarker \#auto $c $this $tf] |
---|
1474 | $m relval $x |
---|
1475 | lappend _isomarkers($tf) $m |
---|
1476 | } |
---|
1477 | } else { |
---|
1478 | foreach x $levels { |
---|
1479 | set m [Rappture::IsoMarker \#auto $c $this $tf] |
---|
1480 | $m relval $x |
---|
1481 | lappend _isomarkers($tf) $m |
---|
1482 | } |
---|
1483 | } |
---|
1484 | } |
---|
1485 | |
---|
1486 | # |
---|
1487 | # The -markers option takes a list of zero or more values (the values |
---|
1488 | # may be separated either by spaces or commas) that have the following |
---|
1489 | # format: |
---|
1490 | # |
---|
1491 | # N% Percent of current total data range. Converted to |
---|
1492 | # to a relative value between 0.0 and 1.0. |
---|
1493 | # N Absolute value of marker. If the marker is outside of |
---|
1494 | # the current range, it will be displayed on the outer |
---|
1495 | # edge of the legends, but it range it represents will |
---|
1496 | # not be seen. |
---|
1497 | # |
---|
1498 | itcl::body Rappture::NanovisViewer::ParseMarkersOption { tf markers } { |
---|
1499 | set c $itk_component(legend) |
---|
1500 | regsub -all "," $markers " " markers |
---|
1501 | foreach marker $markers { |
---|
1502 | set n [scan $marker "%g%s" value suffix] |
---|
1503 | if { $n == 2 && $suffix == "%" } { |
---|
1504 | # ${n}% : Set relative value. |
---|
1505 | set value [expr {$value * 0.01}] |
---|
1506 | set m [Rappture::IsoMarker \#auto $c $this $tf] |
---|
1507 | $m relval $value |
---|
1508 | lappend _isomarkers($tf) $m |
---|
1509 | } else { |
---|
1510 | # ${n} : Set absolute value. |
---|
1511 | set m [Rappture::IsoMarker \#auto $c $this $tf] |
---|
1512 | $m absval $value |
---|
1513 | lappend _isomarkers($tf) $m |
---|
1514 | } |
---|
1515 | } |
---|
1516 | } |
---|
1517 | |
---|
1518 | # ---------------------------------------------------------------------- |
---|
1519 | # USAGE: UndateTransferFuncs |
---|
1520 | # ---------------------------------------------------------------------- |
---|
1521 | itcl::body Rappture::NanovisViewer::updatetransferfuncs {} { |
---|
1522 | $_dispatcher event -idle !send_transfunc |
---|
1523 | } |
---|
1524 | |
---|
1525 | itcl::body Rappture::NanovisViewer::AddIsoMarker { x y } { |
---|
1526 | if { $_first == "" } { |
---|
1527 | error "active transfer function isn't set" |
---|
1528 | } |
---|
1529 | set vol [lindex [CurrentVolumes] 0] |
---|
1530 | set tf $_vol2style($vol) |
---|
1531 | set c $itk_component(legend) |
---|
1532 | set m [Rappture::IsoMarker \#auto $c $this $tf] |
---|
1533 | set w [winfo width $c] |
---|
1534 | $m relval [expr {double($x-10)/($w-20)}] |
---|
1535 | lappend _isomarkers($tf) $m |
---|
1536 | updatetransferfuncs |
---|
1537 | return 1 |
---|
1538 | } |
---|
1539 | |
---|
1540 | itcl::body Rappture::NanovisViewer::rmdupmarker { marker x } { |
---|
1541 | set tf [$marker transferfunc] |
---|
1542 | set bool 0 |
---|
1543 | if { [info exists _isomarkers($tf)] } { |
---|
1544 | set list {} |
---|
1545 | set marker [namespace tail $marker] |
---|
1546 | foreach m $_isomarkers($tf) { |
---|
1547 | set sx [$m screenpos] |
---|
1548 | if { $m != $marker } { |
---|
1549 | if { $x >= ($sx-3) && $x <= ($sx+3) } { |
---|
1550 | $marker relval [$m relval] |
---|
1551 | itcl::delete object $m |
---|
1552 | bell |
---|
1553 | set bool 1 |
---|
1554 | continue |
---|
1555 | } |
---|
1556 | } |
---|
1557 | lappend list $m |
---|
1558 | } |
---|
1559 | set _isomarkers($tf) $list |
---|
1560 | updatetransferfuncs |
---|
1561 | } |
---|
1562 | return $bool |
---|
1563 | } |
---|
1564 | |
---|
1565 | itcl::body Rappture::NanovisViewer::overmarker { marker x } { |
---|
1566 | set tf [$marker transferfunc] |
---|
1567 | if { [info exists _isomarkers($tf)] } { |
---|
1568 | set marker [namespace tail $marker] |
---|
1569 | foreach m $_isomarkers($tf) { |
---|
1570 | set sx [$m screenpos] |
---|
1571 | if { $m != $marker } { |
---|
1572 | set bool [expr { $x >= ($sx-3) && $x <= ($sx+3) }] |
---|
1573 | $m activate $bool |
---|
1574 | } |
---|
1575 | } |
---|
1576 | } |
---|
1577 | return "" |
---|
1578 | } |
---|
1579 | |
---|
1580 | itcl::body Rappture::NanovisViewer::limits { tf } { |
---|
1581 | set _limits(min) 0.0 |
---|
1582 | set _limits(max) 1.0 |
---|
1583 | if { ![info exists _style2vols($tf)] } { |
---|
1584 | return [array get _limits] |
---|
1585 | } |
---|
1586 | set min ""; set max "" |
---|
1587 | foreach vol $_style2vols($tf) { |
---|
1588 | if { ![info exists _serverVols($vol)] } { |
---|
1589 | continue |
---|
1590 | } |
---|
1591 | if { ![info exists _limits($vol-min)] } { |
---|
1592 | continue |
---|
1593 | } |
---|
1594 | if { $min == "" || $min > $_limits($vol-min) } { |
---|
1595 | set min $_limits($vol-min) |
---|
1596 | } |
---|
1597 | if { $max == "" || $max < $_limits($vol-max) } { |
---|
1598 | set max $_limits($vol-max) |
---|
1599 | } |
---|
1600 | } |
---|
1601 | if { $min != "" } { |
---|
1602 | set _limits(min) $min |
---|
1603 | } |
---|
1604 | if { $max != "" } { |
---|
1605 | set _limits(max) $max |
---|
1606 | } |
---|
1607 | return [array get _limits] |
---|
1608 | } |
---|
1609 | |
---|
1610 | |
---|
1611 | itcl::body Rappture::NanovisViewer::BuildViewTab {} { |
---|
1612 | foreach { key value } { |
---|
1613 | grid 0 |
---|
1614 | axes 1 |
---|
1615 | outline 1 |
---|
1616 | volume 1 |
---|
1617 | legend 1 |
---|
1618 | particles 1 |
---|
1619 | lic 1 |
---|
1620 | } { |
---|
1621 | set _settings($this-$key) $value |
---|
1622 | } |
---|
1623 | |
---|
1624 | set fg [option get $itk_component(hull) font Font] |
---|
1625 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
1626 | |
---|
1627 | set inner [$itk_component(main) insert end \ |
---|
1628 | -title "View Settings" \ |
---|
1629 | -icon [Rappture::icon wrench]] |
---|
1630 | $inner configure -borderwidth 4 |
---|
1631 | |
---|
1632 | set ::Rappture::NanovisViewer::_settings($this-isosurface) 0 |
---|
1633 | checkbutton $inner.isosurface \ |
---|
1634 | -text "Isosurface shading" \ |
---|
1635 | -variable [itcl::scope _settings($this-isosurface)] \ |
---|
1636 | -command [itcl::code $this FixSettings isosurface] \ |
---|
1637 | -font "Arial 9" |
---|
1638 | |
---|
1639 | checkbutton $inner.axes \ |
---|
1640 | -text "Axes" \ |
---|
1641 | -variable [itcl::scope _settings($this-axes)] \ |
---|
1642 | -command [itcl::code $this FixSettings axes] \ |
---|
1643 | -font "Arial 9" |
---|
1644 | |
---|
1645 | checkbutton $inner.grid \ |
---|
1646 | -text "Grid" \ |
---|
1647 | -variable [itcl::scope _settings($this-grid)] \ |
---|
1648 | -command [itcl::code $this FixSettings grid] \ |
---|
1649 | -font "Arial 9" |
---|
1650 | |
---|
1651 | checkbutton $inner.outline \ |
---|
1652 | -text "Outline" \ |
---|
1653 | -variable [itcl::scope _settings($this-outline)] \ |
---|
1654 | -command [itcl::code $this FixSettings outline] \ |
---|
1655 | -font "Arial 9" |
---|
1656 | |
---|
1657 | checkbutton $inner.legend \ |
---|
1658 | -text "Legend" \ |
---|
1659 | -variable [itcl::scope _settings($this-legend)] \ |
---|
1660 | -command [itcl::code $this FixSettings legend] \ |
---|
1661 | -font "Arial 9" |
---|
1662 | |
---|
1663 | checkbutton $inner.volume \ |
---|
1664 | -text "Volume" \ |
---|
1665 | -variable [itcl::scope _settings($this-volume)] \ |
---|
1666 | -command [itcl::code $this FixSettings volume] \ |
---|
1667 | -font "Arial 9" |
---|
1668 | |
---|
1669 | blt::table $inner \ |
---|
1670 | 0,0 $inner.axes -columnspan 2 -anchor w \ |
---|
1671 | 1,0 $inner.grid -columnspan 2 -anchor w \ |
---|
1672 | 2,0 $inner.outline -columnspan 2 -anchor w \ |
---|
1673 | 3,0 $inner.volume -columnspan 2 -anchor w \ |
---|
1674 | 4,0 $inner.legend -columnspan 2 -anchor w |
---|
1675 | |
---|
1676 | if 0 { |
---|
1677 | bind $inner <Map> [itcl::code $this GetVolumeInfo $inner] |
---|
1678 | } |
---|
1679 | blt::table configure $inner r* -resize none |
---|
1680 | blt::table configure $inner r5 -resize expand |
---|
1681 | } |
---|
1682 | |
---|
1683 | itcl::body Rappture::NanovisViewer::BuildVolumeTab {} { |
---|
1684 | foreach { key value } { |
---|
1685 | light 40 |
---|
1686 | transp 50 |
---|
1687 | opacity 100 |
---|
1688 | thickness 350 |
---|
1689 | } { |
---|
1690 | set _settings($this-$key) $value |
---|
1691 | } |
---|
1692 | |
---|
1693 | set inner [$itk_component(main) insert end \ |
---|
1694 | -title "Volume Settings" \ |
---|
1695 | -icon [Rappture::icon volume-on]] |
---|
1696 | $inner configure -borderwidth 4 |
---|
1697 | |
---|
1698 | set fg [option get $itk_component(hull) font Font] |
---|
1699 | #set bfg [option get $itk_component(hull) boldFont Font] |
---|
1700 | |
---|
1701 | checkbutton $inner.vol -text "Show volume" -font $fg \ |
---|
1702 | -variable [itcl::scope _settings($this-volume)] \ |
---|
1703 | -command [itcl::code $this FixSettings volume] |
---|
1704 | label $inner.shading -text "Shading:" -font $fg |
---|
1705 | |
---|
1706 | label $inner.dim -text "Dim" -font $fg |
---|
1707 | ::scale $inner.light -from 0 -to 100 -orient horizontal \ |
---|
1708 | -variable [itcl::scope _settings($this-light)] \ |
---|
1709 | -width 10 \ |
---|
1710 | -showvalue off -command [itcl::code $this FixSettings light] |
---|
1711 | label $inner.bright -text "Bright" -font $fg |
---|
1712 | |
---|
1713 | label $inner.fog -text "Fog" -font $fg |
---|
1714 | ::scale $inner.transp -from 0 -to 100 -orient horizontal \ |
---|
1715 | -variable [itcl::scope _settings($this-transp)] \ |
---|
1716 | -width 10 \ |
---|
1717 | -showvalue off -command [itcl::code $this FixSettings transp] |
---|
1718 | label $inner.plastic -text "Plastic" -font $fg |
---|
1719 | |
---|
1720 | label $inner.clear -text "Clear" -font $fg |
---|
1721 | ::scale $inner.opacity -from 0 -to 100 -orient horizontal \ |
---|
1722 | -variable [itcl::scope _settings($this-opacity)] \ |
---|
1723 | -width 10 \ |
---|
1724 | -showvalue off -command [itcl::code $this FixSettings opacity] |
---|
1725 | label $inner.opaque -text "Opaque" -font $fg |
---|
1726 | |
---|
1727 | label $inner.thin -text "Thin" -font $fg |
---|
1728 | ::scale $inner.thickness -from 0 -to 1000 -orient horizontal \ |
---|
1729 | -variable [itcl::scope _settings($this-thickness)] \ |
---|
1730 | -width 10 \ |
---|
1731 | -showvalue off -command [itcl::code $this FixSettings thickness] |
---|
1732 | label $inner.thick -text "Thick" -font $fg |
---|
1733 | |
---|
1734 | blt::table $inner \ |
---|
1735 | 0,0 $inner.vol -columnspan 4 -anchor w -pady 2 \ |
---|
1736 | 1,0 $inner.shading -columnspan 4 -anchor w -pady {10 2} \ |
---|
1737 | 2,0 $inner.dim -anchor e -pady 2 \ |
---|
1738 | 2,1 $inner.light -columnspan 2 -pady 2 -fill x \ |
---|
1739 | 2,3 $inner.bright -anchor w -pady 2 \ |
---|
1740 | 3,0 $inner.fog -anchor e -pady 2 \ |
---|
1741 | 3,1 $inner.transp -columnspan 2 -pady 2 -fill x \ |
---|
1742 | 3,3 $inner.plastic -anchor w -pady 2 \ |
---|
1743 | 4,0 $inner.clear -anchor e -pady 2 \ |
---|
1744 | 4,1 $inner.opacity -columnspan 2 -pady 2 -fill x\ |
---|
1745 | 4,3 $inner.opaque -anchor w -pady 2 \ |
---|
1746 | 5,0 $inner.thin -anchor e -pady 2 \ |
---|
1747 | 5,1 $inner.thickness -columnspan 2 -pady 2 -fill x\ |
---|
1748 | 5,3 $inner.thick -anchor w -pady 2 |
---|
1749 | |
---|
1750 | blt::table configure $inner c0 c1 c3 r* -resize none |
---|
1751 | blt::table configure $inner r6 -resize expand |
---|
1752 | } |
---|
1753 | |
---|
1754 | itcl::body Rappture::NanovisViewer::BuildCutplanesTab {} { |
---|
1755 | set inner [$itk_component(main) insert end \ |
---|
1756 | -title "Cutplane Settings" \ |
---|
1757 | -icon [Rappture::icon cutbutton]] |
---|
1758 | $inner configure -borderwidth 4 |
---|
1759 | |
---|
1760 | # X-value slicer... |
---|
1761 | itk_component add xCutButton { |
---|
1762 | Rappture::PushButton $inner.xbutton \ |
---|
1763 | -onimage [Rappture::icon x-cutplane] \ |
---|
1764 | -offimage [Rappture::icon x-cutplane] \ |
---|
1765 | -command [itcl::code $this FixSettings xcutplane] \ |
---|
1766 | -variable [itcl::scope _settings($this-xcutplane)] |
---|
1767 | } |
---|
1768 | Rappture::Tooltip::for $itk_component(xCutButton) \ |
---|
1769 | "Toggle the X cut plane on/off" |
---|
1770 | |
---|
1771 | itk_component add xCutScale { |
---|
1772 | ::scale $inner.xval -from 100 -to 0 \ |
---|
1773 | -width 10 -orient vertical -showvalue off \ |
---|
1774 | -borderwidth 1 -highlightthickness 0 \ |
---|
1775 | -command [itcl::code $this Slice move x] \ |
---|
1776 | -variable [itcl::scope _settings($this-xcutposition)] |
---|
1777 | } { |
---|
1778 | usual |
---|
1779 | ignore -borderwidth -highlightthickness |
---|
1780 | } |
---|
1781 | # Set the default cutplane value before disabling the scale. |
---|
1782 | $itk_component(xCutScale) set 50 |
---|
1783 | $itk_component(xCutScale) configure -state disabled |
---|
1784 | Rappture::Tooltip::for $itk_component(xCutScale) \ |
---|
1785 | "@[itcl::code $this SlicerTip x]" |
---|
1786 | |
---|
1787 | # Y-value slicer... |
---|
1788 | itk_component add yCutButton { |
---|
1789 | Rappture::PushButton $inner.ybutton \ |
---|
1790 | -onimage [Rappture::icon y-cutplane] \ |
---|
1791 | -offimage [Rappture::icon y-cutplane] \ |
---|
1792 | -command [itcl::code $this FixSettings ycutplane] \ |
---|
1793 | -variable [itcl::scope _settings($this-ycutplane)] |
---|
1794 | } |
---|
1795 | Rappture::Tooltip::for $itk_component(yCutButton) \ |
---|
1796 | "Toggle the Y cut plane on/off" |
---|
1797 | |
---|
1798 | itk_component add yCutScale { |
---|
1799 | ::scale $inner.yval -from 100 -to 0 \ |
---|
1800 | -width 10 -orient vertical -showvalue off \ |
---|
1801 | -borderwidth 1 -highlightthickness 0 \ |
---|
1802 | -command [itcl::code $this Slice move y] \ |
---|
1803 | -variable [itcl::scope _settings($this-ycutposition)] |
---|
1804 | } { |
---|
1805 | usual |
---|
1806 | ignore -borderwidth -highlightthickness |
---|
1807 | } |
---|
1808 | Rappture::Tooltip::for $itk_component(yCutScale) \ |
---|
1809 | "@[itcl::code $this SlicerTip y]" |
---|
1810 | # Set the default cutplane value before disabling the scale. |
---|
1811 | $itk_component(yCutScale) set 50 |
---|
1812 | $itk_component(yCutScale) configure -state disabled |
---|
1813 | |
---|
1814 | # Z-value slicer... |
---|
1815 | itk_component add zCutButton { |
---|
1816 | Rappture::PushButton $inner.zbutton \ |
---|
1817 | -onimage [Rappture::icon z-cutplane] \ |
---|
1818 | -offimage [Rappture::icon z-cutplane] \ |
---|
1819 | -command [itcl::code $this FixSettings zcutplane] \ |
---|
1820 | -variable [itcl::scope _settings($this-zcutplane)] |
---|
1821 | } |
---|
1822 | Rappture::Tooltip::for $itk_component(zCutButton) \ |
---|
1823 | "Toggle the Z cut plane on/off" |
---|
1824 | |
---|
1825 | itk_component add zCutScale { |
---|
1826 | ::scale $inner.zval -from 100 -to 0 \ |
---|
1827 | -width 10 -orient vertical -showvalue off \ |
---|
1828 | -borderwidth 1 -highlightthickness 0 \ |
---|
1829 | -command [itcl::code $this Slice move z] \ |
---|
1830 | -variable [itcl::scope _settings($this-zcutposition)] |
---|
1831 | } { |
---|
1832 | usual |
---|
1833 | ignore -borderwidth -highlightthickness |
---|
1834 | } |
---|
1835 | $itk_component(zCutScale) set 50 |
---|
1836 | $itk_component(zCutScale) configure -state disabled |
---|
1837 | #$itk_component(zCutScale) configure -state disabled |
---|
1838 | Rappture::Tooltip::for $itk_component(zCutScale) \ |
---|
1839 | "@[itcl::code $this SlicerTip z]" |
---|
1840 | |
---|
1841 | blt::table $inner \ |
---|
1842 | 1,1 $itk_component(xCutButton) \ |
---|
1843 | 1,2 $itk_component(yCutButton) \ |
---|
1844 | 1,3 $itk_component(zCutButton) \ |
---|
1845 | 0,1 $itk_component(xCutScale) \ |
---|
1846 | 0,2 $itk_component(yCutScale) \ |
---|
1847 | 0,3 $itk_component(zCutScale) |
---|
1848 | |
---|
1849 | blt::table configure $inner r0 r1 c* -resize none |
---|
1850 | blt::table configure $inner r2 c4 -resize expand |
---|
1851 | blt::table configure $inner c0 -width 2 |
---|
1852 | blt::table configure $inner c1 c2 c3 -padx 2 |
---|
1853 | } |
---|
1854 | |
---|
1855 | itcl::body Rappture::NanovisViewer::BuildCameraTab {} { |
---|
1856 | set inner [$itk_component(main) insert end \ |
---|
1857 | -title "Camera Settings" \ |
---|
1858 | -icon [Rappture::icon camera]] |
---|
1859 | $inner configure -borderwidth 4 |
---|
1860 | |
---|
1861 | set labels { phi theta psi pan-x pan-y zoom } |
---|
1862 | set row 0 |
---|
1863 | foreach tag $labels { |
---|
1864 | label $inner.${tag}label -text $tag -font "Arial 9" |
---|
1865 | entry $inner.${tag} -font "Arial 9" -bg white \ |
---|
1866 | -textvariable [itcl::scope _settings($this-$tag)] |
---|
1867 | bind $inner.${tag} <KeyPress-Return> \ |
---|
1868 | [itcl::code $this camera set ${tag}] |
---|
1869 | blt::table $inner \ |
---|
1870 | $row,0 $inner.${tag}label -anchor e -pady 2 \ |
---|
1871 | $row,1 $inner.${tag} -anchor w -pady 2 |
---|
1872 | blt::table configure $inner r$row -resize none |
---|
1873 | incr row |
---|
1874 | } |
---|
1875 | blt::table configure $inner c0 c1 -resize none |
---|
1876 | blt::table configure $inner c2 -resize expand |
---|
1877 | blt::table configure $inner r$row -resize expand |
---|
1878 | } |
---|
1879 | |
---|
1880 | |
---|
1881 | # ---------------------------------------------------------------------- |
---|
1882 | # USAGE: Slice move x|y|z <newval> |
---|
1883 | # |
---|
1884 | # Called automatically when the user drags the slider to move the |
---|
1885 | # cut plane that slices 3D data. Gets the current value from the |
---|
1886 | # slider and moves the cut plane to the appropriate point in the |
---|
1887 | # data set. |
---|
1888 | # ---------------------------------------------------------------------- |
---|
1889 | itcl::body Rappture::NanovisViewer::Slice {option args} { |
---|
1890 | switch -- $option { |
---|
1891 | move { |
---|
1892 | if {[llength $args] != 2} { |
---|
1893 | error "wrong # args: should be \"Slice move x|y|z newval\"" |
---|
1894 | } |
---|
1895 | set axis [lindex $args 0] |
---|
1896 | set newval [lindex $args 1] |
---|
1897 | |
---|
1898 | set newpos [expr {0.01*$newval}] |
---|
1899 | set vols [CurrentVolumes -cutplanes] |
---|
1900 | set vol [lindex $vols 0] |
---|
1901 | SendCmd "cutplane position $newpos $axis $vol" |
---|
1902 | } |
---|
1903 | default { |
---|
1904 | error "bad option \"$option\": should be axis, move, or volume" |
---|
1905 | } |
---|
1906 | } |
---|
1907 | } |
---|
1908 | |
---|
1909 | # ---------------------------------------------------------------------- |
---|
1910 | # USAGE: SlicerTip <axis> |
---|
1911 | # |
---|
1912 | # Used internally to generate a tooltip for the x/y/z slicer controls. |
---|
1913 | # Returns a message that includes the current slicer value. |
---|
1914 | # ---------------------------------------------------------------------- |
---|
1915 | itcl::body Rappture::NanovisViewer::SlicerTip {axis} { |
---|
1916 | set val [$itk_component(${axis}CutScale) get] |
---|
1917 | # set val [expr {0.01*($val-50) |
---|
1918 | # *($_limits(${axis}max)-$_limits(${axis}min)) |
---|
1919 | # + 0.5*($_limits(${axis}max)+$_limits(${axis}min))}] |
---|
1920 | return "Move the [string toupper $axis] cut plane.\nCurrently: $axis = $val%" |
---|
1921 | } |
---|
1922 | |
---|
1923 | |
---|
1924 | itcl::body Rappture::NanovisViewer::DoResize {} { |
---|
1925 | SendCmd "screen $_width $_height" |
---|
1926 | set _resizePending 0 |
---|
1927 | } |
---|
1928 | |
---|
1929 | itcl::body Rappture::NanovisViewer::EventuallyResize { w h } { |
---|
1930 | set _width $w |
---|
1931 | set _height $h |
---|
1932 | if { !$_resizePending } { |
---|
1933 | $_dispatcher event -idle !resize |
---|
1934 | set _resizePending 1 |
---|
1935 | } |
---|
1936 | } |
---|
1937 | |
---|
1938 | itcl::body Rappture::NanovisViewer::EventuallyResizeLegend {} { |
---|
1939 | if { !$_resizeLegendPending } { |
---|
1940 | $_dispatcher event -idle !legend |
---|
1941 | set _resizeLegendPending 1 |
---|
1942 | } |
---|
1943 | } |
---|
1944 | |
---|
1945 | |
---|
1946 | # camera -- |
---|
1947 | # |
---|
1948 | itcl::body Rappture::NanovisViewer::camera {option args} { |
---|
1949 | switch -- $option { |
---|
1950 | "show" { |
---|
1951 | puts [array get _view] |
---|
1952 | } |
---|
1953 | "set" { |
---|
1954 | set who [lindex $args 0] |
---|
1955 | set x $_settings($this-$who) |
---|
1956 | set code [catch { string is double $x } result] |
---|
1957 | if { $code != 0 || !$result } { |
---|
1958 | set _settings($this-$who) $_view($who) |
---|
1959 | return |
---|
1960 | } |
---|
1961 | switch -- $who { |
---|
1962 | "pan-x" - "pan-y" { |
---|
1963 | set _view($who) $_settings($this-$who) |
---|
1964 | PanCamera |
---|
1965 | } |
---|
1966 | "phi" - "theta" - "psi" { |
---|
1967 | set _view($who) $_settings($this-$who) |
---|
1968 | set xyz [Euler2XYZ $_view(theta) $_view(phi) $_view(psi)] |
---|
1969 | SendCmd "camera angle $xyz" |
---|
1970 | } |
---|
1971 | "zoom" { |
---|
1972 | set _view($who) $_settings($this-$who) |
---|
1973 | SendCmd "camera zoom $_view(zoom)" |
---|
1974 | } |
---|
1975 | } |
---|
1976 | } |
---|
1977 | } |
---|
1978 | } |
---|
1979 | |
---|
1980 | itcl::body Rappture::NanovisViewer::GetVolumeInfo { w } { |
---|
1981 | set flowobj "" |
---|
1982 | foreach key [array names _obj2flow] { |
---|
1983 | set flowobj $_obj2flow($key) |
---|
1984 | break |
---|
1985 | } |
---|
1986 | if { $flowobj == "" } { |
---|
1987 | return |
---|
1988 | } |
---|
1989 | if { [winfo exists $w.frame] } { |
---|
1990 | destroy $w.frame |
---|
1991 | } |
---|
1992 | set inner [frame $w.frame] |
---|
1993 | blt::table $w \ |
---|
1994 | 5,0 $inner -fill both -columnspan 2 -anchor nw |
---|
1995 | array set hints [$dataobj hints] |
---|
1996 | |
---|
1997 | label $inner.volumes -text "Volumes" -font "Arial 9 bold" |
---|
1998 | blt::table $inner \ |
---|
1999 | 1,0 $inner.volumes -anchor w \ |
---|
2000 | blt::table configure $inner c0 c1 -resize none |
---|
2001 | blt::table configure $inner c2 -resize expand |
---|
2002 | |
---|
2003 | set row 3 |
---|
2004 | set volumes [get] |
---|
2005 | if { [llength $volumes] > 0 } { |
---|
2006 | blt::table $inner $row,0 $inner.volumes -anchor w |
---|
2007 | incr row |
---|
2008 | } |
---|
2009 | foreach vol $volumes { |
---|
2010 | array unset info |
---|
2011 | array set info $vol |
---|
2012 | set name $info(name) |
---|
2013 | if { ![info exists _settings($this-volume-$name)] } { |
---|
2014 | set _settings($this-volume-$name) $info(hide) |
---|
2015 | } |
---|
2016 | checkbutton $inner.vol$row -text $info(label) \ |
---|
2017 | -variable [itcl::scope _settings($this-volume-$name)] \ |
---|
2018 | -onvalue 0 -offvalue 1 \ |
---|
2019 | -command [itcl::code $this volume $key $name] \ |
---|
2020 | -font "Arial 9" |
---|
2021 | Rappture::Tooltip::for $inner.vol$row $info(description) |
---|
2022 | blt::table $inner $row,0 $inner.vol$row -anchor w |
---|
2023 | if { !$_settings($this-volume-$name) } { |
---|
2024 | $inner.vol$row select |
---|
2025 | } |
---|
2026 | incr row |
---|
2027 | } |
---|
2028 | blt::table configure $inner r* -resize none |
---|
2029 | blt::table configure $inner r$row -resize expand |
---|
2030 | blt::table configure $inner c3 -resize expand |
---|
2031 | event generate [winfo parent [winfo parent $w]] <Configure> |
---|
2032 | } |
---|
2033 | |
---|
2034 | itcl::body Rappture::NanovisViewer::volume { tag name } { |
---|
2035 | set bool $_settings($this-volume-$name) |
---|
2036 | SendCmd "volume statue $bool $name" |
---|
2037 | } |
---|
2038 | |
---|