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

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Object.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: Object.c,v 1.246 2007/02/14 17:40:31 khughes Exp $
 
2
 * $Id: Object.c,v 1.266 2007/05/05 07:23:28 campbellbarton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
44
44
#include "DNA_view3d_types.h"
45
45
#include "DNA_object_force.h"
46
46
#include "DNA_userdef_types.h"
47
 
#include "DNA_oops_types.h"
48
47
 
49
48
#include "BKE_action.h"
50
49
#include "BKE_anim.h" /* used for dupli-objects */
114
113
#include "Modifier.h"
115
114
#include "Constraint.h"
116
115
#include "gen_utils.h"
 
116
#include "gen_library.h"
117
117
#include "EXPP_interface.h"
118
118
#include "BIF_editkey.h"
119
119
#include "IDProp.h"
346
346
static PyObject *Object_getLocation( BPy_Object * self, PyObject * args );
347
347
static PyObject *Object_getMaterials( BPy_Object * self, PyObject * args );
348
348
static PyObject *Object_getMatrix( BPy_Object * self, PyObject * args );
349
 
static PyObject *Object_getName( BPy_Object * self );
350
349
static PyObject *Object_getParent( BPy_Object * self );
351
350
static PyObject *Object_getParentBoneName( BPy_Object * self );
352
351
static int Object_setParentBoneName( BPy_Object * self, PyObject * value );
381
380
static PyObject *Object_setConstraintInfluenceForBone( BPy_Object * self, PyObject * args );
382
381
static PyObject *Object_setLocation( BPy_Object * self, PyObject * args );
383
382
static PyObject *Object_setMaterials( BPy_Object * self, PyObject * args );
384
 
