# $Revision$ on $Date$
# The above revision line needs to be the first line for all techtk files
# Copyright (c) 2006 Ansys Inc

#----------------------------------------------------------------------------
#
# PADT---------------------------------------------------- Phoenix Analysis &
#                                                         Design Technologies
#
#----------------------------------------------------------------------------
#
#       Package: AI-Environment GUI Management
#
#
#          File: refresher.tcl
#
#
#     Developer: Matt Sutton
#
#
#   Description: This file defines the basic routines used to refresh the
#                GUI from the tree representation.  The algorithm involves
#                a depth first traversal of the GUI tree where each node is
#                visited twice; once upon entering and once upon leaving.
#                Visiting each node in the tree at two different points in the
#                traversal allows for maximum flexability while constructing
#                the GUI.
#
#
#  Example Tree:
#                             Root
#                            /    \
#                           /      \
#                      Child_1     Child_2
#
#
#      Traversal 
#         Order: 1. enterRoot
#                2. enterChild_1
#                3. leaveChild_1
#                4. enterChild_2
#                5. leaveChild_2
#                6. leaveRoot
#
#   
#
#      03/25/02: Demo release 1. No implementation. All procedures are empty 
#                                stubs
#
#           
#           
#
#-----------------------------------------------------------------------------
# For support: 1-480-813-4884 ext. 125 -or- matt.sutton@padtinc.com
#-----------------------------------------------------------------------------

namespace eval ::AIEnv::GUIManagement {}

proc ::AIEnv::GUIManagement::SetState {w state} {
   if ![winfo exist $w] {return ""}
   switch -- [winfo class $w] {
      Button - Label - Entry - Text - Scale \
             - Checkbutton - Radiobutton - Menubutton \
             - ComboBox - LabelEntry - LabelFrame - ListBox \
             - SelectColorMenu - SpinBox - TitleFrame \
             - CheckFrame - RadioFrame - Tree {
         $w configure -state $state
      }
   }

 # it is illegal to set state for the following classes
 #    Frame - Menu - Scrollbar - Message - Listbox
 #          - NoteBook - PanedWindow
}


proc ::AIEnv::GUIManagement::ToggleGrey {Entity {GreyFlag -1}} {
    set GUITree [TreeStack peek]
    variable ItemNameMap
    if { [info exists ItemNameMap($Entity)] } {
        set NodeID $ItemNameMap($Entity)
    } else {
        Error "The specific GUI entity named \"$Entity\" does not exist."   
    }
    $GUITree walk $NodeID -order both -type dfs -command "ItemToggleGrey %n %a $GreyFlag"
    update
}

proc ::AIEnv::GUIManagement::ToggleGreyByNodeID {NodeID {GreyFlag -1} {Update 0}} {
	set GUITree [TreeStack peek]
	$GUITree walk $NodeID -order both -type dfs -command "ItemToggleGrey %n %a $GreyFlag"
    if {$Update == 1} {
    	update
    }
}

proc ::AIEnv::GUIManagement::ItemToggleGrey { NodeID Action GreyFlag } {
	set GUITree [TreeStack peek]
    set Type [$GUITree get $NodeID -key "Type"]
    set cmd ::AIEnv::GUIManagement::${Action}${Type}ToggleGrey
    if {[info command $cmd] != ""} {
       eval "$cmd $NodeID $GreyFlag"
    } else {
       eval "::AIEnv::GUIManagement::${Action}AnyToggleGrey $NodeID $GreyFlag"
    }
}

#------------------------------------------------------------------------------
#   Zone Items
#------------------------------------------------------------------------------
proc ::AIEnv::GUIManagement::enterRootToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveRootToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterTabbedIconZoneToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveTabbedIconZoneToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterIconZoneToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveIconZoneToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterMenuZoneToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveMenuZoneToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterDataEntryZoneToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveDataEntryZoneToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterDialogWindowRootToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveDialogWindowRootToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

#------------------------------------------------------------------------------
#   Menu Items
#------------------------------------------------------------------------------
proc ::AIEnv::GUIManagement::enterMenuBarToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveMenuBarToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterMenuToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue

	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]

    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        set WindowPath [$GUITree get $NodeID -key "WindowPath"]
        set Index [$GUITree get $NodeID -key "Index"]
        if { $GreyFlag == $GreyFlagOnValue } {
            $WindowPath entryconfigure $Index -state disabled   
        } else {
            $WindowPath entryconfigure $Index -state normal 
        }
        # This is a parent so push it's value onto the stack
        GreyFlagStack push $GreyFlag
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterMenuItemToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
}

