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

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

def getLabel():
    return "DropShadow"

def getVersion():
    return 1

def getIconPath():
    return "DropShadow.png"

def getGrouping():
    return "Filter"

def getPluginDescription():
    return "Creates a drop shadow on the source image using its alpha channel."

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.createDoubleParam("shadowAngle", "Angle")
    param.setMinimum(-2147483648, 0)
    param.setMaximum(2147483647, 0)
    param.setDisplayMinimum(-360, 0)
    param.setDisplayMaximum(360, 0)
    param.setDefaultValue(-45, 0)
    param.restoreDefaultValue(0)

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

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

    param = lastNode.createDoubleParam("shadowDist", "Distance")
    param.setMinimum(-2147483648, 0)
    param.setMaximum(2147483647, 0)
    param.setDisplayMinimum(0, 0)
    param.setDisplayMaximum(2000, 0)
    param.setDefaultValue(20, 0)
    param.restoreDefaultValue(0)

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

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

    param = lastNode.createDouble2DParam("shadowBlur", "Bluriness")
    param.setMinimum(0, 0)
    param.setMaximum(1000, 0)
    param.setDisplayMinimum(0, 0)
    param.setDisplayMaximum(100, 0)
    param.setMinimum(0, 1)
    param.setMaximum(1000, 1)
    param.setDisplayMinimum(0, 1)
    param.setDisplayMaximum(100, 1)

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

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

    param = lastNode.createColorParam("shadowOpacity", "Opacity", True)
    param.setMinimum(-1.79769e+308, 0)
    param.setMaximum(1.79769e+308, 0)
    param.setDisplayMinimum(0, 0)
    param.setDisplayMaximum(1, 0)
    param.setDefaultValue(0.5, 0)
    param.restoreDefaultValue(0)
    param.setMinimum(-1.79769e+308, 1)
    param.setMaximum(1.79769e+308, 1)
    param.setDisplayMinimum(0, 1)
    param.setDisplayMaximum(1, 1)
    param.setDefaultValue(0.5, 1)
    param.restoreDefaultValue(1)
    param.setMinimum(-1.79769e+308, 2)
    param.setMaximum(1.79769e+308, 2)
    param.setDisplayMinimum(0, 2)
    param.setDisplayMaximum(1, 2)
    param.setDefaultValue(0.5, 2)
    param.restoreDefaultValue(2)
    param.setMinimum(-1.79769e+308, 3)
    param.setMaximum(1.79769e+308, 3)
    param.setDisplayMinimum(0, 3)
    param.setDisplayMaximum(1, 3)
    param.setDefaultValue(0.5, 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.shadowOpacity = param
    del param

    param = lastNode.createColorParam("shadowColor", "Color", False)
    param.setMinimum(-2147483648, 0)
    param.setMaximum(2147483647, 0)
    param.setDisplayMinimum(0, 0)
    param.setDisplayMaximum(1, 0)
    param.setMinimum(-2147483648, 1)
    param.setMaximum(2147483647, 1)
    param.setDisplayMinimum(0, 1)
    param.setDisplayMaximum(1, 1)
    param.setMinimum(-2147483648, 2)
    param.setMaximum(2147483647, 2)
    param.setDisplayMinimum(0, 2)
    param.setDisplayMaximum(1, 2)

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

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

    param = lastNode.createBooleanParam("shadowCFS", "Color from source")

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

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

    param = lastNode.createBooleanParam("shadowOnly", "Shadow only")

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

    # Set param properties
    param.setHelp("")
    param.setAddNewLine(True)
    param.setAnimationEnabled(False)
    lastNode.shadowOnly = 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 "Shuffle1"
    lastNode = app.createNode("net.sf.openfx.ShufflePlugin", 2, group)
    lastNode.setScriptName("Shuffle1")
    lastNode.setLabel("Shuffle1")
    lastNode.setPosition(759, 87)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.6, 0.24, 0.39)
    groupShuffle1 = lastNode

    param = lastNode.getParam("outputR")
    if param is not None:
        param.set("B.uk.co.thefoundry.OfxImagePlaneColour.R")
        del param

    param = lastNode.getParam("outputG")
    if param is not None:
        param.set("B.uk.co.thefoundry.OfxImagePlaneColour.G")
        del param

    param = lastNode.getParam("outputB")
    if param is not None:
        param.set("B.uk.co.thefoundry.OfxImagePlaneColour.B")
        del param

    del lastNode
    # End of node "Shuffle1"

    # Start of node "Transform2"
    lastNode = app.createNode("net.sf.openfx.TransformPlugin", 1, group)
    lastNode.setScriptName("Transform2")
    lastNode.setLabel("Transform2")
    lastNode.setPosition(759, 167)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.7, 0.3, 0.1)
    groupTransform2 = lastNode

    param = lastNode.getParam("translate")
    if param is not None:
        param.setValue(14.14213562373095, 0)
        param.setValue(-14.14213562373095, 1)
        del param

    param = lastNode.getParam("center")
    if param is not None:
        param.setValue(480, 0)
        param.setValue(270, 1)
        del param

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

    del lastNode
    # End of node "Transform2"

    # Start of node "Premult1"
    lastNode = app.createNode("net.sf.openfx.Premult", 2, group)
    lastNode.setScriptName("Premult1")
    lastNode.setLabel("Premult1")
    lastNode.setPosition(759, 341)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.3, 0.37, 0.776)
    groupPremult1 = lastNode

    del lastNode
    # End of node "Premult1"

    # Start of node "Multiply1"
    lastNode = app.createNode("net.sf.openfx.MultiplyPlugin", 2, group)
    lastNode.setScriptName("Multiply1")
    lastNode.setLabel("Multiply1")
    lastNode.setPosition(759, -23)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.48, 0.66, 1)
    groupMultiply1 = lastNode

    param = lastNode.getParam("NatronOfxParamProcessR")
    if param is not None:
        param.setValue(False)
        del param

    param = lastNode.getParam("NatronOfxParamProcessG")
    if param is not None:
        param.setValue(False)
        del param

    param = lastNode.getParam("NatronOfxParamProcessB")
    if param is not None:
        param.setValue(False)
        del param

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

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

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

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

    del lastNode
    # End of node "Multiply1"

    # Start of node "Solid1"
    lastNode = app.createNode("net.sf.openfx.Solid", 1, group)
    lastNode.setScriptName("Solid1")
    lastNode.setLabel("Solid1")
    lastNode.setPosition(584, 87)
    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("size")
    if param is not None:
        param.setValue(960, 0)
        param.setValue(540, 1)
        del param

    del lastNode
    # End of node "Solid1"

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

    del lastNode
    # End of node "InputSource"

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

    del lastNode
    # End of node "Output1"

    # Start of node "Blur1"
    lastNode = app.createNode("net.sf.cimg.CImgBlur", 3, group)
    lastNode.setScriptName("Blur1")
    lastNode.setLabel("Blur1")
    lastNode.setPosition(759, 260)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.8, 0.5, 0.3)
    groupBlur1 = lastNode

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

    del lastNode
    # End of node "Blur1"

    # Start of node "Merge1"
    lastNode = app.createNode("net.sf.openfx.MergePlugin", 1, group)
    lastNode.setScriptName("Merge1")
    lastNode.setLabel("Merge1")
    lastNode.setPosition(1000, 329)
    lastNode.setSize(104, 56)
    lastNode.setColor(0.3, 0.37, 0.776)
    groupMerge1 = lastNode

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

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

    del lastNode
    # End of node "Merge1"

    # Now that all nodes are created we can connect them together, restore expressions
    groupShuffle1.connectInput(0, groupSolid1)
    groupShuffle1.connectInput(1, groupMultiply1)
    groupTransform2.connectInput(0, groupShuffle1)
    groupPremult1.connectInput(0, groupBlur1)
    groupMultiply1.connectInput(0, groupInputSource)
    groupOutput1.connectInput(0, groupMerge1)
    groupBlur1.connectInput(0, groupTransform2)
    groupMerge1.connectInput(0, groupPremult1)
    groupMerge1.connectInput(1, groupInputSource)

    param = groupShuffle1.getParam("disableNode")
    group.getParam("shadowCFS").setAsAlias(param)
    del param
    param = groupTransform2.getParam("translate")
    param.setExpression("cos(radians(thisGroup.shadowAngle.get()))*thisGroup.shadowDist.get()", False, 0)
    param.setExpression("sin(radians(thisGroup.shadowAngle.get()))*thisGroup.shadowDist.get()", False, 1)
    del param
    param = groupMultiply1.getParam("value")
    group.getParam("shadowOpacity").setAsAlias(param)
    del param
    param = groupSolid1.getParam("color")
    group.getParam("shadowColor").setAsAlias(param)
    del param
    param = groupBlur1.getParam("size")
    group.getParam("shadowBlur").setAsAlias(param)
    del param
    param = groupMerge1.getParam("disableNode")
    group.getParam("shadowOnly").setAsAlias(param)
    del param

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