global proc AETropismTemplate( string $nodeName )
{
	editorTemplate -beginScrollLayout;
	
		// The all go into the collapsable "Parameters" section
		editorTemplate -beginLayout "Overall" -collapse false;

			// Add the default controls
			editorTemplate -addControl "type";
			editorTemplate -addControl "axis";
			editorTemplate -addControl "intensityFitGrowth";
			editorTemplate -addControl "evaluation";
			
		editorTemplate -endLayout;

		editorTemplate -beginLayout "Standard Curve Parameters" -collapse false;
					
			//Add the default controls for the CurveParameters
			string $newFuncAttrib = "tropismCurvNewAttrib";
			string $replaceFuncAttrib = "tropismCurvReplaceAttrib";
			editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "";
		
		editorTemplate -endLayout;
		
		/*editorTemplate -beginLayout "Extra Curve Parameters - not yet implemented" -collapse true;
							
			//Add the default controls for the ExtraCurveParameters
			//string $newFuncAttrib = "tropismExtraNewAttrib";
			//string $replaceFuncAttrib = "tropismExtraReplaceAttrib";
			//editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "";
				
		editorTemplate -endLayout;*/
		
		editorTemplate -beginLayout "Family" -collapse false;
		
			//Add the default controls for the Family-Members-Handling
			string $newFuncAttrib = "tropismFamilyNewAttrib";
			string $replaceFuncAttrib = "tropismFamilyReplaceAttrib";
			editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "";	
						
		editorTemplate -endLayout;
		
		editorTemplate -beginLayout "Xfrog HD" -collapse true;
				
			//Add the default controls for the Alternates-Handling
			string $newFuncAttrib = "tropismAlternateNewAttrib";
			string $replaceFuncAttrib = "tropismAlternateReplaceAttrib";
			editorTemplate -callCustom $newFuncAttrib $replaceFuncAttrib "alternateCurvs";	
								
		editorTemplate -endLayout;
		

		// Create an "Extras" section and also add controls for any
		// attributes we have not explicitly mentioned.
		editorTemplate -addExtraControls;
	editorTemplate -endScrollLayout;

	// Tell the attribute editor not to display the attributes we
	// don't care about.
	editorTemplate -suppress "caching";
	editorTemplate -suppress "nodeState";
}

global proc tropismCurvNewAttrib(string $attr)
{
	tropismCurvReplaceAttrib($attr);
}

