# -*- coding: utf-8 -*-
"""Helper functions and classes for Houdini.

The name of this module is inspired from the Maya module.
"""
import hou


def get_network_pane():
    """returns the network pane"""
    return hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)


def get_scene_viewer():
    """returns the scene viewer"""
    return hou.ui.paneTabOfType(hou.paneTabType.SceneViewer)


def create_spare_input(node, value=""):
    """creates spare inputs for the given node and sets the value

    :param hou.Node node: The node to insert the spare input to.
    :param str value: The value of the parameter
    """
    # Create space input0 for rs proxy output node
    parm_template_group = node.parmTemplateGroup()
    parm_template_group.append(
        hou.StringParmTemplate(
            "spare_input0",
            "Spare Input 0",
            1,
            string_type=hou.stringParmType.NodeReference,
        )
    )
    node.setParmTemplateGroup(parm_template_group)
    node.parm("spare_input0").set(value)


def very_nice_camera_rig(
    focal_length=35, horizontal_film_aperture=36, vertical_film_aperture=24
):
    """creates a very nice camera rig where the Heading, Pitch and Roll controls are on different transform nodes
    allowing more control on the camera movement

    :param focal_length:
    :param horizontal_film_aperture:
    :param vertical_film_aperture:
    """

    obj_context = hou.node("/obj")

    camera = obj_context.createNode("cam")
    # set camera attributes
    camera.parm("focal").set(focal_length)
    # set the film back in millimeters (yeah)
    camera.parm("aperture").set(horizontal_film_aperture)

    main_ctrl = obj_context.createNode("null", "main_ctrl1")
    heading_ctrl = obj_context.createNode("null", "heading_ctrl1")
    pitch_ctrl = obj_context.createNode("null", "pitch_ctrl1")
    roll_ctrl = obj_context.createNode("null", "roll_ctrl1")

    # create DAG hierarchy
    camera.setInput(0, roll_ctrl)
    roll_ctrl.setInput(0, pitch_ctrl)
    pitch_ctrl.setInput(0, heading_ctrl)
    heading_ctrl.setInput(0, main_ctrl)

    # Parameters
    # -----------------------------------------------------------
    # Focal Length And Focal Plane Controls
    # Create space input0 for rs proxy output node

    # Focal Length
    ptg = main_ctrl.parmTemplateGroup()
    ptg.append(
        hou.FloatParmTemplate(
            "focal",
            "Focal Length",
            1,
            default_value=[focal_length],
            min=1.0,
            min_is_strict=True,
        )
    )
    ptg.append(
        hou.FloatParmTemplate(
            "aperture",
            "Aperture",