bugfix [#23182] Using self.report() inside poll() gives crash
[blender.git] / release / scripts / ui / properties_data_lamp.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from rna_prop_ui import PropertyPanel
22
23 narrowui = bpy.context.user_preferences.view.properties_width_check
24
25
26 class LAMP_MT_sunsky_presets(bpy.types.Menu):
27     bl_label = "Sun & Sky Presets"
28     preset_subdir = "sunsky"
29     preset_operator = "script.execute_preset"
30     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
31     draw = bpy.types.Menu.draw_preset
32
33
34 class DataButtonsPanel():
35     bl_space_type = 'PROPERTIES'
36     bl_region_type = 'WINDOW'
37     bl_context = "data"
38
39
40 class DATA_PT_preview(DataButtonsPanel, bpy.types.Panel):
41     bl_label = "Preview"
42     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
43
44     @staticmethod
45     def poll(context):
46         engine = context.scene.render.engine
47         return context.lamp and (engine in __class__.COMPAT_ENGINES)
48
49     def draw(self, context):
50         self.layout.template_preview(context.lamp)
51
52 class DATA_PT_context_lamp(DataButtonsPanel, bpy.types.Panel):
53     bl_label = ""
54     bl_show_header = False
55     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
56
57     @staticmethod
58     def poll(context):
59         engine = context.scene.render.engine
60         return context.lamp and (engine in __class__.COMPAT_ENGINES)
61
62     def draw(self, context):
63         layout = self.layout
64
65         ob = context.object
66         lamp = context.lamp
67         space = context.space_data
68         wide_ui = context.region.width > narrowui
69
70         if wide_ui:
71             split = layout.split(percentage=0.65)
72             if ob:
73                 split.template_ID(ob, "data")
74                 split.separator()
75             elif lamp:
76                 split.template_ID(space, "pin_id")
77                 split.separator()
78         else:
79             if ob:
80                 layout.template_ID(ob, "data")
81             elif lamp:
82                 layout.template_ID(space, "pin_id")
83
84
85 class DATA_PT_custom_props_lamp(DataButtonsPanel, PropertyPanel, bpy.types.Panel):
86     _context_path = "object.data"
87     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
88
89     @staticmethod
90     def poll(context):
91         engine = context.scene.render.engine
92         return context.lamp and (engine in __class__.COMPAT_ENGINES)
93
94
95 class DATA_PT_lamp(DataButtonsPanel, bpy.types.Panel):
96     bl_label = "Lamp"
97     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
98
99     @staticmethod
100     def poll(context):
101         engine = context.scene.render.engine
102         return context.lamp and (engine in __class__.COMPAT_ENGINES)
103
104     def draw(self, context):
105         layout = self.layout
106
107         lamp = context.lamp
108         wide_ui = context.region.width > narrowui
109
110         if wide_ui:
111             layout.prop(lamp, "type", expand=True)
112         else:
113             layout.prop(lamp, "type", text="")
114
115         split = layout.split()
116
117         col = split.column()
118         sub = col.column()
119         sub.prop(lamp, "color", text="")
120         sub.prop(lamp, "energy")
121
122         if lamp.type in ('POINT', 'SPOT'):
123             sub.label(text="Falloff:")
124             sub.prop(lamp, "falloff_type", text="")
125             sub.prop(lamp, "distance")
126
127             if lamp.falloff_type == 'LINEAR_QUADRATIC_WEIGHTED':
128                 col.label(text="Attenuation Factors:")
129                 sub = col.column(align=True)
130                 sub.prop(lamp, "linear_attenuation", slider=True, text="Linear")
131                 sub.prop(lamp, "quadratic_attenuation", slider=True, text="Quadratic")
132
133             col.prop(lamp, "sphere")
134
135         if lamp.type == 'AREA':
136             col.prop(lamp, "distance")
137             col.prop(lamp, "gamma")
138
139         if wide_ui:
140             col = split.column()
141         col.prop(lamp, "negative")
142         col.prop(lamp, "layer", text="This Layer Only")
143         col.prop(lamp, "specular")
144         col.prop(lamp, "diffuse")
145
146
147 class DATA_PT_sunsky(DataButtonsPanel, bpy.types.Panel):
148     bl_label = "Sky & Atmosphere"
149     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
150
151     @staticmethod
152     def poll(context):
153         lamp = context.lamp
154         engine = context.scene.render.engine
155         return (lamp and lamp.type == 'SUN') and (engine in __class__.COMPAT_ENGINES)
156
157     def draw(self, context):
158         layout = self.layout
159
160         lamp = context.lamp.sky
161         wide_ui = context.region.width > narrowui
162
163         row = layout.row(align=True)
164         row.prop(lamp, "use_sky")
165         row.menu("LAMP_MT_sunsky_presets", text=bpy.types.LAMP_MT_sunsky_presets.bl_label)
166         row.operator("lamp.sunsky_preset_add", text="", icon="ZOOMIN")
167
168         row = layout.row()
169         row.active = lamp.use_sky or lamp.use_atmosphere
170         row.prop(lamp, "atmosphere_turbidity", text="Turbidity")
171
172         split = layout.split()
173
174         col = split.column()
175         col.active = lamp.use_sky
176         col.label(text="Blending:")
177         sub = col.column()
178         sub.prop(lamp, "sky_blend_type", text="")
179         sub.prop(lamp, "sky_blend", text="Factor")
180
181         col.label(text="Color Space:")
182         sub = col.column()
183         sub.row().prop(lamp, "sky_color_space", expand=True)
184         sub.prop(lamp, "sky_exposure", text="Exposure")
185
186         if wide_ui:
187             col = split.column()
188         col.active = lamp.use_sky
189         col.label(text="Horizon:")
190         sub = col.column()
191         sub.prop(lamp, "horizon_brightness", text="Brightness")
192         sub.prop(lamp, "spread", text="Spread")
193
194         col.label(text="Sun:")
195         sub = col.column()
196         sub.prop(lamp, "sun_brightness", text="Brightness")
197         sub.prop(lamp, "sun_size", text="Size")
198         sub.prop(lamp, "backscattered_light", slider=True, text="Back Light")
199
200         layout.separator()
201
202         layout.prop(lamp, "use_atmosphere")
203
204         split = layout.split()
205
206         col = split.column()
207         col.active = lamp.use_atmosphere
208         col.label(text="Intensity:")
209         col.prop(lamp, "sun_intensity", text="Sun")
210         col.prop(lamp, "atmosphere_distance_factor", text="Distance")
211
212         if wide_ui:
213             col = split.column()
214         col.active = lamp.use_atmosphere
215         col.label(text="Scattering:")
216         sub = col.column(align=True)
217         sub.prop(lamp, "atmosphere_inscattering", slider=True, text="Inscattering")
218         sub.prop(lamp, "atmosphere_extinction", slider=True, text="Extinction")
219
220
221 class DATA_PT_shadow(DataButtonsPanel, bpy.types.Panel):
222     bl_label = "Shadow"
223     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
224
225     @staticmethod
226     def poll(context):
227         lamp = context.lamp
228         engine = context.scene.render.engine
229         return (lamp and lamp.type in ('POINT', 'SUN', 'SPOT', 'AREA')) and (engine in __class__.COMPAT_ENGINES)
230
231     def draw(self, context):
232         layout = self.layout
233
234         lamp = context.lamp
235         wide_ui = context.region.width > narrowui
236
237         if wide_ui:
238             layout.prop(lamp, "shadow_method", expand=True)
239         else:
240             layout.prop(lamp, "shadow_method", text="")
241
242         if lamp.shadow_method != 'NOSHADOW':
243             split = layout.split()
244
245             col = split.column()
246             col.prop(lamp, "shadow_color", text="")
247
248             if wide_ui:
249                 col = split.column()
250             col.prop(lamp, "shadow_layer", text="This Layer Only")
251             col.prop(lamp, "only_shadow")
252
253         if lamp.shadow_method == 'RAY_SHADOW':
254             col = layout.column()
255             col.label(text="Sampling:")
256             if wide_ui:
257                 col.row().prop(lamp, "shadow_ray_sampling_method", expand=True)
258             else:
259                 col.prop(lamp, "shadow_ray_sampling_method", text="")
260
261             if lamp.type in ('POINT', 'SUN', 'SPOT'):
262                 split = layout.split()
263
264                 col = split.column()
265                 col.prop(lamp, "shadow_soft_size", text="Soft Size")
266
267                 col.prop(lamp, "shadow_ray_samples", text="Samples")
268                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
269                     col.prop(lamp, "shadow_adaptive_threshold", text="Threshold")
270                 if wide_ui:
271                     col = split.column()
272
273             elif lamp.type == 'AREA':
274                 split = layout.split()
275
276                 col = split.column()
277
278                 if lamp.shape == 'SQUARE':
279                     col.prop(lamp, "shadow_ray_samples_x", text="Samples")
280                 elif lamp.shape == 'RECTANGLE':
281                     col.prop(lamp, "shadow_ray_samples_x", text="Samples X")
282                     col.prop(lamp, "shadow_ray_samples_y", text="Samples Y")
283
284                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
285                     col.prop(lamp, "shadow_adaptive_threshold", text="Threshold")
286                     if wide_ui:
287                         col = split.column()
288
289                 elif lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
290                     if wide_ui:
291                         col = split.column()
292                     col.prop(lamp, "umbra")
293                     col.prop(lamp, "dither")
294                     col.prop(lamp, "jitter")
295                 else:
296                     if wide_ui:
297                         col = split.column()
298
299
300         elif lamp.shadow_method == 'BUFFER_SHADOW':
301             col = layout.column()
302             col.label(text="Buffer Type:")
303             if wide_ui:
304                 col.row().prop(lamp, "shadow_buffer_type", expand=True)
305             else:
306                 col.row().prop(lamp, "shadow_buffer_type", text="")
307
308             if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY', 'DEEP'):
309                 split = layout.split()
310
311                 col = split.column()
312                 col.label(text="Filter Type:")
313                 col.prop(lamp, "shadow_filter_type", text="")
314                 sub = col.column(align=True)
315                 sub.prop(lamp, "shadow_buffer_soft", text="Soft")
316                 sub.prop(lamp, "shadow_buffer_bias", text="Bias")
317
318                 if wide_ui:
319                     col = split.column()
320                 col.label(text="Sample Buffers:")
321                 col.prop(lamp, "shadow_sample_buffers", text="")
322                 sub = col.column(align=True)
323                 sub.prop(lamp, "shadow_buffer_size", text="Size")
324                 sub.prop(lamp, "shadow_buffer_samples", text="Samples")
325                 if lamp.shadow_buffer_type == 'DEEP':
326                     col.prop(lamp, "compression_threshold")
327
328             elif lamp.shadow_buffer_type == 'IRREGULAR':
329                 layout.prop(lamp, "shadow_buffer_bias", text="Bias")
330
331             split = layout.split()
332
333             col = split.column()
334             col.prop(lamp, "auto_clip_start", text="Autoclip Start")
335             sub = col.column()
336             sub.active = not lamp.auto_clip_start
337             sub.prop(lamp, "shadow_buffer_clip_start", text="Clip Start")
338
339             if wide_ui:
340                 col = split.column()
341             col.prop(lamp, "auto_clip_end", text="Autoclip End")
342             sub = col.column()
343             sub.active = not lamp.auto_clip_end
344             sub.prop(lamp, "shadow_buffer_clip_end", text=" Clip End")
345
346
347 class DATA_PT_area(DataButtonsPanel, bpy.types.Panel):
348     bl_label = "Area Shape"
349     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
350
351     @staticmethod
352     def poll(context):
353         lamp = context.lamp
354         engine = context.scene.render.engine
355         return (lamp and lamp.type == 'AREA') and (engine in __class__.COMPAT_ENGINES)
356
357     def draw(self, context):
358         layout = self.layout
359
360         lamp = context.lamp
361
362         split = layout.split()
363
364         col = split.column()
365         col.row().prop(lamp, "shape", expand=True)
366
367         sub = col.column(align=True)
368         if (lamp.shape == 'SQUARE'):
369             sub.prop(lamp, "size")
370         elif (lamp.shape == 'RECTANGLE'):
371             sub.prop(lamp, "size", text="Size X")
372             sub.prop(lamp, "size_y", text="Size Y")
373
374
375 class DATA_PT_spot(DataButtonsPanel, bpy.types.Panel):
376     bl_label = "Spot Shape"
377     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
378
379     @staticmethod
380     def poll(context):
381         lamp = context.lamp
382         engine = context.scene.render.engine
383         return (lamp and lamp.type == 'SPOT') and (engine in __class__.COMPAT_ENGINES)
384
385     def draw(self, context):
386         layout = self.layout
387
388         lamp = context.lamp
389         wide_ui = context.region.width > narrowui
390
391         split = layout.split()
392
393         col = split.column()
394         sub = col.column()
395         sub.prop(lamp, "spot_size", text="Size")
396         sub.prop(lamp, "spot_blend", text="Blend", slider=True)
397         col.prop(lamp, "square")
398         col.prop(lamp, "show_cone")
399
400         if wide_ui:
401             col = split.column()
402         else:
403             col.separator()
404         col.prop(lamp, "halo")
405         sub = col.column(align=True)
406         sub.active = lamp.halo
407         sub.prop(lamp, "halo_intensity", text="Intensity")
408         if lamp.shadow_method == 'BUFFER_SHADOW':
409             sub.prop(lamp, "halo_step", text="Step")
410
411
412 class DATA_PT_falloff_curve(DataButtonsPanel, bpy.types.Panel):
413     bl_label = "Falloff Curve"
414     bl_default_closed = True
415     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
416
417     @staticmethod
418     def poll(context):
419         lamp = context.lamp
420         engine = context.scene.render.engine
421
422         return (lamp and lamp.type in ('POINT', 'SPOT') and lamp.falloff_type == 'CUSTOM_CURVE') and (engine in __class__.COMPAT_ENGINES)
423
424     def draw(self, context):
425         lamp = context.lamp
426
427         self.layout.template_curve_mapping(lamp, "falloff_curve")
428
429
430 def register():
431     pass
432
433
434 def unregister():
435     pass
436
437 if __name__ == "__main__":
438     register()