# -*- 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 ZMaskExt.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 ZMaskExt import *
except ImportError:
    pass

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

def getLabel():
    return "ZMask"

def getVersion():
    return 1

def getGrouping():
    return "Filter"

def getPluginDescription():
    return "Creates a mask from a depth buffer by specifying the center value and the amplitude of the range around it with the tightness parameter"

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")

    # 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("centerValue", "Center Value", False)
    param.setMinimum(-2147483648, 0)
    param.setMaximum(2147483647, 0)
    param.setDisplayMinimum(0, 0)
    param.setDisplayMaximum(200, 0)
    param.setDefaultValue(1, 0)
    param.restoreDefaultValue(0)
    param.setMinimum(-2147483648, 1)
    param.setMaximum(2147483647, 1)
    param.setDisplayMinimum(0, 1)
    param.setDisplayMaximum(200, 1)
    param.setDefaultValue(1, 1)
    param.restoreDefaultValue(1)
    param.setMinimum(-2147483648, 2)
    param.setMaximum(2147483647, 2)
    param.setDisplayMinimum(0, 2)
    param.setDisplayMaximum(200, 2)
    param.setDefaultValue(1, 2)
    param.restoreDefaultValue(2)

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

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

    param = lastNode.createColorParam("tightness", "Tightness", True)
    param.setMinimum(-1.79769e+308, 0)
    param.setMaximum(1.79769e+308, 0)
    param.setDisplayMinimum(0, 0)
    param.setDisplayMaximum(100, 0)
    param.setDefaultValue(1, 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(1, 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(1, 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(1, 3)
    param.restoreDefaultValue(3)

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

    # Set param properties
    param.setAddNewLine(True)
    param.setAnimationEnabled(True)
    lastNode.tightness = param
    del param

    param = lastNode.createColorParam("contrast", "Contrast", True)
    param.setMinimum(-1.79769e+308, 0)
    param.setMaximum(1.79769e+308, 0)
    param.setDisplayMinimum(0, 0)
    param.setDisplayMaximum(100, 0)
    param.setDefaultValue(1, 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(1, 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(1, 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(1, 3)
    param.restoreDefaultValue(3)

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

    # Set param properties
    param.setAddNewLine(True)
    param.setAnimationEnabled(True)
    lastNode.contrast = param
    del param

    param = lastNode.createColorParam("offset", "Offset", True)
    param.setMinimum(-1.79769e+308, 0)
    param.setMaximum(1.79769e+308, 0)
    param.setDisplayMinimum(-200, 0)
    param.setDisplayMaximum(200, 0)
    param.setMinimum(-1.79769e+308, 1)
    param.setMaximum(1.79769e+308, 1)
    param.setDisplayMinimum(-200, 1)
    param.setDisplayMaximum(200, 1)
    param.setMinimum(-1.79769e+308, 2)
    param.setMaximum(1.79769e+308, 2)
    param.setDisplayMinimum(-200, 2)
    param.setDisplayMaximum(200, 2)
    param.setMinimum(-1.79769e+308, 3)
    param.setMaximum(1.79769e+308, 3)
    param.setDisplayMinimum(-200, 3)
    param.setDisplayMaximum(200, 3)

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

    # Set param properties
    param.setAddNewLine(True)
    param.setAnimationEnabled(True)
    lastNode.offset = 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.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 "Merge1"
    lastNode = app.createNode("net.sf.openfx.MergePlugin", 1, group)
    lastNode.setScriptName("Merge1")
    lastNode.setLabel("Merge1")
    lastNode.setPosition(764, 248)
    lastNode.setSize(104, 56)
    lastNode.setColor(0.3, 0.37, 0.776)
    groupMerge1 = lastNode

    param = lastNode.getParam("NatronOfxParamStringSublabelName")
    if param is not None:
        param.setValue("difference")
        del param

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

    param = lastNode.getParam("userTextArea")
    if param is not None:
        param.setValue("<Natron>(difference)</Natron>")
        del param

    del lastNode
    # End of node "Merge1"

    # Start of node "Solid1"
    lastNode = app.createNode("net.sf.openfx.Solid", 1, group)
    lastNode.setScriptName("Solid1")
    lastNode.setLabel("Solid1")
    lastNode.setPosition(776, 134)
    lastNode.setSize(80, 34)
    lastNode.setColor(0.3, 0.5, 0.2)
    groupSolid1 = lastNode

    param = lastNode.getParam("NatronParamFormatChoice")
    if param is not None:
        param.set("PC_Video 640x480")
        del param

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

    del lastNode
    # End of node "Solid1"

    # Start of node "Invert1"
    lastNode = app.createNode("net.sf.openfx.Invert", 2, group)
    lastNode.setScriptName("Invert1")
    lastNode.setLabel("Invert1")
    lastNode.setPosition(764, 546)
    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 "Clamp1"
    lastNode = app.createNode("net.sf.openfx.Clamp", 2, group)
    lastNode.setScriptName("Clamp1")
    lastNode.setLabel("Clamp1")
    lastNode.setPosition(764, 455)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.48, 0.66, 1)
    groupClamp1 = lastNode

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

    del lastNode
    # End of node "Clamp1"

    # Start of node "ColorCorrect1"
    lastNode = app.createNode("net.sf.openfx.ColorCorrectPlugin", 2, group)
    lastNode.setScriptName("ColorCorrect1")
    lastNode.setLabel("ColorCorrect1")
    lastNode.setPosition(764, 344)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.48, 0.66, 1)
    groupColorCorrect1 = lastNode

    param = lastNode.getParam("toneRanges")
    if param is not None:
        param.setCurveColor(0, 0.6, 0.4, 0.6)
        param.deleteAllControlPoints(0)
        param.addControlPoint(0, 0, 1, 0, 0, NatronEngine.Natron.KeyframeTypeEnum.eKeyframeTypeHorizontal)
        param.addControlPoint(0, 0.09, 0, 0, 0, NatronEngine.Natron.KeyframeTypeEnum.eKeyframeTypeHorizontal)
        param.setCurveColor(1, 0.8, 0.7, 0.6)
        param.deleteAllControlPoints(1)
        param.addControlPoint(1, 0.5, 0, 0, 0, NatronEngine.Natron.KeyframeTypeEnum.eKeyframeTypeHorizontal)
        param.addControlPoint(1, 1, 1, 0, 0, NatronEngine.Natron.KeyframeTypeEnum.eKeyframeTypeHorizontal)
        del param

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

    del lastNode
    # End of node "ColorCorrect1"

    # Start of node "Output1"
    lastNode = app.createNode("fr.inria.built-in.Output", 1, group)
    lastNode.setLabel("Output1")
    lastNode.setPosition(764, 774)
    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(506, 255)
    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(764, 638)
    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
    groupMerge1.connectInput(0, groupInputSource)
    groupMerge1.connectInput(1, groupSolid1)
    groupInvert1.connectInput(0, groupClamp1)
    groupClamp1.connectInput(0, groupColorCorrect1)
    groupColorCorrect1.connectInput(0, groupMerge1)
    groupOutput1.connectInput(0, groupSwitch1)
    groupSwitch1.connectInput(0, groupInvert1)
    groupSwitch1.connectInput(1, groupInputSource)

    param = groupMerge1.getParam("B_channels")
    group.getParam("Source_channels").setAsAlias(param)
    del param
    param = groupSolid1.getParam("color")
    group.getParam("centerValue").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 = groupColorCorrect1.getParam("MasterContrast")
    group.getParam("contrast").setAsAlias(param)
    del param
    param = groupColorCorrect1.getParam("MasterGamma")
    group.getParam("gamma").setAsAlias(param)
    del param
    param = groupColorCorrect1.getParam("MasterGain")
    group.getParam("tightness").setAsAlias(param)
    del param
    param = groupColorCorrect1.getParam("MasterOffset")
    group.getParam("offset").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["ZMaskExt"]
    except KeyError:
        extModule = None
    if extModule is not None and hasattr(extModule ,"createInstanceExt") and hasattr(extModule.createInstanceExt,"__call__"):
        extModule.createInstanceExt(app,group)
