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

Last change on this file since 3021 was 3019, checked in by ldelgass, 12 years ago

Add cases to handle all vtk viewers in Field2D|3DResult constructors. Also,
bring sequence result viewer routing in line with result viewer.

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