// Copyright (C) 1997-2006 Autodesk, Inc., and/or its licensors.
// All rights reserved.
//
// The coded instructions, statements, computer programs, and/or related
// material (collectively the "Data") in these files contain unpublished
// information proprietary to Autodesk, Inc. ("Autodesk") and/or its licensors,
// which is protected by U.S. and Canadian federal copyright law and by
// international treaties.
//
// The Data is provided for use exclusively by You. You have the right to use,
// modify, and incorporate this Data into other products for purposes authorized 
// by the Autodesk software license agreement, without fee.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. AUTODESK
// DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES
// INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF NON-INFRINGEMENT,
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, OR ARISING FROM A COURSE 
// OF DEALING, USAGE, OR TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS
// LICENSORS BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
// DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK AND/OR ITS
// LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY OR PROBABILITY OF SUCH DAMAGES.

//
//  Procedure Name:
//	AEparentConstraintTemplate
//
//  Description Name;
//	Creates the attribute editor controls for the parentConstraint Node
//
//  Input Value:
//	nodeName 
//
//  Output Value:
//	None
//

global proc AEparentCheckInterpType(string $nodeName)
{
	int $interpType = `getAttr ($nodeName+".interpType")`;

	string $cacheExists[] = `listConnections ($nodeName+".interpCache")`;
	int $enableDeleteCache = (size($cacheExists) > 0);
	button -e -en $enableDeleteCache deleteCacheButton;

	// interpType is an enum, and interpType == 4 is "cache"
	//
	int $enableCreateCache = (($interpType == 4) && (size($cacheExists) == 0) ||
							  ($interpType == 0));
	button -e -en $enableCreateCache createCacheButton;	
}

global proc AEparentCacheReplace(string $plug)
{
	string $buff[];
	tokenize($plug,".",$buff);
	string $nodeName = $buff[0];

	float $rangeStart = `playbackOptions -q -min`;
	float $rangeEnd   = `playbackOptions -q -max`;

	button -e -c ("evalEcho \"parentConstraint -e -dc "+$nodeName+"\"; "+
				  "button -e -en false deleteCacheButton; " +
				  "button -e -en true createCacheButton") deleteCacheButton;

	button -e -c ("evalEcho \"parentConstraint -e -cc "+
				  $rangeStart+" "+$rangeEnd+" "+$nodeName+"\"; "+
				  "button -e -en true deleteCacheButton") createCacheButton;
}

global proc AEparentCacheNew(string $plug)
{
	setUITemplate -pst attributeEditorTemplate;
		
 		columnLayout cachectlColumn;
 		rowLayout -nc 5 deleteCacheLayout;
 		text -label (uiRes("m_AEparentConstraintTemplate.kCache")) ;
		button -label (uiRes("m_AEparentConstraintTemplate.kCreate"))  createCacheButton;
 		text -label "";
		button -label (uiRes("m_AEparentConstraintTemplate.kDelete"))  deleteCacheButton;		
 		text -label "";		
 		setParent ..;

	AEparentCacheReplace($plug);
	setUITemplate -ppt;
}

global proc AEenableRestParentCallback( string $nodeName )
{
	int $enable = `getAttr ($nodeName+".enableRestPosition")`;
	editorTemplate -dimControl $nodeName "restTranslate" (! $enable);
	editorTemplate -dimControl $nodeName "restRotate" (! $enable);	
}


global proc AEparentConstraintTemplate ( string $nodeName )
{
	editorTemplate -beginScrollLayout;		

		// include/call base class/node attributes
		AEtransformMain $nodeName;
		
		editorTemplate -beginLayout (uiRes("m_AEparentConstraintTemplate.kParentConstraintAttributes"))  -collapse 0;

		    editorTemplate -addControl "lockOutput";			
			editorTemplate -addControl "interpType" "AEparentCheckInterpType";
			editorTemplate -callCustom "AEparentCacheNew" "AEparentCacheReplace" "interpType";

			editorTemplate -addControl "constraintTranslate";
			editorTemplate -addControl "constraintRotate";
			editorTemplate -addControl "enableRestPosition" "AEenableRestParentCallback";			
			editorTemplate -addControl "restTranslate";
			editorTemplate -addControl "restRotate";			

			// suppressed attributes
			editorTemplate -suppress "constraintRotatePivot";
			editorTemplate -suppress "constraintParentInverseMatrix";
			editorTemplate -suppress "constraintRotateTranslate";
			editorTemplate -suppress "constraintJointOrient";
			editorTemplate -suppress "constraintRotateOrder";
			editorTemplate -suppress "constraintOffsetPolarity";
			editorTemplate -suppress "target";
			editorTemplate -suppress "interpCache";
			editorTemplate -suppress "lastTargetRotate";

			ccAttributeDispatcher( $nodeName );

		editorTemplate -endLayout;

		// include/call base class/node attributes
		AEtransformNoScroll $nodeName;

	editorTemplate -addExtraControls;
	editorTemplate -endScrollLayout;
}
