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

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Lamp.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: Lamp.c,v 1.47 2006/12/27 05:04:17 campbellbarton Exp $
 
2
 * $Id: Lamp.c,v 1.56 2007/03/26 02:10:21 campbellbarton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
44
44
#include "Ipo.h"
45
45
#include "constant.h"
46
46
#include "gen_utils.h"
 
47
#include "gen_library.h"
47
48
 
48
49
/*****************************************************************************/
49
50
/* Python BPy_Lamp defaults:                                                 */
178
179
/*****************************************************************************/
179
180
/* Python BPy_Lamp methods declarations:                                     */
180
181
/*****************************************************************************/
181
 
static PyObject *Lamp_getName( BPy_Lamp * self );
182
182
static PyObject *Lamp_getType( BPy_Lamp * self );
183
183
static PyObject *Lamp_getTypesConst( void );
184
184
static PyObject *Lamp_getMode( BPy_Lamp * self );
204
204
static PyObject *Lamp_getCol( BPy_Lamp * self );
205
205
static PyObject *Lamp_getIpo( BPy_Lamp * self );
206
206
static PyObject *Lamp_getComponent( BPy_Lamp * self, void * closure );
207
 
static PyObject *Lamp_getUsers( BPy_Lamp * self );
208
207
static PyObject *Lamp_clearIpo( BPy_Lamp * self );
209
208
static PyObject *Lamp_insertIpoKey( BPy_Lamp * self, PyObject * args );
210
209
static PyObject *Lamp_oldsetIpo( BPy_Lamp * self, PyObject * args );
211
 
static PyObject *Lamp_oldsetName( BPy_Lamp * self, PyObject * args );
212
210
static PyObject *Lamp_oldsetType( BPy_Lamp * self, PyObject * args );
213
211
static PyObject *Lamp_oldsetMode( BPy_Lamp * self, PyObject * args );
214
212
static PyObject *Lamp_oldsetSamples( BPy_Lamp * self, PyObject * args );
230
228
static PyObject *Lamp_oldsetQuad1( BPy_Lamp * self, PyObject * args );
231
229
static PyObject *Lamp_oldsetQuad2( BPy_Lamp * self, PyObject * args );
232
230
static PyObject *Lamp_oldsetCol( BPy_Lamp * self, PyObject * args );
 
231
static PyObject *Lamp_copy( BPy_Lamp * self );
233
232
static int Lamp_setIpo( BPy_Lamp * self, PyObject * args );
234
 
static int Lamp_setName( BPy_Lamp * self, PyObject * args );
235
233
static int Lamp_setType( BPy_Lamp * self, PyObject * args );
236
234
static int Lamp_setMode( BPy_Lamp * self, PyObject * args );
237
235
static int Lamp_setSamples( BPy_Lamp * self, PyObject * args );
263
261
/*****************************************************************************/
264
262
static PyMethodDef BPy_Lamp_methods[] = {
265
263
        /* name, method, flags, doc */
266
 
        {"getName", ( PyCFunction ) Lamp_getName, METH_NOARGS,
267
 
         "() - return Lamp name"},
 
264
        
268
265
        {"getType", ( PyCFunction ) Lamp_getType, METH_NOARGS,
269
266
         "() - return Lamp type - 'Lamp':0, 'Sun':1, 'Spot':2, 'Hemi':3, 'Area':4, 'Photon':5"},
270
267
        {"getMode", ( PyCFunction ) Lamp_getMode, METH_NOARGS,
307
304
         "() - return light intensity value #2 for a Quad Lamp"},
308
305
        {"getCol", ( PyCFunction ) Lamp_getCol, METH_NOARGS,
309
306
         "() - return light rgb color triplet"},
310
 
        {"setName", ( PyCFunction ) Lamp_oldsetName, METH_VARARGS,
 
307
        {"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
311
308
         "(str) - rename Lamp"},
312
309
        {"setType", ( PyCFunction ) Lamp_oldsetType, METH_VARARGS,
313
310
         "(str) - change Lamp type, which can be 'Lamp', 'Sun', 'Spot', 'Hemi', 'Area', 'Photon'"},
371
368
         "( lamp-ipo ) - link an IPO to this lamp"},
372
369
         {"insertIpoKey", ( PyCFunction ) Lamp_insertIpoKey, METH_VARARGS,
373
370
         "( Lamp IPO type ) - Inserts a key into IPO"},
374
 
 
 
371
        {"__copy__", ( PyCFunction ) Lamp_copy, METH_NOARGS,
 
372
         "() - Makes a copy of this lamp."},
 
373
        {"copy", ( PyCFunction ) Lamp_copy, METH_NOARGS,
 
374
         "() - Makes a copy of this lamp."},
375
375
        {NULL, NULL, 0, NULL}
376
376
};
377
377
 
