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

Last change on this file since 822 was 822, checked in by gah, 17 years ago
File size: 5.9 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: field2dresult - 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# ======================================================================
15
16package require Itk
17
18option add *Field2DResult.width 4i widgetDefault
19option add *Field2DResult.height 4i widgetDefault
20option add *Field2DResult.foreground black widgetDefault
21option add *Field2DResult.controlBackground gray widgetDefault
22option add *Field2DResult.controlDarkBackground #999999 widgetDefault
23option add *Field2DResult.plotBackground black widgetDefault
24option add *Field2DResult.plotForeground white widgetDefault
25option add *Field2DResult.font \
26    -*-helvetica-medium-r-normal-*-12-* widgetDefault
27
28itcl::class Rappture::Field2DResult {
29    inherit itk::Widget
30
31    itk_option define -mode mode Mode "auto"
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 parameters {title args} { # do nothing }
41    public method download {option args}
42
43    # resources file tells us the nanovis server
44    public common _nanovisHosts ""
45    public proc setNanovisServer {namelist} {
46        if {[regexp {^[a-zA-Z0-9\.]+:[0-9]+(,[a-zA-Z0-9\.]+:[0-9]+)*$} $namelist match]} {
47            set _nanovisHosts $namelist
48        } else {
49            error "bad nanovis server address \"$namelist\": should be host:port,host:port,..."
50        }
51    }
52}
53
54# must use this name -- plugs into Rappture::resources::load
55proc field2d_init_resources {} {
56    Rappture::resources::register \
57        nanovis_server Rappture::Field2DResult::setNanovisServer
58}
59
60itk::usual Field2DResult {
61    keep -background -foreground -cursor -font
62    keep -plotbackground -plotforeground
63}
64
65# ----------------------------------------------------------------------
66# CONSTRUCTOR
67# ----------------------------------------------------------------------
68itcl::body Rappture::Field2DResult::constructor {args} {
69    array set flags {
70        -mode auto
71    }
72    array set flags $args
73
74    if {"" != $_nanovisHosts && $flags(-mode) != "vtk"} {
75        itk_component add renderer {
76            Rappture::HeightMapViewer $itk_interior.ren $_nanovisHosts
77        }
78        pack $itk_component(renderer) -expand yes -fill both
79
80        # can't connect to rendering farm?  then fall back to older viewer
81        if {![$itk_component(renderer) isconnected]} {
82            destroy $itk_component(renderer)
83        }
84    }
85
86    if {![info exists itk_component(renderer)]} {
87        itk_component add renderer {
88            Rappture::ContourResult $itk_interior.ren
89        }
90        pack $itk_component(renderer) -expand yes -fill both
91    }
92
93    eval itk_initialize $args
94}
95
96# ----------------------------------------------------------------------
97# DESTRUCTOR
98# ----------------------------------------------------------------------
99itcl::body Rappture::Field2DResult::destructor {} {
100}
101
102# ----------------------------------------------------------------------
103# USAGE: add <dataobj> ?<settings>?
104#
105# Clients use this to add a data object to the plot.  The optional
106# <settings> are used to configure the plot.  Allowed settings are
107# -color, -brightness, -width, -linestyle, and -raise.
108# ----------------------------------------------------------------------
109itcl::body Rappture::Field2DResult::add {dataobj {settings ""}} {
110    eval $itk_component(renderer) add $dataobj [list $settings]
111}
112
113# ----------------------------------------------------------------------
114# USAGE: get
115#
116# Clients use this to query the list of objects being plotted, in
117# order from bottom to top of this result.
118# ----------------------------------------------------------------------
119itcl::body Rappture::Field2DResult::get {} {
120    return [$itk_component(renderer) get]
121}
122
123# ----------------------------------------------------------------------
124# USAGE: delete ?<dataobj1> <dataobj2> ...?
125#
126# Clients use this to delete a dataobj from the plot.  If no dataobjs
127# are specified, then all dataobjs are deleted.
128# ----------------------------------------------------------------------
129itcl::body Rappture::Field2DResult::delete {args} {
130    eval $itk_component(renderer) delete $args
131}
132
133# ----------------------------------------------------------------------
134# USAGE: scale ?<data1> <data2> ...?
135#
136# Sets the default limits for the overall plot according to the
137# limits of the data for all of the given <data> objects.  This
138# accounts for all objects--even those not showing on the screen.
139# Because of this, the limits are appropriate for all objects as
140# the user scans through data in the ResultSet viewer.
141# ----------------------------------------------------------------------
142itcl::body Rappture::Field2DResult::scale {args} {
143    eval $itk_component(renderer) scale $args
144}
145
146# ----------------------------------------------------------------------
147# USAGE: download coming
148# USAGE: download controls <downloadCommand>
149# USAGE: download now
150#
151# Clients use this method to create a downloadable representation
152# of the plot.  Returns a list of the form {ext string}, where
153# "ext" is the file extension (indicating the type of data) and
154# "string" is the data itself.
155# ----------------------------------------------------------------------
156itcl::body Rappture::Field2DResult::download {option args} {
157    $itk_component(renderer) download $option
158}
Note: See TracBrowser for help on using the repository browser.