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

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/World.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: World.c,v 1.37 2006/12/27 05:04:20 campbellbarton Exp $
 
2
 * $Id: World.c,v 1.48 2007/03/31 15:31:37 khughes Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
56
56
#include "mydevice.h"
57
57
#include "Ipo.h"
58
58
#include "gen_utils.h"
59
 
 
 
59
#include "gen_library.h"
60
60
 
61
61
#define IPOKEY_ZENITH   0
62
62
#define IPOKEY_HORIZON  1
70
70
static PyObject *World_getRange( BPy_World * self );
71
71
static PyObject *World_setRange( BPy_World * self, PyObject * args );
72
72
static PyObject *World_getIpo( BPy_World * self );
73
 
static PyObject *World_setIpo( BPy_World * self, PyObject * args );
 
73
static PyObject *World_oldsetIpo( BPy_World * self, PyObject * args );
 
74
static int       World_setIpo( BPy_World * self, PyObject * args );
74
75
static PyObject *World_clearIpo( BPy_World * self );
75
76
static PyObject *World_insertIpoKey( BPy_World * self, PyObject * args );
76
 
static PyObject *World_getName( BPy_World * self );
77
 
static PyObject *World_setName( BPy_World * self, PyObject * args );
78
77
static PyObject *World_getMode( BPy_World * self );
79
 
static PyObject *World_setMode( BPy_World * self, PyObject * args );
 
78
static PyObject *World_oldsetMode( BPy_World * self, PyObject * args );
 
79
static int       World_setMode( BPy_World * self, PyObject * args );
80
80
static PyObject *World_getSkytype( BPy_World * self );
81
 
static PyObject *World_setSkytype( BPy_World * self, PyObject * args );
 
81
static PyObject *World_oldsetSkytype( BPy_World * self, PyObject * args );
 
82
static int       World_setSkytype( BPy_World * self, PyObject * args );
82
83
static PyObject *World_getMistype( BPy_World * self );
83
 
static PyObject *World_setMistype( BPy_World * self, PyObject * args );
 
84
static PyObject *World_oldsetMistype( BPy_World * self, PyObject * args );
 
85
static int       World_setMistype( BPy_World * self, PyObject * args );
84
86
static PyObject *World_getHor( BPy_World * self );
85
 
static PyObject *World_setHor( BPy_World * self, PyObject * args );
 
87
static PyObject *World_oldsetHor( BPy_World * self, PyObject * args );
 
88
static int       World_setHor( BPy_World * self, PyObject * args );
86
89
static PyObject *World_getZen( BPy_World * self );
87
 
static PyObject *World_setZen( BPy_World * self, PyObject * args );
 
90
static PyObject *World_oldsetZen( BPy_World * self, PyObject * args );
 
91
static int       World_setZen( BPy_World * self, PyObject * args );
88
92
static PyObject *World_getAmb( BPy_World * self );
89
 
static PyObject *World_setAmb( BPy_World * self, PyObject * args );
 
93
static PyObject *World_oldsetAmb( BPy_World * self, PyObject * args );
 
94
static int       World_setAmb( BPy_World * self, PyObject * args );
90
95
static PyObject *World_getStar( BPy_World * self );
91
 
static PyObject *World_setStar( BPy_World * self, PyObject * args );
 
96
static PyObject *World_oldsetStar( BPy_World * self, PyObject * args );
 
97
static int       World_setStar( BPy_World * self, PyObject * args );
92
98
static PyObject *World_getMist( BPy_World * self );
93
 
static PyObject *World_setMist( BPy_World * self, PyObject * args );
 
99
static PyObject *World_oldsetMist( BPy_World * self, PyObject * args );
 
100
static int       World_setMist( BPy_World * self, PyObject * args );
94
101
static PyObject *World_getScriptLinks( BPy_World * self, PyObject * args );
95
102
static PyObject *World_addScriptLink( BPy_World * self, PyObject * args );
96
103
static PyObject *World_clearScriptLinks( BPy_World * self, PyObject * args );
110
117
/*****************************************************************************/
111
118
/* Python World_Type callback function prototypes:                      */
112
119
/*****************************************************************************/
113
 
static void World_DeAlloc( BPy_World * self );
114
120
//static int World_Print (BPy_World *self, FILE *fp, int flags);
115
 
static int World_SetAttr( BPy_World * self, char *name, PyObject * v );
116
121
static int World_Compare( BPy_World * a, BPy_World * b );
117
 
static PyObject *World_GetAttr( BPy_World * self, char *name );
118
122
static PyObject *World_Repr( BPy_World * self );
119
123
 
120
124
 
165
169
         "() - Change this World's range"},
166
170
        {"getIpo", ( PyCFunction ) World_getIpo, METH_NOARGS,
167
171
         "() - Return World Ipo"},
