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