source: trunk/gui/scripts/valueresult.tcl @ 766

Last change on this file since 766 was 766, checked in by mmc, 17 years ago

Fixed the output viewer for numbers/integers to show a plot of
the value versus input parameters. As you change the ResultSet?
control, the x-axis updates to show the number versus values
in the result set.

Fixed the Rappture::result command to include the user's login
in the metadata, so we know who performed the computation.

File size: 9.2 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: ValueResult - Log output for ResultSet
3#
4#  This widget is used to show text output in a ResultSet.  The log
5#  output from a tool, for example, is rendered as a ValueResult.
6# ======================================================================
7#  AUTHOR:  Michael McLennan, Purdue University
8#  Copyright (c) 2004-2005  Purdue Research Foundation
9#
10#  See the file "license.terms" for information on usage and
11#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12# ======================================================================
13package require Itk
14package require BLT
15
16option add *ValueResult.font \
17    -*-helvetica-medium-r-normal-*-12-* widgetDefault
18
19itcl::class Rappture::ValueResult {
20    inherit itk::Widget
21
22    constructor {args} { # defined below }
23
24    public method add {dataobj {settings ""}}
25    public method get {}
26    public method delete {args}
27    public method scale {args}
28    public method parameters {title args} { # do nothing }
29    public method download {option args}
30
31    protected method _rebuild {}
32
33    private variable _dispatcher "" ;# dispatcher for !events
34
35    private variable _dlist ""    ;# list of data objects being displayed
36    private variable _dobj2color  ;# maps data object => color
37    private variable _dobj2raise  ;# maps data object => raise flag 0/1
38    private variable _dobj2desc   ;# maps data object => description
39}
40                                                                               
41itk::usual ValueResult {
42    keep -background -foreground -cursor -font
43}
44
45# ----------------------------------------------------------------------
46# CONSTRUCTOR
47# ----------------------------------------------------------------------
48itcl::body Rappture::ValueResult::constructor {args} {
49    Rappture::dispatcher _dispatcher
50    $_dispatcher register !rebuild
51    $_dispatcher dispatch $this !rebuild "[itcl::code $this _rebuild]; list"
52
53    itk_component add scroller {
54        Rappture::Scroller $itk_interior.scroller \
55            -xscrollmode auto -yscrollmode auto
56    }
57    pack $itk_component(scroller) -expand yes -fill both
58
59    itk_component add html {
60        Rappture::HTMLviewer $itk_component(scroller).html
61    }
62    $itk_component(scroller) contents $itk_component(html)
63
64    eval itk_initialize $args
65}
66
67# ----------------------------------------------------------------------
68# USAGE: add <dataobj> ?<settings>?
69#
70# Clients use this to add a data object to the plot.  If the optional
71# <settings> are specified, then the are applied to the data.  Allowed
72# settings are -color and -brightness, -width, -linestyle and -raise.
73# (Many of these are ignored.)
74# ----------------------------------------------------------------------
75itcl::body Rappture::ValueResult::add {dataobj {settings ""}} {
76    array set params {
77        -color ""
78        -brightness 0
79        -width ""
80        -linestyle ""
81        -raise 0
82        -description ""
83    }
84    foreach {opt val} $settings {
85        if {![info exists params($opt)]} {
86            error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]"
87        }
88        set params($opt) $val
89    }
90    if {$params(-color) == "auto" || $params(-color) == "autoreset"} {
91        # can't handle -autocolors yet
92        set params(-color) black
93    }
94
95    if {"" != $dataobj} {
96        # find the value and assign it with the proper coloring
97        if {"" != $params(-color) && "" != $params(-brightness)
98              && $params(-brightness) != 0} {
99            set params(-color) [Rappture::color::brightness \
100                $params(-color) $params(-brightness)]
101        }
102
103        set pos [lsearch -exact $dataobj $_dlist]
104        if {$pos < 0} {
105            lappend _dlist $dataobj
106            set _dobj2color($dataobj) $params(-color)
107            set _dobj2raise($dataobj) $params(-raise)
108            set _dobj2desc($dataobj) $params(-description)
109            $_dispatcher event -idle !rebuild
110        }
111    }
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::ValueResult::get {} {
121    # put the dataobj list in order according to -raise options
122    set dlist $_dlist
123    foreach obj $dlist {
124        if {[info exists _dobj2raise($obj)] && $_dobj2raise($obj)} {
125            set i [lsearch -exact $dlist $obj]
126            if {$i >= 0} {
127                set dlist [lreplace $dlist $i $i]
128                lappend dlist $obj
129            }
130        }
131    }
132    return $dlist
133}
134
135# ----------------------------------------------------------------------
136# USAGE: delete ?<curve1> <curve2> ...?
137#
138# Clients use this to delete a curve from the plot.  If no curves
139# are specified, then all curves are deleted.
140# ----------------------------------------------------------------------
141itcl::body Rappture::ValueResult::delete {args} {
142    if {[llength $args] == 0} {
143        set args $_dlist
144    }
145
146    # delete all specified objects
147    set changed 0
148    foreach obj $args {
149        set pos [lsearch -exact $_dlist $obj]
150        if {$pos >= 0} {
151            set _dlist [lreplace $_dlist $pos $pos]
152            catch {unset _dobj2color($obj)}
153            catch {unset _dobj2raise($obj)}
154            catch {unset _dobj2desc($obj)}
155            set changed 1
156        }
157    }
158
159    # if anything changed, then rebuild the plot
160    if {$changed} {
161        $_dispatcher event -idle !rebuild
162    }
163}
164
165# ----------------------------------------------------------------------
166# USAGE: scale ?<curve1> <curve2> ...?
167#
168# Sets the default limits for the overall plot according to the
169# limits of the data for all of the given <curve> objects.  This
170# accounts for all curves--even those not showing on the screen.
171# Because of this, the limits are appropriate for all curves as
172# the user scans through data in the ResultSet viewer.
173# ----------------------------------------------------------------------
174itcl::body Rappture::ValueResult::scale {args} {
175    # nothing to do for values
176}
177
178# ----------------------------------------------------------------------
179# USAGE: download coming
180# USAGE: download controls <downloadCommand>
181# USAGE: download now
182#
183# Clients use this method to create a downloadable representation
184# of the plot.  Returns a list of the form {ext string}, where
185# "ext" is the file extension (indicating the type of data) and
186# "string" is the data itself.
187# ----------------------------------------------------------------------
188itcl::body Rappture::ValueResult::download {option args} {
189    switch $option {
190        coming {
191            # nothing to do
192        }
193        controls {
194            # no controls for this download yet
195            return ""
196        }
197        now {
198            if {[llength $_dlist] == 1} {
199                set lstr [$_dlist get about.label]
200                set mesg "$lstr [$_dlist get current]"
201            } else {
202                set mesg ""
203                foreach obj $_dlist {
204                    set lstr [$obj get about.label]
205                    append mesg "$lstr [$obj get current]\n"
206                    if {[string length $_dobj2desc($obj)] > 0} {
207                        foreach line [split $_dobj2desc($obj) \n] {
208                            append mesg " * $line\n"
209                        }
210                        append mesg "\n"
211                    }
212                }
213            }
214            return [list .txt $mesg]
215        }
216        default {
217            error "bad option \"$option\": should be coming, controls, now"
218        }
219    }
220}
221
222# ----------------------------------------------------------------------
223# USAGE: _rebuild
224#
225# Used internally to rebuild the contents of this widget
226# whenever the data within it changes.  Shows the value
227# for the topmost data object in its associated color.
228# ----------------------------------------------------------------------
229itcl::body Rappture::ValueResult::_rebuild {} {
230    set html "<html><body>"
231
232    set obj [lindex $_dlist 0]
233    if {"" != $obj} {
234        set label [$obj get about.label]
235        if {"" != $label && [string index $label end] != ":"} {
236            append label ":"
237        }
238        append html "<h3>$label</h3>\n"
239    }
240
241    foreach obj $_dlist {
242        if {$_dobj2raise($obj)} {
243            set bold0 "<b>"
244            set bold1 "</b>"
245            set bg "background:#ffffcc; border:1px solid #cccccc;"
246        } else {
247            set bold0 ""
248            set bold1 ""
249            set bg ""
250        }
251        if {$_dobj2color($obj) != ""} {
252            set color0 "<font style=\"color: $_dobj2color($obj)\">"
253            set color1 "</font>"
254        } else {
255            set color0 ""
256            set color1 ""
257        }
258
259        append html "<div style=\"margin:8px; padding:4px; $bg\">${bold0}${color0}[$obj get current]${color1}${bold1}"
260        if {$_dobj2raise($obj) && [string length $_dobj2desc($obj)] > 0} {
261            foreach line [split $_dobj2desc($obj) \n] {
262                append html "<li style=\"margin-left:12px;\">$line</li>\n"
263            }
264        }
265        append html "</div>"
266    }
267    append html "</body></html>"
268    $itk_component(html) load $html
269}
Note: See TracBrowser for help on using the repository browser.