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