// 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:  4 April 1997
//
//  Description:
//      Part of the option box for the nurbs to poly conversion.
//

//
//  Procedure Name:
//      nurbsToPolyAddOptions
//
//  Description:
//		Construct the option box UI.  Involves accessing the standard option
//		box and customizing the UI accordingly.
//
//  Input Arguments:
//      None.
//
//  Return Value:
//      None.
//

global proc nurbsToPolyAddOptions( string $parent )
{
	setUITemplate -pushTemplate DefaultTemplate;
	setParent $parent;

	checkBoxGrp -label ""
		-numberOfCheckBoxes 1
		-label1 "Attach Multiple Output Meshes"
		-changeCommand ("mergeMeshesOptionChanged " + $parent)
		mergeBox;

  	floatSliderGrp -label "Merge Tolerance"
		-min 0.0 -max 1.0
		mergeTolerance;

	separator -w 1000; 

	checkBoxGrp -label ""
		-numberOfCheckBoxes 1
		-label1 "Match Render Tessellation"
		-changeCommand ("renderTessellationOptionChanged " + $parent)
		matchRenderTessellationBox;

	separator -w 1000; 

	radioButtonGrp
		-nrb 2
		-label "Type"
		-l1 "Triangles"
		-l2 "Quads"
		type;

	//
	// Ghost the Type controls if the Tessellation method is set
	// to Control Points (format == 3)
	//
	int $format = `nurbsToPolygonsPref -q -f`;
	if ($format == 3) {
		radioButtonGrp -edit -enable 0 type;
	} else {
		radioButtonGrp -edit -enable 1 type;
	}

	string $radioBtnGrp1 =`radioButtonGrp
		-nrb 2
		-label "Tessellation Method"
		-l1 "General"
		-l2 "Count"
		-cc1 ("nurbsToPolyVisibility " + $parent + " 2")
		-cc2 ("nurbsToPolyVisibility " + $parent + " 0")
		format`;

	radioButtonGrp
		-shareCollection $radioBtnGrp1
		-nrb 2
		-label ""
		-l1 "Standard Fit"
		-l2 "Control Points"
		-cc1 ("nurbsToPolyVisibility " + $parent + " 1")
		-cc2 ("nurbsToPolyVisibility " + $parent + " 3")
		format2;

	separator -w 1000; 

	tabLayout -tabsVisible false formatTabs;

		columnLayout tabGeneral;
			text -l " Initial Tessellation Controls";

            optionMenuGrp -l "U Type" uType;
                menuItem -l "Per Surf # of Iso Params in 3D";
                menuItem -l "Per Surf # of Iso Params";
                menuItem -l "Per Span # of Iso Params";

			intSliderGrp -label "Number U"
				-min 1 -max 32 -fmx 10000
				uNumber;

            optionMenuGrp -l "V Type" vType;
                menuItem -l "Per Surf # of Iso Params in 3D";
                menuItem -l "Per Surf # of Iso Params";
                menuItem -l "Per Span # of Iso Params";

			intSliderGrp -label "Number V"
				-min 1 -max 32 -fmx 10000
				vNumber;

			columnLayout secondary;
				separator -w 1000;
				text -l " Secondary Tessellation Controls";
				checkBoxGrp -ncb 1 -l1 "Use Chord Height" useChordHeight;
				floatSliderGrp -l "Chord Height"
					-fmn 0.01 -fmx 0.2 -min 0.01 -max 0.2
					chordHeight;

				checkBoxGrp -ncb 1 -l1 "Use Chord Height Ratio" useChordHeightRatio;
				floatSliderGrp -l "Chord Height Ratio"
					-min 0.9 -max 0.99 -fmn 0.01 -fmx 0.999 
					ratioG;

				checkBoxGrp -ncb 1 -l1 "Edge Swap" edgeSwap;
			setParent ..;

		setParent ..;

		columnLayout tabStandard;
			floatSliderGrp -l "Chord Height Ratio"
				-min 0.9 -max 0.99 -fmn 0.01 -fmx 0.999 
				ratioS;
			floatSliderGrp -l "Fractional Tolerance"
				-fmn 0.000001 -fmx 1000 -min 0.001 -max 1.0
				fractional;
			floatSliderGrp -l "Minimal Edge Length"
				-min 0.0001 -fmn 0.0001 -max 1.0 -fmx 1000
				minEdgeLength;
			floatSliderGrp -l "3D Delta"
				-min 0.01 -max 1.0 -fmx 1000 delta;
		setParent ..;

		columnLayout tabCount;
			intSliderGrp -label "Count"
				-min 1 -max 1000 -fmx 1000000
				count;
		setParent ..;

		columnLayout tabNothing;
		setParent ..;
	setParent ..;

	setUITemplate -popTemplate;
}

global proc mergeMeshesOptionChanged ( string $parent )
{
    int $merge = `checkBoxGrp -q -value1 mergeBox`;

    //    
    // If the merge meshes option is checked we have to make sure that
    // any of the tessellation methods that don't work with it are not
    // chosen, for now this is just the control points method.  If a
    // a conflicting method is chosen then change to the general method.
    //
    if ($merge) {
        int $format = `radioButtonGrp -q -sl format2`;
        if ($format == 2) {
            radioButtonGrp -edit -select 1 format;
            nurbsToPolyVisibility $parent 2;            
        }
    } 
	checkBoxGrp -edit -enable (!$merge) matchRenderTessellationBox;
    radioButtonGrp -edit -enable2 (!$merge) format2;
    floatSliderGrp -edit -enable $merge mergeTolerance;    
}

global proc renderTessellationOptionChanged ( string $parent )
{
    int $match = `checkBoxGrp -q -value1 matchRenderTessellationBox`;

    // If the match tessellation option is checked we have disable all
    // the explicit tessellation settings
    radioButtonGrp -edit -enable (!$match) type;
    radioButtonGrp -edit -enable (!$match) format;
    radioButtonGrp -edit -enable (!$match) format2;
    tabLayout -edit -enable (!$match) formatTabs;    
}
