global num_atts
proc swapItems {node nextPosition} {
global order_tree
set rootNode [$order_tree getRootNode]
set nodeLabel [$node getLabelText]
set nextNode [$rootNode getChildAt $nextPosition]
$node setLabel [$nextNode getLabelText]
$nextNode setLabel $nodeLabel
$order_tree addSelectedNode $nextNode
}
proc sortNodes { } {
global order_tree
set rootNode [$order_tree getRootNode]
for { set jdx 0} {$jdx < [$order_tree getSelectionCount]} {incr jdx} {
set node [$order_tree getSelectedNodes $jdx]
set nextPosition [$rootNode getChildIndex [$node getObject]]
if { [string match $nextPosition ""] } {
$order_tree removeSelectedNode $node
}
}
set sortedIndexes {}
while { [$order_tree getSelectionCount] > 0 } {
set min_val 99999
set minNode 0
for { set jdx 0} {$jdx < [$order_tree getSelectionCount]} {incr jdx} {
set node [$order_tree getSelectedNodes $jdx]
set nextPosition [$rootNode getChildIndex [$node getObject]]
if { $nextPosition < $min_val } {
set minNode $node
set min_val $nextPosition
}
}
$order_tree removeSelectedNode $minNode
lappend sortedIndexes $minNode
}
return $sortedIndexes
}
proc moveToBot { } {
global order_tree
set sortedIndexes [sortNodes]
set rootNode [$order_tree getRootNode]
set idx [llength $sortedIndexes]
incr idx -1
set nextPosition [$rootNode getChildCount]
incr nextPosition -1
for {} {$idx >= 0} {incr idx -1} {
set node [lindex $sortedIndexes $idx]
set selectedIndex [$rootNode getChildIndex [$node getObject]]
set nodeLabel [$node getLabelText]
for {set jdx $selectedIndex} {$jdx < $nextPosition} {incr jdx} {
set nextPos [expr $jdx+1]
swapItems [$rootNode getChildAt $nextPos] $jdx
}
set node [$rootNode getChildAt $nextPosition]
$node setLabel $nodeLabel
incr nextPosition -1
}
$order_tree removeAllSelections
}
proc moveDown { } {
global order_tree
set rootNode [$order_tree getRootNode]
set childCount [$rootNode getChildCount]
set sortedIndexes [sortNodes]
set idx [llength $sortedIndexes]
incr idx -1
for {} {$idx >= 0} {incr idx -1} {
set node [lindex $sortedIndexes $idx]
set nextPosition [$rootNode getChildIndex [$node getObject]]
incr nextPosition
if { $nextPosition < $childCount } {
swapItems $node $nextPosition
} else {
break
}
}
}
proc moveUp { } {
global order_tree
set rootNode [$order_tree getRootNode]
set selectedCount [$order_tree getSelectionCount]
set sortedIndexes [sortNodes]
for { set idx 0} {$idx < [llength $sortedIndexes]} {incr idx} {
set node [lindex $sortedIndexes $idx]
set nextPosition [$rootNode getChildIndex [$node getObject]]
incr nextPosition -1
if {$nextPosition >= 0} {
swapItems $node $nextPosition
} else {
break
}
}
}
proc moveToTop { } {
global order_tree
set rootNode [$order_tree getRootNode]
set sortedIndexes [sortNodes]
set nextPosition 0
set selectedCount [llength $sortedIndexes]
for { set idx 0} {$idx < $selectedCount} {incr idx} {
set node [lindex $sortedIndexes $idx]
set selectedIndex [$rootNode getChildIndex [$node getObject]]
set nodeLabel [$node getLabelText]
for {set jdx $selectedIndex} {$jdx > $idx} {incr jdx -1} {
set nextPosition [expr $jdx-1]
swapItems [$rootNode getChildAt $nextPosition] $jdx
}
set node [$rootNode getChildAt $idx]
$node setLabel $nodeLabel
}
$order_tree removeAllSelections
}
proc sortAlpha { order } {
global order_tree
set rootNode [$order_tree getRootNode]
set buffer [ GuidoExecServer GetAttributeValueList {} ]
set num_atts [ GuidoGetParamBufferValue $buffer attributeNumber ]
if { $num_atts > 0} {
set attributeList [ GuidoGetParamBufferValue $buffer attribute ]
set sorted [lsort $order $attributeList]
for {set i 0} {$i < $num_atts} {incr i} {
set node [$rootNode getChildAt $i]
$node setLabel [lindex $sorted $i]
}
}
}
proc sortType { order } {
global order_tree
set rootNode [$order_tree getRootNode]
set buffer [ GuidoExecServer GetAttributeValueList {} ]
set num_atts [ GuidoGetParamBufferValue $buffer attributeNumber ]
if { $num_atts > 0} {
set attributeList [ GuidoGetParamBufferValue $buffer attribute ]
set attributeFormatList [ GuidoGetParamBufferValue $buffer attributeFormat ]
set charList { }
for {set i 0} {$i < $num_atts} {incr i} {
set value "[lindex $attributeFormatList $i]+[lindex $attributeList $i]"
lappend charList $value
}
set sorted [lsort $order $charList]
for {set i 0} {$i < $num_atts} {incr i} {
set node [$rootNode getChildAt $i]
set value [lindex $sorted $i]
$node setLabel [lindex [split $value +] 1]
}
}
}
proc loadTree { formHandle } {
global dummy_branch
global order_tree
set rootNode [$order_tree getRootNode]
set buffer [ GuidoExecServer GetAttributeValueList {} ]
set num_atts [ GuidoGetParamBufferValue $buffer attributeNumber ]
if { $num_atts > 0} {
set attributeList [ GuidoGetParamBufferValue $buffer attribute ]
set attributeFormatList [ GuidoGetParamBufferValue $buffer attributeFormat ]
for {set i 0} {$i < $num_atts } {incr i} {
GuidoTreeLeaf atts$i {
-label [lindex $attributeList $i]
}
upvar 0 atts$i att
$rootNode addChild $att
}
}
$rootNode removeChild $dummy_branch
$formHandle updateFieldList
}
GuidoForm AttribOrder {
-default_buttons
-label "Order Attributes"
-help_id 1063
-action initial {[loadTree $AttribOrder]}
-layout BoxLayout Y_AXIS
GuidoPanel typePanel {
-layout CentrelineLayout
GuidoComboBox orderingType {
-label "Ordering"
-value_in "Alphabetical" "User Defined"
-exclusive true
-null false
-default "User Defined"
}
}
GuidoFiller space {
-height 0.5
}
GuidoPanel userPanel {
-dependency { "[$orderingType getCurrentValue]" == "User Defined" }
-layout BoxLayout X_AXIS
GuidoPanel mainPanel {
-layout BoxLayout Y_AXIS
GuidoPanel mainButts {
-layout BoxLayout X_AXIS
GuidoButton sortAlpha {
-icon "icons/16/sort_asc.png"
-action valueChanged {[sortAlpha "-increasing"]}
-tip "sort alphabetically"
}
GuidoButton sortAlphaReverse {
-icon "icons/16/sort_desc.png"
-action valueChanged {[sortAlpha "-decreasing"]}
-tip "sort reverse alphabetically"
}
GuidoFiller space {
-width 1
}
GuidoButton sortType {
-icon "icons/16/sort_group_desc.png"
-action valueChanged {[sortType "-increasing"]}
-tip "sort by type"
}
GuidoButton sortTypeReverse {
-icon "icons/16/sort_group_asc.png"
-action valueChanged {[sortType "-decreasing"]}
-tip "sort reverse by type"
}
}
GuidoScrollPane sp {
-height 17
-width 20
GuidoTree order_tree {
-label "Model Attributes"
GuidoTreeBranch dummy_branch {
-menu_enabled false
}
}
$order_tree setTreeIcons "icons/abort.gif" "icons/GraphicsStreamingIdle.gif" "icons/GraphicsStreamingIdle.gif"
}
}
GuidoPanel ButtonPanel {
-layout BoxLayout Y_AXIS
GuidoFiller space {
-height 3
}
GuidoButton moveTop {
-action valueChanged {[moveToTop]}
-tip "Move selected to top"
}
GuidoButton moveUp {
-icon "icons/16/up_arrow.png"
-action valueChanged {[moveUp]}
-tip "Move selected up"
}
GuidoButton moveDown {
-icon "icons/16/down_arrow.png"
-action valueChanged {[moveDown]}
-tip "Move selected down"
}
GuidoButton moveBot {
-action valueChanged {[moveToBot]}
-tip "Move selected to bottom"
}
}
}
}
GuidoApp check_bm "CHECK BM CONNECTED"
$check_bm setParam functionName "BM REORDER ATTRIBUTES"
set result [$check_bm invoke]
$check_bm destroy
if {$result == "0"} {
set formStatus [$AttribOrder interact]
GuidoApp appHandle "BM REORDER ATTRIBUTES"
$appHandle setParam orderType [$orderingType getCurrentValue]
if { [string match [$orderingType getCurrentValue] "User Defined"] } {
set rootNode [$order_tree getRootNode]
set numAtts [$rootNode getChildCount]
$appHandle setParam numAttNames $numAtts
for { set idx 0 } { $idx < $numAtts } {incr idx} {
set childNode [$rootNode getChildAt $idx]
$appHandle setParam att($idx) [$childNode getLabelText]
}
}
$AttribOrder destroy
if {$formStatus == "apply"} {
set appStatus [$appHandle invoke]
}
$appHandle destroy
}
