Cleanup: pep8
[blender.git] / release / scripts / startup / bl_ui / properties_data_curve.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 bpy.types import Panel
22 from rna_prop_ui import PropertyPanel
23
24 from bpy.types import Curve, SurfaceCurve, TextCurve
25
26
27 class CurveButtonsPanel:
28     bl_space_type = 'PROPERTIES'
29     bl_region_type = 'WINDOW'
30     bl_context = "data"
31
32     @classmethod
33     def poll(cls, context):
34         return (context.curve is not None)
35
36
37 class CurveButtonsPanelCurve(CurveButtonsPanel):
38     @classmethod
39     def poll(cls, context):
40         return (type(context.curve) is Curve)
41
42
43 class CurveButtonsPanelSurface(CurveButtonsPanel):
44     @classmethod
45     def poll(cls, context):
46         return (type(context.curve) is SurfaceCurve)
47
48
49 class CurveButtonsPanelText(CurveButtonsPanel):
50     @classmethod
51     def poll(cls, context):
52         return (type(context.curve) is TextCurve)
53
54
55 class CurveButtonsPanelActive(CurveButtonsPanel):
56     """Same as above but for curves only"""
57
58     @classmethod
59     def poll(cls, context):
60         curve = context.curve
61         return (curve and type(curve) is not TextCurve and curve.splines.active)
62
63
64 class DATA_PT_context_curve(CurveButtonsPanel, Panel):
65     bl_label = ""
66     bl_options = {'HIDE_HEADER'}
67
68     def draw(self, context):
69         layout = self.layout
70
71         obj = context.object
72         curve = context.curve
73         space = context.space_data
74
75         if obj:
76             layout.template_ID(obj, "data")
77         elif curve:
78             layout.template_ID(space, "pin_id")
79
80
81 class DATA_PT_shape_curve(CurveButtonsPanel, Panel):
82     bl_label = "Shape"
83
84     def draw(self, context):
85         layout = self.layout
86
87         curve = context.curve
88         is_surf = type(curve) is SurfaceCurve
89         is_curve = type(curve) is Curve
90         is_text = type(curve) is TextCurve
91
92         if is_curve:
93             row = layout.row()
94             row.prop(curve, "dimensions", expand=True)
95
96         split = layout.split()
97
98         col = split.column()
99         col.label(text="Resolution:")
100         sub = col.column(align=True)
101         sub.prop(curve, "resolution_u", text="Preview U")
102         sub.prop(curve, "render_resolution_u", text="Render U")
103         if is_curve:
104             col.label(text="Twisting:")
105             col.prop(curve, "twist_mode", text="")
106             col.prop(curve, "twist_smooth", text="Smooth")
107         elif is_text:
108             col.label(text="Display:")
109             col.prop(curve, "use_fast_edit", text="Fast Editing")
110
111         col = split.column()
112
113         if is_surf:
114             sub = col.column()
115             sub.label(text="")
116             sub = col.column(align=True)
117             sub.prop(curve, "resolution_v", text="Preview V")
118             sub.prop(curve, "render_resolution_v", text="Render V")
119
120         if is_curve or is_text:
121             col.label(text="Fill:")
122             sub = col.column()
123             sub.active = (curve.dimensions == '2D' or (curve.bevel_object is None and curve.dimensions == '3D'))
124             sub.prop(curve, "fill_mode", text="")
125             col.prop(curve, "use_fill_deform")
126
127         if is_curve:
128             col.label(text="Path/Curve-Deform:")
129             sub = col.column()
130             subsub = sub.row()
131             subsub.prop(curve, "use_radius")
132             subsub.prop(curve, "use_stretch")
133             sub.prop(curve, "use_deform_bounds")
134
135
136 class DATA_PT_curve_texture_space(CurveButtonsPanel, Panel):
137     bl_label = "Texture Space"
138     bl_options = {'DEFAULT_CLOSED'}
139     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
140
141     def draw(self, context):
142         layout = self.layout
143
144         curve = context.curve
145
146         row = layout.row()
147         row.prop(curve, "use_auto_texspace")
148         row.prop(curve, "use_uv_as_generated")
149
150         row = layout.row()
151         row.column().prop(curve, "texspace_location", text="Location")
152         row.column().prop(curve, "texspace_size", text="Size")
153
154         layout.operator("curve.match_texture_space")
155
156
157 class DATA_PT_geometry_curve(CurveButtonsPanelCurve, Panel):
158     bl_label = "Geometry"
159
160     @classmethod
161     def poll(cls, context):
162         return (type(context.curve) in {Curve, TextCurve})
163
164     def draw(self, context):
165         layout = self.layout
166
167         curve = context.curve
168
169         split = layout.split()
170
171         col = split.column()
172         col.label(text="Modification:")
173         col.prop(curve, "offset")
174         col.prop(curve, "extrude")
175         col.label(text="Taper Object:")
176         col.prop(curve, "taper_object", text="")
177
178         col = split.column()
179         col.label(text="Bevel:")
180         col.prop(curve, "bevel_depth", text="Depth")
181         col.prop(curve, "bevel_resolution", text="Resolution")
182         col.label(text="Bevel Object:")
183         col.prop(curve, "bevel_object", text="")
184
185         if type(curve) is not TextCurve:
186             col = layout.column(align=True)
187             row = col.row()
188             row.label(text="Bevel Factor:")
189
190             col = layout.column()
191             col.active = (
192                 (curve.bevel_depth > 0.0) or
193                 (curve.extrude > 0.0) or
194                 (curve.bevel_object is not None)
195             )
196             row = col.row(align=True)
197             row.prop(curve, "bevel_factor_mapping_start", text="")
198             row.prop(curve, "bevel_factor_start", text="Start")
199             row = col.row(align=True)
200             row.prop(curve, "bevel_factor_mapping_end", text="")
201             row.prop(curve, "bevel_factor_end", text="End")
202
203             row = layout.row()
204             sub = row.row()
205             sub.active = curve.taper_object is not None
206             sub.prop(curve, "use_map_taper")
207             sub = row.row()
208             sub.active = curve.bevel_object is not None
209             sub.prop(curve, "use_fill_caps")
210
211
212 class DATA_PT_pathanim(CurveButtonsPanelCurve, Panel):
213     bl_label = "Path Animation"
214
215     def draw_header(self, context):
216         curve = context.curve
217
218         self.layout.prop(curve, "use_path", text="")
219
220     def draw(self, context):
221         layout = self.layout
222
223         curve = context.curve
224
225         layout.active = curve.use_path
226
227         col = layout.column()
228         col.prop(curve, "path_duration", text="Frames")
229         col.prop(curve, "eval_time")
230
231         # these are for paths only
232         row = layout.row()
233         row.prop(curve, "use_path_follow")
234
235
236 class DATA_PT_active_spline(CurveButtonsPanelActive, Panel):
237     bl_label = "Active Spline"
238
239     def draw(self, context):
240         layout = self.layout
241
242         curve = context.curve
243         act_spline = curve.splines.active
244         is_surf = type(curve) is SurfaceCurve
245         is_poly = (act_spline.type == 'POLY')
246
247         split = layout.split()
248
249         if is_poly:
250             # These settings are below but its easier to have
251             # polys set aside since they use so few settings
252             row = layout.row()
253             row.label(text="Cyclic:")
254             row.prop(act_spline, "use_cyclic_u", text="U")
255
256             layout.prop(act_spline, "use_smooth")
257         else:
258             col = split.column()
259             col.label(text="Cyclic:")
260             if act_spline.type == 'NURBS':
261                 col.label(text="Bezier:")
262                 col.label(text="Endpoint:")
263                 col.label(text="Order:")
264
265             col.label(text="Resolution:")
266
267             col = split.column()
268             col.prop(act_spline, "use_cyclic_u", text="U")
269
270             if act_spline.type == 'NURBS':
271                 sub = col.column()
272                 # sub.active = (not act_spline.use_cyclic_u)
273                 sub.prop(act_spline, "use_bezier_u", text="U")
274                 sub.prop(act_spline, "use_endpoint_u", text="U")
275
276                 sub = col.column()
277                 sub.prop(act_spline, "order_u", text="U")
278             col.prop(act_spline, "resolution_u", text="U")
279
280             if is_surf:
281                 col = split.column()
282                 col.prop(act_spline, "use_cyclic_v", text="V")
283
284                 # its a surface, assume its a nurbs
285                 sub = col.column()
286                 sub.active = (not act_spline.use_cyclic_v)
287                 sub.prop(act_spline, "use_bezier_v", text="V")
288                 sub.prop(act_spline, "use_endpoint_v", text="V")
289                 sub = col.column()
290                 sub.prop(act_spline, "order_v", text="V")
291                 sub.prop(act_spline, "resolution_v", text="V")
292
293             if act_spline.type == 'BEZIER':
294                 col = layout.column()
295                 col.label(text="Interpolation:")
296
297                 sub = col.column()
298                 sub.active = (curve.dimensions == '3D')
299                 sub.prop(act_spline, "tilt_interpolation", text="Tilt")
300
301                 col.prop(act_spline, "radius_interpolation", text="Radius")
302
303             layout.prop(act_spline, "use_smooth")
304
305
306 class DATA_PT_font(CurveButtonsPanelText, Panel):
307     bl_label = "Font"
308
309     def draw(self, context):
310         layout = self.layout
311
312         text = context.curve
313         char = context.curve.edit_format
314
315         row = layout.split(percentage=0.25)
316         row.label(text="Regular")
317         row.template_ID(text, "font", open="font.open", unlink="font.unlink")
318         row = layout.split(percentage=0.25)
319         row.label(text="Bold")
320         row.template_ID(text, "font_bold", open="font.open", unlink="font.unlink")
321         row = layout.split(percentage=0.25)
322         row.label(text="Italic")
323         row.template_ID(text, "font_italic", open="font.open", unlink="font.unlink")
324         row = layout.split(percentage=0.25)
325         row.label(text="Bold & Italic")
326         row.template_ID(text, "font_bold_italic", open="font.open", unlink="font.unlink")
327
328         # layout.prop(text, "font")
329
330         split = layout.split()
331
332         col = split.column()
333         col.prop(text, "size", text="Size")
334         col = split.column()
335         col.prop(text, "shear")
336
337         split = layout.split()
338
339         col = split.column()
340         col.label(text="Object Font:")
341         col.prop(text, "family", text="")
342
343         col = split.column()
344         col.label(text="Text on Curve:")
345         col.prop(text, "follow_curve", text="")
346
347         split = layout.split()
348
349         col = split.column()
350         sub = col.column(align=True)
351         sub.label(text="Underline:")
352         sub.prop(text, "underline_position", text="Position")
353         sub.prop(text, "underline_height", text="Thickness")
354
355         col = split.column()
356         col.label(text="Character:")
357         col.prop(char, "use_bold")
358         col.prop(char, "use_italic")
359         col.prop(char, "use_underline")
360
361         row = layout.row()
362         row.prop(text, "small_caps_scale", text="Small Caps")
363         row.prop(char, "use_small_caps")
364
365
366 class DATA_PT_paragraph(CurveButtonsPanelText, Panel):
367     bl_label = "Paragraph"
368
369     def draw(self, context):
370         layout = self.layout
371
372         text = context.curve
373
374         layout.label(text="Horizontal Alignment:")
375         layout.row().prop(text, "align_x", expand=True)
376
377         layout.label(text="Vertical Alignment:")
378         layout.row().prop(text, "align_y", expand=True)
379
380         split = layout.split()
381
382         col = split.column(align=True)
383         col.label(text="Spacing:")
384         col.prop(text, "space_character", text="Letter")
385         col.prop(text, "space_word", text="Word")
386         col.prop(text, "space_line", text="Line")
387
388         col = split.column(align=True)
389         col.label(text="Offset:")
390         col.prop(text, "offset_x", text="X")
391         col.prop(text, "offset_y", text="Y")
392
393
394 class DATA_PT_text_boxes(CurveButtonsPanelText, Panel):
395     bl_label = "Text Boxes"
396
397     def draw(self, context):
398         layout = self.layout
399
400         text = context.curve
401
402         split = layout.split()
403         col = split.column()
404         col.operator("font.textbox_add", icon='ZOOMIN')
405         col = split.column()
406
407         for i, box in enumerate(text.text_boxes):
408
409             boxy = layout.box()
410
411             row = boxy.row()
412
413             split = row.split()
414
415             col = split.column(align=True)
416
417             col.label(text="Dimensions:")
418             col.prop(box, "width", text="Width")
419             col.prop(box, "height", text="Height")
420
421             col = split.column(align=True)
422
423             col.label(text="Offset:")
424             col.prop(box, "x", text="X")
425             col.prop(box, "y", text="Y")
426
427             row.operator("font.textbox_remove", text="", icon='X', emboss=False).index = i
428
429
430 class DATA_PT_custom_props_curve(CurveButtonsPanel, PropertyPanel, Panel):
431     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
432     _context_path = "object.data"
433     _property_type = bpy.types.Curve
434
435
436 classes = (
437     DATA_PT_context_curve,
438     DATA_PT_shape_curve,
439     DATA_PT_curve_texture_space,
440     DATA_PT_geometry_curve,
441     DATA_PT_pathanim,
442     DATA_PT_active_spline,
443     DATA_PT_font,
444     DATA_PT_paragraph,
445     DATA_PT_text_boxes,
446     DATA_PT_custom_props_curve,
447 )
448
449 if __name__ == "__main__":  # only for live edit.
450     from bpy.utils import register_class
451     for cls in classes:
452         register_class(cls)