~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: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
 
 *
 
2
 * $Id: Lamp.c,v 1.33 2005/06/10 12:33:09 stiv Exp $
3
3
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or
24
24
 *
25
25
 * This is a new part of Blender.
26
26
 *
27
 
 * Contributor(s): Willian P. Germano
 
27
 * Contributor(s): Willian P. Germano, Nathan Letwory, Stephen Swaney,
 
28
 * Ken Hughes
28
29
 *
29
30
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
30
31
*/
31
32
 
 
33
 
 
34
#include <stdio.h>
 
35
 
 
36
#include <BKE_main.h>
 
37
#include <BKE_global.h>
 
38
#include <BKE_object.h>
 
39
#include <BKE_library.h>
 
40
#include <BLI_blenlib.h>
 
41
#include <BIF_space.h>
 
42
#include <BSE_editipo.h>
 
43
#include <mydevice.h>
 
44
 
32
45
#include "Lamp.h"
 
46
#include "Ipo.h"
 
47
 
 
48
#include "constant.h"
 
49
#include "rgbTuple.h"
 
50
#include "gen_utils.h"
 
51
 
 
52
/*****************************************************************************/
 
53
/* Python BPy_Lamp defaults:                                                 */
 
54
/*****************************************************************************/
 
55
 
 
56
/* Lamp types */
 
57
 
 
58
/* NOTE:
 
59
 these are the same values as LA_* from DNA_lamp_types.h
 
60
 is there some reason we are not simply using those #defines?
 
61
 s. swaney 8-oct-2004
 
62
*/
 
63
 
 
64
#define EXPP_LAMP_TYPE_LAMP 0
 
65
#define EXPP_LAMP_TYPE_SUN  1
 
66
#define EXPP_LAMP_TYPE_SPOT 2
 
67
#define EXPP_LAMP_TYPE_HEMI 3
 
68
#define EXPP_LAMP_TYPE_AREA 4
 
69
#define EXPP_LAMP_TYPE_YF_PHOTON 5
 
70
/*
 
71
  define a constant to keep magic numbers out of the code
 
72
  this value should be equal to the last EXPP_LAMP_TYPE_*
 
73
*/
 
74
#define EXPP_LAMP_TYPE_MAX  5
 
75
 
 
76
/* Lamp mode flags */
 
77
 
 
78
#define EXPP_LAMP_MODE_SHADOWS       1
 
79
#define EXPP_LAMP_MODE_HALO          2
 
80
#define EXPP_LAMP_MODE_LAYER         4
 
81
#define EXPP_LAMP_MODE_QUAD          8
 
82
#define EXPP_LAMP_MODE_NEGATIVE     16
 
83
#define EXPP_LAMP_MODE_ONLYSHADOW   32
 
84
#define EXPP_LAMP_MODE_SPHERE       64
 
85
#define EXPP_LAMP_MODE_SQUARE      128
 
86
#define EXPP_LAMP_MODE_TEXTURE     256
 
87
#define EXPP_LAMP_MODE_OSATEX      512
 
88
#define EXPP_LAMP_MODE_DEEPSHADOW 1024
 
89
#define EXPP_LAMP_MODE_NODIFFUSE  2048
 
90
#define EXPP_LAMP_MODE_NOSPECULAR 4096
 
91
/* Lamp MIN, MAX values */
 
92
 
 
93
#define EXPP_LAMP_SAMPLES_MIN 1
 
94
#define EXPP_LAMP_SAMPLES_MAX 16
 
95
#define EXPP_LAMP_BUFFERSIZE_MIN 512
 
96
#define EXPP_LAMP_BUFFERSIZE_MAX 5120
 
97
#define EXPP_LAMP_ENERGY_MIN  0.0
 
98
#define EXPP_LAMP_ENERGY_MAX 10.0
 
99
#define EXPP_LAMP_DIST_MIN    0.1
 
100
#define EXPP_LAMP_DIST_MAX 5000.0
 
101
#define EXPP_LAMP_SPOTSIZE_MIN   1.0
 
102
#define EXPP_LAMP_SPOTSIZE_MAX 180.0
 
103
#define EXPP_LAMP_SPOTBLEND_MIN 0.00
 
104
#define EXPP_LAMP_SPOTBLEND_MAX 1.00
 
105
#define EXPP_LAMP_CLIPSTART_MIN    0.1
 
106
#define EXPP_LAMP_CLIPSTART_MAX 1000.0
 
107
#define EXPP_LAMP_CLIPEND_MIN    1.0
 
108
#define EXPP_LAMP_CLIPEND_MAX 5000.0
 
109
#define EXPP_LAMP_BIAS_MIN 0.01
 
110
#define EXPP_LAMP_BIAS_MAX 5.00
 
111
#define EXPP_LAMP_SOFTNESS_MIN   1.0
 
112
#define EXPP_LAMP_SOFTNESS_MAX 100.0
 
113
#define EXPP_LAMP_HALOINT_MIN 0.0
 
114
#define EXPP_LAMP_HALOINT_MAX 5.0
 
115
#define EXPP_LAMP_HALOSTEP_MIN  0
 
116
#define EXPP_LAMP_HALOSTEP_MAX 12
 
117
#define EXPP_LAMP_QUAD1_MIN 0.0
 
118
#define EXPP_LAMP_QUAD1_MAX 1.0
 
119
#define EXPP_LAMP_QUAD2_MIN 0.0
 
120
#define EXPP_LAMP_QUAD2_MAX 1.0
 
121
#define EXPP_LAMP_COL_MIN 0.0
 
122
#define EXPP_LAMP_COL_MAX 1.0
 
123
 
 
124
#define IPOKEY_RGB       0
 
125
#define IPOKEY_ENERGY    1
 
126
#define IPOKEY_SPOTSIZE  2
 
127
#define IPOKEY_OFFSET    3
 
128
#define IPOKEY_SIZE      4
 
129
 
 
130
/*****************************************************************************/
 
131
/* Python API function prototypes for the Lamp module.                       */
 
132
/*****************************************************************************/
 
133
static PyObject *M_Lamp_New( PyObject * self, PyObject * args,
 
134
                             PyObject * keywords );
 
135
static PyObject *M_Lamp_Get( PyObject * self, PyObject * args );
 
136
 
 
137
/*****************************************************************************/
 
138
/* The following string definitions are used for documentation strings.      */
 
139
/* In Python these will be written to the console when doing a               */
 
140
/* Blender.Lamp.__doc__                                                      */
 
141
/*****************************************************************************/
 
142
static char M_Lamp_doc[] = "The Blender Lamp module\n\n\
 
143
This module provides control over **Lamp Data** objects in Blender.\n\n\
 
144
Example::\n\n\
 
145
  from Blender import Lamp\n\
 
146
  l = Lamp.New('Spot')            # create new 'Spot' lamp data\n\
 
147
  l.setMode('square', 'shadow')   # set these two lamp mode flags\n\
 
148
  ob = Object.New('Lamp')         # create new lamp object\n\
 
149
  ob.link(l)                      # link lamp obj with lamp data\n";
 
150
 
 
151
static char M_Lamp_New_doc[] = "Lamp.New (type = 'Lamp', name = 'LampData'):\n\
 
152
        Return a new Lamp Data object with the given type and name.";
 
153
 
 
154
static char M_Lamp_Get_doc[] = "Lamp.Get (name = None):\n\
 
155
        Return the Lamp Data with the given name, None if not found, or\n\
 
156
        Return a list with all Lamp Data objects in the current scene,\n\
 
157
        if no argument was given.";
 
158
 
 
159
/*****************************************************************************/
 
160
/* Python method structure definition for Blender.Lamp module:               */
 
161
/*****************************************************************************/
 
162
struct PyMethodDef M_Lamp_methods[] = {
 
163
        {"New", ( PyCFunction ) M_Lamp_New, METH_VARARGS | METH_KEYWORDS,
 
164
         M_Lamp_New_doc},
 
165
        {"Get", M_Lamp_Get, METH_VARARGS, M_Lamp_Get_doc},
 
166
        {"get", M_Lamp_Get, METH_VARARGS, M_Lamp_Get_doc},
 
167
        {NULL, NULL, 0, NULL}
 
168
};
 
169
 
 
170
/*****************************************************************************/
 
171
/* Python BPy_Lamp methods declarations:                                     */
 
172
/*****************************************************************************/
 
173
static PyObject *Lamp_getName( BPy_Lamp * self );
 
174
static PyObject *Lamp_getType( BPy_Lamp * self );
 
175
static PyObject *Lamp_getMode( BPy_Lamp * self );
 
176
static PyObject *Lamp_getSamples( BPy_Lamp * self );
 
177
static PyObject *Lamp_getBufferSize( BPy_Lamp * self );
 
178
static PyObject *Lamp_getHaloStep( BPy_Lamp * self );
 
179
static PyObject *Lamp_getEnergy( BPy_Lamp * self );
 
180
static PyObject *Lamp_getDist( BPy_Lamp * self );
 
181
static PyObject *Lamp_getSpotSize( BPy_Lamp * self );
 
182
static PyObject *Lamp_getSpotBlend( BPy_Lamp * self );
 
183
static PyObject *Lamp_getClipStart( BPy_Lamp * self );
 
184
static PyObject *Lamp_getClipEnd( BPy_Lamp * self );
 
185
static PyObject *Lamp_getBias( BPy_Lamp * self );
 
186
static PyObject *Lamp_getSoftness( BPy_Lamp * self );
 
187
static PyObject *Lamp_getHaloInt( BPy_Lamp * self );
 
188
static PyObject *Lamp_getQuad1( BPy_Lamp * self );
 
189
static PyObject *Lamp_getQuad2( BPy_Lamp * self );
 
190
static PyObject *Lamp_getCol( BPy_Lamp * self );
 
191
static PyObject *Lamp_getIpo( BPy_Lamp * self );
 
192
static PyObject *Lamp_clearIpo( BPy_Lamp * self );
 
193
static PyObject *Lamp_setIpo( BPy_Lamp * self, PyObject * args );
 
194
static PyObject *Lamp_insertIpoKey( BPy_Lamp * self, PyObject * args );
 
195
static PyObject *Lamp_setName( BPy_Lamp * self, PyObject * args );
 
196
static PyObject *Lamp_setType( BPy_Lamp * self, PyObject * args );
 
197
static PyObject *Lamp_setIntType( BPy_Lamp * self, PyObject * args );
 
198
static PyObject *Lamp_setMode( BPy_Lamp * self, PyObject * args );
 
199
static PyObject *Lamp_setIntMode( BPy_Lamp * self, PyObject * args );
 
200
static PyObject *Lamp_setSamples( BPy_Lamp * self, PyObject * args );
 
201
static PyObject *Lamp_setBufferSize( BPy_Lamp * self, PyObject * args );
 
202
static PyObject *Lamp_setHaloStep( BPy_Lamp * self, PyObject * args );
 
203
static PyObject *Lamp_setEnergy( BPy_Lamp * self, PyObject * args );
 
204
static PyObject *Lamp_setDist( BPy_Lamp * self, PyObject * args );
 
205
static PyObject *Lamp_setSpotSize( BPy_Lamp * self, PyObject * args );
 
206
static PyObject *Lamp_setSpotBlend( BPy_Lamp * self, PyObject * args );
 
207
static PyObject *Lamp_setClipStart( BPy_Lamp * self, PyObject * args );
 
208
static PyObject *Lamp_setClipEnd( BPy_Lamp * self, PyObject * args );
 
209
static PyObject *Lamp_setBias( BPy_Lamp * self, PyObject * args );
 
210
static PyObject *Lamp_setSoftness( BPy_Lamp * self, PyObject * args );
 
211
static PyObject *Lamp_setHaloInt( BPy_Lamp * self, PyObject * args );
 
212
static PyObject *Lamp_setQuad1( BPy_Lamp * self, PyObject * args );
 
213
static PyObject *Lamp_setQuad2( BPy_Lamp * self, PyObject * args );
 
214
static PyObject *Lamp_setCol( BPy_Lamp * self, PyObject * args );
 
215
static PyObject *Lamp_setColorComponent( BPy_Lamp * self, char *key,
 
216
                                         PyObject * args );
 
217
static PyObject *Lamp_getScriptLinks( BPy_Lamp * self, PyObject * args );
 
218
static PyObject *Lamp_addScriptLink( BPy_Lamp * self, PyObject * args );
 
219
static PyObject *Lamp_clearScriptLinks( BPy_Lamp * self, PyObject * args );
 
220
 
 
221
/*****************************************************************************/
 
222
/* Python BPy_Lamp methods table:                                            */
 
223
/*****************************************************************************/
 