proc ::AIEnv::GUIManagement::leaveMenuToggleGrey { NodeID GreyFlag } { 
    if { [GreyFlagStack size] != 0 } {
        GreyFlagStack pop
    }
}

proc ::AIEnv::GUIManagement::enterMenuItemToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue

	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]

    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        set WindowPath [$GUITree get $NodeID -key "WindowPath"]
        set Index [$GUITree get $NodeID -key "Index"]
        if { $GreyFlag == $GreyFlagOnValue } {
            $WindowPath entryconfigure $Index -state disabled   
        } else {
            $WindowPath entryconfigure $Index -state normal 
        }
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterMenuItemToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
    
}

proc ::AIEnv::GUIManagement::leaveMenuItemToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterMenuCheckToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue

	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]

    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        set WindowPath [$GUITree get $NodeID -key "WindowPath"]
        set Index [$GUITree get $NodeID -key "Index"]
        if { $GreyFlag == $GreyFlagOnValue } {
            $WindowPath entryconfigure $Index -state disabled   
        } else {
            $WindowPath entryconfigure $Index -state normal 
        }
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterMenuCheckToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
    
}

proc ::AIEnv::GUIManagement::leaveMenuCheckToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterMenuRadioToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue

	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]

    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        set WindowPath [$GUITree get $NodeID -key "WindowPath"]
        set Index [$GUITree get $NodeID -key "Index"]
        if { $GreyFlag == $GreyFlagOnValue } {
            $WindowPath entryconfigure $Index -state disabled   
        } else {
            $WindowPath entryconfigure $Index -state normal 
        }
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterMenuRadioToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
    
}

proc ::AIEnv::GUIManagement::leaveMenuRadioToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterSeparatorToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveSeparatorToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

#------------------------------------------------------------------------------
#   Icon Items
#------------------------------------------------------------------------------
proc ::AIEnv::GUIManagement::enterTabbedIconToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveTabbedIconToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterIconBarToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveIconBarToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterIconButtonToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveIconButtonToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterIconToggleToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveIconToggleToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterIconDropToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveIconDropToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

#------------------------------------------------------------------------------
#   Dialog Items
#------------------------------------------------------------------------------
proc ::AIEnv::GUIManagement::enterTextEntryToggleGrey { NodeID GreyFlag } {
    variable GUIDisplayData
    variable GreyFlagOnValue

	set GUITree [TreeStack peek]
	
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
	if [aie_wb2_is_running] {
	    set input [$GUITree get $NodeID -key "WBInputParam"]
	    if {$input != ""} {
            if {$input == 1} {
                set GreyFlag 1
                set GreyFlagOnValue 1
            }
        }
	}

    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        # Grey flag is now either a 1 or a 0. If 1, grey out the item
        set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-label" } {
                    $w configure -state disabled
                } else {
                    # This would be the entry widget
                    $w configure -state disabled
                    $w configure -background $GUIDisplayData("DisabledBackground")
                }
            }
        } else {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-label" } {
                    $w configure -state normal
                } else {
                    # This would be the entry widget
                    $w configure -state normal
                    $w configure -background $GUIDisplayData("NormalBackground")
                }
            }
        }

        # Record the state for next time
    $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterTextEntryToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
}

proc ::AIEnv::GUIManagement::leaveTextEntryToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}
proc ::AIEnv::GUIManagement::enterTextTableEntryToggleGrey { NodeID GreyFlag } { 
    ::AIEnv::GUIManagement::enterTextEntryToggleGrey $NodeID $GreyFlag
}
proc ::AIEnv::GUIManagement::leaveTextTableEntryToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}
proc ::AIEnv::GUIManagement::enterTableEntryToggleGrey { NodeID GreyFlag } { 
    ::AIEnv::GUIManagement::enterTextEntryToggleGrey $NodeID $GreyFlag
}
proc ::AIEnv::GUIManagement::leaveTableEntryToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterEntityChooserToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue

	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]

    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        # Grey flag is now either a 1 or a 0. If 1, grey out the item
        set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-text" } {
                    $w configure -state disabled
                    $w configure -background $GUIDisplayData("DisabledBackground")  
                } elseif { $WidgetName == "$NodeID-buttonbox" } {
                    foreach w1 [winfo children $w] {
                        $w1 configure -state disabled
                    }
                } else {
                    $w configure -state disabled
                }
            }
        } else {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-text" } {
                    $w configure -state normal
                    $w configure -background $GUIDisplayData("NormalBackground")    
                } elseif { $WidgetName == "$NodeID-buttonbox" } {
                    foreach w1 [winfo children $w] {
                        $w1 configure -state normal
                    }
                } else {
                    $w configure -state normal
                }
            }
        }
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterEntityChooserToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
}


