Ignore:
Timestamp:
Mar 18, 2009, 2:59:21 PM (16 years ago)
Author:
gah
Message:

preliminary HQ output from molvisviewer; unexpand tabs; all jpeg generation at 100%

File:
1 edited

Legend:

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

    r676 r1342  
    5353    private variable _slabs ""      ;# list of node names for slabs in device
    5454    private variable _z0 ""         ;# list parallel to _slabs with z0
    55                                     ;#   coord for lhs of each slab
     55                                    ;#   coord for lhs of each slab
    5656    private variable _z1 ""         ;# list parallel to _slabs with z1
    57                                     ;#   coord for rhs of each slab
     57                                    ;#   coord for rhs of each slab
    5858    private variable _maters ""     ;# list parallel to _slabs with material
    59                                     ;#   for each slab
     59                                    ;#   for each slab
    6060    private variable _colors ""     ;# list parallel to _slabs with color
    61                                     ;#   for each slab
     61                                    ;#   for each slab
    6262
    6363    private variable _controls      ;# maps control path => status on/off
     
    6565    private variable _icons         ;# maps icon data => image handle
    6666}
    67                                                                                
     67                                                                               
    6868itk::usual DeviceLayout1D {
    6969    keep -background -cursor
     
    8686
    8787    itk_component add area {
    88         canvas $itk_interior.area -borderwidth 0 -highlightthickness 0
     88        canvas $itk_interior.area -borderwidth 0 -highlightthickness 0
    8989    } {
    90         usual
    91         ignore -borderwidth -relief
    92         ignore -highlightthickness -highlightbackground -highlightcolor
     90        usual
     91        ignore -borderwidth -relief
     92        ignore -highlightthickness -highlightbackground -highlightcolor
    9393    }
    9494    pack $itk_component(area) -expand yes -fill both
    9595    bind $itk_component(area) <Configure> \
    96         [list $_dispatcher event -idle !redraw]
     96        [list $_dispatcher event -idle !redraw]
    9797
    9898    eval itk_initialize $args
     
    111111itcl::body Rappture::DeviceLayout1D::limits {} {
    112112    if {[$_dispatcher ispending !layout]} {
    113         $_dispatcher cancel !layout
    114         _layout
     113        $_dispatcher cancel !layout
     114        _layout
    115115    }
    116116    set zmin [lindex $_z0 0]
     
    128128itcl::body Rappture::DeviceLayout1D::extents {what} {
    129129    switch -- $what {
    130         bar3D { return $_sizes(bar45) }
    131         default {
    132             error "bad option \"$what\": should be bar3D"
    133         }
     130        bar3D { return $_sizes(bar45) }
     131        default {
     132            error "bad option \"$what\": should be bar3D"
     133        }
    134134    }
    135135}
     
    144144itcl::body Rappture::DeviceLayout1D::controls {option args} {
    145145    switch -- $option {
    146         add {
    147             if {[llength $args] != 1} {
    148                 error "wrong # args: should be \"controls add path\""
    149             }
    150             set path [lindex $args 0]
    151             set _controls($path) 1
    152             $_dispatcher event -idle !layout
    153         }
    154         remove {
    155             error "not yet implemented"
    156         }
     146        add {
     147            if {[llength $args] != 1} {
     148                error "wrong # args: should be \"controls add path\""
     149            }
     150            set path [lindex $args 0]
     151            set _controls($path) 1
     152            $_dispatcher event -idle !layout
     153        }
     154        remove {
     155            error "not yet implemented"
     156        }
    157157    }
    158158}
     
    180180    # add the maximum size of any embedded icons:
    181181    if {$_device != ""} {
    182         foreach nn [$_device children components] {
    183             set icon [$_device get components.$nn.about.icon]
    184             if {"" != $icon} {
    185                 if {[info exists _icons($icon)]} {
    186                     set imh $_icons($icon)
    187                 } else {
    188                     set imh [image create photo -data $icon]
    189                     set _icons($icon) $imh
    190                 }
    191 
    192                 set w [image width $_icons($icon)]
    193                 if {$w > $wmax} {
    194                     set wmax $w
    195                 }
    196 
    197                 set h [image height $_icons($icon)]
    198                 if {$h > $hmax} {
    199                     set hmax $h
    200                 }
    201             }
    202         }
     182        foreach nn [$_device children components] {
     183            set icon [$_device get components.$nn.about.icon]
     184            if {"" != $icon} {
     185                if {[info exists _icons($icon)]} {
     186                    set imh $_icons($icon)
     187                } else {
     188                    set imh [image create photo -data $icon]
     189                    set _icons($icon) $imh
     190                }
     191
     192                set w [image width $_icons($icon)]
     193                if {$w > $wmax} {
     194                    set wmax $w
     195                }
     196
     197                set h [image height $_icons($icon)]
     198                if {$h > $hmax} {
     199                    set hmax $h
     200                }
     201            }
     202        }
    203203    }
    204204    set _sizes(bararea) $hmax
     
    207207    # see if any of the slabs has a material
    208208    foreach m $_maters {
    209         if {"" != $m} {
    210             set extra [expr {1.5*[font metrics $fnt -linespace]}]
    211             set hmax [expr {$hmax+$extra}]
    212             break
    213         }
     209        if {"" != $m} {
     210            set extra [expr {1.5*[font metrics $fnt -linespace]}]
     211            set hmax [expr {$hmax+$extra}]
     212            break
     213        }
    214214    }
    215215
    216216    # see if any of the slabs has a label
    217217    if {$_device != ""} {
    218         foreach nn [$_device children components] {
    219             if {"" != [$_device get components.$nn.about.label]} {
    220                 set extra [expr {1.2*[font metrics $fnt -linespace]}]
    221                 set hmax [expr {$hmax+$extra}]
    222                 break
    223             }
    224         }
     218        foreach nn [$_device children components] {
     219            if {"" != [$_device get components.$nn.about.label]} {
     220                set extra [expr {1.2*[font metrics $fnt -linespace]}]
     221                set hmax [expr {$hmax+$extra}]
     222                break
     223            }
     224        }
    225225    }
    226226
     
    228228    set oldh [component hull cget -height]
    229229    if {$wmax != $oldw || $hmax != $oldh} {
    230         component hull configure -width $wmax -height $hmax
    231         $_dispatcher event -idle !redraw
     230        component hull configure -width $wmax -height $hmax
     231        $_dispatcher event -idle !redraw
    232232    }
    233233    set _sizes(header) [expr {$hmax - $_sizes(bararea)}]
     
    241241
    242242    if {$_device != ""} {
    243         # get the default system of units
    244         set units [set defunits [$_device get units]]
    245         if {$units == "arbitrary" || $units == ""} {
    246             set defunits "m"
    247             set units "um"
    248         }
    249 
    250         foreach nn [$_device children components] {
    251             switch -glob -- $nn {
    252                 box* {
    253                     # get x-coord for each corner
    254                     set c0 [$_device get components.$nn.corner0]
    255                     regsub -all , $c0 { } c0
    256                     set c0 [lindex $c0 0]
    257                     set c0 [Rappture::Units::convert $c0 \
    258                         -context $defunits -to $units -units off]
    259 
    260                     set c1 [$_device get components.$nn.corner1]
    261                     regsub -all , $c1 { } c1
    262                     set c1 [lindex $c1 0]
    263                     set c1 [Rappture::Units::convert $c1 \
    264                         -context $defunits -to $units -units off]
    265 
    266                     lappend slabs components.$nn
    267                     lappend z0 $c0
    268                     lappend z1 $c1
    269 
    270                     set m [$_device get components.$nn.material]
    271                     lappend maters $m
    272 
    273                     if {"" != $m} {
    274                         set c [_mater2color $m]
    275                     } else {
    276                         set c [$_device get components.$nn.about.color]
    277                     }
    278                     if {"" == $c} { set c gray }
    279                     lappend colors $c
    280                 }
    281                 default {
    282                     # element not recognized -- skip it
    283                 }
    284             }
    285         }
     243        # get the default system of units
     244        set units [set defunits [$_device get units]]
     245        if {$units == "arbitrary" || $units == ""} {
     246            set defunits "m"
     247            set units "um"
     248        }
     249
     250        foreach nn [$_device children components] {
     251            switch -glob -- $nn {
     252                box* {
     253                    # get x-coord for each corner
     254                    set c0 [$_device get components.$nn.corner0]
     255                    regsub -all , $c0 { } c0
     256                    set c0 [lindex $c0 0]
     257                    set c0 [Rappture::Units::convert $c0 \
     258                        -context $defunits -to $units -units off]
     259
     260                    set c1 [$_device get components.$nn.corner1]
     261                    regsub -all , $c1 { } c1
     262                    set c1 [lindex $c1 0]
     263                    set c1 [Rappture::Units::convert $c1 \
     264                        -context $defunits -to $units -units off]
     265
     266                    lappend slabs components.$nn
     267                    lappend z0 $c0
     268                    lappend z1 $c1
     269
     270                    set m [$_device get components.$nn.material]
     271                    lappend maters $m
     272
     273                    if {"" != $m} {
     274                        set c [_mater2color $m]
     275                    } else {
     276                        set c [$_device get components.$nn.about.color]
     277                    }
     278                    if {"" == $c} { set c gray }
     279                    lappend colors $c
     280                }
     281                default {
     282                    # element not recognized -- skip it
     283                }
     284            }
     285        }
    286286    }
    287287
    288288    # something change? then store new layout and redraw
    289289    if {![string equal $z0 $_z0]
    290           || ![string equal $z1 $_z1]
    291           || ![string equal $maters $_maters]
    292           || ![string equal $colors $_colors]} {
    293         set _slabs $slabs
    294         set _z0 $z0
    295         set _z1 $z1
    296         set _maters $maters
    297         set _colors $colors
    298 
    299         $_dispatcher event -idle !redraw
     290          || ![string equal $z1 $_z1]
     291          || ![string equal $maters $_maters]
     292          || ![string equal $colors $_colors]} {
     293        set _slabs $slabs
     294        set _z0 $z0
     295        set _z1 $z1
     296        set _maters $maters
     297        set _colors $colors
     298
     299        $_dispatcher event -idle !redraw
    300300    }
    301301}
     
    323323
    324324    for {set i 0} {$i < [llength $_slabs]} {incr i} {
    325         set name [lindex $_slabs $i]
    326         set z0 [lindex $_z0 $i]
    327         set z1 [lindex $_z1 $i]
    328         set xx0 [expr {double($z0)/$zmax * ($x1-$x0) + $x0}]
    329         set xx1 [expr {double($z1)/$zmax * ($x1-$x0) + $x0}]
    330 
    331         set icon [$_device get $name.about.icon]
    332         if {"" != $icon} {
    333             if {[info exists _icons($icon)]} {
    334                 set imh $_icons($icon)
    335             } else {
    336                 set imh [image create photo -data $icon]
    337                 set _icons($icon) $imh
    338             }
    339             _drawIcon $i $xx0 $xx1 $imh
    340         } else {
    341             _drawLayer $i $xx0 $xx1
    342         }
    343         _drawAnnotation $i $xx0 $xx1
     325        set name [lindex $_slabs $i]
     326        set z0 [lindex $_z0 $i]
     327        set z1 [lindex $_z1 $i]
     328        set xx0 [expr {double($z0)/$zmax * ($x1-$x0) + $x0}]
     329        set xx1 [expr {double($z1)/$zmax * ($x1-$x0) + $x0}]
     330
     331        set icon [$_device get $name.about.icon]
     332        if {"" != $icon} {
     333            if {[info exists _icons($icon)]} {
     334                set imh $_icons($icon)
     335            } else {
     336                set imh [image create photo -data $icon]
     337                set _icons($icon) $imh
     338            }
     339            _drawIcon $i $xx0 $xx1 $imh
     340        } else {
     341            _drawLayer $i $xx0 $xx1
     342        }
     343        _drawAnnotation $i $xx0 $xx1
    344344    }
    345345}
     
    368368
    369369    if {$index < [llength $_slabs]} {
    370         set fcolor [lindex $_colors $index]
    371 
    372         #
    373         # Draw one segment of the bar in the canvas:
    374         #
    375         #      ___________________  ____ y1
    376         #     /                  /| ____ y0p
    377         #    /__________________/ / ____ y1p
    378         #    |__________________|/: ____ y0
    379         #    : :                : :
    380         #   x0 x0p             x1 x1p
    381         #
    382         $c create polygon \
    383             $x0 $y0  $x1 $y0  $x1p $y0p  $x1p $y1  $x0p $y1  $x0 $y1p  $x0 $y0 \
    384             -outline $lcolor -fill $fcolor
    385         $c create line $x0 $y1p  $x1 $y1p -fill $lcolor
    386 
    387         #
    388         # Draw the outline around the end cap
    389         #
    390         $c create line $x1 $y0  $x1 $y1p  $x1p $y1 -fill $lcolor
     370        set fcolor [lindex $_colors $index]
     371
     372        #
     373        # Draw one segment of the bar in the canvas:
     374        #
     375        #      ___________________  ____ y1
     376        #     /                  /| ____ y0p
     377        #    /__________________/ / ____ y1p
     378        #    |__________________|/: ____ y0
     379        #    : :                : :
     380        #   x0 x0p             x1 x1p
     381        #
     382        $c create polygon \
     383            $x0 $y0  $x1 $y0  $x1p $y0p  $x1p $y1  $x0p $y1  $x0 $y1p  $x0 $y0 \
     384            -outline $lcolor -fill $fcolor
     385        $c create line $x0 $y1p  $x1 $y1p -fill $lcolor
     386
     387        #
     388        # Draw the outline around the end cap
     389        #
     390        $c create line $x1 $y0  $x1 $y1p  $x1p $y1 -fill $lcolor
    391391    }
    392392}
     
    445445    set mater [lindex $_maters $index]
    446446    if {"" != $mater} {
    447         set x $x1p
    448         $c create rectangle [expr {$x-10}] [expr {$y-14}] \
    449             [expr {$x-0}] [expr {$y-4}] \
    450             -outline black -fill [_mater2color $mater]
    451         set x [expr {$x-12}]
    452         $c create text $x [expr {$y-7}] -anchor e \
    453             -text $mater
    454         set y [expr {$y-1.5*$lh}]
     447        set x $x1p
     448        $c create rectangle [expr {$x-10}] [expr {$y-14}] \
     449            [expr {$x-0}] [expr {$y-4}] \
     450            -outline black -fill [_mater2color $mater]
     451        set x [expr {$x-12}]
     452        $c create text $x [expr {$y-7}] -anchor e \
     453            -text $mater
     454        set y [expr {$y-1.5*$lh}]
    455455    }
    456456
     
    459459    #
    460460    if {"" != $_device} {
    461         set label [$_device get $elem.about.label]
    462         if {"" != $label} {
    463             $c create text [expr {0.5*($x0p+$x1p)}] $y -anchor s \
    464                 -text $label
    465         }
     461        set label [$_device get $elem.about.label]
     462        if {"" != $label} {
     463            $c create text [expr {0.5*($x0p+$x1p)}] $y -anchor s \
     464                -text $label
     465        }
    466466    }
    467467}
     
    477477    set color [$lib get materials.($mater).color]
    478478    if {$color != ""} {
    479         return $color
     479        return $color
    480480    }
    481481    return gray
     
    501501itcl::configbody Rappture::DeviceLayout1D::device {
    502502    if {$itk_option(-device) != ""} {
    503         if {![Rappture::library isvalid $itk_option(-device)]} {
    504             error "bad value \"$itk_option(-device)\": should be Rappture::Library"
    505         }
     503        if {![Rappture::library isvalid $itk_option(-device)]} {
     504            error "bad value \"$itk_option(-device)\": should be Rappture::Library"
     505        }
    506506    }
    507507    set _device $itk_option(-device)
     
    516516itcl::configbody Rappture::DeviceLayout1D::width {
    517517    if {[catch {
    518           winfo pixels $itk_component(hull) $itk_option(-width)
     518          winfo pixels $itk_component(hull) $itk_option(-width)
    519519      } pixels]} {
    520         error "bad screen distance \"$itk_option(-width)\""
     520        error "bad screen distance \"$itk_option(-width)\""
    521521    }
    522522    $_dispatcher event -idle !layout
     
    530530itcl::configbody Rappture::DeviceLayout1D::devicesize {
    531531    if {[catch {
    532           winfo pixels $itk_component(hull) $itk_option(-devicesize)
     532          winfo pixels $itk_component(hull) $itk_option(-devicesize)
    533533      } pixels]} {
    534         error "bad screen distance \"$itk_option(-devicesize)\""
     534        error "bad screen distance \"$itk_option(-devicesize)\""
    535535    }
    536536    set _sizes(bar) $pixels
     
    561561itcl::configbody Rappture::DeviceLayout1D::leftmargin {
    562562    if {[catch {
    563           winfo pixels $itk_component(hull) $itk_option(-leftmargin)
     563          winfo pixels $itk_component(hull) $itk_option(-leftmargin)
    564564      } pixels]} {
    565         error "bad screen distance \"$itk_option(-leftmargin)\""
     565        error "bad screen distance \"$itk_option(-leftmargin)\""
    566566    }
    567567    set _sizes(lm) $pixels
     
    579579itcl::configbody Rappture::DeviceLayout1D::rightmargin {
    580580    if {[catch {
    581           winfo pixels $itk_component(hull) $itk_option(-rightmargin)
     581          winfo pixels $itk_component(hull) $itk_option(-rightmargin)
    582582      } pixels]} {
    583         error "bad screen distance \"$itk_option(-rightmargin)\""
     583        error "bad screen distance \"$itk_option(-rightmargin)\""
    584584    }
    585585    set _sizes(rm) [expr {($pixels > 0) ? $pixels : $_sizes(bar45)}]
Note: See TracChangeset for help on using the changeset viewer.