224
static PyMethodDef BPy_Lamp_methods[] = {
 
225
        /* name, method, flags, doc */
 
226
        {"getName", ( PyCFunction ) Lamp_getName, METH_NOARGS,
 
227
         "() - return Lamp name"},
 
228
        {"getType", ( PyCFunction ) Lamp_getType, METH_NOARGS,
 
229
         "() - return Lamp type - 'Lamp':0, 'Sun':1, 'Spot':2, 'Hemi':3, 'Area':4, 'Photon':5"},
 
230
        {"getMode", ( PyCFunction ) Lamp_getMode, METH_NOARGS,
 
231
         "() - return Lamp mode flags (or'ed value)"},
 
232
        {"getSamples", ( PyCFunction ) Lamp_getSamples, METH_NOARGS,
 
233
         "() - return Lamp samples value"},
 
234
        {"getBufferSize", ( PyCFunction ) Lamp_getBufferSize, METH_NOARGS,
 
235
         "() - return Lamp buffer size value"},
 
236
        {"getHaloStep", ( PyCFunction ) Lamp_getHaloStep, METH_NOARGS,
 
237
         "() - return Lamp halo step value"},
 
238
        {"getEnergy", ( PyCFunction ) Lamp_getEnergy, METH_NOARGS,
 
239
         "() - return Lamp energy value"},
 
240
        {"getDist", ( PyCFunction ) Lamp_getDist, METH_NOARGS,
 
241
         "() - return Lamp clipping distance value"},
 
242
        {"getSpotSize", ( PyCFunction ) Lamp_getSpotSize, METH_NOARGS,
 
243
         "() - return Lamp spot size value"},
 
244
        {"getSpotBlend", ( PyCFunction ) Lamp_getSpotBlend, METH_NOARGS,
 
245
         "() - return Lamp spot blend value"},
 
246
        {"getClipStart", ( PyCFunction ) Lamp_getClipStart, METH_NOARGS,
 
247
         "() - return Lamp clip start value"},
 
248
        {"getClipEnd", ( PyCFunction ) Lamp_getClipEnd, METH_NOARGS,
 
249
         "() - return Lamp clip end value"},
 
250
        {"getBias", ( PyCFunction ) Lamp_getBias, METH_NOARGS,
 
251
         "() - return Lamp bias value"},
 
252
        {"getSoftness", ( PyCFunction ) Lamp_getSoftness, METH_NOARGS,
 
253
         "() - return Lamp softness value"},
 
254
        {"getHaloInt", ( PyCFunction ) Lamp_getHaloInt, METH_NOARGS,
 
255
         "() - return Lamp halo intensity value"},
 
256
        {"getQuad1", ( PyCFunction ) Lamp_getQuad1, METH_NOARGS,
 
257
         "() - return light intensity value #1 for a Quad Lamp"},
 
258
        {"getQuad2", ( PyCFunction ) Lamp_getQuad2, METH_NOARGS,
 
259
         "() - return light intensity value #2 for a Quad Lamp"},
 
260
        {"getCol", ( PyCFunction ) Lamp_getCol, METH_NOARGS,
 
261
         "() - return light rgb color triplet"},
 
262
        {"setName", ( PyCFunction ) Lamp_setName, METH_VARARGS,
 
263
         "(str) - rename Lamp"},
 
264
        {"setType", ( PyCFunction ) Lamp_setType, METH_VARARGS,
 
265
         "(str) - change Lamp type, which can be 'Lamp', 'Sun', 'Spot', 'Hemi', 'Area', 'Photon'"},
 
266
        {"setMode", ( PyCFunction ) Lamp_setMode, METH_VARARGS,
 
267
         "([up to eight str's]) - Set Lamp mode flag(s)"},
 
268
        {"setSamples", ( PyCFunction ) Lamp_setSamples, METH_VARARGS,
 
269
         "(int) - change Lamp samples value"},
 
270
        {"setBufferSize", ( PyCFunction ) Lamp_setBufferSize, METH_VARARGS,
 
271
         "(int) - change Lamp buffer size value"},
 
272
        {"setHaloStep", ( PyCFunction ) Lamp_setHaloStep, METH_VARARGS,
 
273
         "(int) - change Lamp halo step value"},
 
274
        {"setEnergy", ( PyCFunction ) Lamp_setEnergy, METH_VARARGS,
 
275
         "(float) - change Lamp energy value"},
 
276
        {"setDist", ( PyCFunction ) Lamp_setDist, METH_VARARGS,
 
277
         "(float) - change Lamp clipping distance value"},
 
278
        {"setSpotSize", ( PyCFunction ) Lamp_setSpotSize, METH_VARARGS,
 
279
         "(float) - change Lamp spot size value"},
 
280
        {"setSpotBlend", ( PyCFunction ) Lamp_setSpotBlend, METH_VARARGS,
 
281
         "(float) - change Lamp spot blend value"},
 
282
        {"setClipStart", ( PyCFunction ) Lamp_setClipStart, METH_VARARGS,
 
283
         "(float) - change Lamp clip start value"},
 
284
        {"setClipEnd", ( PyCFunction ) Lamp_setClipEnd, METH_VARARGS,
 
285
         "(float) - change Lamp clip end value"},
 
286
        {"setBias", ( PyCFunction ) Lamp_setBias, METH_VARARGS,
 
287
         "(float) - change Lamp draw size value"},
 
288
        {"setSoftness", ( PyCFunction ) Lamp_setSoftness, METH_VARARGS,
 
289
         "(float) - change Lamp softness value"},
 
290
        {"setHaloInt", ( PyCFunction ) Lamp_setHaloInt, METH_VARARGS,
 
291
         "(float) - change Lamp halo intensity value"},
 
292
        {"setQuad1", ( PyCFunction ) Lamp_setQuad1, METH_VARARGS,
 
293
         "(float) - change light intensity value #1 for a Quad Lamp"},
 
294
        {"setQuad2", ( PyCFunction ) Lamp_setQuad2, METH_VARARGS,
 
295
         "(float) - change light intensity value #2 for a Quad Lamp"},
 
296
        {"setCol", ( PyCFunction ) Lamp_setCol, METH_VARARGS,
 
297
         "(f,f,f) or ([f,f,f]) - change light's rgb color triplet"},
 
298
        {"getScriptLinks", ( PyCFunction ) Lamp_getScriptLinks, METH_VARARGS,
 
299
         "(eventname) - Get a list of this lamp's scriptlinks (Text names) "
 
300
         "of the given type\n"
 
301
         "(eventname) - string: FrameChanged, Redraw or Render."},
 
302
        {"addScriptLink", ( PyCFunction ) Lamp_addScriptLink, METH_VARARGS,
 
303
         "(text, evt) - Add a new lamp scriptlink.\n"
 
304
         "(text) - string: an existing Blender Text name;\n"
 
305
         "(evt) string: FrameChanged, Redraw or Render."},
 
306
        {"clearScriptLinks", ( PyCFunction ) Lamp_clearScriptLinks,
 
307
         METH_VARARGS,
 
308
         "() - Delete all scriptlinks from this lamp.\n"
 
309
         "([s1<,s2,s3...>]) - Delete specified scriptlinks from this lamp."},
 
310
        {"getIpo", ( PyCFunction ) Lamp_getIpo, METH_NOARGS,
 
311
         "() - get IPO for this lamp"},
 
312
        {"clearIpo", ( PyCFunction ) Lamp_clearIpo, METH_NOARGS,
 
313
         "() - unlink the IPO for this lamp"},
 
314
        {"setIpo", ( PyCFunction ) Lamp_setIpo, METH_VARARGS,
 
315
         "( lamp-ipo ) - link an IPO to this lamp"},
 
316
         {"insertIpoKey", ( PyCFunction ) Lamp_insertIpoKey, METH_VARARGS,
 
317
         "( Lamp IPO type ) - Inserts a key into IPO"},
 
318
 
 
319
        {NULL, NULL, 0, NULL}
 
320
};
 
321
 
 
322
/*****************************************************************************/
 
323
/* Python TypeLamp callback function prototypes:                             */
 
324
/*****************************************************************************/
 
325
static void Lamp_dealloc( BPy_Lamp * lamp );
 
326
static PyObject *Lamp_getAttr( BPy_Lamp * lamp, char *name );
 
327
static int Lamp_setAttr( BPy_Lamp * lamp, char *name, PyObject * v );
 
328
static int Lamp_compare( BPy_Lamp * a, BPy_Lamp * b );
 
329
static PyObject *Lamp_repr( BPy_Lamp * lamp );
 
330
 
33
331
 
34
332
/*****************************************************************************/
35
333
/* Python TypeLamp structure definition:                                     */
36
334
/*****************************************************************************/
37
 
PyTypeObject Lamp_Type =
38
 
{
39
 
  PyObject_HEAD_INIT(NULL)
40
 
  0,                                    /* ob_size */
41
 
  "Blender Lamp",                       /* tp_name */
42
 
  sizeof (BPy_Lamp),                    /* tp_basicsize */
43
 
  0,                                    /* tp_itemsize */
44
 
  /* methods */
45
 
  (destructor)Lamp_dealloc,             /* tp_dealloc */
46
 
  0,                                    /* tp_print */
47
 
  (getattrfunc)Lamp_getAttr,            /* tp_getattr */
48
 
  (setattrfunc)Lamp_setAttr,            /* tp_setattr */
49
 
  (cmpfunc)Lamp_compare,                /* tp_compare */
50
 
  (reprfunc)Lamp_repr,                  /* tp_repr */
51
 
  0,                                    /* tp_as_number */
52
 
  0,                                    /* tp_as_sequence */
53
 
  0,                                    /* tp_as_mapping */
54
 
  0,                                    /* tp_as_hash */
55
 
  0,0,0,0,0,0,
56
 
  0,                                    /* tp_doc */ 
57
 
  0,0,0,0,0,0,
58
 
  BPy_Lamp_methods,                     /* tp_methods */
59
 
  0,                                    /* tp_members */
 
335
PyTypeObject Lamp_Type = {
 
336
        PyObject_HEAD_INIT( NULL ) 
 
337
        0,      /* ob_size */
 
338
        "Blender Lamp",         /* tp_name */
 
339
        sizeof( BPy_Lamp ),     /* tp_basicsize */
 
340
        0,                      /* tp_itemsize */
 
341
        /* methods */
 
342
        ( destructor ) Lamp_dealloc,    /* tp_dealloc */
 
343
        0,                      /* tp_print */
 
344
        ( getattrfunc ) Lamp_getAttr,   /* tp_getattr */
 
345
        ( setattrfunc ) Lamp_setAttr,   /* tp_setattr */
 
346
        ( cmpfunc ) Lamp_compare,       /* tp_compare */
 
347
        ( reprfunc ) Lamp_repr, /* tp_repr */
 
348
        0,                      /* tp_as_number */
 
349
        0,                      /* tp_as_sequence */
 
350
        0,                      /* tp_as_mapping */
 
351
        0,                      /* tp_as_hash */
 
352
        0, 0, 0, 0, 0, 0,
 
353
        0,                      /* tp_doc */
 
354
        0, 0, 0, 0, 0, 0,
 
355
        BPy_Lamp_methods,       /* tp_methods */
 
356
        0,                      /* tp_members */
 
357
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
60
358
};
61
359
 
62
360
/*****************************************************************************/
63
361
/* Function:              M_Lamp_New                                         */
64
362
/* Python equivalent:     Blender.Lamp.New                                   */
65
363
/*****************************************************************************/
66
 
static PyObject *M_Lamp_New(PyObject *self, PyObject *args, PyObject *keywords)
 
364
static PyObject *M_Lamp_New( PyObject * self, PyObject * args,
 
365
                             PyObject * keywords )
67
366
{
68
 
  char        *type_str = "Lamp";
69
 
  char        *name_str = "LampData";
70
 
  static char *kwlist[] = {"type_str", "name_str", NULL};
71
 
  BPy_Lamp    *py_lamp; /* for Lamp Data object wrapper in Python */
72
 
  Lamp        *bl_lamp; /* for actual Lamp Data we create in Blender */
73
 
  char        buf[21];
74
 
 
75
 
  if (!PyArg_ParseTupleAndKeywords(args, keywords, "|ss", kwlist,
76
 
                          &type_str, &name_str))
77
 
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
78
 
            "expected string(s) or empty argument"));
79
 
 
80
 
  bl_lamp = add_lamp(); /* first create in Blender */
81
 
  if (bl_lamp) /* now create the wrapper obj in Python */
82
 
    py_lamp = (BPy_Lamp *)Lamp_CreatePyObject(bl_lamp);
83
 
  else
84
 
    return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
85
 
                            "couldn't create Lamp Data in Blender"));
 
367
        char *type_str = "Lamp";
 
368
        char *name_str = "LampData";
 
369
        static char *kwlist[] = { "type_str", "name_str", NULL };
 
370
        BPy_Lamp *py_lamp;      /* for Lamp Data object wrapper in Python */
 
371
        Lamp *bl_lamp;          /* for actual Lamp Data we create in Blender */
 
372
        char buf[21];
 
373
 
 
374
        if( !PyArg_ParseTupleAndKeywords( args, keywords, "|ss", kwlist,
 
375
                                          &type_str, &name_str ) )
 
376
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
377
                                                "expected string(s) or empty argument" ) );
 
378
 
 
379
        bl_lamp = add_lamp(  ); /* first create in Blender */
 
380
        if( bl_lamp )           /* now create the wrapper obj in Python */
 
381
                py_lamp = ( BPy_Lamp * ) Lamp_CreatePyObject( bl_lamp );
 
382
        else
 
383
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
384
                                                "couldn't create Lamp Data in Blender" ) );
86
385
 
87
386
        /* let's return user count to zero, because ... */
88
 
        bl_lamp->id.us = 0; /* ... add_lamp() incref'ed it */
89
 
 
90
 
  if (py_lamp == NULL)
91
 
    return (EXPP_ReturnPyObjError (PyExc_MemoryError,
92
 
                            "couldn't create Lamp Data object"));
93
 
 
94
 
  if (strcmp (type_str, "Lamp") == 0)
95
 
    bl_lamp->type = (short)EXPP_LAMP_TYPE_LAMP;
96
 
  else if (strcmp (type_str, "Sun") == 0)
97
 
    bl_lamp->type = (short)EXPP_LAMP_TYPE_SUN;
98
 
  else if (strcmp (type_str, "Spot") == 0)
99
 
    bl_lamp->type = (short)EXPP_LAMP_TYPE_SPOT;
100
 
  else if (strcmp (type_str, "Hemi") == 0)
101
 
    bl_lamp->type = (short)EXPP_LAMP_TYPE_HEMI;
102
 
  else
103
 
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
104
 
            "unknown lamp type"));
105
 
 
106
 
  if (strcmp(name_str, "LampData") == 0)
107
 
    return (PyObject *)py_lamp;
108
 
  else { /* user gave us a name for the lamp, use it */
109
 
    PyOS_snprintf(buf, sizeof(buf), "%s", name_str);
110
 
    rename_id(&bl_lamp->id, buf);
111
 
  }
112
 
 
113
 
  return (PyObject *)py_lamp;
 
387
        bl_lamp->id.us = 0;     /* ... add_lamp() incref'ed it */
 
388
 
 
389
        if( py_lamp == NULL )
 
390
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 
391
                                                "couldn't create Lamp Data object" ) );
 
392
 
 
393
        if( strcmp( type_str, "Lamp" ) == 0 )
 
394
                bl_lamp->type = ( short ) EXPP_LAMP_TYPE_LAMP;
 
395
        else if( strcmp( type_str, "Sun" ) == 0 )
 
396
                bl_lamp->type = ( short ) EXPP_LAMP_TYPE_SUN;
 
397
        else if( strcmp( type_str, "Spot" ) == 0 )
 
398
                bl_lamp->type = ( short ) EXPP_LAMP_TYPE_SPOT;
 
399
        else if( strcmp( type_str, "Hemi" ) == 0 )
 
400
                bl_lamp->type = ( short ) EXPP_LAMP_TYPE_HEMI;
 
401
        else if( strcmp( type_str, "Area" ) == 0 )
 
402
                bl_lamp->type = ( short ) EXPP_LAMP_TYPE_AREA;
 
403
        else if( strcmp( type_str, "Photon" ) == 0 )
 
404
                bl_lamp->type = ( short ) EXPP_LAMP_TYPE_YF_PHOTON;
 
405
        else
 
406
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
407
                                                "unknown lamp type" ) );
 
408
 
 
409
        if( strcmp( name_str, "LampData" ) == 0 )
 
410
                return ( PyObject * ) py_lamp;
 
411
        else {                  /* user gave us a name for the lamp, use it */
 
412
                PyOS_snprintf( buf, sizeof( buf ), "%s", name_str );
 
413
                rename_id( &bl_lamp->id, buf );
 
414
        }
 
415
 
 
416
        return ( PyObject * ) py_lamp;
114
417
}
115
418
 
116
419
/*****************************************************************************/
121
424
/*                        passed in, a list of all lamp data names in the    */
122
425
/*                        current scene is returned.                         */
123
426
/*****************************************************************************/
124
 