proc ::AIEnv::GUIManagement::leaveEntityChooserToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}


proc ::AIEnv::GUIManagement::enterPickScreenCoordToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue

	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]

    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        # Grey flag is now either a 1 or a 0. If 1, grey out the item
        set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { [regexp "$NodeID-text*" $WidgetName] } {
                    $w configure -state disabled
                    $w configure -background $GUIDisplayData("DisabledBackground")  
                } elseif { $WidgetName == "$NodeID-buttonbox" } {
                    foreach w1 [winfo children $w] {
                        $w1 configure -state disabled
                    }
                } else {
                    $w configure -state disabled
                }
            }
        } else {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { [regexp "$NodeID-text*" $WidgetName] } {
                    $w configure -state normal
                    $w configure -background $GUIDisplayData("NormalBackground")    
                } elseif { $WidgetName == "$NodeID-buttonbox" } {
                    foreach w1 [winfo children $w] {
                        $w1 configure -state normal
                    }
                } else {
                    $w configure -state normal
                }
            }
        }
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterEntityChooserToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
}

proc ::AIEnv::GUIManagement::leavePickScreenCoordToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty    
}

proc ::AIEnv::GUIManagement::enterGroupToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue
	
	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        # This is a parent so push it's value onto the stack
        GreyFlagStack push $GreyFlag
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag    
    } else {
        Error "Proc enterGroupToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."  
    }
}


proc ::AIEnv::GUIManagement::leaveGroupToggleGrey { NodeID GreyFlag } { 
    if { [GreyFlagStack size] != 0 } {
        GreyFlagStack pop
    }
}

proc ::AIEnv::GUIManagement::enterGreyGroupToggleGrey { NodeID GreyFlag } {
    variable GUIDisplayData
    variable GreyFlagOnValue
    set GUITree [TreeStack peek]
    # Automatic Greying
    if {$GreyFlag == -1} {
        if { [GreyFlagStack size] != 0 } {
            set GreyFlag [GreyFlagStack peek]
        } else {
            set GreyFlag 0
        }
    } 
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
		set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
		foreach Path $WindowPaths {
			if { $GreyFlag == $GreyFlagOnValue } {
				 $Path configure -state disabled   
			} else {
				 $Path configure -state normal 
			}
		}
        # This is a parent so push it's value onto the stack
        GreyFlagStack push $GreyFlag
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag    
    } else {
        Error "Proc enterGreyGroupToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."  
    }
}

proc ::AIEnv::GUIManagement::leaveGreyGroupToggleGrey { NodeID GreyFlag } {
    if { [GreyFlagStack size] != 0 } {
        GreyFlagStack pop
    }
}

proc ::AIEnv::GUIManagement::enterGreyGroupItemToggleGrey { NodeID GreyFlag } {
    variable GUIDisplayData
    variable GreyFlagOnValue
    set GUITree [TreeStack peek]
    # Determine via the parent grey group's variable if this is the
    # grey group item to ungrey.
    set ParentID [$GUITree parent $NodeID]
    set Siblings [$GUITree children $ParentID]
    set GreyGroupSiblings ""
    
    # Only look at the siblings that are of the grey group type.
    foreach Sibling $Siblings {
		if { [$GUITree get $Sibling -key "Type"] == "GreyGroupItem" } {
			lappend GreyGroupSiblings $Sibling
		}
	}
	set Siblings $GreyGroupSiblings
	
    set GreyGroupVariable [$GUITree get $ParentID -key "FullyQualifiedVariable"]
    set GreyGroupVariableVal [subst $[subst $GreyGroupVariable]]
    if {[llength $Siblings] == 1} {
		if { $GreyGroupVariableVal == 1 } {
			set GreyFlag 0
		} else {
			set GreyFlag 1
		}
	} else {
		set IndexInParent [lsearch -exact $Siblings $NodeID]
		if { $IndexInParent == $GreyGroupVariableVal } {
			set GreyFlag 0
		} else {
			set GreyFlag 1
		}
	}
#mess "in ::AIEnv::GUIManagement::enterGreyGroupItemToggleGrey == $NodeID == $GreyFlag\n"
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
		# This is a parent so push it's value onto the stack
        GreyFlagStack push $GreyFlag
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag 
        # Force the children to grey themselves out.
    } else {
        Error "Proc enterGreyGroupItemToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."  
    }
}

