source: branches/1.6/gui/scripts/vtkglyphviewer.tcl @ 6363

Last change on this file since 6363 was 6363, checked in by ldelgass, 8 years ago

merge viewer fixes from trunk

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