static PyObject *Object_SetName( BPy_Object * self, PyObject * args );
385
383
static PyObject *Object_setSize( BPy_Object * self, PyObject * args );
386
384
static PyObject *Object_setTimeOffset( BPy_Object * self, PyObject * args );
387
385
static PyObject *Object_makeTrack( BPy_Object * self, PyObject * args );
513
511
matrix is not updated for changes made by the script itself\n\
514
512
(like obj.LocX = 10) until a redraw happens, either called by the script or\n\
515
513
automatic when the script finishes."},
516
 
        {"getName", ( PyCFunction ) Object_getName, METH_NOARGS,
 
514
        {"getName", ( PyCFunction ) GenericLib_getName, METH_NOARGS,
517
515
         "Returns the name of the object"},
518
516
        {"getParent", ( PyCFunction ) Object_getParent, METH_NOARGS,
519
517
         "Returns the object's parent object"},
694
692
        {"setMaterials", ( PyCFunction ) Object_setMaterials, METH_VARARGS,
695
693
         "Sets materials. The argument must be a list of valid material\n\
696
694
objects."},
697
 
        {"setName", ( PyCFunction ) Object_SetName, METH_VARARGS,
 
695
        {"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
698
696
         "Sets the name of the object"},
699
697
        {"setSize", ( PyCFunction ) Object_setSize, METH_VARARGS,
700
698
         "Set the object's size. The first argument must be a vector\n\
758
756
         "([s1<,s2,s3...>]) - Delete specified scriptlinks from this object."},
759
757
        {"insertShapeKey", ( PyCFunction ) Object_insertShapeKey, METH_NOARGS,
760
758
         "() - Insert a Shape Key in the current object"},
761
 
        {"__copy__", ( PyCFunction ) Object_copy, METH_NOARGS,
762
 
         "() - Return a copy of this object."},
763
759
        {"getProperties", ( PyCFunction ) Object_GetProperties, METH_NOARGS,
764
760
         "() return a reference to the ID properties associated with this object."},
 
761
        {"__copy__", ( PyCFunction ) Object_copy, METH_NOARGS,
 
762
         "() - Return a copy of this object."},
 
763
        {"copy", ( PyCFunction ) Object_copy, METH_NOARGS,
 
764
         "() - Return a copy of this object."},
765
765
        {NULL, NULL, 0, NULL}
766
766
};
767
767
 
865
865
        PyArg_ParseTuple( args, "|s", &name );
866
866
 
867
867
        if( name != NULL ) {
868
 
                object = GetObjectByName( name );
 
868
                object = ( Object * ) GetIdFromList( &( G.main->object ), name );
869
869
 
870
870
                        /* No object exists with the name specified in the argument name. */
871
871
                if( !object ){
989
989
        static char *kwlist[] = {"mesh", "surface", "curve",
990
990
                        "text", "metaball", "armature", "lamp", "material", "texture", "ipo", NULL};
991
991
        
 
992
        /* duplicating in background causes segfaults */
 
993
        if( G.background == 1 )
 
994
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
995
                                        "cannot duplicate objects in background mode" );
 
996
        
 
997
        
992
998
        if (!PyArg_ParseTupleAndKeywords(args, kwd, "|iiiiiiiiii", kwlist,
993
999
                &mesh_dupe, &surface_dupe, &curve_dupe, &text_dupe, &metaball_dupe,
994
1000
                &armature_dupe, &lamp_dupe, &material_dupe, &texture_dupe, &ipo_dupe))
1099
1105
        switch ( object->type ) {
1100
1106
        case OB_ARMATURE:
1101
1107
                /* TODO: Do we need to add something to G? (see the OB_LAMP case) */
1102
 
                object->data = add_armature(  );
 
1108
                object->data = add_armature( "Armature" );
1103
1109
                break;
1104
1110
        case OB_CAMERA:
1105
1111
                /* TODO: Do we need to add something to G? (see the OB_LAMP case) */
1106
 
                object->data = add_camera(  );
 
1112
                object->data = add_camera( "Camera" );
1107
1113
                break;
1108
1114
        case OB_CURVE:
1109
 
                object->data = add_curve( OB_CURVE );
 
1115
                object->data = add_curve( "Curve", OB_CURVE );
1110
1116
                G.totcurve++;
1111
1117
                break;
1112
1118
        case OB_LAMP:
1113
 
                object->data = add_lamp(  );
 
1119
                object->data = add_lamp( "Lamp" );
1114
1120
                G.totlamp++;
1115
1121
                break;
1116
1122
        case OB_MESH:
1117
 
                object->data = add_mesh(  );
 
1123
                object->data = add_mesh( "Mesh" );
1118
1124
                G.totmesh++;
1119
1125
                break;
1120
1126
        case OB_LATTICE:
1121
 
                object->data = ( void * ) add_lattice(  );
 
1127
                object->data = ( void * ) add_lattice( "Lattice" );
1122
1128
                object->dt = OB_WIRE;
1123
1129
                break;
1124
1130
        case OB_MBALL:
1125
 
                object->data = add_mball(  );
 
1131
                object->data = add_mball( "Meta" );
1126
1132
                break;
1127
1133
 
1128
1134
                /* TODO the following types will be supported later,
1161
1167
        Py_RETURN_NONE;
1162
1168
}
1163
1169
 
 
1170
static int Object_setAction( BPy_Object * self, PyObject * value )
 
1171
{
 
1172
        return GenericLib_assignData(value, (void **) &self->object->action, 0, 1, ID_AC, 0);
 
1173
}
 
1174
 
1164
1175
static PyObject *Object_evaluatePose(BPy_Object *self, PyObject *args)
1165
1176
{
1166
1177
        int frame = 1;
1318
1329
                                               self->object->totcol, all );
1319
1330
}
1320
1331
 
1321
 
static PyObject *Object_getName( BPy_Object * self )
1322
 
{
1323
 
        return PyString_FromString( self->object->id.name + 2 );
1324
 
}
1325
 
 
1326
1332
static PyObject *Object_getParent( BPy_Object * self )
1327
1333
{
1328
 
        if( self->object->parent )
1329
 
                return Object_CreatePyObject( self->object->parent );
1330
 
        Py_RETURN_NONE;
 
1334
        return Object_CreatePyObject( self->object->parent );
1331
1335
}
1332
1336
 
1333
1337
static PyObject *Object_getParentBoneName( BPy_Object * self )
1403
1407
 
1404
1408
static PyObject *Object_getTracked( BPy_Object * self )
1405
1409
{
1406
 
        if( self->object->track )
1407
 
                return Object_CreatePyObject( self->object->track );
1408
 
        Py_RETURN_NONE;
 
1410
        return Object_CreatePyObject( self->object->track );
1409
1411
}
1410
1412
 
1411
1413
static PyObject *Object_getType( BPy_Object * self )
1586
1588
                return EXPP_ReturnPyObjError( PyExc_TypeError,
1587
1589
                                "expected an object as argument" );
1588
1590
 
1589
 
        if( ArmatureObject_Check( py_data ) )
 
1591
        if( BPy_Armature_Check( py_data ) )
1590
1592
                data = ( void * ) PyArmature_AsArmature((BPy_Armature*)py_data);
1591
 
        else if( Camera_CheckPyObject( py_data ) )
 
1593
        else if( BPy_Camera_Check( py_data ) )
1592
1594
                data = ( void * ) Camera_FromPyObject( py_data );
1593
 
        else if( Lamp_CheckPyObject( py_data ) )
 
1595
        else if( BPy_Lamp_Check( py_data ) )
1594
1596
                data = ( void * ) Lamp_FromPyObject( py_data );
1595
 
        else if( Curve_CheckPyObject( py_data ) )
 
1597
        else if( BPy_Curve_Check( py_data ) )
1596
1598
                data = ( void * ) Curve_FromPyObject( py_data );
1597
 
        else if( NMesh_CheckPyObject( py_data ) ) {
 
1599
        else if( BPy_NMesh_Check( py_data ) ) {
1598
1600
                data = ( void * ) NMesh_FromPyObject( py_data, self->object );
1599
1601
                if( !data )             /* NULL means there is already an error */
1600
1602
                        return NULL;
1601
 
        } else if( Mesh_CheckPyObject( py_data ) )
 
1603
        } else if( BPy_Mesh_Check( py_data ) )
1602
1604
                data = ( void * ) Mesh_FromPyObject( py_data, self->object );
1603
 
        else if( Lattice_CheckPyObject( py_data ) )
 
1605
        else if( BPy_Lattice_Check( py_data ) )
1604
1606
                data = ( void * ) Lattice_FromPyObject( py_data );
1605
 
        else if( Metaball_CheckPyObject( py_data ) )
 
1607
        else if( BPy_Metaball_Check( py_data ) )
1606
1608
                data = ( void * ) Metaball_FromPyObject( py_data );
1607
 
        else if( Text3d_CheckPyObject( py_data ) )
 
1609
        else if( BPy_Text3d_Check( py_data ) )
1608
1610
                data = ( void * ) Text3d_FromPyObject( py_data );
1609
1611
 
1610
1612
        /* have we set data to something good? */
1987
1989
        /* Check if the PyObject passed in list is a Blender object. */
1988
1990
        for( i = 0; i < list_length; i++ ) {
1989
1991
                py_child = PySequence_GetItem( list, i );
1990
 
                if( !Object_CheckPyObject( py_child ) ) {
 
1992
                if( !BPy_Object_Check( py_child ) ) {
1991
1993
                        /* Cleanup */
1992
1994
                        free_libblock( &G.main->scene, temp_scene );
1993
1995
                        Py_DECREF( py_child );
2083
2085
{
2084
2086
        Object *child = NULL;
2085
2087
 
2086
 
        if( Object_CheckPyObject( py_child ) )
 
2088
        if( BPy_Object_Check( py_child ) )
2087
2089
                child = ( Object * ) Object_FromPyObject( py_child );
2088
2090
 
2089
2091
        if( child == NULL )
2184
2186
                                "expected integer argument" );
2185
2187
 
2186
2188
        value = ( int )PyInt_AS_LONG( integer );
 
2189
        Py_DECREF( integer );
2187
2190
        if( value & ~DTX_MASK )
2188
2191
                return EXPP_ReturnIntError( PyExc_ValueError,
2189
2192
                                "undefined bit(s) set in bitfield" );
2213
2216
        float rot1, rot2, rot3;
2214
2217
        int status = 0;         /* failure */
2215
2218
 
 
2219
        if( PyTuple_Check( args ) && PyTuple_Size( args ) == 1 )
 
2220
                args = PyTuple_GET_ITEM( args, 0 );
 
2221
 
2216
2222
        if( EulerObject_Check( args ) ) {
2217
2223
                rot1 = ( ( EulerObject * ) args )->eul[0];
2218
2224
                rot2 = ( ( EulerObject * ) args )->eul[1];
2499
2505
        
2500
2506
        icu = verify_ipocurve((ID *)self->object, ID_CO, boneName, constName,
2501
2507
                        CO_ENFORCE);
 
2508
        
 
2509
        if (!icu)
 
2510
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
2511
                                "cannot get a curve from this IPO, may be using libdata" );             
 
2512
        
2502
2513
        insert_vert_ipo(icu, (float)CFRA, influence);
2503
2514
        self->object->recalc |= OB_RECALC_OB;  
2504
2515
 
2614
2625
        Py_RETURN_NONE;
2615
2626
}
2616
2627
 
2617
 
static int Object_setName( BPy_Object * self, PyObject * args )
2618
 
{
2619
 
        char *name;
2620
 
 
2621
 
        name = PyString_AsString ( args );
2622
 
        if( !name )
2623
 
                return EXPP_ReturnIntError( PyExc_TypeError,
2624
 
                                "expected a string argument" );
2625
 
        
2626
 
        rename_id( &self->object->id, name );
2627
 
 
2628
 
        return 0;
2629
 
}
2630
 
 
2631
2628
static PyObject *Object_setSize( BPy_Object * self, PyObject * args )
2632
2629
{
2633
2630
        float sizex;
2855
2852
        /* we accept either a property stringname or actual object */
2856
2853
        if( PyTuple_Size( args ) == 1 ) {
2857
2854
                PyObject *prop = PyTuple_GET_ITEM( args, 0 );
2858
 
                if( Property_CheckPyObject( prop ) )
 
2855
                if( BPy_Property_Check( prop ) )
2859
2856
                        py_prop = (BPy_Property *)prop;
2860
2857
                else
2861
2858
                        prop_name = PyString_AsString( prop );
3002
2999
        Py_RETURN_NONE;
3003
3000
}
3004
3001
 
3005
 
static int Object_setDupliGroup( BPy_Object * self, BPy_Group * args )
 
3002
static int Object_setDupliGroup( BPy_Object * self, PyObject * value )
3006
3003
{
3007
 
        Object *ob= self->object;
3008
 
 
3009
 
        if( (PyObject *)args == Py_None ) {
3010
 
                if (ob->dup_group)
3011
 
                        ob->dup_group->id.us--;
3012
 
                
3013
 
                ob->dup_group = NULL;
3014
 
        } else if( BPy_Group_Check( args ) ) {
3015
 
                if (ob->dup_group)
3016
 
                        ob->dup_group->id.us--;
3017
 
                
3018
 
                ob->dup_group = args->group;
3019
 
                id_us_plus(&ob->dup_group->id);
3020
 
        } else {
3021
 
                return EXPP_ReturnIntError( PyExc_TypeError,
3022
 
                                "expected a group or None" );
3023
 
        }
3024
 
        return 0;
 
3004
        return GenericLib_assignData(value, (void **) &self->object->dup_group, 0, 1, ID_GR, 0);
3025
3005
}
3026
3006
 
3027
3007
static PyObject *Object_getEffects( BPy_Object * self )
3115
3095
{
3116
3096
        BPy_Object *blen_object;
3117
3097
 
3118
 
        if( !obj ) {
3119
 
                Py_RETURN_NONE;
3120
 
        }
3121
 
 
 
3098
        if( !obj ) Py_RETURN_NONE;
 
3099
        
3122
3100
        blen_object =
3123
3101
                ( BPy_Object * ) PyObject_NEW( BPy_Object, &Object_Type );
3124
3102
 
3132
3110
}
3133
3111
 
3134
3112
/*****************************************************************************/
3135
 
/* Function:    Object_CheckPyObject                                     */
3136
 
/* Description: This function returns true when the given PyObject is of the */
3137
 
/*              type Object. Otherwise it will return false.             */
3138
 
/*****************************************************************************/
3139
 
int Object_CheckPyObject( PyObject * py_obj )
3140
 
{
3141
 
        return ( py_obj->ob_type == &Object_Type );
3142
 
}
3143
 
 
3144
 
/*****************************************************************************/
3145
3113
/* Function:    Object_FromPyObject                                      */
3146
3114
/* Description: This function returns the Blender object from the given  */
3147
3115
/*              PyObject.                                                */
3155
3123
}
3156
3124
 
3157
3125
/*****************************************************************************/
3158
 
/* Description: Returns the object with the name specified by the argument  */
3159
 
/*              name. Note that the calling function has to remove the first */
3160
 
/*              two characters of the object name. These two characters    */
3161
 
/*              specify the type of the object (OB, ME, WO, ...)         */
3162
 
/*              The function will return NULL when no object with the given  */
3163
 
/*              name is found.                                           */
3164
 
/*****************************************************************************/
3165
 
Object *GetObjectByName( char *name )
3166
 
{
3167
 
        Object *obj_iter;
3168
 
 
3169
 
        obj_iter = G.main->object.first;
3170
 
        while( obj_iter ) {
3171
 
                if( StringEqual( name, GetIdName( &( obj_iter->id ) ) ) ) {
3172
 
                        return ( obj_iter );
3173
 
                }
3174
 
                obj_iter = obj_iter->id.next;
3175
 
        }
3176
 
 
3177
 
        /* There is no object with the given name */
3178
 
        return ( NULL );
3179
 
}
3180
 
 
3181
 
/*****************************************************************************/
3182
3126
/* Function:    Object_dealloc                                               */
3183
3127
/* Description: This is a callback function for the BlenObject type. It is   */
3184
3128
/*      the destructor function.                                             */
3330
3274
        if( !flt )
3331
3275
                return EXPP_ReturnIntError( PyExc_TypeError,
3332
3276
                                "expected float argument" );
3333
 
        value = PyFloat_AS_DOUBLE( flt );
 
3277
        value = (float)PyFloat_AS_DOUBLE( flt );
3334
3278
        Py_DECREF( flt );
3335
3279
 
3336
3280
        if( value < 0.0f )
3365
3309
                                "expected integer argument" );
3366
3310
 
3367
3311
        value = ( int )PyInt_AS_LONG( integer );
 
3312
        Py_DECREF( integer );
3368
3313
        if( value & ~GAMEFLAG_MASK )
3369
3314
                return EXPP_ReturnIntError( PyExc_ValueError,
3370
3315
                                "undefined bit(s) set in bitfield" );
4030
3975
                return EXPP_ReturnIntError( PyExc_TypeError,
4031
3976
                                        "expected float argument" );
4032
3977
 
4033
 
        param = PyFloat_AsDouble( value );
 
3978
        param = (float)PyFloat_AsDouble( value );
4034
3979
 
4035
3980
        switch( (int)type ) {
4036
3981
        case EXPP_OBJ_ATTR_LOC_X: 
4352
4297
 
4353
4298
static int Object_setIpo( BPy_Object * self, PyObject * value )
4354
4299
{
4355
 
        Ipo *ipo = NULL;
4356
 
        Ipo *oldipo = self->object->ipo;
4357
 
        ID *id;
4358
 
 
4359
 
        /* if parameter is not None, check for valid Ipo */
4360
 
 
4361
 
        if ( value != Py_None ) {
4362
 
                if ( !Ipo_CheckPyObject( value ) )
4363
 
                        return EXPP_ReturnIntError( PyExc_TypeError,
4364
 
                                        "expected an Ipo object" );
4365
 
 
4366
 
                ipo = Ipo_FromPyObject( value );
4367
 
 
4368
 
                if( !ipo )
4369
 
                        return EXPP_ReturnIntError( PyExc_RuntimeError,
4370
 
                                        "null ipo!" );
4371
 
 
4372
 
                if( ipo->blocktype != ID_OB )
4373
 
                        return EXPP_ReturnIntError( PyExc_TypeError,
4374
 
                                        "Ipo is not a object data Ipo" );
4375
 
        }
4376
 
 
4377
 
        /* if already linked to Ipo, delete link */
4378
 
 
4379
 
        if ( oldipo ) {
4380
 
                id = &oldipo->id;
4381
 
                if( id->us > 0 )
4382
 
                        id->us--;
4383
 
        }
4384
 
 
4385
 
        /* assign new Ipo and increment user count, or set to NULL if deleting */
4386
 
 
4387
 
        self->object->ipo = ipo;
4388
 
        if ( ipo )
4389
 
                id_us_plus(&ipo->id);
4390
 
 
4391
 
        return 0;
4392
 
}
4393
 
 
4394
 
static PyObject *Object_getOopsLoc( BPy_Object * self )
4395
 
{
4396
 
        if( G.soops ) { 
4397
 
                Oops *oops = G.soops->oops.first;
4398
 
                while( oops ) {
4399
 
                        if( oops->type == ID_OB && (Object *)oops->id == self->object )
4400
 
                                return Py_BuildValue( "ff", oops->x, oops->y );
4401
 
                        oops = oops->next;
4402
 
                }
4403
 
        }
4404
 
        Py_RETURN_NONE;
4405
 
}
4406
 
 
4407
 
static PyObject *Object_getOopsSel ( BPy_Object * self )
4408
 
{
4409
 
        if( G.soops ) {
4410
 
                Oops *oops= G.soops->oops.first;
4411
 
                while( oops ) {
4412
 
                        if( oops->type == ID_OB
4413
 
                                                && (Object *)oops->id == self->object ) {
4414
 
                                if( oops->flag & SELECT )
4415
 
                                        Py_RETURN_TRUE;
4416
 
                                else
4417
 
                                        Py_RETURN_FALSE;
4418
 
                        }
4419
 
                        oops = oops->next;
4420
 
                }
4421
 
        }
4422
 
        Py_RETURN_NONE;
4423
 
}
4424
 
 
4425
 
static int Object_setOopsLoc( BPy_Object * self, PyObject * value )
4426
 
{
4427
 
        if( G.soops ) {
4428
 
                Oops *oops= G.soops->oops.first;
4429
 
                while( oops ) {
4430
 
                        if( oops->type == ID_OB && (Object *)oops->id == self->object ) {
4431
 
                                if( !PyArg_ParseTuple( value, "ff", &oops->x, &oops->y ) )
4432
 
                                        return EXPP_ReturnIntError( PyExc_TypeError,
4433
 
                                                        "expected two floats as arguments" );
4434
 
                                return 0;
4435
 
                        }
4436
 
                        oops = oops->next;
4437
 
                }
4438
 
                return EXPP_ReturnIntError( PyExc_RuntimeError,
4439
 
                                "couldn't find oopsLoc data for object" );
4440
 
        }
4441
 
        return 0;
4442
 
}
4443
 
 
4444
 
static int Object_setOopsSel( BPy_Object * self, PyObject * value )
4445
 
{
4446
 
        int setting = PyObject_IsTrue( value );
4447
 
 
4448
 
        if( setting == -1 )
4449
 
                return EXPP_ReturnIntError( PyExc_TypeError,
4450
 
                                "expected true/false argument" );
4451
 
 
4452
 
        if( G.soops ) {
4453
 
                Oops *oops = G.soops->oops.first;
4454
 
                while( oops ) {
4455
 
                        if( oops->type==ID_OB ) {
4456
 
                                if( (Object *)oops->id == self->object ) {
4457
 
#if 0
4458
 
        /* this code is what other modules do; it doesn't seem to work */
4459
 
                                        if( !setting )
4460
 
                                                oops->flag &= ~SELECT;
4461
 
                                        else
4462
 
                                                oops->flag |= SELECT;
4463
 
#else
4464
 
        printf ("warning: Object.oopsSel setter may not be coded correctly\n");
4465
 
        /* this code seems to work, but may not be the correct thing to do */
4466
 
                                        if( !setting )
4467
 
                                                self->object->flag &= ~SELECT;
4468
 
                                        else
4469
 
                                                self->object->flag |= SELECT;
4470
 
#endif
4471
 
                                        return 0;
4472
 
                                }
4473
 
                        }
4474
 
                        oops= oops->next;
4475
 
                }
4476
 
        }
4477
 
        return 0;
 
4300
        return GenericLib_assignData(value, (void **) &self->object->ipo, 0, 1, ID_IP, ID_OB);
4478
4301
}
4479
4302
 
4480
4303
static int Object_setTracked( BPy_Object * self, PyObject * value )
4481
4304
{
4482
 
        Object *ob = self->object;
4483
 
 
4484
 
        if( value != Py_None && !BPy_Object_Check( value ) )
4485
 
                return EXPP_ReturnIntError( PyExc_TypeError,
4486
 
                                "expected an object argument" );
4487
 
 
4488
 
        if( value != Py_None )
4489
 
                ob->track = ((BPy_Object *)value)->object;
4490
 
        else
4491
 
                ob->track = ((BPy_Object *)value)->object;
4492
 
        self->object->recalc |= OB_RECALC_OB;  
4493
 
        DAG_scene_sort( G.scene );
4494
 
 
4495
 
        return 0;
4496
 
}
4497
 
 
4498
 
static PyObject *Object_getUsers( BPy_Object * self )
4499
 
{
4500
 
        return PyInt_FromLong( self->object->id.us );
4501
 
}
4502
 
 
4503
 
static PyObject *Object_getFakeUser( BPy_Object * self )
4504
 
{
4505
 
        if (self->object->id.flag & LIB_FAKEUSER)
4506
 
                Py_RETURN_TRUE;
4507
 
        else
4508
 
                Py_RETURN_FALSE;
4509
 
}
4510
 
 
4511
 
static int Object_setFakeUser( BPy_Object * self, PyObject * value )
4512
 
{
4513
 
        return SetIdFakeUser(&self->object->id, value);
 
4305
        int ret;
 
4306
        ret = GenericLib_assignData(value, (void **) &self->object->track, 0, 0, ID_OB, 0);
 
4307
        if (ret==0) {
 
4308
                self->object->recalc |= OB_RECALC_OB;  
 
4309
                DAG_scene_sort( G.scene );
 
4310
        }
 
4311
        return ret;
4514
4312
}
4515
4313
 
4516
4314
/* Localspace matrix */
4582
4380
 
4583
4381
        switch ( object->type ) {
4584
4382
        case OB_ARMATURE:
4585
 
                data_object = PyArmature_FromArmature( object->data );
 
4383
                data_object = Armature_CreatePyObject( object->data );
4586
4384
                break;
4587
4385
        case OB_CAMERA:
4588
4386
                data_object = Camera_CreatePyObject( object->data );
4619
4417
                break;
4620
4418
        case ID_SCE:
4621
4419
                break;
4622
 
        case ID_TXT:
4623
 
                data_object = Text_CreatePyObject( object->data );
4624
 
                break;
4625
4420
        case OB_FONT:
4626
4421
                data_object = Text3d_CreatePyObject( object->data );
4627
4422
                break;          
4700
4495
                                "expected integer argument" );
4701
4496
 
4702
4497
        value = ( short )PyInt_AS_LONG( integer );
 
4498
        Py_DECREF( integer );
4703
4499
        if( value & ~PROTFLAGS_MASK )
4704
4500
                return EXPP_ReturnIntError( PyExc_ValueError,
4705
4501
                                "undefined bit(s) set in bitfield" );
4722
4518
    if( !flt )
4723
4519
        return EXPP_ReturnIntError( PyExc_TypeError,
4724
4520
                "expected float argument" );
4725
 
    value = PyFloat_AS_DOUBLE( flt );
 
4521
    value = (float)PyFloat_AS_DOUBLE( flt );
4726
4522
        Py_DECREF( flt );
4727
4523
 
4728
4524
    if( value < 0.0f )
4744
4540
}
4745
4541
 
4746
4542
static PyGetSetDef BPy_Object_getseters[] = {
 
4543
        GENERIC_LIB_GETSETATTR,
4747
4544
        {"LocX",
4748
4545
         (getter)getFloatAttr, (setter)setFloatAttr,
4749
4546
         "The X location coordinate of the object",
4917
4714
         (getter)Object_getMatrixOldWorld, (setter)NULL,
4918
4715
         "old-type worldspace matrix (prior to Blender 2.34)",
4919
4716
         NULL},
4920
 
        {"name",
4921
 
         (getter)Object_getName, (setter)Object_setName,
4922
 
         "Object data name",
4923
 
         NULL},
4924
 
        {"oopsLoc",
4925
 
         (getter)Object_getOopsLoc, (setter)Object_setOopsLoc,
4926
 
         "Object OOPs location",
4927
 
         NULL},
4928
 
        {"oopsSel",
4929
 
         (getter)Object_getOopsSel, (setter)Object_setOopsSel,
4930
 
         "Object OOPs selection flag",
4931
 
         NULL},
4932
4717
        {"data",
4933
4718
         (getter)get_obj_data, (setter)NULL,
4934
4719
         "The Datablock object linked to this object",
4962
4747
         "The bounding box of this object",
4963
4748
         NULL},
4964
4749
        {"action",
4965
 
         (getter)Object_getAction, (setter)NULL,
 
4750
         (getter)Object_getAction, (setter)Object_setAction,
4966
4751
         "The action associated with this object (if defined)",
4967
4752
         NULL},
4968
4753
        {"game_properties",
4969
4754
         (getter)Object_getAllProperties, (setter)NULL,
4970
4755
         "The object's properties",
4971
4756
         NULL},
4972
 
        {"users",
4973
 
         (getter)Object_getUsers, (setter)NULL,
4974
 
         "The number of object users",
4975
 
         NULL},
4976
 
        {"fakeUser",
4977
 
         (getter)Object_getFakeUser, (setter)Object_setFakeUser,
4978
 
         "The fake user status of this object",
4979
 
         NULL},
4980
4757
         
4981
4758
        {"piFalloff",
4982
4759
         (getter)getFloatAttr, (setter)setFloatAttrClamp,
5256
5033
 
5257
5034
        /* More standard operations (here for binary compatibility) */
5258
5035
 
5259
 
        NULL,                       /* hashfunc tp_hash; */
 
5036
        ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
5260
5037
        NULL,                       /* ternaryfunc tp_call; */
5261
5038
        NULL,                       /* reprfunc tp_str; */
5262
5039
        NULL,                       /* getattrofunc tp_getattro; */
5351
5128
                BPy_constant *d = ( BPy_constant * ) M;
5352
5129
                PyConstant_Insert( d, "OBJECT", PyInt_FromLong( PAROBJECT ) );
5353
5130
                PyConstant_Insert( d, "CURVE", PyInt_FromLong( PARCURVE ) );
5354
 
                PyConstant_Insert( d, "LATTICE", PyInt_FromLong( PARKEY ) );
 
5131
                
 
5132
                /*      2.43 was released as LATTICE as PARKEY, my bad,
 
5133
                        lattice uses PARSKEL also - Campbell */
 
5134
                PyConstant_Insert( d, "LATTICE", PyInt_FromLong( PARSKEL ) ); 
 
5135
                
5355
5136
                PyConstant_Insert( d, "ARMATURE", PyInt_FromLong( PARSKEL ) );
5356
5137
                PyConstant_Insert( d, "VERT1", PyInt_FromLong( PARVERT1 ) );
5357
5138
                PyConstant_Insert( d, "VERT3", PyInt_FromLong( PARVERT3 ) );
5439
5220
        return M;
5440
5221
}
5441
5222
 
 
5223
static PyObject *M_Object_IpoKeyTypesDict( void )
 
5224
{
 
5225
        PyObject *M = PyConstant_New(  );
 
5226
 
 
5227
        if( M ) {
 
5228
                BPy_constant *d = ( BPy_constant * ) M;
 
5229
                PyConstant_Insert( d, "LOC", PyInt_FromLong( IPOKEY_LOC ) );
 
5230
                PyConstant_Insert( d, "ROT", PyInt_FromLong( IPOKEY_ROT ) );
 
5231
                PyConstant_Insert( d, "SIZE", PyInt_FromLong( IPOKEY_SIZE ) );
 
5232
                PyConstant_Insert( d, "LOCROT", PyInt_FromLong( IPOKEY_LOCROT ) );
 
5233
                PyConstant_Insert( d, "LOCROTSIZE", PyInt_FromLong( IPOKEY_LOCROTSIZE ) );
 
5234
                
 
5235
                PyConstant_Insert( d, "PI_STRENGTH", PyInt_FromLong( IPOKEY_PI_STRENGTH ) );
 
5236
                PyConstant_Insert( d, "PI_FALLOFF", PyInt_FromLong( IPOKEY_PI_FALLOFF ) );
 
5237
                PyConstant_Insert( d, "PI_SURFACEDAMP", PyInt_FromLong( IPOKEY_PI_SURFACEDAMP ) );
 
5238
                PyConstant_Insert( d, "PI_RANDOMDAMP", PyInt_FromLong( IPOKEY_PI_RANDOMDAMP ) );
 
5239
                PyConstant_Insert( d, "PI_PERM", PyInt_FromLong( IPOKEY_PI_PERM ) );
 
5240
        }
 
5241
        return M;
 
5242
}
 
5243
 
5442
5244
/*****************************************************************************/
5443
5245
/* Function:     initObject                                             */
5444
5246
/*****************************************************************************/
5452
5254
        PyObject *PITypesDict = M_Object_PITypesDict( );
5453
5255
        PyObject *RBFlagsDict = M_Object_RBFlagsDict( );
5454
5256
        PyObject *RBShapesDict = M_Object_RBShapeBoundDict( );
 
5257
        PyObject *IpoKeyTypesDict = M_Object_IpoKeyTypesDict( );
5455
5258
 
5456
5259
        PyType_Ready( &Object_Type ) ;
5457
5260
 
5458
5261
        module = Py_InitModule3( "Blender.Object", M_Object_methods,
5459
5262
                                 M_Object_doc );
5460
 
 
 
5263
        
 
5264
        
 
5265
        /* We Should Remove these!!!! */
5461
5266
        PyModule_AddIntConstant( module, "LOC", IPOKEY_LOC );
5462
5267
        PyModule_AddIntConstant( module, "ROT", IPOKEY_ROT );
5463
5268
        PyModule_AddIntConstant( module, "SIZE", IPOKEY_SIZE );
5475
5280
        PyModule_AddIntConstant( module, "VORTEX",PFIELD_VORTEX );
5476
5281
        PyModule_AddIntConstant( module, "MAGNET",PFIELD_MAGNET );
5477
5282
        PyModule_AddIntConstant( module, "WIND",PFIELD_WIND );
5478
 
 
 
5283
        /* Only keeping above so as not to break compat */
 
5284
        
 
5285
        
5479
5286
        if( DrawModesDict )
5480
5287
                PyModule_AddObject( module, "DrawModes", DrawModesDict );
5481
5288
        if( DrawTypesDict )
5490
5297
                PyModule_AddObject( module, "RBFlags", RBFlagsDict );
5491
5298
        if( RBShapesDict )
5492
5299
                PyModule_AddObject( module, "RBShapes", RBShapesDict );
5493
 
        
 
5300
        if( IpoKeyTypesDict )
 
5301
                PyModule_AddObject( module, "IpoKeyTypes", IpoKeyTypesDict );   
5494
5302
 
5495
5303
                /*Add SUBMODULES to the module*/
5496
5304
        dict = PyModule_GetDict( module ); /*borrowed*/
5524
5332
                        (setter)Object_setDrawType );
5525
5333
}
5526
5334
 
5527
 
static PyObject *Object_SetName( BPy_Object * self, PyObject * args )
5528
 
{
5529
 
        return EXPP_setterWrapper( (void *)self, args,
5530
 
                        (setter)Object_setName );
5531
 
}
5532
 
 
5533
5335
static PyObject *Object_SetMatrix( BPy_Object * self, PyObject * args )
5534
5336
{
5535
5337
        return EXPP_setterWrapper( (void *)self, args,
5538
5340
 
5539
5341
static PyObject *Object_SetEuler( BPy_Object * self, PyObject * args )
5540
5342
{
5541
 
        return EXPP_setterWrapper( (void *)self, args,
 
5343
        return EXPP_setterWrapperTuple( (void *)self, args,
5542
5344
                        (setter)Object_setEuler );
5543
5345
}
5544
5346