source: trunk/gui/scripts/field2dresult.tcl @ 3934

Last change on this file since 3934 was 3684, checked in by gah, 11 years ago

fixes to rlimit for unlimited

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