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

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

fix for sequence of contours

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