Ignore:
Timestamp:
Apr 13, 2012 12:04:37 PM (12 years ago)
Author:
gah
Message:

sync back with trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/blt4/gui/scripts/resultviewer.tcl

    r2745 r2966  
    3636    protected method _plotAdd {xmlobj {settings ""}}
    3737    protected method _fixScale {args}
    38     protected proc _xml2data {xmlobj path}
     38    protected method _xml2data {xmlobj path}
     39    protected method _cleanIndex {index}
    3940
    4041    private variable _dispatcher ""  ;# dispatchers for !events
     
    4243    private variable _mode2widget    ;# maps plotting mode => widget
    4344    private variable _dataslots ""   ;# list of all data objects in this widget
     45    private variable _xml2data       ;# maps xmlobj => data obj in _dataslots
    4446}
    4547
     
    7981# ----------------------------------------------------------------------
    8082itcl::body Rappture::ResultViewer::add {index xmlobj path} {
     83    set index [_cleanIndex $index]
    8184    set dobj [_xml2data $xmlobj $path]
    8285
     
    9699
    97100# ----------------------------------------------------------------------
    98 # USAGE: clear ?<index>?
    99 #
    100 # Clears one or all results in this result viewer.
     101# USAGE: clear ?<index>|<xmlobj>?
     102#
     103# Clears one or all results in this result viewer.  If a particular
     104# <index> is specified, then all data objects at that index are
     105# deleted.  If a particular <xmlobj> is specified, then all data
     106# objects related to that <xmlobj> are removed--regardless of whether
     107# they reside at one or more indices.
    101108# ----------------------------------------------------------------------
    102109itcl::body Rappture::ResultViewer::clear {{index ""}} {
    103     if {"" != $index} {
     110    if {$index ne ""} {
    104111        # clear one result
    105         if {$index >= 0 && $index < [llength $_dataslots]} {
    106             set slot [lindex $_dataslots $index]
    107             foreach dobj $slot {
     112        if {[catch {_cleanIndex $index} i] == 0} {
     113            if {$i >= 0 && $i < [llength $_dataslots]} {
     114                set slot [lindex $_dataslots $i]
     115                foreach dobj $slot {
     116                    itcl::delete object $dobj
     117                }
     118                set _dataslots [lreplace $_dataslots $i $i ""]
     119                $_dispatcher event -idle !scale
     120            }
     121        } else {
     122            foreach key [array names _xml2data $index-*] {
     123                set dobj $_xml2data($key)
     124
     125                # search for and remove all references to this data object
     126                for {set n 0} {$n < [llength $_dataslots]} {incr n} {
     127                    set slot [lindex $_dataslots $n]
     128                    set pos [lsearch -exact $slot $dobj]
     129                    if {$pos >= 0} {
     130                        set slot [lreplace $slot $pos $pos]
     131                        set _dataslots [lreplace $_dataslots $n $n $slot]
     132                        $_dispatcher event -idle !scale
     133                    }
     134                }
     135
     136                # destroy the object and forget it
    108137                itcl::delete object $dobj
    109             }
    110             set _dataslots [lreplace $_dataslots $index $index ""]
     138                unset _xml2data($key)
     139            }
    111140        }
    112141    } else {
     
    119148        }
    120149        set _dataslots ""
     150        catch {unset _xml2data}
    121151    }
    122152}
     
    139169
    140170# ----------------------------------------------------------------------
    141 # USAGE: plot add ?<index> <settings> <index> <settings> ...?
     171# USAGE: plot add ?<simnum> <settings> <simnum> <settings> ...?
    142172# USAGE: plot clear
    143173#
     
    145175# command clears the current viewer.  Data is still stored in the
    146176# widget, but the results are not shown on screen.  The "plot add"
    147 # command adds the data at the specified <index> to the plot.  If
     177# command adds the data at the specified <simnum> to the plot.  Each
     178# <simnum> is the simulation number, like "#1", "#2", "#3", etc.  If
    148179# the optional <settings> are specified, then they are applied
    149180# to the plot; otherwise, default settings are used.
     
    158189                    continue
    159190                }
     191
     192                set index [_cleanIndex $index]
    160193                set reset "-color autoreset"
    161194                set slot [lindex $_dataslots $index]
     
    263296                    set mode "contour"
    264297                    if {![info exists _mode2widget($mode)]} {
     298                        global env
    265299                        if { [$dataobj isunirect2d] } {
    266300                            if { [$dataobj hints type] == "contour" } {
     
    271305                                set resultMode "heightmap"
    272306                            }
     307                        } elseif { [info exists env(VTKCONTOUR)] } {
     308                            set resultMode "vtkcontour"
    273309                        } else {
    274310                            set resultMode "vtk"
     
    292328                                set fmt "vtk"
    293329                            }
    294                             "opendx" - "dx" - "points-on-mesh" {
     330                            "points-on-mesh" {
     331                                set mesh [$dataobj mesh]
     332                                set fmt [expr {("" != $mesh) ? "vtk" : "nanovis"}]
     333                                set extents [$dataobj extents]
     334                                if { $extents > 1 } {
     335                                    set fmt "flowvis"
     336                                }
     337                            }
     338                            "opendx" - "dx" {
    295339                                set fmt "nanovis"
    296340                                set extents [$dataobj extents]
     
    464508# ----------------------------------------------------------------------
    465509itcl::body Rappture::ResultViewer::_xml2data {xmlobj path} {
     510    if {[info exists _xml2data($xmlobj-$path)]} {
     511        return $_xml2data($xmlobj-$path)
     512    }
     513
    466514    set type [$xmlobj element -as type $path]
    467515    switch -- $type {
    468516        curve {
    469             return [Rappture::Curve ::#auto $xmlobj $path]
     517            set dobj [Rappture::Curve ::#auto $xmlobj $path]
    470518        }
    471519        datatable {
    472             return [Rappture::DataTable ::#auto $xmlobj $path]
     520            set dobj [Rappture::DataTable ::#auto $xmlobj $path]
    473521        }
    474522        histogram {
    475             return [Rappture::Histogram ::#auto $xmlobj $path]
     523            set dobj [Rappture::Histogram ::#auto $xmlobj $path]
    476524        }
    477525        field {
    478             return [Rappture::Field ::#auto $xmlobj $path]
     526            set dobj [Rappture::Field ::#auto $xmlobj $path]
    479527        }
    480528        mesh {
    481             return [Rappture::Mesh ::#auto $xmlobj $path]
     529            set dobj [Rappture::Mesh ::#auto $xmlobj $path]
    482530        }
    483531        table {
    484             return [Rappture::Table ::#auto $xmlobj $path]
     532            set dobj [Rappture::Table ::#auto $xmlobj $path]
    485533        }
    486534        image {
    487             return [Rappture::Image ::#auto $xmlobj $path]
     535            set dobj [Rappture::Image ::#auto $xmlobj $path]
    488536        }
    489537        sequence {
    490             return [Rappture::Sequence ::#auto $xmlobj $path]
     538            set dobj [Rappture::Sequence ::#auto $xmlobj $path]
    491539        }
    492540        string - log {
    493             return [$xmlobj element -as object $path]
     541            set dobj [$xmlobj element -as object $path]
    494542        }
    495543        structure {
    496             return [$xmlobj element -as object $path]
     544            set dobj [$xmlobj element -as object $path]
    497545        }
    498546        number - integer - boolean - choice {
    499             return [$xmlobj element -as object $path]
     547            set dobj [$xmlobj element -as object $path]
    500548        }
    501549        drawing3d - drawing {
    502             return [Rappture::Drawing ::#auto $xmlobj $path]
     550            set dobj [Rappture::Drawing ::#auto $xmlobj $path]
    503551        }
    504552        time - status {
    505             return ""
    506         }
    507     }
    508     error "don't know how to plot <$type> data path=$path"
     553            set dobj ""
     554        }
     555        default {
     556            error "don't know how to plot <$type> data path=$path"
     557        }
     558    }
     559
     560    # store the mapping xmlobj=>dobj so we can find this result later
     561    if {$dobj ne ""} {
     562        set _xml2data($xmlobj-$path) $dobj
     563    }
     564    return $dobj
     565}
     566
     567# ----------------------------------------------------------------------
     568# USAGE: _cleanIndex <index>
     569#
     570# Used internally to create a data object for the data at the
     571# specified <path> in the <xmlobj>.
     572# ----------------------------------------------------------------------
     573itcl::body Rappture::ResultViewer::_cleanIndex {index} {
     574    if {[regexp {^#([0-9]+)} $index match num]} {
     575        return [expr {$num-1}]  ;# start from 0 instead of 1
     576    } elseif {[string is integer -strict $index]} {
     577        return $index
     578    }
     579    error "bad plot index \"$index\": should be 0,1,2,... or #1,#2,#3,..."
    509580}
    510581
Note: See TracChangeset for help on using the changeset viewer.