source: trunk/gui/scripts/field3dresult.tcl @ 2790

Last change on this file since 2790 was 2744, checked in by gah, 12 years ago
File size: 6.8 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: field3dresult - plot a field in a ResultSet
3#
4#  This widget visualizes scalar/vector fields on 3D meshes.
5#  It is normally used in the ResultViewer to show results from the
6#  run of a Rappture tool.  Use the "add" and "delete" methods to
7#  control the dataobjs showing on the plot.
8# ======================================================================
9#  AUTHOR:  Michael McLennan, Purdue University
10#  Copyright (c) 2004-2005  Purdue Research Foundation
11#
12#  See the file "license.terms" for information on usage and
13#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14# ======================================================================
15package require Itk
16
17option add *Field3DResult.width 4i widgetDefault
18option add *Field3DResult.height 4i widgetDefault
19option add *Field3DResult.foreground black widgetDefault
20option add *Field3DResult.controlBackground gray widgetDefault
21option add *Field3DResult.controlDarkBackground #999999 widgetDefault
22option add *Field3DResult.plotBackground black widgetDefault
23option add *Field3DResult.plotForeground white widgetDefault
24option add *Field3DResult.font \
25    -*-helvetica-medium-r-normal-*-12-* widgetDefault
26
27itcl::class Rappture::Field3DResult {
28    inherit itk::Widget
29
30    itk_option define -mode mode Mode "auto"
31
32    constructor {args} { # defined below }
33    destructor { # defined below }
34
35    public method add {dataobj {settings ""}}
36    public method get {}
37    public method delete {args}
38    public method scale {args}
39    public method snap {w h}
40    public method parameters {title args} { # do nothing }
41    public method download {option args}
42}
43
44itk::usual Field3DResult {
45    keep -background -foreground -cursor -font
46    keep -plotbackground -plotforeground
47}
48
49# ----------------------------------------------------------------------
50# CONSTRUCTOR
51# ----------------------------------------------------------------------
52itcl::body Rappture::Field3DResult::constructor {args} {
53    array set flags {
54        -mode auto
55    }
56    array set flags $args
57    switch -- $flags(-mode) {
58        "auto" - "nanovis" - "flowvis" {
59            set servers [Rappture::VisViewer::GetServerList "nanovis"]
60        }
61        "vtkcontour" - "vtkstreamlines" - "vtkvolume" - "vtkviewer"  {
62            set servers [Rappture::VisViewer::GetServerList "vtkvis"]
63        }
64        "vtk" {
65            # Old vtk contour widget
66            set servers ""
67        }
68        default {
69            puts stderr "unknown render mode \"$flags(-mode)\""
70        }
71    }           
72    if {"" != $servers && $flags(-mode) != "vtk"} {
73        switch -- $flags(-mode) {
74            "auto" - "nanovis" {
75                itk_component add renderer {
76                    Rappture::NanovisViewer $itk_interior.ren $servers
77                }
78            }
79            "flowvis" {
80                itk_component add renderer {
81                    Rappture::FlowvisViewer $itk_interior.ren $servers
82                }
83            }
84            "vtkvolume" {
85                catch {
86                itk_component add renderer {
87                    Rappture::VtkVolumeViewer $itk_interior.ren $servers
88                }
89                } errs
90                puts stderr errs=$errs
91            }
92            "vtkstreamlines" {
93                itk_component add renderer {
94                    Rappture::VtkStreamlinesViewer $itk_interior.ren $servers
95                }
96            }
97            default {
98                puts stderr "unknown render mode \"$flags(-mode)\""
99            }
100        }               
101        pack $itk_component(renderer) -expand yes -fill both
102
103        # can't connect to rendering farm?  then fall back to older viewer
104        if {![$itk_component(renderer) isconnected]} {
105            destroy $itk_component(renderer)
106        }
107    }
108
109    if {![info exists itk_component(renderer)]} {
110        itk_component add renderer {
111            Rappture::ContourResult $itk_interior.ren
112        }
113        pack $itk_component(renderer) -expand yes -fill both
114    }
115
116    eval itk_initialize $args
117}
118
119# ----------------------------------------------------------------------
120# DESTRUCTOR
121# ----------------------------------------------------------------------
122itcl::body Rappture::Field3DResult::destructor {} {
123}
124
125# ----------------------------------------------------------------------
126# USAGE: add <dataobj> ?<settings>?
127#
128# Clients use this to add a data object to the plot.  The optional
129# <settings> are used to configure the plot.  Allowed settings are
130# -color, -brightness, -width, -linestyle, and -raise.
131# ----------------------------------------------------------------------
132itcl::body Rappture::Field3DResult::add {dataobj {settings ""}} {
133    eval $itk_component(renderer) add $dataobj [list $settings]
134}
135
136# ----------------------------------------------------------------------
137# USAGE: get
138#
139# Clients use this to query the list of objects being plotted, in
140# order from bottom to top of this result.
141# ----------------------------------------------------------------------
142itcl::body Rappture::Field3DResult::get {} {
143    return [$itk_component(renderer) get]
144}
145
146# ----------------------------------------------------------------------
147# USAGE: delete ?<dataobj1> <dataobj2> ...?
148#
149# Clients use this to delete a dataobj from the plot.  If no dataobjs
150# are specified, then all dataobjs are deleted.
151# ----------------------------------------------------------------------
152itcl::body Rappture::Field3DResult::delete {args} {
153    eval $itk_component(renderer) delete $args
154}
155
156# ----------------------------------------------------------------------
157# USAGE: scale ?<data1> <data2> ...?
158#
159# Sets the default limits for the overall plot according to the
160# limits of the data for all of the given <data> objects.  This
161# accounts for all objects--even those not showing on the screen.
162# Because of this, the limits are appropriate for all objects as
163# the user scans through data in the ResultSet viewer.
164# ----------------------------------------------------------------------
165itcl::body Rappture::Field3DResult::scale {args} {
166    eval $itk_component(renderer) scale $args
167}
168
169# ----------------------------------------------------------------------
170# USAGE: download coming
171# USAGE: download controls <downloadCommand>
172# USAGE: download now
173#
174# Clients use this method to create a downloadable representation
175# of the plot.  Returns a list of the form {ext string}, where
176# "ext" is the file extension (indicating the type of data) and
177# "string" is the data itself.
178# ----------------------------------------------------------------------
179itcl::body Rappture::Field3DResult::download {option args} {
180    eval $itk_component(renderer) download $option $args
181}
182
183itcl::body Rappture::Field3DResult::snap { w h } {
184    return [$itk_component(renderer) snap $w $h]
185}
Note: See TracBrowser for help on using the repository browser.