proc ::AIEnv::GUIManagement::leaveGreyGroupItemToggleGrey { NodeID GreyFlag } {
    if { [GreyFlagStack size] != 0 } {
        GreyFlagStack pop
    }
}

proc ::AIEnv::GUIManagement::enterFrameToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue

	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        set WindowPath [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            $WindowPath configure -state disabled   
        } else {
            $WindowPath configure -state normal 
        }
        # This is a parent so push it's value onto the stack
        GreyFlagStack push $GreyFlag
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Proc enterFrameToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."  
    }
}

proc ::AIEnv::GUIManagement::leaveFrameToggleGrey { NodeID GreyFlag } { 
    if { [GreyFlagStack size] != 0 } {
        GreyFlagStack pop
    }
}

proc ::AIEnv::GUIManagement::enterRadioGroupToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue

	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]

    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        set WindowPath [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            $WindowPath configure -state disabled   
        } else {
            $WindowPath configure -state normal 
        }
        # This is a parent so push it's value onto the stack
        GreyFlagStack push $GreyFlag
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterRadioToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
    
    
}

proc ::AIEnv::GUIManagement::leaveRadioGroupToggleGrey { NodeID GreyFlag } { 
    if { [GreyFlagStack size] != 0 } {
        GreyFlagStack pop
    }
}

proc ::AIEnv::GUIManagement::enterRadioItemToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue
    set GUITree [TreeStack peek]
    set WindowPath [$GUITree get $NodeID -key "WindowPath"]
    if { [GreyFlagStack size] == 0 } {
        $WindowPath configure -state normal
    } else {
        # Radio items follow their parent
        set GreyFlag [GreyFlagStack peek]
        if { $GreyFlag == $GreyFlagOnValue } {
            $WindowPath configure -state disabled
        } else {
            $WindowPath configure -state normal
        }
    }
}

proc ::AIEnv::GUIManagement::leaveRadioItemToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterDropDownEntryToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue
	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        # Grey flag is now either a 1 or a 0. If 1, grey out the item
        set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-label" } {
                    $w configure -state disabled
                } else {
                    # This would be the entry widget
                    $w configure -state disabled
		    # this is not good because we can't read the text which
		    # is also grey - disabled should mean can't change ..
		    # $w configure -entrybg $GUIDisplayData("DisabledBackground")
                }
            }
        } else {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-label" } {
                    $w configure -state normal
                } else {
                    # This would be the entry widget
                    $w configure -state normal
                    $w configure -entrybg $GUIDisplayData("NormalBackground")
                }
            }
        }

        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterDropDownEntryToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
}

proc ::AIEnv::GUIManagement::leaveDropDownEntryToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterIntegerEntryToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue
	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]

	if [aie_wb2_is_running] {
	    set input [$GUITree get $NodeID -key "WBInputParam"]
	    if {$input != ""} {
            if {$input == 1} {
                set GreyFlag 1
                set GreyFlagOnValue 1
            }
        }
	}

    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        # Grey flag is now either a 1 or a 0. If 1, grey out the item
        set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-label" } {
                    $w configure -state disabled
                } else {
                    # This would be the entry widget
                    $w configure -state disabled
                    $w configure -entrybg $GUIDisplayData("DisabledBackground")
                }
            }
        } else {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-label" } {
                    $w configure -state normal
                } else {
                    # This would be the entry widget
                    $w configure -state normal
                    $w configure -entrybg $GUIDisplayData("NormalBackground")
                }
            }
        }

        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterIntegerEntryToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
    
}

