// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto.  Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//

// clang-format off
#include "UsdPCH.h"
// clang-format on

#include <omni/usd/Selection.h>
#include <omni/usd/UsdContext.h>

#include <OgnIsPrimSelectedDatabase.h>


namespace omni
{
namespace graph
{
namespace nodes
{

class OgnIsPrimSelected
{
public:
    static bool compute(OgnIsPrimSelectedDatabase& db)
    {
        omni::usd::UsdContext* usdContext = omni::usd::UsdContext::getContext();
        NameToken primPathToken = db.inputs.primPath();
        bool isSelected {false};
        if (primPathToken != carb::flatcache::kUninitializedToken)
        {
            char const* primPath = db.abi_context().iToken->getText(primPathToken);
            if (primPath)
                isSelected = usdContext->getSelection()->isPrimPathSelected(primPath);
        }
        db.outputs.isSelected() = isSelected;
        return true;
    }
};

REGISTER_OGN_NODE()

} // nodes
} // graph
} // omni
