# -*- coding: utf-8 -*-
# DO NOT EDIT THIS FILE
# This file was automatically generated by Natron PyPlug exporter version 10.

# Hand-written code should be added in a separate file named ZRemapExt.py
# See http://natron.readthedocs.org/en/master/devel/groups.html#adding-hand-written-code-callbacks-etc
# Note that Viewers are never exported

import NatronEngine
import sys

# Try to import the extensions file where callbacks and hand-written code should be located.
try:
    from ZRemapExt import *
except ImportError:
    pass

def getPluginID():
    return "fr.inria.ZRemap"

def getLabel():
    return "ZRemap"

def getVersion():
    return 1

def getIconPath():
    return "ZRemap.png"

def getGrouping():
    return "Filter"

def getPluginDescription():
    return "Remap Z-Depth pass according to a close limit value and a far limit"

def createInstance(app,group):
    # Create all nodes in the group

    # Create the parameters of the group node the same way we did for all internal nodes
    lastNode = group

    # Create the user parameters
    lastNode.controls = lastNode.createPageParam("controls", "Controls")
    param = lastNode.createBooleanParam("zPicking", "Z Picking mode")

    # Add the param to the page
    lastNode.controls.addParam(param)

    # Set param properties
    param.setHelp("")
    param.setAddNewLine(True)
    param.setAnimationEnabled(False)
    lastNode.zPicking = param
    del param

    param = lastNode.createColorParam("closeLimit", "Close Limit", True)
    param.setMinimum(-1.79769e+308, 0)
    param.setMaximum(1.79769e+308, 0)
    param.setDisplayMinimum(0, 0)
    param.setDisplayMaximum(100, 0)
    param.setMinimum(-1.79769e+308, 1)
    param.setMaximum(1.79769e+308, 1)
    param.setDisplayMinimum(0, 1)
    param.setDisplayMaximum(100, 1)
    param.setMinimum(-1.79769e+308, 2)
    param.setMaximum(1.79769e+308, 2)
    param.setDisplayMinimum(0, 2)
    param.setDisplayMaximum(100, 2)
    param.setMinimum(-1.79769e+308, 3)
    param.setMaximum(1.79769e+308, 3)
    param.setDisplayMinimum(0, 3)
    param.setDisplayMaximum(100, 3)

    # Add the param to the page
    lastNode.controls.addParam(param)

    # Set param properties
    param.setHelp("Define the Z value remapped to white.")
    param.setAddNewLine(True)
    param.setAnimationEnabled(True)
    lastNode.closeLimit = param
    del param

    param = lastNode.createColorParam("farLimit", "Far Limit", True)
    param.setMinimum(-1.79769e+308, 0)
    param.setMaximum(1.79769e+308, 0)
    param.setDisplayMinimum(0, 0)
    param.setDisplayMaximum(100, 0)
    param.setDefaultValue(100, 0)
    param.restoreDefaultValue(0)
    param.setMinimum(-1.79769e+308, 1)
    param.setMaximum(1.79769e+308, 1)
    param.setDisplayMinimum(0, 1)
    param.setDisplayMaximum(100, 1)
    param.setDefaultValue(100, 1)
    param.restoreDefaultValue(1)
    param.setMinimum(-1.79769e+308, 2)
    param.setMaximum(1.79769e+308, 2)
    param.setDisplayMinimum(0, 2)
    param.setDisplayMaximum(100, 2)
    param.setDefaultValue(100, 2)
    param.restoreDefaultValue(2)
    param.setMinimum(-1.79769e+308, 3)
    param.setMaximum(1.79769e+308, 3)
    param.setDisplayMinimum(0, 3)
    param.setDisplayMaximum(100, 3)
    param.setDefaultValue(100, 3)
    param.restoreDefaultValue(3)

    # Add the param to the page
    lastNode.controls.addParam(param)

    # Set param properties
    param.setHelp("Define the Z value remapped to black.")
    param.setAddNewLine(True)
    param.setAnimationEnabled(True)
    lastNode.farLimit = param
    del param

    param = lastNode.createColorParam("gamma", "Gamma", True)
    param.setMinimum(-1.79769e+308, 0)
    param.setMaximum(1.79769e+308, 0)
    param.setDisplayMinimum(0.2, 0)
    param.setDisplayMaximum(5, 0)
    param.setDefaultValue(1, 0)
    param.restoreDefaultValue(0)
    param.setMinimum(-1.79769e+308, 1)
    param.setMaximum(1.79769e+308, 1)
    param.setDisplayMinimum(0.2, 1)
    param.setDisplayMaximum(5, 1)
    param.setDefaultValue(1, 1)
    param.restoreDefaultValue(1)
    param.setMinimum(-1.79769e+308, 2)
    param.setMaximum(1.79769e+308, 2)
    param.setDisplayMinimum(0.2, 2)
    param.setDisplayMaximum(5, 2)
    param.setDefaultValue(1, 2)
    param.restoreDefaultValue(2)
    param.setMinimum(-1.79769e+308, 3)
    param.setMaximum(1.79769e+308, 3)
    param.setDisplayMinimum(0.2, 3)
    param.setDisplayMaximum(5, 3)
    param.setDefaultValue(1, 3)
    param.restoreDefaultValue(3)

    # Add the param to the page
    lastNode.controls.addParam(param)

    # Set param properties
    param.setHelp("")
    param.setAddNewLine(True)
    param.setAnimationEnabled(True)
    lastNode.gamma = param
    del param

    param = lastNode.createBooleanParam("invertGradient", "Invert Gradient")

    # Add the param to the page
    lastNode.controls.addParam(param)

    # Set param properties
    param.setHelp("")
    param.setAddNewLine(True)
    param.setAnimationEnabled(False)
    lastNode.invertGradient = param
    del param

    param = lastNode.createChoiceParam("Source_channels", "Source Layer")
    param.setDefaultValue(1)
    param.restoreDefaultValue()

    # Add the param to the page
    lastNode.controls.addParam(param)

    # Set param properties
    param.setHelp("")
    param.setAddNewLine(True)
    param.setAnimationEnabled(False)
    lastNode.Source_channels = param
    del param

    param = lastNode.createChoiceParam("channels", "Output Layer")
    param.setDefaultValue(1)
    param.restoreDefaultValue()

    # Add the param to the page
    lastNode.controls.addParam(param)

    # Set param properties
    param.setHelp("")
    param.setAddNewLine(True)
    param.setAnimationEnabled(False)
    lastNode.channels = param
    del param

    lastNode.userNatron = lastNode.createPageParam("userNatron", "User")
    # Refresh the GUI with the newly created parameters
    lastNode.setPagesOrder(['controls', 'Node', 'Settings', 'userNatron'])
    lastNode.refreshUserParamsGUI()
    del lastNode

    # Start of node "Grade1"
    lastNode = app.createNode("net.sf.openfx.GradePlugin", 2, group)
    lastNode.setScriptName("Grade1")
    lastNode.setLabel("Grade1")
    lastNode.setPosition(726, 92)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.48, 0.66, 1)
    groupGrade1 = lastNode

    param = lastNode.getParam("whitePoint")
    if param is not None:
        param.setValue(100, 0)
        param.setValue(100, 1)
        param.setValue(100, 2)
        param.setValue(100, 3)
        del param

    param = lastNode.getParam("clampBlack")
    if param is not None:
        param.setValue(True)
        del param

    param = lastNode.getParam("premultChanged")
    if param is not None:
        param.setValue(True)
        del param

    param = lastNode.getParam("enableMask_Mask")
    if param is not None:
        param.setValue(True)
        del param

    del lastNode
    # End of node "Grade1"

    # Start of node "Invert1"
    lastNode = app.createNode("net.sf.openfx.Invert", 2, group)
    lastNode.setScriptName("Invert1")
    lastNode.setLabel("Invert1")
    lastNode.setPosition(726, 230)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.48, 0.66, 1)
    groupInvert1 = lastNode

    param = lastNode.getParam("premultChanged")
    if param is not None:
        param.setValue(True)
        del param

    param = lastNode.getParam("channels")
    if param is not None:
        param.set("uk.co.thefoundry.OfxImagePlaneStereoDisparityLeft")
        del param

    del lastNode
    # End of node "Invert1"

    # Start of node "Output1"
    lastNode = app.createNode("fr.inria.built-in.Output", 1, group)
    lastNode.setLabel("Output1")
    lastNode.setPosition(882, 496)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.7, 0.7, 0.7)
    groupOutput1 = lastNode

    del lastNode
    # End of node "Output1"

    # Start of node "InputSource"
    lastNode = app.createNode("fr.inria.built-in.Input", 1, group)
    lastNode.setScriptName("InputSource")
    lastNode.setLabel("InputSource")
    lastNode.setPosition(882, -40)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.3, 0.5, 0.2)
    groupInputSource = lastNode

    del lastNode
    # End of node "InputSource"

    # Start of node "Switch1"
    lastNode = app.createNode("net.sf.openfx.switchPlugin", 1, group)
    lastNode.setScriptName("Switch1")
    lastNode.setLabel("Switch1")
    lastNode.setPosition(882, 381)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.3, 0.37, 0.776)
    groupSwitch1 = lastNode

    param = lastNode.getParam("which")
    if param is not None:
        param.setValue(0, 0)
        del param

    param = lastNode.getParam("p1_channels")
    if param is not None:
        param.set("")
        del param

    del lastNode
    # End of node "Switch1"

    # Now that all nodes are created we can connect them together, restore expressions
    groupGrade1.connectInput(0, groupInputSource)
    groupInvert1.connectInput(0, groupGrade1)
    groupOutput1.connectInput(0, groupSwitch1)
    groupSwitch1.connectInput(0, groupInvert1)
    groupSwitch1.connectInput(1, groupInputSource)

    param = groupGrade1.getParam("blackPoint")
    group.getParam("closeLimit").setAsAlias(param)
    del param
    param = groupGrade1.getParam("whitePoint")
    group.getParam("farLimit").setAsAlias(param)
    del param
    param = groupGrade1.getParam("gamma")
    group.getParam("gamma").setAsAlias(param)
    del param
    param = groupGrade1.getParam("Source_channels")
    group.getParam("Source_channels").setAsAlias(param)
    del param
    param = groupInvert1.getParam("channels")
    group.getParam("channels").setAsAlias(param)
    del param
    param = groupInvert1.getParam("disableNode")
    group.getParam("invertGradient").setAsAlias(param)
    del param
    param = groupSwitch1.getParam("which")
    param.setExpression("thisGroup.zPicking.get()", False, 0)
    del param
    param = groupSwitch1.getParam("p1_channels")
    param.setExpression("thisGroup.Source_channels.get()", False, 0)
    del param

    try:
        extModule = sys.modules["ZRemapExt"]
    except KeyError:
        extModule = None
    if extModule is not None and hasattr(extModule ,"createInstanceExt") and hasattr(extModule.createInstanceExt,"__call__"):
        extModule.createInstanceExt(app,group)
