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

Synthetic Data node to test the renderProduct camera pipeline
"""

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

    Class Members:
        node: Node being evaluated

    Attribute Value Properties:
        Inputs:
            inputs.cameraApertureOffset
            inputs.cameraApertureSize
            inputs.cameraFStop
            inputs.cameraFisheyeParams
            inputs.cameraFocalLength
            inputs.cameraFocusDistance
            inputs.cameraModel
            inputs.cameraNearFar
            inputs.cameraProjection
            inputs.cameraViewTransform
            inputs.exec
            inputs.height
            inputs.metersPerSceneUnit
            inputs.renderProductCameraPath
            inputs.renderProductResolution
            inputs.renderResults
            inputs.rp
            inputs.stage
            inputs.traceError
            inputs.width
        Outputs:
            outputs.test

    Predefined Tokens:
        tokens.simulation
        tokens.postRender
        tokens.onDemand
    """

    # 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:cameraApertureOffset', 'float2', 0, None, 'Camera horizontal and vertical aperture offset', {}, True, [0.0, 0.0], False, ''),
        ('inputs:cameraApertureSize', 'float2', 0, None, 'Camera horizontal and vertical aperture', {}, True, [0.0, 0.0], False, ''),
        ('inputs:cameraFStop', 'float', 0, None, 'Camera fStop', {}, True, 0.0, False, ''),
        ('inputs:cameraFisheyeParams', 'float[]', 0, None, 'Camera fisheye projection parameters', {}, True, [], False, ''),
        ('inputs:cameraFocalLength', 'float', 0, None, 'Camera focal length', {}, True, 0.0, False, ''),
        ('inputs:cameraFocusDistance', 'float', 0, None, 'Camera focus distance', {}, True, 0.0, False, ''),
        ('inputs:cameraModel', 'int', 0, None, 'Camera model (pinhole or fisheye models)', {}, True, 0, False, ''),
        ('inputs:cameraNearFar', 'float2', 0, None, 'Camera near/far clipping range', {}, True, [0.0, 0.0], False, ''),
        ('inputs:cameraProjection', 'matrix4d', 0, None, 'Camera projection matrix', {}, True, [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]], False, ''),
        ('inputs:cameraViewTransform', 'matrix4d', 0, None, 'Camera view matrix', {}, True, [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]], False, ''),
        ('inputs:exec', 'execution', 0, None, 'Trigger', {}, True, None, False, ''),
        ('inputs:height', 'uint', 0, None, 'Height of the frame', {}, True, 0, False, ''),
        ('inputs:metersPerSceneUnit', 'float', 0, None, 'Scene units to meters scale', {}, True, 0.0, False, ''),
        ('inputs:renderProductCameraPath', 'token', 0, None, 'RenderProduct camera prim path', {}, True, "", False, ''),
        ('inputs:renderProductResolution', 'int2', 0, None, 'RenderProduct resolution', {}, True, [0, 0], False, ''),
        ('inputs:renderResults', 'uint64', 0, None, 'OnDemand connection : pointer to render product results', {}, True, 0, False, ''),
        ('inputs:rp', 'uint64', 0, 'renderProduct', 'PostRender connection : pointer to render product for this view', {}, True, 0, False, ''),
        ('inputs:stage', 'token', 0, None, 'Stage in {simulation, postrender, ondemand}', {}, True, "", False, ''),
        ('inputs:traceError', 'bool', 0, None, 'If true print an error message when the frame numbers are out-of-sync', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('inputs:width', 'uint', 0, None, 'Width of the frame', {}, True, 0, False, ''),
        ('outputs:test', 'bool', 0, None, 'Test value : false if failed', {}, True, None, False, ''),
    ])

    class tokens:
        simulation = "simulation"
        postRender = "postRender"
        onDemand = "onDemand"

    @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.cameraProjection = og.AttributeRole.MATRIX
        role_data.inputs.cameraViewTransform = og.AttributeRole.MATRIX
        role_data.inputs.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 cameraApertureOffset(self):
            data_view = og.AttributeValueHelper(self._attributes.cameraApertureOffset)
            return data_view.get()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        @cameraViewTransform.setter
        def cameraViewTransform(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.cameraViewTransform)
            data_view = og.AttributeValueHelper(self._attributes.cameraViewTransform)
            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 height(self):
            data_view = og.AttributeValueHelper(self._attributes.height)
            return data_view.get()

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

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

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

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

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

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

        @renderProductResolution.setter
        def renderProductResolution(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.renderProductResolution)
            data_view = og.AttributeValueHelper(self._attributes.renderProductResolution)
            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 rp(self):
            data_view = og.AttributeValueHelper(self._attributes.rp)
            return data_view.get()

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

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

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

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

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

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

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

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

        @test.setter
        def test(self, value):
            data_view = og.AttributeValueHelper(self._attributes.test)
            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 = OgnSdTestRenderProductCameraDatabase.ValuesForInputs(node, self.attributes.inputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_OUTPUT)
        self.outputs = OgnSdTestRenderProductCameraDatabase.ValuesForOutputs(node, self.attributes.outputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_STATE)
        self.state = OgnSdTestRenderProductCameraDatabase.ValuesForState(node, self.attributes.state, dynamic_attributes)
