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

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

merge viewer cleanups from trunk

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
1626    set fg [option get $itk_component(hull) font Font]
1627    #set bfg [option get $itk_component(hull) boldFont Font]
1628
1629    set inner [$itk_component(main) insert end \
1630        -title "Glyph Settings" \
1631        -icon [Rappture::icon volume-on]]
1632    $inner configure -borderwidth 4
1633
1634    checkbutton $inner.glyphs \
1635        -text "Glyphs" \
1636        -variable [itcl::scope _settings(-glyphsvisible)] \
1637        -command [itcl::code $this AdjustSetting -glyphsvisible] \
1638        -font "Arial 9"
1639
1640    label $inner.gshape_l -text "Glyph shape" -font "Arial 9"
1641    itk_component add gshape {
1642        Rappture::Combobox $inner.gshape -width 10 -editable 0
1643    }
1644    $inner.gshape choices insert end \
1645        "arrow"              "arrow"           \
1646        "cone"               "cone"            \
1647        "cube"               "cube"            \
1648        "cylinder"           "cylinder"        \
1649        "dodecahedron"       "dodecahedron"    \
1650        "icosahedron"        "icosahedron"     \
1651        "line"               "line"            \
1652        "octahedron"         "octahedron"      \
1653        "point"              "point"           \
1654        "sphere"             "sphere"          \
1655        "tetrahedron"        "tetrahedron"
1656
1657    $itk_component(gshape) value $_settings(-glyphshape)
1658    bind $inner.gshape <<Value>> [itcl::code $this AdjustSetting -glyphshape]
1659
1660    label $inner.scaleMode_l -text "Scale by" -font "Arial 9"
1661    itk_component add scaleMode {
1662        Rappture::Combobox $inner.scaleMode -width 10 -editable 0
1663    }
1664    $inner.scaleMode choices insert end \
1665        "scalar" "Scalar"            \
1666        "vmag"   "Vector magnitude"  \
1667        "vcomp"  "Vector components" \
1668        "off"    "Constant size"
1669
1670    $itk_component(scaleMode) value "[$itk_component(scaleMode) label $_settings(-glyphscalemode)]"
1671    bind $inner.scaleMode <<Value>> [itcl::code $this AdjustSetting -glyphscalemode]
1672
1673    checkbutton $inner.normscale \
1674        -text "Normalize scaling" \
1675        -variable [itcl::scope _settings(-glyphnormscale)] \
1676        -command [itcl::code $this AdjustSetting -glyphnormscale] \
1677        -font "Arial 9"
1678    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"
1679
1680    checkbutton $inner.gorient \
1681        -text "Orient" \
1682        -variable [itcl::scope _settings(-glyphorient)] \
1683        -command [itcl::code $this AdjustSetting -glyphorient] \
1684        -font "Arial 9"
1685    Rappture::Tooltip::for $inner.gorient "Orient glyphs by vector field directions"
1686
1687    checkbutton $inner.wireframe \
1688        -text "Wireframe" \
1689        -variable [itcl::scope _settings(-glyphwireframe)] \
1690        -command [itcl::code $this AdjustSetting -glyphwireframe] \
1691        -font "Arial 9"
1692
1693    checkbutton $inner.lighting \
1694        -text "Enable Lighting" \
1695        -variable [itcl::scope _settings(-glyphlighting)] \
1696        -command [itcl::code $this AdjustSetting -glyphlighting] \
1697        -font "Arial 9"
1698
1699    checkbutton $inner.edges \
1700        -text "Edges" \
1701        -variable [itcl::scope _settings(-glyphedges)] \
1702        -command [itcl::code $this AdjustSetting -glyphedges] \
1703        -font "Arial 9"
1704
1705    checkbutton $inner.outline \
1706        -text "Outline" \
1707        -variable [itcl::scope _settings(-outline)] \
1708        -command [itcl::code $this AdjustSetting -outline] \
1709        -font "Arial 9"
1710
1711    checkbutton $inner.legend \
1712        -text "Legend" \
1713        -variable [itcl::scope _settings(-legendvisible)] \
1714        -command [itcl::code $this AdjustSetting -legendvisible] \
1715        -font "Arial 9"
1716
1717    label $inner.background_l -text "Background" -font "Arial 9"
1718    itk_component add background {
1719        Rappture::Combobox $inner.background -width 10 -editable 0
1720    }
1721    $inner.background choices insert end \
1722        "black"              "black"            \
1723        "white"              "white"            \
1724        "grey"               "grey"
1725
1726    $itk_component(background) value $_settings(-background)
1727    bind $inner.background <<Value>> \
1728        [itcl::code $this AdjustSetting -background]
1729
1730    label $inner.opacity_l -text "Opacity" -font "Arial 9"
1731    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
1732        -variable [itcl::scope _widget(-glyphopacity)] \
1733        -width 10 \
1734        -showvalue off \
1735        -command [itcl::code $this AdjustSetting -glyphopacity]
1736    $inner.opacity set [expr $_settings(-glyphopacity) * 100.0]
1737
1738    label $inner.gscale_l -text "Scale factor" -font "Arial 9"
1739    if {0} {
1740    ::scale $inner.gscale -from 1 -to 100 -orient horizontal \
1741        -variable [itcl::scope _settings(-glyphscale)] \
1742        -width 10 \
1743        -showvalue off \
1744        -command [itcl::code $this AdjustSetting -glyphscale]
1745    } else {
1746    itk_component add gscale {
1747        entry $inner.gscale -font "Arial 9" -bg white \
1748            -textvariable [itcl::scope _settings(-glyphscale)]
1749    } {
1750        ignore -font -background
1751    }
1752    bind $inner.gscale <Return> \
1753        [itcl::code $this AdjustSetting -glyphscale]
1754    bind $inner.gscale <KP_Enter> \
1755        [itcl::code $this AdjustSetting -glyphscale]
1756    }
1757    Rappture::Tooltip::for $inner.gscale "Set scaling multiplier (or constant size)"
1758
1759    itk_component add field_l {
1760        label $inner.field_l -text "Color By" -font "Arial 9"
1761    } {
1762        ignore -font
1763    }
1764    itk_component add field {
1765        Rappture::Combobox $inner.field -width 10 -editable 0
1766    }
1767    bind $inner.field <<Value>> \
1768        [itcl::code $this AdjustSetting -field]
1769
1770    label $inner.colormap_l -text "Colormap" -font "Arial 9"
1771    itk_component add colormap {
1772        Rappture::Combobox $inner.colormap -width 10 -editable 0
1773    }
1774
1775    $inner.colormap choices insert end [GetColormapList -includeNone]
1776    $itk_component(colormap) value "BCGYR"
1777    bind $inner.colormap <<Value>> \
1778        [itcl::code $this AdjustSetting -colormap]
1779
1780    blt::table $inner \
1781        0,0 $inner.field_l      -anchor w -pady 2 \
1782        0,1 $inner.field        -anchor w -pady 2 -fill x \
1783        1,0 $inner.colormap_l   -anchor w -pady 2 \
1784        1,1 $inner.colormap     -anchor w -pady 2 -fill x \
1785        2,0 $inner.gshape_l     -anchor w -pady 2 \
1786        2,1 $inner.gshape       -anchor w -pady 2 -fill x \
1787        3,0 $inner.background_l -anchor w -pady 2 \
1788        3,1 $inner.background   -anchor w -pady 2 -fill x \
1789        4,0 $inner.scaleMode_l  -anchor w -pady 2 \
1790        4,1 $inner.scaleMode    -anchor w -pady 2 -fill x \
1791        5,0 $inner.gscale_l     -anchor w -pady 2 \
1792        5,1 $inner.gscale       -anchor w -pady 2 -fill x \
1793        6,0 $inner.normscale    -anchor w -pady 2 -cspan 2 \
1794        7,0 $inner.gorient      -anchor w -pady 2 -cspan 2 \
1795        8,0 $inner.wireframe    -anchor w -pady 2 -cspan 2 \
1796        9,0 $inner.lighting     -anchor w -pady 2 -cspan 2 \
1797        10,0 $inner.edges       -anchor w -pady 2 -cspan 2 \
1798        11,0 $inner.outline     -anchor w -pady 2 -cspan 2 \
1799        12,0 $inner.legend      -anchor w -pady 2 \
1800        13,0 $inner.opacity_l   -anchor w -pady 2 \
1801        13,1 $inner.opacity     -anchor w -pady 2 -fill x
1802
1803    blt::table configure $inner r* c* -resize none
1804    blt::table configure $inner r14 c1 -resize expand
1805}
1806
1807itcl::body Rappture::VtkGlyphViewer::BuildAxisTab {} {
1808
1809    set fg [option get $itk_component(hull) font Font]
1810    #set bfg [option get $itk_component(hull) boldFont Font]
1811
1812    set inner [$itk_component(main) insert end \
1813        -title "Axis Settings" \
1814        -icon [Rappture::icon axis2]]
1815    $inner configure -borderwidth 4
1816
1817    checkbutton $inner.visible \
1818        -text "Axes" \
1819        -variable [itcl::scope _settings(-axesvisible)] \
1820        -command [itcl::code $this AdjustSetting -axesvisible] \
1821        -font "Arial 9"
1822
1823    checkbutton $inner.labels \
1824        -text "Axis Labels" \
1825        -variable [itcl::scope _settings(-axislabels)] \
1826        -command [itcl::code $this AdjustSetting -axislabels] \
1827        -font "Arial 9"
1828    label $inner.grid_l -text "Grid" -font "Arial 9"
1829    checkbutton $inner.xgrid \
1830        -text "X" \
1831        -variable [itcl::scope _settings(-xgrid)] \
1832        -command [itcl::code $this AdjustSetting -xgrid] \
1833        -font "Arial 9"
1834    checkbutton $inner.ygrid \
1835        -text "Y" \
1836        -variable [itcl::scope _settings(-ygrid)] \
1837        -command [itcl::code $this AdjustSetting -ygrid] \
1838        -font "Arial 9"
1839    checkbutton $inner.zgrid \
1840        -text "Z" \
1841        -variable [itcl::scope _settings(-zgrid)] \
1842        -command [itcl::code $this AdjustSetting -zgrid] \
1843        -font "Arial 9"
1844    checkbutton $inner.minorticks \
1845        -text "Minor Ticks" \
1846        -variable [itcl::scope _settings(-axisminorticks)] \
1847        -command [itcl::code $this AdjustSetting -axisminorticks] \
1848        -font "Arial 9"
1849
1850    label $inner.mode_l -text "Mode" -font "Arial 9"
1851
1852    itk_component add axisMode {
1853        Rappture::Combobox $inner.mode -width 10 -editable 0
1854    }
1855    $inner.mode choices insert end \
1856        "static_triad"    "static" \
1857        "closest_triad"   "closest" \
1858        "furthest_triad"  "farthest" \
1859        "outer_edges"     "outer"
1860    $itk_component(axisMode) value $_settings(-axismode)
1861    bind $inner.mode <<Value>> [itcl::code $this AdjustSetting -axismode]
1862
1863    blt::table $inner \
1864        0,0 $inner.visible    -anchor w -cspan 4 \
1865        1,0 $inner.labels     -anchor w -cspan 4 \
1866        2,0 $inner.minorticks -anchor w -cspan 4 \
1867        4,0 $inner.grid_l     -anchor w \
1868        4,1 $inner.xgrid      -anchor w \
1869        4,2 $inner.ygrid      -anchor w \
1870        4,3 $inner.zgrid      -anchor w \
1871        5,0 $inner.mode_l     -anchor w -padx { 2 0 } \
1872        5,1 $inner.mode       -fill x   -cspan 3
1873
1874    blt::table configure $inner r* c* -resize none
1875    blt::table configure $inner r7 c6 -resize expand
1876    blt::table configure $inner r3 -height 0.125i
1877}
1878
1879itcl::body Rappture::VtkGlyphViewer::BuildCameraTab {} {
1880    set inner [$itk_component(main) insert end \
1881        -title "Camera Settings" \
1882        -icon [Rappture::icon camera]]
1883    $inner configure -borderwidth 4
1884
1885    label $inner.view_l -text "view" -font "Arial 9"
1886    set f [frame $inner.view]
1887    foreach side { front back left right top bottom } {
1888        button $f.$side  -image [Rappture::icon view$side] \
1889            -command [itcl::code $this SetOrientation $side]
1890        Rappture::Tooltip::for $f.$side "Change the view to $side"
1891        pack $f.$side -side left
1892    }
1893
1894    blt::table $inner \
1895        0,0 $inner.view_l -anchor e -pady 2 \
1896        0,1 $inner.view -anchor w -pady 2
1897    blt::table configure $inner r0 -resize none
1898
1899    set labels { qx qy qz qw xpan ypan zoom }
1900    set row 1
1901    foreach tag $labels {
1902        label $inner.${tag}label -text $tag -font "Arial 9"
1903        entry $inner.${tag} -font "Arial 9"  -bg white \
1904            -textvariable [itcl::scope _view(-$tag)]
1905        bind $inner.${tag} <Return> \
1906            [itcl::code $this camera set -${tag}]
1907        bind $inner.${tag} <KP_Enter> \
1908            [itcl::code $this camera set -${tag}]
1909        blt::table $inner \
1910            $row,0 $inner.${tag}label -anchor e -pady 2 \
1911            $row,1 $inner.${tag} -anchor w -pady 2
1912        blt::table configure $inner r$row -resize none
1913        incr row
1914    }
1915    checkbutton $inner.ortho \
1916        -text "Orthographic Projection" \
1917        -variable [itcl::scope _view(-ortho)] \
1918        -command [itcl::code $this AdjustSetting -ortho] \
1919        -font "Arial 9"
1920    blt::table $inner \
1921            $row,0 $inner.ortho -cspan 2 -anchor w -pady 2
1922    blt::table configure $inner r$row -resize none
1923    incr row
1924
1925    blt::table configure $inner c* -resize none
1926    blt::table configure $inner c2 -resize expand
1927    blt::table configure $inner r$row -resize expand
1928}
1929
1930itcl::body Rappture::VtkGlyphViewer::BuildCutplanesTab {} {
1931
1932    set fg [option get $itk_component(hull) font Font]
1933
1934    set inner [$itk_component(main) insert end \
1935        -title "Cutplane Settings" \
1936        -icon [Rappture::icon cutbutton]]
1937
1938    $inner configure -borderwidth 4
1939
1940    checkbutton $inner.visible \
1941        -text "Cutplanes" \
1942        -variable [itcl::scope _settings(-cutplanesvisible)] \
1943        -command [itcl::code $this AdjustSetting -cutplanesvisible] \
1944        -font "Arial 9"
1945
1946    checkbutton $inner.wireframe \
1947        -text "Wireframe" \
1948        -variable [itcl::scope _settings(-cutplanewireframe)] \
1949        -command [itcl::code $this AdjustSetting -cutplanewireframe] \
1950        -font "Arial 9"
1951
1952    checkbutton $inner.lighting \
1953        -text "Enable Lighting" \
1954        -variable [itcl::scope _settings(-cutplanelighting)] \
1955        -command [itcl::code $this AdjustSetting -cutplanelighting] \
1956        -font "Arial 9"
1957
1958    checkbutton $inner.edges \
1959        -text "Edges" \
1960        -variable [itcl::scope _settings(-cutplaneedges)] \
1961        -command [itcl::code $this AdjustSetting -cutplaneedges] \
1962        -font "Arial 9"
1963
1964    checkbutton $inner.preinterp \
1965        -text "Interpolate Scalars" \
1966        -variable [itcl::scope _settings(-cutplanepreinterp)] \
1967        -command [itcl::code $this AdjustSetting -cutplanepreinterp] \
1968        -font "Arial 9"
1969
1970    label $inner.opacity_l -text "Opacity" -font "Arial 9"
1971    ::scale $inner.opacity -from 0 -to 100 -orient horizontal \
1972        -variable [itcl::scope _widget(-cutplaneopacity)] \
1973        -width 10 \
1974        -showvalue off \
1975        -command [itcl::code $this AdjustSetting -cutplaneopacity]
1976    $inner.opacity set [expr $_settings(-cutplaneopacity) * 100.0]
1977
1978    # X-value slicer...
1979    itk_component add xbutton {
1980        Rappture::PushButton $inner.xbutton \
1981            -onimage [Rappture::icon x-cutplane-red] \
1982            -offimage [Rappture::icon x-cutplane-red] \
1983            -command [itcl::code $this AdjustSetting -xcutplanevisible] \
1984            -variable [itcl::scope _settings(-xcutplanevisible)] \
1985    }
1986    Rappture::Tooltip::for $itk_component(xbutton) \
1987        "Toggle the X-axis cutplane on/off"
1988    $itk_component(xbutton) select
1989    itk_component add xposition {
1990        ::scale $inner.xval -from 100 -to 0 \
1991            -width 10 -orient vertical -showvalue 1 \
1992            -borderwidth 1 -highlightthickness 0 \
1993            -command [itcl::code $this EventuallySetCutplane x] \
1994            -variable [itcl::scope _settings(-xcutplaneposition)] \
1995            -foreground red2 -font "Arial 9 bold"
1996    } {
1997        usual
1998        ignore -borderwidth -highlightthickness -foreground -font -background
1999    }
2000    # Set the default cutplane value before disabling the scale.
2001    $itk_component(xposition) set 50
2002    $itk_component(xposition) configure -state disabled
2003    Rappture::Tooltip::for $itk_component(xposition) \
2004        "@[itcl::code $this Slice tooltip x]"
2005
2006    # Y-value slicer...
2007    itk_component add ybutton {
2008        Rappture::PushButton $inner.ybutton \
2009            -onimage [Rappture::icon y-cutplane-green] \
2010            -offimage [Rappture::icon y-cutplane-green] \
2011            -command [itcl::code $this AdjustSetting -ycutplanevisible] \
2012            -variable [itcl::scope _settings(-ycutplanevisible)] \
2013    }
2014    Rappture::Tooltip::for $itk_component(ybutton) \
2015        "Toggle the Y-axis cutplane on/off"
2016    $itk_component(ybutton) select
2017
2018    itk_component add yposition {
2019        ::scale $inner.yval -from 100 -to 0 \
2020            -width 10 -orient vertical -showvalue 1 \
2021            -borderwidth 1 -highlightthickness 0 \
2022            -command [itcl::code $this EventuallySetCutplane y] \
2023            -variable [itcl::scope _settings(-ycutplaneposition)] \
2024            -foreground green3 -font "Arial 9 bold"
2025    } {
2026        usual
2027        ignore -borderwidth -highlightthickness -foreground -font
2028    }
2029    Rappture::Tooltip::for $itk_component(yposition) \
2030        "@[itcl::code $this Slice tooltip y]"
2031    # Set the default cutplane value before disabling the scale.
2032    $itk_component(yposition) set 50
2033    $itk_component(yposition) configure -state disabled
2034
2035    # Z-value slicer...
2036    itk_component add zbutton {
2037        Rappture::PushButton $inner.zbutton \
2038            -onimage [Rappture::icon z-cutplane-blue] \
2039            -offimage [Rappture::icon z-cutplane-blue] \
2040            -command [itcl::code $this AdjustSetting -zcutplanevisible] \
2041            -variable [itcl::scope _settings(-zcutplanevisible)] \
2042    } {
2043        usual
2044        ignore -foreground
2045    }
2046    Rappture::Tooltip::for $itk_component(zbutton) \
2047        "Toggle the Z-axis cutplane on/off"
2048    $itk_component(zbutton) select
2049
2050    itk_component add zposition {
2051        ::scale $inner.zval -from 100 -to 0 \
2052            -width 10 -orient vertical -showvalue 1 \
2053            -borderwidth 1 -highlightthickness 0 \
2054            -command [itcl::code $this EventuallySetCutplane z] \
2055            -variable [itcl::scope _settings(-zcutplaneposition)] \
2056            -foreground blue3 -font "Arial 9 bold"
2057    } {
2058        usual
2059        ignore -borderwidth -highlightthickness -foreground -font
2060    }
2061    $itk_component(zposition) set 50
2062    $itk_component(zposition) configure -state disabled
2063    Rappture::Tooltip::for $itk_component(zposition) \
2064        "@[itcl::code $this Slice tooltip z]"
2065
2066    blt::table $inner \
2067        0,0 $inner.visible   -anchor w -pady 2 -cspan 3 \
2068        1,0 $inner.lighting  -anchor w -pady 2 -cspan 3 \
2069        2,0 $inner.wireframe -anchor w -pady 2 -cspan 3 \
2070        3,0 $inner.edges     -anchor w -pady 2 -cspan 3 \
2071        4,0 $inner.preinterp -anchor w -pady 2 -cspan 3 \
2072        5,0 $inner.opacity_l -anchor w -pady 2 -cspan 1 \
2073        5,1 $inner.opacity   -fill x   -pady 2 -cspan 3 \
2074        6,0 $inner.xbutton   -anchor w -padx 2 -pady 2 \
2075        7,0 $inner.ybutton   -anchor w -padx 2 -pady 2 \
2076        8,0 $inner.zbutton   -anchor w -padx 2 -pady 2 \
2077        6,1 $inner.xval      -fill y -rspan 4 \
2078        6,2 $inner.yval      -fill y -rspan 4 \
2079        6,3 $inner.zval      -fill y -rspan 4 \
2080
2081    blt::table configure $inner r* c* -resize none
2082    blt::table configure $inner r9 c4 -resize expand
2083}
2084
2085#
2086# camera --
2087#
2088itcl::body Rappture::VtkGlyphViewer::camera {option args} {
2089    switch -- $option {
2090        "show" {
2091            puts [array get _view]
2092        }
2093        "set" {
2094            set what [lindex $args 0]
2095            set x $_view($what)
2096            set code [catch { string is double $x } result]
2097            if { $code != 0 || !$result } {
2098                return
2099            }
2100            switch -- $what {
2101                "-ortho" {
2102                    if {$_view($what)} {
2103                        SendCmd "camera mode ortho"
2104                    } else {
2105                        SendCmd "camera mode persp"
2106                    }
2107                }
2108                "-xpan" - "-ypan" {
2109                    PanCamera
2110                }
2111                "-qx" - "-qy" - "-qz" - "-qw" {
2112                    set q [ViewToQuaternion]
2113                    $_arcball quaternion $q
2114                    EventuallyRotate $q
2115                }
2116                "-zoom" {
2117                    SendCmd "camera zoom $_view($what)"
2118                }
2119             }
2120        }
2121    }
2122}
2123
2124itcl::body Rappture::VtkGlyphViewer::GetVtkData { args } {
2125    set bytes ""
2126    foreach dataobj [get] {
2127        foreach cname [$dataobj components] {
2128            set tag $dataobj-$cname
2129            set contents [$dataobj vtkdata $cname]
2130            append bytes "$contents\n"
2131        }
2132    }
2133    return [list .vtk $bytes]
2134}
2135
2136itcl::body Rappture::VtkGlyphViewer::GetImage { args } {
2137    if { [image width $_image(download)] > 0 &&
2138         [image height $_image(download)] > 0 } {
2139        set bytes [$_image(download) data -format "jpeg -quality 100"]
2140        set bytes [Rappture::encoding::decode -as b64 $bytes]
2141        return [list .jpg $bytes]
2142    }
2143    return ""
2144}
2145
2146itcl::body Rappture::VtkGlyphViewer::BuildDownloadPopup { popup command } {
2147    Rappture::Balloon $popup \
2148        -title "[Rappture::filexfer::label downloadWord] as..."
2149    set inner [$popup component inner]
2150    label $inner.summary -text "" -anchor w
2151    radiobutton $inner.vtk_button -text "VTK data file" \
2152        -variable [itcl::scope _downloadPopup(format)] \
2153        -font "Arial 9 " \
2154        -value vtk
2155    Rappture::Tooltip::for $inner.vtk_button "Save as VTK data file."
2156    radiobutton $inner.image_button -text "Image File" \
2157        -variable [itcl::scope _downloadPopup(format)] \
2158        -font "Arial 9 " \
2159        -value image
2160    Rappture::Tooltip::for $inner.image_button \
2161        "Save as digital image."
2162
2163    button $inner.ok -text "Save" \
2164        -highlightthickness 0 -pady 2 -padx 3 \
2165        -command $command \
2166        -compound left \
2167        -image [Rappture::icon download]
2168
2169    button $inner.cancel -text "Cancel" \
2170        -highlightthickness 0 -pady 2 -padx 3 \
2171        -command [list $popup deactivate] \
2172        -compound left \
2173        -image [Rappture::icon cancel]
2174
2175    blt::table $inner \
2176        0,0 $inner.summary -cspan 2  \
2177        1,0 $inner.vtk_button -anchor w -cspan 2 -padx { 4 0 } \
2178        2,0 $inner.image_button -anchor w -cspan 2 -padx { 4 0 } \
2179        4,1 $inner.cancel -width .9i -fill y \
2180        4,0 $inner.ok -padx 2 -width .9i -fill y
2181    blt::table configure $inner r3 -height 4
2182    blt::table configure $inner r4 -pady 4
2183    raise $inner.image_button
2184    $inner.vtk_button invoke
2185    return $inner
2186}
2187
2188itcl::body Rappture::VtkGlyphViewer::SetObjectStyle { dataobj comp } {
2189    DebugTrace "Enter"
2190    # Parse style string.
2191    set tag $dataobj-$comp
2192    array set style {
2193        -color                  BCGYR
2194        -constcolor             white
2195        -colormode              vmag
2196        -cutplaneedges          0
2197        -cutplanelighting       1
2198        -cutplaneopacity        1.0
2199        -cutplanepreinterp      1
2200        -cutplanesvisible       0
2201        -cutplanewireframe      0
2202        -edgecolor              black
2203        -edges                  0
2204        -glyphsvisible          1
2205        -gscale                 1
2206        -lighting               1
2207        -linewidth              1.0
2208        -normscale              1
2209        -opacity                1.0
2210        -orientglyphs           1
2211        -outline                0
2212        -ptsize                 1.0
2213        -quality                1
2214        -scalemode              vmag
2215        -shape                  arrow
2216        -wireframe              0
2217        -xcutplaneposition      50
2218        -xcutplanevisible       1
2219        -ycutplaneposition      50
2220        -ycutplanevisible       1
2221        -zcutplaneposition      50
2222        -zcutplanevisible       1
2223    }
2224    set style(-constcolor) $itk_option(-plotforeground)
2225    set numComponents [$dataobj numComponents $comp]
2226    if {$numComponents == 3} {
2227        set style(-shape) "arrow"
2228        set style(-orientglyphs) 1
2229        set style(-scalemode) "vmag"
2230        set style(-colormode) "vmag"
2231    } else {
2232        set style(-shape) "sphere"
2233        set style(-orientglyphs) 0
2234        set style(-scalemode) "scalar"
2235        set style(-colormode) "scalar"
2236    }
2237    array set style [$dataobj style $comp]
2238    # Backwards compat with camel case style option
2239    if { [info exists style(-orientGlyphs)] } {
2240        set style(-orientglyphs) $style(-orientGlyphs)
2241        array unset style -orientGlyphs
2242    }
2243    # Backwards compat with camel case style option
2244    if { [info exists style(-scaleMode)] } {
2245        set style(-scalemode) $style(-scaleMode)
2246        array unset style -scaleMode
2247    }
2248
2249    # This is too complicated.  We want to set the colormap and opacity
2250    # for the dataset.  They can be the default values,
2251    # the style hints loaded with the dataset, or set by user controls.  As
2252    # datasets get loaded, they first use the defaults that are overidden
2253    # by the style hints.  If the user changes the global controls, then that
2254    # overrides everything else.  I don't know what it means when global
2255    # controls are specified as style hints by each dataset.  It complicates
2256    # the code to handle aberrant cases.
2257
2258    if { $_changed(-glyphedges) } {
2259        set style(-edges) $_settings(-glyphedges)
2260    }
2261    if { $_changed(-glyphlighting) } {
2262        set style(-lighting) $_settings(-glyphlighting)
2263    }
2264    if { $_changed(-glyphnormscale) } {
2265        set style(-normscale) $_settings(-glyphnormscale)
2266    }
2267    if { $_changed(-glyphopacity) } {
2268        set style(-opacity) $_settings(-glyphopacity)
2269    }
2270    if { $_changed(-glyphorient) } {
2271        set style(-orientglyphs) $_settings(-glyphorient)
2272    }
2273    if { $_changed(-glyphscale) } {
2274        set style(-gscale) $_settings(-glyphscale)
2275    }
2276    if { $_changed(-glyphwireframe) } {
2277        set style(-wireframe) $_settings(-glyphwireframe)
2278    }
2279    if { $_changed(-colormap) } {
2280        set style(-color) $_settings(-colormap)
2281    }
2282    if { $_currentColormap == "" } {
2283        $itk_component(colormap) value $style(-color)
2284    }
2285    foreach setting {-outline -glyphsvisible -cutplanesvisible \
2286                     -xcutplanevisible -ycutplanevisible -zcutplanevisible \
2287                     -xcutplaneposition -ycutplaneposition -zcutplaneposition \
2288                     -cutplaneedges -cutplanelighting -cutplaneopacity \
2289                     -cutplanepreinterp -cutplanewireframe} {
2290        if {$_changed($setting)} {
2291            # User-modified UI setting overrides style
2292            set style($setting) $_settings($setting)
2293        } else {
2294            # Set UI control to style setting (tool provided or default)
2295            set _settings($setting) $style($setting)
2296        }
2297    }
2298
2299    if 0 {
2300    SendCmd "cutplane add $tag"
2301    SendCmd "cutplane visible 0 $tag"
2302    foreach axis {x y z} {
2303        set pos [expr $style(-${axis}cutplaneposition) * 0.01]
2304        set visible $style(-${axis}cutplanevisible)
2305        SendCmd "cutplane slice $axis $pos $tag"
2306        SendCmd "cutplane axis $axis $visible $tag"
2307    }
2308    SendCmd "cutplane edges $style(-cutplaneedges) $tag"
2309    SendCmd "cutplane lighting $style(-cutplanelighting) $tag"
2310    SendCmd "cutplane opacity $style(-cutplaneopacity) $tag"
2311    set _widget(-cutplaneopacity) [expr $style(-cutplaneopacity) * 100]
2312    SendCmd "cutplane preinterp $style(-cutplanepreinterp) $tag"
2313    SendCmd "cutplane wireframe $style(-cutplanewireframe) $tag"
2314    SendCmd "cutplane visible $style(-cutplanesvisible) $tag"
2315    }
2316
2317    SendCmd "outline add $tag"
2318    SendCmd "outline color [Color2RGB $style(-constcolor)] $tag"
2319    SendCmd "outline visible $style(-outline) $tag"
2320
2321    SendCmd "glyphs add $style(-shape) $tag"
2322    set _settings(-glyphshape) $style(-shape)
2323    $itk_component(gshape) value $style(-shape)
2324    SendCmd "glyphs visible $style(-glyphsvisible) $tag"
2325    SendCmd "glyphs edges $style(-edges) $tag"
2326    set _settings(-glyphedges) $style(-edges)
2327
2328    # normscale=1 and gscale=1 are defaults
2329    if {$style(-normscale) != 1} {
2330        SendCmd "glyphs normscale $style(-normscale) $tag"
2331    }
2332    if {$style(-gscale) != 1} {
2333        SendCmd "glyphs gscale $style(-gscale) $tag"
2334    }
2335    set _settings(-glyphnormscale) $style(-normscale)
2336    set _settings(-glyphscale) $style(-gscale)
2337
2338    if {$style(-colormode) == "constant" || $style(-color) == "none"} {
2339        SendCmd "glyphs colormode constant {} $tag"
2340        set _settings(-colormapvisible) 0
2341        set _settings(-colormap) "none"
2342    } else {
2343        SendCmd "glyphs colormode $style(-colormode) $_curFldName $tag"
2344        set _settings(-colormapvisible) 1
2345        set _settings(-colormap) $style(-color)
2346        SetCurrentColormap $style(-color)
2347    }
2348    $itk_component(colormap) value $_settings(-colormap)
2349    set _colorMode $style(-colormode)
2350
2351    # constant color only used if colormode set to constant
2352    SendCmd "glyphs color [Color2RGB $style(-constcolor)] $tag"
2353    # Omitting field name for gorient and smode commands
2354    # defaults to active scalars or vectors depending on mode
2355    SendCmd "glyphs gorient $style(-orientglyphs) {} $tag"
2356    set _settings(-glyphorient) $style(-orientglyphs)
2357    SendCmd "glyphs smode $style(-scalemode) {} $tag"
2358    set _settings(-glyphscalemode) $style(-scalemode)
2359    $itk_component(scaleMode) value "[$itk_component(scaleMode) label $style(-scalemode)]"
2360    SendCmd "glyphs quality $style(-quality) $tag"
2361    SendCmd "glyphs lighting $style(-lighting) $tag"
2362    set _settings(-glyphlighting) $style(-lighting)
2363    SendCmd "glyphs linecolor [Color2RGB $style(-edgecolor)] $tag"
2364    SendCmd "glyphs linewidth $style(-linewidth) $tag"
2365    SendCmd "glyphs ptsize $style(-ptsize) $tag"
2366    SendCmd "glyphs opacity $style(-opacity) $tag"
2367    set _settings(-glyphopacity) $style(-opacity)
2368    set _widget(-glyphopacity) [expr $style(-opacity) * 100.0]
2369    SendCmd "glyphs wireframe $style(-wireframe) $tag"
2370    set _settings(-glyphwireframe) $style(-wireframe)
2371}
2372
2373itcl::body Rappture::VtkGlyphViewer::IsValidObject { dataobj } {
2374    if {[catch {$dataobj isa Rappture::Field} valid] != 0 || !$valid} {
2375        return 0
2376    }
2377    return 1
2378}
2379
2380#
2381# EnterLegend --
2382#
2383itcl::body Rappture::VtkGlyphViewer::EnterLegend { x y } {
2384    SetLegendTip $x $y
2385}
2386
2387#
2388# MotionLegend --
2389#
2390itcl::body Rappture::VtkGlyphViewer::MotionLegend { x y } {
2391    Rappture::Tooltip::tooltip cancel
2392    set c $itk_component(view)
2393    set cw [winfo width $c]
2394    set ch [winfo height $c]
2395    if { $x >= 0 && $x < $cw && $y >= 0 && $y < $ch } {
2396        SetLegendTip $x $y
2397    }
2398}
2399
2400#
2401# LeaveLegend --
2402#
2403itcl::body Rappture::VtkGlyphViewer::LeaveLegend { } {
2404    Rappture::Tooltip::tooltip cancel
2405    .rappturetooltip configure -icon ""
2406}
2407
2408#
2409# SetLegendTip --
2410#
2411itcl::body Rappture::VtkGlyphViewer::SetLegendTip { x y } {
2412    set fname $_curFldName
2413    set c $itk_component(view)
2414    set w [winfo width $c]
2415    set h [winfo height $c]
2416
2417    set font "Arial 8"
2418    set lineht [font metrics $font -linespace]
2419
2420    set ih [image height $_image(legend)]
2421    set iy [expr $y - ($lineht + 2)]
2422
2423    if { [string match "component*" $fname] } {
2424        set title ""
2425    } else {
2426        if { [info exists _fields($fname)] } {
2427            foreach { title units } $_fields($fname) break
2428            if { $units != "" } {
2429                set title [format "%s (%s)" $title $units]
2430            }
2431        } else {
2432            set title $fname
2433        }
2434    }
2435    # If there's a legend title, increase the offset by the line height.
2436    if { $title != "" } {
2437        incr iy -$lineht
2438    }
2439    # Make a swatch of the selected color
2440    if { [catch { $_image(legend) get 10 $iy } pixel] != 0 } {
2441        return
2442    }
2443    if { ![info exists _image(swatch)] } {
2444        set _image(swatch) [image create photo -width 24 -height 24]
2445    }
2446    set color [eval format "\#%02x%02x%02x" $pixel]
2447    $_image(swatch) put black  -to 0 0 23 23
2448    $_image(swatch) put $color -to 1 1 22 22
2449    .rappturetooltip configure -icon $_image(swatch)
2450
2451    # Compute the value of the point
2452    if { [info exists _limits($_curFldName)] } {
2453        foreach { vmin vmax } $_limits($_curFldName) break
2454        set t [expr 1.0 - (double($iy) / double($ih-1))]
2455        set value [expr $t * ($vmax - $vmin) + $vmin]
2456    } else {
2457        set value 0.0
2458    }
2459    set tx [expr $x + 15]
2460    set ty [expr $y - 5]
2461    Rappture::Tooltip::text $c [format "$title %g" $value]
2462    Rappture::Tooltip::tooltip show $c +$tx,+$ty
2463}
2464
2465# ----------------------------------------------------------------------
2466# USAGE: Slice move x|y|z <newval>
2467#
2468# Called automatically when the user drags the slider to move the
2469# cut plane that slices 3D data.  Gets the current value from the
2470# slider and moves the cut plane to the appropriate point in the
2471# data set.
2472# ----------------------------------------------------------------------
2473itcl::body Rappture::VtkGlyphViewer::Slice {option args} {
2474    switch -- $option {
2475        "move" {
2476            set axis [lindex $args 0]
2477            set newval [lindex $args 1]
2478            if {[llength $args] != 2} {
2479                error "wrong # args: should be \"Slice move x|y|z newval\""
2480            }
2481            set newpos [expr {0.01*$newval}]
2482            SendCmd "cutplane slice $axis $newpos"
2483        }
2484        "tooltip" {
2485            set axis [lindex $args 0]
2486            set val [$itk_component(${axis}position) get]
2487            return "Move the [string toupper $axis] cut plane.\nCurrently:  $axis = $val%"
2488        }
2489        default {
2490            error "bad option \"$option\": should be axis, move, or tooltip"
2491        }
2492    }
2493}
2494
2495#
2496# ReceiveLegend --
2497#
2498# Invoked automatically whenever the "legend" command comes in from
2499# the rendering server.  Indicates that binary image data with the
2500# specified <size> will follow.
2501#
2502itcl::body Rappture::VtkGlyphViewer::ReceiveLegend { colormap title min max size } {
2503    DebugTrace "Enter"
2504    set _title $title
2505    regsub {\(mag\)} $title "" _title
2506    if { [IsConnected] } {
2507        set bytes [ReceiveBytes $size]
2508        if { ![info exists _image(legend)] } {
2509            set _image(legend) [image create photo]
2510        }
2511        $_image(legend) configure -data $bytes
2512        #puts stderr "read $size bytes for [image width $_image(legend)]x[image height $_image(legend)] legend>"
2513        if { [catch {DrawLegend} errs] != 0 } {
2514            global errorInfo
2515            puts stderr "errs=$errs errorInfo=$errorInfo"
2516        }
2517    }
2518}
2519
2520#
2521# DrawLegend --
2522#
2523# Draws the legend on the canvas on the right side of the plot area.
2524#
2525itcl::body Rappture::VtkGlyphViewer::DrawLegend {} {
2526    set fname $_curFldName
2527    set c $itk_component(view)
2528    set w [winfo width $c]
2529    set h [winfo height $c]
2530    set font "Arial 8"
2531    set lineht [font metrics $font -linespace]
2532
2533    if { [string match "component*" $fname] } {
2534        set title ""
2535    } else {
2536        if { [info exists _fields($fname)] } {
2537            foreach { title units } $_fields($fname) break
2538            if { $units != "" } {
2539                set title [format "%s (%s)" $title $units]
2540            }
2541        } else {
2542            set title $fname
2543        }
2544    }
2545    set x [expr $w - 2]
2546    if { !$_settings(-legendvisible) } {
2547        $c delete legend
2548        return
2549    }
2550    if { [$c find withtag "legend"] == "" } {
2551        set y 2
2552        # If there's a legend title, create a text item for the title.
2553        $c create text $x $y \
2554            -anchor ne \
2555            -fill $itk_option(-plotforeground) -tags "title legend" \
2556            -font $font
2557        if { $title != "" } {
2558            incr y $lineht
2559        }
2560        $c create text $x $y \
2561            -anchor ne \
2562            -fill $itk_option(-plotforeground) -tags "vmax legend" \
2563            -font $font
2564        incr y $lineht
2565        $c create image $x $y \
2566            -anchor ne \
2567            -image $_image(legend) -tags "colormap legend"
2568        $c create rectangle $x $y 1 1 \
2569            -fill "" -outline "" -tags "sensor legend"
2570        $c create text $x [expr {$h-2}] \
2571            -anchor se \
2572            -fill $itk_option(-plotforeground) -tags "vmin legend" \
2573            -font $font
2574        $c bind sensor <Enter> [itcl::code $this EnterLegend %x %y]
2575        $c bind sensor <Leave> [itcl::code $this LeaveLegend]
2576        $c bind sensor <Motion> [itcl::code $this MotionLegend %x %y]
2577    }
2578    set x2 $x
2579    set iw [image width $_image(legend)]
2580    set ih [image height $_image(legend)]
2581    set x1 [expr $x2 - ($iw*12)/10]
2582
2583    $c bind title <ButtonPress> [itcl::code $this LegendTitleAction post]
2584    $c bind title <Enter> [itcl::code $this LegendTitleAction enter]
2585    $c bind title <Leave> [itcl::code $this LegendTitleAction leave]
2586    # Reset the item coordinates according the current size of the plot.
2587    $c itemconfigure title -text $title
2588    if { [info exists _limits($_curFldName)] } {
2589        foreach { vmin vmax } $_limits($_curFldName) break
2590        $c itemconfigure vmin -text [format %g $vmin]
2591        $c itemconfigure vmax -text [format %g $vmax]
2592    }
2593    set y 2
2594    # If there's a legend title, move the title to the correct position
2595    if { $title != "" } {
2596        $c itemconfigure title -text $title
2597        $c coords title $x $y
2598        incr y $lineht
2599        $c raise title
2600    }
2601    $c coords vmax $x $y
2602    incr y $lineht
2603    $c coords colormap $x $y
2604    $c coords sensor [expr $x - $iw] $y $x [expr $y + $ih]
2605    $c raise sensor
2606    $c coords vmin $x [expr {$h - 2}]
2607}
2608
2609# ----------------------------------------------------------------------
2610# USAGE: LegendTitleAction post
2611# USAGE: LegendTitleAction enter
2612# USAGE: LegendTitleAction leave
2613# USAGE: LegendTitleAction save
2614#
2615# Used internally to handle the dropdown list for the fields menu combobox.
2616# The post option is invoked when the field title is pressed to launch the
2617# dropdown.  The enter option is invoked when the user mouses over the field
2618# title. The leave option is invoked when the user moves the mouse away
2619# from the field title.  The save option is invoked whenever there is a
2620# selection from the list, to alert the visualization server.
2621# ----------------------------------------------------------------------
2622itcl::body Rappture::VtkGlyphViewer::LegendTitleAction {option} {
2623    set c $itk_component(view)
2624    switch -- $option {
2625        post {
2626            foreach { x1 y1 x2 y2 } [$c bbox title] break
2627            set cw [winfo width $itk_component(view)]
2628            set mw [winfo reqwidth $itk_component(fieldmenu)]
2629            set x1 [expr $cw - $mw]
2630            set x [expr $x1 + [winfo rootx $itk_component(view)]]
2631            set y [expr $y2 + [winfo rooty $itk_component(view)]]
2632            tk_popup $itk_component(fieldmenu) $x $y
2633        }
2634        enter {
2635            $c itemconfigure title -fill red
2636        }
2637        leave {
2638            $c itemconfigure title -fill $itk_option(-plotforeground)
2639        }
2640        save {
2641            $itk_component(field) value $_curFldLabel
2642            AdjustSetting -field
2643        }
2644        default {
2645            error "bad option \"$option\": should be post, enter, leave or save"
2646        }
2647    }
2648}
2649
2650#
2651# SetCurrentColormap --
2652#
2653itcl::body Rappture::VtkGlyphViewer::SetCurrentColormap { name } {
2654    # Keep track of the colormaps that we build.
2655    if { ![info exists _colormaps($name)] } {
2656        BuildColormap $name
2657        set _colormaps($name) 1
2658    }
2659    set _currentColormap $name
2660    SendCmd "glyphs colormap $_currentColormap"
2661    #SendCmd "cutplane colormap $_currentColormap"
2662}
2663
2664#
2665# BuildColormap --
2666#
2667# Build the designated colormap on the server.
2668#
2669itcl::body Rappture::VtkGlyphViewer::BuildColormap { name } {
2670    set cmap [ColorsToColormap $name]
2671    if { [llength $cmap] == 0 } {
2672        set cmap "0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0"
2673    }
2674    set amap "0.0 1.0 1.0 1.0"
2675    SendCmd "colormap add $name { $cmap } { $amap }"
2676}
2677
2678itcl::body Rappture::VtkGlyphViewer::SetOrientation { side } {
2679    array set positions {
2680        front "1 0 0 0"
2681        back  "0 0 1 0"
2682        left  "0.707107 0 -0.707107 0"
2683        right "0.707107 0 0.707107 0"
2684        top   "0.707107 -0.707107 0 0"
2685        bottom "0.707107 0.707107 0 0"
2686    }
2687    foreach name { -qw -qx -qy -qz } value $positions($side) {
2688        set _view($name) $value
2689    }
2690    set q [ViewToQuaternion]
2691    $_arcball quaternion $q
2692    SendCmd "camera orient $q"
2693    SendCmd "camera reset"
2694    set _view(-xpan) 0
2695    set _view(-ypan) 0
2696    set _view(-zoom) 1.0
2697}
2698
2699itcl::body Rappture::VtkGlyphViewer::SetCurrentFieldName { dataobj } {
2700    set _first $dataobj
2701    $itk_component(field) choices delete 0 end
2702    $itk_component(fieldmenu) delete 0 end
2703    array unset _fields
2704    set _curFldName ""
2705    foreach cname [$_first components] {
2706        foreach fname [$_first fieldnames $cname] {
2707            if { [info exists _fields($fname)] } {
2708                continue
2709            }
2710            foreach { label units components } \
2711                [$_first fieldinfo $fname] break
2712            $itk_component(field) choices insert end "$fname" "$label"
2713            $itk_component(fieldmenu) add radiobutton -label "$label" \
2714                -value $label -variable [itcl::scope _curFldLabel] \
2715                -selectcolor red \
2716                -activebackground $itk_option(-plotbackground) \
2717                -activeforeground $itk_option(-plotforeground) \
2718                -font "Arial 8" \
2719                -command [itcl::code $this LegendTitleAction save]
2720            set _fields($fname) [list $label $units $components]
2721            if { $_curFldName == "" } {
2722                set _curFldName $fname
2723                set _curFldLabel $label
2724            }
2725        }
2726    }
2727    $itk_component(field) value $_curFldLabel
2728}
Note: See TracBrowser for help on using the repository browser.