Code got unreadble due to copy-paste (hint for me: revert point)
[blender.git] / source / blender / src / buttons_object.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include "MEM_guardedalloc.h"
43
44 #include "DNA_ID.h"
45 #include "DNA_screen_types.h"
46 #include "DNA_space_types.h"
47 #include "DNA_scene_types.h"
48
49 #include "BKE_action.h"
50 #include "BKE_global.h"
51 #include "BKE_main.h"
52 #include "BKE_library.h"
53 #include "BKE_softbody.h"
54 #include "BKE_utildefines.h"
55
56 #include "BLI_blenlib.h"
57 #include "BLI_arithb.h"
58
59 #include "BSE_filesel.h"
60 #include "BSE_headerbuttons.h"
61
62 #include "BIF_butspace.h"
63 #include "BIF_editaction.h"
64 #include "BIF_gl.h"
65 #include "BIF_glutil.h"
66 #include "BIF_graphics.h"
67 #include "BIF_interface.h"
68 #include "BIF_keyval.h"
69 #include "BIF_mainqueue.h"
70 #include "BIF_mywindow.h"
71 #include "BIF_poseobject.h"
72 #include "BIF_resources.h"
73 #include "BIF_screen.h"
74 #include "BIF_space.h"
75 #include "BIF_toolbox.h"
76
77 #include "BDR_drawobject.h"
78 #include "BDR_editcurve.h"
79
80 #include "mydevice.h"
81 #include "blendef.h"
82
83 /* -----includes for this file specific----- */
84
85
86 #include "DNA_action_types.h"
87 #include "DNA_armature_types.h"
88 #include "DNA_camera_types.h"
89 #include "DNA_cloth_types.h"
90 #include "DNA_constraint_types.h"
91 #include "DNA_curve_types.h"
92 #include "DNA_effect_types.h"
93 #include "DNA_group_types.h"
94 #include "DNA_image_types.h"
95 #include "DNA_key_types.h"
96 #include "DNA_lamp_types.h"
97 #include "DNA_lattice_types.h"
98 #include "DNA_material_types.h"
99 #include "DNA_meta_types.h"
100 #include "DNA_mesh_types.h"
101 #include "DNA_modifier_types.h"
102 #include "DNA_object_types.h"
103 #include "DNA_object_force.h"
104 #include "DNA_object_fluidsim.h"
105 #include "DNA_radio_types.h"
106 #include "DNA_screen_types.h"
107 #include "DNA_sound_types.h"
108 #include "DNA_texture_types.h"
109 #include "DNA_userdef_types.h"
110 #include "DNA_vfont_types.h"
111 #include "DNA_view3d_types.h"
112 #include "DNA_world_types.h"
113 #include "DNA_text_types.h"
114
115 #include "BKE_anim.h"
116 #include "BKE_armature.h"
117 #include "BKE_cloth.h"
118 #include "BKE_constraint.h"
119 #include "BKE_curve.h"
120 #include "BKE_deform.h"
121 #include "BKE_depsgraph.h"
122 #include "BKE_displist.h"
123 #include "BKE_effect.h"
124 #include "BKE_font.h"
125 #include "BKE_group.h"
126 #include "BKE_image.h"
127 #include "BKE_ipo.h"
128 #include "BKE_lattice.h"
129 #include "BKE_material.h"
130 #include "BKE_mball.h"
131 #include "BKE_mesh.h"
132 #include "BKE_modifier.h"
133 #include "BKE_object.h"
134 #include "BKE_sound.h"
135 #include "BKE_texture.h"
136 #include "BKE_utildefines.h"
137 #include "BKE_DerivedMesh.h"
138
139 #include "LBM_fluidsim.h"
140 #include "elbeem.h"
141
142 #include "BIF_editconstraint.h"
143 #include "BIF_editdeform.h"
144
145 #include "BSE_editipo.h"
146 #include "BSE_edit.h"
147
148 #include "BDR_editobject.h"
149 #include "BPY_extern.h"
150
151 #include "butspace.h" // own module
152
153 static float prspeed=0.0;
154 float prlen=0.0;
155
156
157 /* ********************* CONSTRAINT ***************************** */
158
159 static void constraint_active_func(void *ob_v, void *con_v)
160 {
161         Object *ob= ob_v;
162         bConstraint *con;
163         ListBase *lb;
164         
165         /* lets be nice and escape if its active already */
166         if(con_v) {
167                 con= con_v;
168                 if(con->flag & CONSTRAINT_ACTIVE) return;
169         }
170         
171         lb= get_active_constraints(ob);
172         
173         for(con= lb->first; con; con= con->next) {
174                 if(con==con_v) con->flag |= CONSTRAINT_ACTIVE;
175                 else con->flag &= ~CONSTRAINT_ACTIVE;
176         }
177
178         /* make sure ipowin and buttons shows it */
179         if(ob->ipowin==ID_CO) {
180                 allqueue(REDRAWIPO, ID_CO);
181                 allspace(REMAKEIPO, 0);
182                 allqueue(REDRAWNLA, 0);
183         }
184         allqueue(REDRAWBUTSOBJECT, 0);
185 }
186
187 static void add_constraint_to_active(Object *ob, bConstraint *con)
188 {
189         ListBase *list;
190         
191         list = get_active_constraints(ob);
192         if (list) {
193                 unique_constraint_name(con, list);
194                 BLI_addtail(list, con);
195                 
196                 con->flag |= CONSTRAINT_ACTIVE;
197                 for(con= con->prev; con; con= con->prev)
198                         con->flag &= ~CONSTRAINT_ACTIVE;
199         }
200 }
201
202 /* returns base ID for Ipo, sets actname to channel if appropriate */
203 /* should not make action... */
204 void get_constraint_ipo_context(void *ob_v, char *actname)
205 {
206         Object *ob= ob_v;
207         
208         /* todo; check object if it has ob-level action ipo */
209         
210         if (ob->flag & OB_POSEMODE) {
211                 bPoseChannel *pchan;
212                 
213                 pchan = get_active_posechannel(ob);
214                 if (pchan) {
215                         BLI_strncpy(actname, pchan->name, 32);
216                 }
217         }
218         else if(ob->ipoflag & OB_ACTION_OB)
219                 strcpy(actname, "Object");
220 }       
221
222 /* initialize UI to show Ipo window and make sure channels etc exist */
223 static void enable_constraint_ipo_func (void *ob_v, void *con_v)
224 {
225         Object *ob= ob_v;
226         bConstraint *con = con_v;
227         char actname[32]="";
228         
229         /* verifies if active constraint is set and shown in UI */
230         constraint_active_func(ob_v, con_v);
231         
232         /* the context */
233         get_constraint_ipo_context(ob, actname);
234         
235         /* adds ipo & channels & curve if needed */
236         verify_ipo((ID *)ob, ID_CO, actname, con->name);
237         
238         /* make sure ipowin shows it */
239         ob->ipowin= ID_CO;
240         allqueue(REDRAWIPO, ID_CO);
241         allspace(REMAKEIPO, 0);
242         allqueue(REDRAWNLA, 0);
243 }
244
245
246 static void add_influence_key_to_constraint_func (void *ob_v, void *con_v)
247 {
248         Object *ob= ob_v;
249         bConstraint *con = con_v;
250         IpoCurve *icu;
251         char actname[32]="";
252         
253         /* verifies if active constraint is set and shown in UI */
254         constraint_active_func(ob_v, con_v);
255         
256         /* the context */
257         get_constraint_ipo_context(ob, actname);
258
259         /* adds ipo & channels & curve if needed */
260         icu= verify_ipocurve((ID *)ob, ID_CO, actname, con->name, CO_ENFORCE);
261         
262         if (!icu) {
263                 error("Cannot get a curve from this IPO, may be dealing with linked data");
264                 return;
265         }
266         
267         if(ob->action)
268                 insert_vert_icu(icu, get_action_frame(ob, (float)CFRA), con->enforce, 0);
269         else
270                 insert_vert_icu(icu, CFRA, con->enforce, 0);
271         
272         /* make sure ipowin shows it */
273         ob->ipowin= ID_CO;
274         allqueue(REDRAWIPO, ID_CO);
275         allspace(REMAKEIPO, 0);
276         allqueue(REDRAWNLA, 0);
277         
278         BIF_undo_push("Insert Influence Key");
279 }
280
281 void del_constr_func (void *ob_v, void *con_v)
282 {
283         bConstraint *con= con_v;
284         bConstraintChannel *chan;
285         ListBase *lb;
286         
287         /* remove ipo channel */
288         lb= get_active_constraint_channels(ob_v, 0);
289         if(lb) {
290                 chan = get_constraint_channel(lb, con->name);
291                 if(chan) {
292                         if(chan->ipo) chan->ipo->id.us--;
293                         BLI_freelinkN(lb, chan);
294                 }
295         }
296         /* remove constraint itself */
297         lb= get_active_constraints(ob_v);
298         free_constraint_data (con);
299         BLI_freelinkN(lb, con);
300         
301         constraint_active_func(ob_v, NULL);
302 }
303
304 static void del_constraint_func (void *ob_v, void *con_v)
305 {
306         del_constr_func (ob_v, con_v);
307         BIF_undo_push("Delete constraint");
308         allqueue(REDRAWBUTSOBJECT, 0);
309         allqueue(REDRAWIPO, 0); 
310 }
311
312 static void verify_constraint_name_func (void *con_v, void *name_v)
313 {
314         Object *ob= OBACT;
315         bConstraint *con= con_v;
316         char oldname[32];       
317         
318         if (!con)
319                 return;
320         
321         /* put on the stack */
322         BLI_strncpy(oldname, (char *)name_v, 32);
323         
324         rename_constraint(ob, con, oldname);
325         
326         constraint_active_func(ob, con);
327         allqueue(REDRAWACTION, 0); 
328 }
329
330 void const_moveUp(void *ob_v, void *con_v)
331 {
332         bConstraint *con, *constr= con_v;
333         ListBase *conlist;
334         
335         if(constr->prev) {
336                 conlist = get_active_constraints(ob_v);
337                 for(con= conlist->first; con; con= con->next) {
338                         if(con==constr) {
339                                 BLI_remlink(conlist, con);
340                                 BLI_insertlink(conlist, con->prev->prev, con);
341                                 break;
342                         }
343                 }
344         }
345 }
346
347 static void constraint_moveUp(void *ob_v, void *con_v)
348 {
349         const_moveUp(ob_v, con_v);
350         BIF_undo_push("Move constraint");
351 }
352
353 void const_moveDown(void *ob_v, void *con_v)
354 {
355         bConstraint *con, *constr= con_v;
356         ListBase *conlist;
357         
358         if(constr->next) {
359                 conlist = get_active_constraints(ob_v);
360                 for(con= conlist->first; con; con= con->next) {
361                         if(con==constr) {
362                                 BLI_remlink(conlist, con);
363                                 BLI_insertlink(conlist, con->next, con);
364                                 break;
365                         }
366                 }
367         }
368 }
369
370 static void constraint_moveDown(void *ob_v, void *con_v)
371 {
372         const_moveDown(ob_v, con_v);
373         BIF_undo_push("Move constraint");
374 }
375
376 /* autocomplete callback for  buttons */
377 void autocomplete_bone(char *str, void *arg_v)
378 {
379         Object *ob= (Object *)arg_v;
380         
381         if(ob==NULL || ob->pose==NULL) return;
382         
383         /* search if str matches the beginning of name */
384         if(str[0]) {
385                 AutoComplete *autocpl= autocomplete_begin(str, 32);
386                 bPoseChannel *pchan;
387                 
388                 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
389                         autocomplete_do_name(autocpl, pchan->name);
390
391                 autocomplete_end(autocpl, str);
392         }
393 }
394
395 /* autocomplete callback for buttons */
396 void autocomplete_vgroup(char *str, void *arg_v)
397 {
398         Object *ob= (Object *)arg_v;
399         
400         if(ob==NULL) return;
401         
402         /* search if str matches the beginning of a name */
403         if(str[0]) {
404                 AutoComplete *autocpl= autocomplete_begin(str, 32);
405                 bDeformGroup *dg;
406                 
407                 for(dg= ob->defbase.first; dg; dg= dg->next)
408                         if(dg->name!=str)
409                                 autocomplete_do_name(autocpl, dg->name);
410
411                 autocomplete_end(autocpl, str);
412         }
413 }
414
415 /* pole angle callback */
416 void con_kinematic_set_pole_angle(void *ob_v, void *con_v)
417 {
418         bConstraint *con= con_v;
419         bKinematicConstraint *data = con->data;
420
421         if(data->poletar) {
422                 if(data->flag & CONSTRAINT_IK_SETANGLE) {
423                         data->flag |= CONSTRAINT_IK_GETANGLE;
424                         data->flag &= ~CONSTRAINT_IK_SETANGLE;
425                 }
426                 else {
427                         data->flag &= ~CONSTRAINT_IK_GETANGLE;
428                         data->flag |= CONSTRAINT_IK_SETANGLE;
429                 }
430         }
431 }
432
433 /* some commonly used macros in the constraints drawing code */
434 #define is_armature_target(target) (target && target->type==OB_ARMATURE)
435 #define is_armature_owner(ob) ((ob->type == OB_ARMATURE) && (ob->flag & OB_POSEMODE))
436 #define is_geom_target(target) (target && (ELEM(target->type, OB_MESH, OB_LATTICE)) )
437
438 /* Helper function for draw constraint - draws constraint space stuff 
439  * This function should not be called if no menus are required 
440  * owner/target: -1 = don't draw menu; 0= not posemode, 1 = posemode 
441  */
442 static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short xco, short yco, short owner, short target)
443 {
444         short tarx, ownx;
445         short bwidth;
446         
447         /* calculate sizes and placement of menus */
448         if (owner == -1) {
449                 bwidth = 125;
450                 tarx = 120;
451                 ownx = 0;
452                 
453         }
454         else if (target == -1) {
455                 bwidth = 125;
456                 tarx = 0;
457                 ownx = 120;
458         }
459         else {
460                 bwidth = 100;
461                 tarx = 95;
462                 ownx = tarx + bwidth;
463         }
464         
465         
466         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "CSpace:", xco, yco, 80,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
467         
468         uiBlockBeginAlign(block);
469         
470         /* Target-Space */
471         if (target == 1) {
472                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x3|Local with Parent %x4|Local Space %x1", 
473                                                                                                 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
474         }
475         else if (target == 0) {
476                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1", 
477                                                                                 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
478         }
479         
480         /* Owner-Space */
481         if (owner == 1) {
482                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Pose Space %x3|Local with Parent %x4|Local Space %x1", 
483                                                                                                 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");  
484         }
485         else if (owner == 0) {
486                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Local (Without Parent) Space %x1", 
487                                                                                 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");  
488         }
489         
490         uiBlockEndAlign(block);
491 }
492
493 /* draw panel showing settings for a constraint */
494 static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, short *xco, short *yco)
495 {
496         Object *ob= OBACT;
497         bConstraintTypeInfo *cti;
498         uiBut *but;
499         char typestr[32];
500         short height, width = 265;
501         int rb_col;
502
503         cti= constraint_get_typeinfo(con);
504         if (cti == NULL) {
505                 /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
506                 if (con->type == CONSTRAINT_TYPE_NULL)
507                         strcpy(typestr, "Null");
508                 else
509                         strcpy(typestr, "Unknown");
510         }
511         else
512                 strcpy(typestr, cti->name);
513                 
514         /* unless button has own callback, it adds this callback to button */
515         uiBlockSetFunc(block, constraint_active_func, ob, con);
516
517         /* Draw constraint header */
518         uiBlockSetEmboss(block, UI_EMBOSSN);
519         
520         /* rounded header */
521         rb_col= (con->flag & CONSTRAINT_ACTIVE)?40:20;
522         uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-1, width+40, 22, NULL, 5.0, 0.0, 
523                          (con->flag & CONSTRAINT_EXPAND)?3:15 , rb_col-20, ""); 
524         
525         /* open/close */
526         uiDefIconButBitS(block, ICONTOG, CONSTRAINT_EXPAND, B_CONSTRAINT_TEST, ICON_DISCLOSURE_TRI_RIGHT, *xco-10, *yco, 20, 20, &con->flag, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Constraint");
527         
528         /* up/down */
529         uiBlockBeginAlign(block);
530         uiBlockSetEmboss(block, UI_EMBOSS);
531         but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_UP, *xco+width-50, *yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint up in constraint stack");
532         uiButSetFunc(but, constraint_moveUp, ob, con);
533         
534         but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_DOWN, *xco+width-50+18, *yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint down in constraint stack");
535         uiButSetFunc(but, constraint_moveDown, ob, con);
536         uiBlockEndAlign(block);
537         
538         if (con->flag & CONSTRAINT_EXPAND) {
539                 if (con->flag & CONSTRAINT_DISABLE)
540                         uiBlockSetCol(block, TH_REDALERT);
541                 
542                 uiBlockSetEmboss(block, UI_EMBOSS);
543                 
544                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
545                 
546                 but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", *xco+120, *yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name"); 
547                 uiButSetFunc(but, verify_constraint_name_func, con, NULL);
548         }       
549         else {
550                 uiBlockSetEmboss(block, UI_EMBOSSN);
551                 
552                 if (con->flag & CONSTRAINT_DISABLE)
553                         uiBlockSetCol(block, TH_REDALERT);
554                 
555                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
556                 
557                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, con->name, *xco+120, *yco-1, 135, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
558         }
559
560         uiBlockSetCol(block, TH_AUTO);  
561         
562         uiBlockSetEmboss(block, UI_EMBOSSN);
563         
564         but = uiDefIconBut(block, BUT, B_CONSTRAINT_CHANGETARGET, ICON_X, *xco+262, *yco, 19, 19, list, 0.0, 0.0, 0.0, 0.0, "Delete constraint");
565         uiButSetFunc(but, del_constraint_func, ob, con);
566
567         uiBlockSetEmboss(block, UI_EMBOSS);
568
569
570         /* Draw constraint data */
571         if ((con->flag & CONSTRAINT_EXPAND) == 0) {
572                 (*yco) -= 21;
573         }
574         else {
575                 switch (con->type) {
576                 case CONSTRAINT_TYPE_PYTHON:
577                         {
578                                 bPythonConstraint *data = con->data;
579                                 bConstraintTarget *ct;
580                                 uiBut *but2;
581                                 int tarnum, theight;
582                                 static int pyconindex=0;
583                                 char *menustr;
584                                 
585                                 theight = (data->tarnum)? (data->tarnum * 38) : (38);
586                                 height = theight + 78;
587                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40, height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
588                                 
589                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Script:", *xco+60, *yco-24, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
590                                 
591                                 /* do the scripts menu */
592                                 menustr = buildmenu_pyconstraints(data->text, &pyconindex);
593                                 but2 = uiDefButI(block, MENU, B_CONSTRAINT_TEST, menustr,
594                                       *xco+120, *yco-24, 150, 20, &pyconindex,
595                                       0.0, 1.0, 0, 0, "Set the Script Constraint to use");
596                                 uiButSetFunc(but2, validate_pyconstraint_cb, data, &pyconindex);
597                                 MEM_freeN(menustr);     
598                                 
599                                 /* draw target(s) */
600                                 if (data->flag & PYCON_USETARGETS) {
601                                         /* Draw target parameters */ 
602                                         for (ct=data->targets.first, tarnum=1; ct; ct=ct->next, tarnum++) {
603                                                 char tarstr[32];
604                                                 short yoffset= ((tarnum-1) * 38);
605                                                 
606                                                 /* target label */
607                                                 sprintf(tarstr, "Target %02d:", tarnum);
608                                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, tarstr, *xco+45, *yco-(48+yoffset), 60, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
609                                                 
610                                                 /* target space-selector - per target */
611                                                 if (is_armature_target(ct->tar)) {
612                                                         uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x3|Local with Parent %x4|Local Space %x1", 
613                                                                                                                         *xco+10, *yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in");       
614                                                 }
615                                                 else {
616                                                         uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1", 
617                                                                                                                         *xco+10, *yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in");       
618                                                 }
619                                                 
620                                                 uiBlockBeginAlign(block);
621                                                         /* target object */
622                                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-(48+yoffset), 150, 18, &ct->tar, "Target Object"); 
623                                                         
624                                                         /* subtarget */
625                                                         if (is_armature_target(ct->tar)) {
626                                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Subtarget Bone");
627                                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)ct->tar);
628                                                         }
629                                                         else if (is_geom_target(ct->tar)) {
630                                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
631                                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ct->tar);
632                                                         }
633                                                         else {
634                                                                 strcpy(ct->subtarget, "");
635                                                         }
636                                                 uiBlockEndAlign(block);
637                                         }
638                                 }
639                                 else {
640                                         /* Draw indication that no target needed */
641                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+60, *yco-48, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
642                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Not Applicable", *xco+120, *yco-48, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
643                                 }
644                                 
645                                 /* settings */
646                                 uiBlockBeginAlign(block);
647                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Options", *xco, *yco-(52+theight), (width/2),18, NULL, 0, 24, 0, 0, "Change some of the constraint's settings.");
648                                         uiButSetFunc(but, BPY_pyconstraint_settings, data, NULL);
649                                         
650                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Refresh", *xco+((width/2)+10), *yco-(52+theight), (width/2),18, NULL, 0, 24, 0, 0, "Force constraint to refresh it's settings");
651                                 uiBlockEndAlign(block);
652                                 
653                                 /* constraint space settings */
654                                 draw_constraint_spaceselect(block, con, *xco, *yco-(73+theight), is_armature_owner(ob), -1);
655                         }
656                         break;
657                 case CONSTRAINT_TYPE_ACTION:
658                         {
659                                 bActionConstraint *data = con->data;
660                                 float minval, maxval;
661                                 
662                                 height = 108;
663                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
664                                 
665                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
666                                 
667                                 /* Draw target parameters */
668                                 uiBlockBeginAlign(block);
669                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
670                                         
671                                         if (is_armature_target(data->tar)) {
672                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
673                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
674                                         }
675                                         else {
676                                                 strcpy(data->subtarget, "");
677                                         }
678                                 
679                                 uiBlockEndAlign(block);
680                                 
681                                 /* Draw action/type buttons */
682                                 uiBlockBeginAlign(block);
683                                         uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, B_CONSTRAINT_TEST, "AC:",     *xco+((width/2)-117), *yco-64, 78, 18, &data->act, "Action containing the keyed motion for this bone"); 
684                                         uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Key on%t|Loc X%x20|Loc Y%x21|Loc Z%x22|Rot X%x0|Rot Y%x1|Rot Z%x2|Size X%x10|Size Y%x11|Size Z%x12", *xco+((width/2)-117), *yco-84, 78, 18, &data->type, 0, 24, 0, 0, "Specify which transformation channel from the target is used to key the action");
685                                 uiBlockEndAlign(block);
686                                 
687                                 /* Draw start/end frame buttons */
688                                 uiBlockBeginAlign(block);
689                                         uiDefButI(block, NUM, B_CONSTRAINT_TEST, "Start:", *xco+((width/2)-36), *yco-64, 78, 18, &data->start, 1, MAXFRAME, 0.0, 0.0, "Starting frame of the keyed motion"); 
690                                         uiDefButI(block, NUM, B_CONSTRAINT_TEST, "End:", *xco+((width/2)-36), *yco-84, 78, 18, &data->end, 1, MAXFRAME, 0.0, 0.0, "Ending frame of the keyed motion"); 
691                                 uiBlockEndAlign(block);
692                                 
693                                 /* Draw minimum/maximum transform range buttons */
694                                 uiBlockBeginAlign(block);
695                                         if (data->type < 10) { /* rotation */
696                                                 minval = -180.0f;
697                                                 maxval = 180.0f;
698                                         }
699                                         else if (data->type < 20) { /* scaling */
700                                                 minval = 0.0001f;
701                                                 maxval = 1000.0f;
702                                         }
703                                         else { /* location */
704                                                 minval = -1000.0f;
705                                                 maxval = 1000.0f;
706                                         }
707                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Min:", *xco+((width/2)+45), *yco-64, 78, 18, &data->min, minval, maxval, 0, 0, "Minimum value for target channel range");
708                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Max:", *xco+((width/2)+45), *yco-84, 78, 18, &data->max, minval, maxval, 0, 0, "Maximum value for target channel range");
709                                 uiBlockEndAlign(block);
710                                 
711                                 /* constraint space settings */
712                                 draw_constraint_spaceselect(block, con, *xco, *yco-104, -1, is_armature_target(data->tar));
713                         }
714                         break;
715                 case CONSTRAINT_TYPE_CHILDOF:
716                         {
717                                 bChildOfConstraint *data = con->data;
718                                 short normButWidth = (width/3);
719                                 
720                                 height = 165;
721                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
722                                 
723                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Parent:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
724                                 
725                                 /* Draw target parameters */
726                                 uiBlockBeginAlign(block);
727                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object to use as Parent"); 
728                                         
729                                         if (is_armature_target(data->tar)) {
730                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone to use as Parent");
731                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
732                                         }
733                                         else if (is_geom_target(data->tar)) {
734                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
735                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
736                                         }
737                                         else {
738                                                 strcpy(data->subtarget, "");
739                                         }
740                                 uiBlockEndAlign(block);
741                                 
742                                 /* Draw triples of channel toggles */
743                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Use Channel(s):", *xco+65, *yco-64, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
744                                 uiBlockBeginAlign(block); 
745                                         uiDefButBitI(block, TOG, CHILDOF_LOCX, B_CONSTRAINT_TEST, "Loc X", *xco, *yco-84, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects x-location"); 
746                                         uiDefButBitI(block, TOG, CHILDOF_LOCY, B_CONSTRAINT_TEST, "Loc Y", *xco+normButWidth, *yco-84, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects y-location"); 
747                                         uiDefButBitI(block, TOG, CHILDOF_LOCZ, B_CONSTRAINT_TEST, "Loc Z", *xco+(normButWidth * 2), *yco-84, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects z-location"); 
748                                 uiBlockEndAlign(block); 
749                                 
750                                 uiBlockBeginAlign(block); 
751                                         uiDefButBitI(block, TOG, CHILDOF_ROTX, B_CONSTRAINT_TEST, "Rot X", *xco, *yco-105, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects x-rotation"); 
752                                         uiDefButBitI(block, TOG, CHILDOF_ROTY, B_CONSTRAINT_TEST, "Rot Y", *xco+normButWidth, *yco-105, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects y-rotation"); 
753                                         uiDefButBitI(block, TOG, CHILDOF_ROTZ, B_CONSTRAINT_TEST, "Rot Z", *xco+(normButWidth * 2), *yco-105, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects z-rotation"); 
754                                 uiBlockEndAlign(block); 
755                                 
756                                 uiBlockBeginAlign(block); 
757                                         uiDefButBitI(block, TOG, CHILDOF_SIZEX, B_CONSTRAINT_TEST, "Scale X", *xco, *yco-126, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects x-scaling"); 
758                                         uiDefButBitI(block, TOG, CHILDOF_SIZEY, B_CONSTRAINT_TEST, "Scale Y", *xco+normButWidth, *yco-126, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects y-scaling"); 
759                                         uiDefButBitI(block, TOG, CHILDOF_SIZEZ, B_CONSTRAINT_TEST, "Scale Z", *xco+(normButWidth * 2), *yco-126, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects z-scaling"); 
760                                 uiBlockEndAlign(block);
761                                 
762                                 
763                                 /* Inverse options */
764                                 uiBlockBeginAlign(block);
765                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Set Offset", *xco, *yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Calculate current Parent-Inverse Matrix (i.e. restore offset from parent)");
766                                         uiButSetFunc(but, childof_const_setinv, data, NULL);
767                                         
768                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Clear Offset", *xco+((width/2)+10), *yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Clear Parent-Inverse Matrix (i.e. clear offset from parent)");
769                                         uiButSetFunc(but, childof_const_clearinv, data, NULL);
770                                 uiBlockEndAlign(block);
771                         }
772                         break;
773                 case CONSTRAINT_TYPE_LOCLIKE:
774                         {
775                                 bLocateLikeConstraint *data = con->data;
776                                 
777                                 height = 111;
778                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
779                                 
780                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
781                                 
782                                 /* Draw target parameters */
783                                 uiBlockBeginAlign(block);
784                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
785                                         
786                                         if (is_armature_target(data->tar)) {
787                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
788                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
789                                         }
790                                         else if (is_geom_target(data->tar)) {
791                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
792                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
793                                         }
794                                         else {
795                                                 strcpy(data->subtarget, "");
796                                         }
797                                 uiBlockEndAlign(block);
798                                 
799                                 /* Draw XYZ toggles */
800                                 uiBlockBeginAlign(block);
801                                         uiDefButBitI(block, TOG, LOCLIKE_X, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component");
802                                         uiDefButBitI(block, TOG, LOCLIKE_X_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert X component");
803                                         uiDefButBitI(block, TOG, LOCLIKE_Y, B_CONSTRAINT_TEST, "Y", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component");
804                                         uiDefButBitI(block, TOG, LOCLIKE_Y_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Y component");
805                                         uiDefButBitI(block, TOG, LOCLIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+96), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component");
806                                         uiDefButBitI(block, TOG, LOCLIKE_Z_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+128), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Z component");
807                                 uiBlockEndAlign(block);
808                                 
809                                 /* Draw options */
810                                 uiDefButBitI(block, TOG, LOCLIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco, *yco-89, (width/2), 18, &data->flag, 0, 24, 0, 0, "Add original location onto copied location");
811                                 if (is_armature_target(data->tar)) {
812                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Head/Tail:", *xco+(width/2), *yco-89, (width/2), 18, &con->headtail, 0.0, 1, 0.1, 0.1, "Target along length of bone: Head=0, Tail=1");
813                                 }
814                                 
815                                 /* constraint space settings */
816                                 draw_constraint_spaceselect(block, con, *xco, *yco-109, is_armature_owner(ob), is_armature_target(data->tar));
817                         }
818                         break;
819                 case CONSTRAINT_TYPE_ROTLIKE:
820                         {
821                                 bRotateLikeConstraint *data = con->data;
822                                 
823                                 height = 101;
824                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
825                                 
826                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
827                                 
828                                 /* Draw target parameters */
829                                 uiBlockBeginAlign(block);
830
831                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
832                                 
833                                 if (is_armature_target(data->tar)) {
834                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
835                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
836                                 }
837                                 else if (is_geom_target(data->tar)) { 
838                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
839                                         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
840                                 }
841                                 else {
842                                         strcpy(data->subtarget, "");
843                                 }
844
845                                 uiBlockEndAlign(block);
846                                 
847                                 /* Draw XYZ toggles */
848                                 uiBlockBeginAlign(block);
849                                         uiDefButBitI(block, TOG, ROTLIKE_X, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component");
850                                         uiDefButBitI(block, TOG, ROTLIKE_X_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert X component");
851                                         uiDefButBitI(block, TOG, ROTLIKE_Y, B_CONSTRAINT_TEST, "Y", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component");
852                                         uiDefButBitI(block, TOG, ROTLIKE_Y_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Y component");
853                                         uiDefButBitI(block, TOG, ROTLIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+96), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component");
854                                         uiDefButBitI(block, TOG, ROTLIKE_Z_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+128), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Z component");
855                                 uiBlockEndAlign(block);
856                                 
857                                 /* draw offset toggle */
858                                 uiDefButBitI(block, TOG, ROTLIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco, *yco-64, 80, 18, &data->flag, 0, 24, 0, 0, "Add original rotation onto copied rotation");
859                                 
860                                 /* constraint space settings */
861                                 draw_constraint_spaceselect(block, con, *xco, *yco-94, is_armature_owner(ob), is_armature_target(data->tar));
862                         }
863                         break;
864                 case CONSTRAINT_TYPE_SIZELIKE:
865                         {
866                                 bSizeLikeConstraint *data = con->data;
867                                 
868                                 height = 101;
869                                 
870                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
871                                 
872                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
873                                 
874                                 /* Draw target parameters */
875                                 uiBlockBeginAlign(block);
876                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
877                                         
878                                         if (is_armature_target(data->tar)) {
879                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
880                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
881                                         }
882                                         else if (is_geom_target(data->tar)) {
883                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
884                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
885                                         }
886                                         else {
887                                                 strcpy(data->subtarget, "");
888                                         }
889                                 uiBlockEndAlign(block);
890
891                                 /* Draw XYZ toggles */
892                                 uiBlockBeginAlign(block);
893                                         uiDefButBitI(block, TOG, SIZELIKE_X, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component");
894                                         uiDefButBitI(block, TOG, SIZELIKE_Y, B_CONSTRAINT_TEST, "Y", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component");
895                                         uiDefButBitI(block, TOG, SIZELIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component");
896                                 uiBlockEndAlign(block);
897                                 
898                                 /* draw offset toggle */
899                                 uiDefButBitI(block, TOG, SIZELIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco, *yco-64, 80, 18, &data->flag, 0, 24, 0, 0, "Add original scaling onto copied scaling");
900                                 
901                                 /* constraint space settings */
902                                 draw_constraint_spaceselect(block, con, *xco, *yco-94, is_armature_owner(ob), is_armature_target(data->tar));
903                         }
904                         break;
905                 case CONSTRAINT_TYPE_KINEMATIC:
906                         {
907                                 bKinematicConstraint *data = con->data;
908                                 
909                                 height = 146;
910                                 if(data->poletar) 
911                                         height += 30;
912
913                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
914                                 
915                                 /* IK Target */
916                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
917
918                                 /* Draw target parameters */
919                                 uiBlockBeginAlign(block);
920                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco, *yco-44, 137, 19, &data->tar, "Target Object"); 
921
922                                 if (is_armature_target(data->tar)) {
923                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco, *yco-62,137,19, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
924                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
925                                 }
926                                 else if (is_geom_target(data->tar)) {
927                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco, *yco-62,137,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
928                                         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
929                                 }
930                                 else {
931                                         strcpy (data->subtarget, "");
932                                 }
933
934                                 uiBlockEndAlign(block);
935
936                                 /* Settings */
937                                 uiBlockBeginAlign(block);
938                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_TIP, B_CONSTRAINT_TEST, "Use Tail", *xco, *yco-92, 137, 19, &data->flag, 0, 0, 0, 0, "Include Bone's tail als last element in Chain");
939                                 uiDefButI(block, NUM, B_CONSTRAINT_TEST, "ChainLen:", *xco, *yco-112,137,19, &data->rootbone, 0, 255, 0, 0, "If not zero, the amount of bones in this chain");
940
941                                 uiBlockBeginAlign(block);
942                                 uiDefButF(block, NUMSLI, B_CONSTRAINT_TEST, "PosW ", *xco+147, *yco-92, 137, 19, &data->weight, 0.01, 1.0, 2, 2, "For Tree-IK: weight of position control for this target");
943                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_ROT, B_CONSTRAINT_TEST, "Rot", *xco+147, *yco-112, 40,19, &data->flag, 0, 0, 0, 0, "Chain follows rotation of target");
944                                 uiDefButF(block, NUMSLI, B_CONSTRAINT_TEST, "W ", *xco+187, *yco-112, 97, 19, &data->orientweight, 0.01, 1.0, 2, 2, "For Tree-IK: Weight of orientation control for this target");
945
946                                 uiBlockBeginAlign(block);
947
948                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_STRETCH, B_CONSTRAINT_TEST, "Stretch", *xco, *yco-137,137,19, &data->flag, 0, 0, 0, 0, "Enable IK stretching");
949                                 uiBlockBeginAlign(block);
950                                 uiDefButS(block, NUM, B_CONSTRAINT_TEST, "Iterations:", *xco+147, *yco-137, 137, 19, &data->iterations, 1, 10000, 0, 0, "Maximum number of solving iterations"); 
951                                 uiBlockEndAlign(block);
952
953                                 /* Pole Vector */
954                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Pole Target:", *xco+147, *yco-24, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
955
956                                 uiBlockBeginAlign(block);
957                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+147, *yco-44, 137, 19, &data->poletar, "Pole Target Object"); 
958                                 if (is_armature_target(data->poletar)) {
959                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+147, *yco-62,137,19, &data->polesubtarget, 0, 24, 0, 0, "Pole Subtarget Bone");
960                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->poletar);
961                                 }
962                                 else if (is_geom_target(data->poletar)) {
963                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+147, *yco-62,137,18, &data->polesubtarget, 0, 24, 0, 0, "Name of Vertex Group defining pole 'target' points");
964                                         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->poletar);
965                                 }
966                                 else {
967                                         strcpy (data->polesubtarget, "");
968                                 }
969         
970                                 if(data->poletar) {
971                                         uiBlockBeginAlign(block);
972 #if 0
973                                         but = uiDefBut(block, BUT, B_CONSTRAINT_TEST, (data->flag & CONSTRAINT_IK_SETANGLE)? "Set Pole Offset": "Clear Pole Offset", *xco, *yco-167, 137, 19, 0, 0.0, 1.0, 0.0, 0.0, "Set the pole rotation offset from the current pose");
974                                         uiButSetFunc(but, con_kinematic_set_pole_angle, ob, con);
975                                         if(!(data->flag & CONSTRAINT_IK_SETANGLE))
976 #endif
977                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pole Offset ", *xco, *yco-167, 137, 19, &data->poleangle, -180.0, 180.0, 0, 0, "Pole rotation offset");
978                                 }
979                         }
980                         break;
981                 case CONSTRAINT_TYPE_TRACKTO:
982                         {
983                                 bTrackToConstraint *data = con->data;
984                                 
985                                 if (is_armature_target(data->tar)) 
986                                         height = 118;
987                                 else
988                                         height = 96;
989                                         
990                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
991                                 
992                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
993                                 
994                                 /* Draw target parameters */
995                                 uiBlockBeginAlign(block);
996                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
997                                         
998                                         if (is_armature_target(data->tar)) {
999                                                 but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1000                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1001                                         }
1002                                         else if (is_geom_target(data->tar)) {
1003                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1004                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1005                                         }
1006                                         else {
1007                                                 strcpy(data->subtarget, "");
1008                                         }
1009                                 uiBlockEndAlign(block);
1010                                 
1011                                 uiBlockBeginAlign(block);
1012                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Align:", *xco+5, *yco-42, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1013                                         
1014                                         uiDefButBitI(block, TOG, 1, B_CONSTRAINT_TEST, "TargetZ", *xco+60, *yco-42, 50, 18, &data->flags, 0, 1, 0, 0, "Target Z axis, not world Z axis, will constrain up direction");
1015                                 uiBlockEndAlign(block);
1016                                 
1017                                 uiBlockBeginAlign(block);
1018                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1019                                         
1020                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+39, *yco-64,17,18, &data->reserved1, 12.0, 0.0, 0, 0, "X axis points to the target object");
1021                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+56, *yco-64,17,18, &data->reserved1, 12.0, 1.0, 0, 0, "Y axis points to the target object");
1022                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+73, *yco-64,17,18, &data->reserved1, 12.0, 2.0, 0, 0, "Z axis points to the target object");
1023                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-X",    *xco+90, *yco-64,24,18, &data->reserved1, 12.0, 3.0, 0, 0, "-X axis points to the target object");
1024                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Y",    *xco+114, *yco-64,24,18, &data->reserved1, 12.0, 4.0, 0, 0, "-Y axis points to the target object");
1025                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Z",    *xco+138, *yco-64,24,18, &data->reserved1, 12.0, 5.0, 0, 0, "-Z axis points to the target object");
1026                                 uiBlockEndAlign(block);
1027                                 
1028                                 uiBlockBeginAlign(block);
1029                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1030                                         
1031                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+204, *yco-64,17,18, &data->reserved2, 13.0, 0.0, 0, 0, "X axis points upward");
1032                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+221, *yco-64,17,18, &data->reserved2, 13.0, 1.0, 0, 0, "Y axis points upward");
1033                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+238, *yco-64,17,18, &data->reserved2, 13.0, 2.0, 0, 0, "Z axis points upward");
1034                                 uiBlockEndAlign(block);
1035                                 
1036                                 if (is_armature_target(data->tar)) {
1037                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Head/Tail:", *xco, *yco-94, 241, 18, &con->headtail, 0.0, 1, 0.1, 0.1, "Target along length of bone: Head=0, Tail=1");
1038                                         
1039                                         /* constraint space settings */
1040                                         draw_constraint_spaceselect(block, con, *xco, *yco-116, is_armature_owner(ob), is_armature_target(data->tar));
1041                                 }
1042                                 else {
1043                                         /* constraint space settings */
1044                                         draw_constraint_spaceselect(block, con, *xco, *yco-94, is_armature_owner(ob), is_armature_target(data->tar));
1045                                 }
1046                         }
1047                         break;
1048                 case CONSTRAINT_TYPE_MINMAX:
1049                         {
1050                                 bMinMaxConstraint *data = con->data;
1051                                 
1052                                 if (is_armature_target(data->tar)) 
1053                                         height = 88;
1054                                 else
1055                                         height = 66;
1056                                         
1057                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1058                                 
1059                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1060                                 
1061                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Offset:", *xco, *yco-44, 100, 18, &data->offset, -100, 100, 100.0, 0.0, "Offset from the position of the object center"); 
1062                                 
1063                                 /* Draw target parameters */
1064                                 uiBlockBeginAlign(block);
1065                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1066                                         
1067                                         if (is_armature_target(data->tar)) {
1068                                                 but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1069                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1070                                         }
1071                                         else if (is_geom_target(data->tar)) {
1072                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1073                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1074                                         }
1075                                         else {
1076                                                 strcpy(data->subtarget, "");
1077                                         }
1078                                 uiBlockEndAlign(block);
1079                                 
1080                                 uiDefButBitI(block, TOG, 0, B_CONSTRAINT_TEST, "Sticky", *xco, *yco-24, 44, 18, &data->flag, 0, 24, 0, 0, "Immobilize object while constrained");
1081                                 uiDefButBitI(block, TOG, 2, B_CONSTRAINT_TEST, "Use Rot", *xco+44, *yco-24, 64, 18, &data->flag, 0, 24, 0, 0, "Use target object rotation");
1082                                 
1083                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Max/Min:", *xco-8, *yco-64, 54, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1084                                 
1085                                 uiBlockBeginAlign(block);                       
1086                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"X",    *xco+51, *yco-64,17,18, &data->minmaxflag, 12.0, 0.0, 0, 0, "Will not pass below X of target");
1087                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"Y",    *xco+67, *yco-64,17,18, &data->minmaxflag, 12.0, 1.0, 0, 0, "Will not pass below Y of target");
1088                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"Z",    *xco+85, *yco-64,17,18, &data->minmaxflag, 12.0, 2.0, 0, 0, "Will not pass below Z of target");
1089                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"-X",   *xco+102, *yco-64,24,18, &data->minmaxflag, 12.0, 3.0, 0, 0, "Will not pass above X of target");
1090                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"-Y",   *xco+126, *yco-64,24,18, &data->minmaxflag, 12.0, 4.0, 0, 0, "Will not pass above Y of target");
1091                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"-Z",   *xco+150, *yco-64,24,18, &data->minmaxflag, 12.0, 5.0, 0, 0, "Will not pass above Z of target");
1092                                 uiBlockEndAlign(block);
1093                                 
1094                                 if (is_armature_target(data->tar)) {
1095                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Head/Tail:", *xco, *yco-86, 241, 18, &con->headtail, 0.0, 1, 0.1, 0.1, "Target along length of bone: Head=0, Tail=1");
1096                                 }
1097                                 
1098                         }
1099                         break;
1100                 case CONSTRAINT_TYPE_LOCKTRACK:
1101                         {
1102                                 bLockTrackConstraint *data = con->data;
1103                                 height = 66;
1104                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1105                                 
1106                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1107                                 
1108                                 /* Draw target parameters */
1109                                 uiBlockBeginAlign(block);
1110                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1111                                         
1112                                         if (is_armature_target(data->tar)) {
1113                                                 but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1114                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1115                                         }
1116                                         else if (is_geom_target(data->tar)) {
1117                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1118                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1119                                         }
1120                                         else {
1121                                                 strcpy(data->subtarget, "");
1122                                         }
1123                                 uiBlockEndAlign(block);
1124                                 
1125                                 uiBlockBeginAlign(block);
1126                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1127                                         
1128                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"X",    *xco+39, *yco-64,17,18, &data->trackflag, 12.0, 0.0, 0, 0, "X axis points to the target object");
1129                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"Y",    *xco+56, *yco-64,17,18, &data->trackflag, 12.0, 1.0, 0, 0, "Y axis points to the target object");
1130                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"Z",    *xco+73, *yco-64,17,18, &data->trackflag, 12.0, 2.0, 0, 0, "Z axis points to the target object");
1131                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"-X",   *xco+90, *yco-64,24,18, &data->trackflag, 12.0, 3.0, 0, 0, "-X axis points to the target object");
1132                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"-Y",   *xco+114, *yco-64,24,18, &data->trackflag, 12.0, 4.0, 0, 0, "-Y axis points to the target object");
1133                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"-Z",   *xco+138, *yco-64,24,18, &data->trackflag, 12.0, 5.0, 0, 0, "-Z axis points to the target object");
1134                                 uiBlockEndAlign(block);
1135                                 
1136                                 uiBlockBeginAlign(block);
1137                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Lock:", *xco+166, *yco-64, 38, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1138                                         
1139                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"X",    *xco+204, *yco-64,17,18, &data->lockflag, 13.0, 0.0, 0, 0, "X axis is locked");
1140                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"Y",    *xco+221, *yco-64,17,18, &data->lockflag, 13.0, 1.0, 0, 0, "Y axis is locked");
1141                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"Z",    *xco+238, *yco-64,17,18, &data->lockflag, 13.0, 2.0, 0, 0, "Z axis is locked");
1142                                 uiBlockEndAlign(block);
1143                         }
1144                         break;
1145                 case CONSTRAINT_TYPE_FOLLOWPATH:
1146                         {
1147                                 bFollowPathConstraint *data = con->data;
1148                                 
1149                                 height = 66;
1150                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1151                                 
1152                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1153                                 
1154                                 /* Draw target parameters */
1155                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1156                                 
1157                                 /* Draw Curve Follow toggle */
1158                                 uiDefButBitI(block, TOG, 1, B_CONSTRAINT_TEST, "CurveFollow", *xco+39, *yco-44, 100, 18, &data->followflag, 0, 24, 0, 0, "Object will follow the heading and banking of the curve");
1159                                 
1160                                 /* Draw Offset number button */
1161                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Offset:", *xco+155, *yco-44, 100, 18, &data->offset, -MAXFRAMEF, MAXFRAMEF, 100.0, 0.0, "Offset from the position corresponding to the time frame"); 
1162                                 
1163                                 uiBlockBeginAlign(block);
1164                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Fw:", *xco+12, *yco-64, 27, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1165                                         
1166                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"X",    *xco+39, *yco-64,17,18, &data->trackflag, 12.0, 0.0, 0, 0, "The axis that points forward along the path");
1167                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"Y",    *xco+56, *yco-64,17,18, &data->trackflag, 12.0, 1.0, 0, 0, "The axis that points forward along the path");
1168                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"Z",    *xco+73, *yco-64,17,18, &data->trackflag, 12.0, 2.0, 0, 0, "The axis that points forward along the path");
1169                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"-X",   *xco+90, *yco-64,24,18, &data->trackflag, 12.0, 3.0, 0, 0, "The axis that points forward along the path");
1170                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"-Y",   *xco+114, *yco-64,24,18, &data->trackflag, 12.0, 4.0, 0, 0, "The axis that points forward along the path");
1171                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"-Z",   *xco+138, *yco-64,24,18, &data->trackflag, 12.0, 5.0, 0, 0, "The axis that points forward along the path");
1172                                 uiBlockEndAlign(block);
1173                                 
1174                                 uiBlockBeginAlign(block);
1175                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1176                                         
1177                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"X",    *xco+204, *yco-64,17,18, &data->upflag, 13.0, 0.0, 0, 0, "The axis that points upward");
1178                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"Y",    *xco+221, *yco-64,17,18, &data->upflag, 13.0, 1.0, 0, 0, "The axis that points upward");
1179                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST,"Z",    *xco+238, *yco-64,17,18, &data->upflag, 13.0, 2.0, 0, 0, "The axis that points upward");
1180                                 uiBlockEndAlign(block);
1181                         }
1182                         break;
1183                 case CONSTRAINT_TYPE_STRETCHTO:
1184                         {
1185                                 bStretchToConstraint *data = con->data;
1186                                 
1187                                 height = 105;
1188                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1189                                 
1190                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1191                                 
1192                                 /* Draw target parameters */
1193                                 uiBlockBeginAlign(block);
1194                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1195                                         
1196                                         if (is_armature_target(data->tar)) {
1197                                                 but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1198                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1199                                         }
1200                                         else if (is_geom_target(data->tar)) {
1201                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1202                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1203                                         }
1204                                         else {
1205                                                 strcpy(data->subtarget, "");
1206                                         }
1207                                 uiBlockEndAlign(block);
1208                                 
1209                                 uiBlockBeginAlign(block);
1210                                         if (is_armature_target(data->tar)) {
1211                                                 uiDefButF(block, BUTM, B_CONSTRAINT_TEST, "R", *xco, *yco-60, 20, 18, &data->orglength, 0.0, 0, 0, 0, "Recalculate RLength");
1212                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Rest Length:", *xco+18, *yco-60,139,18, &data->orglength, 0.0, 100, 0.5, 0.5, "Length at Rest Position");
1213                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Head/Tail:", *xco+155, *yco-60,97,18, &con->headtail, 0.0, 1, 0.1, 0.1, "Target along length of bone: Head=0, Tail=1");
1214                                         }
1215                                         else {
1216                                                 uiDefButF(block, BUTM, B_CONSTRAINT_TEST, "R", *xco, *yco-60, 20, 18, &data->orglength, 0.0, 0, 0, 0, "Recalculate RLength");
1217                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Rest Length:", *xco+18, *yco-60, 237, 18, &data->orglength, 0.0, 100, 0.5, 0.5, "Length at Rest Position");
1218                                         }
1219                                 uiBlockEndAlign(block);
1220                                 
1221                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Volume Variation:", *xco+18, *yco-82, 237, 18, &data->bulge, 0.0, 100, 0.5, 0.5, "Factor between volume variation and stretching");
1222                                 
1223                                 uiBlockBeginAlign(block);
1224                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Vol:",*xco+14, *yco-104,30,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1225                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"XZ",     *xco+44, *yco-104,30,18, &data->volmode, 12.0, 0.0, 0, 0, "Keep Volume: Scaling X & Z");
1226                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",      *xco+74, *yco-104,20,18, &data->volmode, 12.0, 1.0, 0, 0, "Keep Volume: Scaling X");
1227                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",      *xco+94, *yco-104,20,18, &data->volmode, 12.0, 2.0, 0, 0, "Keep Volume: Scaling Z");
1228                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"NONE", *xco+114, *yco-104,50,18, &data->volmode, 12.0, 3.0, 0, 0, "Ignore Volume");
1229                                 uiBlockEndAlign(block);
1230                                 
1231                                 uiBlockBeginAlign(block);
1232                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Plane:",*xco+175, *yco-104,40,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1233                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",       *xco+215, *yco-104,20,18, &data->plane, 12.0, 0.0, 0, 0, "Keep X axis");
1234                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",       *xco+235, *yco-104,20,18, &data->plane, 12.0, 2.0, 0, 0, "Keep Z axis");
1235                                 uiBlockEndAlign(block);
1236                                 }
1237                         break;
1238                 case CONSTRAINT_TYPE_LOCLIMIT:
1239                         {
1240                                 bLocLimitConstraint *data = con->data;
1241                                 
1242                                 int togButWidth = 50;
1243                                 int textButWidth = ((width/2)-togButWidth);
1244                                 
1245                                 height = 106; 
1246                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1247                                 
1248                                 /* Draw Pairs of LimitToggle+LimitValue */
1249                                 uiBlockBeginAlign(block); 
1250                                         uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "minX", *xco, *yco-28, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x value"); 
1251                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-28, (textButWidth-5), 18, &(data->xmin), -1000, 1000, 0.1,0.5,"Lowest x value to allow"); 
1252                                 uiBlockEndAlign(block); 
1253                                 
1254                                 uiBlockBeginAlign(block); 
1255                                         uiDefButBitS(block, TOG, LIMIT_XMAX, B_CONSTRAINT_TEST, "maxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-28, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum x value"); 
1256                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-28, (textButWidth-5), 18, &(data->xmax), -1000, 1000, 0.1,0.5,"Highest x value to allow"); 
1257                                 uiBlockEndAlign(block); 
1258                                 
1259                                 uiBlockBeginAlign(block); 
1260                                         uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "minY", *xco, *yco-50, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y value"); 
1261                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-50, (textButWidth-5), 18, &(data->ymin), -1000, 1000, 0.1,0.5,"Lowest y value to allow"); 
1262                                 uiBlockEndAlign(block);
1263                                 
1264                                 uiBlockBeginAlign(block); 
1265                                         uiDefButBitS(block, TOG, LIMIT_YMAX, B_CONSTRAINT_TEST, "maxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-50, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum y value"); 
1266                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-50, (textButWidth-5), 18, &(data->ymax), -1000, 1000, 0.1,0.5,"Highest y value to allow"); 
1267                                 uiBlockEndAlign(block); 
1268                                 
1269                                 uiBlockBeginAlign(block); 
1270                                         uiDefButBitS(block, TOG, LIMIT_ZMIN, B_CONSTRAINT_TEST, "minZ", *xco, *yco-72, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z value"); 
1271                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-72, (textButWidth-5), 18, &(data->zmin), -1000, 1000, 0.1,0.5,"Lowest z value to allow"); 
1272                                 uiBlockEndAlign(block);
1273                                 
1274                                 uiBlockBeginAlign(block); 
1275                                         uiDefButBitS(block, TOG, LIMIT_ZMAX, B_CONSTRAINT_TEST, "maxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-72, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum z value"); 
1276                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-72, (textButWidth-5), 18, &(data->zmax), -1000, 1000, 0.1,0.5,"Highest z value to allow"); 
1277                                 uiBlockEndAlign(block);
1278                                 
1279                                 /* constraint space settings */
1280                                 draw_constraint_spaceselect(block, con, *xco, *yco-100, is_armature_owner(ob), -1);
1281                         }
1282                         break;
1283                 case CONSTRAINT_TYPE_ROTLIMIT:
1284                         {
1285                                 bRotLimitConstraint *data = con->data;
1286                                 int normButWidth = (width/3);
1287                                 
1288                                 height = 106; 
1289                                 
1290                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1291                                 
1292                                 /* Draw Pairs of LimitToggle+LimitValue */
1293                                 uiBlockBeginAlign(block); 
1294                                         uiDefButBitS(block, TOG, LIMIT_XROT, B_CONSTRAINT_TEST, "LimitX", *xco, *yco-28, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Limit rotation on x-axis"); 
1295                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min:", *xco+normButWidth, *yco-28, normButWidth, 18, &(data->xmin), -360, 360, 0.1,0.5,"Lowest x value to allow"); 
1296                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max:", *xco+(normButWidth * 2), *yco-28, normButWidth, 18, &(data->xmax), -360, 360, 0.1,0.5,"Highest x value to allow"); 
1297                                 uiBlockEndAlign(block); 
1298                                 
1299                                 uiBlockBeginAlign(block); 
1300                                         uiDefButBitS(block, TOG, LIMIT_YROT, B_CONSTRAINT_TEST, "LimitY", *xco, *yco-50, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Limit rotation on y-axis"); 
1301                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min:", *xco+normButWidth, *yco-50, normButWidth, 18, &(data->ymin), -360, 360, 0.1,0.5,"Lowest y value to allow"); 
1302                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max:", *xco+(normButWidth * 2), *yco-50, normButWidth, 18, &(data->ymax), -360, 360, 0.1,0.5,"Highest y value to allow"); 
1303                                 uiBlockEndAlign(block); 
1304                                 
1305                                 uiBlockBeginAlign(block); 
1306                                         uiDefButBitS(block, TOG, LIMIT_ZROT, B_CONSTRAINT_TEST, "LimitZ", *xco, *yco-72, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Limit rotation on z-axis"); 
1307                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min:", *xco+normButWidth, *yco-72, normButWidth, 18, &(data->zmin), -360, 360, 0.1,0.5,"Lowest z value to allow"); 
1308                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max:", *xco+(normButWidth * 2), *yco-72, normButWidth, 18, &(data->zmax), -360, 360, 0.1,0.5,"Highest z value to allow"); 
1309                                 uiBlockEndAlign(block); 
1310                                 
1311                                 /* constraint space settings */
1312                                 draw_constraint_spaceselect(block, con, *xco, *yco-100, is_armature_owner(ob), -1);
1313                         }
1314                         break;
1315                 case CONSTRAINT_TYPE_SIZELIMIT:
1316                         {
1317                                 bSizeLimitConstraint *data = con->data;
1318                                 
1319                                 int togButWidth = 50;
1320                                 int textButWidth = ((width/2)-togButWidth);
1321                                 
1322                                 height = 106; 
1323                                         
1324                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1325                                 
1326                                 /* Draw Pairs of LimitToggle+LimitValue */
1327                                 uiBlockBeginAlign(block); 
1328                                         uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "minX", *xco, *yco-28, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x value"); 
1329                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-28, (textButWidth-5), 18, &(data->xmin), 0.0001, 1000, 0.1,0.5,"Lowest x value to allow"); 
1330                                 uiBlockEndAlign(block); 
1331                                 
1332                                 uiBlockBeginAlign(block); 
1333                                         uiDefButBitS(block, TOG, LIMIT_XMAX, B_CONSTRAINT_TEST, "maxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-28, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum x value"); 
1334                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-28, (textButWidth-5), 18, &(data->xmax), 0.0001, 1000, 0.1,0.5,"Highest x value to allow"); 
1335                                 uiBlockEndAlign(block); 
1336                                 
1337                                 
1338                                 uiBlockBeginAlign(block); 
1339                                         uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "minY", *xco, *yco-50, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y value"); 
1340                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-50, (textButWidth-5), 18, &(data->ymin), 0.0001, 1000, 0.1,0.5,"Lowest y value to allow"); 
1341                                 uiBlockEndAlign(block); 
1342                                 
1343                                 uiBlockBeginAlign(block); 
1344                                         uiDefButBitS(block, TOG, LIMIT_YMAX, B_CONSTRAINT_TEST, "maxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-50, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum y value"); 
1345                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-50, (textButWidth-5), 18, &(data->ymax), 0.0001, 1000, 0.1,0.5,"Highest y value to allow"); 
1346                                 uiBlockEndAlign(block); 
1347                                 
1348                                 
1349                                 uiBlockBeginAlign(block); 
1350                                         uiDefButBitS(block, TOG, LIMIT_ZMIN, B_CONSTRAINT_TEST, "minZ", *xco, *yco-72, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z value"); 
1351                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-72, (textButWidth-5), 18, &(data->zmin), 0.0001, 1000, 0.1,0.5,"Lowest z value to allow"); 
1352                                 uiBlockEndAlign(block); 
1353                                 
1354                                 uiBlockBeginAlign(block); 
1355                                         uiDefButBitS(block, TOG, LIMIT_ZMAX, B_CONSTRAINT_TEST, "maxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-72, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum z value"); 
1356                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-72, (textButWidth-5), 18, &(data->zmax), 0.0001, 1000, 0.1,0.5,"Highest z value to allow"); 
1357                                 uiBlockEndAlign(block);
1358                                 
1359                                 /* constraint space settings */
1360                                 draw_constraint_spaceselect(block, con, *xco, *yco-100, is_armature_owner(ob), -1);
1361                         }
1362                         break;
1363                 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1364                         {
1365                                 bRigidBodyJointConstraint *data = con->data;
1366                                 float extremeLin = 999.f;
1367                                 float extremeAngX = 180.f;
1368                                 float extremeAngY = 45.f;
1369                                 float extremeAngZ = 45.f;
1370                                 int togButWidth = 70;
1371                                 int offsetY = 150;
1372                                 int textButWidth = ((width/2)-togButWidth);
1373                                 
1374                                 uiDefButI(block, MENU, B_CONSTRAINT_TEST, "Joint Types%t|Ball%x1|Hinge%x2|Cone Twist%x4|Generic (experimental)%x12",//|Extra Force%x6",
1375                                                                                                 *xco, *yco-25, 150, 18, &data->type, 0, 0, 0, 0, "Choose the joint type");
1376                 height = 140;
1377                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF)
1378                                         height = 270;
1379                                 if (data->type==CONSTRAINT_RB_CONETWIST)
1380                                         height = 200;
1381                                 
1382                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
1383                                 
1384                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "toObject:", *xco, *yco-50, 130, 18, &data->tar, "Child Object");
1385                                 uiDefButBitS(block, TOG, CONSTRAINT_DRAW_PIVOT, B_CONSTRAINT_TEST, "ShowPivot", *xco+135, *yco-50, 130, 18, &data->flag, 0, 24, 0, 0, "Show pivot position and rotation");                              
1386                                 
1387                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -1000, 1000, 100, 0.0, "Offset pivot on X");
1388                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Y:", *xco, *yco-100, 130, 18, &data->pivY, -1000, 1000, 100, 0.0, "Offset pivot on Y");
1389                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Z:", *xco, *yco-125, 130, 18, &data->pivZ, -1000, 1000, 100, 0.0, "Offset pivot on z");
1390                                 
1391                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax X:", *xco+135, *yco-75, 130, 18, &data->axX, -360, 360, 1500, 0.0, "Rotate pivot on X Axis (in degrees)");
1392                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Y:", *xco+135, *yco-100, 130, 18, &data->axY, -360, 360, 1500, 0.0, "Rotate pivot on Y Axis (in degrees)");
1393                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Z:", *xco+135, *yco-125, 130, 18, &data->axZ, -360, 360, 1500, 0.0, "Rotate pivot on Z Axis (in degrees)");
1394                                 
1395                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF) {
1396                                         /* Draw Pairs of LimitToggle+LimitValue */
1397                                         uiBlockBeginAlign(block); 
1398                                                 uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1399                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"min x limit"); 
1400                                         uiBlockEndAlign(block);
1401                                         
1402                                         uiBlockBeginAlign(block); 
1403                                                 uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMaxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit"); 
1404                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"max x limit"); 
1405                                         uiBlockEndAlign(block);
1406                                         
1407                                         offsetY += 20;
1408                                         uiBlockBeginAlign(block); 
1409                                                 uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1410                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"min y limit"); 
1411                                         uiBlockEndAlign(block);
1412                                         
1413                                         uiBlockBeginAlign(block); 
1414                                                 uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMaxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit"); 
1415                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"max y limit"); 
1416                                         uiBlockEndAlign(block);
1417                                         
1418                                         offsetY += 20;
1419                                         uiBlockBeginAlign(block); 
1420                                                 uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1421                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"min z limit"); 
1422                                         uiBlockEndAlign(block);
1423                                         
1424                                         uiBlockBeginAlign(block); 
1425                                                 uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMaxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit"); 
1426                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"max z limit"); 
1427                                         uiBlockEndAlign(block);
1428                                         offsetY += 20;
1429                                 }
1430                                 if ((data->type==CONSTRAINT_RB_GENERIC6DOF) || (data->type==CONSTRAINT_RB_CONETWIST)) {
1431                                         /* Draw Pairs of LimitToggle+LimitValue */
1432                                         uiBlockBeginAlign(block); 
1433                                                 uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1434                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"min x limit"); 
1435                                         uiBlockEndAlign(block);
1436                                         uiBlockBeginAlign(block); 
1437                                                 uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMaxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit"); 
1438                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"max x limit"); 
1439                                         uiBlockEndAlign(block);
1440                                         
1441                                         offsetY += 20;
1442                                         uiBlockBeginAlign(block); 
1443                                                 uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1444                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"min y limit"); 
1445                                         uiBlockEndAlign(block);
1446                                         
1447                                         uiBlockBeginAlign(block); 
1448                                                 uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMaxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit"); 
1449                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"max y limit"); 
1450                                         uiBlockEndAlign(block);
1451                                         
1452                                         offsetY += 20;
1453                                         uiBlockBeginAlign(block); 
1454                                                 uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1455                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"min z limit"); 
1456                                         uiBlockEndAlign(block);
1457                                         
1458                                         uiBlockBeginAlign(block); 
1459                                                 uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMaxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit"); 
1460                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"max z limit"); 
1461                                         uiBlockEndAlign(block);
1462                                 }
1463                         }
1464                         break;
1465                 case CONSTRAINT_TYPE_CLAMPTO:
1466                         {
1467                                 bClampToConstraint *data = con->data;
1468                                 
1469                                 height = 90;
1470                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1471                                 
1472                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1473                                 
1474                                 /* Draw target parameters */
1475                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1476                                 
1477                                 /* Draw XYZ toggles */
1478                                 uiBlockBeginAlign(block);
1479                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Main Axis:", *xco, *yco-64, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1480                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST, "Auto", *xco+100, *yco-64, 50, 18, &data->flag, 12.0, CLAMPTO_AUTO, 0, 0, "Automatically determine main-axis of movement");
1481                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST, "X", *xco+150, *yco-64, 32, 18, &data->flag, 12.0, CLAMPTO_X, 0, 0, "Main axis of movement is x-axis");
1482                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST, "Y", *xco+182, *yco-64, 32, 18, &data->flag, 12.0, CLAMPTO_Y, 0, 0, "Main axis of movement is y-axis");
1483                                         uiDefButI(block, ROW, B_CONSTRAINT_TEST, "Z", *xco+214, *yco-64, 32, 18, &data->flag, 12.0, CLAMPTO_Z, 0, 0, "Main axis of movement is z-axis");
1484                                 uiBlockEndAlign(block);
1485                                 
1486                                 /* Extra Options Controlling Behaviour */
1487                                 //uiBlockBeginAlign(block);
1488                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Options:", *xco, *yco-88, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1489                                         uiDefButBitI(block, TOG, CLAMPTO_CYCLIC, B_CONSTRAINT_TEST, "Cyclic", *xco+((width/2)), *yco-88,60,19, &data->flag2, 0, 0, 0, 0, "Treat curve as cyclic curve (no clamping to curve bounding box)");
1490                                 //uiBlockEndAlign(block);
1491                         }
1492                         break;
1493                 case CONSTRAINT_TYPE_TRANSFORM:
1494                         {
1495                                 bTransformConstraint *data = con->data;
1496                                 float fmin, fmax, tmin, tmax;
1497                                 
1498                                 height = 178;
1499                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1500                                 
1501                                 /* Draw target parameters */                    
1502                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1503                                 
1504                                 /* Draw target parameters */
1505                                 uiBlockBeginAlign(block);
1506                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object to use as Parent"); 
1507                                         
1508                                         if (is_armature_target(data->tar)) {
1509                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone to use as Parent");
1510                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1511                                         }
1512                                         else if (is_geom_target(data->tar)) {
1513                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-66,150,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1514                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1515                                         }
1516                                         else {
1517                                                 strcpy(data->subtarget, "");
1518                                         }
1519                                 uiBlockEndAlign(block);
1520                                 
1521                                 /* Extrapolate Ranges? */
1522                                 uiDefButBitC(block, TOG, 1, B_CONSTRAINT_TEST, "Extrapolate", *xco, *yco-42,80,19, &data->expo, 0, 0, 0, 0, "Extrapolate ranges");
1523                                 
1524                                 /* Draw options for source motion */
1525                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Source:", *xco-10, *yco-62, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1526                                 
1527                                 /*      draw Loc/Rot/Size toggles       */
1528                                 uiBlockBeginAlign(block);
1529                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Loc", *xco-5, *yco-82, 45, 18, &data->from, 12.0, 0, 0, 0, "Use Location transform channels from Target");
1530                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Rot", *xco+40, *yco-82, 45, 18, &data->from, 12.0, 1, 0, 0, "Use Rotation transform channels from Target");
1531                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Scale", *xco+85, *yco-82, 45, 18, &data->from, 12.0, 2, 0, 0, "Use Scale transform channels from Target");
1532                                 uiBlockEndAlign(block);
1533                                 
1534                                 /* Draw Pairs of Axis: Min/Max Value*/
1535                                 if (data->from == 2) {
1536                                         fmin= 0.0001;
1537                                         fmax= 1000.0;
1538                                 }
1539                                 else if (data->from == 1) {
1540                                         fmin= -360.0;
1541                                         fmax= 360.0;
1542                                 }
1543                                 else {
1544                                         fmin = -1000.0;
1545                                         fmax= 1000.0;
1546                                 }
1547                                 
1548                                 uiBlockBeginAlign(block); 
1549                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "X:", *xco-10, *yco-107, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1550                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+20, *yco-107, 55, 18, &data->from_min[0], fmin, fmax, 0, 0, "Bottom of range of x-axis source motion for source->target mapping"); 
1551                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+75, *yco-107, 55, 18, &data->from_max[0], fmin, fmax, 0, 0, "Top of range of x-axis source motion for source->target mapping"); 
1552                                 uiBlockEndAlign(block); 
1553                                 
1554                                 uiBlockBeginAlign(block); 
1555                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Y:", *xco-10, *yco-127, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1556                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+20, *yco-127, 55, 18, &data->from_min[1], fmin, fmax, 0, 0, "Bottom of range of y-axis source motion for source->target mapping"); 
1557                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+75, *yco-127, 55, 18, &data->from_max[1], fmin, fmax, 0, 0, "Top of range of y-axis source motion for source->target mapping"); 
1558                                 uiBlockEndAlign(block);
1559                                 
1560                                 uiBlockBeginAlign(block); 
1561                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Z:", *xco-10, *yco-147, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1562                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+20, *yco-147, 55, 18, &data->from_min[2], fmin, fmax, 0, 0, "Bottom of range of z-axis source motion for source->target mapping"); 
1563                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+75, *yco-147, 55, 18, &data->from_max[2], fmin, fmax, 0, 0, "Top of range of z-axis source motion for source->target mapping"); 
1564                                 uiBlockEndAlign(block); 
1565                                 
1566                                 
1567                                 /* Draw options for target motion */
1568                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Destination:", *xco+150, *yco-62, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1569                                 
1570                                 /*      draw Loc/Rot/Size toggles       */
1571                                 uiBlockBeginAlign(block);
1572                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Loc", *xco+150, *yco-82, 45, 18, &data->to, 12.0, 0, 0, 0, "Use as Location transform");
1573                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Rot", *xco+195, *yco-82, 45, 18, &data->to, 12.0, 1, 0, 0, "Use as Rotation transform");
1574                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Scale", *xco+245, *yco-82, 45, 18, &data->to, 12.0, 2, 0, 0, "Use as Scale transform");
1575                                 uiBlockEndAlign(block);
1576                                 
1577                                 /* Draw Pairs of Source-Axis: Min/Max Value*/
1578                                 if (data->to == 2) {
1579                                         tmin= 0.0001;
1580                                         tmax= 1000.0;
1581                                 }
1582                                 else if (data->to == 1) {
1583                                         tmin= -360.0;
1584                                         tmax= 360.0;
1585                                 }
1586                                 else {
1587                                         tmin = -1000.0;
1588                                         tmax= 1000.0;
1589                                 }
1590                                 
1591                                 uiBlockBeginAlign(block); 
1592                                         uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Axis Mapping%t|X->X%x0|Y->X%x1|Z->X%x2", *xco+150, *yco-107, 40, 18, &data->map[0], 0, 24, 0, 0, "Specify which source axis the x-axis destination uses");
1593                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+175, *yco-107, 50, 18, &data->to_min[0], tmin, tmax, 0, 0, "Bottom of range of x-axis destination motion for source->target mapping"); 
1594                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+240, *yco-107, 50, 18, &data->to_max[0], tmin, tmax, 0, 0, "Top of range of x-axis destination motion for source->target mapping"); 
1595                                 uiBlockEndAlign(block); 
1596                                 
1597                                 uiBlockBeginAlign(block); 
1598                                         uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Axis Mapping%t|X->Y%x0|Y->Y%x1|Z->Y%x2", *xco+150, *yco-127, 40, 18, &data->map[1], 0, 24, 0, 0, "Specify which source axis the y-axis destination uses");
1599                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+175, *yco-127, 50, 18, &data->to_min[1], tmin, tmax, 0, 0, "Bottom of range of y-axis destination motion for source->target mapping"); 
1600                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+240, *yco-127, 50, 18, &data->to_max[1], tmin, tmax, 0, 0, "Top of range of y-axis destination motion for source->target mapping"); 
1601                                 uiBlockEndAlign(block);
1602                                 
1603                                 uiBlockBeginAlign(block); 
1604                                         uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Axis Mapping%t|X->Z%x0|Y->Z%x1|Z->Z%x2", *xco+150, *yco-147, 40, 18, &data->map[2], 0, 24, 0, 0, "Specify which source axis the z-axis destination uses");
1605                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+175, *yco-147, 50, 18, &data->to_min[2], tmin, tmax, 0, 0, "Bottom of range of z-axis destination motion for source->target mapping"); 
1606                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+240, *yco-147, 50, 18, &data->to_max[2], tmin, tmax, 0, 0, "Top of range of z-axis destination motion for source->target mapping"); 
1607                                 uiBlockEndAlign(block); 
1608                                 
1609                                 /* constraint space settings */
1610                                 draw_constraint_spaceselect(block, con, *xco, *yco-170, is_armature_owner(ob), is_armature_target(data->tar));
1611                         }
1612                         break;
1613                 case CONSTRAINT_TYPE_NULL:
1614                         {
1615                                 height = 17;
1616                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1617                         }
1618                         break;
1619                 default:
1620                         height = 0;
1621                         break;
1622                 }
1623                 
1624                 (*yco)-=(24+height);
1625         }
1626
1627         if (ELEM(con->type, CONSTRAINT_TYPE_NULL, CONSTRAINT_TYPE_RIGIDBODYJOINT)==0) {
1628                 uiBlockBeginAlign(block);
1629                 uiDefButF(block, NUMSLI, B_CONSTRAINT_INF, "Influence ", *xco, *yco, 197, 20, &(con->enforce), 0.0, 1.0, 0.0, 0.0, "Amount of influence this constraint will have on the final solution");
1630                 but = uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Show", *xco+200, *yco, 45, 20, 0, 0.0, 1.0, 0.0, 0.0, "Show constraint's ipo in the Ipo window, adds a channel if not there");
1631                 /* If this is on an object or bone, add ipo channel the constraint */
1632                 uiButSetFunc (but, enable_constraint_ipo_func, ob, con);
1633                 but = uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Key", *xco+245, *yco, 40, 20, 0, 0.0, 1.0, 0.0, 0.0, "Add an influence keyframe to the constraint");
1634                 /* Add a keyframe to the influence IPO */
1635                 uiButSetFunc (but, add_influence_key_to_constraint_func, ob, con);
1636                 uiBlockEndAlign(block);
1637                 (*yco)-=24;
1638         } 
1639         else {
1640                 (*yco)-=3;
1641         }
1642 }
1643
1644 static uiBlock *add_constraintmenu(void *arg_unused)
1645 {
1646         Object *ob= OBACT;
1647         uiBlock *block;
1648         ListBase *conlist;
1649         short yco= 0;
1650         
1651         conlist = get_active_constraints(ob);
1652         
1653         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1654
1655         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_CHILDOF, "Child Of",                     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1656         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRANSFORM, "Transformation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1657         
1658         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1659         
1660         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIKE, "Copy Location", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1661         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIKE, "Copy Rotation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1662         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIKE, "Copy Scale", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1663         
1664         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1665         
1666         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIMIT, "Limit Location", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1667         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIMIT, "Limit Rotation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1668         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIMIT, "Limit Scale", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1669         
1670         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1671         
1672         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRACKTO, "Track To",     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1673         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_MINMAX, "Floor", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1674         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCKTRACK, "Locked Track", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1675         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_FOLLOWPATH, "Follow Path", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1676                 
1677         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1678         
1679         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_CLAMPTO, "Clamp To", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1680         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_STRETCHTO, "Stretch To", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1681
1682         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_RIGIDBODYJOINT, "Rigid Body Joint", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");//rcruiz
1683
1684         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1685         
1686         if (ob->flag & OB_POSEMODE) {
1687                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_KINEMATIC, "IK Solver", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1688         }
1689         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ACTION, "Action", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1690         
1691         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1692
1693         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_PYTHON, "Script", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1694         
1695         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1696         
1697         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_NULL, "Null",    0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1698         
1699         
1700         uiTextBoundsBlock(block, 50);
1701         uiBlockSetDirection(block, UI_DOWN);
1702                 
1703         return block;
1704 }
1705
1706 void do_constraintbuts(unsigned short event)
1707 {
1708         Object *ob= OBACT;
1709         bConstraint *con;
1710         
1711         switch(event) {
1712         case B_CONSTRAINT_TEST:
1713                 break;  // no handling
1714         case B_CONSTRAINT_INF:
1715                 /* influence; do not execute actions for 1 dag_flush */
1716                 if (ob->pose)
1717                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
1718
1719         case B_CONSTRAINT_CHANGETARGET:
1720                 if (ob->pose) ob->pose->flag |= POSE_RECALC;    // checks & sorts pose channels
1721                 DAG_scene_sort(G.scene);
1722                 break;
1723         
1724         case B_CONSTRAINT_ADD_NULL:
1725                 {
1726                         con = add_new_constraint(CONSTRAINT_TYPE_NULL);
1727                         add_constraint_to_active(ob, con);
1728                         
1729                         BIF_undo_push("Add constraint");
1730                 }
1731                 break;
1732         case B_CONSTRAINT_ADD_PYTHON:
1733                 {
1734                         con = add_new_constraint(CONSTRAINT_TYPE_PYTHON);
1735                         add_constraint_to_active(ob, con);
1736                         
1737                         BIF_undo_push("Add constraint");
1738                 }
1739                 break;  
1740         case B_CONSTRAINT_ADD_KINEMATIC:
1741                 {
1742                         con = add_new_constraint(CONSTRAINT_TYPE_KINEMATIC);
1743                         add_constraint_to_active(ob, con);
1744                         
1745                         BIF_undo_push("Add constraint");
1746                 }
1747                 break;
1748         case B_CONSTRAINT_ADD_CHILDOF:
1749                 {
1750                         con= add_new_constraint(CONSTRAINT_TYPE_CHILDOF);
1751                         add_constraint_to_active(ob, con);
1752                         
1753                         /* if this constraint is being added to a posechannel, make sure
1754                          * the constraint gets evaluated in pose-space
1755                          */
1756                         if (ob->flag & OB_POSEMODE) {
1757                                 con->ownspace = CONSTRAINT_SPACE_POSE;
1758                                 con->flag |= CONSTRAINT_SPACEONCE;
1759                         }
1760                         
1761                         BIF_undo_push("Add constraint");
1762                 }
1763                 break;
1764         case B_CONSTRAINT_ADD_TRACKTO:
1765                 {
1766                         con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
1767                         add_constraint_to_active(ob, con);
1768                         
1769                         BIF_undo_push("Add constraint");
1770                 }
1771                 break;
1772         case B_CONSTRAINT_ADD_MINMAX:
1773                 {
1774                         con = add_new_constraint(CONSTRAINT_TYPE_MINMAX);
1775                         add_constraint_to_active(ob, con);
1776                         
1777                         BIF_undo_push("Add constraint");
1778                 }
1779                 break;
1780         case B_CONSTRAINT_ADD_ROTLIKE:
1781                 {
1782                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIKE);
1783                         add_constraint_to_active(ob, con);
1784                         
1785                         BIF_undo_push("Add constraint");
1786                 }
1787                 break;
1788         case B_CONSTRAINT_ADD_LOCLIKE:
1789                 {
1790                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIKE);
1791                         add_constraint_to_active(ob, con);
1792                         
1793                         BIF_undo_push("Add constraint");
1794                 }
1795                 break;
1796         case B_CONSTRAINT_ADD_SIZELIKE:
1797                 {
1798                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIKE);
1799                         add_constraint_to_active(ob, con);
1800                         
1801                         BIF_undo_push("Add constraint");
1802                 }
1803                 break;
1804         case B_CONSTRAINT_ADD_ACTION:
1805                 {
1806                         con = add_new_constraint(CONSTRAINT_TYPE_ACTION);
1807                         add_constraint_to_active(ob, con);
1808                         
1809                         BIF_undo_push("Add constraint");
1810                 }
1811                 break;
1812         case B_CONSTRAINT_ADD_LOCKTRACK:
1813                 {
1814                         con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
1815                         add_constraint_to_active(ob, con);
1816                         
1817                         BIF_undo_push("Add constraint");
1818                 }
1819                 break;
1820         case B_CONSTRAINT_ADD_FOLLOWPATH:
1821                 {
1822                         con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1823                         add_constraint_to_active(ob, con);
1824                         
1825                         BIF_undo_push("Add constraint");
1826                 }
1827                 break;
1828         case B_CONSTRAINT_ADD_STRETCHTO:
1829                 {
1830                         con = add_new_constraint(CONSTRAINT_TYPE_STRETCHTO);
1831                         add_constraint_to_active(ob, con);
1832                         
1833                         BIF_undo_push("Add constraint");
1834                 }
1835                 break;
1836         case B_CONSTRAINT_ADD_LOCLIMIT:
1837                 {
1838                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIMIT);
1839                         add_constraint_to_active(ob, con);
1840                         
1841                         BIF_undo_push("Add constraint");
1842                 }
1843                 break;
1844         case B_CONSTRAINT_ADD_ROTLIMIT:
1845                 {
1846                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIMIT);
1847                         add_constraint_to_active(ob, con);
1848                         
1849                         BIF_undo_push("Add constraint");
1850                 }
1851                 break;
1852         case B_CONSTRAINT_ADD_SIZELIMIT:
1853                 {
1854                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIMIT);
1855                         add_constraint_to_active(ob, con);
1856                         
1857                         BIF_undo_push("Add constraint");
1858                 }
1859                 break;
1860         case B_CONSTRAINT_ADD_RIGIDBODYJOINT:
1861                 {
1862                         bRigidBodyJointConstraint *data;
1863                         Base *base_iter;
1864                         
1865                         con = add_new_constraint(CONSTRAINT_TYPE_RIGIDBODYJOINT);
1866                         add_constraint_to_active(ob, con);
1867                         
1868                         /* set selected first object as target - moved from new_constraint_data */
1869                         data = (bRigidBodyJointConstraint*)con->data;
1870                         base_iter = G.scene->base.first;
1871             while ( base_iter && !data->tar ) {
1872                 if( ( ( base_iter->flag & SELECT ) &&
1873 //                     ( base_iter->lay & G.vd->lay ) ) &&
1874                     ( base_iter != G.scene->basact ) ))
1875                                 {
1876                         data->tar=base_iter->object;
1877                                                 break;
1878                                 }
1879                 base_iter = base_iter->next;
1880             }
1881                         
1882                         BIF_undo_push("Add constraint");
1883                 }
1884                 break;
1885         case B_CONSTRAINT_ADD_CLAMPTO:
1886                 {
1887                         con = add_new_constraint(CONSTRAINT_TYPE_CLAMPTO);
1888                         add_constraint_to_active(ob, con);
1889                         
1890                         BIF_undo_push("Add constraint");
1891                 }
1892                 break;
1893         case B_CONSTRAINT_ADD_TRANSFORM:
1894                 {
1895                         con = add_new_constraint(CONSTRAINT_TYPE_TRANSFORM);
1896                         add_constraint_to_active(ob, con);
1897                         
1898                         BIF_undo_push("Add constraint");
1899                 }
1900                 break;
1901
1902         default:
1903                 break;
1904         }
1905
1906         object_test_constraints(ob);
1907         
1908         if(ob->pose) update_pose_constraint_flags(ob->pose);
1909         
1910         if(ob->type==OB_ARMATURE) DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA|OB_RECALC_OB);
1911         else DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1912         
1913         allqueue (REDRAWVIEW3D, 0);
1914         allqueue (REDRAWBUTSOBJECT, 0);
1915 }
1916
1917 void softbody_bake(Object *ob)
1918 {
1919         Base *base;
1920         SoftBody *sb;
1921         ScrArea *sa;
1922         float frameleno= G.scene->r.framelen;
1923         int cfrao= CFRA, sfra=100000, efra=0, didbreak =0;
1924         
1925         
1926         G.scene->r.framelen= 1.0;               // baking has to be in uncorrected time
1927         sbSetInterruptCallBack(blender_test_break); // make softbody module ESC aware
1928         G.afbreek=0; // init global break system
1929         
1930         if(ob) {
1931                 sb= ob->soft;
1932                 sfra= MIN2(sfra, sb->sfra);
1933                 efra= MAX2(efra, sb->efra);
1934                 sbObjectToSoftbody(ob); // put softbody in restposition, free bake
1935                 ob->softflag |= OB_SB_BAKEDO;
1936         }
1937         else {
1938                 for(base=G.scene->base.first; base; base= base->next) {
1939                         if(TESTBASELIB(base)) {
1940                                 if(base->object->soft) {
1941                                         sb= base->object->soft;
1942                                         sfra= MIN2(sfra, sb->sfra);
1943                                         efra= MAX2(efra, sb->efra);
1944                                         sbObjectToSoftbody(base->object);       // put softbody in restposition, free bake
1945                                         base->object->softflag |= OB_SB_BAKEDO;
1946                                 }
1947                         }
1948                 }
1949         }
1950         
1951         CFRA= sfra;
1952         update_for_newframe_muted();    // put everything on this frame
1953         
1954         curarea->win_swap= 0;           // clean swapbuffers
1955         
1956         for(; CFRA <= efra; CFRA++) {
1957                 set_timecursor(CFRA);
1958                 
1959                 update_for_newframe_muted();
1960                 
1961                 for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
1962                         if(sa->spacetype == SPACE_VIEW3D) {
1963                                 scrarea_do_windraw(sa);
1964                         }
1965                 }
1966                 screen_swapbuffers();
1967                 //blender_test_break() has a granularity of 10 ms, who cares .. baking the unit cube is kinda boring
1968                 if (blender_test_break()){ 
1969                         didbreak = 1;
1970                         break;
1971                 }
1972
1973         }
1974         if((didbreak)&&(G.qual!=LR_SHIFTKEY)) {
1975                 if(ob) 
1976                         sbObjectToSoftbody(ob); // free bake
1977                 else {
1978                         for(base=G.scene->base.first; base; base= base->next) {
1979                                 if(TESTBASELIB(base)) {
1980                                         if(base->object->soft) {
1981                                                 sbObjectToSoftbody(base->object);       // free bake
1982                                         }
1983                                 }
1984                         }
1985                 }
1986         }
1987         
1988         /* restore */
1989         waitcursor(0);
1990         sbSetInterruptCallBack(NULL); // softbody module won't ESC
1991         G.afbreek=0; // reset global break system
1992         
1993         if(ob) 
1994                 ob->softflag &= ~OB_SB_BAKEDO;
1995         else {
1996                 for(base=G.scene->base.first; base; base= base->next)
1997                         if(TESTBASELIB(base))
1998                                 if(base->object->soft)
1999                                         base->object->softflag &= ~OB_SB_BAKEDO;
2000         }
2001         
2002         CFRA= cfrao;
2003         G.scene->r.framelen= frameleno;
2004         update_for_newframe_muted();
2005         allqueue(REDRAWVIEW3D, 0);
2006         allqueue(REDRAWBUTSOBJECT, 0);
2007 }
2008
2009 // store processed path & file prefix for fluidsim bake directory
2010 void fluidsimFilesel(char *selection)
2011 {
2012         Object *ob = OBACT;
2013         char srcDir[FILE_MAXDIR+FILE_MAXFILE], srcFile[FILE_MAXFILE];
2014         char prefix[FILE_MAXFILE];
2015         char *srch, *srchSub, *srchExt, *lastFound;
2016         int isElbeemSurf = 0;
2017
2018         // make prefix
2019         strcpy(srcDir, selection);
2020         BLI_splitdirstring(srcDir, srcFile);
2021         strcpy(prefix, srcFile);
2022         // check if this is a previously generated surface mesh file
2023         srch = strstr(prefix, "fluidsurface_");
2024         // TODO search from back...
2025         if(srch) {
2026                 srchSub = strstr(prefix,"_preview_");
2027                 if(!srchSub) srchSub = strstr(prefix,"_final_");
2028                 srchExt = strstr(prefix,".gz.bobj");
2029                 if(!srchExt) srchExt = strstr(prefix,".bobj");
2030                 if(srchSub && srchExt) {
2031                         *srch = '\0';
2032                         isElbeemSurf = 1;
2033                 }
2034         }
2035         if(!isElbeemSurf) {
2036                 // try to remove suffix
2037                 lastFound = NULL;
2038                 srch = strchr(prefix, '.'); // search last . from extension
2039                 while(srch) {
2040                         lastFound = srch;
2041                         if(srch) {
2042                                 srch++;
2043                                 srch = strchr(srch, '.');
2044                         }
2045                 }
2046                 if(lastFound) {
2047                         *lastFound = '\0';
2048                 } 
2049         }
2050
2051         if(ob->fluidsimSettings) {
2052                 strcpy(ob->fluidsimSettings->surfdataPath, srcDir);
2053                 //not necessary? strcat(ob->fluidsimSettings->surfdataPath, "/");
2054                 strcat(ob->fluidsimSettings->surfdataPath, prefix);
2055
2056                 // redraw view & buttons...
2057                 allqueue(REDRAWBUTSOBJECT, 0);
2058                 allqueue(REDRAWVIEW3D, 0);
2059                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2060         }
2061 }
2062
2063 void do_object_panels(unsigned short event)
2064 {
2065         Object *ob;
2066         Effect *eff;
2067         
2068         ob= OBACT;
2069         if(ob==NULL)
2070                 return;
2071         
2072         switch(event) {
2073         case B_TRACKBUTS:
2074                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2075                 allqueue(REDRAWVIEW3D, 0);
2076                 break;
2077         case B_RECALCPATH:
2078                 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
2079                 allqueue(REDRAWVIEW3D, 0);
2080                 break;
2081         case B_DUPLI_FRAME:
2082                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFACES|OB_DUPLIGROUP);
2083                 allqueue(REDRAWVIEW3D, 0);
2084                 allqueue(REDRAWBUTSOBJECT, 0);
2085                 break;
2086         case B_DUPLI_VERTS:
2087                 ob->transflag &= ~(OB_DUPLIFRAMES|OB_DUPLIFACES|OB_DUPLIGROUP);
2088                 DAG_scene_sort(G.scene);
2089                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2090                 allqueue(REDRAWVIEW3D, 0);
2091                 allqueue(REDRAWBUTSOBJECT, 0);
2092                 break;
2093         case B_DUPLI_FACES:
2094                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIGROUP);
2095                 allqueue(REDRAWVIEW3D, 0);
2096                 allqueue(REDRAWBUTSOBJECT, 0);
2097                 break;
2098         case B_DUPLI_GROUP:
2099                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIFACES);
2100                 allqueue(REDRAWVIEW3D, 0);
2101                 allqueue(REDRAWBUTSOBJECT, 0);
2102                 break;
2103                 
2104         case B_PRINTSPEED:
2105                 {
2106                         float vec[3];
2107                         CFRA++;
2108                         do_ob_ipo(ob);
2109                         where_is_object(ob);
2110                         VECCOPY(vec, ob->obmat[3]);
2111                         CFRA--;
2112                         do_ob_ipo(ob);
2113                         where_is_object(ob);
2114                         VecSubf(vec, vec, ob->obmat[3]);
2115                         prspeed= Normalize(vec);
2116                         scrarea_queue_winredraw(curarea);
2117                 }
2118                 break;
2119         case B_PRINTLEN:
2120                 if(ob->type==OB_CURVE) {
2121                         Curve *cu=ob->data;
2122                         
2123                         if(cu->path) prlen= cu->path->totdist; else prlen= -1.0;
2124                         scrarea_queue_winredraw(curarea);
2125                 } 
2126                 break;
2127         case B_RELKEY:
2128                 allspace(REMAKEIPO, 0);
2129                 allqueue(REDRAWBUTSOBJECT, 0);
2130                 allqueue(REDRAWBUTSEDIT, 0);
2131                 allqueue(REDRAWIPO, 0);
2132                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2133                 break;
2134         case B_CURVECHECK:
2135                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2136                 allqueue(REDRAWVIEW3D, 0);
2137                 break;
2138         
2139         case B_SOFTBODY_CHANGE:
2140                 ob->softflag |= OB_SB_REDO;
2141                 allqueue(REDRAWBUTSOBJECT, 0);
2142                 allqueue(REDRAWVIEW3D, 0);
2143                 break;
2144         case B_SOFTBODY_DEL_VG:
2145                 if(ob->soft) {
2146                         ob->soft->vertgroup= 0;
2147                         ob->softflag |= OB_SB_REDO;
2148                         allqueue(REDRAWBUTSOBJECT, 0);
2149                         allqueue(REDRAWVIEW3D, 0);
2150                 }
2151                 break;
2152         case B_SOFTBODY_BAKE:
2153                 if(ob->soft) softbody_bake(ob);
2154                 break;
2155         case B_SOFTBODY_BAKE_FREE:
2156                 if(ob->soft) sbObjectToSoftbody(ob);
2157                 allqueue(REDRAWBUTSOBJECT, 0);
2158                 allqueue(REDRAWVIEW3D, 0);
2159                 break;
2160         case B_FLUIDSIM_BAKE:
2161                 /* write config files (currently no simulation) */
2162                 fluidsimBake(ob);
2163                 break;
2164         case B_FLUIDSIM_MAKEPART:
2165                 {
2166                         PartEff *paf= NULL;
2167                         /* prepare fluidsim particle display */
2168                         // simplified delete effect, create new - recalc some particles...
2169                         if(ob==NULL || ob->type!=OB_MESH) break;
2170                         ob->fluidsimSettings->type = 0;
2171                         // reset type, and init particle system once normally
2172                         paf= give_parteff(ob); 
2173                         if( (BLI_countlist(&ob->effect)<MAX_EFFECT) && 
2174                             (!paf)) { 
2175                                 // create new entry
2176                                 copy_act_effect(ob); DAG_scene_sort(G.scene); }
2177                         paf = give_parteff(ob);
2178                         if(paf) {
2179                                 paf->totpart = 1000; paf->sta = paf->end = 1.0; // generate some particles...
2180                                 build_particle_system(ob);
2181                                 ob->fluidsimSettings->type = OB_FLUIDSIM_PARTICLE;
2182                         }
2183                 }
2184                 allqueue(REDRAWVIEW3D, 0);
2185                 allqueue(REDRAWBUTSOBJECT, 0);
2186                 break;
2187         case B_FLUIDSIM_SELDIR: 
2188                 {
2189                         ScrArea *sa = closest_bigger_area();
2190                         /* choose dir for surface files */
2191                         areawinset(sa->win);
2192                         activate_fileselect(FILE_SPECIAL, "Select Directory", ob->fluidsimSettings->surfdataPath, fluidsimFilesel);
2193                 }
2194                 break;
2195         case B_FLUIDSIM_FORCEREDRAW:
2196                 /* force redraw */
2197                 allqueue(REDRAWBUTSOBJECT, 0);
2198                 allqueue(REDRAWVIEW3D, 0);
2199                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2200                 break;
2201         case B_GROUP_RELINK:
2202                 group_relink_nla_objects(ob);
2203                 allqueue(REDRAWVIEW3D, 0);
2204                 break;
2205                 
2206         case B_OBJECT_IPOFLAG:
2207                 if(ob->ipo) ob->ipo->showkey= (ob->ipoflag & OB_DRAWKEY)?1:0;
2208                 allqueue(REDRAWVIEW3D, 0);
2209         case B_CLOTH_CLEARCACHEALL:
2210                 {
2211                         ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
2212                         if(clmd)
2213                         {
2214                                 CFRA= 1;
2215                                 update_for_newframe_muted();
2216                                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
2217                                 cloth_clear_cache(ob, clmd, 2); 
2218                                 allqueue(REDRAWBUTSOBJECT, 0);
2219                                 allqueue(REDRAWVIEW3D, 0);
2220                         }       
2221                 }
2222                 break;  
2223         case B_CLOTH_CLEARCACHEFRAME:
2224                 {
2225                         ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
2226                         if(clmd)
2227                         {
2228                                 cloth_clear_cache(ob, clmd, MAX2(2.0,G.scene->r.cfra+1.0));
2229                                 allqueue(REDRAWBUTSOBJECT, 0);
2230                         }
2231                 }
2232                 break;  
2233         case B_CLOTH_CHANGEPREROLL:
2234                 {
2235                         ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
2236                         if(clmd)
2237                         {
2238                                 /*
2239                                 if(clmd->sim_parms->cache)
2240                                 {
2241                                         CFRA= 1;
2242                                         update_for_newframe_muted();
2243                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
2244                                         allqueue(REDRAWBUTSOBJECT, 0);
2245                                         allqueue(REDRAWVIEW3D, 0);
2246                                 }
2247                                 */
2248                         }
2249                 }
2250                 break;
2251         case B_CLOTH_DEL_VG:
2252                 {
2253                         ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
2254                         if(clmd)
2255                         {
2256                                 clmd->sim_parms->vgroup_mass = 0;
2257                                 do_object_panels(B_CLOTH_RENEW);
2258                         }
2259                         
2260                         allqueue(REDRAWBUTSOBJECT, 0);
2261                 }
2262                 break;  
2263         case B_CLOTH_RENEW:
2264                 {
2265                         ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
2266                         if(clmd)
2267                         {
2268                                 do_object_panels(B_CLOTH_CLEARCACHEALL);
2269                                 cloth_free_modifier (clmd);
2270                         }
2271                 }
2272                 break;
2273         default:
2274                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
2275                         int a=B_SELEFFECT;
2276                         
2277                         eff= ob->effect.first;
2278                         while(eff) {
2279                                 if(event==a) eff->flag |= SELECT;
2280                                 else eff->flag &= ~SELECT;
2281                                 
2282                                 a++;
2283                                 eff= eff->next;
2284                         }
2285                         allqueue(REDRAWBUTSOBJECT, 0);
2286                 }
2287         }
2288
2289 }
2290
2291 static void do_add_groupmenu(void *arg, int event)
2292 {
2293         Object *ob= OBACT;
2294         
2295         if(ob) {
2296                 
2297                 if(event== -1) {
2298                         Group *group= add_group( "Group" );
2299                         add_to_group(group, ob);
2300                 }
2301                 else
2302                         add_to_group(BLI_findlink(&G.main->group, event), ob);
2303                         
2304                 ob->flag |= OB_FROMGROUP;
2305                 BASACT->flag |= OB_FROMGROUP;
2306                 allqueue(REDRAWBUTSOBJECT, 0);
2307                 allqueue(REDRAWVIEW3D, 0);
2308         }               
2309 }
2310
2311 static uiBlock *add_groupmenu(void *arg_unused)
2312 {
2313         uiBlock *block;
2314         Group *group;
2315         short yco= 0;
2316         char str[32];
2317         
2318         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
2319         uiBlockSetButmFunc(block, do_add_groupmenu, NULL);
2320
2321         uiDefBut(block, BUTM, B_NOP, "ADD NEW",         0, 20, 160, 19, NULL, 0.0, 0.0, 1, -1, "");
2322         for(group= G.main->group.first; group; group= group->id.next, yco++) {
2323                 if(group->id.lib) strcpy(str, "L  ");
2324                 else strcpy(str, "   ");
2325                 strcat(str, group->id.name+2);
2326                 uiDefBut(block, BUTM, B_NOP, str,       0, -20*yco, 160, 19, NULL, 0.0, 0.0, 1, yco, "");
2327         }
2328         
2329         uiTextBoundsBlock(block, 50);
2330         uiBlockSetDirection(block, UI_DOWN);    
2331         
2332         return block;
2333 }
2334
2335 static void group_ob_rem(void *gr_v, void *ob_v)
2336 {
2337         Object *ob= OBACT;
2338         
2339         rem_from_group(gr_v, ob);
2340         if(find_group(ob)==NULL) {
2341                 ob->flag &= ~OB_FROMGROUP;
2342                 BASACT->flag &= ~OB_FROMGROUP;
2343         }
2344         allqueue(REDRAWBUTSOBJECT, 0);
2345         allqueue(REDRAWVIEW3D, 0);
2346
2347 }
2348
2349 static void group_local(void *gr_v, void *unused)
2350 {
2351         Group *group= gr_v;
2352         
2353         group->id.lib= NULL;
2354         
2355         allqueue(REDRAWBUTSOBJECT, 0);
2356         allqueue(REDRAWVIEW3D, 0);
2357         
2358 }
2359
2360 static void object_panel_object(Object *ob)
2361 {
2362         uiBlock *block;
2363         uiBut *but;
2364         Group *group;
2365         int a, xco, yco=0;
2366         short dx= 33, dy= 30;
2367
2368         block= uiNewBlock(&curarea->uiblocks, "object_panel_object", UI_EMBOSS, UI_HELV, curarea->win);
2369         if(uiNewPanel(curarea, block, "Object and Links", "Object", 0, 0, 318, 204)==0) return;
2370         
2371         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2372         
2373         /* object name */
2374         uiBlockSetCol(block, TH_BUT_SETTING2);
2375         xco= std_libbuttons(block, 10, 180, 0, NULL, 0, ID_OB, 0, &ob->id, NULL, &(G.buts->menunr), B_OBALONE, B_OBLOCAL, 0, 0, B_KEEPDATA);
2376         uiBlockSetCol(block, TH_AUTO);
2377         
2378         /* parent */
2379         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_OBJECTPANELPARENT, "Par:", xco+5, 180, 305-xco, 20, &ob->parent, "Parent Object"); 
2380         
2381         /* TODO, check for ob->id.lib */
2382         but = uiDefButS(block, NUM, B_NOP, "PassIndex:",                xco+5, 150, 305-xco, 20, &ob->index, 0.0, 1000.0, 0, 0, "Index # for the IndexOB render pass.");
2383
2384         uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group");
2385
2386         /* all groups */
2387         for(group= G.main->group.first; group; group= group->id.next) {
2388                 if(object_in_group(ob, group)) {
2389                         xco= 160;
2390                         
2391                         uiBlockBeginAlign(block);
2392                         but = uiDefBut(block, TEX, B_IDNAME, "GR:",     10, 120-yco, 150, 20, group->id.name+2, 0.0, 21.0, 0, 0, "Displays Group name. Click to change.");
2393                         uiButSetFunc(but, test_idbutton_cb, group->id.name, NULL);
2394                         
2395                         if(group->id.lib) {
2396                                 but= uiDefIconBut(block, BUT, B_NOP, ICON_PARLIB, 160, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Make Group local");
2397                                 uiButSetFunc(but, group_local, group, NULL);
2398                                 xco= 180;
2399                         }
2400                         but = uiDefIconBut(block, BUT, B_NOP, VICON_X, xco, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove Group membership");
2401                         uiButSetFunc(but, group_ob_rem, group, ob);
2402                         
2403                         yco+= 20;
2404                         xco= 10;
2405                         
2406                         /* layers */
2407                         uiBlockBeginAlign(block);
2408                         for(a=0; a<5; a++)
2409                                 uiDefButBitI(block, TOG, 1<<a, REDRAWVIEW3D, "",        (short)(xco+a*(dx/2)), 120-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
2410                         for(a=0; a<5; a++)
2411                                 uiDefButBitI(block, TOG, 1<<(a+10), REDRAWVIEW3D, "",   (short)(xco+a*(dx/2)), 105-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
2412                         
2413                         xco+= 7;
2414                         uiBlockBeginAlign(block);
2415                         for(a=5; a<10; a++)
2416                                 uiDefButBitI(block, TOG, 1<<a, REDRAWVIEW3D, "",        (short)(xco+a*(dx/2)), 120-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
2417                         for(a=5; a<10; a++)
2418                                 uiDefButBitI(block, TOG, 1<<(a+10), REDRAWVIEW3D, "",   (short)(xco+a*(dx/2)), 105-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
2419                         
2420                         uiBlockEndAlign(block);
2421                         
2422                         yco+= 40;
2423                 }
2424         }
2425         
2426         if(120-yco < -10)
2427                 uiNewPanelHeight(block, 204 - (120-yco));
2428 }
2429
2430 static void object_panel_anim(Object *ob)
2431 {
2432         uiBlock *block;
2433         char str[32];
2434         
2435         block= uiNewBlock(&curarea->uiblocks, "object_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
2436         if(uiNewPanel(curarea, block, "Anim settings", "Object", 320, 0, 318, 204)==0) return;
2437         
2438         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2439         
2440         uiBlockBeginAlign(block);
2441         uiDefButS(block, ROW,B_TRACKBUTS,"TrackX",      24,180,59,19, &ob->trackflag, 12.0, 0.0, 0, 0, "Specify the axis that points to another object");
2442         uiDefButS(block, ROW,B_TRACKBUTS,"Y",           85,180,19,19, &ob->trackflag, 12.0, 1.0, 0, 0, "Specify the axis that points to another object");
2443         uiDefButS(block, ROW,B_TRACKBUTS,"Z",           104,180,19,19, &ob->trackflag, 12.0, 2.0, 0, 0, "Specify the axis that points to another object");
2444         uiDefButS(block, ROW,B_TRACKBUTS,"-X",          124,180,24,19, &ob->trackflag, 12.0, 3.0, 0, 0, "Specify the axis that points to another object");
2445         uiDefButS(block, ROW,B_TRACKBUTS,"-Y",          150,180,24,19, &ob->trackflag, 12.0, 4.0, 0, 0, "Specify the axis that points to another object");
2446         uiDefButS(block, ROW,B_TRACKBUTS,"-Z",          178,180,24,19, &ob->trackflag, 12.0, 5.0, 0, 0, "Specify the axis that points to another object");
2447         uiBlockBeginAlign(block);
2448         uiDefButS(block, ROW,REDRAWVIEW3D,"UpX",        226,180,45,19, &ob->upflag, 13.0, 0.0, 0, 0, "Specify the axis that points up");
2449         uiDefButS(block, ROW,REDRAWVIEW3D,"Y",          274,180,20,19, &ob->upflag, 13.0, 1.0, 0, 0, "Specify the axis that points up");
2450         uiDefButS(block, ROW,REDRAWVIEW3D,"Z",          298,180,19,19, &ob->upflag, 13.0, 2.0, 0, 0, "Specify the axis that points up");
2451         
2452         uiBlockBeginAlign(block);
2453         uiDefButBitS(block, TOG, OB_DRAWKEY, B_OBJECT_IPOFLAG, "Draw Key",              24,155,71,19, &ob->ipoflag, 0, 0, 0, 0, "Draw object as key position");
2454         uiDefButBitS(block, TOG, OB_DRAWKEYSEL, REDRAWVIEW3D, "Draw Key Sel",   97,155,81,19, &ob->ipoflag, 0, 0, 0, 0, "Limit the drawing of object keys");
2455         uiDefButBitS(block, TOG, OB_POWERTRACK, REDRAWVIEW3D, "Powertrack",             180,155,78,19, &ob->transflag, 0, 0, 0, 0, "Switch objects rotation off");
2456         uiDefButBitS(block, TOG, PARSLOW, 0, "SlowPar",                                 260,155,56,19, &ob->partype, 0, 0, 0, 0, "Create a delay in the parent relationship");
2457         uiBlockBeginAlign(block);
2458         
2459         uiDefButBitS(block, TOG, OB_DUPLIFRAMES, B_DUPLI_FRAME, "DupliFrames",  24,130,95,20, &ob->transflag, 0, 0, 0, 0, "Make copy of object for every frame");
2460         uiDefButBitS(block, TOG, OB_DUPLIVERTS, B_DUPLI_VERTS, "DupliVerts",            119,130,95,20, &ob->transflag, 0, 0, 0, 0, "Duplicate child objects on all vertices");
2461         uiDefButBitS(block, TOG, OB_DUPLIFACES, B_DUPLI_FACES, "DupliFaces",            214,130,102,20, &ob->transflag, 0, 0, 0, 0, "Duplicate child objects on all faces");
2462         uiDefButBitS(block, TOG, OB_DUPLIGROUP, B_DUPLI_GROUP, "DupliGroup",            24,110,150,20, &ob->transflag, 0, 0, 0, 0, "Enable group instancing");
2463         if(ob->transflag & OB_DUPLIFRAMES)
2464                 uiDefButBitS(block, TOG, OB_DUPLINOSPEED, REDRAWVIEW3D, "No Speed",             174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Set dupliframes to still, regardless of frame");
2465         else if(ob->transflag & OB_DUPLIVERTS)
2466                 uiDefButBitS(block, TOG, OB_DUPLIROT, REDRAWVIEW3D, "Rot",                              174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Rotate dupli according to vertex normal");
2467         else if(ob->transflag & OB_DUPLIFACES)
2468                 uiDefButBitS(block, TOG, OB_DUPLIFACES_SCALE, REDRAWVIEW3D, "Scale",                    174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Scale dupli based on face size");
2469         else
2470                 uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_GROUP_RELINK, "GR:", 174,110,142,20, &ob->dup_group, "Instance an existing group");
2471
2472         uiBlockBeginAlign(block);
2473         /* DupSta and DupEnd are both shorts, so the maxframe is greater then their range
2474         just limit the buttons to the max short */
2475         uiDefButI(block, NUM, REDRAWVIEW3D, "DupSta:",          24,85,141,19, &ob->dupsta, 1.0, 32767, 0, 0, "Specify startframe for Dupliframes");
2476         uiDefButI(block, NUM, REDRAWVIEW3D, "DupOn:",           170,85,146,19, &ob->dupon, 1.0, 1500.0, 0, 0, "Specify the number of frames to use between DupOff frames");
2477         uiDefButI(block, NUM, REDRAWVIEW3D, "DupEnd",           24,65,140,19, &ob->dupend, 1.0, 32767, 0, 0, "Specify endframe for Dupliframes");
2478         uiDefButI(block, NUM, REDRAWVIEW3D, "DupOff",           171,65,145,19, &ob->dupoff, 0.0, 1500.0, 0, 0, "Specify recurring frames to exclude from the Dupliframes");
2479         uiBlockBeginAlign(block);
2480         uiDefButBitS(block, TOG, OB_OFFS_OB, REDRAWALL, "Offs Ob",                      24,35,56,20, &ob->ipoflag, 0, 0, 0, 0, "Not functional at the moment!");
2481         uiDefButBitS(block, TOG, OB_OFFS_PARENT, REDRAWALL, "Offs Par",                 82,35,56,20 , &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the parent");
2482         uiDefButBitS(block, TOG, OB_OFFS_PARTICLE, REDRAWALL, "Offs Particle",          140,35,103,20, &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the particle effect");
2483         
2484         uiBlockBeginAlign(block);
2485         uiDefButF(block, NUM, REDRAWALL, "TimeOffset:",                 24,10,115,20, &ob->sf, -MAXFRAMEF, MAXFRAMEF, 100, 0, "Specify an offset in frames");
2486         uiDefBut(block, BUT, B_AUTOTIMEOFS, "Automatic Time",   139,10,104,20, 0, 0, 0, 0, 0, "Generate automatic timeoffset values for all selected frames");
2487         uiDefBut(block, BUT, B_PRINTSPEED,      "PrSpeed",                      248,10,67,20, 0, 0, 0, 0, 0, "Print objectspeed");
2488         uiBlockEndAlign(block);
2489         
2490         sprintf(str, "%.4f", prspeed);
2491         uiDefBut(block, LABEL, 0, str,                                                  247,35,63,31, NULL, 1.0, 0, 0, 0, "");
2492         
2493 }
2494
2495 static void object_panel_draw(Object *ob)
2496 {
2497         uiBlock *block;
2498         int xco, a, dx, dy;
2499         
2500         block= uiNewBlock(&curarea->uiblocks, "object_panel_draw", UI_EMBOSS, UI_HELV, curarea->win);
2501         if(uiNewPanel(curarea, block, "Draw", "Object", 640, 0, 318, 204)==0) return;
2502         
2503         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2504         
2505         /* LAYERS */
2506         xco= 120;
2507         dx= 35;
2508         dy= 30;
2509         
2510         uiDefBut(block, LABEL, 0, "Layers",                             10,170,100,20, NULL, 0, 0, 0, 0, "");
2511         
2512         uiBlockBeginAlign(block);
2513         for(a=0; a<5; a++)
2514                 uiDefButBitI(block, TOG, 1<<a, B_OBLAY+a, "",   (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2515         for(a=0; a<5; a++)
2516                 uiDefButBitI(block, TOG, 1<<(a+10), B_OBLAY+a+10, "",   (short)(xco+a*(dx/2)), 165, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2517         
2518         xco+= 7;
2519         uiBlockBeginAlign(block);
2520         for(a=5; a<10; a++)
2521                 uiDefButBitI(block, TOG, 1<<a, B_OBLAY+a, "",   (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2522         for(a=5; a<10; a++)
2523                 uiDefButBitI(block, TOG, 1<<(a+10), B_OBLAY+a+10, "",   (short)(xco+a*(dx/2)), 165, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2524         
2525         uiBlockEndAlign(block);
2526         
2527         uiDefBut(block, LABEL, 0, "Drawtype",                                           10,120,100,20, NULL, 0, 0, 0, 0, "");
2528         
2529         uiBlockBeginAlign(block);
2530         uiDefButC(block, ROW, REDRAWVIEW3D, "Shaded",   10,100,100, 20, &ob->dt, 0, OB_SHADED, 0, 0, "Draw active object shaded or textured");
2531         uiDefButC(block, ROW, REDRAWVIEW3D, "Solid",    10,80,100, 20, &ob->dt, 0, OB_SOLID, 0, 0, "Draw active object in solid");
2532         uiDefButC(block, ROW, REDRAWVIEW3D, "Wire",             10,60, 100, 20, &ob->dt, 0, OB_WIRE, 0, 0, "Draw active object in wireframe");
2533         uiDefButC(block, ROW, REDRAWVIEW3D, "Bounds",   10,40, 100, 20, &ob->dt, 0, OB_BOUNDBOX, 0, 0, "Only draw object with bounding box");
2534         uiBlockEndAlign(block);
2535         
2536         uiDefBut(block, LABEL, 0, "Draw Extra",                                                 120,120,90,20, NULL, 0, 0, 0, 0, "");
2537         
2538         uiBlockBeginAlign(block);
2539         uiDefButBitC(block, TOG, OB_BOUNDBOX, REDRAWVIEW3D, "Bounds",                           120, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's bounds");
2540         uiDefButBitC(block, TOG, OB_DRAWNAME, REDRAWVIEW3D, "Name",             210, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's name");
2541         
2542         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Polyheder%x4",
2543                           120, 80, 90, 20, &ob->boundtype, 0, 0, 0, 0, "Selects the boundary display type");
2544         uiDefButBitC(block, TOG, OB_AXIS, REDRAWVIEW3D, "Axis",                 210, 80, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's center and axis");
2545         
2546         uiDefButBitC(block, TOG, OB_TEXSPACE, REDRAWVIEW3D, "TexSpace", 120, 60, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's texture space");
2547         uiDefButBitC(block, TOG, OB_DRAWWIRE, REDRAWVIEW3D, "Wire",             210, 60, 90, 20, &ob->dtx, 0, 0, 0, 0, "Adds the active object's wireframe over solid drawing");
2548         
2549         uiDefButBitC(block, TOG, OB_DRAWTRANSP, REDRAWVIEW3D, "Transp", 120, 40, 90, 20, &ob->dtx, 0, 0, 0, 0, "Enables transparent materials for the active object (Mesh only)");
2550         uiDefButBitC(block, TOG, OB_DRAWXRAY, REDRAWVIEW3D, "X-ray",    210, 40, 90, 20, &ob->dtx, 0, 0, 0, 0, "Makes the active object draw in front of others");
2551 }
2552
2553 void object_panel_constraint(char *context)
2554 {
2555         uiBlock *block;
2556         Object *ob= OBACT;
2557         ListBase *conlist;
2558         bConstraint *curcon;
2559         short xco, yco;
2560         char str[64];
2561         
2562         block= uiNewBlock(&curarea->uiblocks, "object_panel_constraint", UI_EMBOSS, UI_HELV, curarea->win);
2563         if(uiNewPanel(curarea, block, "Constraints", context, 960, 0, 318, 204)==0) return;
2564         
2565         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2566         
2567         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
2568         /* so first we make it default height */
2569         uiNewPanelHeight(block, 204);
2570         
2571         /* do not allow this panel to draw in editmode - why?*/
2572         if(G.obedit==OBACT) return;     // ??
2573         
2574         conlist = get_active_constraints(OBACT);
2575         
2576         if (conlist) {
2577                 uiDefBlockBut(block, add_constraintmenu, NULL, "Add Constraint", 0, 190, 130, 20, "Add a new constraint");
2578                 
2579                 /* print active object or bone */
2580                 str[0]= 0;
2581                 if (ob->flag & OB_POSEMODE) {
2582                         bPoseChannel *pchan=