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