svn merge -r 13177:13240 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[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 = 106; 
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                                 /* constraint space settings */
1373                                 draw_constraint_spaceselect(block, con, *xco, *yco-100, is_armature_owner(ob), -1);
1374                         }
1375                         break;
1376                 case CONSTRAINT_TYPE_SIZELIMIT:
1377                         {
1378                                 bSizeLimitConstraint *data = con->data;
1379                                 
1380                                 int togButWidth = 50;
1381                                 int textButWidth = ((width/2)-togButWidth);
1382                                 
1383                                 height = 136; 
1384                                         
1385                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1386                                 
1387                                 /* Draw Pairs of LimitToggle+LimitValue */
1388                                 uiBlockBeginAlign(block); 
1389                                         uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "minX", *xco, *yco-28, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x value"); 
1390                                         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"); 
1391                                 uiBlockEndAlign(block); 
1392                                 
1393                                 uiBlockBeginAlign(block); 
1394                                         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"); 
1395                                         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"); 
1396                                 uiBlockEndAlign(block); 
1397                                 
1398                                 
1399                                 uiBlockBeginAlign(block); 
1400                                         uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "minY", *xco, *yco-50, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y value"); 
1401                                         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"); 
1402                                 uiBlockEndAlign(block); 
1403                                 
1404                                 uiBlockBeginAlign(block); 
1405                                         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"); 
1406                                         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"); 
1407                                 uiBlockEndAlign(block); 
1408                                 
1409                                 
1410                                 uiBlockBeginAlign(block); 
1411                                         uiDefButBitS(block, TOG, LIMIT_ZMIN, B_CONSTRAINT_TEST, "minZ", *xco, *yco-72, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z value"); 
1412                                         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"); 
1413                                 uiBlockEndAlign(block); 
1414                                 
1415                                 uiBlockBeginAlign(block); 
1416                                         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"); 
1417                                         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"); 
1418                                 uiBlockEndAlign(block);
1419                                 
1420                                 /* special option(s) */
1421                                 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"); 
1422                                 
1423                                 /* constraint space settings */
1424                                 draw_constraint_spaceselect(block, con, *xco, *yco-130, is_armature_owner(ob), -1);
1425                         }
1426                         break;
1427                 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1428                         {
1429                                 bRigidBodyJointConstraint *data = con->data;
1430                                 float extremeLin = 999.f;
1431                                 float extremeAngX = 180.f;
1432                                 float extremeAngY = 45.f;
1433                                 float extremeAngZ = 45.f;
1434                                 int togButWidth = 70;
1435                                 int offsetY = 150;
1436                                 int textButWidth = ((width/2)-togButWidth);
1437                                 
1438                                 uiDefButI(block, MENU, B_CONSTRAINT_TEST, "Joint Types%t|Ball%x1|Hinge%x2|Cone Twist%x4|Generic (experimental)%x12",//|Extra Force%x6",
1439                                                                                                 *xco, *yco-25, 150, 18, &data->type, 0, 0, 0, 0, "Choose the joint type");
1440                 height = 140;
1441                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF)
1442                                         height = 270;
1443                                 if (data->type==CONSTRAINT_RB_CONETWIST)
1444                                         height = 200;
1445                                 
1446                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
1447                                 
1448                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "toObject:", *xco, *yco-50, 130, 18, &data->tar, "Child Object");
1449                                 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");                              
1450                                 
1451                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -1000, 1000, 100, 0.0, "Offset pivot on X");
1452                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Y:", *xco, *yco-100, 130, 18, &data->pivY, -1000, 1000, 100, 0.0, "Offset pivot on Y");
1453                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Z:", *xco, *yco-125, 130, 18, &data->pivZ, -1000, 1000, 100, 0.0, "Offset pivot on z");
1454                                 
1455                                 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)");
1456                                 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)");
1457                                 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)");
1458                                 
1459                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF) {
1460                                         /* Draw Pairs of LimitToggle+LimitValue */
1461                                         uiBlockBeginAlign(block); 
1462                                                 uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1463                                                 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"); 
1464                                         uiBlockEndAlign(block);
1465                                         
1466                                         uiBlockBeginAlign(block); 
1467                                                 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"); 
1468                                                 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"); 
1469                                         uiBlockEndAlign(block);
1470                                         
1471                                         offsetY += 20;
1472                                         uiBlockBeginAlign(block); 
1473                                                 uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1474                                                 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"); 
1475                                         uiBlockEndAlign(block);
1476                                         
1477                                         uiBlockBeginAlign(block); 
1478                                                 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"); 
1479                                                 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"); 
1480                                         uiBlockEndAlign(block);
1481                                         
1482                                         offsetY += 20;
1483                                         uiBlockBeginAlign(block); 
1484                                                 uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1485                                                 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"); 
1486                                         uiBlockEndAlign(block);
1487                                         
1488                                         uiBlockBeginAlign(block); 
1489                                                 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"); 
1490                                                 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"); 
1491                                         uiBlockEndAlign(block);
1492                                         offsetY += 20;
1493                                 }
1494                                 if ((data->type==CONSTRAINT_RB_GENERIC6DOF) || (data->type==CONSTRAINT_RB_CONETWIST)) {
1495                                         /* Draw Pairs of LimitToggle+LimitValue */
1496                                         uiBlockBeginAlign(block); 
1497                                                 uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1498                                                 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"); 
1499                                         uiBlockEndAlign(block);
1500                                         uiBlockBeginAlign(block); 
1501                                                 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"); 
1502                                                 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"); 
1503                                         uiBlockEndAlign(block);
1504                                         
1505                                         offsetY += 20;
1506                                         uiBlockBeginAlign(block); 
1507                                                 uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1508                                                 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"); 
1509                                         uiBlockEndAlign(block);
1510                                         
1511                                         uiBlockBeginAlign(block); 
1512                                                 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"); 
1513                                                 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"); 
1514                                         uiBlockEndAlign(block);
1515                                         
1516                                         offsetY += 20;
1517                                         uiBlockBeginAlign(block); 
1518                                                 uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1519                                                 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"); 
1520                                         uiBlockEndAlign(block);
1521                                         
1522                                         uiBlockBeginAlign(block); 
1523                                                 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"); 
1524                                                 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"); 
1525                                         uiBlockEndAlign(block);
1526                                 }
1527                         }
1528                         break;
1529                 case CONSTRAINT_TYPE_CLAMPTO:
1530                         {
1531                                 bClampToConstraint *data = con->data;
1532                                 
1533                                 height = 90;
1534                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1535                                 
1536                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1537                                 
1538                                 /* Draw target parameters */
1539                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1540                                 
1541                                 /* Draw XYZ toggles */
1542                                 uiBlockBeginAlign(block);
1543                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Main Axis:", *xco, *yco-64, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1544                                         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");
1545                                         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");
1546                                         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");
1547                                         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");
1548                                 uiBlockEndAlign(block);
1549                                 
1550                                 /* Extra Options Controlling Behaviour */
1551                                 //uiBlockBeginAlign(block);
1552                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Options:", *xco, *yco-88, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1553                                         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)");
1554                                 //uiBlockEndAlign(block);
1555                         }
1556                         break;
1557                 case CONSTRAINT_TYPE_TRANSFORM:
1558                         {
1559                                 bTransformConstraint *data = con->data;
1560                                 float fmin, fmax, tmin, tmax;
1561                                 
1562                                 height = 178;
1563                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1564                                 
1565                                 /* Draw target parameters */                    
1566                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1567                                 
1568                                 /* Draw target parameters */
1569                                 uiBlockBeginAlign(block);
1570                                         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"); 
1571                                         
1572                                         if (is_armature_target(data->tar)) {
1573                                                 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");
1574                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1575                                         }
1576                                         else if (is_geom_target(data->tar)) {
1577                                                 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");
1578                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1579                                         }
1580                                         else {
1581                                                 strcpy(data->subtarget, "");
1582                                         }
1583                                 uiBlockEndAlign(block);
1584                                 
1585                                 /* Extrapolate Ranges? */
1586                                 uiDefButBitC(block, TOG, 1, B_CONSTRAINT_TEST, "Extrapolate", *xco, *yco-42,80,19, &data->expo, 0, 0, 0, 0, "Extrapolate ranges");
1587                                 
1588                                 /* Draw options for source motion */
1589                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Source:", *xco-10, *yco-62, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1590                                 
1591                                 /*      draw Loc/Rot/Size toggles       */
1592                                 uiBlockBeginAlign(block);
1593                                         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");
1594                                         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");
1595                                         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");
1596                                 uiBlockEndAlign(block);
1597                                 
1598                                 /* Draw Pairs of Axis: Min/Max Value*/
1599                                 if (data->from == 2) {
1600                                         fmin= 0.0001;
1601                                         fmax= 1000.0;
1602                                 }
1603                                 else if (data->from == 1) {
1604                                         fmin= -360.0;
1605                                         fmax= 360.0;
1606                                 }
1607                                 else {
1608                                         fmin = -1000.0;
1609                                         fmax= 1000.0;
1610                                 }
1611                                 
1612                                 uiBlockBeginAlign(block); 
1613                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "X:", *xco-10, *yco-107, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1614                                         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"); 
1615                                         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"); 
1616                                 uiBlockEndAlign(block); 
1617                                 
1618                                 uiBlockBeginAlign(block); 
1619                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Y:", *xco-10, *yco-127, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1620                                         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"); 
1621                                         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"); 
1622                                 uiBlockEndAlign(block);
1623                                 
1624                                 uiBlockBeginAlign(block); 
1625                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Z:", *xco-10, *yco-147, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1626                                         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"); 
1627                                         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"); 
1628                                 uiBlockEndAlign(block); 
1629                                 
1630                                 
1631                                 /* Draw options for target motion */
1632                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Destination:", *xco+150, *yco-62, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1633                                 
1634                                 /*      draw Loc/Rot/Size toggles       */
1635                                 uiBlockBeginAlign(block);
1636                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Loc", *xco+150, *yco-82, 45, 18, &data->to, 12.0, 0, 0, 0, "Use as Location transform");
1637                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Rot", *xco+195, *yco-82, 45, 18, &data->to, 12.0, 1, 0, 0, "Use as Rotation transform");
1638                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Scale", *xco+245, *yco-82, 45, 18, &data->to, 12.0, 2, 0, 0, "Use as Scale transform");
1639                                 uiBlockEndAlign(block);
1640                                 
1641                                 /* Draw Pairs of Source-Axis: Min/Max Value*/
1642                                 if (data->to == 2) {
1643                                         tmin= 0.0001;
1644                                         tmax= 1000.0;
1645                                 }
1646                                 else if (data->to == 1) {
1647                                         tmin= -360.0;
1648                                         tmax= 360.0;
1649                                 }
1650                                 else {
1651                                         tmin = -1000.0;
1652                                         tmax= 1000.0;
1653                                 }
1654                                 
1655                                 uiBlockBeginAlign(block); 
1656                                         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");
1657                                         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"); 
1658                                         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"); 
1659                                 uiBlockEndAlign(block); 
1660                                 
1661                                 uiBlockBeginAlign(block); 
1662                                         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");
1663                                         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"); 
1664                                         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"); 
1665                                 uiBlockEndAlign(block);
1666                                 
1667                                 uiBlockBeginAlign(block); 
1668                                         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");
1669                                         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"); 
1670                                         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"); 
1671                                 uiBlockEndAlign(block); 
1672                                 
1673                                 /* constraint space settings */
1674                                 draw_constraint_spaceselect(block, con, *xco, *yco-170, is_armature_owner(ob), is_armature_target(data->tar));
1675                         }
1676                         break;
1677                 case CONSTRAINT_TYPE_NULL:
1678                         {
1679                                 height = 17;
1680                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1681                         }
1682                         break;
1683                 default:
1684                         height = 0;
1685                         break;
1686                 }
1687                 
1688                 (*yco)-=(24+height);
1689         }
1690
1691         if (ELEM(con->type, CONSTRAINT_TYPE_NULL, CONSTRAINT_TYPE_RIGIDBODYJOINT)==0) {
1692                 uiBlockBeginAlign(block);
1693                 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");
1694                 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");
1695                 /* If this is on an object or bone, add ipo channel the constraint */
1696                 uiButSetFunc (but, enable_constraint_ipo_func, ob, con);
1697                 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");
1698                 /* Add a keyframe to the influence IPO */
1699                 uiButSetFunc (but, add_influence_key_to_constraint_func, ob, con);
1700                 uiBlockEndAlign(block);
1701                 (*yco)-=24;
1702         } 
1703         else {
1704                 (*yco)-=3;
1705         }
1706         
1707         /* clear any locks set up for proxies/lib-linking */
1708         uiClearButLock();
1709 }
1710
1711 static uiBlock *add_constraintmenu(void *arg_unused)
1712 {
1713         Object *ob= OBACT;
1714         uiBlock *block;
1715         ListBase *conlist;
1716         short yco= 0;
1717         
1718         conlist = get_active_constraints(ob);
1719         
1720         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1721
1722         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_CHILDOF, "Child Of",                     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1723         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRANSFORM, "Transformation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1724         
1725         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1726         
1727         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIKE, "Copy Location", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1728         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIKE, "Copy Rotation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1729         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIKE, "Copy Scale", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1730         
1731         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1732         
1733         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIMIT, "Limit Location", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1734         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIMIT, "Limit Rotation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1735         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIMIT, "Limit Scale", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1736         
1737         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1738         
1739         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRACKTO, "Track To",     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1740         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_MINMAX, "Floor", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1741         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCKTRACK, "Locked Track", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1742         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_FOLLOWPATH, "Follow Path", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1743                 
1744         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1745         
1746         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_CLAMPTO, "Clamp To", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1747         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_STRETCHTO, "Stretch To", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1748
1749         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_RIGIDBODYJOINT, "Rigid Body Joint", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");//rcruiz
1750
1751         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1752         
1753         if (ob->flag & OB_POSEMODE) {
1754                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_KINEMATIC, "IK Solver", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1755         }
1756         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ACTION, "Action", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1757         
1758         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1759
1760         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_PYTHON, "Script", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1761         
1762         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1763         
1764         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_NULL, "Null",    0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1765         
1766         
1767         uiTextBoundsBlock(block, 50);
1768         uiBlockSetDirection(block, UI_DOWN);
1769                 
1770         return block;
1771 }
1772
1773 void do_constraintbuts(unsigned short event)
1774 {
1775         Object *ob= OBACT;
1776         bConstraint *con;
1777         
1778         switch(event) {
1779         case B_CONSTRAINT_TEST:
1780                 break;  // no handling
1781         case B_CONSTRAINT_INF:
1782                 /* influence; do not execute actions for 1 dag_flush */
1783                 if (ob->pose)
1784                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
1785
1786         case B_CONSTRAINT_CHANGETARGET:
1787                 if (ob->pose) ob->pose->flag |= POSE_RECALC;    // checks & sorts pose channels
1788                 DAG_scene_sort(G.scene);
1789                 break;
1790         
1791         case B_CONSTRAINT_ADD_NULL:
1792                 {
1793                         con = add_new_constraint(CONSTRAINT_TYPE_NULL);
1794                         add_constraint_to_active(ob, con);
1795                         
1796                         BIF_undo_push("Add constraint");
1797                 }
1798                 break;
1799         case B_CONSTRAINT_ADD_PYTHON:
1800                 {
1801                         con = add_new_constraint(CONSTRAINT_TYPE_PYTHON);
1802                         add_constraint_to_active(ob, con);
1803                         
1804                         BIF_undo_push("Add constraint");
1805                 }
1806                 break;  
1807         case B_CONSTRAINT_ADD_KINEMATIC:
1808                 {
1809                         con = add_new_constraint(CONSTRAINT_TYPE_KINEMATIC);
1810                         add_constraint_to_active(ob, con);
1811                         
1812                         BIF_undo_push("Add constraint");
1813                 }
1814                 break;
1815         case B_CONSTRAINT_ADD_CHILDOF:
1816                 {
1817                         con= add_new_constraint(CONSTRAINT_TYPE_CHILDOF);
1818                         add_constraint_to_active(ob, con);
1819                         
1820                         /* if this constraint is being added to a posechannel, make sure
1821                          * the constraint gets evaluated in pose-space
1822                          */
1823                         if (ob->flag & OB_POSEMODE) {
1824                                 con->ownspace = CONSTRAINT_SPACE_POSE;
1825                                 con->flag |= CONSTRAINT_SPACEONCE;
1826                         }
1827                         
1828                         BIF_undo_push("Add constraint");
1829                 }
1830                 break;
1831         case B_CONSTRAINT_ADD_TRACKTO:
1832                 {
1833                         con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
1834                         add_constraint_to_active(ob, con);
1835                         
1836                         BIF_undo_push("Add constraint");
1837                 }
1838                 break;
1839         case B_CONSTRAINT_ADD_MINMAX:
1840                 {
1841                         con = add_new_constraint(CONSTRAINT_TYPE_MINMAX);
1842                         add_constraint_to_active(ob, con);
1843                         
1844                         BIF_undo_push("Add constraint");
1845                 }
1846                 break;
1847         case B_CONSTRAINT_ADD_ROTLIKE:
1848                 {
1849                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIKE);
1850                         add_constraint_to_active(ob, con);
1851                         
1852                         BIF_undo_push("Add constraint");
1853                 }
1854                 break;
1855         case B_CONSTRAINT_ADD_LOCLIKE:
1856                 {
1857                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIKE);
1858                         add_constraint_to_active(ob, con);
1859                         
1860                         BIF_undo_push("Add constraint");
1861                 }
1862                 break;
1863         case B_CONSTRAINT_ADD_SIZELIKE:
1864                 {
1865                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIKE);
1866                         add_constraint_to_active(ob, con);
1867                         
1868                         BIF_undo_push("Add constraint");
1869                 }
1870                 break;
1871         case B_CONSTRAINT_ADD_ACTION:
1872                 {
1873                         con = add_new_constraint(CONSTRAINT_TYPE_ACTION);
1874                         add_constraint_to_active(ob, con);
1875                         
1876                         BIF_undo_push("Add constraint");
1877                 }
1878                 break;
1879         case B_CONSTRAINT_ADD_LOCKTRACK:
1880                 {
1881                         con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
1882                         add_constraint_to_active(ob, con);
1883                         
1884                         BIF_undo_push("Add constraint");
1885                 }
1886                 break;
1887         case B_CONSTRAINT_ADD_FOLLOWPATH:
1888                 {
1889                         con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1890                         add_constraint_to_active(ob, con);
1891                         
1892                         BIF_undo_push("Add constraint");
1893                 }
1894                 break;
1895         case B_CONSTRAINT_ADD_STRETCHTO:
1896                 {
1897                         con = add_new_constraint(CONSTRAINT_TYPE_STRETCHTO);
1898                         add_constraint_to_active(ob, con);
1899                         
1900                         BIF_undo_push("Add constraint");
1901                 }
1902                 break;
1903         case B_CONSTRAINT_ADD_LOCLIMIT:
1904                 {
1905                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIMIT);
1906                         add_constraint_to_active(ob, con);
1907                         
1908                         BIF_undo_push("Add constraint");
1909                 }
1910                 break;
1911         case B_CONSTRAINT_ADD_ROTLIMIT:
1912                 {
1913                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIMIT);
1914                         add_constraint_to_active(ob, con);
1915                         
1916                         BIF_undo_push("Add constraint");
1917                 }
1918                 break;
1919         case B_CONSTRAINT_ADD_SIZELIMIT:
1920                 {
1921                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIMIT);
1922                         add_constraint_to_active(ob, con);
1923                         
1924                         BIF_undo_push("Add constraint");
1925                 }
1926                 break;
1927         case B_CONSTRAINT_ADD_RIGIDBODYJOINT:
1928                 {
1929                         bRigidBodyJointConstraint *data;
1930                         Base *base_iter;
1931                         
1932                         con = add_new_constraint(CONSTRAINT_TYPE_RIGIDBODYJOINT);
1933                         add_constraint_to_active(ob, con);
1934                         
1935                         /* set selected first object as target - moved from new_constraint_data */
1936                         data = (bRigidBodyJointConstraint*)con->data;
1937                         base_iter = G.scene->base.first;
1938             while ( base_iter && !data->tar ) {
1939                 if( ( ( base_iter->flag & SELECT ) &&
1940 //                     ( base_iter->lay & G.vd->lay ) ) &&
1941                     ( base_iter != G.scene->basact ) ))
1942                                 {
1943                         data->tar=base_iter->object;
1944                                                 break;
1945                                 }
1946                 base_iter = base_iter->next;
1947             }
1948                         
1949                         BIF_undo_push("Add constraint");
1950                 }
1951                 break;
1952         case B_CONSTRAINT_ADD_CLAMPTO:
1953                 {
1954                         con = add_new_constraint(CONSTRAINT_TYPE_CLAMPTO);
1955                         add_constraint_to_active(ob, con);
1956                         
1957                         BIF_undo_push("Add constraint");
1958                 }
1959                 break;
1960         case B_CONSTRAINT_ADD_TRANSFORM:
1961                 {
1962                         con = add_new_constraint(CONSTRAINT_TYPE_TRANSFORM);
1963                         add_constraint_to_active(ob, con);
1964                         
1965                         BIF_undo_push("Add constraint");
1966                 }
1967                 break;
1968
1969         default:
1970                 break;
1971         }
1972
1973         object_test_constraints(ob);
1974         
1975         if(ob->pose) update_pose_constraint_flags(ob->pose);
1976         
1977         if(ob->type==OB_ARMATURE) DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA|OB_RECALC_OB);
1978         else DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1979         
1980         allqueue (REDRAWVIEW3D, 0);
1981         allqueue (REDRAWBUTSOBJECT, 0);
1982 }
1983
1984 void softbody_bake(Object *ob)
1985 {
1986         Base *base;
1987         SoftBody *sb;
1988         ScrArea *sa;
1989         float frameleno= G.scene->r.framelen;
1990         int cfrao= CFRA, sfra=100000, efra=0, didbreak =0;
1991         
1992         
1993         G.scene->r.framelen= 1.0;               // baking has to be in uncorrected time
1994         sbSetInterruptCallBack(blender_test_break); // make softbody module ESC aware
1995         G.afbreek=0; // init global break system
1996         
1997         if(ob) {
1998                 sb= ob->soft;
1999                 sfra= MIN2(sfra, sb->sfra);
2000                 efra= MAX2(efra, sb->efra);
2001                 sbObjectToSoftbody(ob); // put softbody in restposition, free bake
2002                 ob->softflag |= OB_SB_BAKEDO;
2003         }
2004         else {
2005                 for(base=G.scene->base.first; base; base= base->next) {
2006                         if(TESTBASELIB(base)) {
2007                                 if(base->object->soft) {
2008                                         sb= base->object->soft;
2009                                         sfra= MIN2(sfra, sb->sfra);
2010                                         efra= MAX2(efra, sb->efra);
2011                                         sbObjectToSoftbody(base->object);       // put softbody in restposition, free bake
2012                                         base->object->softflag |= OB_SB_BAKEDO;
2013                                 }
2014                         }
2015                 }
2016         }
2017         
2018         CFRA= sfra;
2019         update_for_newframe_muted();    // put everything on this frame
2020         
2021         curarea->win_swap= 0;           // clean swapbuffers
2022         
2023         for(; CFRA <= efra; CFRA++) {
2024                 set_timecursor(CFRA);
2025                 
2026                 update_for_newframe_muted();
2027                 
2028                 for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
2029                         if(sa->spacetype == SPACE_VIEW3D) {
2030                                 scrarea_do_windraw(sa);
2031                         }
2032                 }
2033                 screen_swapbuffers();
2034                 //blender_test_break() has a granularity of 10 ms, who cares .. baking the unit cube is kinda boring
2035                 if (blender_test_break()){ 
2036                         didbreak = 1;
2037                         break;
2038                 }
2039
2040         }
2041         if((didbreak)&&(G.qual!=LR_SHIFTKEY)) {
2042                 if(ob) 
2043                         sbObjectToSoftbody(ob); // free bake
2044                 else {
2045                         for(base=G.scene->base.first; base; base= base->next) {
2046                                 if(TESTBASELIB(base)) {
2047                                         if(base->object->soft) {
2048                                                 sbObjectToSoftbody(base->object);       // free bake
2049                                         }
2050                                 }
2051                         }
2052                 }
2053         }
2054         
2055         /* restore */
2056         waitcursor(0);
2057         sbSetInterruptCallBack(NULL); // softbody module won't ESC
2058         G.afbreek=0; // reset global break system
2059         
2060         if(ob) 
2061                 ob->softflag &= ~OB_SB_BAKEDO;
2062         else {
2063                 for(base=G.scene->base.first; base; base= base->next)
2064                         if(TESTBASELIB(base))
2065                                 if(base->object->soft)
2066                                         base->object->softflag &= ~OB_SB_BAKEDO;
2067         }
2068         
2069         CFRA= cfrao;
2070         G.scene->r.framelen= frameleno;
2071         update_for_newframe_muted();
2072         allqueue(REDRAWVIEW3D, 0);
2073         allqueue(REDRAWBUTSOBJECT, 0);
2074 }
2075
2076 // store processed path & file prefix for fluidsim bake directory
2077 void fluidsimFilesel(char *selection)
2078 {
2079         Object *ob = OBACT;
2080         char srcDir[FILE_MAXDIR+FILE_MAXFILE], srcFile[FILE_MAXFILE];
2081         char prefix[FILE_MAXFILE];
2082         char *srch, *srchSub, *srchExt, *lastFound;
2083         int isElbeemSurf = 0;
2084
2085         // make prefix
2086         strcpy(srcDir, selection);
2087         BLI_splitdirstring(srcDir, srcFile);
2088         strcpy(prefix, srcFile);
2089         // check if this is a previously generated surface mesh file
2090         srch = strstr(prefix, "fluidsurface_");
2091         // TODO search from back...
2092         if(srch) {
2093                 srchSub = strstr(prefix,"_preview_");
2094                 if(!srchSub) srchSub = strstr(prefix,"_final_");
2095                 srchExt = strstr(prefix,".gz.bobj");
2096                 if(!srchExt) srchExt = strstr(prefix,".bobj");
2097                 if(srchSub && srchExt) {
2098                         *srch = '\0';
2099                         isElbeemSurf = 1;
2100                 }
2101         }
2102         if(!isElbeemSurf) {
2103                 // try to remove suffix
2104                 lastFound = NULL;
2105                 srch = strchr(prefix, '.'); // search last . from extension
2106                 while(srch) {
2107                         lastFound = srch;
2108                         if(srch) {
2109                                 srch++;
2110                                 srch = strchr(srch, '.');
2111                         }
2112                 }
2113                 if(lastFound) {
2114                         *lastFound = '\0';
2115                 } 
2116         }
2117
2118         if(ob->fluidsimSettings) {
2119                 strcpy(ob->fluidsimSettings->surfdataPath, srcDir);
2120                 //not necessary? strcat(ob->fluidsimSettings->surfdataPath, "/");
2121                 strcat(ob->fluidsimSettings->surfdataPath, prefix);
2122
2123                 // redraw view & buttons...
2124                 allqueue(REDRAWBUTSOBJECT, 0);
2125                 allqueue(REDRAWVIEW3D, 0);
2126                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2127         }
2128 }
2129
2130 void do_object_panels(unsigned short event)
2131 {
2132         Object *ob;
2133         Effect *eff;
2134         
2135         ob= OBACT;
2136         if(ob==NULL)
2137                 return;
2138         
2139         switch(event) {
2140         case B_TRACKBUTS:
2141                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2142                 allqueue(REDRAWVIEW3D, 0);
2143                 break;
2144         case B_RECALCPATH:
2145                 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
2146                 allqueue(REDRAWVIEW3D, 0);
2147                 break;
2148         case B_DUPLI_FRAME:
2149                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFACES|OB_DUPLIGROUP);
2150                 allqueue(REDRAWVIEW3D, 0);
2151                 allqueue(REDRAWBUTSOBJECT, 0);
2152                 break;
2153         case B_DUPLI_VERTS:
2154                 ob->transflag &= ~(OB_DUPLIFRAMES|OB_DUPLIFACES|OB_DUPLIGROUP);
2155                 DAG_scene_sort(G.scene);
2156                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2157                 allqueue(REDRAWVIEW3D, 0);
2158                 allqueue(REDRAWBUTSOBJECT, 0);
2159                 break;
2160         case B_DUPLI_FACES:
2161                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIGROUP);
2162                 allqueue(REDRAWVIEW3D, 0);
2163                 allqueue(REDRAWBUTSOBJECT, 0);
2164                 break;
2165         case B_DUPLI_GROUP:
2166                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIFACES);
2167                 allqueue(REDRAWVIEW3D, 0);
2168                 allqueue(REDRAWBUTSOBJECT, 0);
2169                 break;
2170                 
2171         case B_PRINTSPEED:
2172                 {
2173                         float vec[3];
2174                         CFRA++;
2175                         do_ob_ipo(ob);
2176                         where_is_object(ob);
2177                         VECCOPY(vec, ob->obmat[3]);
2178                         CFRA--;
2179                         do_ob_ipo(ob);
2180                         where_is_object(ob);
2181                         VecSubf(vec, vec, ob->obmat[3]);
2182                         prspeed= Normalize(vec);
2183                         scrarea_queue_winredraw(curarea);
2184                 }
2185                 break;
2186         case B_PRINTLEN:
2187                 if(ob->type==OB_CURVE) {
2188                         Curve *cu=ob->data;
2189                         
2190                         if(cu->path) prlen= cu->path->totdist; else prlen= -1.0;
2191                         scrarea_queue_winredraw(curarea);
2192                 } 
2193                 break;
2194         case B_RELKEY:
2195                 allspace(REMAKEIPO, 0);
2196                 allqueue(REDRAWBUTSOBJECT, 0);
2197                 allqueue(REDRAWBUTSEDIT, 0);
2198                 allqueue(REDRAWIPO, 0);
2199                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2200                 break;
2201         case B_CURVECHECK:
2202                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2203                 allqueue(REDRAWVIEW3D, 0);
2204                 break;
2205         
2206         case B_SOFTBODY_CHANGE:
2207                 ob= OBACT;
2208                 if(ob) {
2209                         ParticleSystem *psys = PE_get_current(ob);
2210                         if(psys)
2211                                 psys->softflag |= OB_SB_REDO;
2212                         else
2213                                 ob->softflag |= OB_SB_REDO;
2214                         allqueue(REDRAWBUTSOBJECT, 0);
2215                         allqueue(REDRAWVIEW3D, 0);
2216                 }
2217                 break;
2218         case B_SOFTBODY_DEL_VG:
2219                 if(ob->soft) {
2220                         ob->soft->vertgroup= 0;
2221                         ob->softflag |= OB_SB_REDO;
2222                         allqueue(REDRAWBUTSOBJECT, 0);
2223                         allqueue(REDRAWVIEW3D, 0);
2224                 }
2225                 break;
2226         case B_SOFTBODY_BAKE:
2227                 if(ob->soft) softbody_bake(ob);
2228                 break;
2229         case B_SOFTBODY_BAKE_FREE:
2230                 if(ob->soft) sbObjectToSoftbody(ob);
2231                 allqueue(REDRAWBUTSOBJECT, 0);
2232                 allqueue(REDRAWVIEW3D, 0);
2233                 break;
2234         case B_FLUIDSIM_BAKE:
2235                 /* write config files (currently no simulation) */
2236                 fluidsimBake(ob);
2237                 break;
2238         case B_FLUIDSIM_MAKEPART:
2239                 {
2240                         PartEff *paf= NULL;
2241                         /* prepare fluidsim particle display */
2242                         // simplified delete effect, create new - recalc some particles...
2243                         if(ob==NULL || ob->type!=OB_MESH) break;
2244                         ob->fluidsimSettings->type = 0;
2245                         // reset type, and init particle system once normally
2246                         paf= give_parteff(ob); 
2247                         if( (BLI_countlist(&ob->effect)<MAX_EFFECT) && 
2248                             (!paf)) { 
2249                                 // create new entry
2250                                 copy_act_effect(ob); DAG_scene_sort(G.scene); }
2251                         paf = give_parteff(ob);
2252                         if(paf) {
2253                                 paf->totpart = 1000; paf->sta = paf->end = 1.0; // generate some particles...
2254                                 build_particle_system(ob);
2255                                 ob->fluidsimSettings->type = OB_FLUIDSIM_PARTICLE;
2256                         }
2257                 }
2258                 allqueue(REDRAWVIEW3D, 0);
2259                 allqueue(REDRAWBUTSOBJECT, 0);
2260                 break;
2261         case B_FLUIDSIM_SELDIR: 
2262                 {
2263                         ScrArea *sa = closest_bigger_area();
2264                         /* choose dir for surface files */
2265                         areawinset(sa->win);
2266                         activate_fileselect(FILE_SPECIAL, "Select Directory", ob->fluidsimSettings->surfdataPath, fluidsimFilesel);
2267                 }
2268                 break;
2269         case B_FLUIDSIM_FORCEREDRAW:
2270                 /* force redraw */
2271                 allqueue(REDRAWBUTSOBJECT, 0);
2272                 allqueue(REDRAWVIEW3D, 0);
2273                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2274                 break;
2275         case B_GROUP_RELINK:
2276                 group_relink_nla_objects(ob);
2277                 allqueue(REDRAWVIEW3D, 0);
2278                 break;
2279         case B_BAKEABLE_CHANGE:
2280                 allqueue(REDRAWBUTSOBJECT, 0);
2281                 allqueue(REDRAWVIEW3D, 0);
2282                 break;
2283         case B_OBJECT_IPOFLAG:
2284                 if(ob->ipo) ob->ipo->showkey= (ob->ipoflag & OB_DRAWKEY)?1:0;
2285                 allqueue(REDRAWVIEW3D, 0);
2286                 break;
2287                 
2288         default:
2289                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
2290                         int a=B_SELEFFECT;
2291                         
2292                         eff= ob->effect.first;
2293                         while(eff) {
2294                                 if(event==a) eff->flag |= SELECT;
2295                                 else eff->flag &= ~SELECT;
2296                                 
2297                                 a++;
2298                                 eff= eff->next;
2299                         }
2300                         allqueue(REDRAWBUTSOBJECT, 0);
2301                 }
2302         }
2303
2304 }
2305
2306 static void do_add_groupmenu(void *arg, int event)
2307 {
2308         Object *ob= OBACT;
2309         
2310         if(ob) {
2311                 
2312                 if(event== -1) {
2313                         Group *group= add_group( "Group" );
2314                         add_to_group(group, ob);
2315                 }
2316                 else
2317                         add_to_group(BLI_findlink(&G.main->group, event), ob);
2318                         
2319                 ob->flag |= OB_FROMGROUP;
2320                 BASACT->flag |= OB_FROMGROUP;
2321                 allqueue(REDRAWBUTSOBJECT, 0);
2322                 allqueue(REDRAWVIEW3D, 0);
2323         }               
2324 }
2325
2326 static uiBlock *add_groupmenu(void *arg_unused)
2327 {
2328         uiBlock *block;
2329         Group *group;
2330         short yco= 0;
2331         char str[32];
2332         
2333         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
2334         uiBlockSetButmFunc(block, do_add_groupmenu, NULL);
2335
2336         uiDefBut(block, BUTM, B_NOP, "ADD NEW",         0, 20, 160, 19, NULL, 0.0, 0.0, 1, -1, "");
2337         for(group= G.main->group.first; group; group= group->id.next, yco++) {
2338                 if(group->id.lib) strcpy(str, "L  ");
2339                 else strcpy(str, "   ");
2340                 strcat(str, group->id.name+2);
2341                 uiDefBut(block, BUTM, B_NOP, str,       0, -20*yco, 160, 19, NULL, 0.0, 0.0, 1, yco, "");
2342         }
2343         
2344         uiTextBoundsBlock(block, 50);
2345         uiBlockSetDirection(block, UI_DOWN);    
2346         
2347         return block;
2348 }
2349
2350 static void group_ob_rem(void *gr_v, void *ob_v)
2351 {
2352         Object *ob= OBACT;
2353         
2354         rem_from_group(gr_v, ob);
2355         if(find_group(ob)==NULL) {
2356                 ob->flag &= ~OB_FROMGROUP;
2357                 BASACT->flag &= ~OB_FROMGROUP;
2358         }
2359         allqueue(REDRAWBUTSOBJECT, 0);
2360         allqueue(REDRAWVIEW3D, 0);
2361
2362 }
2363
2364 static void group_local(void *gr_v, void *unused)
2365 {
2366         Group *group= gr_v;
2367         
2368         group->id.lib= NULL;
2369         
2370         allqueue(REDRAWBUTSOBJECT, 0);
2371         allqueue(REDRAWVIEW3D, 0);
2372         
2373 }
2374
2375 static void object_panel_object(Object *ob)
2376 {
2377         uiBlock *block;
2378         uiBut *but;
2379         Group *group;
2380         int a, xco, yco=0;
2381         short dx= 33, dy= 30;
2382         int is_libdata = object_is_libdata(ob);
2383         block= uiNewBlock(&curarea->uiblocks, "object_panel_object", UI_EMBOSS, UI_HELV, curarea->win);
2384         if(uiNewPanel(curarea, block, "Object and Links", "Object", 0, 0, 318, 204)==0) return;
2385         
2386         
2387         
2388         /* object name */
2389         uiBlockSetCol(block, TH_BUT_SETTING2);
2390         uiSetButLock(is_libdata, ERROR_LIBDATA_MESSAGE);
2391         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);
2392         uiBlockSetCol(block, TH_AUTO);
2393         
2394         /* parent */
2395         uiSetButLock(is_libdata, ERROR_LIBDATA_MESSAGE);
2396         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_OBJECTPANELPARENT, "Par:", xco+5, 180, 305-xco, 20, &ob->parent, "Parent Object"); 
2397         
2398         uiSetButLock(is_libdata, ERROR_LIBDATA_MESSAGE);
2399         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.");
2400         
2401         uiSetButLock(1, NULL);
2402         uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group");
2403
2404         /* all groups */
2405         for(group= G.main->group.first; group; group= group->id.next) {
2406                 if(object_in_group(ob, group)) {
2407                         xco= 160;
2408                         
2409                         uiBlockBeginAlign(block);
2410                         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.");
2411                         uiButSetFunc(but, test_idbutton_cb, group->id.name, NULL);
2412                         
2413                         if(group->id.lib) {
2414                                 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");
2415                                 uiButSetFunc(but, group_local, group, NULL);
2416                                 xco= 180;
2417                         }
2418                         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");
2419                         uiButSetFunc(but, group_ob_rem, group, ob);
2420                         
2421                         yco+= 20;
2422                         xco= 10;
2423                         
2424                         /* layers */
2425                         uiBlockBeginAlign(block);
2426                         for(a=0; a<5; a++)
2427                                 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, "");
2428                         for(a=0; a<5; a++)
2429                                 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, "");
2430                         
2431                         xco+= 7;
2432                         uiBlockBeginAlign(block);
2433                         for(a=5; a<10; a++)
2434                                 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, "");
2435                         for(a=5; a<10; a++)
2436                                 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, "");
2437                         
2438                         uiBlockEndAlign(block);
2439                         
2440                         yco+= 40;
2441                 }
2442         }
2443         
2444         if(120-yco < -10)
2445                 uiNewPanelHeight(block, 204 - (120-yco));
2446 }
2447
2448 static void object_panel_anim(Object *ob)
2449 {
2450         uiBlock *block;
2451         char str[32];
2452         
2453         block= uiNewBlock(&curarea->uiblocks, "object_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
2454         if(uiNewPanel(curarea, block, "Anim settings", "Object", 320, 0, 318, 204)==0) return;
2455         
2456         uiSetButLock(object_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2457         
2458         uiBlockBeginAlign(block);
2459         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");
2460         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");
2461         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");
2462         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");
2463         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");
2464         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");
2465         uiBlockBeginAlign(block);
2466         uiDefButS(block, ROW,REDRAWVIEW3D,"UpX",        226,180,45,19, &ob->upflag, 13.0, 0.0, 0, 0, "Specify the axis that points up");
2467         uiDefButS(block, ROW,REDRAWVIEW3D,"Y",          274,180,20,19, &ob->upflag, 13.0, 1.0, 0, 0, "Specify the axis that points up");
2468         uiDefButS(block, ROW,REDRAWVIEW3D,"Z",          298,180,19,19, &ob->upflag, 13.0, 2.0, 0, 0, "Specify the axis that points up");
2469         
2470         uiBlockBeginAlign(block);
2471         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");
2472         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");
2473         uiDefButBitS(block, TOG, OB_POWERTRACK, REDRAWVIEW3D, "Powertrack",             180,155,78,19, &ob->transflag, 0, 0, 0, 0, "Switch objects rotation off");
2474         uiDefButBitS(block, TOG, PARSLOW, 0, "SlowPar",                                 260,155,56,19, &ob->partype, 0, 0, 0, 0, "Create a delay in the parent relationship");
2475         uiBlockBeginAlign(block);
2476         
2477         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");
2478         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");
2479         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");
2480         uiDefButBitS(block, TOG, OB_DUPLIGROUP, B_DUPLI_GROUP, "DupliGroup",            24,110,150,20, &ob->transflag, 0, 0, 0, 0, "Enable group instancing");
2481         if(ob->transflag & OB_DUPLIFRAMES) {
2482                 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");
2483         } else if(ob->transflag & OB_DUPLIVERTS) {
2484                 uiDefButBitS(block, TOG, OB_DUPLIROT, REDRAWVIEW3D, "Rot",                              174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Rotate dupli according to vertex normal");
2485         } else if(ob->transflag & OB_DUPLIFACES) {
2486                 uiDefButBitS(block, TOG, OB_DUPLIFACES_SCALE, REDRAWVIEW3D, "Scale",                    174,110,80,20, &ob->transflag, 0, 0, 0, 0, "Scale dupli based on face size");
2487                 uiDefButF(block, NUM, REDRAWVIEW3D, "",         254,110,62,20, &ob->dupfacesca, 0.001, 10000.0, 0, 0, "Scale the DupliFace objects");
2488         } else {
2489                 uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_GROUP_RELINK, "GR:", 174,110,142,20, &ob->dup_group, "Instance an existing group");
2490         }
2491         
2492         uiBlockBeginAlign(block);
2493         /* DupSta and DupEnd are both shorts, so the maxframe is greater then their range
2494         just limit the buttons to the max short */
2495         uiDefButI(block, NUM, REDRAWVIEW3D, "DupSta:",          24,85,141,19, &ob->dupsta, 1.0, 32767, 0, 0, "Specify startframe for Dupliframes");
2496         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");
2497         uiDefButI(block, NUM, REDRAWVIEW3D, "DupEnd",           24,65,140,19, &ob->dupend, 1.0, 32767, 0, 0, "Specify endframe for Dupliframes");
2498         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");
2499         uiBlockBeginAlign(block);
2500         uiDefButBitS(block, TOG, OB_OFFS_OB, REDRAWALL, "Offs Ob",                      24,35,56,20, &ob->ipoflag, 0, 0, 0, 0, "Not functional at the moment!");
2501         uiDefButBitS(block, TOG, OB_OFFS_PARENT, REDRAWALL, "Offs Par",                 82,35,56,20 , &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the parent");
2502         uiDefButBitS(block, TOG, OB_OFFS_PARTICLE, REDRAWALL, "Offs Particle",          140,35,103,20, &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the particle effect");
2503         
2504         uiBlockBeginAlign(block);
2505         uiDefButF(block, NUM, REDRAWALL, "TimeOffset:",                 24,10,115,20, &ob->sf, -MAXFRAMEF, MAXFRAMEF, 100, 0, "Specify an offset in frames");
2506         uiDefBut(block, BUT, B_AUTOTIMEOFS, "Automatic Time",   139,10,104,20, 0, 0, 0, 0, 0, "Generate automatic timeoffset values for all selected frames");
2507         uiDefBut(block, BUT, B_PRINTSPEED,      "PrSpeed",                      248,10,67,20, 0, 0, 0, 0, 0, "Print objectspeed");
2508         uiBlockEndAlign(block);
2509         
2510         sprintf(str, "%.4f", prspeed);
2511         uiDefBut(block, LABEL, 0, str,                                                  247,35,63,31, NULL, 1.0, 0, 0, 0, "");
2512         
2513 }
2514
2515 static void object_panel_draw(Object *ob)
2516 {
2517         uiBlock *block;
2518         int xco, a, dx, dy;
2519         
2520         block= uiNewBlock(&curarea->uiblocks, "object_panel_draw", UI_EMBOSS, UI_HELV, curarea->win);
2521         if(uiNewPanel(curarea, block, "Draw", "Object", 640, 0, 318, 204)==0) return;
2522         
2523         uiSetButLock(object_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2524         
2525         /* LAYERS */
2526         xco= 120;
2527         dx= 35;
2528         dy= 30;
2529         
2530         uiDefBut(block, LABEL, 0, "Layers",                             10,170,100,20, NULL, 0, 0, 0, 0, "");
2531         
2532         uiBlockBeginAlign(block);
2533         for(a=0; a<5; a++)
2534                 uiDefButBitI(block, TOG, 1<<a, B_OBLAY+a, "",   (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2535         for(a=0; a<5; a++)
2536                 uiDefButBitI(block, TOG, 1<<(a+10), B_OBLAY+a+10, "",   (short)(xco+a*(dx/2)), 165, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2537         
2538         xco+= 7;
2539         uiBlockBeginAlign(block);
2540         for(a=5; a<10; a++)
2541                 uiDefButBitI(block, TOG, 1<<a, B_OBLAY+a, "",   (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2542         for(a=5; a<10; a++)
2543                 uiDefButBitI(block, TOG, 1<<(a+10), B_OBLAY+a+10, "",   (short)(xco+a*(dx/2)), 165, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2544         
2545         uiBlockEndAlign(block);
2546         
2547         uiDefBut(block, LABEL, 0, "Drawtype",                                           10,120,100,20, NULL, 0, 0, 0, 0, "");
2548         
2549         uiBlockBeginAlign(block);
2550         uiDefButC(block, ROW, REDRAWVIEW3D, "Shaded",   10,100,100, 20, &ob->dt, 0, OB_SHADED, 0, 0, "Draw active object shaded or textured");
2551         uiDefButC(block, ROW, REDRAWVIEW3D, "Solid",    10,80,100, 20, &ob->dt, 0, OB_SOLID, 0, 0, "Draw active object in solid");
2552         uiDefButC(block, ROW, REDRAWVIEW3D, "Wire",             10,60, 100, 20, &ob->dt, 0, OB_WIRE, 0, 0, "Draw active object in wireframe");
2553         uiDefButC(block, ROW, REDRAWVIEW3D, "Bounds",   10,40, 100, 20, &ob->dt, 0, OB_BOUNDBOX, 0, 0, "Only draw object with bounding box");
2554         uiBlockEndAlign(block);
2555         
2556         uiDefBut(block, LABEL, 0, "Draw Extra",                                                 120,120,90,20, NULL, 0, 0, 0, 0, "");
2557         
2558         uiBlockBeginAlign(block);
2559         uiDefButBitC(block, TOG, OB_BOUNDBOX, REDRAWVIEW3D, "Bounds",                           120, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's bounds");
2560         uiDefButBitC(block, TOG, OB_DRAWNAME, REDRAWVIEW3D, "Name",             210, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's name");
2561         
2562         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Polyheder%x4",
2563                           120, 80, 90, 20, &ob->boundtype, 0, 0, 0, 0, "Selects the boundary display type");
2564         uiDefButBitC(block, TOG, OB_AXIS, REDRAWVIEW3D, "Axis",                 210, 80, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's center and axis");
2565         
2566         uiDefButBitC(block, TOG, OB_TEXSPACE, REDRAWVIEW3D, "TexSpace", 120, 60, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's texture space");
2567         uiDefButBitC(block, TOG, OB_DRAWWIRE, REDRAWVIEW3D, "Wire",             210, 60, 90, 20, &ob->dtx, 0, 0, 0, 0, "Adds the active object's wireframe over solid drawing");
2568         
2569         uiDefButBitC(block, TOG, OB_DRAWTRANSP, REDRAWVIEW3D, "Transp", 120, 40, 90, 20, &ob->dtx, 0, 0, 0, 0, "Enables transparent materials for the active object (Mesh only)");