Changeset 1562


Ignore:
Timestamp:
Sep 14, 2009 2:14:22 PM (15 years ago)
Author:
gah
Message:

Added cartoon image, changed molecule representation controls, added print options, relabel duplicate xy elements

Location:
trunk/gui/scripts
Files:
2 added
3 edited

Legend:

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

    r1550 r1562  
    4747    private variable _xmarkers "";# list of {x,label,options} triplets.
    4848    private variable _ymarkers "";# list of {y,label,options} triplets.
    49 
    5049    private common _counter 0    ;# counter for unique vector names
    5150}
     
    239238            set _hints(tooltip) $_hints(label)
    240239        }
    241     }
    242 
     240        set _hints(xmlobj) $_xmlobj
     241    }
    243242    if {$keyword != ""} {
    244243        if {[info exists _hints($keyword)]} {
  • trunk/gui/scripts/molvisviewer.tcl

    r1556 r1562  
    5555    private method DoResize {}
    5656    private method EventuallyResize { w h }
    57     private method GetPngImage { widget width height }
     57    private method GetImage { widget }
    5858    private method ReceiveImage { size cacheid frame rock }
    5959    private method WaitIcon { option widget }
     
    8181    public method isconnected {}
    8282    public method labels {option {model "all"}}
    83     public method cartoon {option {model "all"}}
    8483    public method cartoontrace {option {model "all"}}
    8584    public method opacity {option {models "all"} }
     
    9089    public method representation {option {model "all"} }
    9190    public method rock {option}
     91    private method DownloadPopup { popup command }
     92    private method EnableDownload { popup what }
     93
    9294    private variable _icon 0
    9395
     
    200202        $this-spherescale 0.25
    201203        $this-stickradius 0.14
    202         $this-cartoon   no
    203204        $this-cartoontrace no
    204205        $this-model     ballnstick
     
    402403    $inner configure -borderwidth 4
    403404
    404     label $inner.drawinglabel -text "Molecule Reprsentation" \
     405    label $inner.drawinglabel -text "Molecule Representation" \
    405406        -font "Arial 9 bold"
    406407
     
    430431    radiobutton $inner.lines -text "lines" \
    431432        -command [itcl::code $this representation lines all] \
    432         -variable Rappture::MolvisViewer::_settings($this-model) \
     433        -variable [itcl::scope _settings($this-model)] \
    433434        -value lines -font "Arial 9" -pady 0
    434435    Rappture::Tooltip::for $inner.lines \
    435436        "Display bonds as lines. Do not display atoms."
     437
     438    radiobutton $inner.cartoon -text "cartoon" \
     439        -command [itcl::code $this representation cartoon all] \
     440        -variable [itcl::scope _settings($this-model)] \
     441        -value cartoon -font "Arial 9" -pady 0
     442    Rappture::Tooltip::for $inner.cartoon \
     443        "Display cartoon representation of bonds (sticks)."
    436444
    437445    scale $inner.spherescale -width 10 -font "Arial 9 bold" \
     
    474482        "Toggle between orthoscopic/perspective projection modes."
    475483
    476     checkbutton $inner.cartoon -text "Cartoon" \
    477         -command [itcl::code $this cartoon update] \
    478         -variable [itcl::scope _settings($this-cartoon)] \
    479         -font "Arial 9 bold"
    480     Rappture::Tooltip::for $inner.cartoon \
    481         "Set cartoon representation of bonds (sticks)."
    482 
    483484    checkbutton $inner.cartoontrace -text "Cartoon Trace" \
    484485        -command [itcl::code $this cartoontrace update] \
     
    491492    blt::table $inner \
    492493        0,0 $inner.drawinglabel -anchor w -columnspan 4 \
    493         1,1 $inner.pict -anchor w -rowspan 4 \
     494        1,1 $inner.pict -anchor w -rowspan 5 \
    494495        1,2 $inner.bstick -anchor w -columnspan 2 \
    495496        2,2 $inner.spheres -anchor w -columnspan 2 \
    496497        3,2 $inner.sticks -anchor w -columnspan 2 \
    497498        4,2 $inner.lines -anchor w -columnspan 2 \
    498         5,0 $inner.labels -anchor w -columnspan 4 -pady {6 0} \
    499         6,0 $inner.rock -anchor w -columnspan 4 -pady {6 0} \
    500         7,0 $inner.ortho -anchor w -columnspan 4 -pady {6 0} \
    501         8,1 $inner.spherescale -fill x -columnspan 4 -pady {6 0} \
    502         10,1 $inner.stickradius -fill x -columnspan 4 -pady {6 0} \
    503         12,0 $inner.cartoon -anchor w -columnspan 4 -pady {6 0} \
    504         13,0 $inner.cartoontrace -anchor w -columnspan 4 -pady {6 0} \
     499        5,2 $inner.cartoon -anchor w -columnspan 2 \
     500        6,0 $inner.labels -anchor w -columnspan 4 -pady {1 0} \
     501        7,0 $inner.rock -anchor w -columnspan 4 -pady {1 0} \
     502        8,0 $inner.ortho -anchor w -columnspan 4 -pady {1 0} \
     503        9,0 $inner.cartoontrace -anchor w -columnspan 4 -pady {1 0} \
     504        10,1 $inner.spherescale -fill x -columnspan 4 -pady {1 0} \
     505        11,1 $inner.stickradius -fill x -columnspan 4 -pady {1 0} \
    505506
    506507    blt::table configure $inner c0 -resize expand -width 2
     
    508509    blt::table configure $inner c3 -resize expand
    509510    blt::table configure $inner r* -resize none
    510     blt::table configure $inner r14 -resize expand
     511    blt::table configure $inner r13 -resize expand
    511512}
    512513
     
    537538        controls {
    538539            set popup .molvisviewerdownload
    539             if {![winfo exists .molvisviewerdownload]} {
    540                 # if we haven't created the popup yet, do it now
    541                 Rappture::Balloon $popup \
    542                     -title "[Rappture::filexfer::label downloadWord] as..."
    543                 set inner [$popup component inner]
    544                 label $inner.summary -text "" -anchor w
    545                 pack $inner.summary -side top
    546                 set img $_image(plot)
    547                 set res "[image width $img]x[image height $img]"
    548                 radiobutton $inner.draft -text "Image (draft $res)" \
    549                     -variable Rappture::MolvisViewer::_downloadPopup(format) \
    550                     -value draft
    551                 pack $inner.draft -anchor w
    552 
    553                 set res "1200x1200"
    554                 radiobutton $inner.medium -text "Image (standard $res)" \
    555                     -variable Rappture::MolvisViewer::_downloadPopup(format) \
    556                     -value $res
    557                 pack $inner.medium -anchor w
    558 
    559                 set res "2400x2400"
    560                 radiobutton $inner.high -text "Image (high quality $res)" \
    561                     -variable Rappture::MolvisViewer::_downloadPopup(format) \
    562                     -value $res
    563                 pack $inner.high -anchor w
    564 
    565                 radiobutton $inner.pdb -text "PDB File" \
    566                     -variable Rappture::MolvisViewer::_downloadPopup(format) \
    567                     -value pdb
    568                 pack $inner.pdb -anchor w
    569                 button $inner.go -text [Rappture::filexfer::label download] \
    570                     -command [lindex $args 0]
    571                 pack $inner.go -pady 4
     540            if { ![winfo exists .molvisviewerdownload] } {
     541                set inner [DownloadPopup $popup [lindex $args 0]]
    572542            } else {
    573543                set inner [$popup component inner]
    574544            }
     545            set _downloadPopup(image_controls) $inner.image_frame
    575546            set num [llength [get]]
    576547            set num [expr {($num == 1) ? "1 result" : "$num results"}]
     
    587558            }
    588559            switch -- $_downloadPopup(format) {
    589                 draft {
    590                     # Get the image data (as base64) and decode it back to
    591                     # binary.  This is better than writing to temporary
    592                     # files.  When we switch to the BLT picture image it
    593                     # won't be necessary to decode the image data.
    594                     set bytes [$_image(plot) data -format "jpeg -quality 100"]
    595                     set bytes [Rappture::encoding::decode -as b64 $bytes]
    596                     return [list .jpg $bytes]
     560                "image" {
     561                    return [$this GetImage [lindex $args 0]]
    597562                }
    598                 "2400x2400" {
    599                     return [$this GetPngImage [lindex $args 0] 2400 2400]
    600                 }
    601                 "1200x1200" {
    602                     return [$this GetPngImage [lindex $args 0] 1200 1200]
    603                 }
    604                 pdb {
     563                "pdb" {
    605564                    return [list .pdb $_pdbdata]
    606565                }
     
    900859    labels update
    901860    opacity update
    902     cartoon update
    903861    cartoontrace update
    904862
     
    15361494}
    15371495           
    1538 itcl::body Rappture::MolvisViewer::GetPngImage  { widget width height } {
     1496itcl::body Rappture::MolvisViewer::GetImage { widget } {
    15391497    set token "print[incr _nextToken]"
    15401498    set var ::Rappture::MolvisViewer::_hardcopy($this-$token)
    15411499    set $var ""
    15421500
     1501    set controls $_downloadPopup(image_controls)
     1502    set combo $controls.size_combo
     1503    set size [$combo translate [$combo value]]
     1504    switch -- $size {
     1505        "standard" {
     1506            set width 1200
     1507            set height 1200
     1508        }
     1509        "highquality" {
     1510            set width 2400
     1511            set height 2400
     1512        }
     1513        "draft" {
     1514            set width 400
     1515            set height 400
     1516        }
     1517        default {
     1518            error "unknown image size [$inner.image_size_combo value]"
     1519        }
     1520    }
    15431521    # Setup an automatic timeout procedure.
    15441522    $_dispatcher dispatch $this !pngtimeout "set $var {} ; list"
    1545 
     1523   
    15461524    set popup .molvisviewerprint
    15471525    if { ![winfo exists $popup] } {
     
    15641542        set inner [$popup component inner]
    15651543    }
    1566 
     1544    set combo $controls.bgcolor_combo
     1545    set bgcolor [$combo translate [$combo value]]
     1546   
    15671547    $_dispatcher event -after 60000 !pngtimeout
    15681548    WaitIcon start $inner.icon
    15691549    grab set -local $inner
    15701550    focus $inner.cancel
    1571 
    1572     SendCmd "print $token $width $height"
     1551   
     1552    SendCmd "print $token $width $height $bgcolor"
    15731553
    15741554    $popup activate $widget below
     
    15871567
    15881568    if { $_hardcopy($this-$token) != "" } {
    1589         return [list .png $_hardcopy($this-$token)]
     1569        set combo $controls.type_combo
     1570        set type [$combo translate [$combo value]]
     1571        switch -- $type {
     1572            "jpg" {
     1573                set img [image create photo -data $_hardcopy($this-$token)]
     1574                set bytes [$img data -format "jpeg -quality 100"]
     1575                set bytes [Rappture::encoding::decode -as b64 $bytes]
     1576                return [list .jpg $bytes]
     1577            }
     1578            "gif" {
     1579                set img [image create photo -data $_hardcopy($this-$token)]
     1580                set bytes [$img data -format "gif"]
     1581                set bytes [Rappture::encoding::decode -as b64 $bytes]
     1582                return [list .gif $bytes]
     1583            }
     1584            "png" {
     1585                return [list .png $_hardcopy($this-$token)]
     1586            }
     1587        }
    15901588    }
    15911589    return ""
     
    17291727
    17301728# ----------------------------------------------------------------------
    1731 # USAGE: cartoon on|off|toggle
    1732 # USAGE: cartoon update
    1733 #
    1734 # Used internally to turn labels associated with atoms on/off, and to
    1735 # update the positions of the labels so they sit on top of each atom.
    1736 # ----------------------------------------------------------------------
    1737 itcl::body Rappture::MolvisViewer::cartoon {option {models "all"}} {
    1738     set cartoon $_settings($this-cartoon)
    1739     if { $option == "update" } {
    1740         set cartoon $_settings($this-cartoon)
    1741     } elseif { [string is boolean $option] } {
    1742         set cartoon $option
    1743     } else {
    1744         error "bad option \"$option\""
    1745     }
    1746     set _settings($this-cartoon) $cartoon
    1747     if { $models == "all" } {
    1748         set models [array names _mlist]
    1749     }
    1750     SendCmd "cartoon -model all off"
    1751     if { $cartoon } {
    1752         foreach model $models {
    1753             if { [info exists _active($model)] } {
    1754                 SendCmd "cartoon -model $model $cartoon"
    1755             }
    1756         }
    1757     }
    1758 }
    1759 
    1760 # ----------------------------------------------------------------------
    17611729# USAGE: cartoontrace on|off|toggle
    17621730# USAGE: cartoontrace update
     
    17871755    }
    17881756}
     1757
     1758itcl::body Rappture::MolvisViewer::DownloadPopup { popup command } {
     1759    Rappture::Balloon $popup \
     1760        -title "[Rappture::filexfer::label downloadWord] as..."
     1761    set inner [$popup component inner]
     1762    label $inner.summary -text "" -anchor w -font "Arial 11 bold"
     1763    radiobutton $inner.pdb_button -text "PDB File" \
     1764        -variable [itcl::scope _downloadPopup(format)] \
     1765        -command [itcl::code $this EnableDownload $popup pdb] \
     1766        -font "Arial 10 " \
     1767        -value pdb 
     1768    radiobutton $inner.image_button -text "Image File" \
     1769        -variable [itcl::scope _downloadPopup(format)] \
     1770        -command [itcl::code $this EnableDownload $popup image] \
     1771        -font "Arial 10 " \
     1772        -value image
     1773
     1774    set controls [frame $inner.image_frame -bd 2 -relief groove]
     1775    label $controls.size_label -text "Size:" \
     1776        -font "Arial 9"
     1777    set img $_image(plot)
     1778    set res "[image width $img]x[image height $img]"
     1779    Rappture::Combobox $controls.size_combo -width 20 -editable no
     1780    $controls.size_combo choices insert end \
     1781        "draft"  "Draft (400x400)"         \
     1782        "standard"  "Standard (1200x1200)"          \
     1783        "highquality"  "High Quality (2400x2400)"
     1784
     1785    label $controls.bgcolor_label -text "Background:" \
     1786        -font "Arial 9"
     1787    Rappture::Combobox $controls.bgcolor_combo -width 20 -editable no
     1788    $controls.bgcolor_combo choices insert end \
     1789        "black"  "Black" \
     1790        "white"  "White"         
     1791
     1792    label $controls.type_label -text "Type:" \
     1793        -font "Arial 9"
     1794    Rappture::Combobox $controls.type_combo -width 20 -editable no
     1795    $controls.type_combo choices insert end \
     1796        "jpg"  "JPEG Joint Photographic Experts Group Format (*.jpg)" \
     1797        "png"  "PNG Portable Network Graphics Format (*.png)"         
     1798
     1799    button $inner.go -text [Rappture::filexfer::label download] \
     1800        -command $command
     1801
     1802    blt::table $controls \
     1803        1,0 $controls.size_label -anchor e \
     1804        1,1 $controls.size_combo -anchor w \
     1805        2,0 $controls.bgcolor_label -anchor e \
     1806        2,1 $controls.bgcolor_combo -anchor w \
     1807        3,0 $controls.type_label -anchor e \
     1808        3,1 $controls.type_combo -anchor w
     1809    blt::table configure $controls r0 -height 16
     1810    blt::table configure $controls -padx 4 -pady {0 6}
     1811    blt::table $inner \
     1812        0,0 $inner.summary -cspan 2 \
     1813        1,0 $inner.pdb_button -cspan 2 -anchor w \
     1814        2,0 $inner.image_button -cspan 2 -rspan 2 -anchor nw \
     1815        3,1 $controls \
     1816        6,0 $inner.go -cspan 2 -pady 5
     1817    blt::table configure $inner c0 -width 11
     1818    blt::table configure $inner r2 -height 11
     1819    #blt::table configure $inner c1 -width 8
     1820    raise $inner.image_button
     1821    $inner.pdb_button invoke
     1822    $controls.bgcolor_combo value "Black"
     1823    $controls.size_combo value "Draft (400x400)"
     1824    $controls.type_combo value  "PNG Portable Network Graphics Format (*.png)"
     1825    return $inner
     1826}
     1827
     1828itcl::body Rappture::MolvisViewer::EnableDownload { popup what } {
     1829    set inner [$popup component inner]
     1830    switch -- $what {
     1831        "pdb" {
     1832            foreach w [winfo children $inner.image_frame] {
     1833                $w configure -state disabled
     1834            }
     1835        }
     1836        "image" {
     1837            foreach w [winfo children $inner.image_frame] {
     1838                $w configure -state normal
     1839            }
     1840        }
     1841        default {
     1842            error "unknown type of download"
     1843        }
     1844    }
     1845}
  • trunk/gui/scripts/xyresult.tcl

    r1527 r1562  
    9191    protected method _hilite {state x y}
    9292    protected method _axis {option args}
    93     protected method _getAxes {xydata}
     93    protected method _getAxes {curve}
    9494    protected method _getLineMarkerOptions { style }
    9595    protected method _getTextMarkerOptions { style }
     
    435435
    436436    catch {unset _limits}
    437     foreach xydata $args {
     437    foreach curve $args {
    438438        # find the axes for this curve (e.g., {x y2})
    439         foreach {map(x) map(y)} [_getAxes $xydata] break
     439        foreach {map(x) map(y)} [_getAxes $curve] break
    440440
    441441        foreach axis {x y} {
     
    444444                # store results -- ex: _limits(x2log-min)
    445445                set id $map($axis)$type
    446                 foreach {min max} [$xydata limits $axis$type] break
     446                foreach {min max} [$curve limits $axis$type] break
    447447                if {"" != $min && "" != $max} {
    448448                    if {![info exists _limits($id-min)]} {
     
    460460            }
    461461
    462             if {[$xydata hints ${axis}scale] == "log"} {
     462            if {[$curve hints ${axis}scale] == "log"} {
    463463                _axis scale $map($axis) log
    464464            }
     
    633633    set anum(x) 0
    634634    set anum(y) 0
    635     foreach xydata [get] {
     635    foreach curve [get] {
    636636        foreach ax {x y} {
    637             set label [$xydata hints ${ax}label]
     637            set label [$curve hints ${ax}label]
    638638            if {"" != $label} {
    639639                if {![info exists _label2axis($ax-$label)]} {
     
    651651
    652652                    # if this axis has a description, add it as a tooltip
    653                     set desc [string trim [$xydata hints ${ax}desc]]
     653                    set desc [string trim [$curve hints ${ax}desc]]
    654654                    Rappture::Tooltip::text $g-$axis $desc
    655655                }
     
    698698    #
    699699    set count 0
    700     foreach xydata $_clist {
    701         set label [$xydata hints label]
    702         foreach {mapx mapy} [_getAxes $xydata] break
    703 
    704         foreach comp [$xydata components] {
    705             set xv [$xydata mesh $comp]
    706             set yv [$xydata values $comp]
    707 
    708             if {[info exists _curve2color($xydata)]} {
    709                 set color $_curve2color($xydata)
     700    foreach curve $_clist {
     701        set label [$curve hints label]
     702        foreach {mapx mapy} [_getAxes $curve] break
     703
     704        foreach comp [$curve components] {
     705            set xv [$curve mesh $comp]
     706            set yv [$curve values $comp]
     707
     708            if {[info exists _curve2color($curve)]} {
     709                set color $_curve2color($curve)
    710710            } else {
    711                 set color [$xydata hints color]
     711                set color [$curve hints color]
    712712                if {"" == $color} {
    713713                    set color black
     
    715715            }
    716716
    717             if {[info exists _curve2width($xydata)]} {
    718                 set lwidth $_curve2width($xydata)
     717            if {[info exists _curve2width($curve)]} {
     718                set lwidth $_curve2width($curve)
    719719            } else {
    720720                set lwidth 2
    721721            }
    722722
    723             if {[info exists _curve2dashes($xydata)]} {
    724                 set dashes $_curve2dashes($xydata)
     723            if {[info exists _curve2dashes($curve)]} {
     724                set dashes $_curve2dashes($curve)
    725725            } else {
    726726                set dashes ""
     
    736736
    737737            set elem "elem[incr count]"
    738             set _elem2curve($elem) $xydata
    739 
     738            set _elem2curve($elem) $curve
     739            lappend label2elem($label) $elem
    740740            $g element create $elem -x $xv -y $yv \
    741                 -symbol $sym -pixels $pixels -linewidth $lwidth -label $label \
     741                -symbol $sym -pixels $pixels -linewidth $lwidth \
     742                -label $label \
    742743                -color $color -dashes $dashes \
    743744                -mapx $mapx -mapy $mapy
     
    745746    }
    746747
    747     foreach xydata $_clist {
     748    # Fix duplicate labels by appending the simulation number
     749    foreach label [array names label2elem] {
     750        if { [llength $label2elem($label)] == 1 } {
     751            continue
     752        }
     753        foreach elem $label2elem($label) {
     754            set curve $_elem2curve($elem)
     755            scan [$curve hints xmlobj] "::libraryObj%d" suffix
     756            incr suffix
     757            set elabel [format "%s \#%d" $label $suffix]
     758            $g element configure $elem -label $elabel
     759        }
     760    }   
     761
     762    foreach curve $_clist {
    748763        set xmin -Inf
    749764        set ymin -Inf
     
    753768        # Create text/line markers for each *axis.marker specified.
    754769        #
    755         foreach m [$xydata xmarkers] {
     770        foreach m [$curve xmarkers] {
    756771            foreach {at label style} $m break
    757772            set id [$g marker create line -coords [list $at $ymin $at $ymax]]
     
    773788            }
    774789        }
    775         foreach m [$xydata ymarkers] {
     790        foreach m [$curve ymarkers] {
    776791            foreach {at label style} $m break
    777792            set id [$g marker create line -coords [list $xmin $at $xmax $at]]
     
    15211536# x-axis name (x, x2, x3, etc.), and y is the y-axis name.
    15221537# ----------------------------------------------------------------------
    1523 itcl::body Rappture::XyResult::_getAxes {xydata} {
     1538itcl::body Rappture::XyResult::_getAxes {curve} {
    15241539    # rebuild if needed, so we know about the axes
    15251540    if {[$_dispatcher ispending !rebuild]} {
     
    15291544
    15301545    # what is the x axis?  x? x2? x3? ...
    1531     set xlabel [$xydata hints xlabel]
     1546    set xlabel [$curve hints xlabel]
    15321547    if {[info exists _label2axis(x-$xlabel)]} {
    15331548        set mapx $_label2axis(x-$xlabel)
     
    15371552
    15381553    # what is the y axis?  y? y2? y3? ...
    1539     set ylabel [$xydata hints ylabel]
     1554    set ylabel [$curve hints ylabel]
    15401555    if {[info exists _label2axis(y-$ylabel)]} {
    15411556        set mapy $_label2axis(y-$ylabel)
Note: See TracChangeset for help on using the changeset viewer.