Changeset 54


Ignore:
Timestamp:
Sep 9, 2005 9:03:56 AM (16 years ago)
Author:
mmc
Message:
  • Fixed Rappture ticket #17 (logscale plotting problem). The XYResult widget now excludes 0 values and treats all values as absolute when computing automatic scales.
  • Fixed the molecule viewer to avoid extra rendering, to put up a busy cursor when rendering, and to remove an annoying enlargement the first time you click on the molecule to rotate it.
Location:
trunk/gui/scripts
Files:
3 edited

Legend:

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

    r25 r54  
    108108
    109109# ----------------------------------------------------------------------
    110 # USAGE: limits x|y
     110# USAGE: limits x|xlog|y|ylog
    111111#
    112112# Returns the {min max} limits for the specified axis.
     
    116116    set max ""
    117117    switch -- $which {
    118         x { set pos 0 }
    119         y - v { set pos 1 }
     118        x { set pos 0; set log 0 }
     119        xlog { set pos 0; set log 1 }
     120        y - v { set pos 1; set log 0 }
     121        ylog - vlog { set pos 1; set log 1 }
    120122        default {
    121             error "bad option \"$which\": should be x or y"
    122         }
    123     }
     123            error "bad option \"$which\": should be x, xlog, y, ylog, v, vlog"
     124        }
     125    }
     126
     127    blt::vector create tmp zero
    124128    foreach comp [array names _comp2xy] {
    125129        set vname [lindex $_comp2xy($comp) $pos]
    126130        $vname variable vec
     131
     132        if {$log} {
     133            # on a log scale, use abs value and ignore 0's
     134            $vname dup tmp
     135            $vname dup zero
     136            zero expr {tmp == 0}            ;# find the 0's
     137            tmp expr {abs(tmp)}             ;# get the abs value
     138            tmp expr {tmp + zero*max(tmp)}  ;# replace 0's with abs max
     139            set vmin [blt::vector expr min(tmp)]
     140            set vmax [blt::vector expr max(tmp)]
     141        } else {
     142            set vmin $vec(min)
     143            set vmax $vec(max)
     144        }
     145
    127146        if {"" == $min} {
    128             set min $vec(min)
    129         } elseif {$vec(min) < $min} {
    130             set min $vec(min)
     147            set min $vmin
     148        } elseif {$vmin < $min} {
     149            set min $vmin
    131150        }
    132151        if {"" == $max} {
    133             set max $vec(max)
    134         } elseif {$vec(max) > $max} {
    135             set max $vec(max)
    136         }
    137     }
     152            set max $vmax
     153        } elseif {$vmax > $max} {
     154            set max $vmax
     155        }
     156    }
     157    blt::vector destroy tmp zero
     158
    138159    return [list $min $max]
    139160}
  • trunk/gui/scripts/moleculeViewer.tcl

    r52 r54  
    6363
    6464    protected method _clear {}
    65     protected method _render {}
     65    protected method _redraw {}
    6666    protected method _zoom {option}
    6767    protected method _move {option x y}
    6868    protected method _3dView {theta phi}
    6969    protected method _color2rgb {color}
     70
     71    private variable _dispatcher "" ;# dispatcher for !events
    7072
    7173    private variable _tool ""    ;# tool containing this viewer
     
    8587itcl::body Rappture::MoleculeViewer::constructor {tool args} {
    8688    set _tool $tool
     89
     90    Rappture::dispatcher _dispatcher
     91    $_dispatcher register !redraw
     92    $_dispatcher dispatch $this !redraw "[itcl::code $this _redraw]; list"
     93    $_dispatcher register !render
     94    $_dispatcher dispatch $this !render "$this-renWin Render; list"
     95    $_dispatcher register !fixsize
     96    $_dispatcher dispatch $this !fixsize \
     97        "[itcl::code $this emblems fixPosition]; list"
    8798
    8899    itk_option add hull.width hull.height
     
    179190    pack $itk_component(area) -expand yes -fill both
    180191    bind $itk_component(area) <Configure> \
    181         [itcl::code $this emblems fixPosition]
     192        [list $_dispatcher event -idle !fixsize]
    182193
    183194    itk_component add renderer {
     
    205216# ----------------------------------------------------------------------
    206217itcl::body Rappture::MoleculeViewer::destructor {} {
    207     after cancel [itcl::code $this _render]
    208 
    209218    rename $this-renWin ""
    210219    rename $this-ren ""
     
    233242
    234243    $this-ren ResetCamera
    235     $this-renWin Render
    236 }
    237 
    238 # ----------------------------------------------------------------------
    239 # USAGE: _render
     244    $_dispatcher event -now !render
     245}
     246
     247# ----------------------------------------------------------------------
     248# USAGE: _redraw
    240249#
    241250# Used internally to rebuild the scene whenever options within this
    242251# widget change.  Destroys all actors and rebuilds them from scratch.
    243252# ----------------------------------------------------------------------
    244 itcl::body Rappture::MoleculeViewer::_render {} {
     253itcl::body Rappture::MoleculeViewer::_redraw {} {
     254    blt::busy hold $itk_component(hull); update
     255
    245256    _clear
    246257
     
    307318            emblems on
    308319        }
    309         after cancel [list catch [itcl::code $this _zoom reset]]
    310         after 200 [list catch [itcl::code $this _zoom reset]]
     320        _zoom reset
    311321    }
    312322    $this-ren ResetCamera
    313     $this-renWin Render
     323    $_dispatcher event -idle !render
     324
     325    blt::busy release $itk_component(hull)
    314326}
    315327
     
    326338        in {
    327339            [$this-ren GetActiveCamera] Zoom 1.25
    328             emblems fixPosition
    329             $this-renWin Render
    330340        }
    331341        out {
    332342            [$this-ren GetActiveCamera] Zoom 0.8
    333             emblems fixPosition
    334             $this-renWin Render
    335343        }
    336344        reset {
    337             [$this-ren GetActiveCamera] SetViewAngle 30
    338345            $this-ren ResetCamera
    339             [$this-ren GetActiveCamera] Zoom 1.25
    340346            _3dView 45 45
    341             $this-renWin Render
    342 
    343             after cancel [list catch [itcl::code $this emblems fixPosition]]
    344             after 2000 [list catch [itcl::code $this emblems fixPosition]]
    345         }
    346     }
     347        }
     348    }
     349    $_dispatcher event -later !fixsize
     350    $_dispatcher event -idle !render
    347351}
    348352
     
    370374                set w [winfo width $itk_component(renderer)]
    371375                set h [winfo height $itk_component(renderer)]
     376                if {$w <= 0 || $h <= 0} {
     377                    return
     378                }
    372379                set dx [expr {double($x-$_click(x))/$w}]
    373380                set dy [expr {double($y-$_click(y))/$h}]
     
    383390                _3dView $theta $phi
    384391                emblems fixPosition
    385                 $this-renWin Render
     392                $_dispatcher event -idle !render
    386393
    387394                set _click(x) $x
     
    488495        }
    489496    }
    490     $this-renWin Render
     497    $_dispatcher event -idle !render
    491498}
    492499
     
    510517itcl::configbody Rappture::MoleculeViewer::backdrop {
    511518    eval $this-ren SetBackground [_color2rgb $itk_option(-backdrop)]
    512     $this-renWin Render
     519    $_dispatcher event -idle !render
    513520}
    514521
     
    531538        }
    532539    }
    533     after idle [itcl::code $this _render]
    534 }
     540    $_dispatcher event -idle !redraw
     541}
  • trunk/gui/scripts/xyresult.tcl

    r52 r54  
    6868    private variable _elem2curve   ;# maps graph element => curve
    6969    private variable _xmin ""      ;# autoscale min for x-axis
     70    private variable _xlogmin ""   ;# autoscale min for x-axis (log scale)
    7071    private variable _xmax ""      ;# autoscale max for x-axis
     72    private variable _xlogmax ""   ;# autoscale max for x-axis (log scale)
    7173    private variable _vmin ""      ;# autoscale min for y-axis
     74    private variable _vlogmin ""   ;# autoscale min for y-axis (log scale)
    7275    private variable _vmax ""      ;# autoscale max for y-axis
     76    private variable _vlogmax ""   ;# autoscale max for y-axis (log scale)
    7377    private variable _hilite       ;# info from last _hilite operation
    7478    private variable _axis         ;# info for axis being edited
     
    334338itcl::body Rappture::XyResult::scale {args} {
    335339    set _xmin ""
     340    set _xlogmin ""
    336341    set _xmax ""
     342    set _xlogmax ""
    337343    set _vmin ""
     344    set _vlogmin ""
    338345    set _vmax ""
     346    set _vlogmax ""
    339347    foreach obj $args {
    340         foreach axis {x v} {
     348        foreach axis {x xlog v vlog} {
    341349            foreach {min max} [$obj limits $axis] break
    342350            if {"" != $min && "" != $max} {
     
    526534    #
    527535    if {$_xmin != $_xmax} {
    528         $g axis configure x -min $_xmin -max $_xmax
    529     } else {
    530         $g axis configure x -min "" -max ""
    531     }
    532 
    533     if {"" != $_vmin && "" != $_vmax} {
    534         set min $_vmin
    535         set max $_vmax
    536         set log [$g axis cget y -logscale]
     536        set log [$g axis cget x -logscale]
    537537        if {$log} {
     538            set min $_xlogmin
     539            set max $_xlogmax
    538540            if {$min == $max} {
    539541                set min [expr {0.9*$min}]
    540542                set max [expr {1.1*$max}]
    541543            }
    542             set min [expr {pow(10.0,floor(log10($min)))}]
    543             set max [expr {pow(10.0,ceil(log10($max)))}]
     544            set v [expr {floor(log10($min))}]
     545            if {$v > 0} {
     546                set min [expr {pow(10.0,$v)}]
     547            }
     548            set v [expr {floor(log10($max))}]
     549            if {$v > 0} {
     550                set max [expr {pow(10.0,$v)}]
     551            }
    544552        } else {
     553            set min $_xmin
     554            set max $_xmax
     555            if {$min > 0} {
     556                set min [expr {0.95*$min}]
     557            } else {
     558                set min [expr {1.05*$min}]
     559            }
     560            if {$max > 0} {
     561                set max [expr {1.05*$max}]
     562            } else {
     563                set max [expr {0.95*$max}]
     564            }
     565        }
     566        if {$min != $max} {
     567            $g axis configure x -min $min -max $max
     568        } else {
     569            $g axis configure x -min "" -max ""
     570        }
     571    } else {
     572        $g axis configure x -min "" -max ""
     573    }
     574
     575    if {"" != $_vmin && "" != $_vmax} {
     576        set log [$g axis cget y -logscale]
     577        if {$log} {
     578            set min $_vlogmin
     579            set max $_vlogmax
     580            if {$min == $max} {
     581                set min [expr {0.9*$min}]
     582                set max [expr {1.1*$max}]
     583            }
     584            set v [expr {floor(log10($min))}]
     585            if {$v > 0} {
     586                set min [expr {pow(10.0,$v)}]
     587            }
     588            set v [expr {floor(log10($max))}]
     589            if {$v > 0} {
     590                set max [expr {pow(10.0,$v)}]
     591            }
     592        } else {
     593            set min $_vmin
     594            set max $_vmax
    545595            if {$min > 0} {
    546596                set min [expr {0.95*$min}]
Note: See TracChangeset for help on using the changeset viewer.