168
 
        {"setIpo", ( PyCFunction ) World_setIpo, METH_VARARGS,
 
172
        {"setIpo", ( PyCFunction ) World_oldsetIpo, METH_VARARGS,
169
173
         "() - Change this World's ipo"},
170
174
        {"clearIpo", ( PyCFunction ) World_clearIpo, METH_VARARGS,
171
175
         "() - Unlink Ipo from this World"},
172
 
        {"getName", ( PyCFunction ) World_getName, METH_NOARGS,
 
176
        {"getName", ( PyCFunction ) GenericLib_getName, METH_NOARGS,
173
177
         "() - Return World Data name"},
174
 
        {"setName", ( PyCFunction ) World_setName, METH_VARARGS,
 
178
        {"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
175
179
         "() - Set World Data name"},
176
180
        {"getMode", ( PyCFunction ) World_getMode, METH_NOARGS,
177
181
         "() - Return World Data mode"},
178
 
        {"setMode", ( PyCFunction ) World_setMode, METH_VARARGS,
 
182
        {"setMode", ( PyCFunction ) World_oldsetMode, METH_VARARGS,
179
183
         "(i) - Set World Data mode"},
180
184
        {"getSkytype", ( PyCFunction ) World_getSkytype, METH_NOARGS,
181
185
         "() - Return World Data skytype"},
182
 
        {"setSkytype", ( PyCFunction ) World_setSkytype, METH_VARARGS,
 
186
        {"setSkytype", ( PyCFunction ) World_oldsetSkytype, METH_VARARGS,
183
187
         "() - Return World Data skytype"},
184
188
        {"getMistype", ( PyCFunction ) World_getMistype, METH_NOARGS,
185
189
         "() - Return World Data mistype"},
186
 
        {"setMistype", ( PyCFunction ) World_setMistype, METH_VARARGS,
 
190
        {"setMistype", ( PyCFunction ) World_oldsetMistype, METH_VARARGS,
187
191
         "() - Return World Data mistype"},
188
192
        {"getHor", ( PyCFunction ) World_getHor, METH_NOARGS,
189
193
         "() - Return World Data hor"},
190
 
        {"setHor", ( PyCFunction ) World_setHor, METH_VARARGS,
 
194
        {"setHor", ( PyCFunction ) World_oldsetHor, METH_VARARGS,
191
195
         "() - Return World Data hor"},
192
196
        {"getZen", ( PyCFunction ) World_getZen, METH_NOARGS,
193
197
         "() - Return World Data zen"},
194
 
        {"setZen", ( PyCFunction ) World_setZen, METH_VARARGS,
 
198
        {"setZen", ( PyCFunction ) World_oldsetZen, METH_VARARGS,
195
199
         "() - Return World Data zen"},
196
200
        {"getAmb", ( PyCFunction ) World_getAmb, METH_NOARGS,
197
201
         "() - Return World Data amb"},
198
 
        {"setAmb", ( PyCFunction ) World_setAmb, METH_VARARGS,
 
202
        {"setAmb", ( PyCFunction ) World_oldsetAmb, METH_VARARGS,
199
203
         "() - Return World Data amb"},
200
204
        {"getStar", ( PyCFunction ) World_getStar, METH_NOARGS,
201
205
         "() - Return World Data star"},
202
 
        {"setStar", ( PyCFunction ) World_setStar, METH_VARARGS,
 
206
        {"setStar", ( PyCFunction ) World_oldsetStar, METH_VARARGS,
203
207
         "() - Return World Data star"},
204
208
        {"getMist", ( PyCFunction ) World_getMist, METH_NOARGS,
205
209
         "() - Return World Data mist"},
206
 
        {"setMist", ( PyCFunction ) World_setMist, METH_VARARGS,
 
210
        {"setMist", ( PyCFunction ) World_oldsetMist, METH_VARARGS,
207
211
         "() - Return World Data mist"},
208
212
        {"getScriptLinks", ( PyCFunction ) World_getScriptLinks, METH_VARARGS,
209
213
         "(eventname) - Get a list of this world's scriptlinks (Text names) "
225
229
         "( World IPO type ) - Inserts a key into the IPO"},
226
230
        {"__copy__", ( PyCFunction ) World_copy, METH_NOARGS,
227
231
         "() - Makes a copy of this world."},
 
232
        {"copy", ( PyCFunction ) World_copy, METH_NOARGS,
 
233
         "() - Makes a copy of this world."},
228
234
        {NULL, NULL, 0, NULL}
229
235
};
230
236
 
 
237
/*****************************************************************************/
 
238
/* Python attributes get/set structure:                                      */
 
239
/*****************************************************************************/
 
240
static PyGetSetDef BPy_World_getseters[] = {
 
241
        GENERIC_LIB_GETSETATTR,
 
242
        {"skytype", (getter)World_getSkytype, (setter)World_setSkytype,
 
243
         "sky settings as a list", NULL},
 
244
        {"mode", (getter)World_getMode, (setter)World_setMode,
 
245
         "world mode", NULL},
 
246
        {"mistype", (getter)World_getMistype, (setter)World_setMistype,
 
247
         "world mist type", NULL},
 
248
        {"hor", (getter)World_getHor, (setter)World_setHor,
 
249
         "world horizon color", NULL},
 
250
        {"amb", (getter)World_getAmb, (setter)World_setAmb,
 
251
         "world ambient color", NULL},
 
252
        {"mist", (getter)World_getMist, (setter)World_setMist,
 
253
         "world mist settings", NULL},
 
254
        {"ipo", (getter)World_getIpo, (setter)World_setIpo,
 
255
         "world ipo", NULL},
 
256
        {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 
257
};
231
258
 
232
259
/*****************************************************************************/
233
260
/* Python World_Type structure definition:                                */
239
266
        sizeof( BPy_World ),    /* tp_basicsize */
240
267
        0,                      /* tp_itemsize */
241
268
        /* methods */
242
 
        ( destructor ) World_DeAlloc,   /* tp_dealloc */
243
 
        0,                      /* tp_print */
244
 
        ( getattrfunc ) World_GetAttr,  /* tp_getattr */
245
 
        ( setattrfunc ) World_SetAttr,  /* tp_setattr */
 
269
        NULL,   /* tp_dealloc */
 
270
        0,              /* tp_print */
 
271
        NULL,   /* tp_getattr */
 
272
        NULL,   /* tp_setattr */
246
273
        ( cmpfunc ) World_Compare,      /* tp_compare */
247
274
        ( reprfunc ) World_Repr,        /* tp_repr */
248
 
        0,                      /* tp_as_number */
249
 
        0,                      /* tp_as_sequence */
250
 
        0,                      /* tp_as_mapping */
251
 
        0,                      /* tp_as_hash */
252
 
        0, 0, 0, 0, 0, 0,
253
 
        0,                      /* tp_doc */
254
 
        0, 0, 0, 0, 0, 0,
255
 
        BPy_World_methods,      /* tp_methods */
256
 
        0,                      /* tp_members */
257
 
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
275
 
 
276
        /* Method suites for standard classes */
 
277
 
 
278
        NULL,                       /* PyNumberMethods *tp_as_number; */
 
279
        NULL,                       /* PySequenceMethods *tp_as_sequence; */
 
280
        NULL,                       /* PyMappingMethods *tp_as_mapping; */
 
281
 
 
282
        /* More standard operations (here for binary compatibility) */
 
283
 
 
284
        ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
 
285
        NULL,                       /* ternaryfunc tp_call; */
 
286
        NULL,                       /* reprfunc tp_str; */
 
287
        NULL,                       /* getattrofunc tp_getattro; */
 
288
        NULL,                       /* setattrofunc tp_setattro; */
 
289
 
 
290
        /* Functions to access object as input/output buffer */
 
291
        NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
292
 
 
293
  /*** Flags to define presence of optional/expanded features ***/
 
294
        Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
 
295
 
 
296
        NULL,                       /*  char *tp_doc;  Documentation string */
 
297
  /*** Assigned meaning in release 2.0 ***/
 
298
        /* call function for all accessible objects */
 
299
        NULL,                       /* traverseproc tp_traverse; */
 
300
 
 
301
        /* delete references to contained objects */
 
302
        NULL,                       /* inquiry tp_clear; */
 
303
 
 
304
  /***  Assigned meaning in release 2.1 ***/
 
305
  /*** rich comparisons ***/
 
306
        NULL,                       /* richcmpfunc tp_richcompare; */
 
307
 
 
308
  /***  weak reference enabler ***/
 
309
        0,                          /* long tp_weaklistoffset; */
 
310
 
 
311
  /*** Added in release 2.2 ***/
 
312
        /*   Iterators */
 
313
        NULL,                       /* getiterfunc tp_iter; */
 
314
        NULL,                       /* iternextfunc tp_iternext; */
 
315
 
 
316
  /*** Attribute descriptor and subclassing stuff ***/
 
317
        BPy_World_methods,           /* struct PyMethodDef *tp_methods; */
 
318
        NULL,                       /* struct PyMemberDef *tp_members; */
 
319
        BPy_World_getseters,         /* struct PyGetSetDef *tp_getset; */
 
320
        NULL,                       /* struct _typeobject *tp_base; */
 
321
        NULL,                       /* PyObject *tp_dict; */
 
322
        NULL,                       /* descrgetfunc tp_descr_get; */
 
323
        NULL,                       /* descrsetfunc tp_descr_set; */
 
324
        0,                          /* long tp_dictoffset; */
 
325
        NULL,                       /* initproc tp_init; */
 
326
        NULL,                       /* allocfunc tp_alloc; */
 
327
        NULL,                       /* newfunc tp_new; */
 
328
        /*  Low-level free-memory routine */
 
329
        NULL,                       /* freefunc tp_free;  */
 
330
        /* For PyObject_IS_GC */
 
331
        NULL,                       /* inquiry tp_is_gc;  */
 
332
        NULL,                       /* PyObject *tp_bases; */
 
333
        /* method resolution order */
 
334
        NULL,                       /* PyObject *tp_mro;  */
 
335
        NULL,                       /* PyObject *tp_cache; */
 
336
        NULL,                       /* PyObject *tp_subclasses; */
 
337
        NULL,                       /* PyObject *tp_weaklist; */
 
338
        NULL
258
339
};
259
340
 
260
341
/**
326
407
        char *name = NULL;
327
408
        World *world_iter;
328
409
        PyObject *worldlist;
329
 
        BPy_World *wanted_world = NULL;
330
410
        char error_msg[64];
331
411
 
332
412
        if( !PyArg_ParseTuple( args, "|s", &name ) )
333
413
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
334
414
                                                "expected string argument (or nothing)" ) );
335
415
 
336
 
        world_iter = G.main->world.first;
337
 
 
338
416
        if( name ) {            /* (name) - Search world by name */
339
 
                while( ( world_iter ) && ( wanted_world == NULL ) ) {
340
 
                        if( strcmp( name, world_iter->id.name + 2 ) == 0 ) {
341
 
                                wanted_world =
342
 
                                        ( BPy_World * )
343
 
                                        PyObject_NEW( BPy_World, &World_Type );
344
 
                                if( wanted_world )
345
 
                                        wanted_world->world = world_iter;
346
 
                        }
347
 
                        world_iter = world_iter->id.next;
348
 
                }
349
 
 
350
 
                if( wanted_world == NULL ) {    /* Requested world doesn't exist */
 
417
                world_iter = ( World * ) GetIdFromList( &( G.main->world ), name );
 
418
                
 
419
                if( world_iter == NULL ) {      /* Requested world doesn't exist */
351
420
                        PyOS_snprintf( error_msg, sizeof( error_msg ),
352
421
                                       "World \"%s\" not found", name );
353
422
                        return ( EXPP_ReturnPyObjError
354
423
                                 ( PyExc_NameError, error_msg ) );
355
424
                }
356
425
 
357
 
                return ( PyObject * ) wanted_world;
 
426
                return ( PyObject * ) World_CreatePyObject(world_iter);
358
427
        }
359
428
 
360
429
        else {                  /* return a list of all worlds in the scene */
 
430
                world_iter = G.main->world.first;
361
431
                worldlist = PyList_New( 0 );
362
432
                if( worldlist == NULL )
363
433
                        return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
377
447
 
378
448
}
379
449
 
380
 
 
381
 
 
382
450
static PyObject *M_World_GetCurrent( PyObject * self )
383
451
{
384
452
        BPy_World *w = NULL;
 
453
#if 0   /* add back in when bpy becomes "official" */
 
454
        static char warning = 1;
 
455
        if( warning ) {
 
456
                printf("Blender.World.GetCurrent() deprecated!\n\tuse bpy.scenes.world instead\n");
 
457
                --warning;
 
458
        }
 
459
#endif
 
460
 
385
461
        if( !G.scene->world )
386
462
                Py_RETURN_NONE;
387
463
        
404
480
{
405
481
        PyObject *submodule;
406
482
 
407
 
        World_Type.ob_type = &PyType_Type;
 
483
        if( PyType_Ready( &World_Type ) < 0 )
 
484
                return NULL;
408
485
 
409
486
        submodule = Py_InitModule3( "Blender.World",
410
487
                                    M_World_methods, M_World_doc );
419
496
        return ( submodule );
420
497
}
421
498
 
422
 
 
423
499
/*****************************************************************************/
424
500
/* Python BPy_World methods:                                            */
425
501
/*****************************************************************************/
449
525
        return Ipo_CreatePyObject( ipo );
450
526
}
451
527
 
452
 
static PyObject *World_setIpo( BPy_World * self, PyObject * args )
453
 
{
454
 
        PyObject *pyipo = 0;
455
 
        Ipo *ipo = NULL;
456
 
        Ipo *oldipo;
457
 
 
458
 
        if( !PyArg_ParseTuple( args, "O!", &Ipo_Type, &pyipo ) )
459
 
                return EXPP_ReturnPyObjError( PyExc_TypeError,
460
 
                                              "expected Ipo as argument" );
461
 
 
462
 
        ipo = Ipo_FromPyObject( pyipo );
463
 
 
464
 
        if( !ipo )
465
 
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
466
 
                                              "null ipo!" );
467
 
 
468
 
        if( ipo->blocktype != ID_WO )
469
 
                return EXPP_ReturnPyObjError( PyExc_TypeError,
470
 
                                              "this ipo is not a World type ipo" );
471
 
 
472
 
        oldipo = self->world->ipo;
473
 
        if( oldipo ) {
474
 
                ID *id = &oldipo->id;
475
 
                if( id->us > 0 )
476
 
                        id->us--;
477
 
        }
478
 
 
479
 
        id_us_plus(&ipo->id);
480
 
 
481
 
        self->world->ipo = ipo;
482
 
 
483
 
        Py_RETURN_NONE;
 
528
static int World_setIpo( BPy_World * self, PyObject * value )
 
529
{
 
530
        return GenericLib_assignData(value, (void **) &self->world->ipo, 0, 1, ID_IP, ID_WO);
 
531
}
 
532
 
 
533
static PyObject *World_oldsetIpo( BPy_World * self, PyObject * args )
 
534
{
 
535
        return EXPP_setterWrapper( (void *)self, args, (setter)World_setIpo );
484
536
}
485
537
 
486
538
static PyObject *World_clearIpo( BPy_World * self )
501
553
}
502
554
 
503
555
/**
504
 
 * \brief World PyMethod getName
505
 
 *
506
 
 * \return string: The World Data name.
507
 
 */
508
 
 
509
 
static PyObject *World_getName( BPy_World * self )
510
 
{
511
 
        PyObject *attr = PyString_FromString( self->world->id.name + 2 );
512
 
 
513
 
        if( attr )
514
 
                return attr;
515
 
 
516
 
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
517
 
                                        "couldn't get World.name attribute" ) );
518
 
}
519
 
 
520
 
/**
521
 
 * \brief World PyMethod setName
522
 
 * \param name - string: The new World Data name.
523
 
 */
524
 
 
525
 
static PyObject *World_setName( BPy_World * self, PyObject * args )
526
 
{
527
 
        char *name = 0;
528
 
        if( !PyArg_ParseTuple( args, "s", &name ) )
529
 
                return ( EXPP_ReturnPyObjError
530
 
                         ( PyExc_TypeError, "expected string argument" ) );
531
 
        rename_id( &self->world->id, name );
532
 
 
533
 
        Py_RETURN_NONE;
534
 
}
535
 
 
536
 
 
537
 
 
538
 
 
539
 
 
540
 
/**
541
556
 * \brief World PyMethod getSkytype
542
557
 *
543
558
 * \return int : The World Data skytype.
561
576
 * \return int : The World Data skytype.
562
577
 */
563
578
 
564
 
static PyObject *World_setSkytype( BPy_World * self, PyObject * args )
 
579
static int World_setSkytype( BPy_World * self, PyObject * value )
565
580
{
566
 
        int skytype;
567
 
 
568
 
        if( !PyArg_ParseTuple( args, "i", &skytype ) )
569
 
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
581
        if( !PyInt_CheckExact(value) )
 
582
                return ( EXPP_ReturnIntError( PyExc_TypeError,
570
583
                                                "expected int argument" ) );
571
 
        self->world->skytype = (short)skytype;
572
 
        Py_RETURN_NONE;
 
584
        self->world->skytype = (short)PyInt_AsLong(value);
 
585
        return 0;
 
586
}
 
587
 
 
588
static PyObject *World_oldsetSkytype( BPy_World * self, PyObject * args )
 
589
{
 
590
        return EXPP_setterWrapper( (void *)self, args, (setter)World_setSkytype );
573
591
}
574
592
 
575
593
 
597
615
 * \return int : The World Data mode.
598
616
 */
599
617
 
600
 
static PyObject *World_setMode( BPy_World * self, PyObject * args )
 
618
static int World_setMode( BPy_World * self, PyObject * value )
601
619
{
602
 
        int mode;
603
 
 
604
 
        if( !PyArg_ParseTuple( args, "i", &mode ) )
605
 
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
620
        if( !PyInt_CheckExact(value) )
 
621
                return ( EXPP_ReturnIntError( PyExc_TypeError,
606
622
                                                "expected int argument" ) );
607
 
        self->world->mode = (short)mode;
608
 
        Py_RETURN_NONE;
609
 
}
610
 
 
611
 
 
612
 
 
613
 
 
614
 
 
615
 
 
616
 
 
617
 
 
618
 
 
619
 
 
620
 
 
 
623
        self->world->mode = (short)PyInt_AsLong(value);
 
624
        return 0;
 
625
}
 
626
 
 
627
static PyObject *World_oldsetMode( BPy_World * self, PyObject * args )
 
628
{
 
629
        return EXPP_setterWrapper( (void *)self, args, (setter)World_setMode );
 
630
}
621
631
 
622
632
 
623
633
 
645
655
 * \return int : The World Data mistype.
646
656
 */
647
657
 
648
 
static PyObject *World_setMistype( BPy_World * self, PyObject * args )
 
658
static int World_setMistype( BPy_World * self, PyObject * value )
649
659
{
650
 
        int mistype;
651
 
 
652
 
        if( !PyArg_ParseTuple( args, "i", &mistype ) )
653
 
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
660
        if( !PyInt_CheckExact(value) )
 
661
                return ( EXPP_ReturnIntError( PyExc_TypeError,
654
662
                                                "expected int argument" ) );
655
 
        self->world->mistype = (short)mistype;
656
 
        Py_RETURN_NONE;
657
 
}
658
 
 
659
 
 
 
663
        self->world->mistype = (short)PyInt_AsLong(value);
 
664
        return 0;
 
665
}
 
666
 
 
667
static PyObject *World_oldsetMistype( BPy_World * self, PyObject * args )
 
668
{
 
669
        return EXPP_setterWrapper( (void *)self, args, (setter)World_setMistype );
 
670
}
660
671
 
661
672
 
662
673
 
673
684
}
674
685
 
675
686
 
676
 
static PyObject *World_setHor( BPy_World * self, PyObject * args )
 
687
static int World_setHor( BPy_World * self, PyObject * value )
677
688
{
678
 
        PyObject *listargs = 0;
679
 
        if( !PyArg_ParseTuple( args, "O", &listargs ) )
680
 
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
689
        if( !PyList_Check( value ) )
 
690
                return ( EXPP_ReturnIntError( PyExc_TypeError,
681
691
                                                "expected list argument" ) );
682
 
        self->world->horr = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 0 ) );
683
 
        self->world->horg = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 1 ) );
684
 
        self->world->horb = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 2 ) );
