#-------------------------------------------------------------------------------
# Name:        YJ_RebulidBodyBone
# Purpose:     Rebulid Bone
#
# Author:      yangjie
#
# Created:     04/07/2014
# Copyright:   (c) yangjie 2014
# Licence:     <haha>
#-------------------------------------------------------------------------------
from YJ_RigTool_P import*
from YJ_Rig_Pub import*

def YJ_Rebulid_Bone_Main():

    Neck_CB_V,Arm_CB_V,Finger_CB_V,Leg_CB_V,Type,Bone_Rad,Spine_Jnt_seg,Neck_Jnt_seg,Finger_Jnt_Nub,Finger_Jnt_seg  = YJ_Load_List('AttrValueList.pkl')[:]
    orientJoint,SecAO = 'xyz','zup'
    L_LegJnt_List = YJ_Load_List('L_LegJnt_List.pkl')
    L_FootJnt_List = YJ_Load_List('L_FootJnt_List.pkl')
    L_Help_FootJnt_List = YJ_Load_List('L_Help_FootJnt_List.pkl')
    L_toeJnt_List = YJ_Load_List('L_toeJnt_List.pkl')
    Hip_Jnt_List = YJ_Load_List('Hip_Jnt_List.pkl')
    Spine_Jnt_List = YJ_Load_List('Spine_Jnt_List.pkl')
    Neck_Jnt_List = YJ_Load_List('Neck_Jnt_List.pkl')
    L_Shloud_Jnt_List = YJ_Load_List('L_Shloud_Jnt_List.pkl')
    L_Arm_Jnt_List = YJ_Load_List('L_Arm_Jnt_List.pkl')
    Hand_Help_Jnt_L = YJ_Load_List('Hand_Help_Jnt_L.pkl')
    L_FingerAllList_Lis = YJ_Load_List('L_FingerAllList_Lis.pkl')

    YJ_Judge_Rebuild_for_Leg(Leg_CB_V,L_LegJnt_List,orientJoint,SecAO)
    YJ_Judge_Rebuild_for_Foot(Leg_CB_V,L_FootJnt_List,L_Help_FootJnt_List,L_toeJnt_List,orientJoint,SecAO)
    YJ_Judge_Rebuild_for_Spine(Leg_CB_V,Hip_Jnt_List,Spine_Jnt_List,orientJoint,SecAO)
    YJ_Judge_Rebuild_for_Neck(Neck_CB_V,Neck_Jnt_List,orientJoint,SecAO)
    YJ_Judge_Rebuild_for_Shloud(Arm_CB_V,L_Shloud_Jnt_List,orientJoint,SecAO)
    YJ_Judge_Rebuild_for_Arm(Arm_CB_V,L_Arm_Jnt_List,orientJoint,SecAO)
    YJ_Judge_Rebuild_for_Finger(Finger_CB_V,Hand_Help_Jnt_L,L_FingerAllList_Lis,orientJoint,SecAO)

##
def YJ_Judge_Rebuild_for_Leg(Leg_CB_V,L_LegJnt_List,orientJoint,SecAO):
    if Leg_CB_V == 0:
        L_Reb_LegJnt_List,R_Reb_LegJnt_List = YJ_Rebuild_Leg_Bone(L_LegJnt_List,orientJoint,SecAO)
    elif Leg_CB_V == 1:
        L_Reb_LegJnt_List,R_Reb_LegJnt_List = [],[]
##
def YJ_Judge_Rebuild_for_Foot(Leg_CB_V,L_FootJnt_List,L_Help_FootJnt_List,L_toeJnt_List,orientJoint,SecAO):
    if Leg_CB_V == 0:
        L_FootJnt_List,R_FootJnt_List,L_Help_FootJnt_List,R_Help_FootJnt_List = YJ_Rebuild_Foot_Bone(L_FootJnt_List,L_Help_FootJnt_List,L_toeJnt_List,orientJoint,SecAO)
    elif Leg_CB_V == 1:
        L_FootJnt_List,R_FootJnt_List,L_Help_FootJnt_List,R_Help_FootJnt_List = [],[],[],[]
##
def YJ_Judge_Rebuild_for_Spine(Leg_CB_V,Hip_Jnt_List,Spine_Jnt_List,orientJoint,SecAO):
    Spine_Reb_Jnt_List = YJ_Rebuild_HipSpine_Bone(Hip_Jnt_List,Spine_Jnt_List,orientJoint,SecAO)

##
def YJ_Judge_Rebuild_for_Neck(Neck_CB_V,Neck_Jnt_List,orientJoint,SecAO):
    if Neck_CB_V == 0:
        Neck_Reb_Jnt_List =YJ_Rebuild_Neck_Bone(Neck_Jnt_List,orientJoint,SecAO)
    elif Neck_CB_V == 1:
        Neck_Reb_Jnt_List = []
##
def YJ_Judge_Rebuild_for_Shloud(Arm_CB_V,L_Shloud_Jnt_List,orientJoint,SecAO):
    if Arm_CB_V == 0:
        L_Reb_Shloud_Jnt_List,R_Reb_Shloud_Jnt_List = YJ_Rebuild_Shloud_Bone(L_Shloud_Jnt_List,orientJoint,SecAO)
    elif Arm_CB_V == 1:
        L_Reb_Shloud_Jnt_List,R_Reb_Shloud_Jnt_List = [],[]
