Changeset 661 for trunk/gui


Ignore:
Timestamp:
Apr 3, 2007 8:24:38 PM (17 years ago)
Author:
nkissebe
Message:

molvisviewer.tcl: beta3 of molvisviewer

File:
1 edited

Legend:

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

    r648 r661  
    5959    private variable _imagecache
    6060    private variable _state 1
     61    private variable _labels
    6162    private variable _cacheid ""
    6263    private variable _hostlist ""
     
    231232
    232233    # set up bindings for rotation
     234    bind $itk_component(3dview) <ButtonPress> \
     235        [itcl::code $this _vmouse click %b %s %x %y]
     236    bind $itk_component(3dview) <B1-Motion> \
     237        [itcl::code $this _vmouse drag 1 %s %x %y]
     238    bind $itk_component(3dview) <ButtonRelease> \
     239        [itcl::code $this _vmouse release %b %s %x %y]
     240
     241    # set up bindings to bridge mouse events to server
    233242    #bind $itk_component(3dview) <ButtonPress> \
    234     #    [itcl::code $this _vmouse click %b %s %x %y]
     243    #   [itcl::code $this _vmouse2 click %b %s %x %y]
     244    #bind $itk_component(3dview) <ButtonRelease> \
     245    #    [itcl::code $this _vmouse2 release %b %s %x %y]
    235246    #bind $itk_component(3dview) <B1-Motion> \
    236     #    [itcl::code $this _vmouse drag 1 %s %x %y]
    237     #bind $itk_component(3dview) <ButtonRelease> \
    238     #    [itcl::code $this _vmouse release %b %s %x %y]
    239 
    240         # set up bindings to bridge mouse events to server
    241     bind $itk_component(3dview) <ButtonPress> \
    242         [itcl::code $this _vmouse2 click %b %s %x %y]
    243     bind $itk_component(3dview) <ButtonRelease> \
    244         [itcl::code $this _vmouse2 release %b %s %x %y]
    245     bind $itk_component(3dview) <B1-Motion> \
    246         [itcl::code $this _vmouse2 drag 1 %s %x %y]
    247     bind $itk_component(3dview) <B2-Motion> \
    248         [itcl::code $this _vmouse2 drag 2 %s %x %y]
    249     bind $itk_component(3dview) <B3-Motion> \
    250         [itcl::code $this _vmouse2 drag 3 %s %x %y]
    251     bind $itk_component(3dview) <Motion> \
    252         [itcl::code $this _vmouse2 move 0 %s %x %y]
     247    #    [itcl::code $this _vmouse2 drag 1 %s %x %y]
     248    #bind $itk_component(3dview) <B2-Motion> \
     249    #    [itcl::code $this _vmouse2 drag 2 %s %x %y]
     250    #bind $itk_component(3dview) <B3-Motion> \
     251    #    [itcl::code $this _vmouse2 drag 3 %s %x %y]
     252    #bind $itk_component(3dview) <Motion> \
     253    #    [itcl::code $this _vmouse2 move 0 %s %x %y]
    253254
    254255    bind $itk_component(3dview) <Configure> \
     
    265266    set _state 0
    266267    set _model ""
    267 
    268     set i 0
    269     foreach char {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
    270                 a b c d e f g h i j k l m n o p q r s t u v w x y z \
    271                 0 1 2 3 4 5 6 7 8 9 + /} {
    272         set base64_tmp($char) $i
    273         incr i
    274     }
    275 
    276     #
    277     # Create base64 as list: to code for instance C<->3, specify
    278     # that [lindex $base64 67] be 3 (C is 67 in ascii); non-coded
    279     # ascii chars get a {}. we later use the fact that lindex on a
    280     # non-existing index returns {}, and that [expr {} < 0] is true
    281     #
    282 
    283     # the last ascii char is 'z'
    284     scan z %c len
    285     for {set i 0} {$i <= $len} {incr i} {
    286         set char [format %c $i]
    287         set val {}
    288         if {[info exists base64_tmp($char)]} {
    289             set val $base64_tmp($char)
    290         } else {
    291             set val {}
    292         }
    293         lappend _base64 $val
    294     }
    295 
    296     # code the character "=" as -1; used to signal end of message
    297     scan = %c i
    298     set _base64 [lreplace $_base64 $i $i -1]
    299268}
    300269
     
    322291        coming {}
    323292        controls {}
    324         now { 
    325             return [list .jpg [_decodeb64 [$_image(plot) data -format jpeg]]]
     293        now {
     294            return [list .jpg [Rappture::encoding::decode -as b64 [$_image(plot) data -format jpeg]]]
    326295        }
    327296        default {
     
    556525        set _state [$dev get components.molecule.state]
    557526       
    558         if {"" == $model } { set model "molecule" }
     527        if {"" == $model } {
     528                    set model "molecule"
     529            scan $dev "::libraryObj%d" suffix
     530                    set model $model$suffix     
     531        }
    559532        if {"" == $_state} { set _state 1 }
    560533
    561534        if { $model != $_model && $_model != "" } {
    562             _send raw disable $_model
     535            _send disable $_model 0
    563536        }
    564537
    565538        if { [info exists _dataobjs($model-$_state)] } {
    566539            if { $model != $_model } {
    567                 _send raw enable $model
     540                _send enable $model 1
    568541                set _model $model
    569542            }
     
    718691        set diff 0
    719692
    720                 catch { set diff [expr {abs($_mevent(time) - $now)}] }
     693        catch { set diff [expr {abs($_mevent(time) - $now)}] }
    721694
    722695        if {$diff < 75} { # 75ms between motion updates
     
    725698    }
    726699
    727         _send vmouse $vButton $vModifier $vState $x $y
     700     _send vmouse $vButton $vModifier $vState $x $y
    728701
    729702    set _mevent(time) [clock clicks -milliseconds]
     
    731704
    732705itcl::body Rappture::MolvisViewer::_vmouse {option b m x y} {
    733     puts stderr "MolvisViewer::_vmouse($option $b $m $x $y)"
     706    #puts stderr "MolvisViewer::_vmouse($option $b $m $x $y)"
    734707    switch -- $option {
    735708        click {
     
    754727                }
    755728
    756                 eval _send camera angle [expr $y-$_mevent(y)] [expr $x-$_mevent(x)]
    757 
     729                set x1 [expr $w / 3]
     730                set x2 [expr $x1 * 2]
     731                set x3 $w
     732                set y1 [expr $h / 3]
     733                set y2 [expr $y1 * 2]
     734                set y3 $h
     735                set dx [expr $x - $_mevent(x)]
     736                set dy [expr $y - $_mevent(y)]
     737                set mx 0
     738                set my 0
     739                set mz 0
     740
     741                if { $_mevent(x) < $x1 } {
     742                    set mz $dy
     743                } elseif { $_mevent(x) < $x2 } {
     744                    set mx $dy 
     745                } else {
     746                    set mz [expr -$dy]
     747                }
     748
     749                if { $_mevent(y) < $y1 } {
     750                    set mz [expr -$dx]
     751                } elseif { $_mevent(y) < $y2 } {
     752                    set my $dx 
     753                } else {
     754                    set mz $dx
     755                }
     756
     757                _send camera angle $mx $my $mz
    758758                set _mevent(x) $x
    759759                set _mevent(y) $y
     
    853853    }
    854854
     855    set _labels $emblem
     856
    855857    if {$emblem == $current_emblem} { return }
    856858
     
    876878        }
    877879
    878         set emblem [$itk_option(-device) get components.molecule.about.emblems]
    879 
    880         if {$emblem == "" || ![string is boolean $emblem] || !$emblem} {
    881             emblems off
    882         } else {
    883             emblems on
     880        if { ![info exists _labels] } {
     881            set emblem [$itk_option(-device) get components.molecule.about.emblems]
     882
     883            if {$emblem == "" || ![string is boolean $emblem] || !$emblem} {
     884                emblems off
     885            } else {
     886                emblems on
     887            }
    884888        }
    885889    }
     
    888892}
    889893
    890 # ::base64::decode --
    891 #
    892 #   Base64 decode a given string.
    893 #
    894 # Arguments:
    895 #   string  The string to decode.  Characters not in the base64
    896 #       alphabet are ignored (e.g., newlines)
    897 #
    898 # Results:
    899 #   The decoded value.
    900 
    901 itcl::body Rappture::MolvisViewer::_decodeb64 {arg} {
    902     if {[string length $arg] == 0} {return ""}
    903 
    904     set base64 $_base64
    905     set output "" ; # Fix for [Bug 821126]
    906 
    907     binary scan $arg c* X
    908     foreach x $X {
    909         set bits [lindex $base64 $x]
    910         if {$bits >= 0} {
    911             if {[llength [lappend nums $bits]] == 4} {
    912                 foreach {v w z y} $nums break
    913                 set a [expr {($v << 2) | ($w >> 4)}]
    914                 set b [expr {(($w & 0xF) << 4) | ($z >> 2)}]
    915                 set c [expr {(($z & 0x3) << 6) | $y}]
    916                 append output [binary format ccc $a $b $c]
    917                 set nums {}
    918             }               
    919         } elseif {$bits == -1} {
    920             # = indicates end of data.  Output whatever chars are left.
    921             # The encoding algorithm dictates that we can only have 1 or 2
    922             # padding characters.  If x=={}, we have 12 bits of input
    923             # (enough for 1 8-bit output).  If x!={}, we have 18 bits of
    924             # input (enough for 2 8-bit outputs).
    925                
    926             foreach {v w z} $nums break
    927             set a [expr {($v << 2) | (($w & 0x30) >> 4)}]
    928             if {$z == {}} {
    929                 append output [binary format c $a ]
    930             } else {
    931                 set b [expr {(($w & 0xF) << 4) | (($z & 0x3C) >> 2)}]
    932                 append output [binary format cc $a $b]
    933             }               
    934             break
    935         } else {
    936             # RFC 2045 says that line breaks and other characters not part
    937             # of the Base64 alphabet must be ignored, and that the decoder
    938             # can optionally emit a warning or reject the message.  We opt
    939             # not to do so, but to just ignore the character.
    940             continue
    941         }
    942     }
    943     return $output
    944 }
Note: See TracChangeset for help on using the changeset viewer.