685
 
        Py_RETURN_NONE;
 
692
        if( PyList_Size( value ) != 3 )
 
693
                return ( EXPP_ReturnIntError
 
694
                         ( PyExc_TypeError, "list size must be 3" ) );
 
695
        self->world->horr = (float)PyFloat_AsDouble( PyList_GetItem( value, 0 ) );
 
696
        self->world->horg = (float)PyFloat_AsDouble( PyList_GetItem( value, 1 ) );
 
697
        self->world->horb = (float)PyFloat_AsDouble( PyList_GetItem( value, 2 ) );
 
698
        return 0;
686
699
}
687
700
 
 
701
static PyObject *World_oldsetHor( BPy_World * self, PyObject * args )
 
702
{
 
703
        return EXPP_setterWrapper( (void *)self, args, (setter)World_setHor );
 
704
}
688
705
 
689
706
static PyObject *World_getZen( BPy_World * self )
690
707
{
699
716
}
700
717
 
701
718
 
702
 
static PyObject *World_setZen( BPy_World * self, PyObject * args )
 
719
static int World_setZen( BPy_World * self, PyObject * value )
703
720
{
704
 
        PyObject *listargs = 0;
705
 
        if( !PyArg_ParseTuple( args, "O", &listargs ) )
706
 
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
721
        if( !PyList_Check( value ) )
 
722
                return ( EXPP_ReturnIntError( PyExc_TypeError,
707
723
                                                "expected list argument" ) );
708
 
        self->world->zenr = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 0 ) );
