// 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.

// Description:  This procedure is called to start the IMR render
//      for the mentalray renderer.
//
global proc mentalrayStartImrRender(
    string $editor, int $resolution0, int $resolution1, string $camera)
{	
	// Create and connect imr preset
	string $imrOption = mentalrayImrPreset();
	string $currentSettings = "";
    if( $imrOption != "" )
    {
		// 
		// HACK ON HACK: The IMR preset should be used for the regular rendering before IMR.
		//		If the above hack is killed, this ugly hack should go away.
		//
		// This hacky code below overlaps with mentalrayPreviewRender
		//
		string $selection[] = `ls -sl`;
		$currentSettings = `createNode mentalrayOptions`;
		copyNode miDefaultOptions $currentSettings;
		copyNode $imrOption miDefaultOptions;		
		select -noExpand $selection;
    }

    // HACK:  This line of doing "render" is a temporary solution 
    //     to the testResolution change.      
    //     Mayatomr command's -region -x -y command currently 
    //     do not work properly when the -imr flag is used.
    // 
    //     This line should be removed, whence mental fixes this problem.
    //    
    mentalrayRenderViewRender(
        $resolution0, $resolution1,
        $camera, "render", "");

    mentalrayRenderViewRender(
        $resolution0, $resolution1,
        $camera, "IMR", "");

	// restore rendering option
	if( $imrOption != "" )
	{
		copyNode $currentSettings miDefaultOptions;
		delete $currentSettings;
	}

    renderWindowRefreshLayout($editor);

    // Prompt the user to select a region to begin tuning
    //
    renderWindowEditor 
        -edit
        -caption "Select a region to begin tuning"
        $editor;
}