proc ::AIEnv::GUIManagement::leaveIntegerEntryToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterIntegerEntryIconToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue
	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        # Grey flag is now either a 1 or a 0. If 1, grey out the item
        set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-label" } {
                    $w configure -state disabled
                } elseif { $WidgetName == "$NodeID-buttonbox" } {
                    foreach w1 [winfo children $w] {
                        $w1 configure -state disabled
                    }
                } else {
                    # This would be the entry widget
                    $w configure -state disabled
                    $w configure -entrybg $GUIDisplayData("DisabledBackground")
                }
            }
        } else {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-label" } {
                    $w configure -state normal
                } elseif { $WidgetName == "$NodeID-buttonbox" } {
                    foreach w1 [winfo children $w] {
                        $w1 configure -state normal
                    }
                } else {
                    # This would be the entry widget
                    $w configure -state normal
                    $w configure -entrybg $GUIDisplayData("NormalBackground")
                }
            }
        }

        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterIntegerEntryIconToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
    
}

proc ::AIEnv::GUIManagement::leaveIntegerEntryToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterTextButtonToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue
	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        set WindowPath [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            $WindowPath configure -state disabled
        } else {
            $WindowPath configure -state normal
        }

        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterTextButtonToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
}

proc ::AIEnv::GUIManagement::leaveTextButtonToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterDataTableToggleGrey { NodeID GreyFlag } {
	variable GUIDisplayData
    variable GreyFlagOnValue
	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        # Grey flag is now either a 1 or a 0. If 1, grey out the item
        set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-text" } {
                    $w configure -state disabled
                    $w configure -background $GUIDisplayData("DisabledBackground")  
                } elseif { $WidgetName == "$NodeID-buttonbox" } {
                    foreach w1 [winfo children $w] {
                        $w1 configure -state disabled
                    }
                } else {
                    $w configure -state disabled
                }
            }
        } else {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-text" } {
                    $w configure -state normal
                    $w configure -background $GUIDisplayData("NormalBackground")    
                } elseif { $WidgetName == "$NodeID-buttonbox" } {
                    foreach w1 [winfo children $w] {
                        $w1 configure -state normal
                    }
                } else {
                    $w configure -state normal
                }
            }
        }
        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterEntityChooserToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
}

proc ::AIEnv::GUIManagement::leaveDataTableToggleGrey { NodeID GreyFlag } {
	# Intentionally empty	
}

proc ::AIEnv::GUIManagement::enterDialogSpaceGrey { NodeID GreyFlag } {
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveTableToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}



proc ::AIEnv::GUIManagement::enterTextLabelToggleGrey { NodeID GreyFlag } {
}
proc ::AIEnv::GUIManagement::leaveTextLabelToggleGrey { NodeID GreyFlag } {
}

proc ::AIEnv::GUIManagement::anyToggleGreyOn {w} {
   if ![winfo exist $w] {return ""}
   switch -- [winfo class $w] {
      Button - Label - Entry - Text - Scale \
             - Checkbutton - Radiobutton - Menubutton \
             - ComboBox - LabelEntry - LabelFrame - ListBox \
             - SelectColorMenu - SpinBox - TitleFrame \
             - CheckFrame - RadioFrame - Tree {
         $w configure -state disabled
      }
   }

   variable GUIDisplayData
   switch -- [winfo class $w] {
      Entry { $w configure -bg $GUIDisplayData("DisabledBackground") }
      Message { }
      Frame - Menu - Scrollbar { }
      Listbox { }
      NoteBook - PanedWindow { }
   }

   foreach s [winfo children $w] { ::AIEnv::GUIManagement::anyToggleGreyOn $s}
}

proc ::AIEnv::GUIManagement::anyToggleGreyOff  {w} {
   if ![winfo exist $w] {return ""}
   switch -- [winfo class $w] {
      Button - Label - Entry - Text - Scale \
             - Checkbutton - Radiobutton - Menubutton \
             - ComboBox - LabelEntry - LabelFrame - ListBox \
             - SelectColorMenu - SpinBox - TitleFrame \
             - CheckFrame - RadioFrame - Tree {
         $w configure -state normal
      }
   }

   variable GUIDisplayData
   switch -- [winfo class $w] {
      Entry { $w configure -bg $GUIDisplayData("NormalBackground") }
   }

   foreach s [winfo children $w] { ::AIEnv::GUIManagement::anyToggleGreyOff $s}
}