379
379
/* Python attributes get/set structure:                                      */
380
380
/*****************************************************************************/
381
381
static PyGetSetDef BPy_Lamp_getseters[] = {
 
382
        GENERIC_LIB_GETSETATTR,
382
383
        {"bias",
383
384
         (getter)Lamp_getBias, (setter)Lamp_setBias,
384
385
         "Lamp shadow map sampling bias",
423
424
         (getter)Lamp_getMode, (setter)Lamp_setMode,
424
425
         "Lamp mode bitmask",
425
426
         NULL},
426
 
        {"name",
427
 
         (getter)Lamp_getName, (setter)Lamp_setName,
428
 
         "Lamp data name",
429
 
         NULL},
430
427
        {"quad1",
431
428
         (getter)Lamp_getQuad1, (setter)Lamp_setQuad1,
432
429
         "Quad lamp linear distance attenuation",
495
492
         (getter)Lamp_getComponent, (setter)Lamp_setComponent,
496
493
         "Lamp color blue component",
497
494
         (void *)EXPP_LAMP_COMP_B},
498
 
        {"users",
499
 
         (getter)Lamp_getUsers, (setter)NULL,
500
 
         "Number of lamp users",
501
 
         NULL},
502
495
        {"Modes",
503
496
         (getter)Lamp_getModesConst, (setter)NULL,
504
497
         "Dictionary of values for 'mode' attribute",
545
538
 
546
539
        /* More standard operations (here for binary compatibility) */
547
540
 
548
 
        NULL,                       /* hashfunc tp_hash; */
 
541
        ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
549
542
        NULL,                       /* ternaryfunc tp_call; */
550
543
        NULL,                       /* reprfunc tp_str; */
551
544
        NULL,                       /* getattrofunc tp_getattro; */
610
603
                             PyObject * keywords )
611
604
{
612
605
        char *type_str = "Lamp";
613
 
        char *name_str = "LampData";
 
606
        char *name_str = "Lamp";
614
607
        static char *kwlist[] = { "type_str", "name_str", NULL };
615
608
        BPy_Lamp *py_lamp;      /* for Lamp Data object wrapper in Python */
616
609
        Lamp *bl_lamp;          /* for actual Lamp Data we create in Blender */
617
 
        char buf[21];
618
610
 
619
611
        if( !PyArg_ParseTupleAndKeywords( args, keywords, "|ss", kwlist,
620
612
                                          &type_str, &name_str ) )
621
613
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
622
614
                                                "expected string(s) or empty argument" ) );
623
 
 
624
 
        bl_lamp = add_lamp(  ); /* first create in Blender */
 
615
        
 
616
        bl_lamp = add_lamp( name_str ); /* first create in Blender */
 
617
        
625
618
        if( bl_lamp )           /* now create the wrapper obj in Python */
626
619
                py_lamp = ( BPy_Lamp * ) Lamp_CreatePyObject( bl_lamp );
627
620
        else
651
644
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
652
645
                                                "unknown lamp type" ) );
653
646
 
654
 
        if( strcmp( name_str, "LampData" ) == 0 )
655
 
                return ( PyObject * ) py_lamp;
656
 
        else                    /* user gave us a name for the lamp, use it */
657
 
                rename_id( &bl_lamp->id, name_str );
658
 
 
659
647
        return ( PyObject * ) py_lamp;
660
648
}
661
649
 
845
833
        rgb[2] = &lamp->b;
846
834
 
847
835
        pylamp->color = ( BPy_rgbTuple * ) rgbTuple_New( rgb );
848
 
 
 
836
        Py_INCREF(pylamp->color);
 
837
        
849
838
        return ( PyObject * ) pylamp;
850
839
}
851
840
 
852
841
/*****************************************************************************/
853
 
/* Function:    Lamp_CheckPyObject                                           */
854
 
/* Description: This function returns true when the given PyObject is of the */
855
 
/*              type Lamp. Otherwise it will return false.                   */
856
 
/*****************************************************************************/
857
 
int Lamp_CheckPyObject( PyObject * pyobj )
858
 
{
859
 
        return ( pyobj->ob_type == &Lamp_Type );
860
 
}
861
 
 
862
 
/*****************************************************************************/
863
842
/* Function:    Lamp_FromPyObject                                            */
864
843
/* Description: This function returns the Blender lamp from the given        */
865
844
/*              PyObject.                                                    */
870
849
}
871
850
 
872
851
/*****************************************************************************/
873
 
/* Description: Returns the lamp with the name specified by the argument     */
874
 
/*              name. Note that the calling function has to remove the first */
875
 
/*              two characters of the lamp name. These two characters        */
876
 
/*              specify the type of the object (OB, ME, WO, ...)             */
877
 
/*              The function will return NULL when no lamp with the given    */
878
 
/*              name is found.                                               */
879
 
/*****************************************************************************/
880
 
Lamp *GetLampByName( char *name )
881
 
