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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: Armature.c,v 1.53 2007/01/31 03:12:26 stiv Exp $
 
2
 * $Id: Armature.c,v 1.61 2007/03/26 02:10:21 campbellbarton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
42
42
#include "Bone.h"
43
43
#include "NLA.h"
44
44
#include "gen_utils.h"
 
45
#include "gen_library.h"
45
46
 
46
47
#include "DNA_object_types.h" //This must come before BIF_editarmature.h...
47
48
#include "BIF_editarmature.h"
511
512
        bArmature *bl_armature;
512
513
        bl_armature= copy_armature(self->armature);
513
514
        bl_armature->id.us= 0;
514
 
        py_armature= PyArmature_FromArmature( bl_armature );
 
515
        py_armature= Armature_CreatePyObject( bl_armature );
515
516
        return py_armature;
516
517
}
517
518
 
610
611
                        "expected a list of integers" );
611
612
}
612
613
 
613
 
//------------------------Armature.users (getter)
614
 
static PyObject *Armature_getUsers( BPy_Armature * self )
615
 
{
616
 
        return PyInt_FromLong( self->armature->id.us );
617
 
}
618
 
 
619
 
 
620
 
//------------------------Armature.fakeUser (getter)
621
 
static PyObject *Armature_getFakeUser( BPy_Armature * self )
622
 
{
623
 
        if (self->armature->id.flag & LIB_FAKEUSER)
624
 
                Py_RETURN_TRUE;
625
 
        else
626
 
                Py_RETURN_FALSE;
627
 
}
628
 
//------------------------Armature.fakeUser (setter)
629
 
static int Armature_setFakeUser( BPy_Armature * self, PyObject * value )
630
 
{
631
 
        return SetIdFakeUser(&self->armature->id, value);
632
 
}
633
 
 
634
 
 
635
614
//------------------------Armature.mirrorEdit (getter)
636
615
static PyObject *Armature_getMirrorEdit(BPy_Armature *self, void *closure)
637
616
{
935
914
        return EXPP_intError(PyExc_AttributeError, "%s%s", 
936
915
                sArmatureBadArgs, "Expects True or False");
937
916
}
938
 
//------------------------Armature.name (getter)
939
 
//Gets the name of the armature
940
 
static PyObject *Armature_getName(BPy_Armature *self, void *closure)
941
 
{
942
 
    return PyString_FromString(self->armature->id.name +2); //*new*
943
 
}
944
 
//------------------------Armature.name (setter)
945
 
//Sets the name of the armature
946
 
static int Armature_setName(BPy_Armature *self, PyObject *value, void *closure)
947
 
{
948
 
        char *name;
949
 
 
950
 
        if(value){
951
 
                if(PyString_Check(value)){
952
 
                        name = PyString_AsString(value);
953
 
                        rename_id(&self->armature->id, name);
954
 
                        return 0; 
955
 
                }
956
 
        }
957
 
        goto AttributeError;
958
 
 
959
 
AttributeError:
960
 
        return EXPP_intError(PyExc_AttributeError, "%s%s", 
961
 
                sArmatureBadArgs, "Expects string");
962
 
}
 
917
 
963
918
//------------------------Armature.bones (getter)
964
919
//Gets the name of the armature
965
920
static PyObject *Armature_getBoneDict(BPy_Armature *self, void *closure)
991
946
                "() - Rebuilds the armature based on changes to bones since the last call to makeEditable"},
992
947
        {"__copy__", (PyCFunction) Armature_copy, METH_NOARGS, 
993
948
                "() - Return a copy of the armature."},
 
949
        {"copy", (PyCFunction) Armature_copy, METH_NOARGS, 
 
950
                "() - Return a copy of the armature."},
994
951
        {NULL, NULL, 0, NULL}
995
952
};
996
953
//------------------------tp_getset
997
954
//This contains methods for attributes that require checking
998
955
static PyGetSetDef BPy_Armature_getset[] = {
999
 
        {"name", (getter)Armature_getName, (setter)Armature_setName, 
1000
 
                "The armature's name", NULL},
 
956
        GENERIC_LIB_GETSETATTR,
1001
957
        {"bones", (getter)Armature_getBoneDict, (setter)Armature_setBoneDict, 
1002
958
                "The armature's Bone dictionary", NULL},
1003
959
        {"vertexGroups", (getter)Armature_getVertexGroups, (setter)Armature_setVertexGroups, 
1024
980
                "Adds temporal IK chains while grabbing bones", NULL},
1025
981
        {"layers", (getter)Armature_getLayers, (setter)Armature_setLayers, 
1026
982
                "List of layers for the armature", NULL},
1027
 
        {"users", (getter)Armature_getUsers, (setter)NULL, 
1028
 
                "The number of object users", NULL},
1029
 
        {"fakeUser", (getter)Armature_getFakeUser, (setter)Armature_setFakeUser, 
1030
 
                "The fake user status of this object", NULL},
1031
983
        {NULL, NULL, NULL, NULL, NULL}
1032
984
};
1033
985
//------------------------tp_new
1038
990
        BPy_Armature *py_armature = NULL;
