"""Support for simplified access to data on nodes of type omni.graph.nodes.RpResourceExampleDeformer

Allocate CUDA-interoperable RpResource
"""

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 OgnRpResourceExampleDeformerDatabase(og.Database):
    """Helper class providing simplified access to data on nodes of type omni.graph.nodes.RpResourceExampleDeformer

    Class Members:
        node: Node being evaluated

    Attribute Value Properties:
        Inputs:
            inputs.deformScale
            inputs.displacementAxis
            inputs.pointCountCollection
            inputs.positionScale
            inputs.primPathCollection
            inputs.resourcePointerCollection
            inputs.runDeformerKernel
            inputs.stream
            inputs.timeScale
            inputs.verbose
        Outputs:
            outputs.pointCountCollection
            outputs.primPathCollection
            outputs.reload
            outputs.resourcePointerCollection
            outputs.stream
        State:
            state.sequenceCounter

    Predefined Tokens:
        tokens.points
        tokens.transform
        tokens.rpResource
        tokens.pointCount
        tokens.primPath
        tokens.testToken
        tokens.uintData
    """

    # 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:deformScale', 'float', 0, 'Deform Scale', 'Deformation control', {ogn.MetadataKeys.DEFAULT: '1.0'}, True, 1.0, False, ''),
        ('inputs:displacementAxis', 'int', 0, 'Displacement Axis', 'dimension in which mesh is translated', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('inputs:pointCountCollection', 'uint64[]', 0, 'Point Counts', 'Pointer to point counts collection', {}, True, [], False, ''),
        ('inputs:positionScale', 'float', 0, 'Position Scale', 'Deformation control', {ogn.MetadataKeys.DEFAULT: '1.0'}, True, 1.0, False, ''),
        ('inputs:primPathCollection', 'token[]', 0, 'Prim Paths', 'Pointer to prim path collection', {}, True, [], False, ''),
        ('inputs:resourcePointerCollection', 'uint64[]', 0, 'Resource Pointer Collection', 'Pointer to RpResource collection', {}, True, [], False, ''),
        ('inputs:runDeformerKernel', 'bool', 0, 'Run Deformer', 'Whether cuda kernel will be executed', {ogn.MetadataKeys.DEFAULT: 'true'}, True, True, False, ''),
        ('inputs:stream', 'uint64', 0, 'stream', 'Pointer to the CUDA Stream', {}, True, 0, False, ''),
        ('inputs:timeScale', 'float', 0, 'Time Scale', 'Deformation control', {ogn.MetadataKeys.DEFAULT: '0.01'}, True, 0.01, False, ''),
        ('inputs:verbose', 'bool', 0, 'Verbose', 'verbose printing', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('outputs:pointCountCollection', 'uint64[]', 0, 'Point Counts', 'Point count for each prim being deformed', {}, True, None, False, ''),
        ('outputs:primPathCollection', 'token[]', 0, 'Prim Paths', 'Path for each prim being deformed', {}, True, None, False, ''),
        ('outputs:reload', 'bool', 0, 'Reload', 'Force RpResource reload', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('outputs:resourcePointerCollection', 'uint64[]', 0, 'Resource Pointer Collection', 'Pointers to RpResources \n(two resources per prim are assumed -- one for rest positions and one for deformed positions)', {}, True, None, False, ''),
        ('outputs:stream', 'uint64', 0, 'stream', 'Pointer to the CUDA Stream', {}, True, None, False, ''),
        ('state:sequenceCounter', 'uint64', 0, None, 'tick counter for animation', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
    ])

    class tokens:
        points = "points"
        transform = "transform"
        rpResource = "rpResource"
        pointCount = "pointCount"
        primPath = "primPath"
        testToken = "testToken"
        uintData = "uintData"

    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 deformScale(self):
            data_view = og.AttributeValueHelper(self._attributes.deformScale)
            return data_view.get()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        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.pointCountCollection_size = None
            self.primPathCollection_size = None
            self.resourcePointerCollection_size = None
            self._batchedWriteValues = { }

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

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

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

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

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

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

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

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

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

        @stream.setter
        def stream(self, value):
            data_view = og.AttributeValueHelper(self._attributes.stream)
            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)

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

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

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