static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
 
427
static PyObject *M_Lamp_Get( PyObject * self, PyObject * args )
125
428
{
126
 
  char *name = NULL;
127
 
  Lamp *lamp_iter;
128
 
 
129
 
  if (!PyArg_ParseTuple(args, "|s", &name))
130
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
131
 
            "expected string argument (or nothing)"));
132
 
 
133
 
  lamp_iter = G.main->lamp.first;
134
 
 
135
 
  if (name) { /* (name) - Search lamp by name */
136
 
 
137
 
    BPy_Lamp *wanted_lamp = NULL;
138
 
 
139
 
    while ((lamp_iter) && (wanted_lamp == NULL)) {
140
 
 
141
 
      if (strcmp (name, lamp_iter->id.name+2) == 0)
142
 
        wanted_lamp = (BPy_Lamp *)Lamp_CreatePyObject(lamp_iter);
143
 
 
144
 
      lamp_iter = lamp_iter->id.next;
145
 
    }
146
 
 
147
 
    if (wanted_lamp == NULL) { /* Requested lamp doesn't exist */
148
 
      char error_msg[64];
149
 
      PyOS_snprintf(error_msg, sizeof(error_msg),
150
 
                      "Lamp \"%s\" not found", name);
151
 
      return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
152
 
    }
153
 
 
154
 
    return (PyObject *)wanted_lamp;
155
 
  }
156
 
 
157
 
  else { /* () - return a list of all lamps in the scene */
158
 
    int index = 0;
159
 
    PyObject *lamplist, *pyobj;
160
 
 
161
 
    lamplist = PyList_New (BLI_countlist (&(G.main->lamp)));
162
 
 
163
 
    if (lamplist == NULL)
164
 
      return (PythonReturnErrorObject (PyExc_MemoryError,
165
 
              "couldn't create PyList"));
166
 
 
167
 
    while (lamp_iter) {
168
 
      pyobj = Lamp_CreatePyObject (lamp_iter);
169
 
 
170
 
      if (!pyobj)
171
 
        return (PythonReturnErrorObject (PyExc_MemoryError,
172
 
                  "couldn't create PyString"));
173
 
 
174
 
      PyList_SET_ITEM (lamplist, index, pyobj);
175
 
 
176
 
      lamp_iter = lamp_iter->id.next;
177
 
      index++;
178
 
    }
179
 
 
180
 
    return lamplist;
181
 
  }
182
 
}
183
 
 
184
 
static PyObject *Lamp_TypesDict (void)
185
 
{ /* create the Blender.Lamp.Types constant dict */
186
 
  PyObject *Types = M_constant_New();
187
 
 
188
 
  if (Types) {
189
 
    BPy_constant *c = (BPy_constant *)Types;
190
 
 
191
 
    constant_insert (c, "Lamp", PyInt_FromLong (EXPP_LAMP_TYPE_LAMP));
192
 
    constant_insert (c, "Sun",  PyInt_FromLong (EXPP_LAMP_TYPE_SUN));
193
 
    constant_insert (c, "Spot", PyInt_FromLong (EXPP_LAMP_TYPE_SPOT));
194
 
    constant_insert (c, "Hemi", PyInt_FromLong (EXPP_LAMP_TYPE_HEMI));
195
 
 
196
 
  }
197
 
 
198
 
  return Types;
199
 
}
200
 
 
201
 
static PyObject *Lamp_ModesDict (void)
202
 
{ /* create the Blender.Lamp.Modes constant dict */
203
 
  PyObject *Modes = M_constant_New();
204
 
 
205
 
  if (Modes) {
206
 
    BPy_constant *c = (BPy_constant *)Modes;
207
 
 
208
 
    constant_insert (c, "Shadows", PyInt_FromLong (EXPP_LAMP_MODE_SHADOWS));
209
 
    constant_insert (c, "Halo", PyInt_FromLong (EXPP_LAMP_MODE_HALO));
210
 
    constant_insert (c, "Layer", PyInt_FromLong (EXPP_LAMP_MODE_LAYER));
211
 
    constant_insert (c, "Quad", PyInt_FromLong (EXPP_LAMP_MODE_QUAD));
212
 
    constant_insert (c, "Negative", PyInt_FromLong (EXPP_LAMP_MODE_NEGATIVE));
213
 
    constant_insert (c, "Sphere", PyInt_FromLong (EXPP_LAMP_MODE_SPHERE));
214
 
    constant_insert (c, "Square", PyInt_FromLong (EXPP_LAMP_MODE_SQUARE));
215
 
    constant_insert (c, "OnlyShadow",
216
 
                    PyInt_FromLong (EXPP_LAMP_MODE_ONLYSHADOW));
217
 
    constant_insert (c, "NoDiffuse",
218
 
                    PyInt_FromLong (EXPP_LAMP_MODE_NODIFFUSE));
219
 
    constant_insert (c, "NoSpecular",
220
 
                    PyInt_FromLong (EXPP_LAMP_MODE_NOSPECULAR));
221
 
  }
222
 
 
223
 
  return Modes;
 
429
        char *name = NULL;
 
430
        Lamp *lamp_iter;
 
431
 
 
432
        if( !PyArg_ParseTuple( args, "|s", &name ) )
 
433
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
434
                                                "expected string argument (or nothing)" ) );
 
435
 
 
436
        lamp_iter = G.main->lamp.first;
 
437
 
 
438
        if( name ) {            /* (name) - Search lamp by name */
 
439
 
 
440
                BPy_Lamp *wanted_lamp = NULL;
 
441
 
 
442
                while( ( lamp_iter ) && ( wanted_lamp == NULL ) ) {
 
443
 
 
444
                        if( strcmp( name, lamp_iter->id.name + 2 ) == 0 )
 
445
                                wanted_lamp =
 
446
                                        ( BPy_Lamp * )
 
447
                                        Lamp_CreatePyObject( lamp_iter );
 
448
 
 
449
                        lamp_iter = lamp_iter->id.next;
 
450
                }
 
451
 
 
452
                if( wanted_lamp == NULL ) { /* Requested lamp doesn't exist */
 
453
                        char error_msg[64];
 
454
                        PyOS_snprintf( error_msg, sizeof( error_msg ),
 
455
                                       "Lamp \"%s\" not found", name );
 
456
                        return ( EXPP_ReturnPyObjError
 
457
                                 ( PyExc_NameError, error_msg ) );
 
458
                }
 
459
 
 
460
                return ( PyObject * ) wanted_lamp;
 
461
        }
 
462
 
 
463
        else {          /* () - return a list of all lamps in the scene */
 
464
                int index = 0;
 
465
                PyObject *lamplist, *pyobj;
 
466
 
 
467
                lamplist = PyList_New( BLI_countlist( &( G.main->lamp ) ) );
 
468
 
 
469
                if( lamplist == NULL )
 
470
                        return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 
471
                                                        "couldn't create PyList" ) );
 
472
 
 
473
                while( lamp_iter ) {
 
474
                        pyobj = Lamp_CreatePyObject( lamp_iter );
 
475
 
 
476
                        if( !pyobj )
 
477
                                return ( EXPP_ReturnPyObjError
 
478
                                         ( PyExc_MemoryError,
 
479
                                           "couldn't create PyString" ) );
 
480
 
 
481
                        PyList_SET_ITEM( lamplist, index, pyobj );
 
482
 
 
483
                        lamp_iter = lamp_iter->id.next;
 
484
                        index++;
 
485
                }
 
486
 
 
487
                return lamplist;
 
488
        }
 
489
}
 
490
 
 
491
static PyObject *Lamp_TypesDict( void )
 
492
{       /* create the Blender.Lamp.Types constant dict */
 
493
        PyObject *Types = M_constant_New(  );
 
494
 
 
495
        if( Types ) {
 
496
                BPy_constant *c = ( BPy_constant * ) Types;
 
497
 
 
498
                constant_insert( c, "Lamp",
 
499
                                 PyInt_FromLong( EXPP_LAMP_TYPE_LAMP ) );
 
500
                constant_insert( c, "Sun",
 
501
                                 PyInt_FromLong( EXPP_LAMP_TYPE_SUN ) );
 
502
                constant_insert( c, "Spot",
 
503
                                 PyInt_FromLong( EXPP_LAMP_TYPE_SPOT ) );
 
504
                constant_insert( c, "Hemi",
 
505
                                 PyInt_FromLong( EXPP_LAMP_TYPE_HEMI ) );
 
506
                constant_insert( c, "Area",
 
507
                                 PyInt_FromLong( EXPP_LAMP_TYPE_AREA ) );
 
508
                constant_insert( c, "Photon",
 
509
                                 PyInt_FromLong( EXPP_LAMP_TYPE_YF_PHOTON ) );
 
510
        }
 
511
 
 
512
        return Types;
 
513
}
 
514
 
 
515
static PyObject *Lamp_ModesDict( void )
 
516
{                       /* create the Blender.Lamp.Modes constant dict */
 
517
        PyObject *Modes = M_constant_New(  );
 
518
 
 
519
        if( Modes ) {
 
520
                BPy_constant *c = ( BPy_constant * ) Modes;
 
521
 
 
522
                constant_insert( c, "Shadows",
 
523
                                 PyInt_FromLong( EXPP_LAMP_MODE_SHADOWS ) );
 
524
                constant_insert( c, "Halo",
 
525
                                 PyInt_FromLong( EXPP_LAMP_MODE_HALO ) );
 
526
                constant_insert( c, "Layer",
 
527
                                 PyInt_FromLong( EXPP_LAMP_MODE_LAYER ) );
 
528
                constant_insert( c, "Quad",
 
529
                                 PyInt_FromLong( EXPP_LAMP_MODE_QUAD ) );
 
530
                constant_insert( c, "Negative",
 
531
                                 PyInt_FromLong( EXPP_LAMP_MODE_NEGATIVE ) );
 
532
                constant_insert( c, "Sphere",
 
533
                                 PyInt_FromLong( EXPP_LAMP_MODE_SPHERE ) );
 
534
                constant_insert( c, "Square",
 
535
                                 PyInt_FromLong( EXPP_LAMP_MODE_SQUARE ) );
 
536
                constant_insert( c, "OnlyShadow",
 
537
                                 PyInt_FromLong( EXPP_LAMP_MODE_ONLYSHADOW ) );
 
538
                constant_insert( c, "NoDiffuse",
 
539
                                 PyInt_FromLong( EXPP_LAMP_MODE_NODIFFUSE ) );
 
540
                constant_insert( c, "NoSpecular",
 
541
                                 PyInt_FromLong( EXPP_LAMP_MODE_NOSPECULAR ) );
 
542
        }
 
543
 
 
544
        return Modes;
224
545
}
225
546
 
226
547
/*****************************************************************************/
227
548
/* Function:              Lamp_Init                                          */
228
549
/*****************************************************************************/
229
550
/* Needed by the Blender module, to register the Blender.Lamp submodule */
230
 
PyObject *Lamp_Init (void)
 
551
PyObject *Lamp_Init( void )
231
552
{
232
 
  PyObject  *submodule, *Types, *Modes;
233
 
 
234
 
  Lamp_Type.ob_type = &PyType_Type;
235
 
 
236
 
  Types = Lamp_TypesDict ();
237
 
  Modes = Lamp_ModesDict ();
238
 
 
239
 
  submodule = Py_InitModule3("Blender.Lamp", M_Lamp_methods, M_Lamp_doc);
240
 
 
241
 
  if (Types) PyModule_AddObject(submodule, "Types", Types);
242
 
  if (Modes) PyModule_AddObject(submodule, "Modes", Modes);
243
 
 
244
 
  return submodule;
 
553
        PyObject *submodule, *Types, *Modes;
 
554
 
 
555
        Lamp_Type.ob_type = &PyType_Type;
 
556
 
 
557
        Types = Lamp_TypesDict(  );
 
558
        Modes = Lamp_ModesDict(  );
 
559
 
 
560
        submodule =
 
561
                Py_InitModule3( "Blender.Lamp", M_Lamp_methods, M_Lamp_doc );
 
562
 
 
563
        if( Types )
 
564
                PyModule_AddObject( submodule, "Types", Types );
 
565
        if( Modes )
 
566
                PyModule_AddObject( submodule, "Modes", Modes );
 
567
 
 
568
        PyModule_AddIntConstant( submodule, "RGB",      IPOKEY_RGB );
 
569
        PyModule_AddIntConstant( submodule, "ENERGY",   IPOKEY_ENERGY );
 
570
        PyModule_AddIntConstant( submodule, "SPOTSIZE", IPOKEY_SPOTSIZE );
 
571
        PyModule_AddIntConstant( submodule, "OFFSET",   IPOKEY_OFFSET );
 
572
        PyModule_AddIntConstant( submodule, "SIZE",     IPOKEY_SIZE );
 
573
        
 
574
        return submodule;
245
575
}
246
576
 
247
577
/* Three Python Lamp_Type helper functions needed by the Object module: */
251
581
/* Description: This function will create a new BPy_Lamp from an existing    */
252
582
/*              Blender lamp structure.                                      */
253
583
/*****************************************************************************/
254
 
PyObject *Lamp_CreatePyObject (Lamp *lamp)
 
584
PyObject *Lamp_CreatePyObject( Lamp * lamp )
255
585
{
256
 
  BPy_Lamp *pylamp;
257
 
  float *rgb[3];
258
 
 
259
 
  pylamp = (BPy_Lamp *)PyObject_NEW (BPy_Lamp, &Lamp_Type);
260
 
 
261
 
  if (!pylamp)
262
 
    return EXPP_ReturnPyObjError (PyExc_MemoryError,
263
 
            "couldn't create BPy_Lamp object");
264
 
 
265
 
  pylamp->lamp = lamp;
266
 
 
267
 
  rgb[0] = &lamp->r;
268
 
  rgb[1] = &lamp->g;
269
 
  rgb[2] = &lamp->b;
270
 
 
271
 
  pylamp->color = (BPy_rgbTuple *)rgbTuple_New(rgb);
272
 
 
273
 
  return (PyObject *)pylamp;
 
586
        BPy_Lamp *pylamp;
 
587
        float *rgb[3];
 
588
 
 
589
        pylamp = ( BPy_Lamp * ) PyObject_NEW( BPy_Lamp, &Lamp_Type );
 
590
 
 
591
        if( !pylamp )
 
592
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
593
                                              "couldn't create BPy_Lamp object" );
 
594
 
 
595
        pylamp->lamp = lamp;
 
596
 
 
597
        rgb[0] = &lamp->r;
 
598
        rgb[1] = &lamp->g;
 
599
        rgb[2] = &lamp->b;
 
600
 
 
601
        pylamp->color = ( BPy_rgbTuple * ) rgbTuple_New( rgb );
 
602
 
 
603
        return ( PyObject * ) pylamp;
274
604
}
275
605
 
