svn merge -r 20822:21041 https://svn.blender.org/svnroot/bf-blender/branches/blender2...
[blender.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__ = "constraint"
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 == "CHILD_OF":
15                                 self.child_of(box, con)
16                         elif con.type == "TRACK_TO":
17                                 self.track_to(box, con)
18                         elif con.type == "IK":
19                                 self.ik(box, con)
20                         elif con.type == "FOLLOW_PATH":
21                                 self.follow_path(box, con)
22                         elif con.type == "LIMIT_ROTATION":
23                                 self.limit_rotation(box, con)
24                         elif con.type == "LIMIT_LOCATION":
25                                 self.limit_location(box, con)
26                         elif con.type == "LIMIT_SCALE":
27                                 self.limit_scale(box, con)
28                         elif con.type == "COPY_ROTATION":
29                                 self.copy_rotation(box, con)
30                         elif con.type == "COPY_LOCATION":
31                                 self.copy_location(box, con)
32                         elif con.type == "COPY_SCALE":
33                                 self.copy_scale(box, con)
34                         #elif con.type == "SCRIPT":
35                         #       self.script(box, con)
36                         elif con.type == "ACTION":
37                                 self.action(box, con)
38                         elif con.type == "LOCKED_TRACK":
39                                 self.locked_track(box, con)
40                         elif con.type == "LIMIT_DISTANCE":
41                                 self.limit_distance(box, con)
42                         elif con.type == "STRETCH_TO":
43                                 self.stretch_to(box, con)
44                         elif con.type == "FLOOR":
45                                 self.floor(box, con)
46                         elif con.type == "RIGID_BODY_JOINT":
47                                 self.rigid_body(box, con)
48                         elif con.type == "CLAMP_TO":
49                                 self.clamp_to(box, con)
50                         elif con.type == "TRANSFORM":
51                                 self.transform(box, con)
52                         elif con.type == "SHRINKWRAP":
53                                 self.shrinkwrap(box, con)
54                                 
55                         # show/key buttons here are most likely obsolete now, with
56                         # keyframing functionality being part of every button
57                         if con.type not in ("RIGID_BODY_JOINT", "NULL"):
58                                 box.itemR(con, "influence")
59         
60         def space_template(self, layout, con, target=True, owner=True):
61                 if target or owner:
62                         row = layout.row()
63
64                         row.itemL(text="Convert:")
65
66                         if target:
67                                 row.itemR(con, "target_space", text="")
68
69                         if target and owner:
70                                 row.itemL(icon=8) # XXX
71
72                         if owner:
73                                 row.itemR(con, "owner_space", text="")
74                         
75         def target_template(self, layout, con, subtargets=True):
76                 layout.itemR(con, "target") # XXX limiting settings for only 'curves' or some type of object
77                 
78                 if con.target and subtargets:
79                         if con.target.type == "ARMATURE":
80                                 layout.itemR(con, "subtarget", text="Bone") # XXX autocomplete
81                                 
82                                 row = layout.row()
83                                 row.itemL(text="Head/Tail:")
84                                 row.itemR(con, "head_tail", text="")
85                         elif con.target.type in ("MESH", "LATTICE"):
86                                 layout.itemR(con, "subtarget", text="Vertex Group") # XXX autocomplete
87         
88         def child_of(self, layout, con):
89                 self.target_template(layout, con)
90
91                 split = layout.split()
92                 
93                 sub = split.column()
94                 sub.itemL(text="Location:")
95                 sub.itemR(con, "locationx", text="X")
96                 sub.itemR(con, "locationy", text="Y")
97                 sub.itemR(con, "locationz", text="Z")
98                 
99                 sub = split.column()
100                 sub.itemL(text="Rotation:")
101                 sub.itemR(con, "rotationx", text="X")
102                 sub.itemR(con, "rotationy", text="Y")
103                 sub.itemR(con, "rotationz", text="Z")
104                 
105                 sub = split.column()
106                 sub.itemL(text="Scale:")
107                 sub.itemR(con, "sizex", text="X")
108                 sub.itemR(con, "sizey", text="Y")
109                 sub.itemR(con, "sizez", text="Z")
110                 
111                 # Missing
112                 row = layout.row()
113                 row.itemL(text="SET OFFSET")
114                 row.itemL(text="CLEAR OFFSET")
115                 
116         def track_to(self, layout, con):
117                 self.target_template(layout, con)
118                 
119                 row = layout.row()
120                 row.itemL(text="To:")
121                 row.itemR(con, "track", expand=True)
122                 
123                 row = layout.row()
124                 row.itemR(con, "up", text="Up")
125                 row.itemR(con, "target_z")
126                 
127                 self.space_template(layout, con)
128                 
129         def ik(self, layout, con):
130                 self.target_template(layout, con)
131                 
132                 layout.itemR(con, "pole_target")
133                 layout.itemR(con, "pole_subtarget")
134                 
135                 col = layout.column_flow()
136                 col.itemR(con, "iterations")
137                 col.itemR(con, "pole_angle")
138                 col.itemR(con, "weight")
139                 col.itemR(con, "orient_weight")
140                 col.itemR(con, "chain_length")
141                 
142                 col = layout.column_flow()
143                 col.itemR(con, "tail")
144                 col.itemR(con, "rotation")
145                 col.itemR(con, "targetless")
146                 col.itemR(con, "stretch")
147                 
148         def follow_path(self, layout, con):
149                 self.target_template(layout, con)
150                 
151                 row = layout.row()
152                 row.itemR(con, "curve_follow")
153                 row.itemR(con, "offset")
154                 
155                 row = layout.row()
156                 row.itemL(text="Forward:")
157                 row.itemR(con, "forward", expand=True)
158                 
159                 row = layout.row()
160                 row.itemR(con, "up", text="Up")
161                 row.itemL()
162                 
163         def limit_rotation(self, layout, con):
164                 
165                 split = layout.split()
166                 
167                 col = split.column()
168                 col.itemR(con, "use_limit_x")
169                 colsub = col.column()
170                 colsub.active = con.use_limit_x
171                 colsub.itemR(con, "minimum_x", text="Min")
172                 colsub.itemR(con, "maximum_x", text="Max")
173                 
174                 col = split.column()
175                 col.itemR(con, "use_limit_y")
176                 colsub = col.column()
177                 colsub.active = con.use_limit_y
178                 colsub.itemR(con, "minimum_y", text="Min")
179                 colsub.itemR(con, "maximum_y", text="Max")
180                 
181                 col = split.column()
182                 col.itemR(con, "use_limit_z")
183                 colsub = col.column()
184                 colsub.active = con.use_limit_z
185                 colsub.itemR(con, "minimum_z", text="Min")
186                 colsub.itemR(con, "maximum_z", text="Max")
187                 
188                 row = layout.row()
189                 row.itemR(con, "limit_transform")
190                 row.itemL()
191                 
192                 row = layout.row()
193                 row.itemL(text="Convert:")
194                 row.itemR(con, "owner_space", text="")
195                 
196         def limit_location(self, layout, con):
197                 split = layout.split()
198                 
199                 col = split.column()
200                 col.itemR(con, "use_minimum_x")
201                 colsub = col.column()
202                 colsub.active = con.use_minimum_x
203                 colsub.itemR(con, "minimum_x", text="")
204                 col.itemR(con, "use_maximum_x")
205                 colsub = col.column()
206                 colsub.active = con.use_maximum_x
207                 colsub.itemR(con, "maximum_x", text="")
208                 
209                 col = split.column()
210                 col.itemR(con, "use_minimum_y")
211                 colsub = col.column()
212                 colsub.active = con.use_minimum_y
213                 colsub.itemR(con, "minimum_y", text="")
214                 col.itemR(con, "use_maximum_y")
215                 colsub = col.column()
216                 colsub.active = con.use_maximum_y
217                 colsub.itemR(con, "maximum_y", text="")
218                 
219                 col = split.column()
220                 col.itemR(con, "use_minimum_z")
221                 colsub = col.column()
222                 colsub.active = con.use_minimum_z
223                 colsub.itemR(con, "minimum_z", text="")
224                 col.itemR(con, "use_maximum_z")
225                 colsub = col.column()
226                 colsub.active = con.use_maximum_z
227                 colsub.itemR(con, "maximum_z", text="")
228         
229                 row = layout.row()
230                 row.itemR(con, "limit_transform")
231                 row.itemL()
232                 
233                 row = layout.row()
234                 row.itemL(text="Convert:")
235                 row.itemR(con, "owner_space", text="")
236                 
237         def limit_scale(self, layout, con):
238                 split = layout.split()
239
240                 col = split.column()
241                 col.itemR(con, "use_minimum_x")
242                 colsub = col.column()
243                 colsub.active = con.use_minimum_x
244                 colsub.itemR(con, "minimum_x", text="")
245                 col.itemR(con, "use_maximum_x")
246                 colsub = col.column()
247                 colsub.active = con.use_maximum_x
248                 colsub.itemR(con, "maximum_x", text="")
249                 
250                 col = split.column()
251                 col.itemR(con, "use_minimum_y")
252                 colsub = col.column()
253                 colsub.active = con.use_minimum_y
254                 colsub.itemR(con, "minimum_y", text="")
255                 col.itemR(con, "use_maximum_y")
256                 colsub = col.column()
257                 colsub.active = con.use_maximum_y
258                 colsub.itemR(con, "maximum_y", text="")
259                 
260                 col = split.column()
261                 col.itemR(con, "use_minimum_z")
262                 colsub = col.column()
263                 colsub.active = con.use_minimum_z
264                 colsub.itemR(con, "minimum_z", text="")
265                 col.itemR(con, "use_maximum_z")
266                 colsub = col.column()
267                 colsub.active = con.use_maximum_z
268                 colsub.itemR(con, "maximum_z", text="")
269                 
270                 row = layout.row()
271                 row.itemR(con, "limit_transform")
272                 row.itemL()
273                 
274                 row = layout.row()
275                 row.itemL(text="Convert:")
276                 row.itemR(con, "owner_space", text="")
277         
278         def copy_rotation(self, layout, con):
279                 self.target_template(layout, con)
280                 
281                 split = layout.split()
282                 
283                 col = split.column()
284                 col.itemR(con, "rotate_like_x", text="X")
285                 colsub = col.column()
286                 colsub.active = con.rotate_like_x
287                 colsub.itemR(con, "invert_x", text="Invert")
288                 
289                 col = split.column()
290                 col.itemR(con, "rotate_like_y", text="Y")
291                 colsub = col.column()
292                 colsub.active = con.rotate_like_y
293                 colsub.itemR(con, "invert_y", text="Invert")
294                 
295                 col = split.column()
296                 col.itemR(con, "rotate_like_z", text="Z")
297                 colsub = col.column()
298                 colsub.active = con.rotate_like_z
299                 colsub.itemR(con, "invert_z", text="Invert")
300
301                 layout.itemR(con, "offset")
302                 
303                 self.space_template(layout, con)
304                 
305         def copy_location(self, layout, con):
306                 self.target_template(layout, con)
307                 
308                 split = layout.split()
309                 
310                 col = split.column()
311                 col.itemR(con, "locate_like_x", text="X")
312                 colsub = col.column()
313                 colsub.active = con.locate_like_x
314                 colsub.itemR(con, "invert_x", text="Invert")
315                 
316                 col = split.column()
317                 col.itemR(con, "locate_like_y", text="Y")
318                 colsub = col.column()
319                 colsub.active = con.locate_like_y
320                 colsub.itemR(con, "invert_y", text="Invert")
321                 
322                 col = split.column()
323                 col.itemR(con, "locate_like_z", text="Z")
324                 colsub = col.column()
325                 colsub.active = con.locate_like_z
326                 colsub.itemR(con, "invert_z", text="Invert")
327
328                 layout.itemR(con, "offset")
329                         
330                 self.space_template(layout, con)
331                 
332         def copy_scale(self, layout, con):
333                 self.target_template(layout, con)
334                 
335                 row = layout.row(align=True)
336                 row.itemR(con, "size_like_x", text="X")
337                 row.itemR(con, "size_like_y", text="Y")
338                 row.itemR(con, "size_like_z", text="Z")
339
340                 layout.itemR(con, "offset")
341                 
342                 self.space_template(layout, con)
343                 
344         #def script(self, layout, con):
345         
346         def action(self, layout, con):
347                 self.target_template(layout, con)
348                 
349                 layout.itemR(con, "action")
350                 layout.itemR(con, "transform_channel")
351
352                 split = layout.split()
353         
354                 col = split.column(align=True)
355                 col.itemR(con, "start_frame", text="Start")
356                 col.itemR(con, "end_frame", text="End")
357                 
358                 col = split.column(align=True)
359                 col.itemR(con, "minimum", text="Min")
360                 col.itemR(con, "maximum", text="Max")
361                 
362                 row = layout.row()
363                 row.itemL(text="Convert:")
364                 row.itemR(con, "owner_space", text="")
365         
366         def locked_track(self, layout, con):
367                 self.target_template(layout, con)
368                 
369                 row = layout.row()
370                 row.itemL(text="To:")
371                 row.itemR(con, "track", expand=True)
372                 
373                 row = layout.row()
374                 row.itemL(text="Lock:")
375                 row.itemR(con, "locked", expand=True)
376                 
377         def limit_distance(self, layout, con):
378                 self.target_template(layout, con)
379                 
380                 layout.itemR(con, "distance")
381                 
382                 row = layout.row()
383                 row.itemL(text="Clamp Region:")
384                 row.itemR(con, "limit_mode", text="")
385                 #Missing: Recalculate Button
386                 
387         def stretch_to(self, layout, con):
388                 self.target_template(layout, con)
389                 
390                 row = layout.row()
391                 row.itemR(con, "original_length", text="Rest Length")
392                 row.itemR(con, "bulge", text="Volume Variation")
393                 
394                 row = layout.row()
395                 row.itemL(text="Volume:")
396                 row.itemR(con, "volume", expand=True)
397                 row.itemL(text="Plane:")
398                 row.itemR(con, "keep_axis", expand=True)
399                 #Missing: Recalculate Button
400                 
401         def floor(self, layout, con):
402                 self.target_template(layout, con)
403                 
404                 row = layout.row()
405                 row.itemR(con, "sticky")
406                 row.itemR(con, "use_rotation")
407                 
408                 layout.itemR(con, "offset")
409                 
410                 row = layout.row()
411                 row.itemL(text="Min/Max:")
412                 row.itemR(con, "floor_location", expand=True)
413                 
414         def rigid_body(self, layout, con):
415                 self.target_template(layout, con)
416                 
417                 layout.itemR(con, "pivot_type")
418                 layout.itemR(con, "child")
419                 
420                 row = layout.row()
421                 row.itemR(con, "disable_linked_collision", text="No Collision")
422                 row.itemR(con, "draw_pivot")
423                 
424                 split = layout.split()
425                 
426                 col = split.column()
427                 col.itemR(con, "pivot_x")
428                 col.itemR(con, "pivot_y")
429                 col.itemR(con, "pivot_z")
430                 
431                 col = split.column()
432                 col.itemR(con, "axis_x")
433                 col.itemR(con, "axis_y")
434                 col.itemR(con, "axis_z")
435                 
436                 #Missing: Limit arrays (not wrapped in RNA yet) 
437         
438         def clamp_to(self, layout, con):
439                 self.target_template(layout, con)
440                 
441                 row = layout.row()
442                 row.itemL(text="Main Axis:")
443                 row.itemR(con, "main_axis", expand=True)
444                 
445                 row = layout.row()
446                 row.itemR(con, "cyclic")
447                 
448         def transform(self, layout, con):
449                 self.target_template(layout, con)
450                 
451                 layout.itemR(con, "extrapolate_motion", text="Extrapolate")
452                 
453                 split = layout.split()
454                 
455                 col = split.column()
456                 col.itemL(text="Source:")
457                 col.row().itemR(con, "map_from", expand=True)
458                 
459                 sub = col.row(align=True)
460                 sub.itemL(text="X:")
461                 sub.itemR(con, "from_min_x", text="")
462                 sub.itemR(con, "from_max_x", text="")
463                 
464                 sub = col.row(align=True)
465                 sub.itemL(text="Y:")
466                 sub.itemR(con, "from_min_y", text="")
467                 sub.itemR(con, "from_max_y", text="")
468                 
469                 sub = col.row(align=True)
470                 sub.itemL(text="Z:")
471                 sub.itemR(con, "from_min_z", text="")
472                 sub.itemR(con, "from_max_z", text="")
473                 
474                 split = layout.split()
475                 
476                 col = split.column()
477                 col.itemL(text="Destination:")
478                 col.row().itemR(con, "map_to", expand=True)
479
480                 sub = col.row(align=True)
481                 sub.itemR(con, "map_to_x_from", text="")
482                 sub.itemR(con, "to_min_x", text="")
483                 sub.itemR(con, "to_max_x", text="")
484                 
485                 sub = col.row(align=True)
486                 sub.itemR(con, "map_to_y_from", text="")
487                 sub.itemR(con, "to_min_y", text="")
488                 sub.itemR(con, "to_max_y", text="")
489                 
490                 sub = col.row(align=True)
491                 sub.itemR(con, "map_to_z_from", text="")
492                 sub.itemR(con, "to_min_z", text="")
493                 sub.itemR(con, "to_max_z", text="")
494                 
495                 self.space_template(layout, con)
496                 
497         def shrinkwrap (self, layout, con):
498                 self.target_template(layout, con)
499                 
500                 layout.itemR(con, "distance")
501                 layout.itemR(con, "shrinkwrap_type")
502                 
503                 if con.shrinkwrap_type == "PROJECT":
504                         row = layout.row(align=True)
505                         row.itemR(con, "axis_x")
506                         row.itemR(con, "axis_y")
507                         row.itemR(con, "axis_z")
508                 
509 class OBJECT_PT_constraints(ConstraintButtonsPanel):
510         __idname__ = "OBJECT_PT_constraints"
511         __label__ = "Constraints"
512         __context__ = "constraint"
513
514         def poll(self, context):
515                 return (context.object != None)
516                 
517         def draw(self, context):
518                 ob = context.object
519                 layout = self.layout
520
521                 row = layout.row()
522                 row.item_menu_enumO("OBJECT_OT_constraint_add", "type")
523                 row.itemL();
524
525                 for con in ob.constraints:
526                         self.draw_constraint(con)
527
528 class BONE_PT_constraints(ConstraintButtonsPanel):
529         __idname__ = "BONE_PT_constraints"
530         __label__ = "Bone Constraints"
531         __context__ = "constraint"
532
533         def poll(self, context):
534                 ob = context.object
535                 return (ob and ob.type == "ARMATURE")
536                 
537         def draw(self, context):
538                 ob = context.object
539                 pchan = ob.pose.pose_channels[0] # XXX
540                 layout = self.layout
541
542                 #row = layout.row()
543                 #row.item_menu_enumO("BONE_OT_constraint_add", "type")
544                 #row.itemL();
545
546                 for con in pchan.constraints:
547                         self.draw_constraint(con)
548
549 bpy.types.register(OBJECT_PT_constraints)
550 bpy.types.register(BONE_PT_constraints)