{
882
 
        Lamp *lamp_iter;
883
 
 
884
 
        lamp_iter = G.main->lamp.first;
885
 
        while( lamp_iter ) {
886
 
                if( StringEqual( name, GetIdName( &( lamp_iter->id ) ) ) ) {
887
 
                        return lamp_iter;
888
 
                }
889
 
                lamp_iter = lamp_iter->id.next;
890
 
        }
891
 
 
892
 
        /* There is no lamp with the given name */
893
 
        return NULL;
894
 
}
895
 
 
896
 
/*****************************************************************************/
897
852
/* Python BPy_Lamp methods:                                                  */
898
853
/*****************************************************************************/
899
 
static PyObject *Lamp_getName( BPy_Lamp * self )
 
854
 
 
855
/* Lamp.__copy__ */
 
856
static PyObject *Lamp_copy( BPy_Lamp * self )
900
857
{
901
 
        PyObject *attr = PyString_FromString( self->lamp->id.name + 2 );
902
 
 
903
 
        if( attr )
904
 
                return attr;
905
 
 
906
 
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
907
 
                                        "couldn't get Lamp.name attribute" ) );
 
858
        Lamp *lamp = copy_lamp(self->lamp );
 
859
        lamp->id.us = 0;
 
860
        return Lamp_CreatePyObject(lamp);
908
861
}
909
862
 
910
863
static PyObject *Lamp_getType( BPy_Lamp * self )
1131
1084
        return rgbTuple_getCol( self->color );
1132
1085
}
1133
1086
 
1134
 
static int Lamp_setName( BPy_Lamp * self, PyObject * value )
1135
 
{
1136
 
        char *name = NULL;
1137
 
        char buf[21];
1138
 
 
1139
 
        name = PyString_AsString ( value );
1140
 
        if( !name )
1141
 
                return EXPP_ReturnIntError( PyExc_TypeError,
1142
 
                                              "expected string argument" );
1143
 
 
1144
 
        PyOS_snprintf( buf, sizeof( buf ), "%s", name );
1145
 
 
1146
 
        rename_id( &self->lamp->id, buf );
1147
 
 
1148
 
        return 0;
1149
 
}
1150
 
 
1151
1087
static int Lamp_setType( BPy_Lamp * self, PyObject * value )
1152
1088
{
1153
1089
        return EXPP_setIValueRange ( value, &self->lamp->type,
1459
1395
 
1460
1396
static int Lamp_setIpo( BPy_Lamp * self, PyObject * value )
1461
1397
{
1462
 
        Ipo *ipo = NULL;
1463
 
        Ipo *oldipo = self->lamp->ipo;
1464
 
        ID *id;
1465
 
 
1466
 
        /* if parameter is not None, check for valid Ipo */
1467
 
 
1468
 
        if ( value != Py_None ) {
1469
 
                if ( !Ipo_CheckPyObject( value ) )
1470
 
                        return EXPP_ReturnIntError( PyExc_RuntimeError,
1471
 
                                                "expected an Ipo object" );
1472
 
 
1473
 
                ipo = Ipo_FromPyObject( value );
1474
 
 
1475
 
                if( !ipo )
1476
 
                        return EXPP_ReturnIntError( PyExc_RuntimeError,
1477
 
                                                "null ipo!" );
1478
 
 
1479
 
                if( ipo->blocktype != ID_LA )
1480
 
                        return EXPP_ReturnIntError( PyExc_TypeError,
1481
 
                                                "Ipo is not a lamp data Ipo" );
1482
 
        }
1483
 
 
1484
 
        /* if already linked to Ipo, delete link */
1485
 
 
1486
 
        if ( oldipo ) {
1487
 
                id = &oldipo->id;
1488
 
                if( id->us > 0 )
1489
 
                        id->us--;
1490
 
        }
1491
 
 
1492
 
        /* assign new Ipo and increment user count, or set to NULL if deleting */
1493
 
 
1494
 
        self->lamp->ipo = ipo;
1495
 
        if ( ipo ) {
1496
 
                id = &ipo->id;
1497
 
                id_us_plus(id);
1498
 
        }
1499
 
 
1500
 
        return 0;
 
1398
        return GenericLib_assignData(value, (void **) &self->lamp->ipo, 0, 1, ID_IP, ID_LA);
1501
1399
}
1502
1400
 
1503
1401
/*
1585
1483
        return attr;
1586
1484
}
1587
1485
 
1588
 
static PyObject *Lamp_getUsers( BPy_Lamp * self )
1589
 
{
1590
 
        return PyInt_FromLong( self->lamp->id.us );
1591
 
}
1592
 
 
1593
1486
/* #####DEPRECATED###### */
1594
1487
 
1595
 
static PyObject *Lamp_oldsetName( BPy_Lamp * self, PyObject * args )
1596
 
{
1597
 
        return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setName );
1598
 
}
1599
 
 
1600
1488
static PyObject *Lamp_oldsetSamples( BPy_Lamp * self, PyObject * args )
1601
1489
{
1602
1490
        return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSamples );