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