proc ::AIEnv::GUIManagement::enterAnyToggleGrey {NodeID GreyFlag } {
   set GUITree  [TreeStack peek]
   variable GreyFlagOnValue

   set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
   if [expr $GreyFlag != 0 && $GreyFlag != 1] { return ""}

   set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
   if { $GreyFlag == $GreyFlagOnValue } {
      foreach w $WindowPaths { ::AIEnv::GUIManagement::anyToggleGreyOn $w }
   } else {
      foreach w $WindowPaths { ::AIEnv::GUIManagement::anyToggleGreyOff $w }
   }

 #  Record the state for next time
   $GUITree set $NodeID -key "GreyFlag" $GreyFlag
}

proc ::AIEnv::GUIManagement::leaveAnyToggleGrey { NodeID GreyFlag } {
}




proc ::AIEnv::GUIManagement::enterCheckItemToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue
    set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        set WindowPath [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            $WindowPath configure -state disabled
        } else {
            $WindowPath configure -state normal
        }

        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Proc enterTextButtonToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
    
}

proc ::AIEnv::GUIManagement::leaveCheckItemToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterCheckItem2ToggleGrey { NodeID GreyFlag } { 
    variable GUIDisplayData
    variable GreyFlagOnValue

	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]

    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        # Grey flag is now either a 1 or a 0. If 1, grey out the item
        set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach w $WindowPaths {
		$w configure -state disabled
            }
        } else {
            foreach w $WindowPaths {
		$w configure -state normal
            }
        }

        # Record the state for next time
    $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Error: Proc enterCheckItem2ToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }    
}

proc ::AIEnv::GUIManagement::leaveCheckItem2ToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterDialogSpaceToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveDialogSpaceToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterDataEntryDialogToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveDataEntryDialogToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterDialogWindowToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveDialogWindowToggleGrey { NodeID GreyFlag } { 
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterListBoxToggleGrey { NodeID GreyFlag } {
    variable GUIDisplayData
	variable GreyFlagOnValue
    set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach Path $WindowPaths {
				catch {$Path configure -state disabled}
			}
        } else {
			foreach Path $WindowPaths {
				catch {$Path configure -state normal}	
			}
        }

        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Proc enterListBoxToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }
    		
}

proc ::AIEnv::GUIManagement::leaveListBoxToggleGrey { NodeID GreyFlag } {
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterEntityMoverToggleGrey {NodeID GreyFlag} {
	variable GUIDisplayData
	variable GreyFlagOnValue
	set GUITree [TreeStack peek]
	# Automatic Greying
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
    
    if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
        set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach Path $WindowPaths {
				set WidgetName [lindex [split $Path .] end]
				if { $WidgetName == "$NodeID-buttonbox" } {
					set Buttons [winfo children $Path]
					foreach B $Buttons {
						$B configure -state disabled
					}
				} else {
            		$Path configure -state disabled
				}
			}
        } else {
			foreach Path $WindowPaths {
				set WidgetName [lindex [split $Path .] end]
				if { $WidgetName == "$NodeID-buttonbox" } {
					set Buttons [winfo children $Path]
					foreach B $Buttons {
						$B configure -state normal
					}
				} else {
            		$Path configure -state normal
				}
			}
        }

        # Record the state for next time
        $GUITree set $NodeID -key "GreyFlag" $GreyFlag
    } else {
        Error "Proc enterListBoxToggleGrey.\nNodeID=$NodeID GreyFlag=$GreyFlag.\nOnly the values 0 or 1 are valid choices for the grey flag."
    }    
}