276
606
/*****************************************************************************/
278
608
/* Description: This function returns true when the given PyObject is of the */
279
609
/*              type Lamp. Otherwise it will return false.                   */
280
610
/*****************************************************************************/
281
 
int Lamp_CheckPyObject (PyObject *pyobj)
 
611
int Lamp_CheckPyObject( PyObject * pyobj )
282
612
{
283
 
  return (pyobj->ob_type == &Lamp_Type);
 
613
        return ( pyobj->ob_type == &Lamp_Type );
284
614
}
285
615
 
286
616
/*****************************************************************************/
288
618
/* Description: This function returns the Blender lamp from the given        */
289
619
/*              PyObject.                                                    */
290
620
/*****************************************************************************/
291
 
Lamp *Lamp_FromPyObject (PyObject *pyobj)
 
621
Lamp *Lamp_FromPyObject( PyObject * pyobj )
292
622
{
293
 
  return ((BPy_Lamp *)pyobj)->lamp;
 
623
        return ( ( BPy_Lamp * ) pyobj )->lamp;
294
624
}
295
625
 
296
626
/*****************************************************************************/
301
631
/*              The function will return NULL when no lamp with the given    */
302
632
/*              name is found.                                               */
303
633
/*****************************************************************************/
304
 
Lamp * GetLampByName (char * name)
 
634
Lamp *GetLampByName( char *name )
305
635
{
306
 
        Lamp    * lamp_iter;
 
636
        Lamp *lamp_iter;
307
637
 
308
 
    lamp_iter = G.main->lamp.first;
309
 
        while (lamp_iter)
310
 
        {
311
 
                if (StringEqual (name, GetIdName (&(lamp_iter->id))))
312
 
                {
 
638
        lamp_iter = G.main->lamp.first;
 
639
        while( lamp_iter ) {
 
640
                if( StringEqual( name, GetIdName( &( lamp_iter->id ) ) ) ) {
313
641
                        return lamp_iter;
314
642
                }
315
643
                lamp_iter = lamp_iter->id.next;
322
650
/*****************************************************************************/
323
651
/* Python BPy_Lamp methods:                                                  */
324
652
/*****************************************************************************/
325
 
static PyObject *Lamp_getName(BPy_Lamp *self)
326
 
{
327
 
  PyObject *attr = PyString_FromString(self->lamp->id.name+2);
328
 
 
329
 
  if (attr) return attr;
330
 
 
331
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
332
 
          "couldn't get Lamp.name attribute"));
333
 
}
334
 
 
335
 
static PyObject *Lamp_getType(BPy_Lamp *self)
336
 
337
 
  PyObject *attr = PyInt_FromLong(self->lamp->type);
338
 
 
339
 
  if (attr) return attr;
340
 
 
341
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
342
 
          "couldn't get Lamp.type attribute"));
343
 
}
344
 
 
345
 
static PyObject *Lamp_getMode(BPy_Lamp *self)
346
 
{
347
 
  PyObject *attr = PyInt_FromLong(self->lamp->mode);
348
 
 
349
 
  if (attr) return attr;
350
 
 
351
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
352
 
          "couldn't get Lamp.mode attribute"));
353
 
}
354
 
 
355
 
static PyObject *Lamp_getSamples(BPy_Lamp *self)
356
 
{
357
 
  PyObject *attr = PyInt_FromLong(self->lamp->samp);
358
 
 
359
 
  if (attr) return attr;
360
 
 
361
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
362
 
          "couldn't get Lamp.samples attribute"));
363
 
}
364
 
 
365
 
static PyObject *Lamp_getBufferSize(BPy_Lamp *self)
366
 
{
367
 
  PyObject *attr = PyInt_FromLong(self->lamp->bufsize);
368
 
 
369
 
  if (attr) return attr;
370
 
 
371
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
372
 
          "couldn't get Lamp.bufferSize attribute"));
373
 
}
374
 
 
375
 
static PyObject *Lamp_getHaloStep(BPy_Lamp *self)
376
 
{
377
 
  PyObject *attr = PyInt_FromLong(self->lamp->shadhalostep);
378
 
 
379
 
  if (attr) return attr;
380
 
 
381
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
382
 
          "couldn't get Lamp.haloStep attribute"));
383
 
}
384
 
 
385
 
static PyObject *Lamp_getEnergy(BPy_Lamp *self)
386
 
{
387
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->energy);
388
 
 
389
 
  if (attr) return attr;
390
 
 
391
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
392
 
          "couldn't get Lamp.energy attribute"));
393
 
}
394
 
 
395
 
static PyObject *Lamp_getDist(BPy_Lamp *self)
396
 
{
397
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->dist);
398
 
 
399
 
  if (attr) return attr;
400
 
 
401
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
402
 
          "couldn't get Lamp.dist attribute"));
403
 
}
404
 
 
405
 
static PyObject *Lamp_getSpotSize(BPy_Lamp *self)
406
 
{
407
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->spotsize);
408
 
 
409
 
  if (attr) return attr;
410
 
 
411
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
412
 
          "couldn't get Lamp.spotSize attribute"));
413
 
}
414
 
 
415
 
static PyObject *Lamp_getSpotBlend(BPy_Lamp *self)
416
 
{
417
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->spotblend);
418
 
 
419
 
  if (attr) return attr;
420
 
 
421
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
422
 
          "couldn't get Lamp.spotBlend attribute"));
423
 
}
424
 
 
425
 
static PyObject *Lamp_getClipStart(BPy_Lamp *self)
426
 
{
427
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->clipsta);
428
 
 
429
 
  if (attr) return attr;
430
 
 
431
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
432
 
          "couldn't get Lamp.clipStart attribute"));
433
 
}
434
 
 
435
 
static PyObject *Lamp_getClipEnd(BPy_Lamp *self)
436
 
{
437
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->clipend);
438
 
 
439
 
  if (attr) return attr;
440
 
 
441
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
442
 
          "couldn't get Lamp.clipEnd attribute"));
443
 
}
444
 
 
445
 
static PyObject *Lamp_getBias(BPy_Lamp *self)
446
 
{
447
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->bias);
448
 
 
449
 
  if (attr) return attr;
450
 
 
451
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
452
 
          "couldn't get Lamp.bias attribute"));
453
 
}
454
 
 
455
 
static PyObject *Lamp_getSoftness(BPy_Lamp *self)
456
 
{
457
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->soft);
458
 
 
459
 
  if (attr) return attr;
460
 
 
461
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
462
 
          "couldn't get Lamp.softness attribute"));
463
 
}
464
 
 
465
 
static PyObject *Lamp_getHaloInt(BPy_Lamp *self)
466
 
{
467
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->haint);
468
 
 
469
 
  if (attr) return attr;
470
 
 
471
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
472
 
          "couldn't get Lamp.haloInt attribute"));
473
 
}
474
 
 
475
 
static PyObject *Lamp_getQuad1(BPy_Lamp *self)
476
 
{ /* should we complain if Lamp is not of type Quad? */
477
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->att1);
478
 
 
479
 
  if (attr) return attr;
480
 
 
481
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
482
 
          "couldn't get Lamp.quad1 attribute"));
483
 
}
484
 
 
485
 
static PyObject *Lamp_getQuad2(BPy_Lamp *self)
486
 
{ /* should we complain if Lamp is not of type Quad? */
487
 
  PyObject *attr = PyFloat_FromDouble(self->lamp->att2);
488
 
 
489
 
  if (attr) return attr;
490
 
 
491
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
492
 
          "couldn't get Lamp.quad2 attribute"));
493
 
}
494
 
 
495
 
static PyObject *Lamp_getCol(BPy_Lamp *self)
496
 
{
497
 
  return rgbTuple_getCol(self->color);
498
 
}
499
 
 
500
 
static PyObject *Lamp_setName(BPy_Lamp *self, PyObject *args)
501
 
{
502
 
  char *name = NULL;
503
 
  char buf[21];
504
 
 
505
 
  if (!PyArg_ParseTuple(args, "s", &name))
506
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
507
 
            "expected string argument"));
508
 
  
509
 
  PyOS_snprintf(buf, sizeof(buf), "%s", name);
510
 
 
511
 
  rename_id(&self->lamp->id, buf);
512
 
 
513
 
  Py_INCREF(Py_None);
514
 
  return Py_None;
515
 
}
516
 
 
517
 
static PyObject *Lamp_setType(BPy_Lamp *self, PyObject *args)
518
 
{
519
 
  char *type;
520
 
 
521
 
  if (!PyArg_ParseTuple(args, "s", &type))
522
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
523
 
            "expected string argument"));
524
 
 
525
 
  if (strcmp (type, "Lamp") == 0)
526
 
    self->lamp->type = (short)EXPP_LAMP_TYPE_LAMP;
527
 
  else if (strcmp (type, "Sun") == 0)
528
 
    self->lamp->type = (short)EXPP_LAMP_TYPE_SUN; 
529
 
  else if (strcmp (type, "Spot") == 0)
530
 
    self->lamp->type = (short)EXPP_LAMP_TYPE_SPOT;  
531
 
  else if (strcmp (type, "Hemi") == 0)
532
 
    self->lamp->type = (short)EXPP_LAMP_TYPE_HEMI;  
533
 
  else
534
 
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
535
 
            "unknown lamp type"));
536
 
 
537
 
  Py_INCREF(Py_None);
538
 
  return Py_None;
 
653
static PyObject *Lamp_getName( BPy_Lamp * self )
 
654
{
 
655
        PyObject *attr = PyString_FromString( self->lamp->id.name + 2 );
 
656
 
 
657
        if( attr )
 
658
                return attr;
 
659
 
 
660
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
661
                                        "couldn't get Lamp.name attribute" ) );
 
662
}
 
663
 
 
664
static PyObject *Lamp_getType( BPy_Lamp * self )
 
665
{
 
666
        PyObject *attr = PyInt_FromLong( self->lamp->type );
 
667
 
 
668
        if( attr )
 
669
                return attr;
 
670
 
 
671
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
672
                                        "couldn't get Lamp.type attribute" ) );
 
673
}
 
674
 
 
675
static PyObject *Lamp_getMode( BPy_Lamp * self )
 
676
{
 
677
        PyObject *attr = PyInt_FromLong( self->lamp->mode );
 
678
 
 
679
        if( attr )
 
680
                return attr;
 
681
 
 
682
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
683
                                        "couldn't get Lamp.mode attribute" ) );
 
684
}
 
685
 
 
686
static PyObject *Lamp_getSamples( BPy_Lamp * self )
 
687
{
 
688
        PyObject *attr = PyInt_FromLong( self->lamp->samp );
 
689
 
 
690
        if( attr )
 
691
                return attr;
 
692
 
 
693
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
694
                                        "couldn't get Lamp.samples attribute" ) );
 
695
}
 
696
 
 
697
static PyObject *Lamp_getBufferSize( BPy_Lamp * self )
 
698
{
 
699
        PyObject *attr = PyInt_FromLong( self->lamp->bufsize );
 
700
 
 
701
        if( attr )
 
702
                return attr;
 
703
 
 
704
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
705
                                        "couldn't get Lamp.bufferSize attribute" ) );
 
706
}
 
707
 
 
708
static PyObject *Lamp_getHaloStep( BPy_Lamp * self )
 
709
{
 
710
        PyObject *attr = PyInt_FromLong( self->lamp->shadhalostep );
 
711
 
 
712
        if( attr )
 
713
                return attr;
 
714
 
 
715
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
716
                                        "couldn't get Lamp.haloStep attribute" ) );
 
717
}
 
718
 
 
719
static PyObject *Lamp_getEnergy( BPy_Lamp * self )
 
720
{
 
721
        PyObject *attr = PyFloat_FromDouble( self->lamp->energy );
 
722
 
 
723
        if( attr )
 
724
                return attr;
 
725
 
 
726
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
727
                                        "couldn't get Lamp.energy attribute" ) );
 
728
}
 
729
 
 
730
static PyObject *Lamp_getDist( BPy_Lamp * self )
 
731
{
 
732
        PyObject *attr = PyFloat_FromDouble( self->lamp->dist );
 
733
 
 
734
        if( attr )
 
735
                return attr;
 
736
 
 
737
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
738
                                        "couldn't get Lamp.dist attribute" ) );
 
739
}
 
740
 
 
741
static PyObject *Lamp_getSpotSize( BPy_Lamp * self )
 
742
{
 
743
        PyObject *attr = PyFloat_FromDouble( self->lamp->spotsize );
 
744
 
 
745
        if( attr )
 
746
                return attr;
 
747
 
 
748
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
749
                                        "couldn't get Lamp.spotSize attribute" ) );
 
750
}
 
751
 
 
752
static PyObject *Lamp_getSpotBlend( BPy_Lamp * self )
 
753
{
 
754
        PyObject *attr = PyFloat_FromDouble( self->lamp->spotblend );
 
755
 
 
756
        if( attr )
 
757
                return attr;
 
758
 
 
759
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
760
                                        "couldn't get Lamp.spotBlend attribute" ) );
 
761
}
 
762
 
 
763
static PyObject *Lamp_getClipStart( BPy_Lamp * self )
 
764
{
 
765
        PyObject *attr = PyFloat_FromDouble( self->lamp->clipsta );
 
766
 
 
767
        if( attr )
 
768
                return attr;
 
769
 
 
770
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
771
                                        "couldn't get Lamp.clipStart attribute" ) );
 
772
}
 
773
 
 
774
static PyObject *Lamp_getClipEnd( BPy_Lamp * self )
 
775
{
 
776
        PyObject *attr = PyFloat_FromDouble( self->lamp->clipend );
 
777
 
 
778
        if( attr )
 
779
                return attr;
 
780
 
 
781
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
782
                                        "couldn't get Lamp.clipEnd attribute" ) );
 
783
}
 
784
 
 
785
static PyObject *Lamp_getBias( BPy_Lamp * self )
 
786
{
 
787
        PyObject *attr = PyFloat_FromDouble( self->lamp->bias );
 
788
 
 
789
        if( attr )
 
790
                return attr;
 
791
 
 
792
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
793
                                        "couldn't get Lamp.bias attribute" ) );
 
794
}
 
795
 
 
796
static PyObject *Lamp_getSoftness( BPy_Lamp * self )
 
797
{
 
798
        PyObject *attr = PyFloat_FromDouble( self->lamp->soft );
 
799
 
 
800
        if( attr )
 
801
                return attr;
 
802
 
 
803
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
804
                                        "couldn't get Lamp.softness attribute" ) );
 
805
}
 
806
 
 
807
static PyObject *Lamp_getHaloInt( BPy_Lamp * self )
 
808
{
 
809
        PyObject *attr = PyFloat_FromDouble( self->lamp->haint );
 
810
 
 
811
        if( attr )
 
812
                return attr;
 
813
 
 
814
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
815
                                        "couldn't get Lamp.haloInt attribute" ) );
 
816
}
 
817
 
 
818
static PyObject *Lamp_getQuad1( BPy_Lamp * self )
 
