#-------------------------------------------------------------------------------
# Name:        YJ_CreateRCIK_Rig_P
# Purpose:
#
# Author:      YangJie
#
# Created:     12/07/2014
# Copyright:   (c) YangJie 2014
# Email:        691633493@
#-------------------------------------------------------------------------------
from YJ_Rig_Pub import*
from YJ_IK_Rig import*

#JntLis = Shoulder_List
def YJ_CreateRC_IK_Rig(JntLis):
    ZeroCreate = YJRigZeroGrp([JntLis[0]])
    parent(ZeroCreate,w=True )
    RC_Grp = rename(ZeroCreate[0],JntLis[0]+'_RC_Grp' )
    RcIK = YJ_Creat_IK(JntLis[0],JntLis[-1],'ikSCsolver' )
    IK_LocStart,IK_LocEnd,IK_CV = YJ_CreateStre_RCIK(JntLis,RcIK)
    YJ_CleanRC_Layer(IK_LocStart,IK_LocEnd,IK_CV,RC_Grp)
    setAttr (IK_CV + ".inheritsTransform",0)
    return RC_Grp,IK_LocEnd



def YJ_CreateStre_RCIK(JntLis,RcIK):
    IK_LocStart=CreatLocToTarget(JntLis[0]+'LocStar',JntLis[0])
    IK_LocEnd=CreatLocToTarget(JntLis[0]+'LocEnd',JntLis[-1])
    IK_CV,IK_CV_inf=CreatStretchCV(IK_LocStart ,IK_LocEnd,JntLis[0]+'_CV')
    Length=getAttr('%s.arcLength'%IK_CV_inf)
    VPM = YJ_getTranValue_PM(JntLis[-1],'.tx')
    LengthV = Length * VPM
    YJ_Try_Parent(RcIK,IK_LocEnd)
    IK_CVD=YJ_CreateMDNode(IK_CV,Length,2)
    IK_CVM=YJ_CreateMDNode(IK_CV,LengthV,1)

    connectAttr('%s.arcLength'%IK_CV_inf,'%s.input1X'%IK_CVD,f=1)
    connectAttr('%s.outputX'%IK_CVD,'%s.input1X'%IK_CVM,f=1)
    connectAttr( '%s.outputX'%IK_CVM,'%s.translateX'%JntLis[-1],f=1)
    return IK_LocStart,IK_LocEnd,IK_CV

def YJ_CleanRC_Layer(IK_LocStart,IK_LocEnd,IK_CV,RC_Grp):
    YJ_Try_Parent(IK_LocStart,RC_Grp)
    YJ_Try_Parent(IK_LocEnd,RC_Grp)
    YJ_Try_Parent(IK_CV,RC_Grp)
    setAttr(IK_LocStart+'.v',0)
    setAttr(IK_LocEnd+'.v',0)
    setAttr(IK_CV+'.v',0)