709
 
        self->world->zeng = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 1 ) );
710
 
        self->world->zenb = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 2 ) );
711
 
        Py_RETURN_NONE;
712
 
}
713
 
 
714
 
 
 
724
        if( PyList_Size( value ) != 3 )
 
725
                return ( EXPP_ReturnIntError
 
726
                         ( PyExc_TypeError, "list size must be 3" ) );
 
727
        self->world->zenr = (float)PyFloat_AsDouble( PyList_GetItem( value, 0 ) );
 
728
        self->world->zeng = (float)PyFloat_AsDouble( PyList_GetItem( value, 1 ) );
 
729
        self->world->zenb = (float)PyFloat_AsDouble( PyList_GetItem( value, 2 ) );
 
730
        return 0;
 
731
}
 
732
 
 
733
static PyObject *World_oldsetZen( BPy_World * self, PyObject * args )
 
734
{
 
735
        return EXPP_setterWrapper( (void *)self, args, (setter)World_setZen );
 
736
}
715
737
 
716
738
 
717
739
static PyObject *World_getAmb( BPy_World * self )
727
749
}
728
750
 
729
751
 
730
 
static PyObject *World_setAmb( BPy_World * self, PyObject * args )
 
752
static int World_setAmb( BPy_World * self, PyObject * value )
731
753
{
732
 
        PyObject *listargs = 0;
733
 
        if( !PyArg_ParseTuple( args, "O", &listargs ) )
734
 
                return ( EXPP_ReturnPyObjError
735
 
                         ( PyExc_TypeError, "expected list argument" ) );
736
 
        if( !PyList_Check( listargs ) )
737
 
                return ( EXPP_ReturnPyObjError
738
 
                         ( PyExc_TypeError, "expected list argument" ) );
739
 
        if( PyList_Size( listargs ) != 3 )
740
 
                return ( EXPP_ReturnPyObjError
 
754
        if( !PyList_Check( value ) )
 
755
                return ( EXPP_ReturnIntError( PyExc_TypeError,
 
756
                                                "expected list argument" ) );
 
757
        if( PyList_Size( value ) != 3 )
 
758
                return ( EXPP_ReturnIntError
741
759
                         ( PyExc_TypeError, "wrong list size" ) );
742
 
        self->world->ambr = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 0 ) );
