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