// Copyright (C) 1997-2014 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.

// FILE: AEbifrostContainerRelated.mel
// INPUT: string (node name)
// RETURN:	string[] (list of related nodes, with the node whose
//			tab you want to be opened duplicated at the
//			end of the array)
//

global proc string[] AEbifrostContainerRelated( string $node )
{
	string $retval[];

	$retval[0] = $node;

	// Skip the default render render nodes, it's not renderable anyway
	//string $relNodes[] = `defaultNavigation -ren -d $node`;
	string $preferredNode = `defaultNavigation -dwn -d $node`;


	string $plugs[] = `listConnections -s false -sh true -d true $node`;
	for( $plug in $plugs ) {
		string $nType = `nodeType $plug`;
		if( $nType == "bifrostShape" ){
			$retval[size($retval)] = $plug;
		} 
	}

	// Now check the source connections to the bifrostContainer node for PFX strokes and Nucleus nodes

	string $nodes[] = `listHistory -future false $node`;
	string $hNode;

	// Check the src connections for Nucleus nodes too
	// i.e. look for nCloth or nRigid nodes, and if we find one, get the nucleus solver node that
	// its associated with. We stop after finding one, which should cover most cases
	// at worst we might miss some if we had a polyUnite of cloth objects or something

	for( $hNode in $nodes ) {
		string $nType = `nodeType $hNode`;
		if( $nType == "mesh" ){
			$retval[size($retval)] = $hNode;
		}

	}
	
	if( $preferredNode == "" ) {
		$preferredNode = $node;
	}
	$retval[size($retval)] = $preferredNode;

	
	return $retval;

}

