# Path: mayaLib/rigLib/utils/attributes.py
# def addVectorAttribute(object, name, defaultValue=[0, 0, 0]):
# def addFloatAttribute(object, name, defaultValue=0, keyable=False, minValue=None, maxValue=None):
# 
# 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/name.py
# def removeSuffix(name):
# def getSide(name):
# def getAlpha(i):
# 
# Path: mayaLib/rigLib/utils/util.py
# def getDriverDrivenFromConstraint(constraint):
# def returnDriverObject(attribute, skipConversionNodes=False):
# def returnDrivenAttribute(attribute, skipConversionNodes=False):
# def returnDrivenObject(attribute, skipConversionNodes=True):
# def getAllObjectUnderGroup(group, type='mesh'):
# def moveShape(source, destination):
# def get_distance(obj1, obj2):
#     def ctr_dist(objA, objB):
# def get_distance_from_coords(bboxMin, bboxMax):
# def lock_and_hide_all(node):
# def unlock_and_unhide_all(node):
# def no_render(tgt):
# def invertSelection():
# def getPlanarRadiusBBOXFromTransform(transform, radiusFactor=2):
# def matrixConstrain(driver, driven, parent=None, translate=True, rotate=True, scale=False):


import math
import pymel.core as pm
from mayaLib.rigLib.utils import attributes
from mayaLib.rigLib.utils import common
from mayaLib.rigLib.utils import name
from mayaLib.rigLib.utils import util

    rightHandJntList = pm.ls('r_handJA_JNT', 'r_fngMiddleJA_JNT')
    for i, jnt in enumerate(rightHandJntList[:-1]):
        angle = setJointParallelToGrid(rightHandJntList[i], rightHandJntList[i + 1])
        pm.xform(jnt, r=True, ro=(0, 0, -angle), ws=True)


class TwistJoint():
    """
    Add Twist Joint for selected Joint
    :param joint_selection:
    :param n_twist_joint:
    :return:
    """

    def __init__(self, parentJoint, parentGrp='rig_GRP', nTwistJoint=3, rotAxis='X'):
        if not pm.objExists(parentGrp):
            pm.group(n=parentGrp, em=True)

        if not pm.objExists('twistJoints_GRP'):
            self.twistJointsMainGrp = pm.group(n='twistJoints_GRP', p=parentGrp, em=1)
        else:
            self.twistJointsMainGrp = pm.ls('twistJoints_GRP')[0]

        if isinstance(parentJoint, str):
            self.maketwistJoints(pm.ls(parentJoint)[0], nTwistJoint, rotAxis)
        else:
            for jnt in parentJoint:
                self.maketwistJoints(jnt, nTwistJoint, rotAxis)

    def maketwistJoints(self, parentJnt, nTwistJoint, rotAxis):

# Path: mayaLib/rigLib/utils/attributes.py
# def addVectorAttribute(object, name, defaultValue=[0, 0, 0]):
# def addFloatAttribute(object, name, defaultValue=0, keyable=False, minValue=None, maxValue=None):
# 
# 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/name.py
# def removeSuffix(name):
# def getSide(name):
# def getAlpha(i):
# 
# Path: mayaLib/rigLib/utils/util.py
# def getDriverDrivenFromConstraint(constraint):
# def returnDriverObject(attribute, skipConversionNodes=False):
# def returnDrivenAttribute(attribute, skipConversionNodes=False):
# def returnDrivenObject(attribute, skipConversionNodes=True):
# def getAllObjectUnderGroup(group, type='mesh'):
# def moveShape(source, destination):
# def get_distance(obj1, obj2):
#     def ctr_dist(objA, objB):
# def get_distance_from_coords(bboxMin, bboxMax):
# def lock_and_hide_all(node):
# def unlock_and_unhide_all(node):
# def no_render(tgt):
# def invertSelection():
# def getPlanarRadiusBBOXFromTransform(transform, radiusFactor=2):
# def matrixConstrain(driver, driven, parent=None, translate=True, rotate=True, scale=False):


# Path: mayaLib/rigLib/utils/joint.py
import math
import pymel.core as pm
from mayaLib.rigLib.utils import attributes
from mayaLib.rigLib.utils import common
from mayaLib.rigLib.utils import name
from mayaLib.rigLib.utils import util

    rightHandJntList = pm.ls('r_handJA_JNT', 'r_fngMiddleJA_JNT')
    for i, jnt in enumerate(rightHandJntList[:-1]):
        angle = setJointParallelToGrid(rightHandJntList[i], rightHandJntList[i + 1])
        pm.xform(jnt, r=True, ro=(0, 0, -angle), ws=True)


class TwistJoint():
    """
    Add Twist Joint for selected Joint
    :param joint_selection:
    :param n_twist_joint:
    :return:
    """

    def __init__(self, parentJoint, parentGrp='rig_GRP', nTwistJoint=3, rotAxis='X'):
        if not pm.objExists(parentGrp):
            pm.group(n=parentGrp, em=True)

        if not pm.objExists('twistJoints_GRP'):
            self.twistJointsMainGrp = pm.group(n='twistJoints_GRP', p=parentGrp, em=1)
        else:
            self.twistJointsMainGrp = pm.ls('twistJoints_GRP')[0]

        if isinstance(parentJoint, str):
            self.maketwistJoints(pm.ls(parentJoint)[0], nTwistJoint, rotAxis)
        else:
            for jnt in parentJoint:
                self.maketwistJoints(jnt, nTwistJoint, rotAxis)

    def maketwistJoints(self, parentJnt, nTwistJoint, rotAxis):

        prefix = name.removeSuffix(parentJnt)
