# Path: mayaLib/rigLib/utils/common.py
# def centerPivot(obj, targetPivot=None):
# def freezeTranform(obj):
# def deleteHistory(obj):
# def deleteNonDeformerHistory(obj):
# def deleteConnection(objAttrList):
# def setDrivenKey(driver, driverValueList, driven, drivenValueList, cvType='linear'):


import pymel.core as pm
from mayaLib.rigLib.utils import common
__author__ = 'Lorenzo Argentieri'




def spaces(driverList, driverNames, destinationConstraint, destinationAttribute, name='space', maintainOffset=True):
    """
    Add spaces
    :param driverList: list(str), driver object list
    :param driverNames: list(str), attrviute value name for each driver
    :param destinationConstraint: str, destination obj
    :param destinationAttribute: str, where attribute should appear
    :param name: str, name of the attribute
    :param maintainOffset: bool, constraint maintainOffset
    :return:
    """
    pm.addAttr(destinationAttribute, longName=name, attributeType='enum', enumName=':'.join(driverNames), k=1, dv=0)

    constraintList = []
    for driver in driverList:
        cnst = pm.parentConstraint(driver, destinationConstraint, mo=maintainOffset)
        constraintList.append(cnst)

    for counter, cnst in enumerate(constraintList):
        sourceValue = list(range(0, len(constraintList)))
        targetValue = [0] * len(constraintList)
        targetValue[counter] = 1

        target = pm.listConnections(cnst.target[counter].targetWeight, source=True, plugs=True)[0]

# Path: mayaLib/rigLib/utils/common.py
# def centerPivot(obj, targetPivot=None):
# def freezeTranform(obj):
# def deleteHistory(obj):
# def deleteNonDeformerHistory(obj):
# def deleteConnection(objAttrList):
# def setDrivenKey(driver, driverValueList, driven, drivenValueList, cvType='linear'):


# Path: mayaLib/rigLib/utils/spaces.py
import pymel.core as pm
from mayaLib.rigLib.utils import common

__author__ = 'Lorenzo Argentieri'




def spaces(driverList, driverNames, destinationConstraint, destinationAttribute, name='space', maintainOffset=True):
    """
    Add spaces
    :param driverList: list(str), driver object list
    :param driverNames: list(str), attrviute value name for each driver
    :param destinationConstraint: str, destination obj
    :param destinationAttribute: str, where attribute should appear
    :param name: str, name of the attribute
    :param maintainOffset: bool, constraint maintainOffset
    :return:
    """
    pm.addAttr(destinationAttribute, longName=name, attributeType='enum', enumName=':'.join(driverNames), k=1, dv=0)

    constraintList = []
    for driver in driverList:
        cnst = pm.parentConstraint(driver, destinationConstraint, mo=maintainOffset)
        constraintList.append(cnst)

    for counter, cnst in enumerate(constraintList):
        sourceValue = list(range(0, len(constraintList)))
        targetValue = [0] * len(constraintList)
        targetValue[counter] = 1

        target = pm.listConnections(cnst.target[counter].targetWeight, source=True, plugs=True)[0]

        common.setDrivenKey(destinationAttribute + '.' + name, sourceValue, target, targetValue)