38968b64cf51a569da080ec165b9848fb0ac8ea1
[blender.git] / source / blender / python / api2_2x / Lamp.c
1 /* 
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * This is a new part of Blender.
24  *
25  * Contributor(s): Willian P. Germano, Nathan Letwory, Stephen Swaney,
26  * Ken Hughes
27  *
28  * ***** END GPL LICENSE BLOCK *****
29 */
30
31 #include "Lamp.h" /*This must come first*/
32
33 #include "BKE_main.h"
34 #include "BKE_global.h"
35 #include "BKE_object.h"
36 #include "BKE_library.h"
37 #include "BKE_texture.h"
38 #include "BLI_blenlib.h"
39 #include "BIF_keyframing.h"
40 #include "BIF_space.h"
41 #include "BSE_editipo.h"
42 #include "mydevice.h"
43 #include "Ipo.h"
44 #include "MTex.h" 
45 #include "constant.h"
46 #include "gen_utils.h"
47 #include "gen_library.h"
48 #include "BKE_utildefines.h"
49 #include "MEM_guardedalloc.h"
50
51 /*****************************************************************************/
52 /* Python BPy_Lamp defaults:                                                 */
53 /*****************************************************************************/
54
55 /* Lamp types */
56
57 /* NOTE:
58  these are the same values as LA_* from DNA_lamp_types.h
59  is there some reason we are not simply using those #defines?
60  s. swaney 8-oct-2004
61 */
62
63 #define EXPP_LAMP_TYPE_LAMP 0
64 #define EXPP_LAMP_TYPE_SUN  1
65 #define EXPP_LAMP_TYPE_SPOT 2
66 #define EXPP_LAMP_TYPE_HEMI 3
67 #define EXPP_LAMP_TYPE_AREA 4
68 #define EXPP_LAMP_TYPE_YF_PHOTON 5
69 /*
70   define a constant to keep magic numbers out of the code
71   this value should be equal to the last EXPP_LAMP_TYPE_*
72 */
73 #define EXPP_LAMP_TYPE_MAX  5
74
75 /* Lamp mode flags */
76
77 #define EXPP_LAMP_MODE_SHADOWS       1
78 #define EXPP_LAMP_MODE_HALO          2
79 #define EXPP_LAMP_MODE_LAYER         4
80 #define EXPP_LAMP_MODE_QUAD          8
81 #define EXPP_LAMP_MODE_NEGATIVE     16
82 #define EXPP_LAMP_MODE_ONLYSHADOW   32
83 #define EXPP_LAMP_MODE_SPHERE       64
84 #define EXPP_LAMP_MODE_SQUARE      128
85 #define EXPP_LAMP_MODE_TEXTURE     256
86 #define EXPP_LAMP_MODE_OSATEX      512
87 #define EXPP_LAMP_MODE_DEEPSHADOW 1024
88 #define EXPP_LAMP_MODE_NODIFFUSE  2048
89 #define EXPP_LAMP_MODE_NOSPECULAR 4096
90 #define EXPP_LAMP_MODE_SHAD_RAY   8192
91 #define EXPP_LAMP_MODE_LAYER_SHADOW 32768
92
93 /* Lamp MIN, MAX values */
94
95 #define EXPP_LAMP_SAMPLES_MIN 1
96 #define EXPP_LAMP_SAMPLES_MAX 16
97 #define EXPP_LAMP_BUFFERSIZE_MIN 512
98 #define EXPP_LAMP_BUFFERSIZE_MAX 5120
99 #define EXPP_LAMP_ENERGY_MIN  0.0
100 #define EXPP_LAMP_ENERGY_MAX 10.0
101 #define EXPP_LAMP_DIST_MIN    0.1f
102 #define EXPP_LAMP_DIST_MAX 5000.0
103 #define EXPP_LAMP_SPOTSIZE_MIN   1.0
104 #define EXPP_LAMP_SPOTSIZE_MAX 180.0
105 #define EXPP_LAMP_SPOTBLEND_MIN 0.00
106 #define EXPP_LAMP_SPOTBLEND_MAX 1.00
107 #define EXPP_LAMP_CLIPSTART_MIN    0.1f
108 #define EXPP_LAMP_CLIPSTART_MAX 1000.0
109 #define EXPP_LAMP_CLIPEND_MIN    1.0
110 #define EXPP_LAMP_CLIPEND_MAX 5000.0
111 #define EXPP_LAMP_BIAS_MIN 0.01f
112 #define EXPP_LAMP_BIAS_MAX 5.00
113 #define EXPP_LAMP_SOFTNESS_MIN   1.0
114 #define EXPP_LAMP_SOFTNESS_MAX 100.0
115 #define EXPP_LAMP_HALOINT_MIN 0.0
116 #define EXPP_LAMP_HALOINT_MAX 5.0
117 #define EXPP_LAMP_HALOSTEP_MIN  0
118 #define EXPP_LAMP_HALOSTEP_MAX 12
119 #define EXPP_LAMP_QUAD1_MIN 0.0
120 #define EXPP_LAMP_QUAD1_MAX 1.0
121 #define EXPP_LAMP_QUAD2_MIN 0.0
122 #define EXPP_LAMP_QUAD2_MAX 1.0
123 #define EXPP_LAMP_COL_MIN 0.0
124 #define EXPP_LAMP_COL_MAX 1.0
125 #define EXPP_LAMP_FALLOFF_MIN LA_FALLOFF_CONSTANT
126 #define EXPP_LAMP_FALLOFF_MAX LA_FALLOFF_SLIDERS
127
128 /* Raytracing settings */
129 #define EXPP_LAMP_RAYSAMPLES_MIN 1
130 #define EXPP_LAMP_RAYSAMPLES_MAX 16
131 #define EXPP_LAMP_AREASIZE_MIN 0.01f
132 #define EXPP_LAMP_AREASIZE_MAX 100.0f
133
134 /* Lamp_setComponent() keys for which color to get/set */
135 #define EXPP_LAMP_COMP_R                        0x00
136 #define EXPP_LAMP_COMP_G                        0x01
137 #define EXPP_LAMP_COMP_B                        0x02
138
139 #define IPOKEY_RGB       0
140 #define IPOKEY_ENERGY    1
141 #define IPOKEY_SPOTSIZE  2
142 #define IPOKEY_OFFSET    3
143 #define IPOKEY_SIZE      4
144
145 /*****************************************************************************/
146 /* Python API function prototypes for the Lamp module.                       */
147 /*****************************************************************************/
148 static PyObject *M_Lamp_New( PyObject * self, PyObject * args,
149                              PyObject * keywords );
150 static PyObject *M_Lamp_Get( PyObject * self, PyObject * args );
151
152 /*****************************************************************************/
153 /* The following string definitions are used for documentation strings.      */
154 /* In Python these will be written to the console when doing a               */
155 /* Blender.Lamp.__doc__                                                      */
156 /*****************************************************************************/
157 static char M_Lamp_doc[] = "The Blender Lamp module\n\n\
158 This module provides control over **Lamp Data** objects in Blender.\n\n\
159 Example::\n\n\
160   from Blender import Lamp\n\
161   l = Lamp.New('Spot')            # create new 'Spot' lamp data\n\
162   l.setMode('square', 'shadow')   # set these two lamp mode flags\n\
163   ob = Object.New('Lamp')         # create new lamp object\n\
164   ob.link(l)                      # link lamp obj with lamp data\n";
165
166 static char M_Lamp_New_doc[] = "Lamp.New (type = 'Lamp', name = 'LampData'):\n\
167         Return a new Lamp Data object with the given type and name.";
168
169 static char M_Lamp_Get_doc[] = "Lamp.Get (name = None):\n\
170         Return the Lamp Data with the given name, None if not found, or\n\
171         Return a list with all Lamp Data objects in the current scene,\n\
172         if no argument was given.";
173
174 /*****************************************************************************/
175 /* Python method structure definition for Blender.Lamp module:               */
176 /*****************************************************************************/
177 struct PyMethodDef M_Lamp_methods[] = {
178         {"New", ( PyCFunction ) M_Lamp_New, METH_VARARGS | METH_KEYWORDS,
179          M_Lamp_New_doc},
180         {"Get", M_Lamp_Get, METH_VARARGS, M_Lamp_Get_doc},
181         {"get", M_Lamp_Get, METH_VARARGS, M_Lamp_Get_doc},
182         {NULL, NULL, 0, NULL}
183 };
184
185 /*****************************************************************************/
186 /* Python BPy_Lamp methods declarations:                                     */
187 /*****************************************************************************/
188 static PyObject *Lamp_getType( BPy_Lamp * self );
189 static PyObject *Lamp_getTypesConst( void );
190 static PyObject *Lamp_getMode( BPy_Lamp * self );
191 static PyObject *Lamp_getModesConst( void );
192 static PyObject *Lamp_getSamples( BPy_Lamp * self );
193 static PyObject *Lamp_getRaySamplesX( BPy_Lamp * self );
194 static PyObject *Lamp_getRaySamplesY( BPy_Lamp * self );
195 static PyObject *Lamp_getAreaSizeX( BPy_Lamp * self );
196 static PyObject *Lamp_getAreaSizeY( BPy_Lamp * self );
197 static PyObject *Lamp_getBufferSize( BPy_Lamp * self );
198 static PyObject *Lamp_getHaloStep( BPy_Lamp * self );
199 static PyObject *Lamp_getEnergy( BPy_Lamp * self );
200 static PyObject *Lamp_getDist( BPy_Lamp * self );
201 static PyObject *Lamp_getSpotSize( BPy_Lamp * self );
202 static PyObject *Lamp_getSpotBlend( BPy_Lamp * self );
203 static PyObject *Lamp_getClipStart( BPy_Lamp * self );
204 static PyObject *Lamp_getClipEnd( BPy_Lamp * self );
205 static PyObject *Lamp_getBias( BPy_Lamp * self );
206 static PyObject *Lamp_getSoftness( BPy_Lamp * self );
207 static PyObject *Lamp_getHaloInt( BPy_Lamp * self );
208 static PyObject *Lamp_getQuad1( BPy_Lamp * self );
209 static PyObject *Lamp_getQuad2( BPy_Lamp * self );
210 static PyObject *Lamp_getCol( BPy_Lamp * self );
211 static PyObject *Lamp_getIpo( BPy_Lamp * self );
212 static PyObject *Lamp_getComponent( BPy_Lamp * self, void * closure );
213 static PyObject *Lamp_getTextures( BPy_Lamp * self );
214 static PyObject *Lamp_clearIpo( BPy_Lamp * self );
215 static PyObject *Lamp_insertIpoKey( BPy_Lamp * self, PyObject * args );
216 static PyObject *Lamp_oldsetIpo( BPy_Lamp * self, PyObject * args );
217 static PyObject *Lamp_oldsetType( BPy_Lamp * self, PyObject * value );
218 static PyObject *Lamp_oldsetMode( BPy_Lamp * self, PyObject * args );
219 static PyObject *Lamp_oldsetSamples( BPy_Lamp * self, PyObject * args );
220 static PyObject *Lamp_oldsetRaySamplesX( BPy_Lamp * self, PyObject * args );
221 static PyObject *Lamp_oldsetRaySamplesY( BPy_Lamp * self, PyObject * args );
222 static PyObject *Lamp_oldsetAreaSizeX( BPy_Lamp * self, PyObject * args );
223 static PyObject *Lamp_oldsetAreaSizeY( BPy_Lamp * self, PyObject * args );
224 static PyObject *Lamp_oldsetBufferSize( BPy_Lamp * self, PyObject * args );
225 static PyObject *Lamp_oldsetHaloStep( BPy_Lamp * self, PyObject * args );
226 static PyObject *Lamp_oldsetEnergy( BPy_Lamp * self, PyObject * args );
227 static PyObject *Lamp_oldsetDist( BPy_Lamp * self, PyObject * args );
228 static PyObject *Lamp_oldsetSpotSize( BPy_Lamp * self, PyObject * args );
229 static PyObject *Lamp_oldsetSpotBlend( BPy_Lamp * self, PyObject * args );
230 static PyObject *Lamp_oldsetClipStart( BPy_Lamp * self, PyObject * args );
231 static PyObject *Lamp_oldsetClipEnd( BPy_Lamp * self, PyObject * args );
232 static PyObject *Lamp_oldsetBias( BPy_Lamp * self, PyObject * args );
233 static PyObject *Lamp_oldsetSoftness( BPy_Lamp * self, PyObject * args );
234 static PyObject *Lamp_oldsetHaloInt( BPy_Lamp * self, PyObject * args );
235 static PyObject *Lamp_oldsetQuad1( BPy_Lamp * self, PyObject * args );
236 static PyObject *Lamp_oldsetQuad2( BPy_Lamp * self, PyObject * args );
237 static PyObject *Lamp_oldsetCol( BPy_Lamp * self, PyObject * args );
238 static PyObject *Lamp_copy( BPy_Lamp * self );
239 static int Lamp_setIpo( BPy_Lamp * self, PyObject * args );
240 static int Lamp_setType( BPy_Lamp * self, PyObject * args );
241 static int Lamp_setMode( BPy_Lamp * self, PyObject * args );
242 static int Lamp_setSamples( BPy_Lamp * self, PyObject * args );
243 static int Lamp_setRaySamplesX( BPy_Lamp * self, PyObject * args );
244 static int Lamp_setRaySamplesY( BPy_Lamp * self, PyObject * args );
245 static int Lamp_setAreaSizeX( BPy_Lamp * self, PyObject * args );
246 static int Lamp_setAreaSizeY( BPy_Lamp * self, PyObject * args );
247 static int Lamp_setBufferSize( BPy_Lamp * self, PyObject * args );
248 static int Lamp_setHaloStep( BPy_Lamp * self, PyObject * args );
249 static int Lamp_setEnergy( BPy_Lamp * self, PyObject * args );
250 static int Lamp_setDist( BPy_Lamp * self, PyObject * args );
251 static int Lamp_setSpotSize( BPy_Lamp * self, PyObject * args );
252 static int Lamp_setSpotBlend( BPy_Lamp * self, PyObject * args );
253 static int Lamp_setClipStart( BPy_Lamp * self, PyObject * args );
254 static int Lamp_setClipEnd( BPy_Lamp * self, PyObject * args );
255 static int Lamp_setBias( BPy_Lamp * self, PyObject * args );
256 static int Lamp_setSoftness( BPy_Lamp * self, PyObject * args );
257 static int Lamp_setHaloInt( BPy_Lamp * self, PyObject * args );
258 static int Lamp_setQuad1( BPy_Lamp * self, PyObject * args );
259 static int Lamp_setQuad2( BPy_Lamp * self, PyObject * args );
260 static int Lamp_setCol( BPy_Lamp * self, PyObject * args );
261 static int Lamp_setTextures( BPy_Lamp * self, PyObject * value );
262 static PyObject *Lamp_getScriptLinks( BPy_Lamp * self, PyObject * value );
263 static PyObject *Lamp_addScriptLink( BPy_Lamp * self, PyObject * args );
264 static PyObject *Lamp_clearScriptLinks( BPy_Lamp * self, PyObject * args );
265 static int Lamp_setComponent( BPy_Lamp * self, PyObject * value, void * closure );
266 static PyObject *Lamp_getFalloffType( BPy_Lamp * self );
267 static int Lamp_setFalloffType( BPy_Lamp * self, PyObject * value );
268
269 /*****************************************************************************/
270 /* Python BPy_Lamp methods table:                                            */
271 /*****************************************************************************/
272 static PyMethodDef BPy_Lamp_methods[] = {
273         /* name, method, flags, doc */
274         
275         {"getType", ( PyCFunction ) Lamp_getType, METH_NOARGS,
276          "() - return Lamp type - 'Lamp':0, 'Sun':1, 'Spot':2, 'Hemi':3, 'Area':4, 'Photon':5"},
277         {"getMode", ( PyCFunction ) Lamp_getMode, METH_NOARGS,
278          "() - return Lamp mode flags (or'ed value)"},
279         {"getSamples", ( PyCFunction ) Lamp_getSamples, METH_NOARGS,
280          "() - return Lamp samples value"},
281         {"getRaySamplesX", ( PyCFunction ) Lamp_getRaySamplesX, METH_NOARGS,
282          "() - return Lamp raytracing samples on the X axis"},
283         {"getRaySamplesY", ( PyCFunction ) Lamp_getRaySamplesY, METH_NOARGS,
284          "() - return Lamp raytracing samples on the Y axis"},
285         {"getAreaSizeX", ( PyCFunction ) Lamp_getAreaSizeX, METH_NOARGS,
286          "() - return Lamp area size on the X axis"},
287         {"getAreaSizeY", ( PyCFunction ) Lamp_getAreaSizeY, METH_NOARGS,
288          "() - return Lamp area size on the Y axis"},
289         {"getBufferSize", ( PyCFunction ) Lamp_getBufferSize, METH_NOARGS,
290          "() - return Lamp buffer size value"},
291         {"getHaloStep", ( PyCFunction ) Lamp_getHaloStep, METH_NOARGS,
292          "() - return Lamp halo step value"},
293         {"getEnergy", ( PyCFunction ) Lamp_getEnergy, METH_NOARGS,
294          "() - return Lamp energy value"},
295         {"getDist", ( PyCFunction ) Lamp_getDist, METH_NOARGS,
296          "() - return Lamp clipping distance value"},
297         {"getSpotSize", ( PyCFunction ) Lamp_getSpotSize, METH_NOARGS,
298          "() - return Lamp spot size value"},
299         {"getSpotBlend", ( PyCFunction ) Lamp_getSpotBlend, METH_NOARGS,
300          "() - return Lamp spot blend value"},
301         {"getClipStart", ( PyCFunction ) Lamp_getClipStart, METH_NOARGS,
302          "() - return Lamp clip start value"},
303         {"getClipEnd", ( PyCFunction ) Lamp_getClipEnd, METH_NOARGS,
304          "() - return Lamp clip end value"},
305         {"getBias", ( PyCFunction ) Lamp_getBias, METH_NOARGS,
306          "() - return Lamp bias value"},
307         {"getSoftness", ( PyCFunction ) Lamp_getSoftness, METH_NOARGS,
308          "() - return Lamp softness value"},
309         {"getHaloInt", ( PyCFunction ) Lamp_getHaloInt, METH_NOARGS,
310          "() - return Lamp halo intensity value"},
311         {"getQuad1", ( PyCFunction ) Lamp_getQuad1, METH_NOARGS,
312          "() - return light intensity value #1 for a Quad Lamp"},
313         {"getQuad2", ( PyCFunction ) Lamp_getQuad2, METH_NOARGS,
314          "() - return light intensity value #2 for a Quad Lamp"},
315         {"getCol", ( PyCFunction ) Lamp_getCol, METH_NOARGS,
316          "() - return light rgb color triplet"},
317         {"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
318          "(str) - rename Lamp"},
319         {"setType", ( PyCFunction ) Lamp_oldsetType, METH_O,
320          "(str) - change Lamp type, which can be 'Lamp', 'Sun', 'Spot', 'Hemi', 'Area', 'Photon'"},
321         {"setMode", ( PyCFunction ) Lamp_oldsetMode, METH_VARARGS,
322          "([up to eight str's]) - Set Lamp mode flag(s)"},
323         {"setSamples", ( PyCFunction ) Lamp_oldsetSamples, METH_VARARGS,
324          "(int) - change Lamp samples value"},
325         {"setRaySamplesX", ( PyCFunction ) Lamp_oldsetRaySamplesX, METH_VARARGS,
326          "(int) - change Lamp ray X samples value in [1,16]"},
327         {"setRaySamplesY", ( PyCFunction ) Lamp_oldsetRaySamplesY, METH_VARARGS,
328          "(int) - change Lamp ray Y samples value in [1,16]"},
329         {"setAreaSizeX", ( PyCFunction ) Lamp_oldsetAreaSizeX, METH_VARARGS,
330          "(float) - change Lamp ray X size for area lamps, value in [0.01, 100.0]"},
331         {"setAreaSizeY", ( PyCFunction ) Lamp_oldsetAreaSizeY, METH_VARARGS,
332          "(float) - change Lamp ray Y size for area lamps, value in [0.01, 100.0]"},
333         {"setBufferSize", ( PyCFunction ) Lamp_oldsetBufferSize, METH_VARARGS,
334          "(int) - change Lamp buffer size value"},
335         {"setHaloStep", ( PyCFunction ) Lamp_oldsetHaloStep, METH_VARARGS,
336          "(int) - change Lamp halo step value"},
337         {"setEnergy", ( PyCFunction ) Lamp_oldsetEnergy, METH_VARARGS,
338          "(float) - change Lamp energy value"},
339         {"setDist", ( PyCFunction ) Lamp_oldsetDist, METH_VARARGS,
340          "(float) - change Lamp clipping distance value"},
341         {"setSpotSize", ( PyCFunction ) Lamp_oldsetSpotSize, METH_VARARGS,
342          "(float) - change Lamp spot size value"},
343         {"setSpotBlend", ( PyCFunction ) Lamp_oldsetSpotBlend, METH_VARARGS,
344          "(float) - change Lamp spot blend value"},
345         {"setClipStart", ( PyCFunction ) Lamp_oldsetClipStart, METH_VARARGS,
346          "(float) - change Lamp clip start value"},
347         {"setClipEnd", ( PyCFunction ) Lamp_oldsetClipEnd, METH_VARARGS,
348          "(float) - change Lamp clip end value"},
349         {"setBias", ( PyCFunction ) Lamp_oldsetBias, METH_VARARGS,
350          "(float) - change Lamp draw size value"},
351         {"setSoftness", ( PyCFunction ) Lamp_oldsetSoftness, METH_VARARGS,
352          "(float) - change Lamp softness value"},
353         {"setHaloInt", ( PyCFunction ) Lamp_oldsetHaloInt, METH_VARARGS,
354          "(float) - change Lamp halo intensity value"},
355         {"setQuad1", ( PyCFunction ) Lamp_oldsetQuad1, METH_VARARGS,
356          "(float) - change light intensity value #1 for a Quad Lamp"},
357         {"setQuad2", ( PyCFunction ) Lamp_oldsetQuad2, METH_VARARGS,
358          "(float) - change light intensity value #2 for a Quad Lamp"},
359         {"setCol", ( PyCFunction ) Lamp_oldsetCol, METH_VARARGS,
360          "(f,f,f) or ([f,f,f]) - change light's rgb color triplet"},
361         {"getScriptLinks", ( PyCFunction ) Lamp_getScriptLinks, METH_O,
362          "(eventname) - Get a list of this lamp's scriptlinks (Text names) "
363          "of the given type\n"
364          "(eventname) - string: FrameChanged, Redraw or Render."},
365         {"addScriptLink", ( PyCFunction ) Lamp_addScriptLink, METH_VARARGS,
366          "(text, evt) - Add a new lamp scriptlink.\n"
367          "(text) - string: an existing Blender Text name;\n"
368          "(evt) string: FrameChanged, Redraw or Render."},
369         {"clearScriptLinks", ( PyCFunction ) Lamp_clearScriptLinks,
370          METH_VARARGS,
371          "() - Delete all scriptlinks from this lamp.\n"
372          "([s1<,s2,s3...>]) - Delete specified scriptlinks from this lamp."},
373         {"getIpo", ( PyCFunction ) Lamp_getIpo, METH_NOARGS,
374          "() - get IPO for this lamp"},
375         {"clearIpo", ( PyCFunction ) Lamp_clearIpo, METH_NOARGS,
376          "() - unlink the IPO for this lamp"},
377         {"setIpo", ( PyCFunction ) Lamp_oldsetIpo, METH_VARARGS,
378          "( lamp-ipo ) - link an IPO to this lamp"},
379          {"insertIpoKey", ( PyCFunction ) Lamp_insertIpoKey, METH_VARARGS,
380          "( Lamp IPO type ) - Inserts a key into IPO"},
381         {"__copy__", ( PyCFunction ) Lamp_copy, METH_NOARGS,
382          "() - Makes a copy of this lamp."},
383         {"copy", ( PyCFunction ) Lamp_copy, METH_NOARGS,
384          "() - Makes a copy of this lamp."},
385         {NULL, NULL, 0, NULL}
386 };
387
388 /*****************************************************************************/
389 /* Python attributes get/set structure:                                      */
390 /*****************************************************************************/
391 static PyGetSetDef BPy_Lamp_getseters[] = {
392         GENERIC_LIB_GETSETATTR,
393         {"bias",
394          (getter)Lamp_getBias, (setter)Lamp_setBias,
395          "Lamp shadow map sampling bias",
396          NULL},
397         {"bufferSize",
398          (getter)Lamp_getBufferSize, (setter)Lamp_setBufferSize,
399          "Lamp shadow buffer size",
400          NULL},
401         {"clipEnd",
402          (getter)Lamp_getClipEnd, (setter)Lamp_setClipEnd,
403          "Lamp shadow map clip end",
404          NULL},
405         {"clipStart",
406          (getter)Lamp_getClipStart, (setter)Lamp_setClipStart,
407          "Lamp shadow map clip start",
408          NULL},
409         {"col",
410          (getter)Lamp_getCol, (setter)Lamp_setCol,
411          "Lamp RGB color triplet",
412          NULL},
413         {"dist",
414          (getter)Lamp_getDist, (setter)Lamp_setDist,
415          "Lamp clipping distance",
416          NULL},
417         {"energy",
418          (getter)Lamp_getEnergy, (setter)Lamp_setEnergy,
419          "Lamp light intensity",
420          NULL},
421         {"haloInt",
422          (getter)Lamp_getHaloInt, (setter)Lamp_setHaloInt,
423          "Lamp spotlight halo intensity",
424          NULL},
425         {"haloStep",
426          (getter)Lamp_getHaloStep, (setter)Lamp_setHaloStep,
427          "Lamp volumetric halo sampling frequency",
428          NULL},
429         {"ipo",
430          (getter)Lamp_getIpo, (setter)Lamp_setIpo,
431          "Lamp Ipo",
432          NULL},
433         {"mode",
434          (getter)Lamp_getMode, (setter)Lamp_setMode,
435          "Lamp mode bitmask",
436          NULL},
437         {"quad1",
438          (getter)Lamp_getQuad1, (setter)Lamp_setQuad1,
439          "Quad lamp linear distance attenuation",
440          NULL},
441         {"quad2",
442          (getter)Lamp_getQuad2, (setter)Lamp_setQuad2,
443          "Quad lamp quadratic distance attenuation",
444          NULL},
445         {"samples",
446          (getter)Lamp_getSamples, (setter)Lamp_setSamples,
447          "Lamp shadow map samples",
448          NULL},
449         {"raySamplesX",
450          (getter)Lamp_getRaySamplesX, (setter)Lamp_setRaySamplesX,
451          "Lamp raytracing samples on the X axis",
452          NULL},
453         {"raySamplesY",
454          (getter)Lamp_getRaySamplesY, (setter)Lamp_setRaySamplesY,
455          "Lamp raytracing samples on the Y axis",
456          NULL},
457         {"areaSizeX",
458          (getter)Lamp_getAreaSizeX, (setter)Lamp_setAreaSizeX,
459          "Lamp X size for an arealamp",
460          NULL},
461         {"areaSizeY",
462          (getter)Lamp_getAreaSizeY, (setter)Lamp_setAreaSizeY,
463          "Lamp Y size for an arealamp",
464          NULL},
465         {"softness",
466          (getter)Lamp_getSoftness, (setter)Lamp_setSoftness,
467          "Lamp shadow sample area size",
468          NULL},
469         {"spotBlend",
470          (getter)Lamp_getSpotBlend, (setter)Lamp_setSpotBlend,
471          "Lamp spotlight edge softness",
472          NULL},
473         {"spotSize",
474          (getter)Lamp_getSpotSize, (setter)Lamp_setSpotSize,
475          "Lamp spotlight beam angle (in degrees)",
476          NULL},
477         {"type",
478          (getter)Lamp_getType, (setter)Lamp_setType,
479          "Lamp type",
480          NULL},
481         {"falloffType",
482          (getter)Lamp_getFalloffType, (setter)Lamp_setFalloffType,
483          "Lamp falloff type",
484          NULL},
485         {"R",
486          (getter)Lamp_getComponent, (setter)Lamp_setComponent,
487          "Lamp color red component",
488          (void *)EXPP_LAMP_COMP_R},
489         {"r",
490          (getter)Lamp_getComponent, (setter)Lamp_setComponent,
491          "Lamp color red component",
492          (void *)EXPP_LAMP_COMP_R},
493         {"G",
494          (getter)Lamp_getComponent, (setter)Lamp_setComponent,
495          "Lamp color green component",
496          (void *)EXPP_LAMP_COMP_G},
497         {"g",
498          (getter)Lamp_getComponent, (setter)Lamp_setComponent,
499          "Lamp color green component",
500          (void *)EXPP_LAMP_COMP_G},
501         {"B",
502          (getter)Lamp_getComponent, (setter)Lamp_setComponent,
503          "Lamp color blue component",
504          (void *)EXPP_LAMP_COMP_B},
505         {"b",
506          (getter)Lamp_getComponent, (setter)Lamp_setComponent,
507          "Lamp color blue component",
508          (void *)EXPP_LAMP_COMP_B},
509         {"textures",
510          (getter)Lamp_getTextures, (setter)Lamp_setTextures,
511      "The Lamp's texture list as a tuple",
512          NULL},
513         {"Modes",
514          (getter)Lamp_getModesConst, (setter)NULL,
515          "Dictionary of values for 'mode' attribute",
516          NULL},
517         {"Types",
518          (getter)Lamp_getTypesConst, (setter)NULL,
519          "Dictionary of values for 'type' attribute",
520          NULL},
521         {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
522 };
523
524 /*****************************************************************************/
525 /* Python TypeLamp callback function prototypes:                             */
526 /*****************************************************************************/
527 static void Lamp_dealloc( BPy_Lamp * lamp );
528 static int Lamp_compare( BPy_Lamp * a, BPy_Lamp * b );
529 static PyObject *Lamp_repr( BPy_Lamp * lamp );
530
531 /*****************************************************************************/
532 /* Python TypeLamp structure definition:                                     */
533 /*****************************************************************************/
534 PyTypeObject Lamp_Type = {
535         PyObject_HEAD_INIT( NULL )  /* required py macro */
536         0,                          /* ob_size */
537         /*  For printing, in format "<module>.<name>" */
538         "Blender Lamp",             /* char *tp_name; */
539         sizeof( BPy_Lamp ),         /* int tp_basicsize; */
540         0,                          /* tp_itemsize;  For allocation */
541
542         /* Methods to implement standard operations */
543
544         ( destructor ) Lamp_dealloc,/* destructor tp_dealloc; */
545         NULL,                       /* printfunc tp_print; */
546         NULL,                       /* getattrfunc tp_getattr; */
547         NULL,                       /* setattrfunc tp_setattr; */
548         ( cmpfunc ) Lamp_compare,   /* cmpfunc tp_compare; */
549         ( reprfunc ) Lamp_repr,     /* reprfunc tp_repr; */
550
551         /* Method suites for standard classes */
552
553         NULL,                       /* PyNumberMethods *tp_as_number; */
554         NULL,                       /* PySequenceMethods *tp_as_sequence; */
555         NULL,                       /* PyMappingMethods *tp_as_mapping; */
556
557         /* More standard operations (here for binary compatibility) */
558
559         ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
560         NULL,                       /* ternaryfunc tp_call; */
561         NULL,                       /* reprfunc tp_str; */
562         NULL,                       /* getattrofunc tp_getattro; */
563         NULL,                       /* setattrofunc tp_setattro; */
564
565         /* Functions to access object as input/output buffer */
566         NULL,                       /* PyBufferProcs *tp_as_buffer; */
567
568   /*** Flags to define presence of optional/expanded features ***/
569         Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
570
571         NULL,                       /*  char *tp_doc;  Documentation string */
572   /*** Assigned meaning in release 2.0 ***/
573         /* call function for all accessible objects */
574         NULL,                       /* traverseproc tp_traverse; */
575
576         /* delete references to contained objects */
577         NULL,                       /* inquiry tp_clear; */
578
579   /***  Assigned meaning in release 2.1 ***/
580   /*** rich comparisons ***/
581         NULL,                       /* richcmpfunc tp_richcompare; */
582
583   /***  weak reference enabler ***/
584         0,                          /* long tp_weaklistoffset; */
585
586   /*** Added in release 2.2 ***/
587         /*   Iterators */
588         NULL,                       /* getiterfunc tp_iter; */
589         NULL,                       /* iternextfunc tp_iternext; */
590
591   /*** Attribute descriptor and subclassing stuff ***/
592         BPy_Lamp_methods,           /* struct PyMethodDef *tp_methods; */
593         NULL,                       /* struct PyMemberDef *tp_members; */
594         BPy_Lamp_getseters,         /* struct PyGetSetDef *tp_getset; */
595         NULL,                       /* struct _typeobject *tp_base; */
596         NULL,                       /* PyObject *tp_dict; */
597         NULL,                       /* descrgetfunc tp_descr_get; */
598         NULL,                       /* descrsetfunc tp_descr_set; */
599         0,                          /* long tp_dictoffset; */
600         NULL,                       /* initproc tp_init; */
601         NULL,                       /* allocfunc tp_alloc; */
602         NULL,                       /* newfunc tp_new; */
603         /*  Low-level free-memory routine */
604         NULL,                       /* freefunc tp_free;  */
605         /* For PyObject_IS_GC */
606         NULL,                       /* inquiry tp_is_gc;  */
607         NULL,                       /* PyObject *tp_bases; */
608         /* method resolution order */
609         NULL,                       /* PyObject *tp_mro;  */
610         NULL,                       /* PyObject *tp_cache; */
611         NULL,                       /* PyObject *tp_subclasses; */
612         NULL,                       /* PyObject *tp_weaklist; */
613         NULL
614 };
615
616 /*****************************************************************************/
617 /* Function:              M_Lamp_New                                         */
618 /* Python equivalent:     Blender.Lamp.New                                   */
619 /*****************************************************************************/
620 static PyObject *M_Lamp_New( PyObject * self, PyObject * args,
621                              PyObject * keywords )
622 {
623         char *type_str = "Lamp";
624         char *name_str = "Lamp";
625         static char *kwlist[] = { "type_str", "name_str", NULL };
626         BPy_Lamp *py_lamp;      /* for Lamp Data object wrapper in Python */
627         Lamp *bl_lamp;          /* for actual Lamp Data we create in Blender */
628
629         if( !PyArg_ParseTupleAndKeywords( args, keywords, "|ss", kwlist,
630                                           &type_str, &name_str ) )
631                 return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
632                                                 "expected string(s) or empty argument" ) );
633         
634         bl_lamp = add_lamp( name_str ); /* first create in Blender */
635         
636         if( bl_lamp )           /* now create the wrapper obj in Python */
637                 py_lamp = ( BPy_Lamp * ) Lamp_CreatePyObject( bl_lamp );
638         else
639                 return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
640                                                 "couldn't create Lamp Data in Blender" ) );
641
642         /* let's return user count to zero, because ... */
643         bl_lamp->id.us = 0;     /* ... add_lamp() incref'ed it */
644
645         if( py_lamp == NULL )
646                 return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
647                                                 "couldn't create Lamp Data object" ) );
648
649         if( strcmp( type_str, "Lamp" ) == 0 )
650                 bl_lamp->type = ( short ) EXPP_LAMP_TYPE_LAMP;
651         else if( strcmp( type_str, "Sun" ) == 0 )
652                 bl_lamp->type = ( short ) EXPP_LAMP_TYPE_SUN;
653         else if( strcmp( type_str, "Spot" ) == 0 )
654                 bl_lamp->type = ( short ) EXPP_LAMP_TYPE_SPOT;
655         else if( strcmp( type_str, "Hemi" ) == 0 )
656                 bl_lamp->type = ( short ) EXPP_LAMP_TYPE_HEMI;
657         else if( strcmp( type_str, "Area" ) == 0 )
658                 bl_lamp->type = ( short ) EXPP_LAMP_TYPE_AREA;
659         else if( strcmp( type_str, "Photon" ) == 0 )
660                 bl_lamp->type = ( short ) EXPP_LAMP_TYPE_YF_PHOTON;
661         else
662                 return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
663                                                 "unknown lamp type" ) );
664
665         return ( PyObject * ) py_lamp;
666 }
667
668 /*****************************************************************************/
669 /* Function:              M_Lamp_Get                                         */
670 /* Python equivalent:     Blender.Lamp.Get                                   */
671 /* Description:           Receives a string and returns the lamp data obj    */
672 /*                        whose name matches the string.  If no argument is  */
673 /*                        passed in, a list of all lamp data names in the    */
674 /*                        current scene is returned.                         */
675 /*****************************************************************************/
676 static PyObject *M_Lamp_Get( PyObject * self, PyObject * args )
677 {
678         char *name = NULL;
679         Lamp *lamp_iter;
680
681         if( !PyArg_ParseTuple( args, "|s", &name ) )
682                 return ( EXPP_ReturnPyObjError( PyExc_TypeError,
683                                                 "expected string argument (or nothing)" ) );
684
685         lamp_iter = G.main->lamp.first;
686
687         if( name ) {            /* (name) - Search lamp by name */
688
689                 BPy_Lamp *wanted_lamp = NULL;
690
691                 while( ( lamp_iter ) && ( wanted_lamp == NULL ) ) {
692
693                         if( strcmp( name, lamp_iter->id.name + 2 ) == 0 )
694                                 wanted_lamp =
695                                         ( BPy_Lamp * )
696                                         Lamp_CreatePyObject( lamp_iter );
697
698                         lamp_iter = lamp_iter->id.next;
699                 }
700
701                 if( wanted_lamp == NULL ) { /* Requested lamp doesn't exist */
702                         char error_msg[64];
703                         PyOS_snprintf( error_msg, sizeof( error_msg ),
704                                        "Lamp \"%s\" not found", name );
705                         return ( EXPP_ReturnPyObjError
706                                  ( PyExc_NameError, error_msg ) );
707                 }
708
709                 return ( PyObject * ) wanted_lamp;
710         }
711
712         else {          /* () - return a list of all lamps in the scene */
713                 int index = 0;
714                 PyObject *lamplist, *pyobj;
715
716                 lamplist = PyList_New( BLI_countlist( &( G.main->lamp ) ) );
717
718                 if( lamplist == NULL )
719                         return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
720                                                         "couldn't create PyList" ) );
721
722                 while( lamp_iter ) {
723                         pyobj = Lamp_CreatePyObject( lamp_iter );
724
725                         if( !pyobj ) {
726                                 Py_DECREF(lamplist);
727                                 return ( EXPP_ReturnPyObjError
728                                          ( PyExc_MemoryError,
729                                            "couldn't create PyLamp" ) );
730                         }
731
732                         PyList_SET_ITEM( lamplist, index, pyobj );
733
734                         lamp_iter = lamp_iter->id.next;
735                         index++;
736                 }
737
738                 return lamplist;
739         }
740 }
741
742 static PyObject *Lamp_TypesDict( void )
743 {       /* create the Blender.Lamp.Types constant dict */
744         PyObject *Types = PyConstant_New(  );
745
746         if( Types ) {
747                 BPy_constant *c = ( BPy_constant * ) Types;
748
749                 PyConstant_Insert( c, "Lamp",
750                                  PyInt_FromLong( EXPP_LAMP_TYPE_LAMP ) );
751                 PyConstant_Insert( c, "Sun",
752                                  PyInt_FromLong( EXPP_LAMP_TYPE_SUN ) );
753                 PyConstant_Insert( c, "Spot",
754                                  PyInt_FromLong( EXPP_LAMP_TYPE_SPOT ) );
755                 PyConstant_Insert( c, "Hemi",
756                                  PyInt_FromLong( EXPP_LAMP_TYPE_HEMI ) );
757                 PyConstant_Insert( c, "Area",
758                                  PyInt_FromLong( EXPP_LAMP_TYPE_AREA ) );
759                 PyConstant_Insert( c, "Photon",
760                                  PyInt_FromLong( EXPP_LAMP_TYPE_YF_PHOTON ) );
761         }
762
763         return Types;
764 }
765
766 static PyObject *Lamp_ModesDict( void )
767 {                       /* create the Blender.Lamp.Modes constant dict */
768         PyObject *Modes = PyConstant_New(  );
769
770         if( Modes ) {
771                 BPy_constant *c = ( BPy_constant * ) Modes;
772
773                 PyConstant_Insert( c, "Shadows",
774                                  PyInt_FromLong( EXPP_LAMP_MODE_SHADOWS ) );
775                 PyConstant_Insert( c, "Halo",
776                                  PyInt_FromLong( EXPP_LAMP_MODE_HALO ) );
777                 PyConstant_Insert( c, "Layer",
778                                  PyInt_FromLong( EXPP_LAMP_MODE_LAYER ) );
779                 PyConstant_Insert( c, "Quad",
780                                  PyInt_FromLong( EXPP_LAMP_MODE_QUAD ) );
781                 PyConstant_Insert( c, "Negative",
782                                  PyInt_FromLong( EXPP_LAMP_MODE_NEGATIVE ) );
783                 PyConstant_Insert( c, "Sphere",
784                                  PyInt_FromLong( EXPP_LAMP_MODE_SPHERE ) );
785                 PyConstant_Insert( c, "Square",
786                                  PyInt_FromLong( EXPP_LAMP_MODE_SQUARE ) );
787                 PyConstant_Insert( c, "OnlyShadow",
788                                  PyInt_FromLong( EXPP_LAMP_MODE_ONLYSHADOW ) );
789                 PyConstant_Insert( c, "NoDiffuse",
790                                  PyInt_FromLong( EXPP_LAMP_MODE_NODIFFUSE ) );
791                 PyConstant_Insert( c, "NoSpecular",
792                                  PyInt_FromLong( EXPP_LAMP_MODE_NOSPECULAR ) );
793                 PyConstant_Insert( c, "RayShadow",
794                                  PyInt_FromLong( EXPP_LAMP_MODE_SHAD_RAY ) );
795                 PyConstant_Insert( c, "LayerShadow",
796                                  PyInt_FromLong( EXPP_LAMP_MODE_LAYER_SHADOW ) );
797         }
798
799         return Modes;
800 }
801
802 static PyObject *Lamp_FalloffsDict( void )
803 {                       /* create the Blender.Lamp.Modes constant dict */
804         PyObject *Falloffs = PyConstant_New(  );
805
806         if( Falloffs ) {
807                 BPy_constant *c = ( BPy_constant * ) Falloffs;
808
809                 PyConstant_Insert( c, "CONSTANT",
810                                  PyInt_FromLong( LA_FALLOFF_CONSTANT ) );
811                 PyConstant_Insert( c, "INVLINEAR",
812                                  PyInt_FromLong( LA_FALLOFF_INVLINEAR ) );
813                 PyConstant_Insert( c, "INVSQUARE",
814                                  PyInt_FromLong( LA_FALLOFF_INVSQUARE ) );
815                 PyConstant_Insert( c, "CUSTOM",
816                                  PyInt_FromLong( LA_FALLOFF_CURVE ) );
817                 PyConstant_Insert( c, "LINQUAD",
818                                  PyInt_FromLong( LA_FALLOFF_SLIDERS ) );
819         }
820
821         return Falloffs;
822 }
823
824 /*****************************************************************************/
825 /* Function:              Lamp_Init                                          */
826 /*****************************************************************************/
827 /* Needed by the Blender module, to register the Blender.Lamp submodule */
828 PyObject *Lamp_Init( void )
829 {
830         PyObject *submodule, *Types, *Modes, *Falloffs;
831
832         if( PyType_Ready( &Lamp_Type ) < 0)
833                 return NULL;
834
835         Types = Lamp_TypesDict(  );
836         Modes = Lamp_ModesDict(  );
837         Falloffs = Lamp_FalloffsDict(  );
838
839         submodule =
840                 Py_InitModule3( "Blender.Lamp", M_Lamp_methods, M_Lamp_doc );
841
842         if( Types )
843                 PyModule_AddObject( submodule, "Types", Types );
844         if( Modes )
845                 PyModule_AddObject( submodule, "Modes", Modes );
846         if( Falloffs )
847                 PyModule_AddObject( submodule, "Falloffs", Falloffs );
848
849         PyModule_AddIntConstant( submodule, "RGB",      IPOKEY_RGB );
850         PyModule_AddIntConstant( submodule, "ENERGY",   IPOKEY_ENERGY );
851         PyModule_AddIntConstant( submodule, "SPOTSIZE", IPOKEY_SPOTSIZE );
852         PyModule_AddIntConstant( submodule, "OFFSET",   IPOKEY_OFFSET );
853         PyModule_AddIntConstant( submodule, "SIZE",     IPOKEY_SIZE );
854         
855         return submodule;
856 }
857
858 /* Three Python Lamp_Type helper functions needed by the Object module: */
859
860 /*****************************************************************************/
861 /* Function:    Lamp_CreatePyObject                                          */
862 /* Description: This function will create a new BPy_Lamp from an existing    */
863 /*              Blender lamp structure.                                      */
864 /*****************************************************************************/
865 PyObject *Lamp_CreatePyObject( Lamp * lamp )
866 {
867         BPy_Lamp *pylamp;
868         float *rgb[3];
869
870         pylamp = ( BPy_Lamp * ) PyObject_NEW( BPy_Lamp, &Lamp_Type );
871
872         if( !pylamp )
873                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
874                                               "couldn't create BPy_Lamp object" );
875
876         pylamp->lamp = lamp;
877
878         rgb[0] = &lamp->r;
879         rgb[1] = &lamp->g;
880         rgb[2] = &lamp->b;
881
882         pylamp->color = ( BPy_rgbTuple * ) rgbTuple_New( rgb );
883         Py_INCREF(pylamp->color);
884         
885         return ( PyObject * ) pylamp;
886 }
887
888 /*****************************************************************************/
889 /* Function:    Lamp_FromPyObject                                            */
890 /* Description: This function returns the Blender lamp from the given        */
891 /*              PyObject.                                                    */
892 /*****************************************************************************/
893 Lamp *Lamp_FromPyObject( PyObject * pyobj )
894 {
895         return ( ( BPy_Lamp * ) pyobj )->lamp;
896 }
897
898 /*****************************************************************************/
899 /* Python BPy_Lamp methods:                                                  */
900 /*****************************************************************************/
901
902 /* Lamp.__copy__ */
903 static PyObject *Lamp_copy( BPy_Lamp * self )
904 {
905         Lamp *lamp = copy_lamp(self->lamp );
906         lamp->id.us = 0;
907         return Lamp_CreatePyObject(lamp);
908 }
909
910 static PyObject *Lamp_getType( BPy_Lamp * self )
911 {
912         return PyInt_FromLong( self->lamp->type );
913 }
914
915 static PyObject *Lamp_getMode( BPy_Lamp * self )
916 {
917         return PyInt_FromLong( self->lamp->mode );
918 }
919
920 static PyObject *Lamp_getSamples( BPy_Lamp * self )
921 {
922         return PyInt_FromLong( self->lamp->samp );
923 }
924
925 static PyObject *Lamp_getRaySamplesX( BPy_Lamp * self )
926 {
927         return PyInt_FromLong( self->lamp->ray_samp );
928 }
929
930 static PyObject *Lamp_getRaySamplesY( BPy_Lamp * self )
931 {
932         return PyInt_FromLong( self->lamp->ray_sampy );
933 }
934
935 static PyObject *Lamp_getAreaSizeX( BPy_Lamp * self )
936 {
937         return PyFloat_FromDouble( self->lamp->area_size );
938 }
939
940 static PyObject *Lamp_getAreaSizeY( BPy_Lamp * self )
941 {
942         return PyFloat_FromDouble( self->lamp->area_sizey );
943 }
944
945 static PyObject *Lamp_getBufferSize( BPy_Lamp * self )
946 {
947         return PyInt_FromLong( self->lamp->bufsize );
948 }
949
950 static PyObject *Lamp_getHaloStep( BPy_Lamp * self )
951 {
952         return PyInt_FromLong( self->lamp->shadhalostep );
953 }
954
955 static PyObject *Lamp_getEnergy( BPy_Lamp * self )
956 {
957         return PyFloat_FromDouble( self->lamp->energy );
958 }
959
960 static PyObject *Lamp_getDist( BPy_Lamp * self )
961 {
962         return PyFloat_FromDouble( self->lamp->dist );
963 }
964
965 static PyObject *Lamp_getSpotSize( BPy_Lamp * self )
966 {
967         return PyFloat_FromDouble( self->lamp->spotsize );
968 }
969
970 static PyObject *Lamp_getSpotBlend( BPy_Lamp * self )
971 {
972         return PyFloat_FromDouble( self->lamp->spotblend );
973 }
974
975 static PyObject *Lamp_getClipStart( BPy_Lamp * self )
976 {
977         return PyFloat_FromDouble( self->lamp->clipsta );
978 }
979
980 static PyObject *Lamp_getClipEnd( BPy_Lamp * self )
981 {
982         return PyFloat_FromDouble( self->lamp->clipend );
983 }
984
985 static PyObject *Lamp_getBias( BPy_Lamp * self )
986 {
987         return PyFloat_FromDouble( self->lamp->bias );
988 }
989
990 static PyObject *Lamp_getSoftness( BPy_Lamp * self )
991 {
992         return PyFloat_FromDouble( self->lamp->soft );
993 }
994
995 static PyObject *Lamp_getHaloInt( BPy_Lamp * self )
996 {
997         return PyFloat_FromDouble( self->lamp->haint );
998 }
999
1000 static PyObject *Lamp_getQuad1( BPy_Lamp * self )
1001 {                               /* should we complain if Lamp is not of type Quad? */
1002         return PyFloat_FromDouble( self->lamp->att1 );
1003 }
1004
1005 static PyObject *Lamp_getQuad2( BPy_Lamp * self )
1006 {                       /* should we complain if Lamp is not of type Quad? */
1007         return PyFloat_FromDouble( self->lamp->att2 );
1008 }
1009
1010 static PyObject *Lamp_getCol( BPy_Lamp * self )
1011 {
1012         return rgbTuple_getCol( self->color );
1013 }
1014
1015 static PyObject *Lamp_getFalloffType( BPy_Lamp * self )
1016 {
1017         return PyInt_FromLong( (int)self->lamp->falloff_type );
1018 }
1019
1020 static int Lamp_setType( BPy_Lamp * self, PyObject * value )
1021 {
1022         return EXPP_setIValueRange ( value, &self->lamp->type,
1023                                                                 0, EXPP_LAMP_TYPE_MAX, 'h' );
1024 }
1025
1026 static int Lamp_setMode( BPy_Lamp * self, PyObject * value )
1027 {
1028         int param;
1029         static int bitmask = EXPP_LAMP_MODE_SHADOWS
1030                                 | EXPP_LAMP_MODE_HALO
1031                                 | EXPP_LAMP_MODE_LAYER
1032                                 | EXPP_LAMP_MODE_QUAD
1033                                 | EXPP_LAMP_MODE_NEGATIVE
1034                                 | EXPP_LAMP_MODE_ONLYSHADOW
1035                                 | EXPP_LAMP_MODE_SPHERE
1036                                 | EXPP_LAMP_MODE_SQUARE
1037                                 | EXPP_LAMP_MODE_NODIFFUSE
1038                                 | EXPP_LAMP_MODE_NOSPECULAR
1039                                 | EXPP_LAMP_MODE_SHAD_RAY
1040                                 | EXPP_LAMP_MODE_LAYER_SHADOW;
1041
1042         if( !PyInt_Check ( value ) ) {
1043                 char errstr[128];
1044                 sprintf ( errstr , "expected int bitmask of 0x%04x", bitmask );
1045                 return EXPP_ReturnIntError( PyExc_TypeError, errstr );
1046         }
1047         param = PyInt_AS_LONG ( value );
1048
1049         if ( ( param & bitmask ) != param )
1050                 return EXPP_ReturnIntError( PyExc_ValueError,
1051                                                 "invalid bit(s) set in mask" );
1052
1053         self->lamp->mode = param; 
1054
1055         return 0;
1056 }
1057
1058 static int Lamp_setSamples( BPy_Lamp * self, PyObject * value )
1059 {
1060         return EXPP_setIValueClamped ( value, &self->lamp->samp,
1061                                                                 EXPP_LAMP_SAMPLES_MIN,
1062                                                                 EXPP_LAMP_SAMPLES_MAX, 'h' );
1063 }
1064
1065
1066 static int Lamp_setRaySamplesX( BPy_Lamp * self, PyObject * value )
1067 {
1068         return EXPP_setIValueClamped ( value, &self->lamp->ray_samp, 
1069                                                                 EXPP_LAMP_RAYSAMPLES_MIN,
1070                                                                 EXPP_LAMP_RAYSAMPLES_MAX, 'h' );
1071 }
1072
1073 static int Lamp_setRaySamplesY( BPy_Lamp * self, PyObject * value )
1074 {
1075         return EXPP_setIValueClamped ( value, &self->lamp->ray_sampy,
1076                                                                 EXPP_LAMP_RAYSAMPLES_MIN,
1077                                                                 EXPP_LAMP_RAYSAMPLES_MAX, 'h' );
1078 }
1079
1080 static int Lamp_setAreaSizeX( BPy_Lamp * self, PyObject * value )
1081 {
1082         return EXPP_setFloatClamped ( value, &self->lamp->area_size, 
1083                                                                 EXPP_LAMP_AREASIZE_MIN,
1084                                                                 EXPP_LAMP_AREASIZE_MAX );
1085 }
1086
1087 static int Lamp_setAreaSizeY( BPy_Lamp * self, PyObject * value )
1088 {
1089         return EXPP_setFloatClamped ( value, &self->lamp->area_sizey, 
1090                                                                 EXPP_LAMP_AREASIZE_MIN,
1091                                                                 EXPP_LAMP_AREASIZE_MAX );
1092 }
1093
1094 static int Lamp_setBufferSize( BPy_Lamp * self, PyObject * value )
1095 {
1096         return EXPP_setIValueClamped ( value, &self->lamp->bufsize,
1097                                                                 EXPP_LAMP_BUFFERSIZE_MIN,
1098                                                                 EXPP_LAMP_BUFFERSIZE_MAX, 'h' );
1099 }
1100
1101 static int Lamp_setHaloStep( BPy_Lamp * self, PyObject * value )
1102 {
1103         return EXPP_setIValueClamped ( value, &self->lamp->shadhalostep,
1104                                                                 EXPP_LAMP_HALOSTEP_MIN,
1105                                                                 EXPP_LAMP_HALOSTEP_MAX, 'h' );
1106 }
1107
1108 static int Lamp_setEnergy( BPy_Lamp * self, PyObject * value )
1109 {
1110         return EXPP_setFloatClamped ( value, &self->lamp->energy, 
1111                                                                 EXPP_LAMP_ENERGY_MIN,
1112                                                                 EXPP_LAMP_ENERGY_MAX );
1113 }
1114
1115 static int Lamp_setDist( BPy_Lamp * self, PyObject * value )
1116 {
1117         return EXPP_setFloatClamped ( value, &self->lamp->dist, 
1118                                                                 EXPP_LAMP_DIST_MIN,
1119                                                                 EXPP_LAMP_DIST_MAX );
1120 }
1121
1122 static int Lamp_setSpotSize( BPy_Lamp * self, PyObject * value )
1123 {
1124         return EXPP_setFloatClamped ( value, &self->lamp->spotsize, 
1125                                                                 EXPP_LAMP_SPOTSIZE_MIN,
1126                                                                 EXPP_LAMP_SPOTSIZE_MAX );
1127 }
1128
1129 static int Lamp_setSpotBlend( BPy_Lamp * self, PyObject * value )
1130 {
1131         return EXPP_setFloatClamped ( value, &self->lamp->spotblend, 
1132                                                                 EXPP_LAMP_SPOTBLEND_MIN,
1133                                                                 EXPP_LAMP_SPOTBLEND_MAX );
1134 }
1135
1136 static int Lamp_setClipStart( BPy_Lamp * self, PyObject * value )
1137 {
1138         return EXPP_setFloatClamped ( value, &self->lamp->clipsta, 
1139                                                                 EXPP_LAMP_CLIPSTART_MIN,
1140                                                                 EXPP_LAMP_CLIPSTART_MAX );
1141 }
1142
1143 static int Lamp_setClipEnd( BPy_Lamp * self, PyObject * value )
1144 {
1145         return EXPP_setFloatClamped ( value, &self->lamp->clipend, 
1146                                                                 EXPP_LAMP_CLIPEND_MIN,
1147                                                                 EXPP_LAMP_CLIPEND_MAX );
1148 }
1149
1150 static int Lamp_setBias( BPy_Lamp * self, PyObject * value )
1151 {
1152         return EXPP_setFloatClamped ( value, &self->lamp->bias,
1153                                                                 EXPP_LAMP_BIAS_MIN,
1154                                                                 EXPP_LAMP_BIAS_MAX );
1155 }
1156
1157 static int Lamp_setSoftness( BPy_Lamp * self, PyObject * value )
1158 {
1159         return EXPP_setFloatClamped ( value, &self->lamp->soft,
1160                                                                 EXPP_LAMP_SOFTNESS_MIN,
1161                                                                 EXPP_LAMP_SOFTNESS_MAX );
1162 }
1163
1164 static int Lamp_setHaloInt( BPy_Lamp * self, PyObject * value )
1165 {
1166         return EXPP_setFloatClamped ( value, &self->lamp->haint,
1167                                                                 EXPP_LAMP_HALOINT_MIN,
1168                                                                 EXPP_LAMP_HALOINT_MAX );
1169 }
1170
1171 static int Lamp_setQuad1( BPy_Lamp * self, PyObject * value )
1172 {
1173         return EXPP_setFloatClamped ( value, &self->lamp->att1,
1174                                                                 EXPP_LAMP_QUAD1_MIN,
1175                                                                 EXPP_LAMP_QUAD1_MAX );
1176 }
1177
1178 static int Lamp_setQuad2( BPy_Lamp * self, PyObject * value )
1179 {
1180         return EXPP_setFloatClamped ( value, &self->lamp->att2,
1181                                                                 EXPP_LAMP_QUAD2_MIN,
1182                                                                 EXPP_LAMP_QUAD2_MAX );
1183 }
1184
1185 static int Lamp_setFalloffType( BPy_Lamp * self, PyObject * value )
1186 {
1187         return EXPP_setIValueRange ( value, &self->lamp->falloff_type,
1188                                                                 EXPP_LAMP_FALLOFF_MIN, EXPP_LAMP_FALLOFF_MAX, 'h' );
1189 }
1190
1191
1192 static PyObject *Lamp_getComponent( BPy_Lamp * self, void * closure )
1193 {
1194         switch ( GET_INT_FROM_POINTER(closure) ) {
1195         case EXPP_LAMP_COMP_R:
1196                 return PyFloat_FromDouble( self->lamp->r );
1197         case EXPP_LAMP_COMP_G:
1198                 return PyFloat_FromDouble( self->lamp->g );
1199         case EXPP_LAMP_COMP_B:
1200                 return PyFloat_FromDouble( self->lamp->b );
1201         default:
1202                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1203                                         "unknown color component specified" );
1204         }
1205 }
1206
1207 static int Lamp_setComponent( BPy_Lamp * self, PyObject * value,
1208                                                         void * closure )
1209 {
1210         float color;
1211
1212         if( !PyNumber_Check ( value ) )
1213                 return EXPP_ReturnIntError( PyExc_TypeError,
1214                                                 "expected float argument in [0.0,1.0]" );
1215
1216         color = (float)PyFloat_AsDouble( value );
1217         color = EXPP_ClampFloat( color, EXPP_LAMP_COL_MIN, EXPP_LAMP_COL_MAX );
1218
1219         switch ( GET_INT_FROM_POINTER(closure) ) {
1220         case EXPP_LAMP_COMP_R:
1221                 self->lamp->r = color;
1222                 return 0;
1223         case EXPP_LAMP_COMP_G:
1224                 self->lamp->g = color;
1225                 return 0;
1226         case EXPP_LAMP_COMP_B:
1227                 self->lamp->b = color;
1228                 return 0;
1229         }
1230         return EXPP_ReturnIntError( PyExc_RuntimeError,
1231                                 "unknown color component specified" );
1232 }
1233
1234 static int Lamp_setCol( BPy_Lamp * self, PyObject * args )
1235 {
1236         return rgbTuple_setCol( self->color, args );
1237 }
1238
1239 /* lamp.addScriptLink */
1240 static PyObject *Lamp_addScriptLink( BPy_Lamp * self, PyObject * args )
1241 {
1242         Lamp *lamp = self->lamp;
1243         ScriptLink *slink = NULL;
1244
1245         slink = &( lamp )->scriptlink;
1246
1247         return EXPP_addScriptLink( slink, args, 0 );
1248 }
1249
1250 /* lamp.clearScriptLinks */
1251 static PyObject *Lamp_clearScriptLinks( BPy_Lamp * self, PyObject * args )
1252 {
1253         Lamp *lamp = self->lamp;
1254         ScriptLink *slink = NULL;
1255
1256         slink = &( lamp )->scriptlink;
1257
1258         return EXPP_clearScriptLinks( slink, args );
1259 }
1260
1261 /* mat.getScriptLinks */
1262 static PyObject *Lamp_getScriptLinks( BPy_Lamp * self, PyObject * value )
1263 {
1264         Lamp *lamp = self->lamp;
1265         ScriptLink *slink = NULL;
1266         PyObject *ret = NULL;
1267
1268         slink = &( lamp )->scriptlink;
1269
1270         ret = EXPP_getScriptLinks( slink, value, 0 );
1271
1272         if( ret )
1273                 return ret;
1274         else
1275                 return NULL;
1276 }
1277
1278 /*****************************************************************************/
1279 /* Function:    Lamp_dealloc                                                 */
1280 /* Description: This is a callback function for the BPy_Lamp type. It is     */
1281 /*              the destructor function.                                     */
1282 /*****************************************************************************/
1283 static void Lamp_dealloc( BPy_Lamp * self )
1284 {
1285         Py_DECREF( self->color );
1286         PyObject_DEL( self );
1287 }
1288
1289 /*****************************************************************************/
1290 /* Function:    Lamp_compare                                                 */
1291 /* Description: This is a callback function for the BPy_Lamp type. It        */
1292 /*              compares two Lamp_Type objects. Only the "==" and "!="       */
1293 /*              comparisons are meaningful. Returns 0 for equality and -1    */
1294 /*              if they don't point to the same Blender Lamp struct.         */
1295 /*              In Python it becomes 1 if they are equal, 0 otherwise.       */
1296 /*****************************************************************************/
1297 static int Lamp_compare( BPy_Lamp * a, BPy_Lamp * b )
1298 {
1299         return ( a->lamp == b->lamp ) ? 0 : -1;
1300 }
1301
1302 /*****************************************************************************/
1303 /* Function:    Lamp_repr                                                    */
1304 /* Description: This is a callback function for the BPy_Lamp type. It        */
1305 /*              builds a meaninful string to represent lamp objects.         */
1306 /*****************************************************************************/
1307 static PyObject *Lamp_repr( BPy_Lamp * self )
1308 {
1309         return PyString_FromFormat( "[Lamp \"%s\"]", self->lamp->id.name + 2 );
1310 }
1311
1312 static PyObject *Lamp_getIpo( BPy_Lamp * self )
1313 {
1314         struct Ipo *ipo = self->lamp->ipo;
1315
1316         if( !ipo )
1317                 Py_RETURN_NONE;
1318
1319         return Ipo_CreatePyObject( ipo );
1320 }
1321
1322 /*
1323  * this should accept a Py_None argument and just delete the Ipo link
1324  * (as Lamp_clearIpo() does)
1325  */
1326
1327 static int Lamp_setIpo( BPy_Lamp * self, PyObject * value )
1328 {
1329         return GenericLib_assignData(value, (void **) &self->lamp->ipo, 0, 1, ID_IP, ID_LA);
1330 }
1331
1332 /*
1333  * Lamp_insertIpoKey()
1334  *  inserts Lamp IPO key for RGB,ENERGY,SPOTSIZE,OFFSET,SIZE
1335  */
1336
1337 static PyObject *Lamp_insertIpoKey( BPy_Lamp * self, PyObject * args )
1338 {
1339         int key = 0, map;
1340
1341         if( !PyArg_ParseTuple( args, "i", &( key ) ) )
1342                 return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
1343                                                                                 "expected int argument" ) );
1344
1345         map = texchannel_to_adrcode(self->lamp->texact);
1346
1347         if (key == IPOKEY_RGB ) {
1348                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL, LA_COL_R, 0);
1349                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL,LA_COL_G, 0);
1350                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL,LA_COL_B, 0);
1351         }
1352         if (key == IPOKEY_ENERGY ) {
1353                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL,LA_ENERGY, 0);
1354         }       
1355         if (key == IPOKEY_SPOTSIZE ) {
1356                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL,LA_SPOTSI, 0);
1357         }
1358         if (key == IPOKEY_OFFSET ) {
1359                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL, map+MAP_OFS_X, 0);
1360                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL, map+MAP_OFS_Y, 0);
1361                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL, map+MAP_OFS_Z, 0);
1362         }
1363         if (key == IPOKEY_SIZE ) {
1364                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL, map+MAP_SIZE_X, 0);
1365                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL, map+MAP_SIZE_Y, 0);
1366                 insertkey((ID *)self->lamp, ID_LA, NULL, NULL, map+MAP_SIZE_Z, 0);
1367         }
1368
1369         allspace(REMAKEIPO, 0);
1370         EXPP_allqueue(REDRAWIPO, 0);
1371         EXPP_allqueue(REDRAWVIEW3D, 0);
1372         EXPP_allqueue(REDRAWACTION, 0);
1373         EXPP_allqueue(REDRAWNLA, 0);
1374
1375         Py_RETURN_NONE;
1376 }
1377
1378 static PyObject *Lamp_getModesConst( void )
1379 {
1380         return Py_BuildValue
1381                         ( "{s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h}",
1382                           "Shadows", EXPP_LAMP_MODE_SHADOWS, "Halo",
1383                           EXPP_LAMP_MODE_HALO, "Layer", EXPP_LAMP_MODE_LAYER,
1384                           "Quad", EXPP_LAMP_MODE_QUAD, "Negative",
1385                           EXPP_LAMP_MODE_NEGATIVE, "OnlyShadow",
1386                           EXPP_LAMP_MODE_ONLYSHADOW, "Sphere",
1387                           EXPP_LAMP_MODE_SPHERE, "Square",
1388                           EXPP_LAMP_MODE_SQUARE, "NoDiffuse",
1389                           EXPP_LAMP_MODE_NODIFFUSE, "NoSpecular",
1390                           EXPP_LAMP_MODE_NOSPECULAR, "RayShadow",
1391                           EXPP_LAMP_MODE_SHAD_RAY, "LayerShadow",
1392                           EXPP_LAMP_MODE_LAYER_SHADOW);
1393 }
1394
1395 static PyObject *Lamp_getTypesConst( void )
1396 {
1397         return Py_BuildValue( "{s:h,s:h,s:h,s:h,s:h,s:h}",
1398                                       "Lamp", EXPP_LAMP_TYPE_LAMP,
1399                                       "Sun", EXPP_LAMP_TYPE_SUN,
1400                                       "Spot", EXPP_LAMP_TYPE_SPOT,
1401                                       "Hemi", EXPP_LAMP_TYPE_HEMI, 
1402                                       "Area", EXPP_LAMP_TYPE_AREA, 
1403                                       "Photon", EXPP_LAMP_TYPE_YF_PHOTON );
1404 }
1405
1406 static PyObject *Lamp_getTextures( BPy_Lamp * self )
1407 {
1408         int i;
1409         PyObject *tuple;
1410
1411         /* build a texture list */
1412         tuple = PyTuple_New( MAX_MTEX );
1413         if( !tuple )
1414                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1415                                               "couldn't create PyTuple" );
1416
1417         for( i = 0; i < MAX_MTEX; ++i ) {
1418                 struct MTex *mtex = self->lamp->mtex[i];
1419                 if( mtex ) {
1420                         PyTuple_SET_ITEM( tuple, i, MTex_CreatePyObject( mtex, ID_LA ) );
1421                 } else {
1422                         Py_INCREF( Py_None );
1423                         PyTuple_SET_ITEM( tuple, i, Py_None );
1424                 }
1425         }
1426
1427         return tuple;
1428 }
1429
1430 static int Lamp_setTextures( BPy_Lamp * self, PyObject * value )
1431 {
1432         int i;
1433
1434         if( !PyList_Check( value ) && !PyTuple_Check( value ) )
1435                 return EXPP_ReturnIntError( PyExc_TypeError,
1436                                                 "expected tuple or list of integers" );
1437
1438         /* don't allow more than MAX_MTEX items */
1439         if( PySequence_Size(value) > MAX_MTEX )
1440                 return EXPP_ReturnIntError( PyExc_AttributeError,
1441                                                 "size of sequence greater than number of allowed textures" );
1442
1443         /* get a fast sequence; in Python 2.5, this just return the original
1444          * list or tuple and INCREFs it, so we must DECREF */
1445         value = PySequence_Fast( value, "" );
1446
1447         /* check the list for valid entries */
1448         for( i= 0; i < PySequence_Size(value) ; ++i ) {
1449                 PyObject *item = PySequence_Fast_GET_ITEM( value, i );
1450                 if( item == Py_None || ( BPy_MTex_Check( item ) &&
1451                                                 ((BPy_MTex *)item)->type == ID_LA ) ) {
1452                         continue;
1453                 } else {
1454                         Py_DECREF(value);
1455                         return EXPP_ReturnIntError( PyExc_TypeError,
1456                                         "expected tuple or list containing lamp MTex objects and NONE" );
1457                 }
1458         }
1459
1460         /* for each MTex object, copy to this structure */
1461         for( i= 0; i < PySequence_Size(value) ; ++i ) {
1462                 PyObject *item = PySequence_Fast_GET_ITEM( value, i );
1463                 struct MTex *mtex = self->lamp->mtex[i];
1464                 if( item != Py_None ) {
1465                         BPy_MTex *obj = (BPy_MTex *)item;
1466
1467                         /* if MTex is already at this location, just skip it */
1468                         if( obj->mtex == mtex ) continue;
1469
1470                         /* create a new entry if needed, otherwise update reference count
1471                          * for texture that is being replaced */
1472                         if( !mtex )
1473                                 mtex = self->lamp->mtex[i] = add_mtex(  );
1474                         else
1475                                 mtex->tex->id.us--;
1476
1477                         /* copy the data */
1478                         mtex->tex = obj->mtex->tex;
1479                         id_us_plus( &mtex->tex->id );
1480                         mtex->texco = obj->mtex->texco;
1481                         mtex->mapto = obj->mtex->mapto;
1482                 }
1483         }
1484
1485         /* now go back and free any entries now marked as None */
1486         for( i= 0; i < PySequence_Size(value) ; ++i ) {
1487                 PyObject *item = PySequence_Fast_GET_ITEM( value, i );
1488                 struct MTex *mtex = self->lamp->mtex[i];
1489                 if( item == Py_None && mtex ) {
1490                         mtex->tex->id.us--;
1491                         MEM_freeN( mtex );
1492                         self->lamp->mtex[i] = NULL;
1493                 } 
1494         }
1495
1496         Py_DECREF(value);
1497         return 0;
1498 }
1499
1500 /* #####DEPRECATED###### */
1501
1502 static PyObject *Lamp_oldsetSamples( BPy_Lamp * self, PyObject * args )
1503 {
1504         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSamples );
1505 }
1506
1507 static PyObject *Lamp_oldsetRaySamplesX( BPy_Lamp * self, PyObject * args )
1508 {
1509         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setRaySamplesX );
1510 }
1511
1512 static PyObject *Lamp_oldsetRaySamplesY( BPy_Lamp * self, PyObject * args )
1513 {
1514         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setRaySamplesY );
1515 }
1516
1517 static PyObject *Lamp_oldsetAreaSizeX( BPy_Lamp * self, PyObject * args )
1518 {
1519         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setAreaSizeX );
1520 }
1521
1522 static PyObject *Lamp_oldsetAreaSizeY( BPy_Lamp * self, PyObject * args )
1523 {
1524         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setAreaSizeY );
1525 }
1526
1527 static PyObject *Lamp_oldsetBufferSize( BPy_Lamp * self, PyObject * args )
1528 {
1529         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setBufferSize );
1530 }
1531
1532 static PyObject *Lamp_oldsetHaloStep( BPy_Lamp * self, PyObject * args )
1533 {
1534         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setHaloStep );
1535 }
1536
1537 static PyObject *Lamp_oldsetEnergy( BPy_Lamp * self, PyObject * args )
1538 {
1539         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setEnergy );
1540 }
1541
1542 static PyObject *Lamp_oldsetDist( BPy_Lamp * self, PyObject * args )
1543 {
1544         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setDist );
1545 }
1546
1547 static PyObject *Lamp_oldsetSpotSize( BPy_Lamp * self, PyObject * args )
1548 {
1549         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSpotSize );
1550 }
1551
1552 static PyObject *Lamp_oldsetSpotBlend( BPy_Lamp * self, PyObject * args )
1553 {
1554         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSpotBlend );
1555 }
1556
1557 static PyObject *Lamp_oldsetClipStart( BPy_Lamp * self, PyObject * args )
1558 {
1559         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setClipStart );
1560 }
1561
1562 static PyObject *Lamp_oldsetClipEnd( BPy_Lamp * self, PyObject * args )
1563 {
1564         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setClipEnd );
1565 }
1566
1567 static PyObject *Lamp_oldsetBias( BPy_Lamp * self, PyObject * args )
1568 {
1569         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setBias );
1570 }
1571
1572 static PyObject *Lamp_oldsetSoftness( BPy_Lamp * self, PyObject * args )
1573 {
1574         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSoftness );
1575 }
1576
1577 static PyObject *Lamp_oldsetHaloInt( BPy_Lamp * self, PyObject * args )
1578 {
1579         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setHaloInt );
1580 }
1581
1582 static PyObject *Lamp_oldsetQuad1( BPy_Lamp * self, PyObject * args )
1583 {
1584         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setQuad1 );
1585 }
1586
1587 static PyObject *Lamp_oldsetQuad2( BPy_Lamp * self, PyObject * args )
1588 {
1589         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setQuad2 );
1590 }
1591
1592 static PyObject *Lamp_oldsetIpo( BPy_Lamp * self, PyObject * args )
1593 {
1594         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setIpo );
1595 }
1596
1597 static PyObject *Lamp_oldsetCol( BPy_Lamp * self, PyObject * args )
1598 {
1599         return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setCol );
1600 }
1601
1602 /* 
1603  * the "not-well-behaved" methods which require more processing than 
1604  * just the simple wrapper
1605  */
1606
1607 /*
1608  * clearIpo() returns True/False depending on whether lamp has an Ipo
1609  */
1610
1611 static PyObject *Lamp_clearIpo( BPy_Lamp * self )
1612 {
1613         /* if Ipo defined, delete it and return true */
1614
1615         if( self->lamp->ipo ) {
1616                 PyObject *value = Py_BuildValue( "(O)", Py_None );
1617                 EXPP_setterWrapper ( (void *)self, value, (setter)Lamp_setIpo );
1618                 Py_DECREF ( value );
1619                 return EXPP_incr_ret_True();
1620         }
1621         return EXPP_incr_ret_False(); /* no ipo found */
1622 }
1623
1624 /*
1625  * setType() accepts a string while mode setter takes an integer
1626  */
1627
1628 static PyObject *Lamp_oldsetType( BPy_Lamp * self, PyObject * value )
1629 {
1630         char *type = PyString_AsString(value);
1631         PyObject *arg, *error;
1632
1633         /* parse string argument */     
1634         if( !type ) 
1635                 return EXPP_ReturnPyObjError ( PyExc_TypeError,
1636                                                "expected string argument" );
1637         
1638         /* check for valid arguments, set type accordingly */
1639
1640         if( !strcmp( type, "Lamp" ) )
1641                 self->lamp->type = ( short ) EXPP_LAMP_TYPE_LAMP;
1642         else if( !strcmp( type, "Sun" ) )
1643                 self->lamp->type = ( short ) EXPP_LAMP_TYPE_SUN;
1644         else if( !strcmp( type, "Spot" ) )
1645                 self->lamp->type = ( short ) EXPP_LAMP_TYPE_SPOT;
1646         else if( !strcmp( type, "Hemi" ) )
1647                 self->lamp->type = ( short ) EXPP_LAMP_TYPE_HEMI;
1648         else if( !strcmp( type, "Area" ) )
1649                 self->lamp->type = ( short ) EXPP_LAMP_TYPE_AREA;
1650         else if( !strcmp( type, "Photon" ) )
1651                 self->lamp->type = ( short ) EXPP_LAMP_TYPE_YF_PHOTON;
1652         else
1653                 return EXPP_ReturnPyObjError( PyExc_AttributeError,
1654                                                 "unknown lamp type" );
1655
1656         /* build tuple, call wrapper */
1657
1658         arg = Py_BuildValue( "(i)", self->lamp->type );
1659         error = EXPP_setterWrapper ( (void *)self, arg, (setter)Lamp_setType );
1660         Py_DECREF ( arg );
1661         return error;
1662 }
1663
1664 /*
1665  * setMode() accepts up to ten strings while mode setter takes an integer
1666  */
1667
1668 static PyObject *Lamp_oldsetMode( BPy_Lamp * self, PyObject * args )
1669 {
1670         short i, flag = 0;
1671         PyObject *error, *value;
1672         char *name;
1673
1674         /* check that we're passed a tuple of no more than 10 args*/
1675
1676         if ( !PyTuple_Check( args ) || PyTuple_Size( args ) > 10 )
1677                 return EXPP_ReturnPyObjError ( PyExc_AttributeError,
1678                                         "expected up to 10 string arguments" );
1679
1680         /* check each argument for type, find its value */
1681
1682         for ( i = (short)PyTuple_Size( args ); i-- ; ) {
1683                 name = PyString_AsString ( PyTuple_GET_ITEM( args, i ) );
1684                 if( !name )
1685                         return EXPP_ReturnPyObjError ( PyExc_AttributeError,
1686                                         "expected string argument" );
1687
1688                 if( !strcmp( name, "Shadows" ) )
1689                         flag |= ( short ) EXPP_LAMP_MODE_SHADOWS;
1690                 else if( !strcmp( name, "Halo" ) )
1691                         flag |= ( short ) EXPP_LAMP_MODE_HALO;
1692                 else if( !strcmp( name, "Layer" ) )
1693                         flag |= ( short ) EXPP_LAMP_MODE_LAYER;
1694                 else if( !strcmp( name, "Quad" ) )
1695                         flag |= ( short ) EXPP_LAMP_MODE_QUAD;
1696                 else if( !strcmp( name, "Negative" ) )
1697                         flag |= ( short ) EXPP_LAMP_MODE_NEGATIVE;
1698                 else if( !strcmp( name, "OnlyShadow" ) )
1699                         flag |= ( short ) EXPP_LAMP_MODE_ONLYSHADOW;
1700                 else if( !strcmp( name, "Sphere" ) )
1701                         flag |= ( short ) EXPP_LAMP_MODE_SPHERE;
1702                 else if( !strcmp( name, "Square" ) )
1703                         flag |= ( short ) EXPP_LAMP_MODE_SQUARE;
1704                 else if( !strcmp( name, "NoDiffuse" ) )
1705                         flag |= ( short ) EXPP_LAMP_MODE_NODIFFUSE;
1706                 else if( !strcmp( name, "NoSpecular" ) )
1707                         flag |= ( short ) EXPP_LAMP_MODE_NOSPECULAR;
1708                 else if( !strcmp( name, "RayShadow" ) )
1709                         flag |= ( short ) EXPP_LAMP_MODE_SHAD_RAY;
1710                 else if( !strcmp( name, "LayerShadow" ) )
1711                         flag |= ( short ) EXPP_LAMP_MODE_LAYER_SHADOW;
1712                 else
1713                         return EXPP_ReturnPyObjError( PyExc_AttributeError,
1714                                                         "unknown lamp flag argument" );
1715         }
1716
1717         /* build tuple, call wrapper */
1718
1719         value = Py_BuildValue( "(i)", flag );
1720         error = EXPP_setterWrapper ( (void *)self, value, (setter)Lamp_setMode );
1721         Py_DECREF ( value );
1722         return error;
1723 }
1724