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

Last change on this file since 2144 was 2144, checked in by gah, 13 years ago

vtk-contour-viewer additions: still experimental

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