Ignore:
Timestamp:
May 12, 2007, 2:14:49 PM (17 years ago)
Author:
mmc
Message:

Fix for support ticket #1455, "floating-point value too large to represent".
The user was entering a really big value like "1e400" into the doping
area of PN Junction Lab. The GUI would choke and the job would later
fail. Fixed the field editor to test for bad values and honor min/max
limits set on parameters in a device structure.

Fix for support ticket #1465, "bad option "add": should be one of...".
The new molecule viewer requires add/delete operations. This is now
part of the general structure viewer, but the DeviceViewer1D class was
not updated properly. It is now. Fixed the structure demo to copy
the input to the output so we can test for this.

File:
1 edited

Legend:

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

    r464 r729  
    3232    destructor { # defined below }
    3333
     34    public method add {dataobj {settings ""}}
     35    public method get {}
     36    public method delete {args}
     37
    3438    public method controls {option args}
    3539    public method download {option args}
     
    4852
    4953    private variable _owner ""      ;# thing managing this control
     54    private variable _dlist ""      ;# list of dataobj objects
     55    private variable _dobj2raise    ;# maps dataobj => raise flag
    5056    private variable _device ""     ;# XML library with <structure>
    5157    private variable _tab2fields    ;# maps tab name => list of fields
    5258    private variable _field2parm    ;# maps field path => parameter name
    5359    private variable _units ""      ;# units for field being edited
    54     private variable _restrict ""   ;# restriction expr for field being edited
    5560    private variable _marker        ;# marker currently being edited
    5661}
     
    137142    after cancel [list catch [itcl::code $this _fixAxes]]
    138143    after cancel [list catch [itcl::code $this _align]]
     144    after cancel [list catch [itcl::code $this _loadDevice]]
     145}
     146
     147# ----------------------------------------------------------------------
     148# USAGE: add <dataobj> ?<settings>?
     149#
     150# Clients use this to add a data object to the plot.  The optional
     151# <settings> are used to configure the plot.  Allowed settings are
     152# -color, -brightness, -width, -linestyle, and -raise. Only
     153# -brightness and -raise do anything.
     154# ----------------------------------------------------------------------
     155itcl::body Rappture::DeviceViewer1D::add {dataobj {settings ""}} {
     156    array set params {
     157        -color auto
     158        -brightness 0
     159        -width 1
     160        -raise 0
     161        -linestyle solid
     162        -description ""
     163    }
     164    foreach {opt val} $settings {
     165        if {![info exists params($opt)]} {
     166            error "bad settings \"$opt\": should be [join [lsort [array names params]] {, }]"
     167        }
     168        set params($opt) $val
     169    }
     170 
     171    set pos [lsearch -exact $dataobj $_dlist]
     172
     173    if {$pos < 0} {
     174        if {![Rappture::library isvalid $dataobj]} {
     175            error "bad value \"$dataobj\": should be Rappture::library object"
     176        }
     177
     178        lappend _dlist $dataobj
     179        set _dobj2raise($dataobj) $params(-raise)
     180
     181        after cancel [list catch [itcl::code $this _loadDevice]]
     182        after idle [list catch [itcl::code $this _loadDevice]]
     183    }
     184}
     185
     186# ----------------------------------------------------------------------
     187# USAGE: get
     188#
     189# Clients use this to query the list of objects being plotted, in
     190# order from bottom to top of this result.
     191# ----------------------------------------------------------------------
     192itcl::body Rappture::DeviceViewer1D::get {} {
     193    # put the dataobj list in order according to -raise options
     194    set dlist $_dlist
     195    foreach obj $dlist {
     196        if {[info exists _dobj2raise($obj)] && $_dobj2raise($obj)} {
     197            set i [lsearch -exact $dlist $obj]
     198            if {$i >= 0} {
     199                set dlist [lreplace $dlist $i $i]
     200                lappend dlist $obj
     201            }
     202        }
     203    }
     204    return $dlist
     205}
     206
     207# ----------------------------------------------------------------------
     208# USAGE: delete ?<dataobj> <dataobj> ...?
     209#
     210# Clients use this to delete a dataobj from the plot. If no dataobjs
     211# are specified, then all dataobjs are deleted.
     212# ----------------------------------------------------------------------
     213itcl::body Rappture::DeviceViewer1D::delete {args} {
     214    if {[llength $args] == 0} {
     215        set args $_dlist
     216    }
     217
     218    # delete all specified dataobjs
     219    set changed 0
     220    foreach dataobj $args {
     221        set pos [lsearch -exact $_dlist $dataobj]
     222        if {$pos >= 0} {
     223            set _dlist [lreplace $_dlist $pos $pos]
     224            catch {unset _dobj2raise($dataobj)}
     225            set changed 1
     226        }
     227    }
     228
     229    # if anything changed, then rebuild the plot
     230    if {$changed} {
     231        after cancel [list catch [itcl::code $this _loadDevice]]
     232        after idle [list catch [itcl::code $this _loadDevice]]
     233    }
    139234}
    140235
     
    203298# ----------------------------------------------------------------------
    204299itcl::body Rappture::DeviceViewer1D::_loadDevice {} {
     300    set _device [lindex [get] end]
     301
    205302    #
    206303    # Release any info left over from the last device.
     
    418515        }
    419516
    420         if {[info exists hints(restrict)]} {
    421             set _restrict $hints(restrict)
    422         } else {
    423             set _restrict ""
    424         }
    425 
    426517        if {[info exists hints(scale)]
    427518              && [string match log* $hints(scale)]} {
     
    645736                    return 0
    646737                }
    647                 if {"" != $_restrict
    648                       && [catch {Rappture::Units::convert $result \
    649                         -context $_units -to $_units -units off} value] == 0} {
    650 
    651                     set rexpr $_restrict
    652                     regsub -all value $rexpr {$value} rexpr
    653                     if {[catch {expr $rexpr} result] == 0 && !$result} {
    654                         bell
    655                         Rappture::Tooltip::cue $itk_component(geditor) "Should satisfy the condition: $_restrict"
    656                         return 0
    657                     }
    658                 }
     738            }
     739            if {[catch {$_marker(fobj) controls validate $_marker(path) $name} result]} {
     740                bell
     741                Rappture::Tooltip::cue $itk_component(geditor) $result
     742                return 0
    659743            }
    660744            return 1
     
    779863        }
    780864    }
    781     set _device $itk_option(-device)
    782     _loadDevice
    783 }
     865
     866    delete
     867    if {"" != $itk_option(-device)} {
     868        add $itk_option(-device)
     869    }
     870    after cancel [list catch [itcl::code $this _loadDevice]]
     871    after idle [list catch [itcl::code $this _loadDevice]]
     872}
Note: See TracChangeset for help on using the changeset viewer.