source: branches/r9/gui/scripts/fieldresult.tcl @ 5106

Last change on this file since 5106 was 4919, checked in by gah, 9 years ago
File size: 8.3 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    set servers ""
59    switch -- $flags(-mode) {
60        "nanovis" - "flowvis" {
61            set servers [Rappture::VisViewer::GetServerList "nanovis"]
62        }
63        "contour" - "glyphs" - "heightmap" - "isosurface" - "streamlines" - "surface" - "vtkimage" - "vtkviewer" - "vtkvolume" {
64            set servers [Rappture::VisViewer::GetServerList "vtkvis"]
65        }
66        default {
67            puts stderr "unknown render mode \"$flags(-mode)\""
68        }
69    }
70    if {"" != $servers} {
71        switch -- $flags(-mode) {
72            "nanovis" {
73                itk_component add renderer {
74                    Rappture::NanovisViewer $itk_interior.ren $servers
75                }
76            }
77            "flowvis" {
78                itk_component add renderer {
79                    Rappture::FlowvisViewer $itk_interior.ren $servers
80                }
81            }
82            "glyphs" {
83                itk_component add renderer {
84                    Rappture::VtkGlyphViewer $itk_interior.ren $servers
85                }
86            }
87            "contour" - "heightmap" {
88                itk_component add renderer {
89                    Rappture::VtkHeightmapViewer $itk_interior.ren $servers \
90                        -mode $flags(-mode)
91                }
92            }
93            "isosurface" {
94                itk_component add renderer {
95                    Rappture::VtkIsosurfaceViewer $itk_interior.ren $servers
96                }
97            }
98            "streamlines" {
99                itk_component add renderer {
100                    Rappture::VtkStreamlinesViewer $itk_interior.ren $servers
101                }
102            }
103            "surface" {
104                itk_component add renderer {
105                    Rappture::VtkSurfaceViewer $itk_interior.ren $servers
106                }
107            }
108            "vtkimage" {
109                itk_component add renderer {
110                    Rappture::VtkImageViewer $itk_interior.ren $servers
111                }
112            }
113            "vtkviewer" {
114                itk_component add renderer {
115                    Rappture::VtkViewer $itk_interior.ren $servers
116                }
117            }
118            "vtkvolume" {
119                itk_component add renderer {
120                    Rappture::VtkVolumeViewer $itk_interior.ren $servers
121                }
122            }
123            default {
124                puts stderr "unknown render mode \"$flags(-mode)\""
125            }
126        }               
127        pack $itk_component(renderer) -expand yes -fill both
128
129        # can't connect to rendering farm?
130        if {![$itk_component(renderer) isconnected]} {
131            # Should show a message here
132            #destroy $itk_component(renderer)
133        }
134    }
135
136    if {![info exists itk_component(renderer)]} {
137        # No valid renderer (or couldn't connect?)
138        # Should show a message here
139    }
140    eval itk_initialize $args
141    #update
142}
143
144# ----------------------------------------------------------------------
145# DESTRUCTOR
146# ----------------------------------------------------------------------
147itcl::body Rappture::FieldResult::destructor {} {
148}
149
150# ----------------------------------------------------------------------
151# USAGE: add <dataobj> ?<settings>?
152#
153# Clients use this to add a data object to the plot.  The optional
154# <settings> are used to configure the plot.  Allowed settings are
155# -color, -brightness, -width, -linestyle, and -raise.
156# ----------------------------------------------------------------------
157itcl::body Rappture::FieldResult::add {dataobj {settings ""}} {
158    if { ![info exists itk_component(renderer)] } {
159        puts stderr "add: no renderer created."
160        return
161    }
162    eval $itk_component(renderer) add $dataobj [list $settings]
163}
164
165# ----------------------------------------------------------------------
166# USAGE: get
167#
168# Clients use this to query the list of objects being plotted, in
169# order from bottom to top of this result.
170# ----------------------------------------------------------------------
171itcl::body Rappture::FieldResult::get {} {
172    if { ![info exists itk_component(renderer)] } {
173        puts stderr "get: no renderer created."
174        return
175    }
176    return [$itk_component(renderer) get]
177}
178
179# ----------------------------------------------------------------------
180# USAGE: delete ?<dataobj1> <dataobj2> ...?
181#
182# Clients use this to delete a dataobj from the plot.  If no dataobjs
183# are specified, then all dataobjs are deleted.
184# ----------------------------------------------------------------------
185itcl::body Rappture::FieldResult::delete {args} {
186    if { [info exists itk_component(renderer)] } {
187        eval $itk_component(renderer) delete $args
188    }
189}
190
191# ----------------------------------------------------------------------
192# USAGE: scale ?<data1> <data2> ...?
193#
194# Sets the default limits for the overall plot according to the
195# limits of the data for all of the given <data> objects.  This
196# accounts for all objects--even those not showing on the screen.
197# Because of this, the limits are appropriate for all objects as
198# the user scans through data in the ResultSet viewer.
199# ----------------------------------------------------------------------
200itcl::body Rappture::FieldResult::scale {args} {
201    if { ![info exists itk_component(renderer)] } {
202        puts stderr "scale: no renderer created."
203        return
204    }
205    eval $itk_component(renderer) scale $args
206}
207
208# ----------------------------------------------------------------------
209# USAGE: download coming
210# USAGE: download controls <downloadCommand>
211# USAGE: download now
212#
213# Clients use this method to create a downloadable representation
214# of the plot.  Returns a list of the form {ext string}, where
215# "ext" is the file extension (indicating the type of data) and
216# "string" is the data itself.
217# ----------------------------------------------------------------------
218itcl::body Rappture::FieldResult::download {option args} {
219    if { ![info exists itk_component(renderer)] } {
220        puts stderr "download: no renderer created."
221        return
222    }
223    eval $itk_component(renderer) download $option $args
224}
225
226itcl::body Rappture::FieldResult::snap { w h } {
227    if { ![info exists itk_component(renderer)] } {
228        puts stderr "snap: no renderer created."
229        return
230    }
231    return [$itk_component(renderer) snap $w $h]
232}
Note: See TracBrowser for help on using the repository browser.