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

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

def getLabel():
    return "AngleBlur"

def getVersion():
    return 1

def getGrouping():
    return "Filter"

def getPluginDescription():
    return "The Angle Blur effect gives the illusion of motion in a given direction."

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("angleBlur_angle", "Angle")
    param.setMinimum(-2147483648, 0)
    param.setMaximum(2147483647, 0)
    param.setDisplayMinimum(-360, 0)
    param.setDisplayMaximum(360, 0)

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

    # Set param properties
    param.setHelp("Determines the direction into which the image is blurred. This is an angle in degrees.")
    param.setAddNewLine(True)
    param.setAnimationEnabled(True)
    lastNode.angleBlur_angle = param
    del param

    param = lastNode.createDoubleParam("angleBlur_distance", "Distance")
    param.setMinimum(-2147483648, 0)
    param.setMaximum(2147483647, 0)
    param.setDisplayMinimum(0, 0)
    param.setDisplayMaximum(1000, 0)

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

    # Set param properties
    param.setHelp("Determines how much the image will be blurred")
    param.setAddNewLine(True)
    param.setAnimationEnabled(True)
    lastNode.angleBlur_distance = 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 "Source"
    lastNode = app.createNode("fr.inria.built-in.Input", 1, group)
    lastNode.setScriptName("Source")
    lastNode.setLabel("Source")
    lastNode.setPosition(1000, 67)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.3, 0.5, 0.2)
    groupSource = lastNode

    del lastNode
    # End of node "Source"

    # 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 "Transform1"
    lastNode = app.createNode("net.sf.openfx.TransformPlugin", 1, group)
    lastNode.setScriptName("Transform1")
    lastNode.setLabel("Transform1")
    lastNode.setPosition(1000, 173)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.7, 0.3, 0.1)
    groupTransform1 = lastNode

    param = lastNode.getParam("rotate")
    if param is not None:
        param.setValue(0, 0)
        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 "Transform1"

    # Start of node "Transform3"
    lastNode = app.createNode("net.sf.openfx.TransformPlugin", 1, group)
    lastNode.setScriptName("Transform3")
    lastNode.setLabel("Transform3")
    lastNode.setPosition(1000, 328)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.7, 0.3, 0.1)
    groupTransform3 = lastNode

    param = lastNode.getParam("rotate")
    if param is not None:
        param.setValue(0, 0)
        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

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

    del lastNode
    # End of node "Transform3"

    # Start of node "Blur2"
    lastNode = app.createNode("net.sf.cimg.CImgBlur", 3, group)
    lastNode.setScriptName("Blur2")
    lastNode.setLabel("Blur2")
    lastNode.setPosition(1000, 246)
    lastNode.setSize(104, 34)
    lastNode.setColor(0.8, 0.5, 0.3)
    groupBlur2 = lastNode

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

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

    del lastNode
    # End of node "Blur2"

    # Now that all nodes are created we can connect them together, restore expressions
    groupOutput1.connectInput(0, groupTransform3)
    groupTransform1.connectInput(0, groupSource)
    groupTransform3.connectInput(0, groupBlur2)
    groupBlur2.connectInput(0, groupTransform1)

    param = groupTransform1.getParam("rotate")
    param.setExpression("thisGroup.angleBlur_angle.get()", False, 0)
    del param
    param = groupTransform3.getParam("rotate")
    param.setExpression("thisGroup.angleBlur_angle.get()", False, 0)
    del param
    param = groupTransform3.getParam("center")
    param.setExpression("thisGroup.Transform1.center.get()[dimension]", False, 0)
    param.setExpression("thisGroup.Transform1.center.get()[dimension]", False, 1)
    del param
    param = groupBlur2.getParam("size")
    param.setExpression("thisGroup.angleBlur_distance.get()", False, 0)
    del param

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