Changeset 1400 for trunk


Ignore:
Timestamp:
Apr 15, 2009 6:22:24 PM (15 years ago)
Author:
mmc
Message:

Fixed support ticket #5831, which produced an error message like:

can't set _cntlInfo(...): bad value "1e+18/cm3"

The problem arose when you simulated two values like 1e+18 and 1.0e+18.
The Radiodial understood that these were the same value, but it honored
only one of the string representations and rejected the other when you
tried to adjust the dials. It now keeps all recognized string values,
and maps the string onto the real value when you're manipulating the
control. Also fixed the ResultSet? to avoid creating the Radiodial when
the value is numerically the same even though strings are different.

Location:
trunk/gui/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/radiodial.tcl

    r1395 r1400  
    6868    protected method _navigate {offset}
    6969    protected method _limits {}
     70    protected method _findLabel {str}
    7071    protected method _fixSize {}
    7172    protected method _fixValue {args}
    7273
    7374    private variable _values ""       ;# list of all values on the dial
    74     private variable _val2label       ;# maps value => label
     75    private variable _val2label       ;# maps value => string label(s)
    7576    private variable _current ""      ;# current value (where pointer is)
    7677    private variable _variable ""     ;# variable associated with -variable
     
    128129        set value [llength $_values]
    129130    }
    130     lappend _values $value
    131     set _values [lsort -real $_values]
    132     set _val2label($value) $label
     131
     132    # Add this value if we've never see it before
     133    if {[lsearch -real $_values $value] < 0} {
     134        lappend _values $value
     135        set _values [lsort -real $_values]
     136    }
     137
     138    # Keep all equivalent strings for this value.
     139    # That way, we can later select either "1e18" or "1.0e+18"
     140    lappend _val2label($value) $label
    133141
    134142    if {"" == $_current} {
     
    199207            label {
    200208                set v [lindex $_values $i]
    201                 $op rlist $_val2label($v)
     209                $op rlist [lindex $_val2label($v) 0]
    202210            }
    203211            value {
     
    214222                foreach {min max} [_limits] break
    215223                set frac [expr {double($v-$min)/($max-$min)}]
    216                 $op rlist [list $_val2label($v) $v $frac]
     224                set l [lindex $_val2label($v) 0]
     225                $op rlist [list $l $v $frac]
    217226            }
    218227            default {
     
    234243    } elseif {[llength $args] == 1} {
    235244        set newval [lindex $args 0]
    236         set found 0
    237         foreach v $_values {
    238             if {[string equal $_val2label($v) $newval]} {
    239                 set newval $v
    240                 set found 1
    241                 break
    242             }
    243         }
    244         if {!$found} {
    245             error "bad value \"$newval\": possible matches are \"[join $_values ,]\""
    246         }
     245        _findLabel $newval  ;# make sure this label is recognized
    247246        _setCurrent $newval
    248247
     
    263262# ----------------------------------------------------------------------
    264263itcl::body Rappture::Radiodial::color {value} {
    265     set found 0
    266     foreach v $_values {
    267         if {[string equal $_val2label($v) $value]} {
    268             set value $v
    269             set found 1
    270             break
    271         }
    272     }
    273     if {!$found} {
    274         error "bad value \"$value\": possible matches are \"[join $_values ,]\""
    275     }
     264    _findLabel $value  ;# make sure this label is recognized
    276265
    277266    if {"" != $_spectrum} {
     
    300289        upvar #0 $_variable var
    301290        if {[info exists _val2label($value)]} {
    302             set var $_val2label($value)
     291            set var [lindex $_val2label($value) 0]
    303292        } else {
    304293            set var $value
     
    422411    set vw $itk_option(-valuewidth)
    423412    if {$vw > 0 && "" != $_current} {
    424         set str $_val2label($_current)
     413        set str [lindex $_val2label($_current) 0]
    425414        if {[string length $str] >= $vw} {
    426415            set str "[string range $str 0 [expr {$vw-3}]]..."
     
    436425
    437426        # set up a tooltip so you can mouse over truncated values
    438         Rappture::Tooltip::text $c $_val2label($_current)
     427        Rappture::Tooltip::text $c [lindex $_val2label($_current) 0]
    439428        $c bind $id <Enter> \
    440429            [list ::Rappture::Tooltip::tooltip pending %W +$x0,$y1]
     
    550539
    551540# ----------------------------------------------------------------------
     541# USAGE: _findLabel <string>
     542#
     543# Used internally to search for the given <string> label among the
     544# known values.  Returns an index into the _values list, or throws
     545# an error if the string is not recognized.  Given the null string,
     546# it returns -1, indicating that the value is not in _values, but
     547# it is valid.
     548# ----------------------------------------------------------------------
     549itcl::body Rappture::Radiodial::_findLabel {str} {
     550    if {"" == $str} {
     551        return -1
     552    }
     553    for {set nv 0} {$nv < [llength $_values]} {incr nv} {
     554        set v [lindex $_values $nv]
     555        if {[lsearch -exact $_val2label($v) $str] >= 0} {
     556            return $nv
     557        }
     558    }
     559    error "bad value \"$str\": should be something matching the raw values \"[join $_values ,]\""
     560}
     561
     562# ----------------------------------------------------------------------
    552563# USAGE: _fixSize
    553564#
     
    615626
    616627    set newval $var
    617     set found 0
    618     foreach v $_values {
    619         if {[string equal $_val2label($v) $newval]} {
    620             set newval $v
    621             set found 1
    622             break
    623         }
    624     }
    625     if {!$found && "" != $newval} {
    626         error "bad value \"$newval\": possible matches are \"[join $_values ,]\""
    627     }
     628    set n [_findLabel $newval]
     629    set newval [expr {($n >= 0) ? [lindex $_values $n] : ""}]
    628630    set _current $newval  ;# set current directly, so we don't trigger again
    629631
  • trunk/gui/scripts/resultset.tcl

    r1399 r1400  
    6666    protected method _toggleAll {{column "current"}}
    6767    protected method _getValues {column {which ""}}
    68     protected method _getRawValues {column {which ""}}
    6968    protected method _getTooltip {role column}
    7069    protected method _getParamDesc {which {index "current"}}
     
    283282            continue
    284283        }
    285         if {[$_results column names $vpath] == ""} {
     284
     285        # make sure that these values really are different
     286        set oldval [lindex [Rappture::LibraryObj::value $xmlobj0 $vpath] 0]
     287        set newval [lindex [Rappture::LibraryObj::value $xmlobj $vpath] 0]
     288
     289        if {$oldval != $newval && [$_results column names $vpath] == ""} {
    286290            # no column for this quantity yet
    287291            $_results column insert end -name $vpath -default $oldval
     
    653657
    654658            $dial clear
    655             foreach {label val} [_getRawValues $col all] {
     659            foreach {label val} [_getValues $col all] {
    656660                $dial add $label $val
    657661            }
     
    15251529
    15261530# ----------------------------------------------------------------------
    1527 # USAGE: _getRawValues <column> ?<which>?
    1528 #
    1529 # Called automatically whenever the user hovers a control within
    1530 # this widget.  Returns the tooltip associated with the control.
    1531 # ----------------------------------------------------------------------
    1532 itcl::body Rappture::ResultSet::_getRawValues {col {which ""}} {
    1533     if {$col == "xmlobj"} {
    1534         # load the Simulation # control
    1535         set nruns [$_results size]
    1536         for {set n 0} {$n < $nruns} {incr n} {
    1537             set v "#[expr {$n+1}]"
    1538             set label2val($v) $n
    1539         }
    1540     } else {
    1541         set vlist ""
    1542         foreach rec [$_results get -format [list xmlobj $col]] {
    1543             lappend vlist [lindex $rec 1]
    1544         }
    1545         # Don't have normalized. Sort and create nums
    1546         set n 0
    1547         foreach v [lsort $vlist] {
    1548             incr n
    1549             set label2val($v) $n
    1550         }
    1551     }
    1552     switch -- $which {
    1553         current {
    1554             set curr $_cntlInfo($this-$col-value)
    1555             if {[info exists label2val($curr)]} {
    1556                 return [list $curr $label2val($curr)]
    1557             }
    1558             return ""
    1559         }
    1560         all {
    1561             return [array get label2val]
    1562         }
    1563         default {
    1564             if {[string is integer $which]} {
    1565                 if {$col == "xmlobj"} {
    1566                     set val "#[expr {$which+1}]"
    1567                 } else {
    1568                     set val [lindex [$_results get -format $col $which] 0]
    1569                 }
    1570                 if {[info exists label2val($val)]} {
    1571                     return [list $val $label2val($val)]
    1572                 }
    1573                 return ""
    1574             }
    1575             error "bad option \"$which\": should be all, current, or an integer index"
    1576         }
    1577     }
    1578 }
    1579 
    1580 # ----------------------------------------------------------------------
    15811531# USAGE: _getTooltip <role> <column>
    15821532#
Note: See TracChangeset for help on using the changeset viewer.