1039
991
        bArmature *bl_armature;
1040
992
 
1041
 
        bl_armature = add_armature();
 
993
        bl_armature = add_armature("Armature");
1042
994
        if(bl_armature) {
1043
995
                bl_armature->id.us = 0; // return count to 0 - add_armature() inc'd it 
1044
996
 
1135
1087
        0,                                                              //tp_as_number
1136
1088
        0,                                                              //tp_as_sequence
1137
1089
        0,                                                              //tp_as_mapping
1138
 
        0,                                                              //tp_hash
 
1090
        ( hashfunc ) GenericLib_hash,   //tp_hash
1139
1091
        0,                                                              //tp_call
1140
1092
        0,                                                              //tp_str
1141
1093
        0,                                                              //tp_getattro
1225
1177
                if(size == 0){  //GET ALL ARMATURES
1226
1178
                        data = G.main->armature.first; //get the first data ID from the armature library
1227
1179
                        while (data){
1228
 
                                py_armature = PyArmature_FromArmature(data); //*new*
 
1180
                                py_armature = Armature_CreatePyObject(data); //*new*
1229
1181
                                sprintf(buffer, "%s", ((bArmature*)data)->id.name +2);
1230
1182
                                if(PyDict_SetItemString(dict, buffer, py_armature) == -1){ //add to dictionary
1231
1183
                                        EXPP_decr3(seq, dict, py_armature);
1242
1194
                                Py_DECREF(item);
1243
1195
                                data = find_id("AR", name); //get data from library
1244
1196
                                if (data != NULL){
1245
 
                                        py_armature = PyArmature_FromArmature(data); //*new*
 
1197
                                        py_armature = Armature_CreatePyObject(data); //*new*
1246
1198
                                        if(PyDict_SetItemString(dict, name, py_armature) == -1){ //add to dictionary
1247
1199
                                                EXPP_decr3(seq, dict, py_armature);
1248
1200
                                                goto RuntimeError;
1270
1222
                Py_DECREF(seq);
1271
1223
                data = find_id("AR", name); //get data from library
1272
1224
                if (data != NULL){
1273
 
                        return PyArmature_FromArmature(data); //*new*
 
1225
                        return Armature_CreatePyObject(data); //*new*
1274
1226
                }else{
1275
1227
                        char buffer[128];
1276
1228
                        PyOS_snprintf( buffer, sizeof(buffer),
1296
1248
        char *name = "Armature";
1297
1249
        struct bArmature *armature;
1298
1250
        BPy_Armature *obj;
1299
 
        char buf[21];
1300
1251
 
1301
1252
        if( !PyArg_ParseTuple( args, "|s", &name ) )
1302
1253
                return EXPP_ReturnPyObjError( PyExc_TypeError,
1303
1254
                                              "expected nothing or a string as argument" );
1304
1255
 
1305
 
        armature= add_armature();
 
1256
        armature= add_armature(name);
1306
1257
        armature->id.us = 0;
1307
 
        obj = (BPy_Armature *)PyArmature_FromArmature(armature); /*new*/
 
1258
        obj = (BPy_Armature *)Armature_CreatePyObject(armature); /*new*/
1308
1259
 
1309
1260
        if( !obj )
1310
1261
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1311
1262
                                       "PyObject_New() failed" );       
1312
1263
 
1313
 
        PyOS_snprintf( buf, sizeof( buf ), "%s", name );
1314
 
        rename_id( &armature->id, buf );
1315
 
 
1316
1264
        obj->armature = armature;
1317
1265
        return (PyObject *)obj;
1318
1266
}
1345
1293
}
1346
1294
//-----------------(internal)
1347
1295
//Converts a bArmature to a PyArmature
1348
 
PyObject *PyArmature_FromArmature(struct bArmature *armature)
 
1296
PyObject *Armature_CreatePyObject(struct bArmature *armature)
1349
1297
{
1350
1298
        BPy_Armature *py_armature = NULL;
1351
1299
        PyObject *maindict = NULL, *weakref = NULL;
1384
1332
 
1385
1333
RuntimeError:
1386
1334
        return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
1387
 
                sModuleError, "PyArmature_FromArmature: ", "Internal Error Ocurred");
 
1335
                sModuleError, "Armature_CreatePyObject: ", "Internal Error Ocurred");
1388
1336
}
1389
1337
//-----------------(internal)
1390
1338
//Converts a PyArmature to a bArmature
1393
1341
        return (py_armature->armature);
1394
1342
}
1395
1343
 
1396
 
// This function returns true when the given PyObject
1397
 
// is of the type Sound. Otherwise it will return false
1398
 
int Armature_CheckPyObject( PyObject * pyobj )
1399
 
{
1400
 
        return ( pyobj->ob_type == &Armature_Type);
1401
 
}
1402
 
 
1403
1344
struct bArmature *Armature_FromPyObject( PyObject * py_obj )
1404
1345
{
1405
1346
        return PyArmature_AsArmature((BPy_Armature*)py_obj);