"""Support for simplified access to data on nodes of type omni.syntheticdata.SdInstanceMappingPtr

Synthetic Data node to expose the scene instances semantic hierarchy information
"""

import numpy

import omni.graph.core as og
import omni.graph.core._omni_graph_core as _og
import omni.graph.tools.ogn as ogn



class OgnSdInstanceMappingPtrDatabase(og.Database):
    """Helper class providing simplified access to data on nodes of type omni.syntheticdata.SdInstanceMappingPtr

    Class Members:
        node: Node being evaluated

    Attribute Value Properties:
        Inputs:
            inputs.cudaPtr
            inputs.exec
            inputs.renderResults
            inputs.semanticFilerTokens
        Outputs:
            outputs.cudaDeviceIndex
            outputs.exec
            outputs.instanceMapPtr
            outputs.instancePrimPathPtr
            outputs.lastUpdateTimeDenominator
            outputs.lastUpdateTimeNumerator
            outputs.minInstanceIndex
            outputs.minSemanticIndex
            outputs.numInstances
            outputs.numSemantics
            outputs.semanticLabelTokenPtrs
            outputs.semanticLocalTransformPtr
            outputs.semanticMapPtr
            outputs.semanticPrimPathPtr
            outputs.semanticWorldTransformPtr

    Predefined Tokens:
        tokens.InstanceMappingInfoSDhost
        tokens.InstancePrimTokenSDhost
        tokens.InstancePrimTokenSD
        tokens.SemanticPrimTokenSDhost
        tokens.SemanticPrimTokenSD
        tokens.InstanceMapSDhost
        tokens.InstanceMapSD
        tokens.SemanticMapSDhost
        tokens.SemanticMapSD
        tokens.SemanticWorldTransformSDhost
        tokens.SemanticWorldTransformSD
        tokens.SemanticLocalTransformSDhost
        tokens.SemanticLocalTransformSD
        tokens.SemanticLabelTokenSDhost
        tokens.SemanticLabelTokenSD
    """

    # Imprint the generator and target ABI versions in the file for JIT generation
    GENERATOR_VERSION = (1, 41, 3)
    TARGET_VERSION = (2, 139, 12)

    # This is an internal object that provides per-class storage of a per-node data dictionary
    PER_NODE_DATA = {}

    # This is an internal object that describes unchanging attributes in a generic way
    # The values in this list are in no particular order, as a per-attribute tuple
    #     Name, Type, ExtendedTypeIndex, UiName, Description, Metadata,
    #     Is_Required, DefaultValue, Is_Deprecated, DeprecationMsg
    # You should not need to access any of this data directly, use the defined database interfaces
    INTERFACE = og.Database._get_interface([
        ('inputs:cudaPtr', 'bool', 0, None, 'If true, return cuda device pointer instead of host pointer', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('inputs:exec', 'execution', 0, None, 'Trigger', {}, True, None, False, ''),
        ('inputs:renderResults', 'uint64', 0, None, 'Render results pointer', {}, True, 0, False, ''),
        ('inputs:semanticFilerTokens', 'token[]', 0, None, 'Tokens identifying the semantic filters applied to the output semantic labels. Each token should correspond to an activated SdSemanticFilter node', {ogn.MetadataKeys.DEFAULT: '[]'}, True, [], False, ''),
        ('outputs:cudaDeviceIndex', 'int', 0, None, 'If the data is on the device it is the cuda index of this device otherwise it is set to -1', {ogn.MetadataKeys.DEFAULT: '-1'}, True, -1, False, ''),
        ('outputs:exec', 'execution', 0, 'Received', 'Executes when the event is received', {}, True, None, False, ''),
        ('outputs:instanceMapPtr', 'uint64', 0, None, 'Array pointer of numInstances uint16_t containing the semantic index of the instance prim first semantic prim parent', {}, True, None, False, ''),
        ('outputs:instancePrimPathPtr', 'uint64', 0, None, 'Array pointer of numInstances uint64_t containing the prim path tokens for every instance prims', {}, True, None, False, ''),
        ('outputs:lastUpdateTimeDenominator', 'uint64', 0, None, 'Time denominator of the last time the data has changed', {}, True, None, False, ''),
        ('outputs:lastUpdateTimeNumerator', 'int64', 0, None, 'Time numerator of the last time the data has changed', {}, True, None, False, ''),
        ('outputs:minInstanceIndex', 'uint', 0, None, 'Instance index of the first instance prim in the instance arrays', {}, True, None, False, ''),
        ('outputs:minSemanticIndex', 'uint', 0, None, 'Semantic index of the first semantic prim in the semantic arrays', {}, True, None, False, ''),
        ('outputs:numInstances', 'uint', 0, None, 'Number of instances prim in the instance arrays', {}, True, None, False, ''),
        ('outputs:numSemantics', 'uint', 0, None, 'Number of semantic prim in the semantic arrays', {}, True, None, False, ''),
        ('outputs:semanticLabelTokenPtrs', 'uint64[]', 0, None, 'Array containing for every input semantic filters the corresponding array pointer of numSemantics uint64_t representing the semantic label of the semantic prim', {}, True, None, False, ''),
        ('outputs:semanticLocalTransformPtr', 'uint64', 0, None, 'Array pointer of numSemantics 4x4 float matrices containing the transform from world to object space for every semantic prims', {}, True, None, False, ''),
        ('outputs:semanticMapPtr', 'uint64', 0, None, 'Array pointer of numSemantics uint16_t containing the semantic index of the semantic prim first semantic prim parent', {}, True, None, False, ''),
        ('outputs:semanticPrimPathPtr', 'uint64', 0, None, 'Array pointer of numSemantics uint32_t containing the prim part of the prim path tokens for every semantic prims', {}, True, None, False, ''),
        ('outputs:semanticWorldTransformPtr', 'uint64', 0, None, 'Array pointer of numSemantics 4x4 float matrices containing the transform from local to world space for every semantic entity', {}, True, None, False, ''),
    ])

    class tokens:
        InstanceMappingInfoSDhost = "InstanceMappingInfoSDhost"
        InstancePrimTokenSDhost = "InstancePrimTokenSDhost"
        InstancePrimTokenSD = "InstancePrimTokenSD"
        SemanticPrimTokenSDhost = "SemanticPrimTokenSDhost"
        SemanticPrimTokenSD = "SemanticPrimTokenSD"
        InstanceMapSDhost = "InstanceMapSDhost"
        InstanceMapSD = "InstanceMapSD"
        SemanticMapSDhost = "SemanticMapSDhost"
        SemanticMapSD = "SemanticMapSD"
        SemanticWorldTransformSDhost = "SemanticWorldTransformSDhost"
        SemanticWorldTransformSD = "SemanticWorldTransformSD"
        SemanticLocalTransformSDhost = "SemanticLocalTransformSDhost"
        SemanticLocalTransformSD = "SemanticLocalTransformSD"
        SemanticLabelTokenSDhost = "SemanticLabelTokenSDhost"
        SemanticLabelTokenSD = "SemanticLabelTokenSD"

    @classmethod
    def _populate_role_data(cls):
        """Populate a role structure with the non-default roles on this node type"""
        role_data = super()._populate_role_data()
        role_data.inputs.exec = og.AttributeRole.EXECUTION
        role_data.outputs.exec = og.AttributeRole.EXECUTION
        return role_data

    class ValuesForInputs(og.DynamicAttributeAccess):
        LOCAL_PROPERTY_NAMES = { }
        """Helper class that creates natural hierarchical access to input attributes"""
        def __init__(self, node: og.Node, attributes, dynamic_attributes: og.DynamicAttributeInterface):
            """Initialize simplified access for the attribute data"""
            context = node.get_graph().get_default_graph_context()
            super().__init__(context, node, attributes, dynamic_attributes)
            self._batchedReadAttributes = []
            self._batchedReadValues = []

        @property
        def cudaPtr(self):
            data_view = og.AttributeValueHelper(self._attributes.cudaPtr)
            return data_view.get()

        @cudaPtr.setter
        def cudaPtr(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.cudaPtr)
            data_view = og.AttributeValueHelper(self._attributes.cudaPtr)
            data_view.set(value)

        @property
        def exec(self):
            data_view = og.AttributeValueHelper(self._attributes.exec)
            return data_view.get()

        @exec.setter
        def exec(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.exec)
            data_view = og.AttributeValueHelper(self._attributes.exec)
            data_view.set(value)

        @property
        def renderResults(self):
            data_view = og.AttributeValueHelper(self._attributes.renderResults)
            return data_view.get()

        @renderResults.setter
        def renderResults(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.renderResults)
            data_view = og.AttributeValueHelper(self._attributes.renderResults)
            data_view.set(value)

        @property
        def semanticFilerTokens(self):
            data_view = og.AttributeValueHelper(self._attributes.semanticFilerTokens)
            return data_view.get()

        @semanticFilerTokens.setter
        def semanticFilerTokens(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.semanticFilerTokens)
            data_view = og.AttributeValueHelper(self._attributes.semanticFilerTokens)
            data_view.set(value)
            self.semanticFilerTokens_size = data_view.get_array_size()

        def _prefetch(self):
            readAttributes = self._batchedReadAttributes
            newValues = _og._prefetch_input_attributes_data(readAttributes)
            if len(readAttributes) == len(newValues):
                self._batchedReadValues = newValues

    class ValuesForOutputs(og.DynamicAttributeAccess):
        LOCAL_PROPERTY_NAMES = { }
        """Helper class that creates natural hierarchical access to output attributes"""
        def __init__(self, node: og.Node, attributes, dynamic_attributes: og.DynamicAttributeInterface):
            """Initialize simplified access for the attribute data"""
            context = node.get_graph().get_default_graph_context()
            super().__init__(context, node, attributes, dynamic_attributes)
            self.semanticLabelTokenPtrs_size = None
            self._batchedWriteValues = { }

        @property
        def cudaDeviceIndex(self):
            data_view = og.AttributeValueHelper(self._attributes.cudaDeviceIndex)
            return data_view.get()

        @cudaDeviceIndex.setter
        def cudaDeviceIndex(self, value):
            data_view = og.AttributeValueHelper(self._attributes.cudaDeviceIndex)
            data_view.set(value)

        @property
        def exec(self):
            data_view = og.AttributeValueHelper(self._attributes.exec)
            return data_view.get()

        @exec.setter
        def exec(self, value):
            data_view = og.AttributeValueHelper(self._attributes.exec)
            data_view.set(value)

        @property
        def instanceMapPtr(self):
            data_view = og.AttributeValueHelper(self._attributes.instanceMapPtr)
            return data_view.get()

        @instanceMapPtr.setter
        def instanceMapPtr(self, value):
            data_view = og.AttributeValueHelper(self._attributes.instanceMapPtr)
            data_view.set(value)

        @property
        def instancePrimPathPtr(self):
            data_view = og.AttributeValueHelper(self._attributes.instancePrimPathPtr)
            return data_view.get()

        @instancePrimPathPtr.setter
        def instancePrimPathPtr(self, value):
            data_view = og.AttributeValueHelper(self._attributes.instancePrimPathPtr)
            data_view.set(value)

        @property
        def lastUpdateTimeDenominator(self):
            data_view = og.AttributeValueHelper(self._attributes.lastUpdateTimeDenominator)
            return data_view.get()

        @lastUpdateTimeDenominator.setter
        def lastUpdateTimeDenominator(self, value):
            data_view = og.AttributeValueHelper(self._attributes.lastUpdateTimeDenominator)
            data_view.set(value)

        @property
        def lastUpdateTimeNumerator(self):
            data_view = og.AttributeValueHelper(self._attributes.lastUpdateTimeNumerator)
            return data_view.get()

        @lastUpdateTimeNumerator.setter
        def lastUpdateTimeNumerator(self, value):
            data_view = og.AttributeValueHelper(self._attributes.lastUpdateTimeNumerator)
            data_view.set(value)

        @property
        def minInstanceIndex(self):
            data_view = og.AttributeValueHelper(self._attributes.minInstanceIndex)
            return data_view.get()

        @minInstanceIndex.setter
        def minInstanceIndex(self, value):
            data_view = og.AttributeValueHelper(self._attributes.minInstanceIndex)
            data_view.set(value)

        @property
        def minSemanticIndex(self):
            data_view = og.AttributeValueHelper(self._attributes.minSemanticIndex)
            return data_view.get()

        @minSemanticIndex.setter
        def minSemanticIndex(self, value):
            data_view = og.AttributeValueHelper(self._attributes.minSemanticIndex)
            data_view.set(value)

        @property
        def numInstances(self):
            data_view = og.AttributeValueHelper(self._attributes.numInstances)
            return data_view.get()

        @numInstances.setter
        def numInstances(self, value):
            data_view = og.AttributeValueHelper(self._attributes.numInstances)
            data_view.set(value)

        @property
        def numSemantics(self):
            data_view = og.AttributeValueHelper(self._attributes.numSemantics)
            return data_view.get()

        @numSemantics.setter
        def numSemantics(self, value):
            data_view = og.AttributeValueHelper(self._attributes.numSemantics)
            data_view.set(value)

        @property
        def semanticLabelTokenPtrs(self):
            data_view = og.AttributeValueHelper(self._attributes.semanticLabelTokenPtrs)
            return data_view.get(reserved_element_count=self.semanticLabelTokenPtrs_size)

        @semanticLabelTokenPtrs.setter
        def semanticLabelTokenPtrs(self, value):
            data_view = og.AttributeValueHelper(self._attributes.semanticLabelTokenPtrs)
            data_view.set(value)
            self.semanticLabelTokenPtrs_size = data_view.get_array_size()

        @property
        def semanticLocalTransformPtr(self):
            data_view = og.AttributeValueHelper(self._attributes.semanticLocalTransformPtr)
            return data_view.get()

        @semanticLocalTransformPtr.setter
        def semanticLocalTransformPtr(self, value):
            data_view = og.AttributeValueHelper(self._attributes.semanticLocalTransformPtr)
            data_view.set(value)

        @property
        def semanticMapPtr(self):
            data_view = og.AttributeValueHelper(self._attributes.semanticMapPtr)
            return data_view.get()

        @semanticMapPtr.setter
        def semanticMapPtr(self, value):
            data_view = og.AttributeValueHelper(self._attributes.semanticMapPtr)
            data_view.set(value)

        @property
        def semanticPrimPathPtr(self):
            data_view = og.AttributeValueHelper(self._attributes.semanticPrimPathPtr)
            return data_view.get()

        @semanticPrimPathPtr.setter
        def semanticPrimPathPtr(self, value):
            data_view = og.AttributeValueHelper(self._attributes.semanticPrimPathPtr)
            data_view.set(value)

        @property
        def semanticWorldTransformPtr(self):
            data_view = og.AttributeValueHelper(self._attributes.semanticWorldTransformPtr)
            return data_view.get()

        @semanticWorldTransformPtr.setter
        def semanticWorldTransformPtr(self, value):
            data_view = og.AttributeValueHelper(self._attributes.semanticWorldTransformPtr)
            data_view.set(value)

        def _commit(self):
            _og._commit_output_attributes_data(self._batchedWriteValues)
            self._batchedWriteValues = { }

    class ValuesForState(og.DynamicAttributeAccess):
        """Helper class that creates natural hierarchical access to state attributes"""
        def __init__(self, node: og.Node, attributes, dynamic_attributes: og.DynamicAttributeInterface):
            """Initialize simplified access for the attribute data"""
            context = node.get_graph().get_default_graph_context()
            super().__init__(context, node, attributes, dynamic_attributes)

    def __init__(self, node):
        super().__init__(node)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_INPUT)
        self.inputs = OgnSdInstanceMappingPtrDatabase.ValuesForInputs(node, self.attributes.inputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_OUTPUT)
        self.outputs = OgnSdInstanceMappingPtrDatabase.ValuesForOutputs(node, self.attributes.outputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_STATE)
        self.state = OgnSdInstanceMappingPtrDatabase.ValuesForState(node, self.attributes.state, dynamic_attributes)