819
{                               /* should we complain if Lamp is not of type Quad? */
 
820
        PyObject *attr = PyFloat_FromDouble( self->lamp->att1 );
 
821
 
 
822
        if( attr )
 
823
                return attr;
 
824
 
 
825
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
826
                                        "couldn't get Lamp.quad1 attribute" ) );
 
827
}
 
828
 
 
829
static PyObject *Lamp_getQuad2( BPy_Lamp * self )
 
830
{                       /* should we complain if Lamp is not of type Quad? */
 
831
        PyObject *attr = PyFloat_FromDouble( self->lamp->att2 );
 
832
 
 
833
        if( attr )
 
834
                return attr;
 
835
 
 
836
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
837
                                        "couldn't get Lamp.quad2 attribute" ) );
 
838
}
 
839
 
 
840
static PyObject *Lamp_getCol( BPy_Lamp * self )
 
841
{
 
842
        return rgbTuple_getCol( self->color );
 
843
}
 
844
 
 
845
static PyObject *Lamp_setName( BPy_Lamp * self, PyObject * args )
 
846
{
 
847
        char *name = NULL;
 
848
        char buf[21];
 
849
 
 
850
        if( !PyArg_ParseTuple( args, "s", &name ) )
 
851
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
852
                                                "expected string argument" ) );
 
853
 
 
854
        PyOS_snprintf( buf, sizeof( buf ), "%s", name );
 
855
 
 
856
        rename_id( &self->lamp->id, buf );
 
857
 
 
858
        Py_INCREF( Py_None );
 
859
        return Py_None;
 
860
}
 
861
 
 
862
static PyObject *Lamp_setType( BPy_Lamp * self, PyObject * args )
 
863
{
 
864
        char *type;
 
865
 
 
866
        if( !PyArg_ParseTuple( args, "s", &type ) )
 
867
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
868
                                                "expected string argument" ) );
 
869
 
 
870
        if( strcmp( type, "Lamp" ) == 0 )
 
871
                self->lamp->type = ( short ) EXPP_LAMP_TYPE_LAMP;
 
872
        else if( strcmp( type, "Sun" ) == 0 )
 
873
                self->lamp->type = ( short ) EXPP_LAMP_TYPE_SUN;
 
874
        else if( strcmp( type, "Spot" ) == 0 )
 
875
                self->lamp->type = ( short ) EXPP_LAMP_TYPE_SPOT;
 
876
        else if( strcmp( type, "Hemi" ) == 0 )
 
877
                self->lamp->type = ( short ) EXPP_LAMP_TYPE_HEMI;
 
878
        else if( strcmp( type, "Area" ) == 0 )
 
879
                self->lamp->type = ( short ) EXPP_LAMP_TYPE_AREA;
 
880
        else if( strcmp( type, "Photon" ) == 0 )
 
881
                self->lamp->type = ( short ) EXPP_LAMP_TYPE_YF_PHOTON;
 
882
        else
 
883
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
884
                                                "unknown lamp type" ) );
 
885
 
 
886
        Py_INCREF( Py_None );
 
887
        return Py_None;
539
888
}
540
889
 
541
890
/* This one is 'private'. It is not really a method, just a helper function for
542
891
 * when script writers use Lamp.type = t instead of Lamp.setType(t), since in
543
892
 * the first case t shoud be an int and in the second it should be a string. So
544
 
 * while the method setType expects a string ('persp' or 'ortho') or an empty
 
893
 * while the method setType expects a string  or an empty
545
894
 * argument, this function should receive an int (0 or 1). */
546
 
static PyObject *Lamp_setIntType(BPy_Lamp *self, PyObject *args)
 
895
static PyObject *Lamp_setIntType( BPy_Lamp * self, PyObject * args )
547
896
{
548
 
  short value;
549
 
 
550
 
  if (!PyArg_ParseTuple(args, "h", &value))
551
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
552
 
            "expected int argument in [0,3]"));
553
 
 
554
 
  if (value >= 0 && value <= 3)
555
 
    self->lamp->type = value;
556
 
  else
557
 
    return (EXPP_ReturnPyObjError (PyExc_ValueError,
558
 
            "expected int argument in [0,3]"));
559
 
 
560
 
  Py_INCREF(Py_None);
561
 
  return Py_None;
 
897
        short value;
 
898
 
 
899
        if( !PyArg_ParseTuple( args, "h", &value ) )
 
900
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
901
                                                "expected int argument in [0,5]" ) );
 
902
 
 
903
        if( value >= 0 && value <= EXPP_LAMP_TYPE_MAX )
 
904
                self->lamp->type = value;
 
905
        else
 
906
                return ( EXPP_ReturnPyObjError( PyExc_ValueError,
 
907
                                                "expected int argument in [0,5]" ) );
 
908
 
 
909
        Py_INCREF( Py_None );
 
910
        return Py_None;
562
911
}
563
912
 
564
 
static PyObject *Lamp_setMode(BPy_Lamp *self, PyObject *args)
 
913
static PyObject *Lamp_setMode( BPy_Lamp * self, PyObject * args )
565
914
{
566
 
  char *m[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
567
 
  short i, flag = 0;
568
 
 
569
 
  if (!PyArg_ParseTuple(args, "|ssssssss", &m[0], &m[1], &m[2],
570
 
                        &m[3], &m[4], &m[5], &m[6], &m[7], &m[8], &m[9]))
571
 
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
572
 
            "expected from none to 10 string argument(s)"));
573
 
 
574
 
  for (i = 0; i < 10; i++) {
575
 
    if (m[i] == NULL) break;
576
 
    if (strcmp(m[i], "Shadows") == 0)
577
 
      flag |= (short)EXPP_LAMP_MODE_SHADOWS;
578
 
    else if (strcmp(m[i], "Halo") == 0)
579
 
      flag |= (short)EXPP_LAMP_MODE_HALO;
580
 
    else if (strcmp(m[i], "Layer") == 0)
581
 
      flag |= (short)EXPP_LAMP_MODE_LAYER;
582
 
    else if (strcmp(m[i], "Quad") == 0)
583
 
      flag |= (short)EXPP_LAMP_MODE_QUAD;
584
 
    else if (strcmp(m[i], "Negative") == 0)
585
 
      flag |= (short)EXPP_LAMP_MODE_NEGATIVE;
586
 
    else if (strcmp(m[i], "OnlyShadow") == 0)
587
 
      flag |= (short)EXPP_LAMP_MODE_ONLYSHADOW;
588
 
    else if (strcmp(m[i], "Sphere") == 0)
589
 
      flag |= (short)EXPP_LAMP_MODE_SPHERE;
590
 
    else if (strcmp(m[i], "Square") == 0)
591
 
      flag |= (short)EXPP_LAMP_MODE_SQUARE;
592
 
    else if (strcmp(m[i], "NoDiffuse") == 0)
593
 
      flag |= (short)EXPP_LAMP_MODE_NODIFFUSE;
594
 
    else if (strcmp(m[i], "NoSpecular") == 0)
595
 
      flag |= (short)EXPP_LAMP_MODE_NOSPECULAR;
596
 
    else
597
 
      return (EXPP_ReturnPyObjError (PyExc_AttributeError,
598
 
              "unknown lamp flag argument"));
599
 
  }
600
 
 
601
 
  self->lamp->mode = flag;
602
 
 
603
 
  Py_INCREF(Py_None);
604
 
  return Py_None;
 
915
        char *m[10] =
 
916
                { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
 
917
        short i, flag = 0;
 
918
 
 
919
        if( !PyArg_ParseTuple( args, "|ssssssss", &m[0], &m[1], &m[2],
 
920
                               &m[3], &m[4], &m[5], &m[6], &m[7], &m[8],
 
921
                               &m[9] ) )
 
922
                return ( EXPP_ReturnPyObjError
 
923
                         ( PyExc_AttributeError,
 
924
                           "expected from none to 10 string argument(s)" ) );
 
925
 
 
926
        for( i = 0; i < 10; i++ ) {
 
927
                if( m[i] == NULL )
 
928
                        break;
 
929
                if( strcmp( m[i], "Shadows" ) == 0 )
 
930
                        flag |= ( short ) EXPP_LAMP_MODE_SHADOWS;
 
931
                else if( strcmp( m[i], "Halo" ) == 0 )
 
932
                        flag |= ( short ) EXPP_LAMP_MODE_HALO;
 
933
                else if( strcmp( m[i], "Layer" ) == 0 )
 
934
                        flag |= ( short ) EXPP_LAMP_MODE_LAYER;
 
935
                else if( strcmp( m[i], "Quad" ) == 0 )
 
936
                        flag |= ( short ) EXPP_LAMP_MODE_QUAD;
 
937
                else if( strcmp( m[i], "Negative" ) == 0 )
 
938
                        flag |= ( short ) EXPP_LAMP_MODE_NEGATIVE;
 
939
                else if( strcmp( m[i], "OnlyShadow" ) == 0 )
 
940
                        flag |= ( short ) EXPP_LAMP_MODE_ONLYSHADOW;
 
941
                else if( strcmp( m[i], "Sphere" ) == 0 )
 
942
                        flag |= ( short ) EXPP_LAMP_MODE_SPHERE;
 
943
                else if( strcmp( m[i], "Square" ) == 0 )
 
944
                        flag |= ( short ) EXPP_LAMP_MODE_SQUARE;
 
945
                else if( strcmp( m[i], "NoDiffuse" ) == 0 )
 
946
                        flag |= ( short ) EXPP_LAMP_MODE_NODIFFUSE;
 
947
                else if( strcmp( m[i], "NoSpecular" ) == 0 )
 
948
                        flag |= ( short ) EXPP_LAMP_MODE_NOSPECULAR;
 
949
                else
 
950
                        return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
951
                                                        "unknown lamp flag argument" ) );
 
952
        }
 
953
 
 
954
        self->lamp->mode = flag;
 
955
 
 
956
        Py_INCREF( Py_None );
 
957
        return Py_None;
605
958
}
606
959
 
607
960
/* Another helper function, for the same reason.
608
961
 * (See comment before Lamp_setIntType above). */
609
 
static PyObject *Lamp_setIntMode(BPy_Lamp *self, PyObject *args)
 
962
static PyObject *Lamp_setIntMode( BPy_Lamp * self, PyObject * args )
610
963
{
611
 
  short value;
 
964
        short value;
612
965
 
613
 
  if (!PyArg_ParseTuple(args, "h", &value))
614
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
615
 
            "expected int argument"));
 
966
        if( !PyArg_ParseTuple( args, "h", &value ) )
 
967
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
968
                                                "expected int argument" ) );
616
969
 
617
970
/* well, with so many flag bits, we just accept any short int, no checking */
618
 
  self->lamp->mode = value;
619
 
 
620
 
  Py_INCREF(Py_None);
621
 
  return Py_None;
622
 
}
623
 
 
624
 
static PyObject *Lamp_setSamples(BPy_Lamp *self, PyObject *args)
625
 
{
626
 
  short value;
627
 
 
628
 
  if (!PyArg_ParseTuple(args, "h", &value))
629
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
630
 
            "expected int argument in [1,16]"));
631
 
 
632
 
  self->lamp->samp = EXPP_ClampInt (value,
633
 
                  EXPP_LAMP_SAMPLES_MIN, EXPP_LAMP_SAMPLES_MAX);
634
 
 
635
 
  Py_INCREF(Py_None);
636
 
  return Py_None;
637
 
}
638
 
 
639
 
static PyObject *Lamp_setBufferSize(BPy_Lamp *self, PyObject *args)
640
 
{
641
 
  short value;
642
 
 
643
 
  if (!PyArg_ParseTuple(args, "h", &value))
644
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
645
 
            "expected int argument in [512, 5120]"));
646
 
  
647
 
  self->lamp->bufsize = EXPP_ClampInt (value,
648
 
                  EXPP_LAMP_BUFFERSIZE_MIN, EXPP_LAMP_BUFFERSIZE_MAX);
649
 
 
650
 
  Py_INCREF(Py_None);
651
 
  return Py_None;
652
 
}
653
 
 
654
 
static PyObject *Lamp_setHaloStep(BPy_Lamp *self, PyObject *args)
655
 
{
656
 
  short value;
657
 
 
658
 
  if (!PyArg_ParseTuple(args, "h", &value))
659
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
660
 
            "expected int argument in [0,12]"));
661
 
 
662
 
  self->lamp->shadhalostep = EXPP_ClampInt (value,
663
 
                  EXPP_LAMP_HALOSTEP_MIN, EXPP_LAMP_HALOSTEP_MAX);
664
 
 
665
 
  Py_INCREF(Py_None);
666
 
  return Py_None;
667
 
}
668
 
 
669
 
static PyObject *Lamp_setEnergy(BPy_Lamp *self, PyObject *args)
670
 
{
671
 
  float value;
672
 
  
673
 
  if (!PyArg_ParseTuple(args, "f", &value))
674
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
675
 
            "expected float argument"));
676
 
 
677
 
  self->lamp->energy = EXPP_ClampFloat (value,
678
 
                  EXPP_LAMP_ENERGY_MIN, EXPP_LAMP_ENERGY_MAX);
679
 
 
680
 
  Py_INCREF(Py_None);
681
 
  return Py_None;
682
 
}
683
 
 
684
 
static PyObject *Lamp_setDist(BPy_Lamp *self, PyObject *args)
685
 
{
686
 
  float value;
687
 
  
688
 
  if (!PyArg_ParseTuple(args, "f", &value))
689
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
690
 
            "expected float argument"));
691
 
 
692
 
  self->lamp->dist = EXPP_ClampFloat (value,
693
 
                  EXPP_LAMP_DIST_MIN, EXPP_LAMP_DIST_MAX);
694
 
 
695
 
  Py_INCREF(Py_None);
696
 
  return Py_None;
697
 
}
698
 
 
699
 
static PyObject *Lamp_setSpotSize(BPy_Lamp *self, PyObject *args)
700
 
{
701
 
  float value;
702
 
  
703
 
  if (!PyArg_ParseTuple(args, "f", &value))
704
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
705
 
            "expected float argument"));
706
 
 
707
 
  self->lamp->spotsize = EXPP_ClampFloat (value,
708
 
                  EXPP_LAMP_SPOTSIZE_MIN, EXPP_LAMP_SPOTSIZE_MAX);
709
 
 
710
 
  Py_INCREF(Py_None);
711
 
  return Py_None;
712
 
}
713
 
 
714
 
static PyObject *Lamp_setSpotBlend(BPy_Lamp *self, PyObject *args)
715
 
{
716
 
  float value;
717
 
  
718
 
  if (!PyArg_ParseTuple(args, "f", &value))
719
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
720
 
            "expected float argument"));
721
 
 
722
 
  self->lamp->spotblend = EXPP_ClampFloat (value,
723
 
                  EXPP_LAMP_SPOTBLEND_MIN, EXPP_LAMP_SPOTBLEND_MAX);