global proc tropismCurvReplaceAttrib(string $attr)
{
	$type = `nodeType ($attr+"intensity")`;
	int $end   = `size($attr)`-1;
	$node = `substring $attr 1 $end`;
	
	if(!`layout -exists ($type+"_curveParam_layout")`) columnLayout ($type+"_curveParam_layout");
	
	setParent ($type+"_curveParam_layout");
	if(!`layout -exists ($type+"_intensity_layout")`) rowLayout -nc 3 ($type+"_intensity_layout"); //intensity
	if(!`text -exists ($type+"_intensity_text")`){
		setParent ($type+"_intensity_layout");
		text -label ("Intensity") ($type+"_intensity_text");
	}
	if(!`textField -exists ($type+"_intensity_tf")`){
		setParent ($type+"_intensity_layout");
		textField  -ed 0 -tx "<no connection>" ($type+"_intensity_tf");
	}
	if(!`symbolButton -exists ($type+"_intensity_button")`){
			setParent ($type+"_intensity_layout");
			symbolButton -i "inArrow.xpm" -h 20 ($type+"_intensity_button");
	}
	
	
	string $params = `connectionInfo -sfd ($attr+"intensity")`;				//intensity
	if(`size($params)`!=0 && `nodeType $params`=="curveEmulation"){
		string $conInput[];
		tokenize($params, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_intensity_tf");
		symbolButton -e -i "inArrow.xpm" -h 20 -command ("select "+$conInput[0]+";") ($type+"_intensity_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_intensity_tf");
		$actionCommand  = "string $XFtempStringCurveEmulationName = `XFCreateCurveEmulation`; 								\n";
		$actionCommand += "string $XFtempStringCurveEmulationResult = `XFConnectCurveAttr $XFtempStringCurveEmulationName "+$node+" intensity`;		\n";
		$actionCommand += "textField -e -tx $XFtempStringCurveEmulationResult (\""+$type+"_intensity_tf\");						\n";
		$actionCommand += "symbolButton -e -i \"inArrow.xpm\" -h 20 -command (\"select \"+$XFtempStringCurveEmulationResult+\";\") "+$type+"_intensity_button;	\n";
		symbolButton -e -i "addy.xpm" -h 20 -command $actionCommand ($type+"_intensity_button");
	}
}

global proc tropismFamilyNewAttrib(string $attr)
{
	tropismFamilyReplaceAttrib($attr);
}

global proc tropismFamilyReplaceAttrib(string $attr)	//still needs change for non-XFrogObject-childs
{
	$type = `nodeType ($attr+"inParameters")`;

	if(!`layout -exists ($type+"_children_layout")`) columnLayout ($type+"_children_layout");
	
	setParent ($type+"_children_layout");
	if(!`layout -exists ($type+"_parent_layout")`) rowLayout -nc 3 ($type+"_parent_layout"); //parent
	if(!`text -exists ($type+"_parent_text")`){
		setParent ($type+"_parent_layout");
		text -label ("Parent") ($type+"_parent_text");
	}
	if(!`textField -exists ($type+"_parent_tf")`){
		setParent ($type+"_parent_layout");
		textField  -ed 0 -tx "<no connection>" ($type+"_parent_tf");
	}
	if(!`symbolButton -exists ($type+"_parent_button")`){
			setParent ($type+"_parent_layout");
			symbolButton -i "inArrow.xpm" -h 20 ($type+"_parent_button");
	}
	
	setParent ($type+"_children_layout");
	if(!`layout -exists ($type+"_pathC_layout_row1")`) rowLayout -nc 3 ($type+"_pathC_layout_row1"); //pathC
	if(!`text -exists ($type+"_pathC_text")`){
		setParent ($type+"_pathC_layout_row1");
		text -label ("Curve") ($type+"_pathC_text");
	}
	if(!`textField -exists ($type+"_pathC_tf")`){
		setParent ($type+"_pathC_layout_row1");
		textField  -ed 0 -tx "<no connection>" ($type+"_pathC_tf");
	}
	if(!`symbolButton -exists ($type+"_pathC_button")`){
		setParent ($type+"_pathC_layout_row1");
		symbolButton -i "addy.xpm" -h 20 ($type+"_pathC_button");
	}
	
	setParent ($type+"_children_layout");
	if(!`layout -exists ($type+"_ref_layout_row1")`) rowLayout -nc 3 ($type+"_ref_layout_row1"); //refObj
	if(!`text -exists ($type+"_ref_text")`){
		setParent ($type+"_ref_layout_row1");
		text -label ("Reference") ($type+"_ref_text");
	}
	if(!`textField -exists ($type+"_ref_tf")`){
		setParent ($type+"_ref_layout_row1");
		textField  -ed 0 -tx "<no connection>" ($type+"_ref_tf");
	}
	if(!`symbolButton -exists ($type+"_ref_button")`){
		setParent ($type+"_ref_layout_row1");
		symbolButton -i "addy.xpm" -h 20 ($type+"_ref_button");
	}
	
	setParent ($type+"_children_layout");
	if(!`layout -exists ($type+"_refCurve_layout_row1")`) rowLayout -nc 3 ($type+"_refCurve_layout_row1"); //refObj
	if(!`text -exists ($type+"_refCurve_text")`){
		setParent ($type+"_refCurve_layout_row1");
		text -label ("Reference Spline") ($type+"_refCurve_text");
	}
	if(!`textField -exists ($type+"_refCurve_tf")`){
		setParent ($type+"_refCurve_layout_row1");
		textField  -ed 0 -tx "<no connection>" ($type+"_refCurve_tf");
	}
	if(!`symbolButton -exists ($type+"_refCurve_button")`){
		setParent ($type+"_refCurve_layout_row1");
		symbolButton -i "addy.xpm" -h 20 ($type+"_refCurve_button");
	}
	
	string $pParams;
	string $pParamsData;
	if( catchQuiet ($pParams = `connectionInfo -sfd ($attr+"inParameters")`)) $pParams="";			//parent
	if(`size($pParams)`!=0){
		string $conInput[];
		tokenize($pParams, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_parent_tf");
		symbolButton -e -en 1 -command ("select "+$conInput[0]+";") ($type+"_parent_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_parent_tf");
		symbolButton -e -en 0 ($type+"_parent_button");
	}
	
	if( catchQuiet ($pParams = `connectionInfo -sfd ($attr+"inPathCurves[0]")`)) $pParams="";		//curve
	if( catchQuiet ($pParamsData = `connectionInfo -sfd ($attr+"inPathCurvesData")`)) $pParamsData="";	//curveData

	if(`size($pParamsData)`!=0){
		string $conInput[];
		tokenize($pParamsData, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_pathC_tf");
		symbolButton -e -i "inArrow.xpm" -h 20 -command ("select "+$conInput[0]+";") ($type+"_pathC_button");
	} else if (`size($pParams)`!=0){
		string $conInput[];
		tokenize($pParams, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_pathC_tf");
		symbolButton -e -i "inArrow.xpm" -h 20 -command ("select "+$conInput[0]+";") ($type+"_pathC_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_pathC_tf");
		string $actionCommand 	=  "string $curveName = \"\";												\n";
		$actionCommand		+= "if(!catch($curveName = `XFConnectCurve 0`)){									\n";
		$actionCommand		+= "	textField -e -tx $curveName (\""+$type+"_pathC_tf\");								\n";
		$actionCommand		+= "	symbolButton -e -i \"inArrow.xpm\" -h 20 -command (\"select \"+$curveName+\";\") (\""+$type+"_pathC_button\");	\n";
		$actionCommand		+= "}															";
		symbolButton -e -i "addy.xpm" -h 20 -command $actionCommand ($type+"_pathC_button");
	}
	
	if( catchQuiet ($pParams = `connectionInfo -sfd ($attr+"refTransformationMatrix")`)) $pParams="";	//ref
	if(`size($pParams)`!=0){
		string $conInput[];
		tokenize($pParams, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_ref_tf");
		symbolButton -e -i "inArrow.xpm" -command ("select "+$conInput[0]+";") ($type+"_ref_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_ref_tf");
		$actionCommand  = "string $sel[]=`ls -selection`;										\n";
		$actionCommand += "if(`size($sel)`==2){												\n";
		$actionCommand += "	connectAttr ($sel[0]+\".worldMatrix\") (\""+$attr+"refTransformationMatrix\");				\n";
		$actionCommand += "	textField -e -tx $sel[0] (\""+$type+"_ref_tf\");							\n";
		$actionCommand += "	symbolButton -e -i \"inArrow.xpm\" -command (\"select \"+$sel[0]+\";\") (\""+$type+"_ref_button\");	\n";
		$actionCommand += "}														";
		symbolButton -e -i "addy.xpm" -command $actionCommand ($type+"_ref_button");
	}
	
	if( catchQuiet ($pParams = `connectionInfo -sfd ($attr+"inShapeCurves[0]")`)) $pParams="";	//refCurve
	if(`size($pParams)`!=0){
		string $conInput[];
		tokenize($pParams, ".", $conInput);
		textField -e -tx $conInput[0] ($type+"_refCurve_tf");
		symbolButton -e -i "inArrow.xpm" -command ("select "+$conInput[0]+";") ($type+"_refCurve_button");
	} else {
		textField -e -tx "<no connection>" ($type+"_refCurve_tf");
		$actionCommand  = "string $sel[]=`ls -selection`;										\n";
		$actionCommand += "if(`size($sel)`==2){												\n";
		$actionCommand += "	connectAttr ($sel[0]+\".worldSpace[0]\") (\""+$attr+"inShapeCurves[0]\");				\n";
		$actionCommand += "	textField -e -tx $sel[0] (\""+$type+"_refCurve_tf\");							\n";
		$actionCommand += "	symbolButton -e -i \"inArrow.xpm\" -command (\"select \"+$sel[0]+\";\") (\""+$type+"_refCurve_button\");	\n";
		$actionCommand += "}														";
		symbolButton -e -i "addy.xpm" -command $actionCommand ($type+"_refCurve_button");
	}
}

global proc tropismAlternateNewAttrib(string $attr)
{
	tropismAlternateReplaceAttrib($attr);
}

global proc tropismAlternateReplaceAttrib(string $attr)
{
	$type = `nodeType ($attr)`;
	string $altInput[];
	tokenize($attr, ".", $altInput);
	string $parentName[] = `listRelatives -parent ($altInput[0])`;
	
	int $freePlug = -1;
	if(!`layout -exists ($type+"_alternate_layout")`) columnLayout ($type+"_alternate_layout");
	
	setParent ($type+"_alternate_layout");
	if(!`layout -exists ($type+"_alternate_line_layout")`) rowLayout -nc 3 ($type+"_alternate_line_layout"); //alternate
	if(!`text -exists ($type+"_alternate_fill")`){
		setParent ($type+"_alternate_line_layout");
		text -label ("") ($type+"_alternate_fill");
	}
	if(!`text -exists ($type+"_alternate_text")`){
		setParent ($type+"_alternate_line_layout");
		text -label ("Generate alternate curve") -align "right" ($type+"_alternate_text");
	}
	if(!`symbolButton -exists ($type+"_alternate_button")`){
			setParent ($type+"_alternate_line_layout");
			symbolButton -i "addy.xpm" -h 20 ($type+"_alternate_button");
	}


	int $altIdxList[] = `getAttr -mi ($altInput[0]+".alternateOffs")`;
	string $altlist[] = `listConnections -d off -s on -p on -c on ($attr)`;
	int $altCount  = -1;
	for ($i=0; $i<`size($altIdxList)`; $i++) if ($altIdxList[$i] > $altCount) $altCount = $altIdxList[$i];
	for ($i=0; $i<`size($altlist)`/2; $i++) {
		string $conInput[];
		tokenize($altlist[$i*2], "[", $conInput);
		string $plugOffsetString = $conInput[(`size($conInput)`-1)];
		int $plugOffsetStringLength = `size($plugOffsetString)`-1;
		$plugOffsetString = `substring $plugOffsetString 1 $plugOffsetStringLength`;
		int $plugOffset = $plugOffsetString;
		if ($plugOffset > $altCount) $altCount = $plugOffset;
	}
	$altCount++;
	int $altIterate=0;
	while(`layout -exists ($type+"_alternate_"+$altIterate+"_layout1")`){
		$altIterate++;	
	}
	if($altCount>$altIterate){	// create additional lines
		for($i=$altIterate; $i<$altCount; $i++){
			setParent ($type+"_alternate_layout");
			rowLayout -nc 3 ($type+"_alternate_"+$i+"_layout1");
			text -label ("Offset "+$i) ($type+"_alternate_"+$i+"_text1");
			textField  -ed 1 -tx "" ($type+"_alternate_"+$i+"_offset_tf");
			text -label ("") ($type+"_alternate_"+$i+"_fill");
			setParent ($type+"_alternate_layout");
			rowLayout -nc 3 ($type+"_alternate_"+$i+"_layout2");
			text -label ("Alternate "+$i) ($type+"_alternate_"+$i+"_text2");
			textField  -ed 0 -tx "<no connection>" ($type+"_alternate_"+$i+"_tf");
			symbolButton -i "addy.xpm" -h 20 ($type+"_alternate_"+$i+"_switch_button");
		}
	}
	if($altCount<$altIterate){	// delete unneeded lines
		for($i=$altCount; $i<$altIterate; $i++){
			deleteUI -control ($type+"_alternate_"+$i+"_text1");
			deleteUI -control ($type+"_alternate_"+$i+"_offset_tf");
			deleteUI -control ($type+"_alternate_"+$i+"_fill");
			deleteUI -control ($type+"_alternate_"+$i+"_text2");
			deleteUI -control ($type+"_alternate_"+$i+"_tf");
			deleteUI -control ($type+"_alternate_"+$i+"_switch_button");
			deleteUI -layout ($type+"_alternate_"+$i+"_layout1");
			deleteUI -layout ($type+"_alternate_"+$i+"_layout2");
		}
	}
	for($i=0; $i<$altCount; $i++){
		text -e -label ("Offset ["+$i+"]") ($type+"_alternate_"+$i+"_text1");
		text -e -label ("Alternate Curve["+$i+"]") ($type+"_alternate_"+$i+"_text2");
		string $changeCommand = "setAttr (\"" + $altInput[0] + ".alternateOffs["+$i+"]\") -type \"string\" (`textField -q -tx (\"" + $type + "_alternate_" + $i + "_offset_tf\")`);\n";
		string $changeValue = `getAttr ($altInput[0] + ".alternateOffs["+$i+"]")`;
		textField -e -tx ($changeValue) -cc ($changeCommand) ($type+"_alternate_"+$i+"_offset_tf");
		string $altlist[] = `listConnections -d off -s on -p on ($attr+"["+$i+"]")`;
		if (`size($altlist)`>0) {
			string $conInput[];
			tokenize($altlist[0], ".", $conInput);
			textField -e -tx $conInput[0] ($type+"_alternate_"+$i+"_tf");
			symbolButton -e -i "inArrow.xpm" -h 20 -command ("select "+$conInput[0]+";") ($type+"_alternate_"+$i+"_switch_button");
		} else {
			$actionCommand  = "string $sel[]=`ls -selection`;																								\n";
			$actionCommand += "if(`size($sel)`==2){																											\n";
			$actionCommand += "	connectAttr ($sel[0]+\".worldSpace[0]\") (\""+$altInput[0]+".alternateCurvs["+$i+"]\");										\n";
			$actionCommand += "	parent ($sel[0]) (\"" + $parentName[0] + "\");																				\n";
			$actionCommand += " select (\"" + $altInput[0] + "\");																							\n";
			$actionCommand += "}																															";
			textField -e -tx "<no connection>" ($type+"_alternate_"+$i+"_tf");
			symbolButton -e -i "addy.xpm" -h 20 -command $actionCommand ($type+"_alternate_"+$i+"_switch_button");
		}
	}
	
	string $actionCommand	= "setAttr (\"" + $altInput[0] + ".alternateOffs[" + $altCount + "]\") -type \"string\" \"\";									";
	symbolButton -e -command $actionCommand ($type+"_alternate_button");
}