// 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.

//
//  Procedure Name:
//      renderLayerPresetMenu
//
//  Description:
//		Build a menu for managing user presets with the "nodePreset" command,
//      or applying built-in presets.
//
//  Input Arguments:
//      $presetMenu - the name of the menu control
//      $node       - the name of the render layer to create the menu for
//
//  Return Value:
//      None
//

global proc renderLayerPresetMenu( string $presetMenu, string $node )
{
    setParent -menu $presetMenu;

    popupMenu -e -deleteAllItems $presetMenu;

        // Menu items for built-in presets
        //

        menuItem -label "Luminance Depth" -command ("renderLayerBuiltinPreset linearDepth "+$node);
        menuItem -label "Occlusion" -command ("renderLayerBuiltinPreset occlusion "+$node);
        menuItem -label "Geometry Matte"     -command ("renderLayerBuiltinPreset matte "+$node);
        menuItem -label "Diffuse"   -command ("renderLayerBuiltinPreset diffuse "+$node);
        menuItem -label "Specular"  -command ("renderLayerBuiltinPreset specular "+$node);
        menuItem -label "Shadow"    -command ("renderLayerBuiltinPreset shadow "+$node);

        menuItem -divider true;

        string $presets[] = `nodePreset -list $node`;

        // Menu items for managing user presets
        //

        string $script = "renderLayerSaveCustomPreset(\"#nodeName\",\"#presetName\")";
        menuItem -label ("Save Preset...") -command
            ("saveNodePresetDialog { "+
                "\""+$node+"\""+
                ", \"-custom\""+
                ", \""+encodeString($script)+"\""+
                ", \"-attributes\""+
                ", \"renderPassInfo attributeOverrideScript\""+
                " }");
        
        if (size($presets) > 0) {
            // There are user presets, create a menu and sub-items
            // to delete them.

            menuItem -label ("Delete Preset") -subMenu true;

            for ($item in $presets) {
                menuItem -label $item -command
                    ("nodePresetConfirmDeleteDialog { "+
                        "\""+$node+"\""+
                        ", \""+$item+"\""+
                        " }");
            }

            setParent -menu ..;
        }

        menuItem -divider true;

        // Menu items for applying the user presets
        //

        for ($item in $presets) {
            menuItem -label $item
                -command ("nodePreset -load "+$node+" "+$item);
        }
}
