- Timestamp:
- Jun 14, 2007, 6:55:08 PM (17 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/molvisviewer.tcl
r770 r772 36 36 37 37 public method emblems {option} 38 public method rock {option} 38 39 public method representation {option {model "all"} } 39 40 … … 42 43 public method isconnected {} 43 44 public method download {option args} 44 protected method _rock {option}45 45 protected method _sendit {args} 46 46 protected method _send {args} … … 49 49 protected method _rebuild { } 50 50 protected method _zoom {option} 51 52 53 51 protected method _configure {w h} 52 protected method _unmap {} 53 protected method _map {} 54 54 protected method _vmouse2 {option b m x y} 55 55 protected method _vmouse {option b m x y} … … 72 72 private variable _model 73 73 private variable _mlist 74 private variable _mrepresentation "ball_and_stick" 74 75 75 76 private variable _imagecache … … 78 79 private variable _cacheid "" 79 80 private variable _hostlist "" 80 private variable _mrepresentation "spheres"81 81 private variable _cacheimage "" 82 private variable _busy 0 83 private variable _mapped 0 82 private variable _busy 0 83 private variable _mapped 0 84 85 common settings ;# array of settings for all known widgets 84 86 } 85 87 … … 99 101 set _rocker(on) 0 100 102 set _state(server) 1 101 set _state(client) 1 103 set _state(client) 1 104 105 array set settings [list \ 106 $this-model $_mrepresentation \ 107 $this-modelimg [image create photo -width 64 -height 64] \ 108 $this-emblems 0 \ 109 $this-rock 0 \ 110 ] 111 $settings($this-modelimg) copy [Rappture::icon ballnstick] 102 112 103 113 Rappture::dispatcher _dispatcher … … 119 129 pack $itk_component(controls) -side right -fill y 120 130 131 itk_component add zoom { 132 frame $itk_component(controls).zoom 133 } { 134 usual 135 rename -background -controlbackground controlBackground Background 136 } 137 pack $itk_component(zoom) -side top 138 121 139 itk_component add reset { 122 button $itk_component( controls).reset \140 button $itk_component(zoom).reset \ 123 141 -borderwidth 1 -padx 1 -pady 1 \ 124 142 -bitmap [Rappture::icon reset] \ … … 129 147 rename -highlightbackground -controlbackground controlBackground Background 130 148 } 131 pack $itk_component(reset) - padx 4-pady 4149 pack $itk_component(reset) -side left -padx {4 1} -pady 4 132 150 Rappture::Tooltip::for $itk_component(reset) "Reset the view to the default zoom level" 133 151 134 152 itk_component add zoomin { 135 button $itk_component( controls).zin \153 button $itk_component(zoom).zin \ 136 154 -borderwidth 1 -padx 1 -pady 1 \ 137 155 -bitmap [Rappture::icon zoomin] \ … … 142 160 rename -highlightbackground -controlbackground controlBackground Background 143 161 } 144 pack $itk_component(zoomin) - padx 4-pady 4162 pack $itk_component(zoomin) -side left -padx 1 -pady 4 145 163 Rappture::Tooltip::for $itk_component(zoomin) "Zoom in" 146 164 147 165 itk_component add zoomout { 148 button $itk_component( controls).zout \166 button $itk_component(zoom).zout \ 149 167 -borderwidth 1 -padx 1 -pady 1 \ 150 168 -bitmap [Rappture::icon zoomout] \ … … 155 173 rename -highlightbackground -controlbackground controlBackground Background 156 174 } 157 pack $itk_component(zoomout) - padx 4-pady 4175 pack $itk_component(zoomout) -side left -padx {1 4} -pady 4 158 176 159 177 Rappture::Tooltip::for $itk_component(zoomout) "Zoom out" 160 178 179 # 180 # Settings panel... 181 # 182 itk_component add settings { 183 button $itk_component(controls).settings -text "Settings..." \ 184 -borderwidth 1 -relief flat -overrelief raised \ 185 -padx 2 -pady 1 \ 186 -command [list $itk_component(controls).panel activate $itk_component(controls).settings left] 187 } { 188 usual 189 ignore -borderwidth 190 rename -background -controlbackground controlBackground Background 191 rename -highlightbackground -controlbackground controlBackground Background 192 } 193 pack $itk_component(settings) -side top -pady {8 2} 194 195 Rappture::Balloon $itk_component(controls).panel -title "Rendering Options" 196 set inner [$itk_component(controls).panel component inner] 197 frame $inner.model 198 pack $inner.model -side top -fill x 199 set fg [option get $itk_component(hull) font Font] 200 201 label $inner.model.pict -image $settings($this-modelimg) 202 pack $inner.model.pict -side left -anchor n 203 label $inner.model.heading -text "Method for drawing atoms:" 204 pack $inner.model.heading -side top -anchor w 205 radiobutton $inner.model.bstick -text "Balls and sticks" \ 206 -command [itcl::code $this representation ball_and_stick all] \ 207 -variable Rappture::MolvisViewer::settings($this-model) -value ball_and_stick 208 pack $inner.model.bstick -side top -anchor w 209 radiobutton $inner.model.spheres -text "Spheres" \ 210 -command [itcl::code $this representation spheres all] \ 211 -variable Rappture::MolvisViewer::settings($this-model) -value spheres 212 pack $inner.model.spheres -side top -anchor w 213 radiobutton $inner.model.lines -text "Lines" \ 214 -command [itcl::code $this representation lines all] \ 215 -variable Rappture::MolvisViewer::settings($this-model) -value lines 216 pack $inner.model.lines -side top -anchor w 217 218 checkbutton $inner.labels -text "Show labels on atoms" \ 219 -command [itcl::code $this emblems update] \ 220 -variable Rappture::MolvisViewer::settings($this-emblems) 221 pack $inner.labels -side top -anchor w -pady {4 1} 222 223 checkbutton $inner.rock -text "Rock model back and forth" \ 224 -command [itcl::code $this rock toggle] \ 225 -variable Rappture::MolvisViewer::settings($this-rock) 226 pack $inner.rock -side top -anchor w -pady {1 4} 227 228 # 229 # Shortcuts 230 # 231 itk_component add shortcuts { 232 frame $itk_component(controls).shortcuts 233 } { 234 usual 235 rename -background -controlbackground controlBackground Background 236 } 237 pack $itk_component(shortcuts) -side top 238 161 239 itk_component add labels { 162 label $itk_component( controls).labels \240 label $itk_component(shortcuts).labels \ 163 241 -borderwidth 1 -padx 1 -pady 1 \ 164 242 -relief "raised" -bitmap [Rappture::icon atoms] … … 168 246 rename -highlightbackground -controlbackground controlBackground Background 169 247 } 170 pack $itk_component(labels) - padx 4-pady 4 -ipadx 1 -ipady 1248 pack $itk_component(labels) -side left -padx {4 1} -pady 4 -ipadx 1 -ipady 1 171 249 Rappture::Tooltip::for $itk_component(labels) "Show/hide the labels on atoms" 172 250 bind $itk_component(labels) <ButtonPress> \ … … 174 252 175 253 itk_component add rock { 176 label $itk_component( controls).rock \254 label $itk_component(shortcuts).rock \ 177 255 -borderwidth 1 -padx 1 -pady 1 \ 178 -relief "raised" - text "R" \256 -relief "raised" -bitmap [Rappture::icon rocker] 179 257 } { 180 258 usual … … 182 260 rename -highlightbackground -controlbackground controlBackground Background 183 261 } 184 pack $itk_component(rock) -padx 4 -pady 4 -ipadx 1 -ipady 1 185 Rappture::Tooltip::for $itk_component(rock) "Rock model +/- 10 degrees" 186 187 itk_component add show_lines { 188 label $itk_component(controls).show_lines \ 189 -borderwidth 1 -padx 1 -pady 1 \ 190 -relief "raised" -text "/" \ 191 } { 192 usual 193 ignore -borderwidth 194 rename -highlightbackground -controlbackground controlBackground Background 195 } 196 pack $itk_component(show_lines) -padx 4 -pady 4 197 bind $itk_component(show_lines) <ButtonPress> \ 198 [itcl::code $this representation lines all] 199 200 itk_component add show_spheres { 201 label $itk_component(controls).show_spheres \ 202 -borderwidth 1 -padx 1 -pady 1 \ 203 -relief "sunken" -text "O" \ 204 } { 205 usual 206 ignore -borderwidth 207 rename -highlightbackground -controlbackground controlBackground Background 208 } 209 pack $itk_component(show_spheres) -padx 4 -pady 4 210 bind $itk_component(show_spheres) <ButtonPress> \ 211 [itcl::code $this representation spheres all] 212 213 itk_component add show_ball_and_stick { 214 label $itk_component(controls).show_ball_and_stick \ 215 -borderwidth 1 -padx 1 -pady 1 \ 216 -relief "raised" -text "%" \ 217 } { 218 usual 219 ignore -borderwidth 220 rename -highlightbackground -controlbackground controlBackground Background 221 } 222 pack $itk_component(show_ball_and_stick) -padx 4 -pady 4 223 bind $itk_component(show_ball_and_stick) <ButtonPress> \ 224 [itcl::code $this representation ball_and_stick all] 225 262 pack $itk_component(rock) -side left -padx 1 -pady 4 -ipadx 1 -ipady 1 263 Rappture::Tooltip::for $itk_component(rock) "Rock model back and forth" 264 226 265 bind $itk_component(rock) <ButtonPress> \ 227 [itcl::code $this _rock toggle]266 [itcl::code $this rock toggle] 228 267 229 268 # … … 270 309 # [itcl::code $this _vmouse2 move 0 %s %x %y] 271 310 272 311 connect $hostlist 273 312 274 313 bind $itk_component(3dview) <Configure> \ … … 290 329 itcl::body Rappture::MolvisViewer::destructor {} { 291 330 #puts stderr "MolvisViewer::destructor()" 331 disconnect 332 292 333 image delete $_image(plot) 293 disconnect 334 image delete $settings($this-modelimg) 335 unset settings($this-emblems) 336 unset settings($this-rock) 337 unset settings($this-model) 338 unset settings($this-modelimg) 294 339 } 295 340 … … 356 401 357 402 set hosts [lrange $hosts 1 end] 358 403 set result 0 359 404 360 405 while {1} { … … 387 432 if {[string equal $hostname "0.0.0.0"]} { 388 433 set _sid $sid 389 390 434 set _rocker(server) 0 435 set _cacheid 0 391 436 392 437 fileevent $_sid readable [itcl::code $this _receive $_sid] … … 396 441 397 442 set result 1 398 443 break 399 444 } 400 445 } … … 414 459 #puts stderr "MolvisViewer::disconnect()" 415 460 416 461 catch { fileevent $_sid readable {} } 417 462 catch { after cancel $_rocker(afterid) } 418 463 catch { after cancel $_mevent(afterid) } 419 464 catch { close $_sid } 420 465 catch { unset _dataobjs } 421 422 catch {unset _mlist }466 catch { unset _model } 467 catch { unset _mlist } 423 468 catch { unset _imagecache } 424 469 425 470 set _sid "" 426 427 471 set _state(server) 1 472 set _state(client) 1 428 473 } 429 474 … … 449 494 if { $_sid != "" } { 450 495 if { ![catch { puts $_sid $args }] } { 451 452 453 496 flush $_sid 497 return 0 498 } else { 454 499 catch { close $_sid } 455 500 set _sid "" 456 457 501 } 502 } 458 503 459 504 $_dispatcher event -after 1 !rebuild 460 505 461 506 return 1 462 507 } 463 508 … … 469 514 set _state(server) $_state(client) 470 515 } 471 516 } 472 517 473 518 if { $_rocker(server) != $_rocker(client) } { 474 519 if { [_sendit "rock -defer $_rocker(client)"] == 0 } { 475 520 set _rocker(server) $_rocker(client) 476 477 521 } 522 } 478 523 479 524 eval _sendit $args … … 491 536 492 537 if { $sid == "" } { 493 494 495 496 538 return 539 } 540 541 fileevent $sid readable {} 497 542 498 543 if { $sid != $_sid } { 499 500 544 return 545 } 501 546 502 547 fconfigure $_sid -buffering line -blocking 0 … … 505 550 506 551 if { ![fblocked $_sid] } { 507 508 552 catch { close $_sid } 553 set _sid "" 509 554 $_dispatcher event -after 750 !serverDown 510 555 } 511 556 512 557 } elseif {[regexp {^\s*nv>\s*image\s+(\d+)\s*(\d+)\s*,\s*(\d+)\s*,\s*(-{0,1}\d+)} $line whole match cacheid frame rock]} { 513 558 514 559 set tag "$frame,$rock" 515 560 516 561 if { $cacheid != $_cacheid } { 517 562 catch { unset _imagecache } … … 521 566 fconfigure $_sid -buffering none -blocking 1 522 567 set _imagecache($tag) [read $_sid $match] 523 568 #puts stderr "CACHED: $tag,$cacheid" 524 569 $_image(plot) put $_imagecache($tag) 525 570 set _image(id) $tag 526 571 527 572 if { $_busy } { 528 573 $itk_component(3dview) configure -cursor "" 529 530 574 set _busy 0 575 } 531 576 532 577 } else { … … 535 580 } 536 581 537 582 if { $_sid != "" } { 538 583 fileevent $_sid readable [itcl::code $this _receive $_sid] 539 584 } … … 551 596 552 597 if { $_inrebuild } { 553 554 555 556 557 598 # don't allow overlapping rebuild calls 599 return 600 } 601 602 set _inrebuild 1 558 603 559 604 if {"" == $_sid} { … … 573 618 } else { 574 619 Rappture::Tooltip::cue @$x,$y "Can't connect to visualization server. This may be a network problem. Wait a few moments and try resetting the view." 575 576 620 set _inrebuild 0 621 set _busy 1 577 622 return 578 579 } 580 581 582 623 } 624 } 625 626 set changed 0 627 set _busy 1 583 628 584 629 $itk_component(3dview) configure -cursor watch 585 630 586 631 # refresh GUI (primarily to make pending cursor changes visible) 587 632 update idletasks 588 633 … … 596 641 set model "molecule" 597 642 scan $dev "::libraryObj%d" suffix 598 set model $model$suffix 643 set model $model$suffix 599 644 } 600 645 601 646 if {"" == $state} { set state $_state(server) } 602 647 603 604 605 606 607 608 609 648 if { ![info exists _mlist($model)] } { # new, turn on 649 set _mlist($model) 2 650 } elseif { $_mlist($model) == 1 } { # on, leave on 651 set _mlist($model) 3 652 } elseif { $_mlist($model) == 0 } { # off, turn on 653 set _mlist($model) 2 654 } 610 655 611 656 if { ![info exists _dataobjs($model-$state)] } { 612 613 657 set data1 "" 658 set serial 0 614 659 615 660 foreach _atom [$dev children -type atom components.molecule] { … … 618 663 regsub {,} $xyz {} xyz 619 664 scan $xyz "%f %f %f" x y z 620 621 622 623 624 625 626 627 628 629 630 665 set recname "ATOM " 666 set altLoc "" 667 set resName "" 668 set chainID "" 669 set Seqno "" 670 set occupancy 1 671 set tempFactor 0 672 set recID "" 673 set segID "" 674 set element "" 675 set charge "" 631 676 set atom $symbol 632 677 set line [format "%6s%5d %4s%1s%3s %1s%5s %8.3f%8.3f%8.3f%6.2f%6.2f%8s\n" $recname $serial $atom $altLoc $resName $chainID $Seqno $x $y $z $occupancy $tempFactor $recID] … … 650 695 } 651 696 652 653 654 655 656 657 658 659 660 661 662 663 664 697 if { ![info exists _model($model-transparency)] } { 698 set _model($model-transparency) "undefined" 699 } 700 701 if { ![info exists _model($model-representation)] } { 702 set _model($model-representation) "undefined" 703 set _model($model-newrepresentation) $_mrepresentation 704 } 705 706 707 if { $_model($model-transparency) != $_dobj2transparency($dev) } { 708 set _model($model-newtransparency) $_dobj2transparency($dev) 709 } 665 710 } 666 711 … … 670 715 if { $_mlist($obj) == 1 } { 671 716 _send disable -defer $obj 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 717 set _mlist($obj) 0 718 set changed 1 719 } elseif { $_mlist($obj) == 2 } { 720 set _mlist($obj) 1 721 _send enable -defer $obj 722 if { $_labels } { 723 _send label -defer on 724 } else { 725 _send label -defer off 726 } 727 set changed 1 728 } elseif { $_mlist($obj) == 3 } { 729 set _mlist($obj) 1 730 } 731 732 733 if { $_mlist($obj) == 1 } { 734 if { [info exists _model($obj-newtransparency)] || [info exists _model($obj-newrepresentation)] } { 735 if { ![info exists _model($obj-newrepresentation)] } { 736 set _model($obj-newrepresentation) $_model($obj-representation) 737 } 738 if { ![info exists _model($obj-newtransparency)] } { 739 set _model($obj-newtransparency) $_model($obj-transparency) 740 } 741 _send $_model($obj-newrepresentation) -defer -model $obj -$_model($obj-newtransparency) 742 set changed 1 743 set _model($obj-transparency) $_model($obj-newtransparency) 744 set _model($obj-representation) $_model($obj-newrepresentation) 745 catch { 746 unset _model($obj-newtransparency) 747 unset _model($obj-newrepresentation) 748 } 749 } 750 } 751 752 } 753 754 if { $changed } { 710 755 catch { unset _imagecache } 711 756 } 712 757 713 758 if { $dlist == "" } { 714 715 716 717 718 719 759 set _state(server) 1 760 set _state(client) 1 761 _send frame -push 1 762 } elseif { ![info exists _imagecache($state,$_rocker(client))] } { 763 set _state(server) $state 764 set _state(client) $state 720 765 _send frame -push $state 721 766 } else { 722 723 724 725 726 727 728 729 730 731 732 767 set _state(client) $state 768 _update 769 } 770 771 set _inrebuild 0 772 773 if { $_sid == "" } { 774 # connection failed during rebuild, don't attempt to reconnect/rebuild 775 # until user initiates some action 776 777 disconnect 733 778 $_dispatcher cancel !rebuild 734 779 $_dispatcher event -after 750 !serverDown 735 } 780 } 781 $itk_component(3dview) configure -cursor "" 736 782 } 737 783 … … 740 786 741 787 #pause rocking loop while unmapped (saves CPU time) 742 _rock pause743 744 745 746 747 788 rock pause 789 790 # blank image, mark current image dirty 791 # this will force reload from cache, or remain blank if cache is cleared 792 # this prevents old image from briefly appearing when a new result is added 793 # by result viewer 748 794 749 795 set _mapped 0 750 796 $_image(plot) blank 751 797 set _image(id) "" 752 798 } 753 799 … … 757 803 set _mapped 1 758 804 759 760 _rock unpause761 762 805 # resume rocking loop if it was on 806 rock unpause 807 808 # rebuild image if modified, or redisplay cached image if not 763 809 $_dispatcher event -idle !rebuild 764 810 } … … 769 815 $_image(plot) configure -width $w -height $h 770 816 771 772 773 817 # immediately invalidate cache, defer update until mapped 818 819 catch { unset _imagecache } 774 820 775 821 if { $_mapped } { 776 822 _send screen $w $h 777 823 } else { 778 824 _send screen -defer $w $h 779 825 } 780 826 } 781 827 … … 808 854 if { $_image(id) != "$_state(client),$_rocker(client)" } { 809 855 if { [info exists _imagecache($_state(client),$_rocker(client))] } { 810 856 #puts stderr "DISPLAYING CACHED IMAGE" 811 857 $_image(plot) put $_imagecache($_state(client),$_rocker(client)) 812 set _image(id) "$_state(client),$_rocker(client)" 813 } 814 } 815 } 816 817 # ---------------------------------------------------------------------- 818 # USAGE: _vmouse click <x> <y> 819 # USAGE: _vmouse drag <x> <y> 820 # USAGE: _vmouse release <x> <y> 821 # 822 # Called automatically when the user clicks/drags/releases in the 823 # plot area. Moves the plot according to the user's actions. 824 # ---------------------------------------------------------------------- 825 826 itcl::body Rappture::MolvisViewer::_rock { option } { 858 set _image(id) "$_state(client),$_rocker(client)" 859 } 860 } 861 } 862 863 # ---------------------------------------------------------------------- 864 # USAGE: rock on|off|toggle 865 # USAGE: rock pause|unpause|step 866 # 867 # Used to control the "rocking" model for the molecule being displayed. 868 # Clients should use only the on/off/toggle options; the rest are for 869 # internal control of the rocking motion. 870 # ---------------------------------------------------------------------- 871 itcl::body Rappture::MolvisViewer::rock { option } { 827 872 #puts "MolvisViewer::_rock($option,$_rocker(client))" 828 873 … … 841 886 } 842 887 843 if { $option == "on" || $option == "toggle" && !$_rocker(on) } {888 if { $option == "on" || ($option == "toggle" && !$_rocker(on)) } { 844 889 set _rocker(on) 1 890 set settings($this-rock) 1 845 891 $itk_component(rock) configure -relief sunken 846 } elseif { $option == "off" || $option == "toggle" && $_rocker(on) } {892 } elseif { $option == "off" || ($option == "toggle" && $_rocker(on)) } { 847 893 set _rocker(on) 0 894 set settings($this-rock) 0 848 895 $itk_component(rock) configure -relief raised 849 896 } elseif { $option == "step"} { … … 852 899 set _rocker(dir) -1 853 900 } elseif { $_rocker(client) <= -10 } { 854 855 } 856 857 set _rocker(client) [expr $_rocker(client) + $_rocker(dir)]901 set _rocker(dir) 1 902 } 903 904 set _rocker(client) [expr {$_rocker(client) + $_rocker(dir)}] 858 905 859 906 if { ![info exists _imagecache($_state(server),$_rocker(client))] } { 860 907 set _rocker(server) $_rocker(client) 861 908 _send rock $_rocker(client) 862 909 } 863 864 _update 865 } 866 867 if { $_rocker(on) && $option != "pause" } { 868 set _rocker(afterid) [after 200 [itcl::code $this _rock step]] 869 } 910 _update 911 } 912 913 if { $_rocker(on) && $option != "pause" } { 914 set _rocker(afterid) [after 200 [itcl::code $this rock step]] 915 } 870 916 } 871 917 … … 911 957 } 912 958 913 914 915 959 if { ![info exists _mevent(x)] } { 960 set option "click" 961 } 916 962 917 963 if { $option == "click" } { … … 920 966 921 967 if { $option == "drag" || $option == "release" } { 922 968 set diff 0 923 969 catch { set diff [expr $now - $_mevent(time) ] } 924 970 … … 948 994 set mz $dy 949 995 } elseif { $_mevent(x) < $x2 } { 950 set mx $dy 996 set mx $dy 951 997 } else { 952 998 set mz [expr -$dy] … … 956 1002 set mz [expr -$dx] 957 1003 } elseif { $_mevent(y) < $y2 } { 958 set my $dx 1004 set my $dx 959 1005 } else { 960 1006 set mz $dx … … 987 1033 set y [expr {[winfo rooty $itk_component(area)]+10}] 988 1034 989 1035 if { $_busy } { 990 1036 $itk_component(3dview) configure -cursor "" 991 1037 set _busy 0 992 1038 } 993 1039 994 1040 Rappture::Tooltip::cue @$x,$y "Lost connection to visualization server. This happens sometimes when there are too many users and the system runs out of memory.\n\nTo reconnect, reset the view or press any other control. Your picture should come right back up." … … 1010 1056 switch -- $option { 1011 1057 spheres { 1012 $itk_component(show_spheres) configure -relief sunken 1013 $itk_component(show_lines) configure -relief raised 1014 $itk_component(show_ball_and_stick) configure -relief raised 1058 $settings($this-modelimg) copy [Rappture::icon spheres] 1015 1059 } 1016 1060 ball_and_stick { 1017 $itk_component(show_spheres) configure -relief raised 1018 $itk_component(show_lines) configure -relief raised 1019 $itk_component(show_ball_and_stick) configure -relief sunken 1061 $settings($this-modelimg) copy [Rappture::icon ballnstick] 1020 1062 } 1021 1063 lines { 1022 $itk_component(show_spheres) configure -relief raised 1023 $itk_component(show_lines) configure -relief sunken 1024 $itk_component(show_ball_and_stick) configure -relief raised 1025 } 1026 default { 1027 return 1028 } 1029 } 1064 $settings($this-modelimg) copy [Rappture::icon lines] 1065 } 1066 default { 1067 return 1068 } 1069 } 1070 1071 # save the current option to set all radiobuttons -- just in case 1072 # this method gets called without the user clicking on a radiobutton 1073 set settings($this-model) $option 1030 1074 1031 1075 set _mrepresentation $option … … 1033 1077 if { $model == "all" } { 1034 1078 set models [array names _mlist] 1035 1036 1037 1079 } else { 1080 set models $model 1081 } 1038 1082 1039 1083 foreach obj $models { 1040 1041 1042 1043 1044 1045 1046 1047 1084 if { [info exists _model($obj-representation)] } { 1085 if { $_model($obj-representation) != $option } { 1086 set _model($obj-newrepresentation) $option 1087 } else { 1088 catch { unset _model($obj-newrepresentation) } 1089 } 1090 } 1091 } 1048 1092 1049 1093 $_dispatcher event -idle !rebuild … … 1051 1095 1052 1096 # ---------------------------------------------------------------------- 1053 # USAGE: emblems on 1054 # USAGE: emblems off 1055 # USAGE: emblems toggle 1097 # USAGE: emblems on|off|toggle 1098 # USAGE: emblems update 1056 1099 # 1057 1100 # Used internally to turn labels associated with atoms on/off, and to … … 1060 1103 itcl::body Rappture::MolvisViewer::emblems {option} { 1061 1104 #puts stderr "MolvisViewer::emblems($option)" 1062 1063 if {[$itk_component(labels) cget -relief] == "sunken"} {1064 set current_emblem 11065 } else {1066 set current_emblem 01067 }1068 1105 1069 1106 switch -- $option { … … 1075 1112 } 1076 1113 toggle { 1077 if { $current_emblem == 1} {1114 if {$settings($this-emblems)} { 1078 1115 set emblem 0 1079 1116 } else { … … 1081 1118 } 1082 1119 } 1120 update { 1121 set emblem $settings($this-emblems) 1122 } 1083 1123 default { 1084 error "bad option \"$option\": should be on, off, toggle "1124 error "bad option \"$option\": should be on, off, toggle, update" 1085 1125 } 1086 1126 } … … 1088 1128 set _labels $emblem 1089 1129 1090 if {$emblem == $current_emblem} { return } 1130 if {$emblem == $settings($this-emblems) && $option != "update"} { 1131 # nothing to do 1132 return 1133 } 1091 1134 1092 1135 if {$emblem} { 1093 1136 $itk_component(labels) configure -relief sunken 1137 set settings($this-emblems) 1 1094 1138 _send label on 1095 1139 } else { 1096 1140 $itk_component(labels) configure -relief raised 1141 set settings($this-emblems) 0 1097 1142 _send label off 1098 1143 } … … 1111 1156 1112 1157 array set params { 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1158 -color auto 1159 -brightness 0 1160 -width 1 1161 -raise 0 1162 -linestyle solid 1163 -description "" 1164 -param "" 1165 } 1166 1167 foreach {opt val} $settings { 1168 if {![info exists params($opt)]} { 1169 error "bad settings \"$opt\": should be [join [lsort [array names params]] {, }]" 1170 } 1171 set params($opt) $val 1172 } 1128 1173 1129 1130 1131 1174 set pos [lsearch -exact $dataobj $_dlist] 1175 1176 if {$pos < 0} { 1132 1177 if {![Rappture::library isvalid $dataobj]} { 1133 1178 error "bad value \"$dataobj\": should be Rappture::library object" 1134 1179 } 1135 1136 1180 1181 if { $_labels == "default" } { 1137 1182 set emblem [$dataobj get components.molecule.about.emblems] 1138 1183 … … 1144 1189 } 1145 1190 1146 1147 1148 1149 1150 1151 1152 1191 lappend _dlist $dataobj 1192 if { $params(-brightness) >= 0.5 } { 1193 set _dobj2transparency($dataobj) "ghost" 1194 } else { 1195 set _dobj2transparency($dataobj) "normal" 1196 } 1197 set _dobj2raise($dataobj) $params(-raise) 1153 1198 1154 1199 $_dispatcher event -idle !rebuild … … 1166 1211 1167 1212 # put the dataobj list in order according to -raise options 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1213 set dlist $_dlist 1214 foreach obj $dlist { 1215 if {[info exists _dobj2raise($obj)] && $_dobj2raise($obj)} { 1216 set i [lsearch -exact $dlist $obj] 1217 if {$i >= 0} { 1218 set dlist [lreplace $dlist $i $i] 1219 lappend dlist $obj 1220 } 1221 } 1222 } 1223 return $dlist 1179 1224 } 1180 1225 … … 1189 1234 1190 1235 if {[llength $args] == 0} { 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1236 set args $_dlist 1237 } 1238 1239 # delete all specified dataobjs 1240 set changed 0 1241 foreach dataobj $args { 1242 set pos [lsearch -exact $_dlist $dataobj] 1243 if {$pos >= 0} { 1244 set _dlist [lreplace $_dlist $pos $pos] 1245 catch {unset _dobj2transparency($dataobj)} 1246 catch {unset _dobj2color($dataobj)} 1247 catch {unset _dobj2width($dataobj)} 1248 catch {unset _dobj2dashes($dataobj)} 1249 catch {unset _dobj2raise($dataobj)} 1205 1250 set changed 1 1206 1207 1208 1209 1210 1251 } 1252 } 1253 1254 # if anything changed, then rebuild the plot 1255 if {$changed} { 1211 1256 $_dispatcher event -idle !rebuild 1212 1257 } 1213 1258 } 1214 1259 … … 1224 1269 error "bad value \"$itk_option(-device)\": should be Rappture::library object" 1225 1270 } 1226 1227 1228 1229 1230 1271 $this delete 1272 $this add $itk_option(-device) 1273 } else { 1274 $this delete 1275 } 1231 1276 1232 1277 $_dispatcher event -idle !rebuild 1233 1278 } 1234
Note: See TracChangeset
for help on using the changeset viewer.