rna UI api rename...
[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., 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 ObjectButtonsPanel(bpy.types.Panel):
26     bl_space_type = 'PROPERTIES'
27     bl_region_type = 'WINDOW'
28     bl_context = "object"
29
30
31 class OBJECT_PT_context_object(ObjectButtonsPanel):
32     bl_label = ""
33     bl_show_header = False
34
35     def draw(self, context):
36         layout = self.layout
37
38         ob = context.object
39
40         row = layout.row()
41         row.label(text="", icon='ICON_OBJECT_DATA')
42         row.prop(ob, "name", text="")
43
44
45 class OBJECT_PT_transform(ObjectButtonsPanel):
46     bl_label = "Transform"
47
48     def draw(self, context):
49         layout = self.layout
50
51         ob = context.object
52         wide_ui = context.region.width > narrowui
53
54         if wide_ui:
55             row = layout.row()
56
57             row.column().prop(ob, "location")
58             if ob.rotation_mode == 'QUATERNION':
59                 row.column().prop(ob, "rotation_quaternion", text="Rotation")
60             elif ob.rotation_mode == 'AXIS_ANGLE':
61                 #row.column().label(text="Rotation")
62                 #row.column().prop(pchan, "rotation_angle", text="Angle")
63                 #row.column().prop(pchan, "rotation_axis", text="Axis")
64                 row.column().prop(ob, "rotation_axis_angle", text="Rotation")
65             else:
66                 row.column().prop(ob, "rotation_euler", text="Rotation")
67
68             row.column().prop(ob, "scale")
69
70             layout.prop(ob, "rotation_mode")
71         else:
72             col = layout.column()
73             col.prop(ob, "location")
74             col.label(text="Rotation:")
75             col.prop(ob, "rotation_mode", text="")
76             if ob.rotation_mode == 'QUATERNION':
77                 col.prop(ob, "rotation_quaternion", text="")
78             elif ob.rotation_mode == 'AXIS_ANGLE':
79                 col.prop(ob, "rotation_axis_angle", text="")
80             else:
81                 col.prop(ob, "rotation_euler", text="")
82             col.prop(ob, "scale")
83
84
85 class OBJECT_PT_transform_locks(ObjectButtonsPanel):
86     bl_label = "Transform Locks"
87     bl_default_closed = True
88
89     def draw(self, context):
90         layout = self.layout
91
92         ob = context.object
93         # wide_ui = context.region.width > narrowui
94
95         row = layout.row()
96
97         col = row.column()
98         col.prop(ob, "lock_location", text="Location")
99
100         col = row.column()
101         if ob.rotation_mode in ('QUATERNION', 'AXIS_ANGLE'):
102             col.prop(ob, "lock_rotations_4d", text="Rotation")
103             if ob.lock_rotations_4d:
104                 col.prop(ob, "lock_rotation_w", text="W")
105             col.prop(ob, "lock_rotation", text="")
106         else:
107             col.prop(ob, "lock_rotation", text="Rotation")
108
109         row.column().prop(ob, "lock_scale", text="Scale")
110
111
112 class OBJECT_PT_relations(ObjectButtonsPanel):
113     bl_label = "Relations"
114
115     def draw(self, context):
116         layout = self.layout
117
118         ob = context.object
119         wide_ui = context.region.width > narrowui
120
121         split = layout.split()
122
123         col = split.column()
124         col.prop(ob, "layers")
125         col.separator()
126         col.prop(ob, "pass_index")
127
128         if wide_ui:
129             col = split.column()
130         col.label(text="Parent:")
131         col.prop(ob, "parent", text="")
132
133         sub = col.column()
134         sub.prop(ob, "parent_type", text="")
135         parent = ob.parent
136         if parent and ob.parent_type == 'BONE' and parent.type == 'ARMATURE':
137             sub.prop_pointer(ob, "parent_bone", parent.data, "bones", text="")
138         sub.active = (parent is not None)
139
140
141 class OBJECT_PT_groups(ObjectButtonsPanel):
142     bl_label = "Groups"
143
144     def draw(self, context):
145         layout = self.layout
146
147         ob = context.object
148         wide_ui = context.region.width > narrowui
149
150         if wide_ui:
151             split = layout.split()
152             split.operator_menu_enum("object.group_add", "group", text="Add to Group")
153             split.label()
154         else:
155             layout.operator_menu_enum("object.group_add", "group", text="Add to Group")
156
157         for group in bpy.data.groups:
158             if ob.name in group.objects:
159                 col = layout.column(align=True)
160
161                 col.set_context_pointer("group", group)
162
163                 row = col.box().row()
164                 row.prop(group, "name", text="")
165                 row.operator("object.group_remove", text="", icon='VICON_X')
166
167                 split = col.box().split()
168
169                 col = split.column()
170                 col.prop(group, "layer", text="Dupli")
171
172                 if wide_ui:
173                     col = split.column()
174                 col.prop(group, "dupli_offset", text="")
175
176
177 class OBJECT_PT_display(ObjectButtonsPanel):
178     bl_label = "Display"
179
180     def draw(self, context):
181         layout = self.layout
182
183         ob = context.object
184         wide_ui = context.region.width > narrowui
185
186         split = layout.split()
187         col = split.column()
188         col.prop(ob, "max_draw_type", text="Type")
189
190         if wide_ui:
191             col = split.column()
192         row = col.row()
193         row.prop(ob, "draw_bounds", text="Bounds")
194         sub = row.row()
195         sub.active = ob.draw_bounds
196         sub.prop(ob, "draw_bounds_type", text="")
197
198         split = layout.split()
199
200         col = split.column()
201         col.prop(ob, "draw_name", text="Name")
202         col.prop(ob, "draw_axis", text="Axis")
203         col.prop(ob, "draw_wire", text="Wire")
204
205         if wide_ui:
206             col = split.column()
207         col.prop(ob, "draw_texture_space", text="Texture Space")
208         col.prop(ob, "x_ray", text="X-Ray")
209         col.prop(ob, "draw_transparent", text="Transparency")
210
211
212 class OBJECT_PT_duplication(ObjectButtonsPanel):
213     bl_label = "Duplication"
214
215     def draw(self, context):
216         layout = self.layout
217
218         ob = context.object
219         wide_ui = context.region.width > narrowui
220
221         if wide_ui:
222             layout.prop(ob, "dupli_type", expand=True)
223         else:
224             layout.prop(ob, "dupli_type", text="")
225
226         if ob.dupli_type == 'FRAMES':
227             split = layout.split()
228
229             col = split.column(align=True)
230             col.prop(ob, "dupli_frames_start", text="Start")
231             col.prop(ob, "dupli_frames_end", text="End")
232
233             if wide_ui:
234                 col = split.column(align=True)
235             col.prop(ob, "dupli_frames_on", text="On")
236             col.prop(ob, "dupli_frames_off", text="Off")
237
238             layout.prop(ob, "dupli_frames_no_speed", text="No Speed")
239
240         elif ob.dupli_type == 'VERTS':
241             layout.prop(ob, "dupli_verts_rotation", text="Rotation")
242
243         elif ob.dupli_type == 'FACES':
244             split = layout.split()
245
246             col = split.column()
247             col.prop(ob, "dupli_faces_scale", text="Scale")
248
249             if wide_ui:
250                 col = split.column()
251             col.prop(ob, "dupli_faces_inherit_scale", text="Inherit Scale")
252
253         elif ob.dupli_type == 'GROUP':
254             if wide_ui:
255                 layout.prop(ob, "dupli_group", text="Group")
256             else:
257                 layout.prop(ob, "dupli_group", text="")
258
259
260 class OBJECT_PT_animation(ObjectButtonsPanel):
261     bl_label = "Animation"
262
263     def draw(self, context):
264         layout = self.layout
265
266         ob = context.object
267         wide_ui = context.region.width > narrowui
268
269         split = layout.split()
270
271         col = split.column()
272         col.label(text="Time Offset:")
273         col.prop(ob, "time_offset_edit", text="Edit")
274         row = col.row()
275         row.prop(ob, "time_offset_particle", text="Particle")
276         row.active = len(ob.particle_systems) != 0
277         row = col.row()
278         row.prop(ob, "time_offset_parent", text="Parent")
279         row.active = (ob.parent is not None)
280         row = col.row()
281         row.prop(ob, "slow_parent")
282         row.active = (ob.parent is not None)
283         col.prop(ob, "time_offset", text="Offset")
284
285         if wide_ui:
286             col = split.column()
287         col.label(text="Track:")
288         col.prop(ob, "track", text="")
289         col.prop(ob, "track_axis", text="Axis")
290         col.prop(ob, "up_axis", text="Up Axis")
291         row = col.row()
292         row.prop(ob, "track_override_parent", text="Override Parent")
293         row.active = (ob.parent is not None)
294
295
296 class OBJECT_PT_properties(ObjectButtonsPanel):
297     bl_label = "Properties"
298     bl_default_closed = True
299
300     def draw(self, context):
301         import rna_prop_ui
302         # reload(rna_prop_ui)
303
304         rna_prop_ui.draw(self.layout, context, "object")
305
306 bpy.types.register(OBJECT_PT_context_object)
307 bpy.types.register(OBJECT_PT_transform)
308 bpy.types.register(OBJECT_PT_transform_locks)
309 bpy.types.register(OBJECT_PT_relations)
310 bpy.types.register(OBJECT_PT_groups)
311 bpy.types.register(OBJECT_PT_display)
312 bpy.types.register(OBJECT_PT_duplication)
313 bpy.types.register(OBJECT_PT_animation)
314 bpy.types.register(OBJECT_PT_properties)