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

Last change on this file since 2219 was 2205, checked in by gah, 13 years ago
File size: 6.2 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
58    switch -- $flags(-mode) {
59        "auto" - "nanovis" - "flowvis" {
60            set servers [Rappture::VisViewer::GetServerList "nanovis"]
61        }
62        "vtkcontour" {
63            set servers [Rappture::VisViewer::GetServerList "vtkvis"]
64        }
65        "vtk" {
66            # Old vtk contour widget
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            default {
85                puts stderr "unknown render mode \"$flags(-mode)\""
86            }
87        }               
88        pack $itk_component(renderer) -expand yes -fill both
89
90        # can't connect to rendering farm?  then fall back to older viewer
91        if {![$itk_component(renderer) isconnected]} {
92            destroy $itk_component(renderer)
93        }
94    }
95
96    if {![info exists itk_component(renderer)]} {
97        itk_component add renderer {
98            Rappture::ContourResult $itk_interior.ren
99        }
100        pack $itk_component(renderer) -expand yes -fill both
101    }
102
103    eval itk_initialize $args
104}
105
106# ----------------------------------------------------------------------
107# DESTRUCTOR
108# ----------------------------------------------------------------------
109itcl::body Rappture::Field3DResult::destructor {} {
110}
111
112# ----------------------------------------------------------------------
113# USAGE: add <dataobj> ?<settings>?
114#
115# Clients use this to add a data object to the plot.  The optional
116# <settings> are used to configure the plot.  Allowed settings are
117# -color, -brightness, -width, -linestyle, and -raise.
118# ----------------------------------------------------------------------
119itcl::body Rappture::Field3DResult::add {dataobj {settings ""}} {
120    eval $itk_component(renderer) add $dataobj [list $settings]
121}
122
123# ----------------------------------------------------------------------
124# USAGE: get
125#
126# Clients use this to query the list of objects being plotted, in
127# order from bottom to top of this result.
128# ----------------------------------------------------------------------
129itcl::body Rappture::Field3DResult::get {} {
130    return [$itk_component(renderer) get]
131}
132
133# ----------------------------------------------------------------------
134# USAGE: delete ?<dataobj1> <dataobj2> ...?
135#
136# Clients use this to delete a dataobj from the plot.  If no dataobjs
137# are specified, then all dataobjs are deleted.
138# ----------------------------------------------------------------------
139itcl::body Rappture::Field3DResult::delete {args} {
140    eval $itk_component(renderer) delete $args
141}
142
143# ----------------------------------------------------------------------
144# USAGE: scale ?<data1> <data2> ...?
145#
146# Sets the default limits for the overall plot according to the
147# limits of the data for all of the given <data> objects.  This
148# accounts for all objects--even those not showing on the screen.
149# Because of this, the limits are appropriate for all objects as
150# the user scans through data in the ResultSet viewer.
151# ----------------------------------------------------------------------
152itcl::body Rappture::Field3DResult::scale {args} {
153    eval $itk_component(renderer) scale $args
154}
155
156# ----------------------------------------------------------------------
157# USAGE: download coming
158# USAGE: download controls <downloadCommand>
159# USAGE: download now
160#
161# Clients use this method to create a downloadable representation
162# of the plot.  Returns a list of the form {ext string}, where
163# "ext" is the file extension (indicating the type of data) and
164# "string" is the data itself.
165# ----------------------------------------------------------------------
166itcl::body Rappture::Field3DResult::download {option args} {
167    eval $itk_component(renderer) download $option $args
168}
169
170itcl::body Rappture::Field3DResult::snap { w h } {
171    return [$itk_component(renderer) snap $w $h]
172}
Note: See TracBrowser for help on using the repository browser.