603ac76120d9cc00aa280bdfdfa951c37d31c7b0
[blender.git] / release / scripts / ui / properties_object.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 rna_prop_ui import PropertyPanel
22
23 narrowui = bpy.context.user_preferences.view.properties_width_check
24
25
26 class ObjectButtonsPanel():
27     bl_space_type = 'PROPERTIES'
28     bl_region_type = 'WINDOW'
29     bl_context = "object"
30
31
32 class OBJECT_PT_context_object(ObjectButtonsPanel, bpy.types.Panel):
33     bl_label = ""
34     bl_show_header = False
35
36     def draw(self, context):
37         layout = self.layout
38         space = context.space_data
39         ob = context.object
40
41         row = layout.row()
42         row.label(text="", icon='OBJECT_DATA')
43         if space.use_pin_id:
44             row.template_ID(space, "pin_id")
45         else:
46             row.prop(ob, "name", text="")
47
48
49 class OBJECT_PT_transform(ObjectButtonsPanel, bpy.types.Panel):
50     bl_label = "Transform"
51
52     def draw(self, context):
53         layout = self.layout
54
55         ob = context.object
56         wide_ui = context.region.width > narrowui
57
58         if wide_ui:
59             row = layout.row()
60
61             row.column().prop(ob, "location")
62             if ob.rotation_mode == 'QUATERNION':
63                 row.column().prop(ob, "rotation_quaternion", text="Rotation")
64             elif ob.rotation_mode == 'AXIS_ANGLE':
65                 #row.column().label(text="Rotation")
66                 #row.column().prop(pchan, "rotation_angle", text="Angle")
67                 #row.column().prop(pchan, "rotation_axis", text="Axis")
68                 row.column().prop(ob, "rotation_axis_angle", text="Rotation")
69             else:
70                 row.column().prop(ob, "rotation_euler", text="Rotation")
71
72             row.column().prop(ob, "scale")
73
74             layout.prop(ob, "rotation_mode")
75         else:
76             col = layout.column()
77             col.prop(ob, "location")
78             col.label(text="Rotation:")
79             col.prop(ob, "rotation_mode", text="")
80             if ob.rotation_mode == 'QUATERNION':
81                 col.prop(ob, "rotation_quaternion", text="")
82             elif ob.rotation_mode == 'AXIS_ANGLE':
83                 col.prop(ob, "rotation_axis_angle", text="")
84             else:
85                 col.prop(ob, "rotation_euler", text="")
86             col.prop(ob, "scale")
87
88
89 class OBJECT_PT_transform_locks(ObjectButtonsPanel, bpy.types.Panel):
90     bl_label = "Transform Locks"
91     bl_default_closed = True
92
93     def draw(self, context):
94         layout = self.layout
95
96         ob = context.object
97         # wide_ui = context.region.width > narrowui
98
99         row = layout.row()
100
101         col = row.column()
102         col.prop(ob, "lock_location", text="Location")
103
104         col = row.column()
105         if ob.rotation_mode in ('QUATERNION', 'AXIS_ANGLE'):
106             col.prop(ob, "lock_rotations_4d", text="Rotation")
107             if ob.lock_rotations_4d:
108                 col.prop(ob, "lock_rotation_w", text="W")
109             col.prop(ob, "lock_rotation", text="")
110         else:
111             col.prop(ob, "lock_rotation", text="Rotation")
112
113         row.column().prop(ob, "lock_scale", text="Scale")
114
115
116 class OBJECT_PT_relations(ObjectButtonsPanel, bpy.types.Panel):
117     bl_label = "Relations"
118
119     def draw(self, context):
120         layout = self.layout
121
122         ob = context.object
123         wide_ui = context.region.width > narrowui
124
125         split = layout.split()
126
127         col = split.column()
128         col.prop(ob, "layers")
129         col.separator()
130         col.prop(ob, "pass_index")
131
132         if wide_ui:
133             col = split.column()
134         col.label(text="Parent:")
135         col.prop(ob, "parent", text="")
136
137         sub = col.column()
138         sub.prop(ob, "parent_type", text="")
139         parent = ob.parent
140         if parent and ob.parent_type == 'BONE' and parent.type == 'ARMATURE':
141             sub.prop_object(ob, "parent_bone", parent.data, "bones", text="")
142         sub.active = (parent is not None)
143
144
145 class OBJECT_PT_groups(ObjectButtonsPanel, bpy.types.Panel):
146     bl_label = "Groups"
147
148     def draw(self, context):
149         layout = self.layout
150
151         ob = context.object
152         wide_ui = context.region.width > narrowui
153
154         row = layout.row(align=True)
155         row.operator("object.group_link", text="Add to Group")
156         row.operator("object.group_add", text="", icon='ZOOMIN')
157
158         # XXX, this is bad practice, yes, I wrote it :( - campbell
159         index = 0
160         value = str(tuple(context.scene.cursor_location))
161         for group in bpy.data.groups:
162             if ob.name in group.objects:
163                 col = layout.column(align=True)
164
165                 col.set_context_pointer("group", group)
166
167                 row = col.box().row()
168                 row.prop(group, "name", text="")
169                 row.operator("object.group_remove", text="", icon='X', emboss=False)
170
171                 split = col.box().split()
172
173                 col = split.column()
174                 col.prop(group, "layer", text="Dupli")
175
176                 if wide_ui:
177                     col = split.column()
178                 col.prop(group, "dupli_offset", text="")
179
180                 prop = col.operator("wm.context_set_value", text="From Cursor")
181                 prop.data_path = "object.users_group[%d].dupli_offset" % index
182                 prop.value = value
183                 index += 1
184
185
186 class OBJECT_PT_display(ObjectButtonsPanel, bpy.types.Panel):
187     bl_label = "Display"
188
189     def draw(self, context):
190         layout = self.layout
191
192         ob = context.object
193         wide_ui = context.region.width > narrowui
194
195         split = layout.split()
196         col = split.column()
197         col.prop(ob, "max_draw_type", text="Type")
198
199         if wide_ui:
200             col = split.column()
201         row = col.row()
202         row.prop(ob, "draw_bounds", text="Bounds")
203         sub = row.row()
204         sub.active = ob.draw_bounds
205         sub.prop(ob, "draw_bounds_type", text="")
206
207         split = layout.split()
208
209         col = split.column()
210         col.prop(ob, "draw_name", text="Name")
211         col.prop(ob, "draw_axis", text="Axis")
212         col.prop(ob, "draw_wire", text="Wire")
213         col.prop(ob, "color", text="Object Color")
214
215         if wide_ui:
216             col = split.column()
217         col.prop(ob, "draw_texture_space", text="Texture Space")
218         col.prop(ob, "x_ray", text="X-Ray")
219         col.prop(ob, "draw_transparent", text="Transparency")
220
221
222 class OBJECT_PT_duplication(ObjectButtonsPanel, bpy.types.Panel):
223     bl_label = "Duplication"
224
225     def draw(self, context):
226         layout = self.layout
227
228         ob = context.object
229         wide_ui = context.region.width > narrowui
230
231         if wide_ui:
232             layout.prop(ob, "dupli_type", expand=True)
233         else:
234             layout.prop(ob, "dupli_type", text="")
235
236         if ob.dupli_type == 'FRAMES':
237             split = layout.split()
238
239             col = split.column(align=True)
240             col.prop(ob, "dupli_frames_start", text="Start")
241             col.prop(ob, "dupli_frames_end", text="End")
242
243             if wide_ui:
244                 col = split.column(align=True)
245             col.prop(ob, "dupli_frames_on", text="On")
246             col.prop(ob, "dupli_frames_off", text="Off")
247
248             layout.prop(ob, "use_dupli_frames_speed", text="Speed")
249
250         elif ob.dupli_type == 'VERTS':
251             layout.prop(ob, "use_dupli_verts_rotation", text="Rotation")
252
253         elif ob.dupli_type == 'FACES':
254             split = layout.split()
255
256             col = split.column()
257             col.prop(ob, "use_dupli_faces_scale", text="Scale")
258
259             if wide_ui:
260                 col = split.column()
261             col.prop(ob, "dupli_faces_scale", text="Inherit Scale")
262
263         elif ob.dupli_type == 'GROUP':
264             if wide_ui:
265                 layout.prop(ob, "dupli_group", text="Group")
266             else:
267                 layout.prop(ob, "dupli_group", text="")
268
269 # XXX: the following options are all quite buggy, ancient hacks that should be dropped
270
271 class OBJECT_PT_animation(ObjectButtonsPanel, bpy.types.Panel):
272     bl_label = "Animation Hacks"
273     bl_default_closed = True
274
275     def draw(self, context):
276         layout = self.layout
277
278         ob = context.object
279         wide_ui = context.region.width > narrowui
280
281         split = layout.split()
282
283         col = split.column()
284         col.label(text="Time Offset:")
285         col.prop(ob, "time_offset_edit", text="Edit")
286         row = col.row()
287         row.prop(ob, "time_offset_particle", text="Particle")
288         row.active = len(ob.particle_systems) != 0
289         row = col.row()
290         row.prop(ob, "time_offset_parent", text="Parent")
291         row.active = (ob.parent is not None)
292         row = col.row()
293         row.prop(ob, "slow_parent")
294         row.active = (ob.parent is not None)
295         col.prop(ob, "time_offset", text="Offset")
296
297         # XXX: these are still used for a few curve-related tracking features
298         if wide_ui:
299             col = split.column()
300         col.label(text="Tracking Axes:")
301         col.prop(ob, "track_axis", text="Axis")
302         col.prop(ob, "up_axis", text="Up Axis")
303
304 from properties_animviz import MotionPathButtonsPanel, OnionSkinButtonsPanel
305
306
307 class OBJECT_PT_motion_paths(MotionPathButtonsPanel, bpy.types.Panel):
308     #bl_label = "Object Motion Paths"
309     bl_context = "object"
310
311     @staticmethod
312     def poll(context):
313         return (context.object)
314
315     def draw(self, context):
316         layout = self.layout
317
318         ob = context.object
319         wide_ui = context.region.width > narrowui
320
321         self.draw_settings(context, ob.animation_visualisation, wide_ui)
322
323         layout.separator()
324
325         split = layout.split()
326
327         col = split.column()
328         col.operator("object.paths_calculate", text="Calculate Paths")
329
330         if wide_ui:
331             col = split.column()
332         col.operator("object.paths_clear", text="Clear Paths")
333
334
335 class OBJECT_PT_onion_skinning(OnionSkinButtonsPanel): #, bpy.types.Panel): # inherit from panel when ready
336     #bl_label = "Object Onion Skinning"
337     bl_context = "object"
338
339     @staticmethod
340     def poll(context):
341         return (context.object)
342
343     def draw(self, context):
344         layout = self.layout
345
346         ob = context.object
347         wide_ui = context.region.width > narrowui
348
349         self.draw_settings(context, ob.animation_visualisation, wide_ui)
350
351 class OBJECT_PT_custom_props(ObjectButtonsPanel, PropertyPanel, bpy.types.Panel):
352     _context_path = "object"
353
354 def register():
355     pass
356
357
358 def unregister():
359     pass
360
361 if __name__ == "__main__":
362     register()