e2987e0a05c47bac99c1b774fdff7c3aefd00047
[blender.git] / release / scripts / 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22
23 class DataButtonsPanel(bpy.types.Panel):
24     bl_space_type = 'PROPERTIES'
25     bl_region_type = 'WINDOW'
26     bl_context = "data"
27
28     def poll(self, context):
29         return (context.object and context.object.type in ('CURVE', 'SURFACE') and context.curve)
30
31
32 class DataButtonsPanelCurve(DataButtonsPanel):
33     '''Same as above but for curves only'''
34
35     def poll(self, context):
36         return (context.object and context.object.type == 'CURVE' and context.curve)
37
38
39 class DataButtonsPanelActive(DataButtonsPanel):
40     '''Same as above but for curves only'''
41
42     def poll(self, context):
43         curve = context.curve
44         return (curve and curve.active_spline)
45
46
47 class DATA_PT_context_curve(DataButtonsPanel):
48     bl_label = ""
49     bl_show_header = False
50
51     def draw(self, context):
52         layout = self.layout
53
54         ob = context.object
55         curve = context.curve
56         space = context.space_data
57
58         split = layout.split(percentage=0.65)
59
60         if ob:
61             split.template_ID(ob, "data")
62             split.itemS()
63         elif curve:
64             split.template_ID(space, "pin_id")
65             split.itemS()
66
67
68 class DATA_PT_shape_curve(DataButtonsPanel):
69     bl_label = "Shape"
70
71     def draw(self, context):
72         layout = self.layout
73
74         ob = context.object
75         curve = context.curve
76         space = context.space_data
77         is_surf = (ob.type == 'SURFACE')
78
79         if not is_surf:
80             row = layout.row()
81             row.itemR(curve, "dimensions", expand=True)
82
83         split = layout.split()
84
85         col = split.column()
86
87         if not is_surf:
88             sub = col.column()
89             sub.active = (curve.dimensions == '2D')
90             sub.itemL(text="Caps:")
91             row = sub.row()
92             row.itemR(curve, "front")
93             row.itemR(curve, "back")
94
95         col.itemL(text="Textures:")
96 #               col.itemR(curve, "uv_orco")
97         col.itemR(curve, "auto_texspace")
98
99         col = split.column()
100         col.itemL(text="Resolution:")
101         sub = col.column(align=True)
102         sub.itemR(curve, "resolution_u", text="Preview U")
103         sub.itemR(curve, "render_resolution_u", text="Render U")
104
105         if is_surf:
106             sub = col.column(align=True)
107             sub.itemR(curve, "resolution_v", text="Preview V")
108             sub.itemR(curve, "render_resolution_v", text="Render V")
109
110         # XXX - put somewhere nicer.
111         row = layout.row()
112         row.itemR(curve, "twist_mode")
113         row.itemR(curve, "twist_smooth") # XXX - may not be kept
114
115 #               col.itemL(text="Display:")
116 #               col.itemL(text="HANDLES")
117 #               col.itemL(text="NORMALS")
118 #               col.itemR(curve, "vertex_normal_flip")
119
120
121 class DATA_PT_geometry_curve(DataButtonsPanel):
122     bl_label = "Geometry"
123
124     def draw(self, context):
125         layout = self.layout
126
127         curve = context.curve
128
129         split = layout.split()
130
131         col = split.column()
132         col.itemL(text="Modification:")
133         col.itemR(curve, "width")
134         col.itemR(curve, "extrude")
135         col.itemL(text="Taper Object:")
136         col.itemR(curve, "taper_object", text="")
137
138         col = split.column()
139         col.itemL(text="Bevel:")
140         col.itemR(curve, "bevel_depth", text="Depth")
141         col.itemR(curve, "bevel_resolution", text="Resolution")
142         col.itemL(text="Bevel Object:")
143         col.itemR(curve, "bevel_object", text="")
144
145
146 class DATA_PT_pathanim(DataButtonsPanelCurve):
147     bl_label = "Path Animation"
148
149     def draw_header(self, context):
150         curve = context.curve
151
152         self.layout.itemR(curve, "use_path", text="")
153
154     def draw(self, context):
155         layout = self.layout
156
157         curve = context.curve
158
159         layout.active = curve.use_path
160
161         split = layout.split()
162
163         col = split.column()
164         col.itemR(curve, "path_length", text="Frames")
165         col.itemR(curve, "use_path_follow")
166
167         col = split.column()
168         col.itemR(curve, "use_stretch")
169         col.itemR(curve, "use_radius")
170         col.itemR(curve, "use_time_offset", text="Offset Children")
171
172
173 class DATA_PT_active_spline(DataButtonsPanelActive):
174     bl_label = "Active Spline"
175
176     def draw(self, context):
177         layout = self.layout
178
179         ob = context.object
180         curve = context.curve
181         act_spline = curve.active_spline
182         is_surf = (ob.type == 'SURFACE')
183         is_poly = (act_spline.type == 'POLY')
184
185         split = layout.split()
186
187         if is_poly:
188             # These settings are below but its easier to have
189             # poly's set aside since they use so few settings
190             col = split.column()
191             col.itemL(text="Cyclic:")
192             col.itemR(act_spline, "smooth")
193             col = split.column()
194             col.itemR(act_spline, "cyclic_u", text="U")
195
196         else:
197             col = split.column()
198             col.itemL(text="Cyclic:")
199             if act_spline.type == 'NURBS':
200                 col.itemL(text="Bezier:")
201                 col.itemL(text="Endpoint:")
202                 col.itemL(text="Order:")
203
204             col.itemL(text="Resolution:")
205
206             col = split.column()
207             col.itemR(act_spline, "cyclic_u", text="U")
208
209             if act_spline.type == 'NURBS':
210                 sub = col.column()
211                 # sub.active = (not act_spline.cyclic_u)
212                 sub.itemR(act_spline, "bezier_u", text="U")
213                 sub.itemR(act_spline, "endpoint_u", text="U")
214
215                 sub = col.column()
216                 sub.itemR(act_spline, "order_u", text="U")
217             col.itemR(act_spline, "resolution_u", text="U")
218
219             if is_surf:
220                 col = split.column()
221                 col.itemR(act_spline, "cyclic_v", text="V")
222
223                 # its a surface, assume its a nurb.
224                 sub = col.column()
225                 sub.active = (not act_spline.cyclic_v)
226                 sub.itemR(act_spline, "bezier_v", text="V")
227                 sub.itemR(act_spline, "endpoint_v", text="V")
228                 sub = col.column()
229                 sub.itemR(act_spline, "order_v", text="V")
230                 sub.itemR(act_spline, "resolution_v", text="V")
231
232
233             if not is_surf:
234                 split = layout.split()
235                 col = split.column()
236                 col.active = (curve.dimensions == '3D')
237
238                 col.itemL(text="Interpolation:")
239                 col.itemR(act_spline, "tilt_interpolation", text="Tilt")
240                 col.itemR(act_spline, "radius_interpolation", text="Radius")
241
242             split = layout.split()
243             col = split.column()
244             col.itemR(act_spline, "smooth")
245
246 bpy.types.register(DATA_PT_context_curve)
247 bpy.types.register(DATA_PT_shape_curve)
248 bpy.types.register(DATA_PT_geometry_curve)
249 bpy.types.register(DATA_PT_pathanim)
250 bpy.types.register(DATA_PT_active_spline)