proc ::AIEnv::GUIManagement::leaveEntityMoverToggleGrey {NodeID GreyFlag} {
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterMultiSelectToggleGrey {NodeID GreyFlag} {
	variable GUIDisplayData
	variable GreyFlagOnValue
	set GUITree [TreeStack peek]
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
    set Name [$GUITree get $NodeID -key "Name"]
	if { $GreyFlag == $GreyFlagOnValue } {
		$Name widgetgrey
	} else {
		$Name widgetungrey
	}
}

proc ::AIEnv::GUIManagement::leaveMultiSelectToggleGrey {NodeID GreyFlag} {
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::enterMultiSelectRowsToggleGrey {NodeID GreyFlag} {
	# Intentionally empty
}

proc ::AIEnv::GUIManagement::leaveMultiSelectRowsToggleGrey {NodeID GreyFlag} {
	# Intentionally empty	
}

proc ::AIEnv::GUIManagement::enterMultiSelectColumnsToggleGrey {NodeID GreyFlag} {
	# Intentionally empty	
}

proc ::AIEnv::GUIManagement::leaveMultiSelectColumnsToggleGrey {NodeID GreyFlag} {
	# Intentionally empty	
}

proc ::AIEnv::GUIManagement::enterExclusiveGroupToggleGrey {NodeID GreyFlag} {
	variable GreyFlagOnValue
	variable GUIDisplayData
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
	if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
		set GUITree [TreeStack peek]
		set Name [$GUITree get $NodeID -key "Name"]
		if { $GreyFlag == $GreyFlagOnValue } {
			$Name widgetgrey
		} else {
			$Name widgetungrey
		}
		GreyFlagStack push $GreyFlag
	}
}

proc ::AIEnv::GUIManagement::leaveExclusiveGroupToggleGrey {NodeID GreyFlag} {
	if { [GreyFlagStack size] != 0 } {
	    GreyFlagStack pop
    }
}

proc ::AIEnv::GUIManagement::enterExclusiveGroupItemToggleGrey {NodeID GreyFlag} {

   set GUITree [TreeStack peek_one]
   set ParentNodeID [$GUITree parent $NodeID]
   set ParentName [$GUITree get $ParentNodeID -key "Name"]
   set ThisName [$GUITree get $NodeID -key "Name"]

   set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]

   if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
      set wg [::AIEnv::GUIManagement::ExclusiveGroup::GetGroupItemWidget $ParentName $ThisName]
      if ![winfo exist $wg] {return ""}

      variable GreyFlagOnValue

      if { $GreyFlag == $GreyFlagOnValue } {
         $wg configure -state disabled
      } else {
         $wg configure -state normal
      }
   }
}

proc ::AIEnv::GUIManagement::leaveExclusiveGroupItemToggleGrey {NodeID GreyFlag} {
	
}

proc ::AIEnv::GUIManagement::enterFileChooserToggleGrey {NodeID GreyFlag} {
	
}

proc ::AIEnv::GUIManagement::leaveFileChooserToggleGrey {NodeID GreyFlag} {
	variable GreyFlagOnValue
	variable GUIDisplayData
	
	set GreyFlag [CheckAutoGreying $NodeID $GreyFlag]
	
	if { [expr $GreyFlag == 0 || $GreyFlag == 1] } {
		set GUITree [TreeStack peek]
		set WindowPaths [$GUITree get $NodeID -key "WindowPath"]
        if { $GreyFlag == $GreyFlagOnValue } {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-text" } {
					 # This would be the entry widget
					$w configure -state disabled
                    $w configure -background $GUIDisplayData("DisabledBackground")
				} elseif { $WidgetName == "$NodeID-buttonbox" } {
					set Buttons [winfo children $w]
					foreach B $Buttons {
						$B configure -state disabled
					}					
				} else {
                    $w configure -state disabled
                } 
            }
        } else {
            foreach w $WindowPaths {
                set WidgetName [lindex [split $w .] end]
                if { $WidgetName == "$NodeID-text" } {
					 # This would be the entry widget
					$w configure -state normal
                    $w configure -background $GUIDisplayData("NormalBackground")
				} elseif { $WidgetName == "$NodeID-buttonbox" } {
					set Buttons [winfo children $w]
					foreach B $Buttons {
						$B configure -state normal
					}					
				} else {
                    $w configure -state normal
                } 
            }
		}
	}
 }


proc ::AIEnv::GUIManagement::CheckAutoGreying {NodeID GreyFlag} {
	variable GreyFlagOnValue
	set GUITree [TreeStack peek]
	# Automatic Greying
	if {$GreyFlag == -1} {
		if { [GreyFlagStack size] != 0 } {
			set GreyFlag [GreyFlagStack peek]
		} else {
			set CurrGreyFlag [$GUITree get $NodeID -key "GreyFlag"]
			# Flip the current grey flag
			if { $CurrGreyFlag == 0 } {
				set GreyFlag 1
			} else {
				set GreyFlag 0
			}
		}
    } 
    return $GreyFlag
}

proc ::AIEnv::GUIManagement::GetGreyFlag {Entity} {
    set GUITree [TreeStack peek]
    variable ItemNameMap
    set CurrGreyFlag -1
    if { [info exists ItemNameMap($Entity)] } {
        set NodeID $ItemNameMap($Entity)
        set CurrGreyFlag [$GUITree get $NodeID -key "GreyFlag"]
    } else {
        Error "The specific GUI entity named \"$Entity\" does not exist."   
    }
    return $CurrGreyFlag  
}






