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