// Copyright (C) 1997-2004 Alias Systems Corp.
// 
// The information in this file is provided for the exclusive use of the
// licensees of Alias.  Such users have the right to use, modify,
// and incorporate this code into other products for purposes authorized
// by the Alias license agreement, without fee.
// 
// ALIAS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
// EVENT SHALL ALIAS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

//
//  Alias Script File
//  MODIFY THIS AT YOUR OWN RISK
//
//  Creation Date:  Feb 13, 2001
//
//  Description:
//      A scriptJob to contro the IK/FK switching UI
//


global proc ikSelectionChanged(string $menu)
//
//	Description:
//		When the selection changes, this updated the ik/fk UI
//
{
	if (`headsUpDisplay -exists HUDIKSolverState` &&
		`headsUpDisplay -q -vis HUDIKSolverState`) {

		//	The menu will get updated when the Heads Up Display is 
		//	updated.
		//
		return;
	}

	//	There are five different returned values from ikFKSolverState()
	//		0	:	No joints or ikHandles are selected.
	//		1	:	The selected items have their solver enabled.
	//		2 	:	The selected items have their solver disabled.
	//		3 	:	No solver on the selcted joints.
	//		4 	:	Some of the selected items have their solvers 
	//				enabled and others have their solvers disabled.
	//
	int $solverState = ikFKSolverState(`ls -sl`);
	int $ikOn = false;

	if ($solverState == 1 || $solverState == 4) {
		$ikOn = true;
	}

	menuItem -edit -checkBox $ikOn $menu;
	optionVar -intValue ikFKSwitchState $ikOn;
}

global proc updateIKFKCheckBox(int $state)
{
	global string $gikFKSwitchStateCheckBoxMenu;
	if (`menuItem -ex $gikFKSwitchStateCheckBoxMenu`) {
		menuItem -edit -checkBox $state $gikFKSwitchStateCheckBoxMenu;
		optionVar -intValue ikFKSwitchState $state;
	}
}

global proc setUpIKSelectionScriptJob(string $menu)
{
	global string $gikFKSwitchStateCheckBoxMenu;
	$gikFKSwitchStateCheckBoxMenu = $menu;

	scriptJob -protected -event "SelectionChanged" 
		("ikSelectionChanged(\""+$menu+"\")");

	scriptJob -protected -event timeChanged
		("ikSelectionChanged(\""+$menu+"\")");
}