##
def YJ_Judge_Rebuild_for_Arm(Arm_CB_V,L_Arm_Jnt_List,orientJoint,SecAO):
    if Arm_CB_V == 0:
        L_Reb_Arm_Jnt_List, R_Reb_Arm_Jnt_List   = YJ_Rebuild_Arm_Bone(L_Arm_Jnt_List,orientJoint,SecAO)
    elif Arm_CB_V == 1:
        L_Reb_Arm_Jnt_List, R_Reb_Arm_Jnt_List = [],[]
##
def YJ_Judge_Rebuild_for_Finger(Finger_CB_V,Hand_Help_Jnt_L,L_FingerAllList_Lis,orientJoint,SecAO):
    if Finger_CB_V == 0:
        L_Reb_FingerAllList_Lis, R_Reb_FingerAllList_Lis   =  YJ_Rebuild_Finger_Bone(Hand_Help_Jnt_L,L_FingerAllList_Lis,orientJoint,SecAO)
    elif Finger_CB_V == 1:
        L_Reb_FingerAllList_Lis, R_Reb_FingerAllList_Lis  = [],[]
##

def YJ_Rebuild_Leg_Bone(L_LegJnt_List,orientJoint,SecAO):
    R_LegJnt_List = YJ_GetMir_List(L_LegJnt_List)
    delete( R_LegJnt_List[0] )
    YJ_Lock_Attribute(0,L_LegJnt_List,0,1)
    YJ_FreezeAttr(L_LegJnt_List)
    YJ_OrientJnt(L_LegJnt_List,orientJoint,SecAO)
    R_LegJnt_List = YJ_MirJoint(L_LegJnt_List)
    return L_LegJnt_List,R_LegJnt_List

def YJ_Rebuild_Foot_Bone(L_FootJnt_List,L_Help_FootJnt_List,L_toeJnt_List,orientJoint,SecAO):
    R_FootJnt_List = YJ_GetMir_List(L_FootJnt_List)
    delete( R_FootJnt_List[0] )
    YJ_Lock_Attribute(0,L_FootJnt_List,0,1)
    for i in L_Help_FootJnt_List:
        parent(i,world = 1)
    YJ_FreezeAttr(L_toeJnt_List)
    YJ_OrientJnt(L_toeJnt_List,orientJoint,SecAO)
    for i in L_Help_FootJnt_List:
        YJ_Try_Parent(i,L_toeJnt_List[0])
    R_FootJnt_List = YJ_MirJoint(L_FootJnt_List)
    R_Help_FootJnt_List = YJ_GetMir_List(L_Help_FootJnt_List)
    return L_FootJnt_List,R_FootJnt_List,L_Help_FootJnt_List,R_Help_FootJnt_List


def YJ_Rebuild_HipSpine_Bone(Hip_Jnt_List,Spine_Jnt_List,orientJoint,SecAO):
    YJ_Lock_Attribute(0,Spine_Jnt_List,0,1)
    YJ_FreezeAttr(Spine_Jnt_List)
    YJ_OrientJnt(Spine_Jnt_List,orientJoint,SecAO)
    return Spine_Jnt_List

def YJ_Rebuild_Neck_Bone(Neck_Jnt_List,orientJoint,SecAO):
    YJ_Lock_Attribute(0,Neck_Jnt_List,0,1)
    YJ_FreezeAttr(Neck_Jnt_List)
    YJ_OrientJnt(Neck_Jnt_List,orientJoint,SecAO)
    return  Neck_Jnt_List

def YJ_Rebuild_Shloud_Bone(L_Shloud_Jnt_List,orientJoint,SecAO):
    R_Shloud_Jnt_List = YJ_GetMir_List(L_Shloud_Jnt_List)
    delete( R_Shloud_Jnt_List[0] )
    YJ_Lock_Attribute(0,L_Shloud_Jnt_List,0,1)
    YJ_FreezeAttr(L_Shloud_Jnt_List)
    YJ_OrientJnt(L_Shloud_Jnt_List,orientJoint,SecAO)
    R_Shloud_Jnt_List = YJ_MirJoint(L_Shloud_Jnt_List)
    return  L_Shloud_Jnt_List,R_Shloud_Jnt_List

def YJ_Rebuild_Arm_Bone(L_Arm_Jnt_List,orientJoint,SecAO):
    R_Arm_Jnt_List = YJ_GetMir_List(L_Arm_Jnt_List)
    delete( R_Arm_Jnt_List[0] )
    YJ_Lock_Attribute(0,L_Arm_Jnt_List,0,1)
    YJ_FreezeAttr(L_Arm_Jnt_List)
    YJ_OrientJnt(L_Arm_Jnt_List,orientJoint,SecAO)
    R_Arm_Jnt_List = YJ_MirJoint(L_Arm_Jnt_List)
    return L_Arm_Jnt_List, R_Arm_Jnt_List

def YJ_Rebuild_Finger_Bone(Hand_Help_Jnt_L,L_FingerAllList_Lis,orientJoint,SecAO):
    R_FingerAllList_Lis = []
    Hand_Help_Jnt_R = YJ_GetMir_List(Hand_Help_Jnt_L)
    delete( Hand_Help_Jnt_R[0] )
    for i in L_FingerAllList_Lis:
        parent(i[0],world = 1)
    delete( Hand_Help_Jnt_L[0] )
    for i in  L_FingerAllList_Lis:
        YJ_Lock_Attribute(0,i,0,1)
        YJ_Lock_Attribute(0,i,0,1)
        YJ_Lock_Attribute(0,i,0,1)
        YJ_FreezeAttr(i)
        YJ_OrientJnt(i,orientJoint,SecAO)
        R_i = YJ_MirJoint(i)
        R_FingerAllList_Lis.append(R_i)
    return L_FingerAllList_Lis,R_FingerAllList_Lis