- Timestamp:
- Apr 3, 2007, 8:24:38 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/molvisviewer.tcl
r648 r661 59 59 private variable _imagecache 60 60 private variable _state 1 61 private variable _labels 61 62 private variable _cacheid "" 62 63 private variable _hostlist "" … … 231 232 232 233 # 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 233 242 #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] 235 246 #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] 253 254 254 255 bind $itk_component(3dview) <Configure> \ … … 265 266 set _state 0 266 267 set _model "" 267 268 set i 0269 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) $i273 incr i274 }275 276 #277 # Create base64 as list: to code for instance C<->3, specify278 # that [lindex $base64 67] be 3 (C is 67 in ascii); non-coded279 # ascii chars get a {}. we later use the fact that lindex on a280 # non-existing index returns {}, and that [expr {} < 0] is true281 #282 283 # the last ascii char is 'z'284 scan z %c len285 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 $val294 }295 296 # code the character "=" as -1; used to signal end of message297 scan = %c i298 set _base64 [lreplace $_base64 $i $i -1]299 268 } 300 269 … … 322 291 coming {} 323 292 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]]] 326 295 } 327 296 default { … … 556 525 set _state [$dev get components.molecule.state] 557 526 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 } 559 532 if {"" == $_state} { set _state 1 } 560 533 561 534 if { $model != $_model && $_model != "" } { 562 _send raw disable $_model535 _send disable $_model 0 563 536 } 564 537 565 538 if { [info exists _dataobjs($model-$_state)] } { 566 539 if { $model != $_model } { 567 _send raw enable $model540 _send enable $model 1 568 541 set _model $model 569 542 } … … 718 691 set diff 0 719 692 720 693 catch { set diff [expr {abs($_mevent(time) - $now)}] } 721 694 722 695 if {$diff < 75} { # 75ms between motion updates … … 725 698 } 726 699 727 700 _send vmouse $vButton $vModifier $vState $x $y 728 701 729 702 set _mevent(time) [clock clicks -milliseconds] … … 731 704 732 705 itcl::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)" 734 707 switch -- $option { 735 708 click { … … 754 727 } 755 728 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 758 758 set _mevent(x) $x 759 759 set _mevent(y) $y … … 853 853 } 854 854 855 set _labels $emblem 856 855 857 if {$emblem == $current_emblem} { return } 856 858 … … 876 878 } 877 879 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 } 884 888 } 885 889 } … … 888 892 } 889 893 890 # ::base64::decode --891 #892 # Base64 decode a given string.893 #894 # Arguments:895 # string The string to decode. Characters not in the base64896 # 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 $_base64905 set output "" ; # Fix for [Bug 821126]906 907 binary scan $arg c* X908 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 break913 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 2922 # padding characters. If x=={}, we have 12 bits of input923 # (enough for 1 8-bit output). If x!={}, we have 18 bits of924 # input (enough for 2 8-bit outputs).925 926 foreach {v w z} $nums break927 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 break935 } else {936 # RFC 2045 says that line breaks and other characters not part937 # of the Base64 alphabet must be ignored, and that the decoder938 # can optionally emit a warning or reject the message. We opt939 # not to do so, but to just ignore the character.940 continue941 }942 }943 return $output944 }
Note: See TracChangeset
for help on using the changeset viewer.