/******************************************************************************
	NINTENDO NITRO-System Maya Plugin

	File:         NNS_ShowDispFace.mel
	Description:  show disp face
	Date:         2004/11/29
	Author:       T.Endo

	Copyright 2003-2006 Nintendo. All rights reserved.
******************************************************************************/

/******************************************************************************
	show	
******************************************************************************/
global proc nnsShowDispFace_Show(int $disp_face_show)
{
	int $sg_count = 0;
	select -cl;
	string $sgs[] = `ls -typ shadingEngine`;
	for ($sg in $sgs) {
		if ($sg == "initialParticleSE" || $sg == "swatchShadingGroup")
			continue;
		int $disp_face = (`attributeQuery -n $sg -ex "nns_disp_face"`) ?
			`getAttr ($sg + ".nns_disp_face")` : 0;
		if ($disp_face == $disp_face_show) {
			select -add $sg;		// face
			select -add -ne $sg;	// shadingEngine
			++$sg_count;
		}
	}

	if ($sg_count == 0)
		print "Not found\n";
	else {
		string $msg = "Found: " + $sg_count + " shadingEngine node";
		if ($sg_count >= 2)
			$msg += "s";
		print ($msg + "\n");
	}
}

/******************************************************************************
	main
******************************************************************************/
global proc NNS_ShowDispFace()
{

//-----------------------------------------------------------------------------
// backup selection
	string $sel_bak[] = `ls -sl`;
	string $sel_bak_str;
	for ($sel in $sel_bak)
		$sel_bak_str += ($sel + " ");
	select -cl;
	
//-----------------------------------------------------------------------------
// create window
	int $wd = 450;
	int $ht = 140;
	if (!`window -exists nnsShowDispFace_Win`) {
		string $close_cmd = "deleteUI nnsShowDispFace_Win";
		string $remain_cmd = "if (!`checkBoxGrp -q -v1 nnsShowDispFace_KeepSelecion`) {"
			+ "select -cl;select -ne " + $sel_bak_str + ";}";

		window -t "NITRO Show Display Face" -wh $wd $ht -mxb 0
			nnsShowDispFace_Win;

		columnLayout -adj 1 -cat "both" 4 -cal "center" -rs 15;
			radioButtonGrp -nrb 3 -l "Display Face"
				-la3 "Front Face" "Back Face" "Both Face"
				-cw4 100 100 100 100
				-cc "nnsShowDispFace_Show(`radioButtonGrp -q -sl nnsShowDispFace_DispFace` - 1)"
				nnsShowDispFace_DispFace;
			checkBoxGrp -ncb 1 -l "" -l1 "Keep Selection" -v1 1
				-cw 1 180
				nnsShowDispFace_KeepSelecion;
			button -h 26 -l "Close"
				-c ($remain_cmd + $close_cmd);
		setParent ..;	// columnLayout
	}
	window -e -wh $wd $ht nnsShowDispFace_Win;

//-----------------------------------------------------------------------------
// show window
	showWindow nnsShowDispFace_Win;
}
