source: trunk/gui/scripts/fieldresult.tcl @ 4291

Last change on this file since 4291 was 4169, checked in by ldelgass, 10 years ago

Collapse Field2DResult and Field3DResult into FieldResult? and rely on Field
object to set default viewer appropriately. Also, don't try to fall back to
old Tcl VTK contour viewer. We should probably show the user an appropriate
error message if we don't have a valid viewer (which really shouldn't ever
happen). If no server can be reached, should we leave it to the specific
viewer widget to handle the error or should we delete the viewer and bubble
the error up to the FieldResult? widget?

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