~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Pose.c

  • Committer: Bazaar Package Importer
  • Author(s): Lukas Fittl
  • Date: 2006-09-20 01:57:27 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060920015727-gmoqlxwstx9wwqs3
Tags: 2.42a-1ubuntu1
* Merge from Debian unstable (Closes: Malone #55903). Remaining changes:
  - debian/genpot: Add python scripts from Lee June <blender@eyou.com> to
    generate a reasonable PO template from the sources. Since gettext is used
    in a highly nonstandard way, xgettext does not work for this job.
  - debian/rules: Call the scripts, generate po/blender.pot, and clean it up
    in the clean target.
  - Add a proper header to the generated PO template.
* debian/control: Build depend on libavformat-dev >= 3:0.cvs20060823-3.1,
  otherwise this package will FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "BKE_utildefines.h"
40
40
#include "BIF_editaction.h"
41
41
#include "BIF_space.h"
 
42
#include "BIF_poseobject.h"
42
43
#include "BKE_depsgraph.h"
43
44
#include "DNA_object_types.h"
44
45
#include "DNA_ipo_types.h"
49
50
#include "BLI_arithb.h"
50
51
#include "Mathutils.h"
51
52
#include "Object.h"
 
53
#include "Constraint.h"
52
54
#include "NLA.h"
53
55
#include "gen_utils.h"
54
56
 
57
59
//------------------------ERROR CODES---------------------------------
58
60
//This is here just to make me happy and to have more consistant error strings :)
59
61
static const char sPoseError[] = "Pose - Error: ";
60
 
static const char sPoseBadArgs[] = "Pose - Bad Arguments: ";
 
62
//static const char sPoseBadArgs[] = "Pose - Bad Arguments: ";
61
63
static const char sPoseBoneError[] = "PoseBone - Error: ";
62
 
static const char sPoseBoneBadArgs[] = "PoseBone - Bad Arguments: ";
 
64
//static const char sPoseBoneBadArgs[] = "PoseBone - Bad Arguments: ";
63
65
static const char sPoseBonesDictError[] = "PoseBone - Error: ";
64
 
static const char sPoseBonesDictBadArgs[] = "PoseBone - Bad Arguments: ";
 
66
//static const char sPoseBonesDictBadArgs[] = "PoseBone - Bad Arguments: ";
65
67
 
66
68
//################## PoseBonesDict_Type (internal) ########################
67
69
/*This is an internal psuedo-dictionary type that allows for manipulation
72
74
//------------------METHOD IMPLEMENTATIONS-----------------------------
73
75
//------------------------Pose.bones.items()
74
76
//Returns a list of key:value pairs like dict.items()
75
 
PyObject* PoseBonesDict_items(BPy_PoseBonesDict *self)
 
77
static PyObject* PoseBonesDict_items(BPy_PoseBonesDict *self)
76
78
{
77
79
        return PyDict_Items(self->bonesMap); 
78
80
}
79
81
//------------------------Pose.bones.keys()
80
82
//Returns a list of keys like dict.keys()
81
 
PyObject* PoseBonesDict_keys(BPy_PoseBonesDict *self)
 
83
static PyObject* PoseBonesDict_keys(BPy_PoseBonesDict *self)
82
84
{
83
85
        return PyDict_Keys(self->bonesMap);
84
86
}
85
87
//------------------------Armature.bones.values()
86
88
//Returns a list of values like dict.values()
87
 
PyObject* PoseBonesDict_values(BPy_PoseBonesDict *self)
 
89
static PyObject* PoseBonesDict_values(BPy_PoseBonesDict *self)
88
90
{
89
91
        return PyDict_Values(self->bonesMap);
90
92
}
116
118
                if (!py_posechannel)
117
119
                        return -1;
118
120
 
119
 
                if(PyDict_SetItem(dictionary, 
120
 
                        PyString_FromString(pchan->name), py_posechannel) == -1){
 
121
                if(PyDict_SetItemString(dictionary,
 
122
                                        pchan->name, py_posechannel) == -1){
121
123
                        return -1;
122
124
                }
123
125
                Py_DECREF(py_posechannel);
165
167
}
166
168
//------------------------mp_length
167
169
//This gets the size of the dictionary
168
 
int PoseBonesDict_len(BPy_PoseBonesDict *self)
 
170
static int PoseBonesDict_len(BPy_PoseBonesDict *self)
169
171
{
170
172
        return BLI_countlist(self->bones);
171
173
}
172
174
//-----------------------mp_subscript
173
175
//This defines getting a bone from the dictionary - x = Bones['key']
174
 
PyObject *PoseBonesDict_GetItem(BPy_PoseBonesDict *self, PyObject* key)
 
176
static PyObject *PoseBonesDict_GetItem(BPy_PoseBonesDict *self, PyObject* key)
175
177
176
178
        PyObject *value = NULL;
177
179
 
463
465
 
464
466
        //set the frame we want insertion on
465
467
        oldframe = G.scene->r.cfra;
466
 
        G.scene->r.cfra = (short)frame;
 
468
        G.scene->r.cfra = frame;
467
469
 
468
470
        //add the action channel if it's not there
469
471
        verify_action_channel(((BPy_Object*)parent_object)->object->action, 
498
500
        }
499
501
 
500
502
        //flip the frame back
501
 
        G.scene->r.cfra = (short)oldframe;
 
503
        G.scene->r.cfra = oldframe;
502
504
 
503
505
        //update the IPOs
504
506
        remake_action_ipos (((BPy_Object*)parent_object)->object->action);
705
707
        return EXPP_intError(PyExc_AttributeError, "%s%s%s",
706
708
                sPoseBoneError, ".poseMatrix: ", "not able to set this property");
707
709
}
708
 
////------------------------PoseBone.constraints (getter)
709
 
////Gets the constraints list
710
 
//static PyObject *PoseBone_getConstraints(BPy_PoseBone *self, void *closure)
711
 
//{
712
 
//      PyObject *list = NULL, *py_constraint = NULL;
713
 
//      bConstraint *constraint = NULL;
714
 
//
715
 
//      list = PyList_New(0);
716
 
//      for (constraint = self->posechannel->constraints.first; constraint; constraint = constraint->next){
717
 
//              py_constraint = PyConstraint_FromConstraint(constraint);
718
 
//              if (!py_constraint)
719
 
//                      return NULL;
720
 
//              if (PyList_Append(list, py_constraint) == -1){
721
 
//                      Py_DECREF(py_constraint);
722
 
//                      goto RuntimeError;
723
 
//              }
724
 
//              Py_DECREF(py_constraint);
725
 
//      }
726
 
//      return list;
727
 
//
728
 
//RuntimeError:
729
 
//      return EXPP_objError(PyExc_RuntimeError, "%s%s%s",
730
 
//              sPoseBoneError, ".constraints: ", "unable to build constraint list");
731
 
//}
732
 
////------------------------PoseBone.constraints (setter)
733
 
////Sets the constraints list
734
 
//static int PoseBone_setConstraints(BPy_PoseBone *self, PyObject *value, void *closure)
735
 
//{
736
 
//      printf("This is not implemented yet...");
737
 
//      return 1;
738
 
//}
 
710
//------------------------PoseBone.constraints (getter)
 
711
//Gets the constraints sequence
 
712
static PyObject *PoseBone_getConstraints(BPy_PoseBone *self, void *closure)
 
713
{
 
714
        return PoseConstraintSeq_CreatePyObject( self->posechannel );
 
715
}
 
716
//------------------------PoseBone.limitmin (getter)
 
717
//Gets the pose bone limitmin value
 
718
static PyObject *PoseBone_getLimitMin(BPy_PoseBone *self, void *closure)
 
719
{
 
720
        float mylimitmin[3];
 
721
        Object *obj = NULL;
 
722
 
 
723
        obj = Object_FromPoseChannel(self->posechannel);
 
724
        if (obj==NULL){
 
725
                return EXPP_ReturnPyObjError(PyExc_AttributeError, "Bone data is not found");
 
726
        }
 
727
        mylimitmin[0]=0.0f;
 
728
        mylimitmin[1]=0.0f;
 
729
        mylimitmin[2]=0.0f;
 
730
        if(pose_channel_in_IK_chain(obj, self->posechannel)){
 
731
                if ((self->posechannel->ikflag & BONE_IK_NO_XDOF)==0) {
 
732
                        if ((self->posechannel->ikflag & BONE_IK_XLIMIT)) {
 
733
                                mylimitmin[0] = self->posechannel->limitmin[0];
 
734
                        }
 
735
                }
 
736
                if ((self->posechannel->ikflag & BONE_IK_NO_YDOF)==0) {
 
737
                        if ((self->posechannel->ikflag & BONE_IK_YLIMIT)) {
 
738
                                mylimitmin[1] = self->posechannel->limitmin[1];
 
739
                        }
 
740
                }
 
741
                if ((self->posechannel->ikflag & BONE_IK_NO_ZDOF)==0) {
 
742
                        if ((self->posechannel->ikflag & BONE_IK_ZLIMIT)) {
 
743
                                mylimitmin[2] = self->posechannel->limitmin[2];
 
744
                        }
 
745
                }
 
746
        }
 
747
        return newVectorObject(mylimitmin, 3, Py_NEW);
 
748
}
 
749
//------------------------PoseBone.limitmin (setter)
 
750
//Sets the pose bone limitmin value
 
751
static int PoseBone_setLimitMin(BPy_PoseBone *self, PyObject *value, void *closure)
 
752
{
 
753
        float newlimitmin[3];
 
754
        int x;
 
755
        Object *obj = NULL;
 
756
        if(!PySequence_Check(value)){
 
757
                return EXPP_ReturnIntError(PyExc_AttributeError, "Argument is not a sequence");
 
758
        }
 
759
        if (PySequence_Size(value) !=3){
 
760
                return EXPP_ReturnIntError(PyExc_AttributeError, "Argument size must be 3");
 
761
        }
 
762
        newlimitmin[0]=0.0f;
 
763
        newlimitmin[1]=0.0f;
 
764
        newlimitmin[2]=0.0f;
 
765
        for (x = 0; x<3;x++){
 
766
                PyObject *item;
 
767
                item = PySequence_GetItem(value, x); //new reference
 
768
                if (PyFloat_Check(item)){
 
769
                        newlimitmin[x] = (float)PyFloat_AsDouble(item);
 
770
                }else if (PyInt_Check(item)){
 
771
                        newlimitmin[x] = (float)PyInt_AsLong(item);
 
772
                }
 
773
                Py_DECREF(item);
 
774
        }
 
775
        obj = Object_FromPoseChannel(self->posechannel);
 
776
        if (obj==NULL){
 
777
                return EXPP_ReturnIntError(PyExc_AttributeError, "Bone data is not found");
 
778
        }
 
779
        if(!pose_channel_in_IK_chain(obj, self->posechannel)){
 
780
                return EXPP_ReturnIntError(PyExc_AttributeError, "Bone is not part of an IK chain");
 
781
        }
 
782
        if ((self->posechannel->ikflag & BONE_IK_NO_XDOF)==0) {
 
783
                if ((self->posechannel->ikflag & BONE_IK_XLIMIT)) {
 
784
                        self->posechannel->limitmin[0] = EXPP_ClampFloat(newlimitmin[0], -180.0f, 0.0f);
 
785
                }
 
786
        }
 
787
        if ((self->posechannel->ikflag & BONE_IK_NO_YDOF)==0) {
 
788
                if ((self->posechannel->ikflag & BONE_IK_YLIMIT)) {
 
789
                        self->posechannel->limitmin[1] = EXPP_ClampFloat(newlimitmin[1], -180.0f, 0.0f);
 
790
                }
 
791
        }
 
792
        if ((self->posechannel->ikflag & BONE_IK_NO_ZDOF)==0) {
 
793
                if ((self->posechannel->ikflag & BONE_IK_ZLIMIT)) {
 
794
                        self->posechannel->limitmin[2] = EXPP_ClampFloat(newlimitmin[2], -180.0f, 0.0f);
 
795
                }
 
796
        }
 
797
        DAG_object_flush_update(G.scene, obj, OB_RECALC_DATA);
 
798
        return 0;
 
799
}
 
800
 
 
801
//------------------------PoseBone.limitmax (getter)
 
802
//Gets the pose bone limitmax value
 
803
static PyObject *PoseBone_getLimitMax(BPy_PoseBone *self, void *closure)
 
804
{
 
805
        float mylimitmax[3];
 
806
        Object *obj = NULL;
 
807
 
 
808
        obj = Object_FromPoseChannel(self->posechannel);
 
809
        if (obj==NULL){
 
810
                return EXPP_ReturnPyObjError(PyExc_AttributeError, "Bone data is not found");
 
811
        }
 
812
        mylimitmax[0]=0.0f;
 
813
        mylimitmax[1]=0.0f;
 
814
        mylimitmax[2]=0.0f;
 
815
        if(pose_channel_in_IK_chain(obj, self->posechannel)){
 
816
                if ((self->posechannel->ikflag & BONE_IK_NO_XDOF)==0) {
 
817
                        if ((self->posechannel->ikflag & BONE_IK_XLIMIT)) {
 
818
                                mylimitmax[0] = self->posechannel->limitmax[0];
 
819
                        }
 
820
                }
 
821
                if ((self->posechannel->ikflag & BONE_IK_NO_YDOF)==0) {
 
822
                        if ((self->posechannel->ikflag & BONE_IK_YLIMIT)) {
 
823
                                mylimitmax[1] = self->posechannel->limitmax[1];
 
824
                        }
 
825
                }
 
826
                if ((self->posechannel->ikflag & BONE_IK_NO_ZDOF)==0) {
 
827
                        if ((self->posechannel->ikflag & BONE_IK_ZLIMIT)) {
 
828
                                mylimitmax[2] = self->posechannel->limitmax[2];
 
829
                        }
 
830
                }
 
831
        }
 
832
        return newVectorObject(mylimitmax, 3, Py_NEW);
 
833
}
 
834
//------------------------PoseBone.limitmax (setter)
 
835
//Sets the pose bone limitmax value
 
836
static int PoseBone_setLimitMax(BPy_PoseBone *self, PyObject *value, void *closure)
 
837
{
 
838
        float newlimitmax[3];
 
839
        int x;
 
840
        Object *obj = NULL;
 
841
        if(!PySequence_Check(value)){
 
842
                return EXPP_ReturnIntError(PyExc_AttributeError, "Argument is not a sequence");
 
843
        }
 
844
        if (PySequence_Size(value) !=3){
 
845
                return EXPP_ReturnIntError(PyExc_AttributeError, "Argument size must be 3");
 
846
        }
 
847
        newlimitmax[0]=0.0f;
 
848
        newlimitmax[1]=0.0f;
 
849
        newlimitmax[2]=0.0f;
 
850
        for (x = 0; x<3;x++){
 
851
                PyObject *item;
 
852
                item = PySequence_GetItem(value, x); //new reference
 
853
                if (PyFloat_Check(item)){
 
854
                        newlimitmax[x] = (float)PyFloat_AsDouble(item);
 
855
                }else if (PyInt_Check(item)){
 
856
                        newlimitmax[x] = (float)PyInt_AsLong(item);
 
857
                }
 
858
                Py_DECREF(item);
 
859
        }
 
860
        obj = Object_FromPoseChannel(self->posechannel);
 
861
        if (obj==NULL){
 
862
                return EXPP_ReturnIntError(PyExc_AttributeError, "Bone data is not found");
 
863
        }
 
864
        if(!pose_channel_in_IK_chain(obj, self->posechannel)){
 
865
                return EXPP_ReturnIntError(PyExc_AttributeError, "Bone is not part of an IK chain");
 
866
        }
 
867
        if ((self->posechannel->ikflag & BONE_IK_NO_XDOF)==0) {
 
868
                if ((self->posechannel->ikflag & BONE_IK_XLIMIT)) {
 
869
                        self->posechannel->limitmax[0] = EXPP_ClampFloat(newlimitmax[0], 0.0f, 180.0f);
 
870
                }
 
871
        }
 
872
        if ((self->posechannel->ikflag & BONE_IK_NO_YDOF)==0) {
 
873
                if ((self->posechannel->ikflag & BONE_IK_YLIMIT)) {
 
874
                        self->posechannel->limitmax[1] = EXPP_ClampFloat(newlimitmax[1], 0.0f, 180.0f);
 
875
                }
 
876
        }
 
877
        if ((self->posechannel->ikflag & BONE_IK_NO_ZDOF)==0) {
 
878
                if ((self->posechannel->ikflag & BONE_IK_ZLIMIT)) {
 
879
                        self->posechannel->limitmax[2] = EXPP_ClampFloat(newlimitmax[2], 0.0f, 180.0f);
 
880
                }
 
881
        }
 
882
        DAG_object_flush_update(G.scene, obj, OB_RECALC_DATA);
 
883
        return 0;
 
884
}
739
885
//------------------------PoseBone.head (getter)
740
886
//Gets the pose head position
741
887
static PyObject *PoseBone_getHead(BPy_PoseBone *self, void *closure)
782
928
                "The pose bone's head positon", NULL},
783
929
        {"tail", (getter)PoseBone_getTail, (setter)PoseBone_setTail, 
784
930
                "The pose bone's tail positon", NULL},
785
 
        //{"constraints", (getter)PoseBone_getConstraints, (setter)PoseBone_setConstraints, 
786
 
        //      "The list of contraints that pertain to this pose bone", NULL},
 
931
    {"limitMin", (getter)PoseBone_getLimitMin, (setter)PoseBone_setLimitMin,
 
932
        "The pose bone dof min", NULL},
 
933
    {"limitMax", (getter)PoseBone_getLimitMax, (setter)PoseBone_setLimitMax,
 
934
        "The pose bone dof max", NULL},
 
935
        {"constraints", (getter)PoseBone_getConstraints, (setter)NULL, 
 
936
                "The list of contraints that pertain to this pose bone", NULL},
787
937
        {NULL, NULL, NULL, NULL, NULL}
788
938
};
789
939
//------------------------tp_dealloc
938
1088
        return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
939
1089
                sPoseBoneError, "PyPoseBone_FromPosechannel: ", "Internal Error Ocurred");
940
1090
}
 
1091
//------------------------------Object_FromPoseChannel (internal)
 
1092
//An ugly method for determining where the pchan chame from
 
1093
Object *Object_FromPoseChannel(bPoseChannel *curr_pchan)
 
1094
{
 
1095
        int success = 0;
 
1096
        Object *obj = NULL;
 
1097
        bPoseChannel *pchan = NULL;
 
1098
        for(obj = G.main->object.first; obj; obj = obj->id.next){
 
1099
                if (obj->pose){
 
1100
                        for (pchan = obj->pose->chanbase.first; pchan; pchan = pchan->next){
 
1101
                                if (curr_pchan == pchan){
 
1102
                                        success = 1;
 
1103
                                        break;
 
1104
                                }
 
1105
                        }
 
1106
                        if (success)
 
1107
                                break;
 
1108
                }
 
1109
        }
 
1110
        return obj;
 
1111
}