source: branches/1.5/gui/scripts/fieldresult.tcl @ 6127

Last change on this file since 6127 was 6127, checked in by ldelgass, 8 years ago

Merge r6052:6053,r6066:6069,r6080 from trunk

File size: 7.5 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2# ----------------------------------------------------------------------
3#  COMPONENT: fieldresult - plot a field in a ResultSet
4#
5#  This widget visualizes fields on 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# ======================================================================
16package require Itk
17
18option add *FieldResult.width 4i widgetDefault
19option add *FieldResult.height 4i widgetDefault
20option add *FieldResult.foreground black widgetDefault
21option add *FieldResult.controlBackground gray widgetDefault
22option add *FieldResult.controlDarkBackground #999999 widgetDefault
23option add *FieldResult.plotBackground black widgetDefault
24option add *FieldResult.plotForeground white widgetDefault
25option add *FieldResult.font \
26    -*-helvetica-medium-r-normal-*-12-* widgetDefault
27
28itcl::class Rappture::FieldResult {
29    inherit itk::Widget
30
31    itk_option define -mode mode Mode ""
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 FieldResult {
46    keep -background -foreground -cursor -font
47    keep -plotbackground -plotforeground
48}
49
50# ----------------------------------------------------------------------
51# CONSTRUCTOR
52# ----------------------------------------------------------------------
53itcl::body Rappture::FieldResult::constructor {args} {
54    array set flags {
55        -mode ""
56    }
57    array set flags $args
58    switch -- $flags(-mode) {
59        "nanovis" {
60            itk_component add renderer {
61                Rappture::NanovisViewer $itk_interior.ren
62            }
63        }
64        "flowvis" {
65            itk_component add renderer {
66                Rappture::FlowvisViewer $itk_interior.ren
67            }
68        }
69        "glyphs" {
70            itk_component add renderer {
71                Rappture::VtkGlyphViewer $itk_interior.ren
72            }
73        }
74        "contour" - "heightmap" {
75            itk_component add renderer {
76                Rappture::VtkHeightmapViewer $itk_interior.ren \
77                    -mode $flags(-mode)
78            }
79        }
80        "isosurface" {
81            itk_component add renderer {
82                Rappture::VtkIsosurfaceViewer $itk_interior.ren
83            }
84        }
85        "streamlines" {
86            itk_component add renderer {
87                Rappture::VtkStreamlinesViewer $itk_interior.ren
88            }
89        }
90        "surface" {
91            itk_component add renderer {
92                Rappture::VtkSurfaceViewer $itk_interior.ren
93            }
94        }
95        "vtkimage" {
96            itk_component add renderer {
97                Rappture::VtkImageViewer $itk_interior.ren
98            }
99        }
100        "vtkviewer" {
101            itk_component add renderer {
102                Rappture::VtkViewer $itk_interior.ren
103            }
104        }
105        "vtkvolume" {
106            itk_component add renderer {
107                Rappture::VtkVolumeViewer $itk_interior.ren
108            }
109        }
110        default {
111            puts stderr "unknown render mode \"$flags(-mode)\""
112        }
113    }
114    pack $itk_component(renderer) -expand yes -fill both
115
116    # can't connect to rendering farm?
117    if {![$itk_component(renderer) isconnected]} {
118        # Should show a message here
119        #destroy $itk_component(renderer)
120    }
121
122    if {![info exists itk_component(renderer)]} {
123        # No valid renderer (or couldn't connect?)
124        # Should show a message here
125    }
126    eval itk_initialize $args
127    #update
128}
129
130# ----------------------------------------------------------------------
131# DESTRUCTOR
132# ----------------------------------------------------------------------
133itcl::body Rappture::FieldResult::destructor {} {
134}
135
136# ----------------------------------------------------------------------
137# USAGE: add <dataobj> ?<settings>?
138#
139# Clients use this to add a data object to the plot.  The optional
140# <settings> are used to configure the plot.  Allowed settings are
141# -color, -brightness, -width, -linestyle, and -raise.
142# ----------------------------------------------------------------------
143itcl::body Rappture::FieldResult::add {dataobj {settings ""}} {
144    if { ![info exists itk_component(renderer)] } {
145        puts stderr "add: no renderer created."
146        return
147    }
148    eval $itk_component(renderer) add $dataobj [list $settings]
149}
150
151# ----------------------------------------------------------------------
152# USAGE: get
153#
154# Clients use this to query the list of objects being plotted, in
155# order from bottom to top of this result.
156# ----------------------------------------------------------------------
157itcl::body Rappture::FieldResult::get {} {
158    if { ![info exists itk_component(renderer)] } {
159        puts stderr "get: no renderer created."
160        return
161    }
162    return [$itk_component(renderer) get]
163}
164
165# ----------------------------------------------------------------------
166# USAGE: delete ?<dataobj1> <dataobj2> ...?
167#
168# Clients use this to delete a dataobj from the plot.  If no dataobjs
169# are specified, then all dataobjs are deleted.
170# ----------------------------------------------------------------------
171itcl::body Rappture::FieldResult::delete {args} {
172    if { [info exists itk_component(renderer)] } {
173        eval $itk_component(renderer) delete $args
174    }
175}
176
177# ----------------------------------------------------------------------
178# USAGE: scale ?<data1> <data2> ...?
179#
180# Sets the default limits for the overall plot according to the
181# limits of the data for all of the given <data> objects.  This
182# accounts for all objects--even those not showing on the screen.
183# Because of this, the limits are appropriate for all objects as
184# the user scans through data in the ResultSet viewer.
185# ----------------------------------------------------------------------
186itcl::body Rappture::FieldResult::scale {args} {
187    if { ![info exists itk_component(renderer)] } {
188        puts stderr "scale: no renderer created."
189        return
190    }
191    eval $itk_component(renderer) scale $args
192}
193
194# ----------------------------------------------------------------------
195# USAGE: download coming
196# USAGE: download controls <downloadCommand>
197# USAGE: download now
198#
199# Clients use this method to create a downloadable representation
200# of the plot.  Returns a list of the form {ext string}, where
201# "ext" is the file extension (indicating the type of data) and
202# "string" is the data itself.
203# ----------------------------------------------------------------------
204itcl::body Rappture::FieldResult::download {option args} {
205    if { ![info exists itk_component(renderer)] } {
206        puts stderr "download: no renderer created."
207        return
208    }
209    eval $itk_component(renderer) download $option $args
210}
211
212itcl::body Rappture::FieldResult::snap { w h } {
213    if { ![info exists itk_component(renderer)] } {
214        puts stderr "snap: no renderer created."
215        return
216    }
217    return [$itk_component(renderer) snap $w $h]
218}
Note: See TracBrowser for help on using the repository browser.