Changeset 2628 for trunk/gui/scripts
- Timestamp:
- Oct 14, 2011, 11:48:46 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/molvisviewer.tcl
r2613 r2628 65 65 private variable _cacheid "" 66 66 private variable _cacheimage "" 67 68 private variable _delta1 1069 private variable _delta2 270 67 71 68 private common _settings ; # Array of settings for all known … … 82 79 private variable _width 83 80 private variable _height 84 private variable _res tore1; # Restore camera settings81 private variable _reset 1; # Restore camera settings 85 82 private variable _cell 0; # Restore camera settings 83 private variable _flush 1 86 84 87 85 constructor { hostlist args } { … … 183 181 set _state(client) 1 184 182 set _hostlist $hostlist 185 set _res tore1183 set _reset 1 186 184 187 185 array set _view { … … 401 399 } 402 400 403 itcl::body Rappture::MolvisViewer::BuildSettingsTab {} {404 set fg [option get $itk_component(hull) font Font]405 406 set inner [$itk_component(main) insert end \407 -title "Settings" \408 -icon [Rappture::icon wrench]]409 $inner configure -borderwidth 4410 411 label $inner.drawinglabel -text "Molecule Representation" \412 -font "Arial 9 bold"413 414 label $inner.pict -image $_settings($this-modelimg)415 416 radiobutton $inner.bstick -text "balls and sticks" \417 -command [itcl::code $this Representation ballnstick all] \418 -variable Rappture::MolvisViewer::_settings($this-model) \419 -value ballnstick -font "Arial 9" -pady 0420 Rappture::Tooltip::for $inner.bstick \421 "Display atoms (balls) and connections (sticks) "422 423 radiobutton $inner.spheres -text "spheres" \424 -command [itcl::code $this Representation spheres all] \425 -variable Rappture::MolvisViewer::_settings($this-model) \426 -value spheres -font "Arial 9" -pady 0427 Rappture::Tooltip::for $inner.spheres \428 "Display atoms as spheres. Do not display bonds."429 430 radiobutton $inner.sticks -text "sticks" \431 -command [itcl::code $this Representation sticks all] \432 -variable Rappture::MolvisViewer::_settings($this-model) \433 -value sticks -font "Arial 9" -pady 0434 Rappture::Tooltip::for $inner.sticks \435 "Display bonds as sticks. Do not display atoms."436 437 radiobutton $inner.lines -text "lines" \438 -command [itcl::code $this Representation lines all] \439 -variable [itcl::scope _settings($this-model)] \440 -value lines -font "Arial 9" -pady 0441 Rappture::Tooltip::for $inner.lines \442 "Display bonds as lines. Do not display atoms."443 444 radiobutton $inner.cartoon -text "cartoon" \445 -command [itcl::code $this Representation cartoon all] \446 -variable [itcl::scope _settings($this-model)] \447 -value cartoon -font "Arial 9" -pady 0448 Rappture::Tooltip::for $inner.cartoon \449 "Display cartoon representation of bonds (sticks)."450 451 scale $inner.spherescale -width 10 -font "Arial 9 bold" \452 -from 0.1 -to 2.0 -resolution 0.05 -label "Sphere Scale" \453 -showvalue true -orient horizontal \454 -command [itcl::code $this SphereScale] \455 -variable Rappture::MolvisViewer::_settings($this-spherescale)456 $inner.spherescale set $_settings($this-spherescale)457 Rappture::Tooltip::for $inner.spherescale \458 "Adjust scale of atoms (spheres or balls). 1.0 is the full VDW radius."459 460 scale $inner.stickradius -width 10 -font "Arial 9 bold" \461 -from 0.1 -to 1.0 -resolution 0.025 -label "Stick Radius" \462 -showvalue true -orient horizontal \463 -command [itcl::code $this StickRadius] \464 -variable Rappture::MolvisViewer::_settings($this-stickradius)465 Rappture::Tooltip::for $inner.stickradius \466 "Adjust scale of bonds (sticks)."467 $inner.stickradius set $_settings($this-stickradius)468 469 checkbutton $inner.labels -text "Show labels on atoms" \470 -command [itcl::code $this labels update] \471 -variable [itcl::scope _settings($this-showlabels)] \472 -font "Arial 9 bold"473 Rappture::Tooltip::for $inner.labels \474 "Display atom symbol and serial number."475 476 checkbutton $inner.rock -text "Rock model back and forth" \477 -command [itcl::code $this Rock toggle] \478 -variable Rappture::MolvisViewer::_settings($this-rock) \479 -font "Arial 9 bold"480 Rappture::Tooltip::for $inner.rock \481 "Rotate the object back and forth around the y-axis."482 483 checkbutton $inner.ortho -text "Orthoscopic projection" \484 -command [itcl::code $this OrthoProjection update] \485 -variable Rappture::MolvisViewer::_settings($this-ortho) \486 -font "Arial 9 bold"487 Rappture::Tooltip::for $inner.ortho \488 "Toggle between orthoscopic/perspective projection modes."489 490 checkbutton $inner.cartoontrace -text "Cartoon Trace" \491 -command [itcl::code $this CartoonTrace update] \492 -variable [itcl::scope _settings($this-cartoontrace)] \493 -font "Arial 9 bold"494 Rappture::Tooltip::for $inner.cartoontrace \495 "Set cartoon representation of bonds (sticks)."496 497 checkbutton $inner.cell -text "Parallelepiped" \498 -command [itcl::code $this Cell toggle] \499 -font "Arial 9 bold"500 $inner.cell select501 502 label $inner.spacer503 blt::table $inner \504 0,0 $inner.drawinglabel -anchor w -columnspan 4 \505 1,1 $inner.pict -anchor w -rowspan 5 \506 1,2 $inner.bstick -anchor w -columnspan 2 \507 2,2 $inner.spheres -anchor w -columnspan 2 \508 3,2 $inner.sticks -anchor w -columnspan 2 \509 4,2 $inner.lines -anchor w -columnspan 2 \510 5,2 $inner.cartoon -anchor w -columnspan 2 \511 6,0 $inner.labels -anchor w -columnspan 4 -pady {1 0} \512 7,0 $inner.rock -anchor w -columnspan 4 -pady {1 0} \513 8,0 $inner.ortho -anchor w -columnspan 4 -pady {1 0} \514 9,0 $inner.cartoontrace -anchor w -columnspan 4 -pady {1 0} \515 10,0 $inner.cell -anchor w -columnspan 4 -pady {1 0} \516 11,1 $inner.spherescale -fill x -columnspan 4 -pady {1 0} \517 12,1 $inner.stickradius -fill x -columnspan 4 -pady {1 0} \518 519 blt::table configure $inner c0 -resize expand -width 2520 blt::table configure $inner c1 c2 -resize none521 blt::table configure $inner c3 -resize expand522 blt::table configure $inner r* -resize none523 blt::table configure $inner r13 -resize expand524 }525 526 401 # ---------------------------------------------------------------------- 527 402 # DESTRUCTOR … … 532 407 image delete $_image(plot) 533 408 array unset _settings $this-* 409 } 410 411 412 # ---------------------------------------------------------------------- 413 # USAGE: add <dataobj> ?<settings>? 414 # 415 # Clients use this to add a data object to the plot. The optional 416 # <settings> are used to configure the plot. Allowed settings are 417 # -color, -brightness, -width, -linestyle, and -raise. Only 418 # -brightness and -raise do anything. 419 # ---------------------------------------------------------------------- 420 itcl::body Rappture::MolvisViewer::add { dataobj {options ""}} { 421 array set params { 422 -color auto 423 -brightness 0 424 -width 1 425 -raise 0 426 -linestyle solid 427 -description "" 428 -param "" 429 } 430 431 foreach {opt val} $options { 432 if {![info exists params($opt)]} { 433 error "bad settings \"$opt\": should be [join [lsort [array names params]] {, }]" 434 } 435 set params($opt) $val 436 } 437 438 set pos [lsearch -exact $dataobj $_dlist] 439 440 if {$pos < 0} { 441 if {![Rappture::library isvalid $dataobj]} { 442 error "bad value \"$dataobj\": should be Rappture::library object" 443 } 444 445 if { !$_settings($this-showlabels-initialized) } { 446 set showlabels [$dataobj get components.molecule.about.emblems] 447 if { $showlabels != "" && [string is boolean $showlabels] } { 448 set _settings($this-showlabels) $showlabels 449 } 450 } 451 452 lappend _dlist $dataobj 453 if { $params(-brightness) >= 0.5 } { 454 set _dobj2transparency($dataobj) "ghost" 455 } else { 456 set _dobj2transparency($dataobj) "normal" 457 } 458 set _dobj2raise($dataobj) $params(-raise) 459 debug "setting parameters for $dataobj\n" 460 461 if { [isconnected] } { 462 $_dispatcher event -idle !rebuild 463 } 464 } 465 } 466 467 # ---------------------------------------------------------------------- 468 # USAGE: delete ?<dataobj> <dataobj> ...? 469 # 470 # Clients use this to delete a dataobj from the plot. If no dataobjs 471 # are specified, then all dataobjs are deleted. 472 # ---------------------------------------------------------------------- 473 itcl::body Rappture::MolvisViewer::delete { args } { 474 if {[llength $args] == 0} { 475 set args $_dlist 476 } 477 478 # delete all specified dataobjs 479 set changed 0 480 set _flush 1 481 foreach dataobj $args { 482 set pos [lsearch -exact $_dlist $dataobj] 483 if {$pos >= 0} { 484 set _dlist [lreplace $_dlist $pos $pos] 485 if { [info exists _obj2models($dataobj)] } { 486 foreach model $_obj2models($dataobj) { 487 array unset _active $model 488 } 489 } 490 array unset _obj2models $dataobj 491 array unset _dobj2transparency $dataobj 492 array unset _dobj2color $dataobj 493 array unset _dobj2width $dataobj 494 array unset _dobj2dashes $dataobj 495 array unset _dobj2raise $dataobj 496 set changed 1 497 } 498 } 499 500 # if anything changed, then rebuild the plot 501 if {$changed} { 502 if { [isconnected] } { 503 $_dispatcher event -idle !rebuild 504 } 505 } 506 } 507 508 # ---------------------------------------------------------------------- 509 # USAGE: get 510 # 511 # Clients use this to query the list of objects being plotted, in 512 # order from bottom to top of this result. 513 # ---------------------------------------------------------------------- 514 itcl::body Rappture::MolvisViewer::get {} { 515 # put the dataobj list in order according to -raise options 516 set dlist $_dlist 517 foreach obj $dlist { 518 if {[info exists _dobj2raise($obj)] && $_dobj2raise($obj)} { 519 set i [lsearch -exact $dlist $obj] 520 if {$i >= 0} { 521 set dlist [lreplace $dlist $i $i] 522 lappend dlist $obj 523 } 524 } 525 } 526 return $dlist 534 527 } 535 528 … … 608 601 return 0 609 602 } 610 set _res tore1603 set _reset 1 611 604 set result [VisViewer::Connect $hosts] 612 605 if { $result } { … … 707 700 708 701 702 itcl::body Rappture::MolvisViewer::BuildSettingsTab {} { 703 set fg [option get $itk_component(hull) font Font] 704 705 set inner [$itk_component(main) insert end \ 706 -title "Settings" \ 707 -icon [Rappture::icon wrench]] 708 $inner configure -borderwidth 4 709 710 label $inner.drawinglabel -text "Molecule Representation" \ 711 -font "Arial 9 bold" 712 713 label $inner.pict -image $_settings($this-modelimg) 714 715 radiobutton $inner.bstick -text "balls and sticks" \ 716 -command [itcl::code $this Representation ballnstick all] \ 717 -variable Rappture::MolvisViewer::_settings($this-model) \ 718 -value ballnstick -font "Arial 9" -pady 0 719 Rappture::Tooltip::for $inner.bstick \ 720 "Display atoms (balls) and connections (sticks) " 721 722 radiobutton $inner.spheres -text "spheres" \ 723 -command [itcl::code $this Representation spheres all] \ 724 -variable Rappture::MolvisViewer::_settings($this-model) \ 725 -value spheres -font "Arial 9" -pady 0 726 Rappture::Tooltip::for $inner.spheres \ 727 "Display atoms as spheres. Do not display bonds." 728 729 radiobutton $inner.sticks -text "sticks" \ 730 -command [itcl::code $this Representation sticks all] \ 731 -variable Rappture::MolvisViewer::_settings($this-model) \ 732 -value sticks -font "Arial 9" -pady 0 733 Rappture::Tooltip::for $inner.sticks \ 734 "Display bonds as sticks. Do not display atoms." 735 736 radiobutton $inner.lines -text "lines" \ 737 -command [itcl::code $this Representation lines all] \ 738 -variable [itcl::scope _settings($this-model)] \ 739 -value lines -font "Arial 9" -pady 0 740 Rappture::Tooltip::for $inner.lines \ 741 "Display bonds as lines. Do not display atoms." 742 743 radiobutton $inner.cartoon -text "cartoon" \ 744 -command [itcl::code $this Representation cartoon all] \ 745 -variable [itcl::scope _settings($this-model)] \ 746 -value cartoon -font "Arial 9" -pady 0 747 Rappture::Tooltip::for $inner.cartoon \ 748 "Display cartoon representation of bonds (sticks)." 749 750 scale $inner.spherescale -width 10 -font "Arial 9 bold" \ 751 -from 0.1 -to 2.0 -resolution 0.05 -label "Sphere Scale" \ 752 -showvalue true -orient horizontal \ 753 -command [itcl::code $this SphereScale] \ 754 -variable Rappture::MolvisViewer::_settings($this-spherescale) 755 $inner.spherescale set $_settings($this-spherescale) 756 Rappture::Tooltip::for $inner.spherescale \ 757 "Adjust scale of atoms (spheres or balls). 1.0 is the full VDW radius." 758 759 scale $inner.stickradius -width 10 -font "Arial 9 bold" \ 760 -from 0.1 -to 1.0 -resolution 0.025 -label "Stick Radius" \ 761 -showvalue true -orient horizontal \ 762 -command [itcl::code $this StickRadius] \ 763 -variable Rappture::MolvisViewer::_settings($this-stickradius) 764 Rappture::Tooltip::for $inner.stickradius \ 765 "Adjust scale of bonds (sticks)." 766 $inner.stickradius set $_settings($this-stickradius) 767 768 checkbutton $inner.labels -text "Show labels on atoms" \ 769 -command [itcl::code $this labels update] \ 770 -variable [itcl::scope _settings($this-showlabels)] \ 771 -font "Arial 9 bold" 772 Rappture::Tooltip::for $inner.labels \ 773 "Display atom symbol and serial number." 774 775 checkbutton $inner.rock -text "Rock model back and forth" \ 776 -command [itcl::code $this Rock toggle] \ 777 -variable Rappture::MolvisViewer::_settings($this-rock) \ 778 -font "Arial 9 bold" 779 Rappture::Tooltip::for $inner.rock \ 780 "Rotate the object back and forth around the y-axis." 781 782 checkbutton $inner.ortho -text "Orthoscopic projection" \ 783 -command [itcl::code $this OrthoProjection update] \ 784 -variable Rappture::MolvisViewer::_settings($this-ortho) \ 785 -font "Arial 9 bold" 786 Rappture::Tooltip::for $inner.ortho \ 787 "Toggle between orthoscopic/perspective projection modes." 788 789 checkbutton $inner.cartoontrace -text "Cartoon Trace" \ 790 -command [itcl::code $this CartoonTrace update] \ 791 -variable [itcl::scope _settings($this-cartoontrace)] \ 792 -font "Arial 9 bold" 793 Rappture::Tooltip::for $inner.cartoontrace \ 794 "Set cartoon representation of bonds (sticks)." 795 796 checkbutton $inner.cell -text "Parallelepiped" \ 797 -command [itcl::code $this Cell toggle] \ 798 -font "Arial 9 bold" 799 $inner.cell select 800 801 label $inner.spacer 802 blt::table $inner \ 803 0,0 $inner.drawinglabel -anchor w -columnspan 4 \ 804 1,1 $inner.pict -anchor w -rowspan 5 \ 805 1,2 $inner.bstick -anchor w -columnspan 2 \ 806 2,2 $inner.spheres -anchor w -columnspan 2 \ 807 3,2 $inner.sticks -anchor w -columnspan 2 \ 808 4,2 $inner.lines -anchor w -columnspan 2 \ 809 5,2 $inner.cartoon -anchor w -columnspan 2 \ 810 6,0 $inner.labels -anchor w -columnspan 4 -pady {1 0} \ 811 7,0 $inner.rock -anchor w -columnspan 4 -pady {1 0} \ 812 8,0 $inner.ortho -anchor w -columnspan 4 -pady {1 0} \ 813 9,0 $inner.cartoontrace -anchor w -columnspan 4 -pady {1 0} \ 814 10,0 $inner.cell -anchor w -columnspan 4 -pady {1 0} \ 815 11,1 $inner.spherescale -fill x -columnspan 4 -pady {1 0} \ 816 12,1 $inner.stickradius -fill x -columnspan 4 -pady {1 0} \ 817 818 blt::table configure $inner c0 -resize expand -width 2 819 blt::table configure $inner c1 c2 -resize none 820 blt::table configure $inner c3 -resize expand 821 blt::table configure $inner r* -resize none 822 blt::table configure $inner r13 -resize expand 823 } 824 709 825 # ---------------------------------------------------------------------- 710 826 # USAGE: Rebuild … … 725 841 set _cell 0 726 842 727 if { $_res tore} {843 if { $_reset } { 728 844 set _rocker(server) 0 729 845 set _cacheid 0 … … 933 1049 set flush 0 934 1050 } 935 if { $_res tore} {1051 if { $_reset } { 936 1052 # Set or restore viewing parameters. We do this for the first 937 1053 # model and assume this works for everything else. … … 948 1064 949 1065 SendCmd "raw -defer {zoom complete=1}" 950 set _res tore01066 set _reset 0 951 1067 } 952 1068 if { $changed } { … … 967 1083 $inner.cell configure -state disabled 968 1084 } 969 if { $ flush } {1085 if { $_flush || $flush } { 970 1086 global readyForNextFrame 971 1087 set readyForNextFrame 0; # Don't advance to the next frame 972 1088 # until we get an image. 973 1089 SendCmd "ppm"; # Flush the results. 1090 set _flush 0 974 1091 } 975 1092 set _buffering 0; # Turn off buffering. … … 1461 1578 1462 1579 1463 # ----------------------------------------------------------------------1464 # USAGE: add <dataobj> ?<settings>?1465 #1466 # Clients use this to add a data object to the plot. The optional1467 # <settings> are used to configure the plot. Allowed settings are1468 # -color, -brightness, -width, -linestyle, and -raise. Only1469 # -brightness and -raise do anything.1470 # ----------------------------------------------------------------------1471 itcl::body Rappture::MolvisViewer::add { dataobj {options ""}} {1472 array set params {1473 -color auto1474 -brightness 01475 -width 11476 -raise 01477 -linestyle solid1478 -description ""1479 -param ""1480 }1481 1482 foreach {opt val} $options {1483 if {![info exists params($opt)]} {1484 error "bad settings \"$opt\": should be [join [lsort [array names params]] {, }]"1485 }1486 set params($opt) $val1487 }1488 1489 set pos [lsearch -exact $dataobj $_dlist]1490 1491 if {$pos < 0} {1492 if {![Rappture::library isvalid $dataobj]} {1493 error "bad value \"$dataobj\": should be Rappture::library object"1494 }1495 1496 if { !$_settings($this-showlabels-initialized) } {1497 set showlabels [$dataobj get components.molecule.about.emblems]1498 if { $showlabels != "" && [string is boolean $showlabels] } {1499 set _settings($this-showlabels) $showlabels1500 }1501 }1502 1503 lappend _dlist $dataobj1504 if { $params(-brightness) >= 0.5 } {1505 set _dobj2transparency($dataobj) "ghost"1506 } else {1507 set _dobj2transparency($dataobj) "normal"1508 }1509 set _dobj2raise($dataobj) $params(-raise)1510 debug "setting parameters for $dataobj\n"1511 1512 if { [isconnected] } {1513 $_dispatcher event -idle !rebuild1514 }1515 }1516 }1517 1518 1580 # 1519 1581 # ResetView … … 1541 1603 SendCmd "zoom $_view(zoom)" 1542 1604 } 1543 1544 # ----------------------------------------------------------------------1545 # USAGE: get1546 #1547 # Clients use this to query the list of objects being plotted, in1548 # order from bottom to top of this result.1549 # ----------------------------------------------------------------------1550 itcl::body Rappture::MolvisViewer::get {} {1551 # put the dataobj list in order according to -raise options1552 set dlist $_dlist1553 foreach obj $dlist {1554 if {[info exists _dobj2raise($obj)] && $_dobj2raise($obj)} {1555 set i [lsearch -exact $dlist $obj]1556 if {$i >= 0} {1557 set dlist [lreplace $dlist $i $i]1558 lappend dlist $obj1559 }1560 }1561 }1562 return $dlist1563 }1564 1565 # ----------------------------------------------------------------------1566 # USAGE: delete ?<dataobj> <dataobj> ...?1567 #1568 # Clients use this to delete a dataobj from the plot. If no dataobjs1569 # are specified, then all dataobjs are deleted.1570 # ----------------------------------------------------------------------1571 itcl::body Rappture::MolvisViewer::delete { args } {1572 if {[llength $args] == 0} {1573 set args $_dlist1574 }1575 1576 # delete all specified dataobjs1577 set changed 01578 foreach dataobj $args {1579 set pos [lsearch -exact $_dlist $dataobj]1580 if {$pos >= 0} {1581 set _dlist [lreplace $_dlist $pos $pos]1582 if { [info exists _obj2models($dataobj)] } {1583 foreach model $_obj2models($dataobj) {1584 array unset _active $model1585 }1586 }1587 array unset _obj2models $dataobj1588 array unset _dobj2transparency $dataobj1589 array unset _dobj2color $dataobj1590 array unset _dobj2width $dataobj1591 array unset _dobj2dashes $dataobj1592 array unset _dobj2raise $dataobj1593 set changed 11594 }1595 }1596 1597 # if anything changed, then rebuild the plot1598 if {$changed} {1599 if { [isconnected] } {1600 $_dispatcher event -idle !rebuild1601 }1602 }1603 }1604 1605 # ----------------------------------------------------------------------1606 # OPTION: -device1607 # ----------------------------------------------------------------------1608 itcl::configbody Rappture::MolvisViewer::device {1609 if {$itk_option(-device) != "" } {1610 1611 if {![Rappture::library isvalid $itk_option(-device)]} {1612 error "bad value \"$itk_option(-device)\": should be Rappture::library object"1613 }1614 $this delete1615 $this add $itk_option(-device)1616 } else {1617 $this delete1618 }1619 1620 if { [isconnected] } {1621 $_dispatcher event -idle !rebuild1622 }1623 }1624 1625 1605 1626 1606 … … 2096 2076 return $vertices 2097 2077 } 2078 2079 2080 # ---------------------------------------------------------------------- 2081 # OPTION: -device 2082 # ---------------------------------------------------------------------- 2083 itcl::configbody Rappture::MolvisViewer::device { 2084 if {$itk_option(-device) != "" } { 2085 2086 if {![Rappture::library isvalid $itk_option(-device)]} { 2087 error "bad value \"$itk_option(-device)\": should be Rappture::library object" 2088 } 2089 $this delete 2090 $this add $itk_option(-device) 2091 } else { 2092 $this delete 2093 } 2094 2095 if { [isconnected] } { 2096 $_dispatcher event -idle !rebuild 2097 } 2098 } 2099
Note: See TracChangeset
for help on using the changeset viewer.