724
 
 
725
 
  Py_INCREF(Py_None);
726
 
  return Py_None;
727
 
}
728
 
 
729
 
static PyObject *Lamp_setClipStart(BPy_Lamp *self, PyObject *args)
730
 
{
731
 
  float value;
732
 
  
733
 
  if (!PyArg_ParseTuple(args, "f", &value))
734
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
735
 
            "expected float argument"));
736
 
  
737
 
  self->lamp->clipsta = EXPP_ClampFloat (value,
738
 
                  EXPP_LAMP_CLIPSTART_MIN, EXPP_LAMP_CLIPSTART_MAX);
739
 
 
740
 
  Py_INCREF(Py_None);
741
 
  return Py_None;
742
 
}
743
 
 
744
 
static PyObject *Lamp_setClipEnd(BPy_Lamp *self, PyObject *args)
745
 
{
746
 
  float value;
747
 
 
748
 
  if (!PyArg_ParseTuple(args, "f", &value))
749
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
750
 
            "expected float argument"));
751
 
 
752
 
  self->lamp->clipend = EXPP_ClampFloat (value,
753
 
                  EXPP_LAMP_CLIPEND_MIN, EXPP_LAMP_CLIPEND_MAX);
754
 
 
755
 
  Py_INCREF(Py_None);
756
 
  return Py_None;
757
 
}
758
 
 
759
 
static PyObject *Lamp_setBias(BPy_Lamp *self, PyObject *args)
760
 
{
761
 
  float value;
762
 
  
763
 
  if (!PyArg_ParseTuple(args, "f", &value))
764
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
765
 
            "expected float argument"));
766
 
 
767
 
  self->lamp->bias = EXPP_ClampFloat (value,
768
 
                  EXPP_LAMP_BIAS_MIN, EXPP_LAMP_BIAS_MAX);
769
 
 
770
 
  Py_INCREF(Py_None);
771
 
  return Py_None;
772
 
}
773
 
 
774
 
static PyObject *Lamp_setSoftness(BPy_Lamp *self, PyObject *args)
775
 
{
776
 
  float value;
777
 
  
778
 
  if (!PyArg_ParseTuple(args, "f", &value))
779
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
780
 
            "expected float argument"));
781
 
 
782
 
  self->lamp->soft = EXPP_ClampFloat (value,
783
 
                  EXPP_LAMP_SOFTNESS_MIN, EXPP_LAMP_SOFTNESS_MAX);
784
 
 
785
 
  Py_INCREF(Py_None);
786
 
  return Py_None;
787
 
}
788
 
 
789
 
static PyObject *Lamp_setHaloInt(BPy_Lamp *self, PyObject *args)
790
 
{
791
 
  float value;
792
 
 
793
 
  if (!PyArg_ParseTuple(args, "f", &value))
794
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
795
 
            "expected float argument"));
796
 
 
797
 
  self->lamp->haint = EXPP_ClampFloat (value,
798
 
                  EXPP_LAMP_HALOINT_MIN, EXPP_LAMP_HALOINT_MAX);
799
 
 
800
 
  Py_INCREF(Py_None);
801
 
  return Py_None;
802
 
}
803
 
 
804
 
static PyObject *Lamp_setQuad1(BPy_Lamp *self, PyObject *args)
805
 
{
806
 
  float value;
807
 
 
808
 
  if (!PyArg_ParseTuple(args, "f", &value))
809
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
810
 
            "expected float argument"));
811
 
 
812
 
  self->lamp->att1 = EXPP_ClampFloat (value,
813
 
                  EXPP_LAMP_QUAD1_MIN, EXPP_LAMP_QUAD1_MAX);
814
 
 
815
 
  Py_INCREF(Py_None);
816
 
  return Py_None;
817
 
}
818
 
 
819
 
static PyObject *Lamp_setQuad2(BPy_Lamp *self, PyObject *args)
820
 
{
821
 
  float value;
822
 
 
823
 
  if (!PyArg_ParseTuple(args, "f", &value))
824
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
825
 
            "expected float argument"));
826
 
 
827
 
  self->lamp->att2 = EXPP_ClampFloat (value,
828
 
                  EXPP_LAMP_QUAD2_MIN, EXPP_LAMP_QUAD2_MAX);
829
 
 
830
 
  Py_INCREF(Py_None);
831
 
  return Py_None;
832
 
}
833
 
 
834
 
static PyObject *Lamp_setColorComponent(BPy_Lamp *self, char *key,
835
 
                PyObject *args)
836
 
{ /* for compatibility with old bpython */
837
 
  float value;
838
 
 
839
 
  if (!PyArg_ParseTuple(args, "f", &value))
840
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
841
 
            "expected float argument in [0.0, 1.0]"));
842
 
 
843
 
  value = EXPP_ClampFloat (value, EXPP_LAMP_COL_MIN,
844
 
                  EXPP_LAMP_COL_MAX);
845
 
 
846
 
  if (!strcmp(key, "R"))
847
 
    self->lamp->r = value;
848
 
  else if (!strcmp(key, "G"))
849
 
    self->lamp->g = value;
850
 
  else if (!strcmp(key, "B"))
851
 
    self->lamp->b = value;
852
 
 
853
 
  Py_INCREF(Py_None);
854
 
  return Py_None;
855
 
}
856
 
 
857
 
static PyObject *Lamp_setCol(BPy_Lamp *self, PyObject *args)
858
 
{
859
 
  return rgbTuple_setCol(self->color, args);
 
971
        self->lamp->mode = value;
 
972
 
 
973
        Py_INCREF( Py_None );
 
974
        return Py_None;
 
975
}
 
976
 
 
977
static PyObject *Lamp_setSamples( BPy_Lamp * self, PyObject * args )
 
978
{
 
979
        short value;
 
980
 
 
981
        if( !PyArg_ParseTuple( args, "h", &value ) )
 
982
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
983
                                                "expected int argument in [1,16]" ) );
 
984
 
 
985
        self->lamp->samp = EXPP_ClampInt( value,
 
986
                                          EXPP_LAMP_SAMPLES_MIN,
 
987
                                          EXPP_LAMP_SAMPLES_MAX );
 
988
 
 
989
        Py_INCREF( Py_None );
 
990
        return Py_None;
 
991
}
 
992
 
 
993
static PyObject *Lamp_setBufferSize( BPy_Lamp * self, PyObject * args )
 
994
{
 
995
        short value;
 
996
 
 
997
        if( !PyArg_ParseTuple( args, "h", &value ) )
 
998
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
999
                                                "expected int argument in [512, 5120]" ) );
 
1000
 
 
1001
        self->lamp->bufsize = EXPP_ClampInt( value,
 
1002
                                             EXPP_LAMP_BUFFERSIZE_MIN,
 
1003
                                             EXPP_LAMP_BUFFERSIZE_MAX );
 
1004
 
 
1005
        Py_INCREF( Py_None );
 
1006
        return Py_None;
 
1007
}
 
1008
 
 
1009
static PyObject *Lamp_setHaloStep( BPy_Lamp * self, PyObject * args )
 
1010
{
 
1011
        short value;
 
1012
 
 
1013
        if( !PyArg_ParseTuple( args, "h", &value ) )
 
1014
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1015
                                                "expected int argument in [0,12]" ) );
 
1016
 
 
1017
        self->lamp->shadhalostep = EXPP_ClampInt( value,
 
1018
                                                  EXPP_LAMP_HALOSTEP_MIN,
 
1019
                                                  EXPP_LAMP_HALOSTEP_MAX );
 
1020
 
 
1021
        Py_INCREF( Py_None );
 
1022
        return Py_None;
 
1023
}
 
1024
 
 
1025
static PyObject *Lamp_setEnergy( BPy_Lamp * self, PyObject * args )
 
1026
{
 
1027
        float value;
 
1028
 
 
1029
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1030
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1031
                                                "expected float argument" ) );
 
1032
 
 
1033
        self->lamp->energy = EXPP_ClampFloat( value,
 
1034
                                              EXPP_LAMP_ENERGY_MIN,
 
1035
                                              EXPP_LAMP_ENERGY_MAX );
 
1036
 
 
1037
        Py_INCREF( Py_None );
 
1038
        return Py_None;
 
1039
}
 
1040
 
 
1041
static PyObject *Lamp_setDist( BPy_Lamp * self, PyObject * args )
 
1042
{
 
1043
        float value;
 
1044
 
 
1045
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1046
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1047
                                                "expected float argument" ) );
 
1048
 
 
1049
        self->lamp->dist = EXPP_ClampFloat( value,
 
1050
                                            EXPP_LAMP_DIST_MIN,
 
1051
                                            EXPP_LAMP_DIST_MAX );
 
1052
 
 
1053
        Py_INCREF( Py_None );
 
1054
        return Py_None;
 
1055
}
 
1056
 
 
1057
static PyObject *Lamp_setSpotSize( BPy_Lamp * self, PyObject * args )
 
1058
{
 
1059
        float value;
 
1060
 
 
1061
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1062
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1063
                                                "expected float argument" ) );
 
1064
 
 
1065
        self->lamp->spotsize = EXPP_ClampFloat( value,
 
1066
                                                EXPP_LAMP_SPOTSIZE_MIN,
 
1067
                                                EXPP_LAMP_SPOTSIZE_MAX );
 
1068
 
 
1069
        Py_INCREF( Py_None );
 
1070
        return Py_None;
 
1071
}
 
1072
 
 
1073
static PyObject *Lamp_setSpotBlend( BPy_Lamp * self, PyObject * args )
 
1074
{
 
1075
        float value;
 
1076
 
 
1077
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1078
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1079
                                                "expected float argument" ) );
 
1080
 
 
1081
        self->lamp->spotblend = EXPP_ClampFloat( value,
 
1082
                                                 EXPP_LAMP_SPOTBLEND_MIN,
 
1083
                                                 EXPP_LAMP_SPOTBLEND_MAX );
 
1084
 
 
1085
        Py_INCREF( Py_None );
 
1086
        return Py_None;
 
1087
}
 
1088
 
 
1089
static PyObject *Lamp_setClipStart( BPy_Lamp * self, PyObject * args )
 
1090
{
 
1091
        float value;
 
1092
 
 
1093
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1094
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1095
                                                "expected float argument" ) );
 
1096
 
 
1097
        self->lamp->clipsta = EXPP_ClampFloat( value,
 
1098
                                               EXPP_LAMP_CLIPSTART_MIN,
 
1099
                                               EXPP_LAMP_CLIPSTART_MAX );
 
1100
 
 
1101
        Py_INCREF( Py_None );
 
1102
        return Py_None;
 
1103
}
 
1104
 
 
1105
static PyObject *Lamp_setClipEnd( BPy_Lamp * self, PyObject * args )
 
1106
{
 
1107
        float value;
 
1108
 
 
1109
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1110
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1111
                                                "expected float argument" ) );
 
1112
 
 
1113
        self->lamp->clipend = EXPP_ClampFloat( value,
 
1114
                                               EXPP_LAMP_CLIPEND_MIN,
 
1115
                                               EXPP_LAMP_CLIPEND_MAX );
 
1116
 
 
1117
        Py_INCREF( Py_None );
 
1118
        return Py_None;
 
1119
}
 
1120
 
 
1121
static PyObject *Lamp_setBias( BPy_Lamp * self, PyObject * args )
 
1122
{
 
1123
        float value;
 
1124
 
 
1125
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1126
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1127
                                                "expected float argument" ) );
 
1128
 
 
1129
        self->lamp->bias = EXPP_ClampFloat( value,
 
1130
                                            EXPP_LAMP_BIAS_MIN,
 
1131
                                            EXPP_LAMP_BIAS_MAX );
 
1132
 
 
1133
        Py_INCREF( Py_None );
 
1134
        return Py_None;
 
1135
}
 
1136
 
 
1137
static PyObject *Lamp_setSoftness( BPy_Lamp * self, PyObject * args )
 
1138
{
 
1139
        float value;
 
1140
 
 
1141
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1142
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1143
                                                "expected float argument" ) );
 
1144
 
 
1145
        self->lamp->soft = EXPP_ClampFloat( value,
 
1146
                                            EXPP_LAMP_SOFTNESS_MIN,
 
1147
                                            EXPP_LAMP_SOFTNESS_MAX );
 
1148
 
 
1149
        Py_INCREF( Py_None );
 
1150
        return Py_None;
 
1151
}
 
1152
 
 
1153
static PyObject *Lamp_setHaloInt( BPy_Lamp * self, PyObject * args )
 
1154
{
 
1155
        float value;
 
1156
 
 
1157
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1158
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1159
                                                "expected float argument" ) );
 
1160
 
 
1161
        self->lamp->haint = EXPP_ClampFloat( value,
 
1162
                                             EXPP_LAMP_HALOINT_MIN,
 
1163
                                             EXPP_LAMP_HALOINT_MAX );
 
1164
 
 
1165
        Py_INCREF( Py_None );
 
1166
        return Py_None;
 
1167
}
 
1168
 
 
1169
static PyObject *Lamp_setQuad1( BPy_Lamp * self, PyObject * args )
 
1170
{
 
1171
        float value;
 
1172
 
 
1173
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1174
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1175
                                                "expected float argument" ) );
 
1176
 
 
1177
        self->lamp->att1 = EXPP_ClampFloat( value,
 
1178
                                            EXPP_LAMP_QUAD1_MIN,
 
1179
                                            EXPP_LAMP_QUAD1_MAX );
 
1180
 
 
1181
        Py_INCREF( Py_None );
 
1182
        return Py_None;
 
1183
}
 
1184
 
 
1185
static PyObject *Lamp_setQuad2( BPy_Lamp * self, PyObject * args )
 
1186
{
 
1187
        float value;
 
1188
 
 
1189
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1190
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1191
                                                "expected float argument" ) );
 
1192
 
 
1193
        self->lamp->att2 = EXPP_ClampFloat( value,
 
1194
                                            EXPP_LAMP_QUAD2_MIN,
 
1195
                                            EXPP_LAMP_QUAD2_MAX );
 
1196
 
 
1197
        Py_INCREF( Py_None );
 
1198
        return Py_None;
 
1199
}
 
1200
 
 
1201
static PyObject *Lamp_setColorComponent( BPy_Lamp * self, char *key,
 
1202
                                         PyObject * args )
 
1203
{                               /* for compatibility with old bpython */
 
1204
        float value;
 
1205
 
 
1206
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
1207
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
1208
                                                "expected float argument in [0.0, 1.0]" ) );
 
1209
 
 
1210
        value = EXPP_ClampFloat( value, EXPP_LAMP_COL_MIN, EXPP_LAMP_COL_MAX );
 
1211
 
 
1212
        if( !strcmp( key, "R" ) )
 
1213
                self->lamp->r = value;
 
1214
        else if( !strcmp( key, "G" ) )
 