743
 
        self->world->ambg = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 1 ) );
744
 
        self->world->ambb = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 2 ) );
745
 
        Py_RETURN_NONE;
 
760
        self->world->ambr = (float)PyFloat_AsDouble( PyList_GetItem( value, 0 ) );
 
761
        self->world->ambg = (float)PyFloat_AsDouble( PyList_GetItem( value, 1 ) );
 
762
        self->world->ambb = (float)PyFloat_AsDouble( PyList_GetItem( value, 2 ) );
 
763
        return 0;
746
764
}
747
765
 
 
766
static PyObject *World_oldsetAmb( BPy_World * self, PyObject * args )
 
767
{
 
768
        return EXPP_setterWrapper( (void *)self, args, (setter)World_setAmb );
 
769
}
748
770
 
749
771
static PyObject *World_getStar( BPy_World * self )
750
772
{
763
785
}
764
786
 
765
787
 
766
 
static PyObject *World_setStar( BPy_World * self, PyObject * args )
 
788
static int World_setStar( BPy_World * self, PyObject * value )
767
789
{
768
 
        PyObject *listargs = 0;
769
 
        if( !PyArg_ParseTuple( args, "O", &listargs ) )
770
 
                return ( EXPP_ReturnPyObjError
771
 
                         ( PyExc_TypeError, "expected list argument" ) );
772
 
        if( !PyList_Check( listargs ) )
773
 
                return ( EXPP_ReturnPyObjError
774
 
                         ( PyExc_TypeError, "expected list argument" ) );
775
 
        if( PyList_Size( listargs ) != 7 )
776
 
                return ( EXPP_ReturnPyObjError
 
790
        if( !PyList_Check( value ) )
 
791
                return ( EXPP_ReturnIntError
 
792
                         ( PyExc_TypeError, "expected list argument" ) );
 
793
        if( PyList_Size( value ) != 7 )
 
794
                return ( EXPP_ReturnIntError
777
795
                         ( PyExc_TypeError, "wrong list size" ) );
778
 
        self->world->starr = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 0 ) );
