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

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

Merge cleanups from trunk (partial hand merge of r6182, not including custom
range support in glyph viewer)

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