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