// 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:  Mar 14, 1997
//
//  Description:
//      This script is doing the boundary work.
//


global proc performBoundaryPreset( int $doHistory, int $order,
								   int $insist, int $partial,
								   int $polys, int $useGlobal,
								   float $globalTol, float $localTol )
{
	// Get a list of each type of acceptable object type - 
	// s, and s-on-surface.
	//
	global int $gSelectIsoparmsBit;
	global int $gSelectNurbsCurvesBit;
	global int $gSelectSurfaceEdgeBit;
	global int $gSelectCurvesOnSurfacesBit;
	global int $gSelectMeshEdge;

	string $list[] = `filterExpand -ex true -sm $gSelectMeshEdge -sm $gSelectIsoparmsBit -sm $gSelectNurbsCurvesBit -sm $gSelectSurfaceEdgeBit -sm $gSelectCurvesOnSurfacesBit`;

	// Execute boundary on all active s.
	//
	$cmd = "boundary" + " -ch " + $doHistory + 
		   " -or " + $order +
		   " -ep " + $insist + 
		   " -rn " + $partial +
		   " -po " + $polys;

	if( $useGlobal ) {
		$cmd += " -ept " + $globalTol;
	}
	else {
		$cmd += " -ept " + $localTol;
	}

	int $i, $n = size($list);
	if( $n > 4 ) {
		warning ("Boundary: Too many curves (" + $n + ").  Select 3 or 4.");
		$n = 4;
	}

	if( $n < 3 ) {
		error ("Boundary: Not enough curves (" + $n + ").  Select 3 or 4.");
		return;
	}

	for( $i=0; $i<$n; $i+=1 ) {
		$cmd = $cmd + " \"" + $list[$i] + "\"";
	}
	string $results[] = evalEcho($cmd);

	if( 0 == size($results) ) {
		error ("Boundary: Operation failed.");
	}
	else {
		select -r $results[0];
	}
}

