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

DEPRECATED: Use GetLocationAtDistanceOnCurve2
"""

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

    Class Members:
        node: Node being evaluated

    Attribute Value Properties:
        Inputs:
            inputs.curve
            inputs.distance
            inputs.forwardAxis
            inputs.upAxis
        Outputs:
            outputs.location
            outputs.orientation
            outputs.rotateXYZ

    Predefined Tokens:
        tokens.x
        tokens.y
        tokens.z
        tokens.X
        tokens.Y
        tokens.Z
    """

    # 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:curve', 'point3d[]', 0, 'Curve', 'The curve to be examined', {}, True, [], False, ''),
        ('inputs:distance', 'double[]', 0, 'Distances', 'The distances along the curve, wrapped to the range 0-1.0', {}, True, [], False, ''),
        ('inputs:forwardAxis', 'token', 0, 'Forward', 'The direction vector from which the returned rotation is relative, one of X, Y, Z', {ogn.MetadataKeys.DEFAULT: '"X"'}, True, "X", False, ''),
        ('inputs:upAxis', 'token', 0, 'Up', 'The world Up vector, the curve should be in a plane perpendicular with this - one of X, Y, Z', {ogn.MetadataKeys.DEFAULT: '"Y"'}, True, "Y", False, ''),
        ('outputs:location', 'point3d[]', 0, 'Locations on curve at the given distances in world space', 'Locations', {}, True, None, False, ''),
        ('outputs:orientation', 'quatf[]', 0, 'World space orientations of the curve at the given distances, may not be smooth for some curves', 'Orientations', {}, True, None, False, ''),
        ('outputs:rotateXYZ', 'vector3d[]', 0, 'World space rotations of the curve at the given distances, may not be smooth for some curves', 'Rotations', {}, True, None, False, ''),
    ])

    class tokens:
        x = "x"
        y = "y"
        z = "z"
        X = "X"
        Y = "Y"
        Z = "Z"

    @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.curve = og.AttributeRole.POSITION
        role_data.outputs.location = og.AttributeRole.POSITION
        role_data.outputs.orientation = og.AttributeRole.QUATERNION
        role_data.outputs.rotateXYZ = og.AttributeRole.VECTOR
        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 curve(self):
            data_view = og.AttributeValueHelper(self._attributes.curve)
            return data_view.get()

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

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

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

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

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

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

        @upAxis.setter
        def upAxis(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.upAxis)
            data_view = og.AttributeValueHelper(self._attributes.upAxis)
            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.location_size = None
            self.orientation_size = None
            self.rotateXYZ_size = None
            self._batchedWriteValues = { }

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

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

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

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

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

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

        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 = OgnGetLocationAtDistanceOnCurveDatabase.ValuesForInputs(node, self.attributes.inputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_OUTPUT)
        self.outputs = OgnGetLocationAtDistanceOnCurveDatabase.ValuesForOutputs(node, self.attributes.outputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_STATE)
        self.state = OgnGetLocationAtDistanceOnCurveDatabase.ValuesForState(node, self.attributes.state, dynamic_attributes)
