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

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

merge (by hand) with Rappture1.2 branch

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