source: trunk/gui/scripts/field3dresult.tcl @ 460

Last change on this file since 460 was 460, checked in by mmc, 18 years ago

Fixed the 3D viewer so that if it detects old-style vtk data, it will
drop back to using the old vtk viewer. This means that older tools
shouldn't be affected by the new nanovis upgrade.

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