source: trunk/gui/scripts/uqnotebook.tcl @ 6480

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

Merge UQ and fixes from 1.4 branch

File size: 8.2 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2
3# ----------------------------------------------------------------------
4#  COMPONENT: UqNotebook - Tabbed Notebook for UQ results.
5#
6# ======================================================================
7#  AUTHOR:  Martin Hunt, Purdue University
8#  Copyright (c) 2015  HUBzero Foundation, LLC
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
16
17itcl::class Rappture::UqNotebook {
18    inherit itk::Widget
19
20    itk_option define -gridcolor gridColor GridColor ""
21    itk_option define -activecolor activeColor ActiveColor ""
22    itk_option define -dimcolor dimColor DimColor ""
23    itk_option define -autocolors autoColors AutoColors ""
24
25    constructor {args} {
26        # defined below
27    }
28    destructor {
29        # defined below
30    }
31
32    public method add {dataobj {settings ""}}
33    public method scale {args}
34    public method download {option args}
35    public method parameters {title args} {}
36    public method delete {args}
37    public method get {}
38    private method _plotit {xmlobj path index settings}
39    private variable _index2widget; #_index2widget($sim,$tab) -> $w
40    private variable _nblist; # _nblist($sim) returns notebook to pack
41    private variable _nbnum 0; # currently displayed notebook number (sim)
42}
43
44itk::usual UqNotebook {
45    keep -background -cursor -font
46}
47itk::usual Tabset {
48    keep -background -cursor -font
49}
50itk::usual Tabnotebook {
51    keep -background -cursor -font
52}
53
54# ----------------------------------------------------------------------
55# CONSTRUCTOR
56# ----------------------------------------------------------------------
57itcl::body Rappture::UqNotebook::constructor {args} {
58    #Rappture::dispatcher _dispatcher
59    #$_dispatcher register !rebuild
60    #$_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list"
61
62    option add hull.width hull.height
63    pack propagate $itk_component(hull) yes
64
65    eval itk_initialize $args
66}
67
68# ----------------------------------------------------------------------
69# DESTRUCTOR
70# ----------------------------------------------------------------------
71itcl::body Rappture::UqNotebook::destructor {} {
72}
73
74# ----------------------------------------------------------------------
75# USAGE: add <dataobj> ?<settings>?
76#
77# Clients use this to add a dataobj to the plot.  The optional <settings>
78# are used to configure the plot.  Allowed settings are -color,
79# -brightness, -width, -linestyle and -raise.
80# ----------------------------------------------------------------------
81itcl::body Rappture::UqNotebook::add {uqobj {settings ""}} {
82    #puts "UqNotebook ADD $uqobj ($settings)"
83    array set attrs $settings
84    array set d [$uqobj get]
85    #puts "SIMULATION $attrs(-simulation)"
86
87    # the notebook number is the same as the simulation number
88    set nbnum $attrs(-simulation)
89
90    # See if we are already displaying the requested notebook
91    if {$nbnum == $_nbnum} {
92        return
93    }
94
95    if {[info exists _nblist($_nbnum)]} {
96        set active [$itk_component(uq_nb_$_nbnum) index select]
97        pack forget $itk_component(uq_nb_$_nbnum)
98    } else  {
99        set active -1
100    }
101
102    set _nbnum $nbnum
103
104    if {![info exists _nblist($nbnum)]} {
105        #puts "Creating notebook #$nbnum"
106        itk_component add uq_nb_$nbnum {
107            blt::tabnotebook $itk_interior.uq_nb_$nbnum -tearoff no
108        }
109
110        set _nblist($nbnum) $itk_component(uq_nb_$nbnum)
111
112        foreach name [list PDF Probability Sensitivity Response "All Runs" Sequence] {
113            if {[info exists d($name)]} {
114                foreach {index items} $d($name) break
115                $itk_component(uq_nb_$nbnum) insert $index -text $name
116                foreach obj $items {
117                    foreach {xmlobj path} $obj break
118                    _plotit $xmlobj $path $index $settings
119                }
120            }
121        }
122    }
123    pack $itk_component(uq_nb_$nbnum) -expand yes -fill both
124    if {$active >= 0} {
125        after 100 $itk_component(uq_nb_$nbnum) select $active
126        after idle $itk_component(uq_nb_$nbnum) select $active
127    }
128}
129
130itcl::body Rappture::UqNotebook::_plotit {xmlobj path index settings} {
131    set type [$xmlobj element -as type $path]
132    #puts "uqNotebook::_plotit: xmlobj=$xmlobj path=$path type=$type"
133
134    if {[regexp {output.curve\(curve_pdf-[^-]*-([0-9]+)\)} $path match prob]} {
135        puts "Probability: $prob"
136    } else {
137        set prob ""
138    }
139
140    array set attrs $settings
141    set sim $attrs(-simulation)
142    # puts "sim=$sim index=$index"
143    set dobj ""
144
145    set w $itk_component(uq_nb_$sim).$index
146    switch -- $type {
147        response {
148            set dobj [Rappture::Response ::#auto $xmlobj $path]
149            if {![info exists _index2widget($sim,$index)]} {
150                Rappture::ResponseViewer $w
151            }
152        }
153        histogram {
154            set dobj [Rappture::Histogram ::#auto $xmlobj $path]
155            if {![info exists _index2widget($sim,$index)]} {
156                Rappture::HistogramResult $w
157            }
158        }
159        curve {
160            set dobj [Rappture::Curve ::#auto $xmlobj $path]
161            set type [$dobj hints type]
162            if {![info exists _index2widget($sim,$index)]} {
163                if {$type == "bars"} {
164                    Rappture::BarchartResult $w
165                } elseif {$prob != ""} {
166                    Rappture::UqCurve $w
167                } else {
168                    Rappture::XyResult $w
169                }
170            }
171        }
172        sequence {
173            set dobj [Rappture::Sequence ::#auto $xmlobj $path]
174            if {![info exists _index2widget($sim,$index)]} {
175                Rappture::SequenceResult $w
176            }
177        }
178        field {
179            set dobj [Rappture::Field ::#auto $xmlobj $path]
180        }
181        mesh {
182            set dobj [Rappture::Mesh ::#auto $xmlobj $path]
183        }
184        default {
185            error "Don't know how to plot $type"
186        }
187    }
188    set _index2widget($sim,$index) $w
189    if {$dobj != ""} {
190        if {$prob != ""} {
191            lappend settings -probability $prob
192        }
193        $w add $dobj $settings
194    }
195    $itk_component(uq_nb_$sim) tab configure $index -window $w -fill both
196}
197
198
199# ----------------------------------------------------------------------
200# USAGE: delete ?<dataobj1> <dataobj2> ...?
201#
202# Clients use this to delete a dataobj from the plot.  If no dataobjs
203# are specified, then all dataobjs are deleted.
204# ----------------------------------------------------------------------
205itcl::body Rappture::UqNotebook::delete {args} {
206    # puts "UqNotebook::delete $args"
207    # catch {$itk_component(uq_nb) delete 0 end}
208
209    # foreach index [array name _index2widget] {
210    #     puts "destroying index $index"
211    #     destroy $_index2widget($index)
212    # }
213    # foreach dobj $_objlist {
214    #     puts "destroying $dobj"
215    #     destroy $dobj
216    # }
217    # unset _index2widget
218    # set _objlist {}
219}
220
221# ----------------------------------------------------------------------
222# USAGE: scale ?<dataobj1> <dataobj2> ...?
223#
224# Sets the default limits for the overall plot according to the
225# limits of the data for all of the given <dataobj> objects.  This
226# accounts for all dataobjs--even those not showing on the screen.
227# Because of this, the limits are appropriate for all dataobjs as
228# the user scans through data in the ResultSet viewer.
229# ----------------------------------------------------------------------
230itcl::body Rappture::UqNotebook::scale {args} {
231    #puts "UqNotebook::scale $args"
232
233    # get all the tabs and call scale
234    #set num_tabs [$itk_component(uq_nb_$_nbnum) tab names]
235    #for {set i 0} {$i < $num_tabs} {incr i} {
236    #    puts "calling scale for tab $i"
237    #    eval $_index2widget($_nbnum,$i) scale $args
238    #}
239}
240
241itcl::body Rappture::UqNotebook::get {} {
242    #puts "*************** UqNotebook gets"
243}
244
245
246itcl::body Rappture::UqNotebook::download {option args} {
247    #set tab [$itk_component(uq_nb_$_nbnum) index select]
248    #puts "UqNotebook::download $option  : $args -> $_index2widget($_nbnum,$tab)"
249    #eval $_index2widget($_nbnum,$tab) download $option $args
250}
Note: See TracBrowser for help on using the repository browser.