// Copyright (C) 1997-2010 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:
//	AEjointTemplate
//
//  Description:
//	Creates the attribute editor controls for the joint Node
//
//  Input Value:
//	nodeName
//
//  Output Value:
//	None
//

global proc setJointDOFState ( string $attrJointTypeX, 
			string $attrJointTypeY, 
			string $attrJointTypeZ )
{	
	string $setX;
	string $setY;
	string $setZ;
	string $XYZ;

	string $nodeName[];
	tokenize ($attrJointTypeX, ".", $nodeName);
	int $jointTypeX = `getAttr $attrJointTypeX`;
	int $jointTypeY = `getAttr $attrJointTypeY`;
	int $jointTypeZ = `getAttr $attrJointTypeZ`;

	// assign the corresponding strings for the joint types
	if ( $jointTypeX ) 
		 $setX = "x";
	if ( $jointTypeY ) 
		 $setY = "y";
	if ( $jointTypeZ ) 
		 $setZ = "z";

	// put the three values together to be able to excute 
	// the command correctly
	$XYZ = ( $setX + $setY + $setZ );
	

	// execute the command to lock specific attributes
	// and manip handles
	joint -e -dof $XYZ $nodeName[0];
}


//
//  Procedure Name:
//	AEjointTypeReplace
//
//

global proc AEjointTypeReplace ( string $attrJointTypeX, 
			string $attrJointTypeY, 
			string $attrJointTypeZ )
{	
	connectControl jointTypeBoxes -index 2  $attrJointTypeX;
	connectControl jointTypeBoxes -index 3  $attrJointTypeY;
	connectControl jointTypeBoxes -index 4  $attrJointTypeZ;
	checkBoxGrp -e	
		-cc ("setJointDOFState " 
			+ $attrJointTypeX + " "
			+ $attrJointTypeY + " "
			+ $attrJointTypeZ)
		jointTypeBoxes;
}


//
//  Procedure Name:
//	AEjointTypeNew
//
//

global proc AEjointTypeNew ( string $attrJointTypeX, 
			string $attrJointTypeY, 
			string $attrJointTypeZ )
{
	checkBoxGrp -ncb 3 -label (uiRes("m_AEjointTemplate.kDegreesofFreedom"))  
		-label1 (uiRes("m_AEjointTemplate.kX"))  
		-label2 (uiRes("m_AEjointTemplate.kY"))  
		-label3 (uiRes("m_AEjointTemplate.kZ"))  jointTypeBoxes; 
	
	connectControl jointTypeBoxes -index 2  $attrJointTypeX;
	connectControl jointTypeBoxes -index 3  $attrJointTypeY;
	connectControl jointTypeBoxes -index 4  $attrJointTypeZ;
	checkBoxGrp -e	
		-cc ("setJointDOFState " 
			+ $attrJointTypeX + " "
			+ $attrJointTypeY + " "
			+ $attrJointTypeZ)
		jointTypeBoxes;
}


global proc AEminRotateDampRangeNew( string $attrName )
{
	setUITemplate -pst attributeEditorTemplate;	
 	attrFieldGrp -attribute $attrName -label (uiRes("m_AEjointTemplate.kMinDampRange")) 
            minRotateDampRangeGrp;
    setUITemplate -ppt;
}

global proc AEminRotateDampRangeReplace( string $attrName )
{
 	attrFieldGrp -e -attribute $attrName -label (uiRes("m_AEjointTemplate.kMinDampRange2")) 
            minRotateDampRangeGrp;
}

global proc AEmaxRotateDampRangeNew( string $attrName )
{
	setUITemplate -pst attributeEditorTemplate;	
 	attrFieldGrp -attribute $attrName -label (uiRes("m_AEjointTemplate.kMaxDampRange")) 
            maxRotateDampRangeGrp;
    setUITemplate -ppt;
}

global proc AEmaxRotateDampRangeReplace( string $attrName )
{
 	attrFieldGrp -e -attribute $attrName -label (uiRes("m_AEjointTemplate.kMaxDampRange2")) 
            maxRotateDampRangeGrp;
}

