Changeset 379


Ignore:
Timestamp:
Dec 4, 2009 5:05:11 PM (11 years ago)
Author:
toby
Message:

# on 2001/04/16 21:25:33, toby did:
Add atom sort feature

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/addcmds.tcl

    • Property rcs:date changed from 2001/04/03 19:16:41 to 2001/04/16 21:25:33
    • Property rcs:lines changed from +68 -4 to +67 -7
    • Property rcs:rev changed from 1.17 to 1.18
    r378 r379  
    772772    set row 0
    773773    set col 0
    774     foreach i {Atom\ntype Name x y z Occ Uiso Use} {
    775         grid [label $np.l_${row}$i -text $i] -column [incr col] -row $row
    776     }
     774    grid [label $np.l_${row}0 -text "  #  "] -column $col -row $row
     775    foreach i {Atom\ntype Name x y z Occ Uiso} \
     776            var {type name x y z occ uiso} {
     777        grid [button $np.l_${row}$i -text $i -padx 0 -pady 0 \
     778                -command "sortAddAtoms $phase $top $var"] \
     779                -column [incr col] -row $row -sticky nsew
     780    }
     781    grid [label $np.l_${row}Use -text Use\nFlag] -column [incr col] -row $row
    777782
    778783    set expgui(SetAddAtomsScroll) 0
     
    809814                -column 3 -row 5 -columnspan 2 -sticky e
    810815        grid [button $top.fr.b3 -text "Import atoms from: " \
    811                 -command "ImportAtoms \$expgui(importFormat) $top"] \
     816                -command "ImportAtoms \$expgui(importFormat) $top $phase"] \
    812817                -column 0 -row 0 -sticky e
    813818        eval tk_optionMenu $top.fr.b4 expgui(importFormat) \
     
    12511256}
    12521257
    1253 proc ImportAtoms {format top} {
     1258proc ImportAtoms {format top phase} {
    12541259    global expgui
    12551260    foreach item $expgui(extensions_$format) {
     
    12721277        }
    12731278    }
     1279    # sort the atoms by number, so that empty entries are at the bottom
     1280    sortAddAtoms $phase $top number
    12741281}
    12751282
     
    14841491    set row 0
    14851492    set col 0
    1486     foreach i {Atom\ntype Name x y z Occ Uiso Use} {
    1487         grid [label $np.l_${row}$i -text $i] -column [incr col] -row $row
    1488     }
     1493    grid [label $np.l_${row}0 -text "  #  "] -column $col -row $row
     1494    foreach i {Atom\ntype Name x y z Occ Uiso} \
     1495            var {type name x y z occ uiso} {
     1496        grid [button $np.l_${row}$i -text $i -padx 0 -pady 0 \
     1497                -command "sortAddAtoms $phase $top $var"] \
     1498                -column [incr col] -row $row -sticky nsew
     1499    }
     1500    grid [label $np.l_${row}Use -text Use\nFlag] -column [incr col] -row $row
    14891501
    14901502    # add the old atoms, if appropriate
     
    15351547                -column 3 -row 5 -columnspan 2 -sticky e
    15361548        grid [button $top.fr.b3 -text "Import atoms from: " \
    1537                 -command "ImportAtoms \$expgui(importFormat) $top"] \
     1549                -command "ImportAtoms \$expgui(importFormat) $top $phase"] \
    15381550                -column 0 -row 0 -sticky e
    15391551        eval tk_optionMenu $top.fr.b4 expgui(importFormat) \
     
    16891701}
    16901702
     1703proc sortAddAtoms {phase top sortvar} {
     1704    global expgui
     1705    set np $top.canvas.fr
     1706    set validlist {}
     1707    set invalidlist {}
     1708    set row 0
     1709    while {![catch {grid info $np.e[incr row]t}]} {
     1710        set valid 1
     1711        set line $row
     1712        if !{$expgui(UseAtom$row)} {set valid 0}
     1713        lappend line $expgui(UseAtom$row)
     1714        if {[set type [string trim [$np.e${row}t get]]] == ""} {set valid 0}
     1715        lappend line [string trim [$np.e${row}t get]]
     1716        lappend line [string trim [$np.e${row}n get]]
     1717        foreach i {x y z o u} {
     1718            set tmp [string trim [$np.e${row}$i get]]
     1719            lappend line $tmp
     1720            if {$tmp == "" || [catch {expr $tmp}]} {set valid 0}
     1721        }
     1722        if {$valid} {
     1723            lappend validlist $line
     1724        } else {
     1725            lappend invalidlist $line
     1726        }
     1727    }
     1728    switch $sortvar {
     1729        type {set sortlist [lsort -index 2 -dictionary $validlist]}
     1730        name {set sortlist [lsort -index 3 -dictionary $validlist]}
     1731        x {set sortlist [lsort -index 4 -real $validlist]}
     1732        y {set sortlist [lsort -index 5 -real $validlist]}
     1733        z {set sortlist [lsort -index 6 -real $validlist]}
     1734        occ {set sortlist [lsort -index 7 -real $validlist]}
     1735        uiso  {set sortlist [lsort -index 8 -real $validlist]}
     1736        default {set sortlist $validlist}
     1737    }
     1738
     1739    if {[llength $invalidlist] > 0} {append sortlist " $invalidlist"}
     1740    set row 0
     1741    foreach line $sortlist {
     1742        incr row
     1743        set expgui(UseAtom$row) [lindex $line 1]
     1744        foreach item [lrange $line 2 end] \
     1745                var {t n x y z o u} {
     1746            $np.e${row}$var delete 0 end
     1747            $np.e${row}$var insert end $item
     1748        }
     1749    }
     1750}
Note: See TracChangeset for help on using the changeset viewer.