// 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:  4 April 1997
//
//  Procedure Name:
//      performPolyMapSewMove
//
//  Description:
//        
//         
//  Input Arguments:
//        $option : Whether to set the options to default values.
//  Return Value:
//        command string iff $option==2
//

//
// Initialize optionVars for polyMapSewMove:
// Color, Texture, Vertex
// 
proc setOptionVars (
	string		$prefix, 
	int			$forceFactorySettings,
	string		$vars[]
)
{
	string $varName;

	// Must match $vars
	int    $intValues[]= { 0, 10 };

	for ( $i = size($vars) ; $i-- ; )
	{
		$varName = ($prefix + $vars[$i]);
		if ($forceFactorySettings || !`optionVar -exists $varName`)
			optionVar -intValue $varName $intValues[$i];
	}
}

global proc performPolyMapSewMoveSetup (string $parent, int $forceFactorySettings)
{
	string $prefix = "polyMapSewMove";
	string $intVars[] ={"lps", "nf"};
	string $varName;

	setOptionVars($prefix, $forceFactorySettings, $intVars);
	setParent $parent;

	$varName = ($prefix + $intVars[0]);
	int $val = `optionVar -query $varName`;
	checkBoxGrp -edit -value1 $val $varName;

	$varName = ($prefix + $intVars[1]);
    intSliderGrp -edit -en $val -value `optionVar -query $varName` $varName;
}

global proc performPolyMapSewMoveCallback (string $parent, int $doIt)
{
	string $prefix = "polyMapSewMove";
	string $intVars[] ={"lps", "nf"};
	string $varName;

	setParent $parent;
	
	$varName = ($prefix + $intVars[0]);
	optionVar -intValue $varName `checkBoxGrp -query -value1 $varName`;
	
	$varName = ($prefix + $intVars[1]);
	optionVar -intValue $varName (`intSliderGrp -q -value $varName`);

	if ($doIt) 
	{
		performPolyMapSewMove 0;
		addToRecentCommandQueue "performPolyMapSewMove 0" "PolyMapSewMove";
	}
}

proc polyMapSewMoveOptions (string $prefix, string $intVars[])
{
	string $commandName = "performPolyMapSewMove";
	string $callback = ($commandName + "Callback");
	string $setup = ($commandName + "Setup");
	string $varName;

	string $layout = getOptionBox();
	setParent $layout;
	setUITemplate -pushTemplate DefaultTemplate;
	waitCursor -state 1;
	
	string $parent = `columnLayout -adjustableColumn 1`;

	$varName = ($prefix + $intVars[0]);
	$varName2 = ($prefix + $intVars[1]);
	string $grayCmd = 
		"{ int $tmp = `checkBoxGrp -q -v1 "+$varName + "`;" +
		"  intSliderGrp -e -en $tmp "+$varName2+";}";

    checkBoxGrp -label1 "Limit Piece Size" -cc $grayCmd $varName;
	intSliderGrp -label "Number of Faces " $varName2;

	waitCursor -state 0;
	setUITemplate -popTemplate;

	string $applyBtn = getOptionBoxApplyBtn();
	button -edit -label "Move and Sew"
	       -command ($callback + " " + $parent + " " + 1) $applyBtn;
	string $saveBtn = getOptionBoxSaveBtn();
	button -edit 
		-command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
		$saveBtn;
	string $resetBtn = getOptionBoxResetBtn();
	button -edit 
		-command ($setup + " " + $parent + " " + 1) $resetBtn;

	setOptionBoxTitle("Polygon Move and Sew UVs Options");

	setOptionBoxHelpTag( "MoveandSewUVs" );

	eval (($setup + " " + $parent + " " + 0));

	showOptionBox();
}

global proc string performPolyMapSewMove (int $option)
{
	string $prefix = "polyMapSewMove";
	string $intVars[] ={"lps", "nf"};
	string $cmd="";

	switch ($option) 
	{
		case 0:
		string $varName;
		int $ival;
		setOptionVars($prefix, false, $intVars);
		$cmd = "polyMapSewMove";
		for ( $i = size($intVars) ; $i-- ; )
		{
			$varName = ($prefix + $intVars[$i]);
			$ival = `optionVar -query $varName`;
			$cmd = $cmd + " -" + $intVars[$i] + " " + $ival;
		}

		polyPerformAction $cmd "f" 0;
		break;

		case 1:
			polyMapSewMoveOptions($prefix, $intVars);
			break;
		case 2:
			$cmd="performPolyMapSewMove 0";
			break;
	}
	return $cmd;
}