global proc AEminRotateDampStrengthNew( string $attrName )
{
	setUITemplate -pst attributeEditorTemplate;	
 	attrFieldGrp -attribute $attrName -label (uiRes("m_AEjointTemplate.kMinDampStrength")) 
            minRotateDampStrengthGrp;
    setUITemplate -ppt;
}

global proc AEminRotateDampStrengthReplace( string $attrName )
{
 	attrFieldGrp -e -attribute $attrName -label (uiRes("m_AEjointTemplate.kMinDampStrength2")) 
            minRotateDampStrengthGrp;
}

global proc AEmaxRotateDampStrengthNew( string $attrName )
{
	setUITemplate -pst attributeEditorTemplate;	
 	attrFieldGrp -attribute $attrName -label (uiRes("m_AEjointTemplate.kMaxDampStrength")) 
            maxRotateDampStrengthGrp;
    setUITemplate -ppt;
}

global proc AEmaxRotateDampStrengthReplace( string $attrName )
{
 	attrFieldGrp -e -attribute $attrName -label (uiRes("m_AEjointTemplate.kMaxDampStrength2")) 
            maxRotateDampStrengthGrp;
}

global proc checkPuppetPartOther( string $nodeName )
{
	int $val = `getAttr ($nodeName+".type")`;
	int $dimOther = ($val != 18);
	editorTemplate -dimControl $nodeName "otherType" $dimOther;
}

//
//  Procedure Name:
//	AEjointTemplate
//
//

global proc AEjointTemplate ( string $nodeName ) 
{
editorTemplate -beginScrollLayout;
	// include/call base class/node attributes
	AEtransformMain $nodeName;

editorTemplate -beginLayout (uiRes("m_AEjointTemplate.kJoint"))  -collapse 0;

	editorTemplate -addControl "drawStyle";

	editorTemplate -addControl "radius";

	editorTemplate -callCustom "AEjointTypeNew" "AEjointTypeReplace" 
				"jointTypeX"
				"jointTypeY"
				"jointTypeZ";

	editorTemplate -addControl "stiffness";

	editorTemplate -addControl "preferredAngle";

	editorTemplate -addControl "jointOrient";
	editorTemplate -addControl "segmentScaleCompensate";


	editorTemplate -beginLayout (uiRes("m_AEjointTemplate.kJointLabelling"))  -collapse 0;
	editorTemplate -addControl "side";
	editorTemplate -addControl "type" "checkPuppetPartOther";
	editorTemplate -label (uiRes("m_AEjointTemplate.kOtherType"))  -addControl "otherType";
	editorTemplate -addControl "drawLabel";
	editorTemplate -endLayout;
	
	editorTemplate -beginLayout (uiRes("m_AEjointTemplate.kJointRotationLimitDamping")) ;
		editorTemplate -callCustom "AEminRotateDampRangeNew"
			"AEminRotateDampRangeReplace" "minRotateDampRange";
		editorTemplate -callCustom "AEmaxRotateDampRangeNew"
			"AEmaxRotateDampRangeReplace" "maxRotateDampRange";
		editorTemplate -callCustom "AEminRotateDampStrengthNew"
			"AEminRotateDampStrengthReplace" "minRotateDampStrength";
		editorTemplate -callCustom "AEmaxRotateDampStrengthNew"
			"AEmaxRotateDampStrengthReplace" "maxRotateDampStrength";
	editorTemplate -endLayout;


editorTemplate -endLayout;

	//suppressed attributes
	editorTemplate -suppress "inverseScale";
	editorTemplate -suppress "bindPose";
	editorTemplate -suppress "bindRotation";
	editorTemplate -suppress "bindJointOrient";
	editorTemplate -suppress "bindScale";
	editorTemplate -suppress "bindInverseScale";	
	editorTemplate -suppress "bindSegmentScaleCompensate";	
	editorTemplate -suppress "jointOrientType";
	editorTemplate -suppress "jointType";	
	editorTemplate -suppress "dofMask";
	editorTemplate -suppress "fkRotate";
	editorTemplate -suppress "ikRotate";

	ccAttributeDispatcher( $nodeName );

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

	// For joints bound to smooth skins
	//
	AEtransformSkinCluster $nodeName;

editorTemplate -addExtraControls;
editorTemplate -endScrollLayout;

}