1215
                self->lamp->g = value;
 
1216
        else if( !strcmp( key, "B" ) )
 
1217
                self->lamp->b = value;
 
1218
 
 
1219
        Py_INCREF( Py_None );
 
1220
        return Py_None;
 
1221
}
 
1222
 
 
1223
static PyObject *Lamp_setCol( BPy_Lamp * self, PyObject * args )
 
1224
{
 
1225
        return rgbTuple_setCol( self->color, args );
 
1226
}
 
1227
 
 
1228
/* lamp.addScriptLink */
 
1229
static PyObject *Lamp_addScriptLink( BPy_Lamp * self, PyObject * args )
 
1230
{
 
1231
        Lamp *lamp = self->lamp;
 
1232
        ScriptLink *slink = NULL;
 
1233
 
 
1234
        slink = &( lamp )->scriptlink;
 
1235
 
 
1236
        return EXPP_addScriptLink( slink, args, 0 );
 
1237
}
 
1238
 
 
1239
/* lamp.clearScriptLinks */
 
1240
static PyObject *Lamp_clearScriptLinks( BPy_Lamp * self, PyObject * args )
 
1241
{
 
1242
        Lamp *lamp = self->lamp;
 
1243
        ScriptLink *slink = NULL;
 
1244
 
 
1245
        slink = &( lamp )->scriptlink;
 
1246
 
 
1247
        return EXPP_clearScriptLinks( slink, args );
 
1248
}
 
1249
 
 
1250
/* mat.getScriptLinks */
 
1251
static PyObject *Lamp_getScriptLinks( BPy_Lamp * self, PyObject * args )
 
1252
{
 
1253
        Lamp *lamp = self->lamp;
 
1254
        ScriptLink *slink = NULL;
 
1255
        PyObject *ret = NULL;
 
1256
 
 
1257
        slink = &( lamp )->scriptlink;
 
1258
 
 
1259
        ret = EXPP_getScriptLinks( slink, args, 0 );
 
1260
 
 
1261
        if( ret )
 
1262
                return ret;
 
1263
        else
 
1264
                return NULL;
860
1265
}
861
1266
 
862
1267
/*****************************************************************************/
864
1269
/* Description: This is a callback function for the BPy_Lamp type. It is     */
865
1270
/*              the destructor function.                                     */
866
1271
/*****************************************************************************/
867
 
static void Lamp_dealloc (BPy_Lamp *self)
 
1272
static void Lamp_dealloc( BPy_Lamp * self )
868
1273
{
869
 
        Py_DECREF (self->color);
870
 
  PyObject_DEL (self);
 
1274
        Py_DECREF( self->color );
 
1275
        PyObject_DEL( self );
871
1276
}
872
1277
 
873
1278
/*****************************************************************************/
876
1281
/*              the function that accesses BPy_Lamp member variables and     */
877
1282
/*              methods.                                                     */
878
1283
/*****************************************************************************/
879
 
static PyObject *Lamp_getAttr (BPy_Lamp *self, char *name)
 
1284
static PyObject *Lamp_getAttr( BPy_Lamp * self, char *name )
880
1285
{
881
 
  PyObject *attr = Py_None;
882
 
 
883
 
  if (strcmp(name, "name") == 0)
884
 
    attr = PyString_FromString(self->lamp->id.name+2);
885
 
  else if (strcmp(name, "type") == 0)
886
 
    attr = PyInt_FromLong(self->lamp->type);
887
 
  else if (strcmp(name, "mode") == 0)
888
 
    attr = PyInt_FromLong(self->lamp->mode);
889
 
  else if (strcmp(name, "samples") == 0)
890
 
    attr = PyInt_FromLong(self->lamp->samp);
891
 
  else if (strcmp(name, "bufferSize") == 0)
892
 
    attr = PyInt_FromLong(self->lamp->bufsize);
893
 
  else if (strcmp(name, "haloStep") == 0)
894
 
    attr = PyInt_FromLong(self->lamp->shadhalostep);
895
 
  else if (strcmp(name, "R") == 0)
896
 
    attr = PyFloat_FromDouble(self->lamp->r);
897
 
  else if (strcmp(name, "G") == 0)
898
 
    attr = PyFloat_FromDouble(self->lamp->g);
899
 
  else if (strcmp(name, "B") == 0)
900
 
    attr = PyFloat_FromDouble(self->lamp->b);
901
 
  else if (strcmp(name, "col") == 0)
902
 
    attr = Lamp_getCol(self);
903
 
  else if (strcmp(name, "energy") == 0)
904
 
    attr = PyFloat_FromDouble(self->lamp->energy);
905
 
  else if (strcmp(name, "dist") == 0)
906
 
    attr = PyFloat_FromDouble(self->lamp->dist);
907
 
  else if (strcmp(name, "spotSize") == 0)
908
 
    attr = PyFloat_FromDouble(self->lamp->spotsize);
909
 
  else if (strcmp(name, "spotBlend") == 0)
910
 
    attr = PyFloat_FromDouble(self->lamp->spotblend);
911
 
  else if (strcmp(name, "clipStart") == 0)
912
 
    attr = PyFloat_FromDouble(self->lamp->clipsta);
913
 
  else if (strcmp(name, "clipEnd") == 0)
914
 
    attr = PyFloat_FromDouble(self->lamp->clipend);
915
 
  else if (strcmp(name, "bias") == 0)
916
 
    attr = PyFloat_FromDouble(self->lamp->bias);
917
 
  else if (strcmp(name, "softness") == 0)
918
 
    attr = PyFloat_FromDouble(self->lamp->soft);
919
 
  else if (strcmp(name, "haloInt") == 0)
920
 
    attr = PyFloat_FromDouble(self->lamp->haint);
921
 
  else if (strcmp(name, "quad1") == 0)
922
 
    attr = PyFloat_FromDouble(self->lamp->att1);
923
 
  else if (strcmp(name, "quad2") == 0)
924
 
    attr = PyFloat_FromDouble(self->lamp->att2);
925
 
 
926
 
  else if (strcmp(name, "Types") == 0) {
927
 
    attr = Py_BuildValue("{s:h,s:h,s:h,s:h}",
928
 
                    "Lamp", EXPP_LAMP_TYPE_LAMP,
929
 
                    "Sun" , EXPP_LAMP_TYPE_SUN,
930
 
                    "Spot", EXPP_LAMP_TYPE_SPOT,
931
 
                    "Hemi", EXPP_LAMP_TYPE_HEMI);
932
 
  }
933
 
 
934
 
  else if (strcmp(name, "Modes") == 0) {
935
 
    attr = Py_BuildValue("{s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h}",
936
 
                    "Shadows",    EXPP_LAMP_MODE_SHADOWS,
937
 
                    "Halo",       EXPP_LAMP_MODE_HALO,
938
 
                    "Layer",      EXPP_LAMP_MODE_LAYER,
939
 
                    "Quad",       EXPP_LAMP_MODE_QUAD,
940
 
                    "Negative",   EXPP_LAMP_MODE_NEGATIVE,
941
 
                    "OnlyShadow", EXPP_LAMP_MODE_ONLYSHADOW,
942
 
                    "Sphere",     EXPP_LAMP_MODE_SPHERE,
943
 
                    "Square",     EXPP_LAMP_MODE_SQUARE,
944
 
                    "NoDiffuse",  EXPP_LAMP_MODE_NODIFFUSE,
945
 
                    "NoSpecular", EXPP_LAMP_MODE_NOSPECULAR);
946
 
  }
947
 
 
948
 
  else if (strcmp(name, "__members__") == 0) {
949
 
    /* 23 entries */
950
 
    attr = Py_BuildValue("[s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s]",
951
 
                    "name", "type", "mode", "samples", "bufferSize",
952
 
                    "haloStep", "R", "G", "B", "energy", "dist",
953
 
                    "spotSize", "spotBlend", "clipStart", "clipEnd",
954
 
                    "bias", "softness", "haloInt", "quad1", "quad2",
955
 
                    "Types", "Modes", "col");
956
 
  }
957
 
 
958
 
  if (!attr)
959
 
    return (EXPP_ReturnPyObjError (PyExc_MemoryError,
960
 
                      "couldn't create PyObject"));
961
 
 
962
 
  if (attr != Py_None) return attr; /* member attribute found, return it */
963
 
 
964
 
  /* not an attribute, search the methods table */
965
 
  return Py_FindMethod(BPy_Lamp_methods, (PyObject *)self, name);
 
1286
        PyObject *attr = Py_None;
 
1287
 
 
1288
        if( strcmp( name, "name" ) == 0 )
 
1289
                attr = PyString_FromString( self->lamp->id.name + 2 );
 
1290
        else if( strcmp( name, "type" ) == 0 )
 
1291
                attr = PyInt_FromLong( self->lamp->type );
 
1292
        else if( strcmp( name, "mode" ) == 0 )
 
1293
                attr = PyInt_FromLong( self->lamp->mode );
 
1294
        else if( strcmp( name, "samples" ) == 0 )
 
1295
                attr = PyInt_FromLong( self->lamp->samp );
 
1296
        else if( strcmp( name, "bufferSize" ) == 0 )
 
1297
                attr = PyInt_FromLong( self->lamp->bufsize );
 
1298
        else if( strcmp( name, "haloStep" ) == 0 )
 
1299
                attr = PyInt_FromLong( self->lamp->shadhalostep );
 
1300
        else if( strcmp( name, "R" ) == 0 )
 
1301
                attr = PyFloat_FromDouble( self->lamp->r );
 
1302
        else if( strcmp( name, "G" ) == 0 )
 
1303
                attr = PyFloat_FromDouble( self->lamp->g );
 
1304
        else if( strcmp( name, "B" ) == 0 )
 
1305
                attr = PyFloat_FromDouble( self->lamp->b );
 
1306
        else if( strcmp( name, "col" ) == 0 )
 
1307
                attr = Lamp_getCol( self );
 
1308
        else if( strcmp( name, "energy" ) == 0 )
 
1309
                attr = PyFloat_FromDouble( self->lamp->energy );
 
1310
        else if( strcmp( name, "dist" ) == 0 )
 
1311
                attr = PyFloat_FromDouble( self->lamp->dist );
 
1312
        else if( strcmp( name, "spotSize" ) == 0 )
 
1313
                attr = PyFloat_FromDouble( self->lamp->spotsize );
 
1314
        else if( strcmp( name, "spotBlend" ) == 0 )
 
1315
                attr = PyFloat_FromDouble( self->lamp->spotblend );
 
1316
        else if( strcmp( name, "clipStart" ) == 0 )
 
1317
                attr = PyFloat_FromDouble( self->lamp->clipsta );
 
1318
        else if( strcmp( name, "clipEnd" ) == 0 )
 
1319
                attr = PyFloat_FromDouble( self->lamp->clipend );
 
1320
        else if( strcmp( name, "bias" ) == 0 )
 
1321
                attr = PyFloat_FromDouble( self->lamp->bias );
 
1322
        else if( strcmp( name, "softness" ) == 0 )
 
1323
                attr = PyFloat_FromDouble( self->lamp->soft );
 
1324
        else if( strcmp( name, "haloInt" ) == 0 )
 
1325
                attr = PyFloat_FromDouble( self->lamp->haint );
 
1326
        else if( strcmp( name, "quad1" ) == 0 )
 
1327
                attr = PyFloat_FromDouble( self->lamp->att1 );
 
1328
        else if( strcmp( name, "quad2" ) == 0 )
 
1329
                attr = PyFloat_FromDouble( self->lamp->att2 );
 
1330
        else if( strcmp( name, "users" ) == 0 )
 
1331
                attr = PyInt_FromLong( self->lamp->id.us );
 
1332
        
 
1333
        else if( strcmp( name, "Types" ) == 0 ) {
 
1334
                attr = Py_BuildValue( "{s:h,s:h,s:h,s:h,s:h,s:h}",
 
1335
                                      "Lamp", EXPP_LAMP_TYPE_LAMP,
 
1336
                                      "Sun", EXPP_LAMP_TYPE_SUN,
 
1337
                                      "Spot", EXPP_LAMP_TYPE_SPOT,
 
1338
                                      "Hemi", EXPP_LAMP_TYPE_HEMI, 
 
1339
                                      "Area", EXPP_LAMP_TYPE_AREA, 
 
1340
                                      "Photon", EXPP_LAMP_TYPE_YF_PHOTON 
 
1341
                        );
 
1342
        }
 
1343
 
 
1344
        else if( strcmp( name, "Modes" ) == 0 ) {
 
1345
                attr = Py_BuildValue
 
1346
                        ( "{s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h}",
 
1347
                          "Shadows", EXPP_LAMP_MODE_SHADOWS, "Halo",
 
1348
                          EXPP_LAMP_MODE_HALO, "Layer", EXPP_LAMP_MODE_LAYER,
 
1349
                          "Quad", EXPP_LAMP_MODE_QUAD, "Negative",
 
1350
                          EXPP_LAMP_MODE_NEGATIVE, "OnlyShadow",
 
1351
                          EXPP_LAMP_MODE_ONLYSHADOW, "Sphere",
 
1352
                          EXPP_LAMP_MODE_SPHERE, "Square",
 
1353
                          EXPP_LAMP_MODE_SQUARE, "NoDiffuse",
 
1354
                          EXPP_LAMP_MODE_NODIFFUSE, "NoSpecular",
 
1355
                          EXPP_LAMP_MODE_NOSPECULAR );
 
1356
        }
 
1357
        
 
1358
        else if( strcmp( name, "__members__" ) == 0 ) {
 
1359
                /* 23 entries */
 
1360
                attr = Py_BuildValue
 
1361
                        ( "[s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s]",
 
1362
                          "name", "type", "mode", "samples", "bufferSize",
 
1363
                          "haloStep", "R", "G", "B", "energy", "dist",
 
1364
                          "spotSize", "spotBlend", "clipStart", "clipEnd",
 
1365
                          "bias", "softness", "haloInt", "quad1", "quad2",
 
1366
                          "Types", "Modes", "col", "users" );
 
1367
        }
 
1368
 
 
1369
        if( !attr )
 
1370
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 
1371
                                                "couldn't create PyObject" ) );
 
1372
 
 
1373
        if( attr != Py_None )
 
1374
                return attr;    /* member attribute found, return it */
 
1375
 
 
1376
        /* not an attribute, search the methods table */
 
1377
        return Py_FindMethod( BPy_Lamp_methods, ( PyObject * ) self, name );
966
1378
}
967
1379
 
968
1380
/*****************************************************************************/
971
1383
/*              function that changes Lamp Data members values. If this      */
972
1384
/*              data is linked to a Blender Lamp, it also gets updated.      */
973
1385
/*****************************************************************************/
974
 
static int Lamp_setAttr (BPy_Lamp *self, char *name, PyObject *value)
 
