Merging r43501 through r43720 form trunk into soc-2011-tomato
[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         if 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", text="Fill Deformed")
115
116
117 class DATA_PT_curve_texture_space(CurveButtonsPanel, Panel):
118     bl_label = "Texture Space"
119     bl_options = {'DEFAULT_CLOSED'}
120     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
121
122     def draw(self, context):
123         layout = self.layout
124
125         curve = context.curve
126
127         row = layout.row()
128         row.prop(curve, "use_auto_texspace")
129         row.prop(curve, "use_uv_as_generated")
130
131         row = layout.row()
132         row.column().prop(curve, "texspace_location", text="Location")
133         row.column().prop(curve, "texspace_size", text="Size")
134
135
136 class DATA_PT_geometry_curve(CurveButtonsPanel, Panel):
137     bl_label = "Geometry"
138
139     @classmethod
140     def poll(cls, context):
141         obj = context.object
142         if obj and obj.type == 'SURFACE':
143             return False
144
145         return context.curve
146
147     def draw(self, context):
148         layout = self.layout
149
150         curve = context.curve
151
152         split = layout.split()
153
154         col = split.column()
155         col.label(text="Modification:")
156         col.prop(curve, "offset")
157         col.prop(curve, "extrude")
158         col.label(text="Taper Object:")
159         col.prop(curve, "taper_object", text="")
160
161         col = split.column()
162         col.label(text="Bevel:")
163         col.prop(curve, "bevel_depth", text="Depth")
164         col.prop(curve, "bevel_resolution", text="Resolution")
165         col.label(text="Bevel Object:")
166         col.prop(curve, "bevel_object", text="")
167
168
169 class DATA_PT_pathanim(CurveButtonsPanelCurve, Panel):
170     bl_label = "Path Animation"
171
172     def draw_header(self, context):
173         curve = context.curve
174
175         self.layout.prop(curve, "use_path", text="")
176
177     def draw(self, context):
178         layout = self.layout
179
180         curve = context.curve
181
182         layout.active = curve.use_path
183
184         col = layout.column()
185         layout.prop(curve, "path_duration", text="Frames")
186         layout.prop(curve, "eval_time")
187
188         split = layout.split()
189
190         col = split.column()
191         col.prop(curve, "use_path_follow")
192         col.prop(curve, "use_stretch")
193         col.prop(curve, "use_deform_bounds")
194
195         col = split.column()
196         col.prop(curve, "use_radius")
197         col.prop(curve, "use_time_offset", text="Offset Children")
198
199
200 class DATA_PT_active_spline(CurveButtonsPanelActive, Panel):
201     bl_label = "Active Spline"
202
203     def draw(self, context):
204         layout = self.layout
205
206         ob = context.object
207         curve = context.curve
208         act_spline = curve.splines.active
209         is_surf = (ob.type == 'SURFACE')
210         is_poly = (act_spline.type == 'POLY')
211
212         split = layout.split()
213
214         if is_poly:
215             # These settings are below but its easier to have
216             # poly's set aside since they use so few settings
217             row = layout.row()
218             row.label(text="Cyclic:")
219             row.prop(act_spline, "use_cyclic_u", text="U")
220
221             layout.prop(act_spline, "use_smooth")
222         else:
223             col = split.column()
224             col.label(text="Cyclic:")
225             if act_spline.type == 'NURBS':
226                 col.label(text="Bezier:")
227                 col.label(text="Endpoint:")
228                 col.label(text="Order:")
229
230             col.label(text="Resolution:")
231
232             col = split.column()
233             col.prop(act_spline, "use_cyclic_u", text="U")
234
235             if act_spline.type == 'NURBS':
236                 sub = col.column()
237                 # sub.active = (not act_spline.use_cyclic_u)
238                 sub.prop(act_spline, "use_bezier_u", text="U")
239                 sub.prop(act_spline, "use_endpoint_u", text="U")
240
241                 sub = col.column()
242                 sub.prop(act_spline, "order_u", text="U")
243             col.prop(act_spline, "resolution_u", text="U")
244
245             if is_surf:
246                 col = split.column()
247                 col.prop(act_spline, "use_cyclic_v", text="V")
248
249                 # its a surface, assume its a nurb.
250                 sub = col.column()
251                 sub.active = (not act_spline.use_cyclic_v)
252                 sub.prop(act_spline, "use_bezier_v", text="V")
253                 sub.prop(act_spline, "use_endpoint_v", text="V")
254                 sub = col.column()
255                 sub.prop(act_spline, "order_v", text="V")
256                 sub.prop(act_spline, "resolution_v", text="V")
257
258             if not is_surf:
259                 col = layout.column()
260                 col.label(text="Interpolation:")
261
262                 sub = col.column()
263                 sub.active = (curve.dimensions == '3D')
264                 sub.prop(act_spline, "tilt_interpolation", text="Tilt")
265
266                 col.prop(act_spline, "radius_interpolation", text="Radius")
267
268             layout.prop(act_spline, "use_smooth")
269
270
271 class DATA_PT_font(CurveButtonsPanel, Panel):
272     bl_label = "Font"
273
274     @classmethod
275     def poll(cls, context):
276         return (context.object and context.object.type == 'FONT' and context.curve)
277
278     def draw(self, context):
279         layout = self.layout
280
281         text = context.curve
282         char = context.curve.edit_format
283
284         row = layout.split(percentage=0.25)
285         row.label(text="Regular")
286         row.template_ID(text, "font", open="font.open", unlink="font.unlink")
287         row = layout.split(percentage=0.25)
288         row.label(text="Bold")
289         row.template_ID(text, "font_bold", open="font.open", unlink="font.unlink")
290         row = layout.split(percentage=0.25)
291         row.label(text="Italic")
292         row.template_ID(text, "font_italic", open="font.open", unlink="font.unlink")
293         row = layout.split(percentage=0.25)
294         row.label(text="Bold & Italic")
295         row.template_ID(text, "font_bold_italic", open="font.open", unlink="font.unlink")
296
297         #layout.prop(text, "font")
298
299         split = layout.split()
300
301         col = split.column()
302         col.prop(text, "size", text="Size")
303         col = split.column()
304         col.prop(text, "shear")
305
306         split = layout.split()
307
308         col = split.column()
309         col.label(text="Object Font:")
310         col.prop(text, "family", text="")
311
312         col = split.column()
313         col.label(text="Text on Curve:")
314         col.prop(text, "follow_curve", text="")
315
316         split = layout.split()
317
318         col = split.column()
319         colsub = col.column(align=True)
320         colsub.label(text="Underline:")
321         colsub.prop(text, "underline_position", text="Position")
322         colsub.prop(text, "underline_height", text="Thickness")
323
324         col = split.column()
325         col.label(text="Character:")
326         col.prop(char, "use_bold")
327         col.prop(char, "use_italic")
328         col.prop(char, "use_underline")
329
330         row = layout.row()
331         row.prop(text, "small_caps_scale", text="Small Caps")
332         row.prop(char, "use_small_caps")
333
334
335 class DATA_PT_paragraph(CurveButtonsPanel, Panel):
336     bl_label = "Paragraph"
337
338     @classmethod
339     def poll(cls, context):
340         return (context.object and context.object.type == 'FONT' and context.curve)
341
342     def draw(self, context):
343         layout = self.layout
344
345         text = context.curve
346
347         layout.label(text="Align:")
348         layout.prop(text, "align", expand=True)
349
350         split = layout.split()
351
352         col = split.column(align=True)
353         col.label(text="Spacing:")
354         col.prop(text, "space_character", text="Character")
355         col.prop(text, "space_word", text="Word")
356         col.prop(text, "space_line", text="Line")
357
358         col = split.column(align=True)
359         col.label(text="Offset:")
360         col.prop(text, "offset_x", text="X")
361         col.prop(text, "offset_y", text="Y")
362
363
364 class DATA_PT_text_boxes(CurveButtonsPanel, Panel):
365     bl_label = "Text Boxes"
366
367     @classmethod
368     def poll(cls, context):
369         return (context.object and context.object.type == 'FONT' and context.curve)
370
371     def draw(self, context):
372         layout = self.layout
373
374         text = context.curve
375
376         split = layout.split()
377         col = split.column()
378         col.operator("font.textbox_add", icon='ZOOMIN')
379         col = split.column()
380
381         for i, box in enumerate(text.text_boxes):
382
383             boxy = layout.box()
384
385             row = boxy.row()
386
387             split = row.split()
388
389             col = split.column(align=True)
390
391             col.label(text="Dimensions:")
392             col.prop(box, "width", text="Width")
393             col.prop(box, "height", text="Height")
394
395             col = split.column(align=True)
396
397             col.label(text="Offset:")
398             col.prop(box, "x", text="X")
399             col.prop(box, "y", text="Y")
400
401             row.operator("font.textbox_remove", text='', icon='X', emboss=False).index = i
402
403
404 class DATA_PT_custom_props_curve(CurveButtonsPanel, PropertyPanel, Panel):
405     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
406     _context_path = "object.data"
407     _property_type = bpy.types.Curve
408
409 if __name__ == "__main__":  # only for live edit.
410     bpy.utils.register_module(__name__)