2.5 Buttons
[blender-staging.git] / release / ui / buttons_object_constraint.py
1
2 import bpy
3
4 class ConstraintButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "object"
8
9         def draw_constraint(self, con):
10                 layout = self.layout
11                 box = layout.template_constraint(con)
12
13                 if box:
14                         if con.type == "COPY_LOCATION":
15                                 self.copy_location(box, con)
16
17                         # show/key buttons here are most likely obsolete now, with
18                         # keyframing functionality being part of every button
19                         if con.type not in ("RIGID_BODY_JOINT", "NULL"):
20                                 box.itemR(con, "influence")
21         
22         def space_template(self, layout, con, target=True, owner=True):
23                 if target or owner:
24                         row = layout.row()
25
26                         row.itemL(text="Convert:")
27
28                         if target:
29                                 row.itemR(con, "target_space", text="")
30
31                         if target and owner:
32                                 row.itemL(icon=8) # XXX
33
34                         if owner:
35                                 row.itemR(con, "owner_space", text="")
36                         
37         def target_template(self, layout, con, subtargets=True):
38                 layout.itemR(con, "target") # XXX limiting settings for only 'curves' or some type of object
39                 
40                 if con.target and subtargets:
41                         if con.target.type == "ARMATURE":
42                                 layout.itemR(con, "subtarget", text="Bone") # XXX autocomplete
43                                 
44                                 row = layout.row()
45                                 row.itemL(text="Head/Tail:")
46                                 row.itemR(con, "head_tail", text="")
47                         elif con.target.type in ("MESH", "LATTICE"):
48                                 layout.itemR(con, "subtarget", text="Vertex Group") # XXX autocomplete
49         
50         def copy_location(self, layout, con):
51                 self.target_template(layout, con)
52                 
53                 row = layout.row(align=True)
54                 row.itemR(con, "locate_like_x", text="X", toggle=True)
55                 row.itemR(con, "invert_x", text="-", toggle=True)
56                 row.itemR(con, "locate_like_y", text="Y", toggle=True)
57                 row.itemR(con, "invert_y", text="-", toggle=True)
58                 row.itemR(con, "locate_like_z", text="Z", toggle=True)
59                 row.itemR(con, "invert_z", text="-", toggle=True)
60
61                 layout.itemR(con, "offset")
62
63                 self.space_template(layout, con)
64
65 class OBJECT_PT_constraints(ConstraintButtonsPanel):
66         __idname__ = "OBJECT_PT_constraints"
67         __label__ = "Constraints"
68         __context__ = "object"
69
70         def poll(self, context):
71                 ob = context.active_object
72                 return (ob != None)
73                 
74         def draw(self, context):
75                 ob = context.active_object
76                 layout = self.layout
77
78                 row = layout.row()
79                 row.item_menu_enumO("OBJECT_OT_constraint_add", "type")
80                 row.itemL();
81
82                 for con in ob.constraints:
83                         self.draw_constraint(con)
84
85 class BONE_PT_constraints(ConstraintButtonsPanel):
86         __idname__ = "BONE_PT_constraints"
87         __label__ = "Constraints"
88         __context__ = "bone"
89
90         def poll(self, context):
91                 ob = context.active_object
92                 return (ob and ob.type == "ARMATURE")
93                 
94         def draw(self, context):
95                 ob = context.active_object
96                 pchan = ob.pose.pose_channels[0]
97                 layout = self.layout
98
99                 #row = layout.row()
100                 #row.item_menu_enumO("BONE_OT_constraint_add", "type")
101                 #row.itemL();
102
103                 for con in pchan.constraints:
104                         self.draw_constraint(con)
105
106 bpy.types.register(OBJECT_PT_constraints)
107 bpy.types.register(BONE_PT_constraints)
108