1386
static int Lamp_setAttr( BPy_Lamp * self, char *name, PyObject * value )
975
1387
{
976
 
  PyObject *valtuple; 
977
 
  PyObject *error = NULL;
978
 
 
979
 
  valtuple = Py_BuildValue("(O)", value); /*the set* functions expect a tuple*/
980
 
 
981
 
  if (!valtuple)
982
 
    return EXPP_ReturnIntError(PyExc_MemoryError,
983
 
                  "LampSetAttr: couldn't create tuple");
984
 
 
985
 
  if (strcmp (name, "name") == 0)
986
 
    error = Lamp_setName (self, valtuple);
987
 
  else if (strcmp (name, "type") == 0)
988
 
    error = Lamp_setIntType (self, valtuple); /* special case */
989
 
  else if (strcmp (name, "mode") == 0)
990
 
    error = Lamp_setIntMode (self, valtuple); /* special case */
991
 
  else if (strcmp (name, "samples") == 0)
992
 
    error = Lamp_setSamples (self, valtuple);
993
 
  else if (strcmp (name, "bufferSize") == 0)
994
 
    error = Lamp_setBufferSize (self, valtuple);
995
 
  else if (strcmp (name, "haloStep") == 0)
996
 
    error = Lamp_setHaloStep (self, valtuple);
997
 
  else if (strcmp (name, "R") == 0)
998
 
    error = Lamp_setColorComponent (self, "R", valtuple);
999
 
  else if (strcmp (name, "G") == 0)
1000
 
    error = Lamp_setColorComponent (self, "G", valtuple);
1001
 
  else if (strcmp (name, "B") == 0)
1002
 
    error = Lamp_setColorComponent (self, "B", valtuple);
1003
 
  else if (strcmp (name, "energy") == 0)
1004
 
    error = Lamp_setEnergy (self, valtuple);
1005
 
  else if (strcmp (name, "dist") == 0)
1006
 
    error = Lamp_setDist (self, valtuple);
1007
 
  else if (strcmp (name, "spotSize") == 0)
1008
 
    error = Lamp_setSpotSize (self, valtuple);
1009
 
  else if (strcmp (name, "spotBlend") == 0)
1010
 
    error = Lamp_setSpotBlend (self, valtuple);
1011
 
  else if (strcmp (name, "clipStart") == 0)
1012
 
    error = Lamp_setClipStart (self, valtuple);
1013
 
  else if (strcmp (name, "clipEnd") == 0)
1014
 
    error = Lamp_setClipEnd (self, valtuple);
1015
 
  else if (strcmp (name, "bias") == 0)
1016
 
    error = Lamp_setBias (self, valtuple);
1017
 
  else if (strcmp (name, "softness") == 0)
1018
 
    error = Lamp_setSoftness (self, valtuple);
1019
 
  else if (strcmp (name, "haloInt") == 0)
1020
 
    error = Lamp_setHaloInt (self, valtuple);
1021
 
  else if (strcmp (name, "quad1") == 0)
1022
 
    error = Lamp_setQuad1 (self, valtuple);
1023
 
  else if (strcmp (name, "quad2") == 0)
1024
 
    error = Lamp_setQuad2 (self, valtuple);
1025
 
  else if (strcmp (name, "col") == 0)
1026
 
    error = Lamp_setCol (self, valtuple);
1027
 
 
1028
 
  else { /* Error */
1029
 
    Py_DECREF(valtuple);
1030
 
  
1031
 
    if ((strcmp (name, "Types") == 0) || /* user tried to change a */
1032
 
        (strcmp (name, "Modes") == 0))   /* constant dict type ... */
1033
 
      return (EXPP_ReturnIntError (PyExc_AttributeError,
1034
 
                   "constant dictionary -- cannot be changed"));
1035
 
 
1036
 
    else /* ... or no member with the given name was found */
1037
 
      return (EXPP_ReturnIntError (PyExc_AttributeError,
1038
 
                   "attribute not found"));
1039
 
  }
1040
 
 
1041
 
  Py_DECREF(valtuple);
1042
 
  
1043
 
  if (error != Py_None) return -1;
1044
 
 
1045
 
  Py_DECREF(Py_None); /* was incref'ed by the called Lamp_set* function */
1046
 
  return 0; /* normal exit */
 
1388
        PyObject *valtuple;
 
1389
        PyObject *error = NULL;
 
1390
 
 
1391
        valtuple = Py_BuildValue( "(O)", value );       /*the set* functions expect a tuple */
 
1392
 
 
1393
        if( !valtuple )
 
1394
                return EXPP_ReturnIntError( PyExc_MemoryError,
 
1395
                                            "LampSetAttr: couldn't create tuple" );
 
1396
 
 
1397
        if( strcmp( name, "name" ) == 0 )
 
1398
                error = Lamp_setName( self, valtuple );
 
1399
        else if( strcmp( name, "type" ) == 0 )
 
1400
                error = Lamp_setIntType( self, valtuple );      /* special case */
 
1401
        else if( strcmp( name, "mode" ) == 0 )
 
1402
                error = Lamp_setIntMode( self, valtuple );      /* special case */
 
1403
        else if( strcmp( name, "samples" ) == 0 )
 
1404
                error = Lamp_setSamples( self, valtuple );
 
1405
        else if( strcmp( name, "bufferSize" ) == 0 )
 
1406
                error = Lamp_setBufferSize( self, valtuple );
 
1407
        else if( strcmp( name, "haloStep" ) == 0 )
 
1408
                error = Lamp_setHaloStep( self, valtuple );
 
1409
        else if( strcmp( name, "R" ) == 0 )
 
1410
                error = Lamp_setColorComponent( self, "R", valtuple );
 
1411
        else if( strcmp( name, "G" ) == 0 )
 
1412
                error = Lamp_setColorComponent( self, "G", valtuple );
 
1413
        else if( strcmp( name, "B" ) == 0 )
 
1414
                error = Lamp_setColorComponent( self, "B", valtuple );
 
1415
        else if( strcmp( name, "energy" ) == 0 )
 
1416
                error = Lamp_setEnergy( self, valtuple );
 
1417
        else if( strcmp( name, "dist" ) == 0 )
 
1418
                error = Lamp_setDist( self, valtuple );
 
1419
        else if( strcmp( name, "spotSize" ) == 0 )
 
1420
                error = Lamp_setSpotSize( self, valtuple );
 
1421
        else if( strcmp( name, "spotBlend" ) == 0 )
 
1422
                error = Lamp_setSpotBlend( self, valtuple );
 
1423
        else if( strcmp( name, "clipStart" ) == 0 )
 
1424
                error = Lamp_setClipStart( self, valtuple );
 
1425
        else if( strcmp( name, "clipEnd" ) == 0 )
 
1426
                error = Lamp_setClipEnd( self, valtuple );
 
1427
        else if( strcmp( name, "bias" ) == 0 )
 
1428
                error = Lamp_setBias( self, valtuple );
 
1429
        else if( strcmp( name, "softness" ) == 0 )
 
1430
                error = Lamp_setSoftness( self, valtuple );
 
1431
        else if( strcmp( name, "haloInt" ) == 0 )
 
1432
                error = Lamp_setHaloInt( self, valtuple );
 
1433
        else if( strcmp( name, "quad1" ) == 0 )
 
1434
                error = Lamp_setQuad1( self, valtuple );
 
1435
        else if( strcmp( name, "quad2" ) == 0 )
 
1436
                error = Lamp_setQuad2( self, valtuple );
 
1437
        else if( strcmp( name, "col" ) == 0 )
 
1438
                error = Lamp_setCol( self, valtuple );
 
1439
 
 
1440
        else {                  /* Error */
 
1441
                Py_DECREF( valtuple );
 
1442
 
 
1443
                if( ( strcmp( name, "Types" ) == 0 ) || /* user tried to change a */
 
1444
                    ( strcmp( name, "Modes" ) == 0 ) )  /* constant dict type ... */
 
1445
                        return ( EXPP_ReturnIntError( PyExc_AttributeError,
 
1446
                                                      "constant dictionary -- cannot be changed" ) );
 
1447
 
 
1448
                else    /* ... or no member with the given name was found */
 
1449
                        return ( EXPP_ReturnIntError( PyExc_AttributeError,
 
1450
                                                      "attribute not found" ) );
 
1451
        }
 
1452
 
 
1453
        Py_DECREF( valtuple );
 
1454
 
 
1455
        if( error != Py_None )
 
1456
                return -1;
 
1457
 
 
1458
        Py_DECREF( Py_None );   /* was incref'ed by the called Lamp_set* function */
 
1459
        return 0;               /* normal exit */
1047
1460
}
1048
1461
 
1049
1462
/*****************************************************************************/
1054
1467
/*              they don't point to the same Blender Lamp struct.            */
1055
1468
/*              In Python it becomes 1 if they are equal, 0 otherwise.       */
1056
1469
/*****************************************************************************/
1057
 
static int Lamp_compare (BPy_Lamp *a, BPy_Lamp *b)
 
1470
static int Lamp_compare( BPy_Lamp * a, BPy_Lamp * b )
1058
1471
{
1059
 
  Lamp *pa = a->lamp, *pb = b->lamp;
1060
 
  return (pa == pb) ? 0:-1;
 
1472
        Lamp *pa = a->lamp, *pb = b->lamp;
 
1473
        return ( pa == pb ) ? 0 : -1;
1061
1474
}
1062
1475
 
1063
1476
/*****************************************************************************/
1065
1478
/* Description: This is a callback function for the BPy_Lamp type. It        */
1066
1479
/*              builds a meaninful string to represent lamp objects.         */
1067
1480
/*****************************************************************************/
1068
 
static PyObject *Lamp_repr (BPy_Lamp *self)
1069
 
{
1070
 
  return PyString_FromFormat("[Lamp \"%s\"]", self->lamp->id.name+2);
 
1481
static PyObject *Lamp_repr( BPy_Lamp * self )
 
1482
{
 
1483
        return PyString_FromFormat( "[Lamp \"%s\"]", self->lamp->id.name + 2 );
 
1484
}
 
1485
 
 
1486
static PyObject *Lamp_getIpo( BPy_Lamp * self )
 
1487
{
 
1488
        struct Ipo *ipo = self->lamp->ipo;
 
1489
 
 
1490
        if( !ipo ) {
 
1491
                Py_INCREF( Py_None );
 
1492
                return Py_None;
 
1493
        }
 
1494
 
 
1495
        return Ipo_CreatePyObject( ipo );
 
1496
}
 
1497
 
 
1498
extern PyTypeObject Ipo_Type;
 
1499
 
 
1500
static PyObject *Lamp_setIpo( BPy_Lamp * self, PyObject * args )
 
1501
{
 
1502
        PyObject *pyipo = 0;
 
1503
        Ipo *ipo = NULL;
 
1504
        Ipo *oldipo;
 
1505
 
 
1506
        if( !PyArg_ParseTuple( args, "O!", &Ipo_Type, &pyipo ) )
 
1507
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1508
                                              "expected Ipo as argument" );
 
1509
 
 
1510
        ipo = Ipo_FromPyObject( pyipo );
 
1511
 
 
1512
        if( !ipo )
 
1513
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
1514
                                              "null ipo!" );
 
1515
 
 
1516
        if( ipo->blocktype != ID_LA )
 
1517
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1518
                                              "this ipo is not a lamp data ipo" );
 
1519
 
 
1520
        oldipo = self->lamp->ipo;
 
1521
        if( oldipo ) {
 
1522
                ID *id = &oldipo->id;
 
1523
                if( id->us > 0 )
 
1524
                        id->us--;
 
1525
        }
 
1526
 
 
1527
        ( ( ID * ) & ipo->id )->us++;
 
1528
 
 
1529
        self->lamp->ipo = ipo;
 
1530
 
 
1531
        Py_INCREF( Py_None );
 
1532
        return Py_None;
 
1533
}
 
1534
 
 
1535
static PyObject *Lamp_clearIpo( BPy_Lamp * self )
 
1536
{
 
1537
        Lamp *lamp = self->lamp;
 
1538
        Ipo *ipo = ( Ipo * ) lamp->ipo;
 
1539
 
 
1540
        if( ipo ) {
 
1541
                ID *id = &ipo->id;
 
1542
                if( id->us > 0 )
 
1543
                        id->us--;
 
1544
                lamp->ipo = NULL;
 
1545
 
 
1546
                return EXPP_incr_ret_True();
 
1547
        }
 
1548
 
 
1549
        return EXPP_incr_ret_False(); /* no ipo found */
 
1550
}
 
1551
 
 
1552
/*
 
1553
 * Lamp_insertIpoKey()
 
1554
 *  inserts Lamp IPO key for RGB,ENERGY,SPOTSIZE,OFFSET,SIZE
 
1555
 */
 
1556
 
 
1557
static PyObject *Lamp_insertIpoKey( BPy_Lamp * self, PyObject * args )
 
1558
{
 
1559
        int key = 0, map;
 
1560
 
 
1561
        if( !PyArg_ParseTuple( args, "i", &( key ) ) )
 
1562
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
1563
                                                                                "expected int argument" ) );
 
1564
 
 
1565
        map = texchannel_to_adrcode(self->lamp->texact);
 
1566
 
 
1567
        if (key == IPOKEY_RGB ) {
 
1568
                insertkey((ID *)self->lamp,LA_COL_R);
 
1569
                insertkey((ID *)self->lamp,LA_COL_G);
 
1570
                insertkey((ID *)self->lamp,LA_COL_B);      
 
1571
        }
 
1572
        if (key == IPOKEY_ENERGY ) {
 
1573
                insertkey((ID *)self->lamp,LA_ENERGY);    
 
1574
        }       
 
1575
        if (key == IPOKEY_SPOTSIZE ) {
 
1576
                insertkey((ID *)self->lamp,LA_SPOTSI);    
 
1577
        }
 
1578
        if (key == IPOKEY_OFFSET ) {
 
1579
                insertkey((ID *)self->lamp, map+MAP_OFS_X);
 
1580
                insertkey((ID *)self->lamp, map+MAP_OFS_Y);
 
1581
                insertkey((ID *)self->lamp, map+MAP_OFS_Z);  
 
1582
        }
 
1583
        if (key == IPOKEY_SIZE ) {
 
1584
                insertkey((ID *)self->lamp, map+MAP_SIZE_X);
 
1585
                insertkey((ID *)self->lamp, map+MAP_SIZE_Y);
 
1586
                insertkey((ID *)self->lamp, map+MAP_SIZE_Z);  
 
1587
        }
 
1588
 
 
1589
        allspace(REMAKEIPO, 0);
 
1590
        EXPP_allqueue(REDRAWIPO, 0);
 
1591
        EXPP_allqueue(REDRAWVIEW3D, 0);
 
1592
        EXPP_allqueue(REDRAWACTION, 0);
 
1593
        EXPP_allqueue(REDRAWNLA, 0);
 
1594
 
 
1595
        return EXPP_incr_ret( Py_None );
1071
1596
}