Changeset 179 for trunk/addcmds.tcl
- Timestamp:
- Dec 4, 2009 5:01:43 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/addcmds.tcl
- Property rcs:date changed from 2000/05/26 22:55:32 to 2000/06/01 02:46:47
- Property rcs:lines changed from +7 -3 to +128 -56
- Property rcs:rev changed from 1.5 to 1.6
r167 r179 633 633 global expmap 634 634 635 # is there room for more atoms? Well, we will check this later635 # is there room for more atoms? Well, we will check this someday 636 636 if {$phase == ""} return 637 637 if {[llength $phase] != 1} return 638 638 639 set np .newatoms 640 catch {destroy $np} 641 toplevel $np 642 643 grid [label $np.l1 -text "Adding atoms to phase #$phase"] \ 644 -column 0 -row 0 -sticky w -columnspan 10 645 # grid [label $np.l2 -text "Phase title:"] -column 0 -row 1 639 set top .newatoms 640 catch {destroy $top} 641 toplevel $top 642 643 grid [label $top.l1 -relief groove -bd 4 -anchor center\ 644 -text "Adding atoms to phase #$phase"] \ 645 -column 0 -row 0 \ 646 -sticky we -columnspan 10 647 # grid [label $top.l2 -text "Phase title:"] -column 0 -row 1 648 649 grid [canvas $top.canvas \ 650 -scrollregion {0 0 5000 500} -width 0 -height 250 \ 651 -yscrollcommand "$top.scroll set"] \ 652 -column 0 -row 2 -columnspan 4 -sticky nsew 653 grid columnconfigure $top 3 -weight 1 654 grid rowconfigure $top 2 -weight 1 655 grid rowconfigure $top 1 -pad 5 656 scrollbar $top.scroll \ 657 -command "$top.canvas yview" 658 frame $top.canvas.fr 659 $top.canvas create window 0 0 -anchor nw -window $top.canvas.fr 660 661 set np $top.canvas.fr 662 set row 0 663 set col 0 664 foreach i {Atom\ntype Name x y z Occ Uiso Use} { 665 grid [label $np.l_${row}$i -text $i] -column [incr col] -row $row 666 } 667 668 global expgui 669 set expgui(SetAddAtomsScroll) 0 670 MakeAddAtomsRow $top 671 bind $top <Configure> "SetAddAtomsScroll $top" 672 673 grid rowconfigure .newatoms 3 -min 10 674 grid [button $top.b1 -text "Add Atoms"\ 675 -command "addatom $phase $top"] -column 0 -row 4 -sticky w 676 bind $top <Return> "addatom $phase $top" 677 grid [button $top.b2 -text Cancel \ 678 -command "destroy $top"] -column 1 -row 4 -sticky w 679 680 grid [button $top.b3 -text "More atoms" \ 681 -command "MakeAddAtomsRow $top"] -column 3 \ 682 -columnspan 2 -row 4 -sticky e 683 684 wm title $top "add new atom" 685 686 # grab focus, etc. 687 putontop $top 688 689 tkwait window $top 690 691 # fix focus... 692 afterputontop 693 } 694 695 proc MakeAddAtomsRow {top} { 696 set np $top.canvas.fr 697 set col -1 646 698 set row 1 647 set col -1 648 foreach i {Atom\ntype Name x y z Occ Uiso} { 649 grid [label $np.l_${row}$i -text $i] -column [incr col] -row $row 650 } 651 652 set row 2 653 set col -1 699 # find an empty row 700 while {![catch {grid info $np.e${row}t}]} {incr row} 701 grid [label $np.e${row}num -text $row] -column [incr col] -row $row 654 702 grid [entry $np.e${row}t -width 5] -column [incr col] -row $row 655 703 grid [entry $np.e${row}n -width 8] -column [incr col] -row $row 656 704 foreach i {x y z o u} { 657 grid [entry $np.e${row}$i -width 12] -column [incr col] -row $row 658 } 705 grid [entry $np.e${row}$i -width 9] -column [incr col] -row $row 706 } 707 grid [checkbutton $np.e${row}use -variable expgui(UseAtom$row)] \ 708 -column [incr col] -row $row 659 709 # default occupancy 660 710 $np.e${row}o delete 0 end … … 666 716 $np.e${row}n delete 0 end 667 717 $np.e${row}n insert end (default) 668 669 grid [button $np.b1 -text Add \ 670 -command "addatom $phase $np"] -column 2 -row 3 671 bind $np <Return> "addatom $phase $np" 672 grid [button $np.b2 -text Cancel \ 673 -command "destroy $np"] -column 3 -row 3 674 675 wm title $np "add new atom" 676 677 # grab focus, etc. 678 putontop $np 679 680 tkwait window $np 681 682 # fix focus... 683 afterputontop 684 } 685 686 proc addatom {phase np} { 718 # use by default 719 $np.e${row}use select 720 721 SetAddAtomsScroll $top 722 } 723 724 proc SetAddAtomsScroll {top} { 725 global expgui 726 if $expgui(SetAddAtomsScroll) return 727 # prevent reentrance 728 set expgui(SetAddAtomsScroll) 1 729 update 730 set sizes [grid bbox $top.canvas.fr] 731 $top.canvas config -scrollregion $sizes -width [lindex $sizes 2] 732 # use the scroll for BIG atom lists 733 if {[lindex $sizes 3] > [winfo height $top.canvas]} { 734 grid $top.scroll -sticky ns -column 4 -row 2 735 } else { 736 grid forget $top.scroll 737 } 738 update 739 set expgui(SetAddAtomsScroll) 0 740 } 741 742 proc addatom {phase top} { 687 743 global expgui env 688 # validate the input 744 set np $top.canvas.fr 745 set row 0 746 # loop over the defined rows 689 747 set err {} 690 set row 2 691 if {[set type [string trim [$np.e${row}t get]]] == ""} { 692 append err " No atom type specified\n" 693 } 694 695 set name [string trim [$np.e${row}n get]] 696 if {$name == "(default)"} {set name "/"} 697 if {$name == ""} {set name "/"} 698 699 foreach i {x y z o u} n {x y z Occ Uiso} { 700 if {[set $i [string trim [$np.e${row}$i get]]] == ""} { 701 append err " No value specified for $n\n" 702 } elseif {[catch {expr [set $i]}]} { 703 append err " The value for $n is invalid\n" 704 } 705 } 706 748 set atomlist {} 749 while {![catch {grid info $np.e[incr row]t}]} { 750 if !{$expgui(UseAtom$row)} continue 751 puts "Use $row" 752 # ignore blank entries 753 set line {} 754 foreach i {t x y z} { 755 append line [string trim [$np.e${row}$i get]] 756 } 757 if {$line == ""} continue 758 puts "not blank $row" 759 # validate the input 760 if {[set type [string trim [$np.e${row}t get]]] == ""} { 761 append err " line $row: No atom type specified\n" 762 } 763 set name [string trim [$np.e${row}n get]] 764 if {$name == "(default)"} {set name "/"} 765 if {$name == ""} {set name "/"} 766 foreach i {x y z o u} n {x y z Occ Uiso} { 767 if {[set $i [string trim [$np.e${row}$i get]]] == ""} { 768 append err " line $row: No value specified for $n\n" 769 } elseif {[catch {expr [set $i]}]} { 770 append err " line $row: The value for $n is invalid\n" 771 } 772 } 773 lappend atomlist "$type $x $y $z $o $name I $u" 774 } 707 775 if {$err != ""} { 708 tk_dialog .phaseerr "Add Atom Error" \ 709 "The following error(s) were found in your input:\n$err" \ 710 error 0 "OK" 776 MyMessageBox -icon warning -message "Note Errors:\n$err" -parent $top 711 777 return 712 778 } 713 714 # ok do it! 779 if {[llength $atomlist] == 0} { 780 MyMessageBox -icon warning -message "No atoms to load!" -parent $top 781 return 782 } 783 # ok add the atoms! 715 784 set fp [open exptool.in w] 716 785 puts $fp "A" 717 786 puts $fp $phase 718 # for now, only one atom at a time 719 puts $fp 1 720 puts $fp "$type $x $y $z $o $name I $u" 787 # number of atoms 788 puts $fp [llength $atomlist] 789 foreach atomline $atomlist { 790 puts $fp $atomline 791 } 721 792 close $fp 722 793 # needed in UNIX … … 724 795 # needed in Windows 725 796 set env(GSAS) [file nativename $expgui(gsasdir)] 797 726 798 global tcl_platform 727 799 # Save the current exp file … … 744 816 set out [read $fp] 745 817 close $fp 746 destroy $ np818 destroy $top 747 819 if {$errmsg != ""} { 748 820 append errmsg "\n" $out … … 751 823 } 752 824 ShowBigMessage \ 753 $ np \825 $top \ 754 826 "Please review the result from adding the atom" \ 755 827 $errmsg
Note: See TracChangeset
for help on using the changeset viewer.