779
 
        self->world->starg = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 1 ) );
780
 
        self->world->starb = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 2 ) );
 
796
        self->world->starr = (float)PyFloat_AsDouble( PyList_GetItem( value, 0 ) );
 
797
        self->world->starg = (float)PyFloat_AsDouble( PyList_GetItem( value, 1 ) );
 
798
        self->world->starb = (float)PyFloat_AsDouble( PyList_GetItem( value, 2 ) );
781
799
        self->world->starsize =
782
 
                (float)PyFloat_AsDouble( PyList_GetItem( listargs, 3 ) );
 
800
                (float)PyFloat_AsDouble( PyList_GetItem( value, 3 ) );
783
801
        self->world->starmindist =
784
 
                (float)PyFloat_AsDouble( PyList_GetItem( listargs, 4 ) );
 
802
                (float)PyFloat_AsDouble( PyList_GetItem( value, 4 ) );
785
803
        self->world->stardist =
786
 
                (float)PyFloat_AsDouble( PyList_GetItem( listargs, 5 ) );
 
804
                (float)PyFloat_AsDouble( PyList_GetItem( value, 5 ) );
787
805
        self->world->starcolnoise =
788
 
                (float)PyFloat_AsDouble( PyList_GetItem( listargs, 6 ) );
789
 
        Py_RETURN_NONE;
