# Path: pdil/tool/fossil/_core/find.py
# def rootBone(nodes=None):
# def controllers(main=None):
# def mainGroup(nodePool=None, fromControl=None):
# def mainGroups():
# def rootMotion(main=None):
# def blueprintCards(skeletonBlueprint=None):
#     def order(obj):
# def cardJointBuildOrder():
# def cardHierarchy():
#     def gatherChildren(cards):
# 
# Path: pdil/tool/fossil/_core/ids.py
# def getIdSpec(obj):
# def readIdSpec(spec):
#     def __init__(cls, name, bases, clsdict):
#     def getSpec(cls, obj):
#     def readSpec(cls, data):
#     def baseSpec(cls, obj):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
# class RegisterSpec(type):
# class IdSpec(six.with_metaclass(RegisterSpec)):
# class SubControllerSpec(IdSpec):
# class RigControllerSpec(IdSpec):
# class CardSpec(IdSpec):
# class BPJointSpec(IdSpec):
# class JointSpec(IdSpec):
# class UnknownSpec(IdSpec):
# 
# Path: pdil/tool/fossil/_lib/tpose/tpcore.py
# def getRCard(card, validCards=None):
#     ''' Given a regular bp card, returns the reposeCard from the list of `validCards`
#     Use `getValidReposeCards()` for `validCards` (this is performance optimization).
#     '''
#     validCards = validCards if validCards else getValidReposeCards()
#     
#     for plug in card.message.listConnections(s=False, d=True, p=True):
#         if plug.attrName() == 'bpCard':
#             if plug.node() in validCards:
#                 return plug.node()
# 
# def getRJoint(bpj):
#     ''' Get repositioned joint from blueprint joint
#     '''
#     for plug in bpj.message.listConnections(s=False, d=True, p=True):
#         if plug.attrName() == 'bpj':
#             return plug.node()


from collections import OrderedDict
from copy import deepcopy
from pymel.core import dt, move, PyNode, rotate, xform
from ..._core import find
from ..._core import ids
from .tpcore import getRCard, getRJoint
import inspect
import math
import operator
import re
import pdil
@registerAdjuster
def fingerAlign(_card, baseJoint ):
    ''' Points joints directly down +X with up vector along -Z
    '''
    
    fingerCardRepose = getCardParent(getRJoint(baseJoint))
    
    xform( fingerCardRepose, ws=True, ro=[90, 90, 180] )
    
    reposes = [getRJoint(j) for j in baseJoint.card.joints]
    
    for jointA, jointB in zip(reposes, reposes[1:]):
        bPos = pdil.dagObj.getPos( jointB )
        aPos = pdil.dagObj.getPos( jointA )
        out = bPos - aPos
        toRotate = math.degrees( out.angle( (1, 0, 0) ) )
        
        if aPos.y < bPos.y:
            toRotate *= -1
        
        rotate(jointA, [0, 0, toRotate ], ws=True, r=True)

    
@registerAdjuster(anyJoint=['referenceJoint'])
def pelvisAlign( pelvisCard, referenceJoint ):
    ''' Adjusts the height by how much the reference joint moves in the repose.
    
    Commonly on the pelvis, with toe as referenceJoint.  When the legs are straighted, this will raise
    the repose to maintain floor contant.
    '''

# Path: pdil/tool/fossil/_core/find.py
# def rootBone(nodes=None):
# def controllers(main=None):
# def mainGroup(nodePool=None, fromControl=None):
# def mainGroups():
# def rootMotion(main=None):
# def blueprintCards(skeletonBlueprint=None):
#     def order(obj):
# def cardJointBuildOrder():
# def cardHierarchy():
#     def gatherChildren(cards):
# 
# Path: pdil/tool/fossil/_core/ids.py
# def getIdSpec(obj):
# def readIdSpec(spec):
#     def __init__(cls, name, bases, clsdict):
#     def getSpec(cls, obj):
#     def readSpec(cls, data):
#     def baseSpec(cls, obj):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
#     def getSpec(self, obj):
#     def readSpec(self, spec):
# class RegisterSpec(type):
# class IdSpec(six.with_metaclass(RegisterSpec)):
# class SubControllerSpec(IdSpec):
# class RigControllerSpec(IdSpec):
# class CardSpec(IdSpec):
# class BPJointSpec(IdSpec):
# class JointSpec(IdSpec):
# class UnknownSpec(IdSpec):
# 
# Path: pdil/tool/fossil/_lib/tpose/tpcore.py
# def getRCard(card, validCards=None):
#     ''' Given a regular bp card, returns the reposeCard from the list of `validCards`
#     Use `getValidReposeCards()` for `validCards` (this is performance optimization).
#     '''
#     validCards = validCards if validCards else getValidReposeCards()
#     
#     for plug in card.message.listConnections(s=False, d=True, p=True):
#         if plug.attrName() == 'bpCard':
#             if plug.node() in validCards:
#                 return plug.node()
# 
# def getRJoint(bpj):
#     ''' Get repositioned joint from blueprint joint
#     '''
#     for plug in bpj.message.listConnections(s=False, d=True, p=True):
#         if plug.attrName() == 'bpj':
#             return plug.node()


# Path: pdil/tool/fossil/_lib/tpose/adjusters.py
from collections import OrderedDict
from copy import deepcopy
from pymel.core import dt, move, PyNode, rotate, xform
from ..._core import find
from ..._core import ids
from .tpcore import getRCard, getRJoint
import inspect
import math
import operator
import re
import pdil

@registerAdjuster
def fingerAlign(_card, baseJoint ):
    ''' Points joints directly down +X with up vector along -Z
    '''
    
    fingerCardRepose = getCardParent(getRJoint(baseJoint))
    
    xform( fingerCardRepose, ws=True, ro=[90, 90, 180] )
    
    reposes = [getRJoint(j) for j in baseJoint.card.joints]
    
    for jointA, jointB in zip(reposes, reposes[1:]):
        bPos = pdil.dagObj.getPos( jointB )
        aPos = pdil.dagObj.getPos( jointA )
        out = bPos - aPos
        toRotate = math.degrees( out.angle( (1, 0, 0) ) )
        
        if aPos.y < bPos.y:
            toRotate *= -1
        
        rotate(jointA, [0, 0, toRotate ], ws=True, r=True)

    
@registerAdjuster(anyJoint=['referenceJoint'])
def pelvisAlign( pelvisCard, referenceJoint ):
    ''' Adjusts the height by how much the reference joint moves in the repose.
    
    Commonly on the pelvis, with toe as referenceJoint.  When the legs are straighted, this will raise
    the repose to maintain floor contant.
    '''

    pelvisCardRepose = getRCard( pelvisCard )