790
 
}
791
 
 
792
 
 
793
 
 
794
 
 
 
806
                (float)PyFloat_AsDouble( PyList_GetItem( value, 6 ) );
 
807
        return 0;
 
808
}
 
809
 
 
810
static PyObject *World_oldsetStar( BPy_World * self, PyObject * args )
 
811
{
 
812
        return EXPP_setterWrapper( (void *)self, args, (setter)World_setStar );
 
813
}
795
814
 
796
815
 
797
816
static PyObject *World_getMist( BPy_World * self )
808
827
}
809
828
 
810
829
 
811
 
static PyObject *World_setMist( BPy_World * self, PyObject * args )
 
830
static int World_setMist( BPy_World * self, PyObject * value )
812
831
{
813
 
        PyObject *listargs = 0;
814
 
        if( !PyArg_ParseTuple( args, "O", &listargs ) )
815
 
                return ( EXPP_ReturnPyObjError
816
 
                         ( PyExc_TypeError, "expected list argument" ) );
817
 
        if( !PyList_Check( listargs ) )
818
 
                return ( EXPP_ReturnPyObjError
819
 
                         ( PyExc_TypeError, "expected list argument" ) );
820
 
        if( PyList_Size( listargs ) != 4 )
821
 
                return ( EXPP_ReturnPyObjError
 
832
        if( !PyList_Check( value ) )
 
833
                return ( EXPP_ReturnIntError
 
834
                         ( PyExc_TypeError, "expected list argument" ) );
 
835
        if( PyList_Size( value ) != 4 )
 
836
                return ( EXPP_ReturnIntError
822
837
                         ( PyExc_TypeError, "wrong list size" ) );
823
 
        self->world->misi = (float)PyFloat_AsDouble( PyList_GetItem( listargs, 0 ) );
 
838
        self->world->misi = (float)PyFloat_AsDouble( PyList_GetItem( value, 0 ) );
824
839
        self->world->miststa =
825
 
                (float)PyFloat_AsDouble( PyList_GetItem( listargs, 1 ) );
 
840
                (float)PyFloat_AsDouble( PyList_GetItem( value, 1 ) );
826
841
        self->world->mistdist =
827
 
                (float)PyFloat_AsDouble( PyList_GetItem( listargs, 2 ) );
 
842
                (float)PyFloat_AsDouble( PyList_GetItem( value, 2 ) );
828
843
        self->world->misthi =
829
 
                (float)PyFloat_AsDouble( PyList_GetItem( listargs, 3 ) );
830
 
        Py_RETURN_NONE;
831
 
}
 
844
                (float)PyFloat_AsDouble( PyList_GetItem( value, 3 ) );
 
845
        return 0;
 
846
}
 
847
 
 
848
static PyObject *World_oldsetMist( BPy_World * self, PyObject * args )
 
849
{
 
850
        return EXPP_setterWrapper( (void *)self, args, (setter)World_setMist );
 
851
}
 
852
 
832
853
 
833
854
/* world.addScriptLink */
834
855
static PyObject *World_addScriptLink( BPy_World * self, PyObject * args )
870
891
}
871
892
 
872
893
 
873
 
 
874
894
/* world.setCurrent */
875
895
static PyObject *World_setCurrent( BPy_World * self )
876
896
{
877
897
        World *world = self->world;
 
898
#if 0   /* add back in when bpy becomes "official" */
 
899
        static char warning = 1;
 
900
        if( warning ) {
 
901
                printf("world.setCurrent() deprecated!\n\tuse bpy.scenes.world=world instead\n");
 
902
                --warning;
 
903
        }
 
904
#endif
 
905
 
878
906
        /* If there is a world then it now has one less user */
879
907
        if( G.scene->world )
880
908
                G.scene->world->id.us--;
886
914
/* world.__copy__ */
887
915
static PyObject *World_copy( BPy_World * self )
888
916
{
889
 
        BPy_World *pyworld;
890
 
        World *blworld;
891
 
 
892
 
        blworld = copy_world( self->world );
893
 
 
894
 
        if( blworld ) {
895
 
                /* return user count to zero because add_world() inc'd it */
896
 
                blworld->id.us = 0;
897
 
                /* create python wrapper obj */
898
 
                pyworld =
899
 
                        ( BPy_World * ) PyObject_NEW( BPy_World, &World_Type );
900
 
        } else
901
 
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
902
 
                                                "couldn't create World Data in Blender" ) );
903
 
 
904
 
        if( pyworld == NULL )
905
 
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
906
 
                                                "couldn't create World Data object" ) );
907
 
 
908
 
        pyworld->world = blworld;
909
 
 
910
 
        return ( PyObject * ) pyworld;
911
 
}
912
 
 
913
 
 
914
 
/*@{*/
915
 
 
916
 
/**
917
 
 * \brief The World PyType destructor
918
 
 */
919
 
 
920
 
static void World_DeAlloc( BPy_World * self )
921
 
{
922
 
        PyObject_DEL( self );
923
 
}
924
 
 
925
 
/**
926
 
 * \brief The World PyType attribute getter
927
 
 *
928
 
 * This is the callback called when a user tries to retrieve the contents of
929
 
 * World PyObject data members.  Ex. in Python: "print myworld.lens".
930
 
 */
931
 
 
932
 
static PyObject *World_GetAttr( BPy_World * self, char *name )
933
 
{
934
 
 
935
 
        if( strcmp( name, "name" ) == 0 )
936
 
                return World_getName( self );
937
 
        if( strcmp( name, "skytype" ) == 0 )
938
 
                return World_getSkytype( self );
939
 
        if( strcmp( name, "mode" ) == 0 )
940
 
                return World_getMode( self );
941
 
        if( strcmp( name, "mistype" ) == 0 )
942
 
                return World_getMistype( self );
943
 
        if( strcmp( name, "hor" ) == 0 )
944
 
                return World_getHor( self );
945
 
        if( strcmp( name, "zen" ) == 0 )
946
 
                return World_getZen( self );
947
 
        if( strcmp( name, "amb" ) == 0 )
948
 
                return World_getAmb( self );
949
 
        if( strcmp( name, "star" ) == 0 )
950
 
                return World_getStar( self );
951
 
        if( strcmp( name, "mist" ) == 0 )
952
 
                return World_getMist( self );
953
 
        if( strcmp( name, "users" ) == 0 )
954
 
                return PyInt_FromLong( self->world->id.us );
955
 
        return Py_FindMethod( BPy_World_methods, ( PyObject * ) self, name );
956
 
}
957
 
 
958
 
/**
959
 
 * \brief The World PyType attribute setter
960
 
 *
961
 
 * This is the callback called when the user tries to change the value of some
962
 
 * World data member.  Ex. in Python: "myworld.lens = 45.0".
963
 
 */
964
 
 
965
 
static int World_SetAttr( BPy_World * self, char *name, PyObject * value )
966
 
{
967
 
        PyObject *error=NULL;
968
 
        PyObject *valtuple = Py_BuildValue( "(O)", value );
969
 
 
970
 
        if( !valtuple )
971
 
                return EXPP_ReturnIntError( PyExc_MemoryError,
972
 
                                            "WorldSetAttr: couldn't parse args" );
973
 
        else if( strcmp( name, "name" ) == 0 )
974
 
                error = World_setName( self, valtuple );
975
 
        else if( strcmp( name, "skytype" ) == 0 )
976
 
                error = World_setSkytype( self, valtuple );
977
 
        else if( strcmp( name, "mode" ) == 0 )
978
 
                error = World_setMode( self, valtuple );
979
 
        else if( strcmp( name, "mistype" ) == 0 )
980
 
                error = World_setMistype( self, valtuple );
981
 
        else if( strcmp( name, "hor" ) == 0 )
982
 
                error = World_setHor( self, valtuple );
983
 
        else if( strcmp( name, "zen" ) == 0 )
984
 
                error = World_setZen( self, valtuple );
985
 
        else if( strcmp( name, "amb" ) == 0 )
986
 
                error = World_setAmb( self, valtuple );
987
 
        else if( strcmp( name, "star" ) == 0 )
988
 
                error = World_setStar( self, valtuple );
989
 
        else if( strcmp( name, "mist" ) == 0 )
990
 
                error = World_setMist( self, valtuple );
991
 
        else {
992
 
                Py_DECREF( valtuple );
993
 
                return ( EXPP_ReturnIntError( PyExc_KeyError,
994
 
                                                  "attribute not found" ) );
995
 
        }
996
 
 
997
 
        Py_DECREF(valtuple);
998
 
 
999
 
        if( error != Py_None )
1000
 
                return -1;
1001
 
 
1002
 
        Py_DECREF( Py_None );
1003
 
        return 0;
 
917
        World *world = copy_world(self->world );
 
918
        world->id.us = 0;
 
919
        return World_CreatePyObject(world);
1004
920
}
1005
921
 
1006
922
/**
1066
982
        }
1067
983
        blen_object->world = world;
1068
984
        return ( ( PyObject * ) blen_object );
1069
 
 
1070
 
}
1071
 
 
1072
 
int World_CheckPyObject( PyObject * py_obj )
1073
 
{
1074
 
        return ( py_obj->ob_type == &World_Type );
1075
 
}
1076
 
 
 
985
}
1077
986
 
1078
987
World *World_FromPyObject( PyObject * py_obj )
1079
988
{
1084
993
 
1085
994
}
1086
995
 
1087
 
/*****************************************************************************/
1088
 
/* Description: Returns the object with the name specified by the argument   */
1089
 
/*              name. Note that the calling function has to remove the first */
1090
 
/*              two characters of the object name. These two characters      */
1091
 
/*              specify the type of the object (OB, ME, WO, ...)           */
1092
 
/*              The function will return NULL when no object with the given  */
1093
 
/*               name is found.                                         */
1094
 
/*****************************************************************************/
1095
 
World *GetWorldByName( char *name )
1096
 
{
1097
 
        World *world_iter;
1098
 
 
1099
 
        world_iter = G.main->world.first;
1100
 
        while( world_iter ) {
1101
 
                if( StringEqual( name, GetIdName( &( world_iter->id ) ) ) ) {
1102
 
                        return ( world_iter );
1103
 
                }
1104
 
                world_iter = world_iter->id.next;
1105
 
        }
1106
 
 
1107
 
        /* There is no object with the given name */
1108
 
        return ( NULL );
1109
 
}
1110
996
/*
1111
997
 * World_insertIpoKey()
1112
998
 *  inserts World IPO key for ZENITH,HORIZON,MIST,STARS,OFFSET,SIZE