1fb202be6afc58216003a45bfab3c1cfa5214478
[blender.git] / source / blender / python / api2_2x / Constraint.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  * This is a new part of Blender.
27  *
28  * Contributor(s): Joseph Gilbert, Ken Hughes
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include "Constraint.h" /*This must come first*/
34
35 #include "DNA_object_types.h"
36 #include "DNA_effect_types.h"
37 #include "DNA_vec_types.h"
38 #include "DNA_curve_types.h"
39
40 #include "BKE_main.h"
41 #include "BKE_global.h"
42 #include "BKE_library.h"
43 #include "BKE_action.h"
44 #include "BKE_armature.h"
45 #include "BLI_blenlib.h"
46 #include "BIF_editconstraint.h"
47 #include "BSE_editipo.h"
48 #include "MEM_guardedalloc.h"
49 #include "butspace.h"
50 #include "blendef.h"
51 #include "mydevice.h"
52
53 #include "Object.h"
54 #include "NLA.h"
55 #include "gen_utils.h"
56
57 enum constraint_constants {
58         EXPP_CONSTR_XROT = 0,
59         EXPP_CONSTR_YROT = 1,
60         EXPP_CONSTR_ZROT = 2,
61
62         EXPP_CONSTR_MAXX = TRACK_X,
63         EXPP_CONSTR_MAXY = TRACK_Y,
64         EXPP_CONSTR_MAXZ = TRACK_Z,
65         EXPP_CONSTR_MINX = TRACK_nX,
66         EXPP_CONSTR_MINY = TRACK_nY,
67         EXPP_CONSTR_MINZ = TRACK_nZ,
68
69         EXPP_CONSTR_TARGET = 100,
70         EXPP_CONSTR_STRETCH,
71         EXPP_CONSTR_ITERATIONS,
72         EXPP_CONSTR_BONE,
73         EXPP_CONSTR_CHAINLEN,
74         EXPP_CONSTR_POSWEIGHT,
75         EXPP_CONSTR_ROTWEIGHT,
76         EXPP_CONSTR_ROTATE,
77         EXPP_CONSTR_USETIP,
78
79         EXPP_CONSTR_ACTION,
80         EXPP_CONSTR_LOCAL,
81         EXPP_CONSTR_START,
82         EXPP_CONSTR_END,
83         EXPP_CONSTR_MIN,
84         EXPP_CONSTR_MAX,
85         EXPP_CONSTR_KEYON,
86
87         EXPP_CONSTR_TRACK,
88         EXPP_CONSTR_UP,
89
90         EXPP_CONSTR_RESTLENGTH,
91         EXPP_CONSTR_VOLVARIATION,
92         EXPP_CONSTR_VOLUMEMODE,
93         EXPP_CONSTR_PLANE,
94
95         EXPP_CONSTR_FOLLOW,
96         EXPP_CONSTR_OFFSET,
97         EXPP_CONSTR_FORWARD,
98
99         EXPP_CONSTR_LOCK,
100
101         EXPP_CONSTR_MINMAX,
102         EXPP_CONSTR_STICKY,
103
104         EXPP_CONSTR_COPY,
105         EXPP_CONSTR_LIMIT,
106         
107         EXPP_CONSTR_LIMXMIN = LIMIT_XMIN,
108         EXPP_CONSTR_LIMXMAX = LIMIT_XMAX,
109         EXPP_CONSTR_LIMYMIN = LIMIT_YMIN,
110         EXPP_CONSTR_LIMYMAX = LIMIT_YMAX,
111         EXPP_CONSTR_LIMZMIN = LIMIT_ZMIN,
112         EXPP_CONSTR_LIMZMAX = LIMIT_ZMAX,
113         
114         EXPP_CONSTR_LIMXROT = LIMIT_XROT,
115         EXPP_CONSTR_LIMYROT = LIMIT_YROT,
116         EXPP_CONSTR_LIMZROT = LIMIT_ZROT,
117         
118         EXPP_CONSTR_XMIN,
119         EXPP_CONSTR_XMAX,
120         EXPP_CONSTR_YMIN,
121         EXPP_CONSTR_YMAX,
122         EXPP_CONSTR_ZMIN,
123         EXPP_CONSTR_ZMAX,
124         
125         EXPP_CONSTR_LIMLOCALBONE,
126         EXPP_CONSTR_LIMLOCALNOPAR,
127         
128         EXPP_CONSTR_RB_TYPE,
129         EXPP_CONSTR_RB_BALL,
130         EXPP_CONSTR_RB_HINGE,
131         EXPP_CONSTR_RB_GENERIC6DOF,
132         EXPP_CONSTR_RB_VEHICLE,
133         EXPP_CONSTR_RB_PIVX,
134         EXPP_CONSTR_RB_PIVY,
135         EXPP_CONSTR_RB_PIVZ,
136         EXPP_CONSTR_RB_AXX,
137         EXPP_CONSTR_RB_AXY,
138         EXPP_CONSTR_RB_AXZ,
139         EXPP_CONSTR_RB_MINLIMIT0,
140         EXPP_CONSTR_RB_MINLIMIT1,
141         EXPP_CONSTR_RB_MINLIMIT2,
142         EXPP_CONSTR_RB_MINLIMIT3,
143         EXPP_CONSTR_RB_MINLIMIT4,
144         EXPP_CONSTR_RB_MINLIMIT5,
145         EXPP_CONSTR_RB_MAXLIMIT0,
146         EXPP_CONSTR_RB_MAXLIMIT1,
147         EXPP_CONSTR_RB_MAXLIMIT2,
148         EXPP_CONSTR_RB_MAXLIMIT3,
149         EXPP_CONSTR_RB_MAXLIMIT4,
150         EXPP_CONSTR_RB_MAXLIMIT5,
151         EXPP_CONSTR_RB_EXTRAFZ,
152         EXPP_CONSTR_RB_FLAG,
153         
154 };
155
156 /*****************************************************************************/
157 /* Python BPy_Constraint methods declarations:                               */
158 /*****************************************************************************/
159 static PyObject *Constraint_getName( BPy_Constraint * self );
160 static int Constraint_setName( BPy_Constraint * self, PyObject *arg );
161 static PyObject *Constraint_getType( BPy_Constraint * self );
162 static PyObject *Constraint_getInfluence( BPy_Constraint * self );
163 static int Constraint_setInfluence( BPy_Constraint * self, PyObject * arg );
164
165 static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * arg );
166
167 static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key );
168 static int Constraint_setData( BPy_Constraint * self, PyObject * key, 
169                 PyObject * value );
170
171 /*****************************************************************************/
172 /* Python BPy_Constraint methods table:                                      */
173 /*****************************************************************************/
174 static PyMethodDef BPy_Constraint_methods[] = {
175         /* name, method, flags, doc */
176         {"insertKey", ( PyCFunction ) Constraint_insertKey, METH_VARARGS,
177          "Insert influence keyframe for constraint"},
178         {NULL, NULL, 0, NULL}
179 };
180
181 /*****************************************************************************/
182 /* Python BPy_Constraint attributes get/set structure:                       */
183 /*****************************************************************************/
184 static PyGetSetDef BPy_Constraint_getseters[] = {
185         {"name",
186         (getter)Constraint_getName, (setter)Constraint_setName,
187          "Constraint name", NULL},
188         {"type",
189         (getter)Constraint_getType, (setter)NULL,
190          "Constraint type (read only)", NULL},
191         {"influence",
192         (getter)Constraint_getInfluence, (setter)Constraint_setInfluence,
193          "Constraint influence", NULL},
194         {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
195 };
196
197 /*****************************************************************************/
198 /* Python Constraint_Type Mapping Methods table:                             */
199 /*****************************************************************************/
200 static PyMappingMethods Constraint_as_mapping = {
201         NULL,                               /* mp_length        */
202         ( binaryfunc ) Constraint_getData,      /* mp_subscript     */
203         ( objobjargproc ) Constraint_setData,   /* mp_ass_subscript */
204 };
205
206 /*****************************************************************************/
207 /* Python Constraint_Type callback function prototypes:                      */
208 /*****************************************************************************/
209 static PyObject *Constraint_repr( BPy_Constraint * self );
210 static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b );
211
212 /*****************************************************************************/
213 /* Python Constraint_Type structure definition:                              */
214 /*****************************************************************************/
215 PyTypeObject Constraint_Type = {
216         PyObject_HEAD_INIT( NULL )  /* required py macro */
217         0,                          /* ob_size */
218         /*  For printing, in format "<module>.<name>" */
219         "Blender Constraint",         /* char *tp_name; */
220         sizeof( BPy_Constraint ),     /* int tp_basicsize; */
221         0,                          /* tp_itemsize;  For allocation */
222
223         /* Methods to implement standard operations */
224
225         NULL,                                           /* destructor tp_dealloc; */
226         NULL,                       /* printfunc tp_print; */
227         NULL,                       /* getattrfunc tp_getattr; */
228         NULL,                       /* setattrfunc tp_setattr; */
229         ( cmpfunc ) Constraint_compare, /* cmpfunc tp_compare; */
230         ( reprfunc ) Constraint_repr, /* reprfunc tp_repr; */
231
232         /* Method suites for standard classes */
233
234         NULL,                       /* PyNumberMethods *tp_as_number; */
235         NULL,                       /* PySequenceMethods *tp_as_sequence; */
236         &Constraint_as_mapping,       /* PyMappingMethods *tp_as_mapping; */
237
238         /* More standard operations (here for binary compatibility) */
239
240         NULL,                       /* hashfunc tp_hash; */
241         NULL,                       /* ternaryfunc tp_call; */
242         NULL,                       /* reprfunc tp_str; */
243         NULL,                       /* getattrofunc tp_getattro; */
244         NULL,                       /* setattrofunc tp_setattro; */
245
246         /* Functions to access object as input/output buffer */
247         NULL,                       /* PyBufferProcs *tp_as_buffer; */
248
249   /*** Flags to define presence of optional/expanded features ***/
250         Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
251
252         NULL,                       /*  char *tp_doc;  Documentation string */
253   /*** Assigned meaning in release 2.0 ***/
254         /* call function for all accessible objects */
255         NULL,                       /* traverseproc tp_traverse; */
256
257         /* delete references to contained objects */
258         NULL,                       /* inquiry tp_clear; */
259
260   /***  Assigned meaning in release 2.1 ***/
261   /*** rich comparisons ***/
262         NULL,                       /* richcmpfunc tp_richcompare; */
263
264   /***  weak reference enabler ***/
265         0,                          /* long tp_weaklistoffset; */
266
267   /*** Added in release 2.2 ***/
268         /*   Iterators */
269         NULL,                       /* getiterfunc tp_iter; */
270         NULL,                       /* iternextfunc tp_iternext; */
271
272   /*** Attribute descriptor and subclassing stuff ***/
273         BPy_Constraint_methods,       /* struct PyMethodDef *tp_methods; */
274         NULL,                       /* struct PyMemberDef *tp_members; */
275         BPy_Constraint_getseters,     /* struct PyGetSetDef *tp_getset; */
276         NULL,                       /* struct _typeobject *tp_base; */
277         NULL,                       /* PyObject *tp_dict; */
278         NULL,                       /* descrgetfunc tp_descr_get; */
279         NULL,                       /* descrsetfunc tp_descr_set; */
280         0,                          /* long tp_dictoffset; */
281         NULL,                       /* initproc tp_init; */
282         NULL,                       /* allocfunc tp_alloc; */
283         NULL,                       /* newfunc tp_new; */
284         /*  Low-level free-memory routine */
285         NULL,                       /* freefunc tp_free;  */
286         /* For PyObject_IS_GC */
287         NULL,                       /* inquiry tp_is_gc;  */
288         NULL,                       /* PyObject *tp_bases; */
289         /* method resolution order */
290         NULL,                       /* PyObject *tp_mro;  */
291         NULL,                       /* PyObject *tp_cache; */
292         NULL,                       /* PyObject *tp_subclasses; */
293         NULL,                       /* PyObject *tp_weaklist; */
294         NULL
295 };
296
297 /*****************************************************************************/
298 /* Python BPy_Constraint methods:                                            */
299 /*****************************************************************************/
300
301 /*
302  * return the name of this constraint
303  */
304
305 static PyObject *Constraint_getName( BPy_Constraint * self )
306 {
307         if( !self->con )
308                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
309                                 "This constraint has been removed!" );
310         
311         return PyString_FromString( self->con->name );
312 }
313
314 /*
315  * set the name of this constraint
316  */
317
318 static int Constraint_setName( BPy_Constraint * self, PyObject * attr )
319 {
320         char *name = PyString_AsString( attr );
321         if( !name )
322                 return EXPP_ReturnIntError( PyExc_TypeError, "expected string arg" );
323
324         if( !self->con )
325                 return EXPP_ReturnIntError( PyExc_RuntimeError,
326                                 "This constraint has been removed!" );
327         
328         BLI_strncpy( self->con->name, name, sizeof( self->con->name ) );
329
330         return 0;
331 }
332
333 /*
334  * return the influence of this constraint
335  */
336
337 static PyObject *Constraint_getInfluence( BPy_Constraint * self )
338 {
339         if( !self->con )
340                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
341                                 "This constraint has been removed!" );
342         
343         return PyFloat_FromDouble( (double)self->con->enforce );
344 }
345
346 /*
347  * set the influence of this constraint
348  */
349
350 static int Constraint_setInfluence( BPy_Constraint * self, PyObject * value )
351 {
352         if( !self->con )
353                 return EXPP_ReturnIntError( PyExc_RuntimeError,
354                                 "This constraint has been removed!" );
355
356         return EXPP_setFloatClamped( value, &self->con->enforce, 0.0, 1.0 );
357 }
358
359 /*
360  * return the type of this constraint
361  */
362
363 static PyObject *Constraint_getType( BPy_Constraint * self )
364 {
365         if( !self->con )
366                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
367                                 "This constraint has been removed!" );
368         
369         return PyInt_FromLong( self->con->type );
370 }
371
372 /*
373  * add keyframe for influence
374         base on code in add_influence_key_to_constraint_func()
375  */
376
377 static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * arg )
378 {
379         IpoCurve *icu;
380         float cfra;
381         char actname[32] = "";
382         Object *ob = self->obj;
383         bConstraint *con = self->con;
384
385         if( !self->con )
386                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
387                                 "This constraint has been removed!" );
388
389         /* get frame for inserting key */
390         if( !PyArg_ParseTuple( arg, "f", &cfra ) )
391                 return EXPP_ReturnPyObjError( PyExc_TypeError,
392                                 "expected a float argument" );
393
394         // constraint_active_func(ob_v, con_v);
395         get_constraint_ipo_context( ob, actname );
396         icu= verify_ipocurve((ID *)ob, ID_CO, actname, con->name, CO_ENFORCE);
397
398         if( ob->action )
399                 insert_vert_ipo( icu, get_action_frame(ob, cfra), con->enforce);
400         else
401                 insert_vert_ipo( icu, cfra, con->enforce);
402
403         Py_RETURN_NONE;
404 }
405
406 /*****************************************************************************/
407 /* Specific constraint get/set procedures                                    */
408 /*****************************************************************************/
409
410 static PyObject *kinematic_getter( BPy_Constraint * self, int type )
411 {
412         bKinematicConstraint *con = (bKinematicConstraint *)(self->con->data);
413
414         switch( type ) {
415         case EXPP_CONSTR_TARGET:
416                 return Object_CreatePyObject( con->tar );
417         case EXPP_CONSTR_BONE:
418                 return PyString_FromString( con->subtarget );
419         case EXPP_CONSTR_STRETCH:
420                 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_STRETCH ) ) ;
421         case EXPP_CONSTR_ITERATIONS:
422                 return PyInt_FromLong( (long)con->iterations );
423         case EXPP_CONSTR_CHAINLEN:
424                 return PyInt_FromLong( (long)con->rootbone );
425         case EXPP_CONSTR_POSWEIGHT:
426                 return PyFloat_FromDouble( (double)con->weight );
427         case EXPP_CONSTR_ROTWEIGHT:
428                 return PyFloat_FromDouble( (double)con->orientweight );
429         case EXPP_CONSTR_ROTATE:
430                 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_ROT ) ) ;
431         case EXPP_CONSTR_USETIP:
432                 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_TIP ) ) ;
433         default:
434                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
435         }
436 }
437
438 static int kinematic_setter( BPy_Constraint *self, int type, PyObject *value )
439 {
440         bKinematicConstraint *con = (bKinematicConstraint *)(self->con->data);
441
442         switch( type ) {
443         case EXPP_CONSTR_TARGET: {
444                 Object *obj = (( BPy_Object * )value)->object;
445                 if( !BPy_Object_Check( value ) )
446                         return EXPP_ReturnIntError( PyExc_TypeError, 
447                                         "expected BPy object argument" );
448                 con->tar = obj;
449                 return 0;
450                 }
451         case EXPP_CONSTR_BONE: {
452                 char *name = PyString_AsString( value );
453                 if( !name )
454                         return EXPP_ReturnIntError( PyExc_TypeError,
455                                         "expected string arg" );
456
457                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
458
459                 return 0;
460                 }
461         case EXPP_CONSTR_STRETCH:
462                 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_STRETCH, 'h' );
463         case EXPP_CONSTR_ITERATIONS:
464                 return EXPP_setIValueClamped( value, &con->iterations, 1, 10000, 'h' );
465         case EXPP_CONSTR_CHAINLEN:
466                 return EXPP_setIValueClamped( value, &con->rootbone, 0, 255, 'i' );
467         case EXPP_CONSTR_POSWEIGHT:
468                 return EXPP_setFloatClamped( value, &con->weight, 0.01f, 1.0 );
469         case EXPP_CONSTR_ROTWEIGHT:
470                 return EXPP_setFloatClamped( value, &con->orientweight, 0.01f, 1.0 );
471         case EXPP_CONSTR_ROTATE:
472                 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_ROT, 'h' );
473         case EXPP_CONSTR_USETIP:
474                 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_TIP, 'h' );
475         default:
476                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
477         }
478 }
479
480 static PyObject *action_getter( BPy_Constraint * self, int type )
481 {
482         bActionConstraint *con = (bActionConstraint *)(self->con->data);
483
484         switch( type ) {
485         case EXPP_CONSTR_TARGET:
486                 return Object_CreatePyObject( con->tar );
487         case EXPP_CONSTR_BONE:
488                 return PyString_FromString( con->subtarget );
489         case EXPP_CONSTR_ACTION:
490                 return Action_CreatePyObject( con->act );
491         case EXPP_CONSTR_LOCAL:
492                 return PyBool_FromLong( (long)( con->local & SELECT ) );
493         case EXPP_CONSTR_START:
494                 return PyInt_FromLong( (long)con->start );
495         case EXPP_CONSTR_END:
496                 return PyInt_FromLong( (long)con->end );
497         case EXPP_CONSTR_MIN:
498                 return PyFloat_FromDouble( (double)con->min );
499         case EXPP_CONSTR_MAX:
500                 return PyFloat_FromDouble( (double)con->max );
501         case EXPP_CONSTR_KEYON:
502                 return PyInt_FromLong( (long)con->type );
503         default:
504                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
505         }
506 }
507
508 static int action_setter( BPy_Constraint *self, int type, PyObject *value )
509 {
510         bActionConstraint *con = (bActionConstraint *)(self->con->data);
511
512         switch( type ) {
513         case EXPP_CONSTR_TARGET: {
514                 Object *obj = (( BPy_Object * )value)->object;
515                 if( !BPy_Object_Check( value ) )
516                         return EXPP_ReturnIntError( PyExc_TypeError, 
517                                         "expected BPy object argument" );
518                 con->tar = obj;
519                 return 0;
520                 }
521         case EXPP_CONSTR_BONE: {
522                 char *name = PyString_AsString( value );
523                 if( !name )
524                         return EXPP_ReturnIntError( PyExc_TypeError,
525                                         "expected string arg" );
526
527                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
528
529                 return 0;
530                 }
531         case EXPP_CONSTR_ACTION: {
532                 bAction *act = (( BPy_Action * )value)->action;
533                 if( !BPy_Action_Check( value ) )
534                         return EXPP_ReturnIntError( PyExc_TypeError, 
535                                         "expected BPy action argument" );
536                 con->act = act;
537                 return 0;
538                 }
539         case EXPP_CONSTR_LOCAL:
540                 return EXPP_setBitfield( value, &con->local, SELECT, 'h' );
541         case EXPP_CONSTR_START:
542                 return EXPP_setIValueClamped( value, &con->start, 1, MAXFRAME, 'h' );
543         case EXPP_CONSTR_END:
544                 return EXPP_setIValueClamped( value, &con->end, 1, MAXFRAME, 'h' );
545         case EXPP_CONSTR_MIN:
546                 return EXPP_setFloatClamped( value, &con->min, -180.0, 180.0 );
547         case EXPP_CONSTR_MAX:
548                 return EXPP_setFloatClamped( value, &con->max, -180.0, 180.0 );
549         case EXPP_CONSTR_KEYON:
550                 return EXPP_setIValueRange( value, &con->type,
551                                 EXPP_CONSTR_XROT, EXPP_CONSTR_ZROT, 'h' );
552         default:
553                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
554         }
555 }
556
557 static PyObject *trackto_getter( BPy_Constraint * self, int type )
558 {
559         bTrackToConstraint *con = (bTrackToConstraint *)(self->con->data);
560
561         switch( type ) {
562         case EXPP_CONSTR_TARGET:
563                 return Object_CreatePyObject( con->tar );
564         case EXPP_CONSTR_BONE:
565                 return PyString_FromString( con->subtarget );
566         case EXPP_CONSTR_TRACK:
567                 return PyInt_FromLong( (long)con->reserved1 );
568         case EXPP_CONSTR_UP:
569                 return PyInt_FromLong( (long)con->reserved2 );
570         default:
571                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
572         }
573 }
574
575 static int trackto_setter( BPy_Constraint *self, int type, PyObject *value )
576 {
577         bTrackToConstraint *con = (bTrackToConstraint *)(self->con->data);
578
579         switch( type ) {
580         case EXPP_CONSTR_TARGET: {
581                 Object *obj = (( BPy_Object * )value)->object;
582                 if( !BPy_Object_Check( value ) )
583                         return EXPP_ReturnIntError( PyExc_TypeError, 
584                                         "expected BPy object argument" );
585                 con->tar = obj;
586                 return 0;
587                 }
588         case EXPP_CONSTR_BONE: {
589                 char *name = PyString_AsString( value );
590                 if( !name )
591                         return EXPP_ReturnIntError( PyExc_TypeError,
592                                         "expected string arg" );
593
594                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
595
596                 return 0;
597                 }
598         case EXPP_CONSTR_TRACK:
599                 return EXPP_setIValueRange( value, &con->reserved1,
600                                 TRACK_X, TRACK_nZ, 'i' );
601         case EXPP_CONSTR_UP:
602                 return EXPP_setIValueRange( value, &con->reserved2,
603                                 UP_X, UP_Z, 'i' );
604         default:
605                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
606         }
607 }
608
609 static PyObject *stretchto_getter( BPy_Constraint * self, int type )
610 {
611         bStretchToConstraint *con = (bStretchToConstraint *)(self->con->data);
612
613         switch( type ) {
614         case EXPP_CONSTR_TARGET:
615                 return Object_CreatePyObject( con->tar );
616         case EXPP_CONSTR_BONE:
617                 return PyString_FromString( con->subtarget );
618         case EXPP_CONSTR_RESTLENGTH:
619                 return PyFloat_FromDouble( (double)con->orglength );
620         case EXPP_CONSTR_VOLVARIATION:
621                 return PyFloat_FromDouble( (double)con->bulge );
622         case EXPP_CONSTR_VOLUMEMODE:
623                 return PyInt_FromLong( (long)con->volmode );
624         case EXPP_CONSTR_PLANE:
625                 return PyInt_FromLong( (long)con->plane );
626         default:
627                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
628         }
629 }
630
631 static int stretchto_setter( BPy_Constraint *self, int type, PyObject *value )
632 {
633         bStretchToConstraint *con = (bStretchToConstraint *)(self->con->data);
634
635         switch( type ) {
636         case EXPP_CONSTR_TARGET: {
637                 Object *obj = (( BPy_Object * )value)->object;
638                 if( !BPy_Object_Check( value ) )
639                         return EXPP_ReturnIntError( PyExc_TypeError, 
640                                         "expected BPy object argument" );
641                 con->tar = obj;
642                 return 0;
643                 }
644         case EXPP_CONSTR_BONE: {
645                 char *name = PyString_AsString( value );
646                 if( !name )
647                         return EXPP_ReturnIntError( PyExc_TypeError,
648                                         "expected string arg" );
649
650                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
651
652                 return 0;
653                 }
654         case EXPP_CONSTR_RESTLENGTH:
655                 return EXPP_setFloatClamped( value, &con->orglength, 0.0, 100.0 );
656         case EXPP_CONSTR_VOLVARIATION:
657                 return EXPP_setFloatClamped( value, &con->bulge, 0.0, 100.0 );
658         case EXPP_CONSTR_VOLUMEMODE:
659                 return EXPP_setIValueRange( value, &con->volmode,
660                                 VOLUME_XZ, NO_VOLUME, 'h' );
661         case EXPP_CONSTR_PLANE: {
662                 int status, oldcode = con->plane;
663                 status = EXPP_setIValueRange( value, &con->plane,
664                                 PLANE_X, PLANE_Z, 'h' );
665                 if( !status && con->plane == PLANE_Y ) {
666                         con->plane = oldcode;
667                         return EXPP_ReturnIntError( PyExc_ValueError,
668                                         "value must be either PLANEX or PLANEZ" );
669                 }
670                 return status;
671                 }
672         default:
673                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
674         }
675 }
676
677 static PyObject *followpath_getter( BPy_Constraint * self, int type )
678 {
679         bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
680
681         switch( type ) {
682         case EXPP_CONSTR_TARGET:
683                 return Object_CreatePyObject( con->tar );
684         case EXPP_CONSTR_FOLLOW:
685                 return PyBool_FromLong( (long)( con->followflag & SELECT ) );
686         case EXPP_CONSTR_OFFSET:
687                 return PyFloat_FromDouble( (double)con->offset );
688         case EXPP_CONSTR_FORWARD:
689                 return PyInt_FromLong( (long)con->trackflag );
690         case EXPP_CONSTR_UP:
691                 return PyInt_FromLong( (long)con->upflag );
692         default:
693                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
694         }
695 }
696
697 static int followpath_setter( BPy_Constraint *self, int type, PyObject *value )
698 {
699         bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
700
701         switch( type ) {
702         case EXPP_CONSTR_TARGET: {
703                 Object *obj = (( BPy_Object * )value)->object;
704                 if( !BPy_Object_Check( value ) )
705                         return EXPP_ReturnIntError( PyExc_TypeError, 
706                                         "expected BPy object argument" );
707                 con->tar = obj;
708                 return 0;
709                 }
710         case EXPP_CONSTR_FOLLOW:
711                 return EXPP_setBitfield( value, &con->followflag, SELECT, 'i' );
712         case EXPP_CONSTR_OFFSET:
713                 return EXPP_setFloatClamped( value, &con->offset,
714                                 -MAXFRAMEF, MAXFRAMEF );
715         case EXPP_CONSTR_FORWARD:
716                 return EXPP_setIValueRange( value, &con->trackflag,
717                                 TRACK_X, TRACK_nZ, 'i' );
718         case EXPP_CONSTR_UP:
719                 return EXPP_setIValueRange( value, &con->upflag,
720                                 UP_X, UP_Z, 'i' );
721         default:
722                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
723         }
724 }
725
726 static PyObject *locktrack_getter( BPy_Constraint * self, int type )
727 {
728         bLockTrackConstraint *con = (bLockTrackConstraint *)(self->con->data);
729
730         switch( type ) {
731         case EXPP_CONSTR_TARGET:
732                 return Object_CreatePyObject( con->tar );
733         case EXPP_CONSTR_BONE:
734                 return PyString_FromString( con->subtarget );
735         case EXPP_CONSTR_TRACK:
736                 return PyInt_FromLong( (long)con->trackflag );
737         case EXPP_CONSTR_LOCK:
738                 return PyInt_FromLong( (long)con->lockflag );
739         default:
740                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
741         }
742 }
743
744 static int locktrack_setter( BPy_Constraint *self, int type, PyObject *value )
745 {
746         bLockTrackConstraint *con = (bLockTrackConstraint *)(self->con->data);
747
748         switch( type ) {
749         case EXPP_CONSTR_TARGET: {
750                 Object *obj = (( BPy_Object * )value)->object;
751                 if( !BPy_Object_Check( value ) )
752                         return EXPP_ReturnIntError( PyExc_TypeError, 
753                                         "expected BPy object argument" );
754                 con->tar = obj;
755                 return 0;
756                 }
757         case EXPP_CONSTR_BONE: {
758                 char *name = PyString_AsString( value );
759                 if( !name )
760                         return EXPP_ReturnIntError( PyExc_TypeError,
761                                         "expected string arg" );
762
763                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
764
765                 return 0;
766                 }
767         case EXPP_CONSTR_TRACK:
768                 return EXPP_setIValueRange( value, &con->trackflag,
769                                 TRACK_X, TRACK_nZ, 'i' );
770         case EXPP_CONSTR_LOCK:
771                 return EXPP_setIValueRange( value, &con->lockflag,
772                                 LOCK_X, LOCK_Z, 'i' );
773         default:
774                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
775         }
776 }
777
778 static PyObject *floor_getter( BPy_Constraint * self, int type )
779 {
780         bMinMaxConstraint *con = (bMinMaxConstraint *)(self->con->data);
781
782         switch( type ) {
783         case EXPP_CONSTR_TARGET:
784                 return Object_CreatePyObject( con->tar );
785         case EXPP_CONSTR_BONE:
786                 return PyString_FromString( con->subtarget );
787         case EXPP_CONSTR_MINMAX:
788                 return PyInt_FromLong( (long)con->minmaxflag );
789         case EXPP_CONSTR_OFFSET:
790                 return PyFloat_FromDouble( (double)con->offset );
791         case EXPP_CONSTR_STICKY:
792                 return PyBool_FromLong( (long)( con->flag & MINMAX_STICKY ) ) ;
793         default:
794                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
795         }
796 }
797
798 static int floor_setter( BPy_Constraint *self, int type, PyObject *value )
799 {
800         bMinMaxConstraint *con = (bMinMaxConstraint *)(self->con->data);
801
802         switch( type ) {
803         case EXPP_CONSTR_TARGET: {
804                 Object *obj = (( BPy_Object * )value)->object;
805                 if( !BPy_Object_Check( value ) )
806                         return EXPP_ReturnIntError( PyExc_TypeError, 
807                                         "expected BPy object argument" );
808                 con->tar = obj;
809                 return 0;
810                 }
811         case EXPP_CONSTR_BONE: {
812                 char *name = PyString_AsString( value );
813                 if( !name )
814                         return EXPP_ReturnIntError( PyExc_TypeError,
815                                         "expected string arg" );
816
817                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
818
819                 return 0;
820                 }
821         case EXPP_CONSTR_MINMAX:
822                 return EXPP_setIValueRange( value, &con->minmaxflag,
823                                 EXPP_CONSTR_MAXX, EXPP_CONSTR_MINZ, 'i' );
824         case EXPP_CONSTR_OFFSET:
825                 return EXPP_setFloatClamped( value, &con->offset, -100.0, 100.0 );
826         case EXPP_CONSTR_STICKY:
827                 return EXPP_setBitfield( value, &con->flag, MINMAX_STICKY, 'h' );
828         default:
829                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
830         }
831 }
832
833 static PyObject *locatelike_getter( BPy_Constraint * self, int type )
834 {
835         bLocateLikeConstraint *con = (bLocateLikeConstraint *)(self->con->data);
836
837         switch( type ) {
838         case EXPP_CONSTR_TARGET:
839                 return Object_CreatePyObject( con->tar );
840         case EXPP_CONSTR_BONE:
841                 return PyString_FromString( con->subtarget );
842         case EXPP_CONSTR_COPY:
843                 return PyInt_FromLong( (long)con->flag );
844         case EXPP_CONSTR_LOCAL:
845                 if( get_armature( con->tar ) )
846                         return PyBool_FromLong( (long)
847                                         ( self->con->flag & CONSTRAINT_LOCAL ) ) ;
848                 Py_RETURN_NONE;
849         default:
850                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
851         }
852 }
853
854 static int locatelike_setter( BPy_Constraint *self, int type, PyObject *value )
855 {
856         bLocateLikeConstraint *con = (bLocateLikeConstraint *)(self->con->data);
857
858         switch( type ) {
859         case EXPP_CONSTR_TARGET: {
860                 Object *obj = (( BPy_Object * )value)->object;
861                 if( !BPy_Object_Check( value ) )
862                         return EXPP_ReturnIntError( PyExc_TypeError, 
863                                         "expected BPy object argument" );
864                 con->tar = obj;
865                 return 0;
866                 }
867         case EXPP_CONSTR_BONE: {
868                 char *name = PyString_AsString( value );
869                 if( !name )
870                         return EXPP_ReturnIntError( PyExc_TypeError,
871                                         "expected string arg" );
872
873                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
874
875                 return 0;
876                 }
877         case EXPP_CONSTR_COPY:
878                 return EXPP_setIValueRange( value, &con->flag,
879                                 0, LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z, 'i' );
880         case EXPP_CONSTR_LOCAL:
881                 if( !get_armature( con->tar ) )
882                         return EXPP_ReturnIntError( PyExc_RuntimeError,
883                                         "only armature targets have LOCAL key" );
884                 return EXPP_setBitfield( value, &self->con->flag,
885                                 CONSTRAINT_LOCAL, 'h' );
886         default:
887                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
888         }
889 }
890
891 static PyObject *rotatelike_getter( BPy_Constraint * self, int type )
892 {
893         bRotateLikeConstraint *con = (bRotateLikeConstraint *)(self->con->data);
894
895         switch( type ) {
896         case EXPP_CONSTR_TARGET:
897                 return Object_CreatePyObject( con->tar );
898         case EXPP_CONSTR_BONE:
899                 return PyString_FromString( con->subtarget );
900         case EXPP_CONSTR_COPY:
901                 return PyInt_FromLong( (long)con->flag );
902         case EXPP_CONSTR_LOCAL:
903                 if( get_armature( con->tar ) )
904                         return PyBool_FromLong( (long)
905                                         ( self->con->flag & CONSTRAINT_LOCAL ) ) ;
906                 Py_RETURN_NONE;
907         default:
908                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
909         }
910 }
911
912 static int rotatelike_setter( BPy_Constraint *self, int type, PyObject *value )
913 {
914         bRotateLikeConstraint *con = (bRotateLikeConstraint *)(self->con->data);
915
916         switch( type ) {
917         case EXPP_CONSTR_TARGET: {
918                 Object *obj = (( BPy_Object * )value)->object;
919                 if( !BPy_Object_Check( value ) )
920                         return EXPP_ReturnIntError( PyExc_TypeError, 
921                                         "expected BPy object argument" );
922                 con->tar = obj;
923                 return 0;
924                 }
925         case EXPP_CONSTR_BONE: {
926                 char *name = PyString_AsString( value );
927                 if( !name )
928                         return EXPP_ReturnIntError( PyExc_TypeError,
929                                         "expected string arg" );
930
931                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
932
933                 return 0;
934                 }
935         case EXPP_CONSTR_COPY:
936                 return EXPP_setIValueRange( value, &con->flag,
937                                 0, LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z, 'i' );
938         case EXPP_CONSTR_LOCAL:
939                 if( !get_armature( con->tar ) )
940                         return EXPP_ReturnIntError( PyExc_RuntimeError,
941                                         "only armature targets have LOCAL key" );
942                 return EXPP_setBitfield( value, &self->con->flag,
943                                 CONSTRAINT_LOCAL, 'h' );
944         default:
945                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
946         }
947 }
948
949 static PyObject *sizelike_getter( BPy_Constraint * self, int type )
950 {
951         bSizeLikeConstraint *con = (bSizeLikeConstraint *)(self->con->data);
952
953         switch( type ) {
954         case EXPP_CONSTR_TARGET:
955                 return Object_CreatePyObject( con->tar );
956         case EXPP_CONSTR_BONE:
957                 return PyString_FromString( con->subtarget );
958         case EXPP_CONSTR_COPY:
959                 return PyInt_FromLong( (long)con->flag );
960 #if 0
961         case EXPP_CONSTR_LOCAL:
962                 if( get_armature( con->tar ) )
963                         return PyBool_FromLong( (long)
964                                         ( self->con->flag & CONSTRAINT_LOCAL ) ) ;
965                 Py_RETURN_NONE;
966 #endif
967         default:
968                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
969         }
970 }
971
972 static int sizelike_setter( BPy_Constraint *self, int type, PyObject *value )
973 {
974         bSizeLikeConstraint *con = (bSizeLikeConstraint *)(self->con->data);
975
976         switch( type ) {
977         case EXPP_CONSTR_TARGET: {
978                 Object *obj = (( BPy_Object * )value)->object;
979                 if( !BPy_Object_Check( value ) )
980                         return EXPP_ReturnIntError( PyExc_TypeError, 
981                                         "expected BPy object argument" );
982                 con->tar = obj;
983                 return 0;
984                 }
985         case EXPP_CONSTR_BONE: {
986                 char *name = PyString_AsString( value );
987                 if( !name )
988                         return EXPP_ReturnIntError( PyExc_TypeError,
989                                         "expected string arg" );
990
991                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
992
993                 return 0;
994                 }
995         case EXPP_CONSTR_COPY:
996                 return EXPP_setIValueRange( value, &con->flag,
997                                 0, LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z, 'i' );
998 #if 0
999         case EXPP_CONSTR_LOCAL:
1000                 if( !get_armature( con->tar ) )
1001                         return EXPP_ReturnIntError( PyExc_RuntimeError,
1002                                         "only armature targets have LOCAL key" );
1003                 return EXPP_setBitfield( value, &self->con->flag,
1004                                 CONSTRAINT_LOCAL, 'h' );
1005 #endif
1006         default:
1007                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1008         }
1009 }
1010
1011 static PyObject *loclimit_getter( BPy_Constraint * self, int type)
1012 {
1013         bLocLimitConstraint *con = (bLocLimitConstraint *)(self->con->data);
1014
1015         switch( type ) {
1016         case EXPP_CONSTR_LIMIT:
1017                 return PyInt_FromLong( (long)con->flag );
1018         case EXPP_CONSTR_LIMLOCALBONE:
1019                 return PyBool_FromLong( (long)
1020                                         ( self->con->flag & CONSTRAINT_LOCAL ) ) ;
1021         case EXPP_CONSTR_LIMLOCALNOPAR:
1022                 return PyBool_FromLong( (long)
1023                                         ( con->flag2 & LIMIT_NOPARENT ) ) ;
1024         case EXPP_CONSTR_XMIN:
1025                 return PyFloat_FromDouble( (double)con->xmin );
1026         case EXPP_CONSTR_XMAX:
1027                 return PyFloat_FromDouble( (double)con->xmax );
1028         case EXPP_CONSTR_YMIN:
1029                 return PyFloat_FromDouble( (double)con->ymin );
1030         case EXPP_CONSTR_YMAX:
1031                 return PyFloat_FromDouble( (double)con->ymax );
1032         case EXPP_CONSTR_ZMIN:
1033                 return PyFloat_FromDouble( (double)con->zmin );
1034         case EXPP_CONSTR_ZMAX:
1035                 return PyFloat_FromDouble( (double)con->zmax );
1036         default:
1037                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1038         }
1039 }
1040
1041 static int loclimit_setter( BPy_Constraint *self, int type, PyObject *value )
1042 {
1043         bLocLimitConstraint *con = (bLocLimitConstraint *)(self->con->data);    
1044         
1045         switch( type ) {
1046         case EXPP_CONSTR_LIMIT:
1047                 return EXPP_setIValueRange( value, &con->flag, 0, 
1048                         LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX , 'i' );
1049         case EXPP_CONSTR_LIMLOCALBONE:
1050                 return EXPP_setBitfield( value, &self->con->flag,
1051                                 CONSTRAINT_LOCAL, 'h' );
1052         case EXPP_CONSTR_LIMLOCALNOPAR:
1053                 return EXPP_setBitfield( value, &con->flag2,
1054                                 LIMIT_NOPARENT, 'h' );
1055         case EXPP_CONSTR_XMIN:
1056                 return EXPP_setFloatClamped( value, &con->xmin, -1000.0, 1000.0 );
1057         case EXPP_CONSTR_XMAX:
1058                 return EXPP_setFloatClamped( value, &con->xmax, -1000.0, 1000.0 );
1059         case EXPP_CONSTR_YMIN:
1060                 return EXPP_setFloatClamped( value, &con->ymin, -1000.0, 1000.0 );
1061         case EXPP_CONSTR_YMAX:
1062                 return EXPP_setFloatClamped( value, &con->ymax, -1000.0, 1000.0 );
1063         case EXPP_CONSTR_ZMIN:
1064                 return EXPP_setFloatClamped( value, &con->zmin, -1000.0, 1000.0 );
1065         case EXPP_CONSTR_ZMAX:
1066                 return EXPP_setFloatClamped( value, &con->zmax, -1000.0, 1000.0 );
1067         default:
1068                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1069         }
1070 }
1071
1072 static PyObject *rotlimit_getter( BPy_Constraint * self, int type )
1073 {
1074         bRotLimitConstraint *con = (bRotLimitConstraint *)(self->con->data);
1075
1076         switch( type ) {
1077         case EXPP_CONSTR_LIMIT:
1078                 return PyInt_FromLong( (long)con->flag );
1079         case EXPP_CONSTR_LIMLOCALBONE:
1080                 return PyBool_FromLong( (long)
1081                                         (self->con->flag & CONSTRAINT_LOCAL ) ); 
1082         case EXPP_CONSTR_XMIN:
1083                 return PyFloat_FromDouble( (double)con->xmin );
1084         case EXPP_CONSTR_XMAX:
1085                 return PyFloat_FromDouble( (double)con->xmax );
1086         case EXPP_CONSTR_YMIN:
1087                 return PyFloat_FromDouble( (double)con->ymin );
1088         case EXPP_CONSTR_YMAX:
1089                 return PyFloat_FromDouble( (double)con->ymax );
1090         case EXPP_CONSTR_ZMIN:
1091                 return PyFloat_FromDouble( (double)con->zmin );
1092         case EXPP_CONSTR_ZMAX:
1093                 return PyFloat_FromDouble( (double)con->zmax );
1094         default:
1095                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1096         }
1097 }
1098
1099 static int rotlimit_setter( BPy_Constraint *self, int type, PyObject *value )
1100 {
1101         bRotLimitConstraint *con = (bRotLimitConstraint *)(self->con->data);    
1102         
1103         switch( type ) {
1104         case EXPP_CONSTR_LIMIT:
1105                 return EXPP_setIValueRange( value, &con->flag, 0, 
1106                         LIMIT_XROT | LIMIT_YROT | LIMIT_ZROT, 'i' );
1107         case EXPP_CONSTR_LIMLOCALBONE:
1108                 return EXPP_setBitfield( value, &self->con->flag,
1109                                 CONSTRAINT_LOCAL, 'h' );
1110         case EXPP_CONSTR_XMIN:
1111                 return EXPP_setFloatClamped( value, &con->xmin, -360.0, 360.0 );
1112         case EXPP_CONSTR_XMAX:
1113                 return EXPP_setFloatClamped( value, &con->xmax, -360.0, 360.0 );
1114         case EXPP_CONSTR_YMIN:
1115                 return EXPP_setFloatClamped( value, &con->ymin, -360.0, 360.0 );
1116         case EXPP_CONSTR_YMAX:
1117                 return EXPP_setFloatClamped( value, &con->ymax, -360.0, 360.0 );
1118         case EXPP_CONSTR_ZMIN:
1119                 return EXPP_setFloatClamped( value, &con->zmin, -360.0, 360.0 );
1120         case EXPP_CONSTR_ZMAX:
1121                 return EXPP_setFloatClamped( value, &con->zmax, -360.0, 360.0 );
1122         default:
1123                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1124         }
1125 }
1126
1127 static PyObject *sizelimit_getter( BPy_Constraint * self, int type)
1128 {
1129         bSizeLimitConstraint *con = (bSizeLimitConstraint *)(self->con->data);
1130
1131         switch( type ) {
1132         case EXPP_CONSTR_LIMIT:
1133                 return PyInt_FromLong( (long)con->flag );
1134         case EXPP_CONSTR_XMIN:
1135                 return PyFloat_FromDouble( (double)con->xmin );
1136         case EXPP_CONSTR_XMAX:
1137                 return PyFloat_FromDouble( (double)con->xmax );
1138         case EXPP_CONSTR_YMIN:
1139                 return PyFloat_FromDouble( (double)con->ymin );
1140         case EXPP_CONSTR_YMAX:
1141                 return PyFloat_FromDouble( (double)con->ymax );
1142         case EXPP_CONSTR_ZMIN:
1143                 return PyFloat_FromDouble( (double)con->zmin );
1144         case EXPP_CONSTR_ZMAX:
1145                 return PyFloat_FromDouble( (double)con->zmax );
1146         default:
1147                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1148         }
1149 }
1150
1151 static int sizelimit_setter( BPy_Constraint *self, int type, PyObject *value )
1152 {
1153         bSizeLimitConstraint *con = (bSizeLimitConstraint *)(self->con->data);  
1154         
1155         switch( type ) {
1156         case EXPP_CONSTR_LIMIT:
1157                 return EXPP_setIValueRange( value, &con->flag, 0, 
1158                         LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
1159         case EXPP_CONSTR_XMIN:
1160                 return EXPP_setFloatClamped( value, &con->xmin, -1000.0, 1000.0 );
1161         case EXPP_CONSTR_XMAX:
1162                 return EXPP_setFloatClamped( value, &con->xmax, -1000.0, 1000.0 );
1163         case EXPP_CONSTR_YMIN:
1164                 return EXPP_setFloatClamped( value, &con->ymin, -1000.0, 1000.0 );
1165         case EXPP_CONSTR_YMAX:
1166                 return EXPP_setFloatClamped( value, &con->ymax, -1000.0, 1000.0 );
1167         case EXPP_CONSTR_ZMIN:
1168                 return EXPP_setFloatClamped( value, &con->zmin, -1000.0, 1000.0 );
1169         case EXPP_CONSTR_ZMAX:
1170                 return EXPP_setFloatClamped( value, &con->zmax, -1000.0, 1000.0 );
1171         default:
1172                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1173         }
1174 }
1175
1176
1177 static PyObject *rigidbody_getter( BPy_Constraint * self, int type)
1178 {
1179         bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);
1180
1181         switch( type ) {
1182         case EXPP_CONSTR_TARGET:
1183                 return Object_CreatePyObject( con->tar );
1184         case EXPP_CONSTR_RB_PIVX:
1185                 return PyFloat_FromDouble( (double)con->pivX );
1186         case EXPP_CONSTR_RB_PIVY:
1187                 return PyFloat_FromDouble( (double)con->pivY );
1188         case EXPP_CONSTR_RB_PIVZ:
1189                 return PyFloat_FromDouble( (double)con->pivZ );
1190         case EXPP_CONSTR_RB_AXX:
1191                 return PyFloat_FromDouble( (double)con->axX );
1192         case EXPP_CONSTR_RB_AXY:
1193                 return PyFloat_FromDouble( (double)con->axY );
1194         case EXPP_CONSTR_RB_AXZ:
1195                 return PyFloat_FromDouble( (double)con->axZ );
1196         case EXPP_CONSTR_RB_MINLIMIT0:
1197                 return PyFloat_FromDouble( (double)con->minLimit[0] );
1198         case EXPP_CONSTR_RB_MINLIMIT1:
1199                 return PyFloat_FromDouble( (double)con->minLimit[1] );
1200         case EXPP_CONSTR_RB_MINLIMIT2:
1201                 return PyFloat_FromDouble( (double)con->minLimit[2] );
1202         case EXPP_CONSTR_RB_MINLIMIT3:
1203                 return PyFloat_FromDouble( (double)con->minLimit[3] );
1204         case EXPP_CONSTR_RB_MINLIMIT4:
1205                 return PyFloat_FromDouble( (double)con->minLimit[4] );
1206         case EXPP_CONSTR_RB_MINLIMIT5:
1207                 return PyFloat_FromDouble( (double)con->minLimit[5] );
1208         case EXPP_CONSTR_RB_MAXLIMIT0:
1209                 return PyFloat_FromDouble( (double)con->maxLimit[0] );
1210         case EXPP_CONSTR_RB_MAXLIMIT1:
1211                 return PyFloat_FromDouble( (double)con->maxLimit[1] );
1212         case EXPP_CONSTR_RB_MAXLIMIT2:
1213                 return PyFloat_FromDouble( (double)con->maxLimit[2] );
1214         case EXPP_CONSTR_RB_MAXLIMIT3:
1215                 return PyFloat_FromDouble( (double)con->maxLimit[3] );
1216         case EXPP_CONSTR_RB_MAXLIMIT4:
1217                 return PyFloat_FromDouble( (double)con->maxLimit[4] );
1218         case EXPP_CONSTR_RB_MAXLIMIT5:
1219                 return PyFloat_FromDouble( (double)con->maxLimit[5] );
1220         case EXPP_CONSTR_RB_EXTRAFZ:
1221                 return PyFloat_FromDouble( (double)con->extraFz );              
1222         case EXPP_CONSTR_LIMIT:
1223                 return PyInt_FromLong( (int)con->flag );
1224                 
1225         case EXPP_CONSTR_RB_TYPE:
1226                 return PyInt_FromLong( (int)con->type );
1227         default:
1228                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1229         }
1230 }
1231
1232
1233 static int rigidbody_setter( BPy_Constraint *self, int type, PyObject *value )
1234 {
1235         bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);        
1236         
1237         switch( type ) {
1238         case EXPP_CONSTR_TARGET: {
1239                 Object *obj = (( BPy_Object * )value)->object;
1240                 if( !BPy_Object_Check( value ) )
1241                         return EXPP_ReturnIntError( PyExc_TypeError, 
1242                                         "expected BPy object argument" );
1243                 con->tar = obj;
1244                 return 0;
1245                 }
1246         case EXPP_CONSTR_RB_PIVX:
1247                 return EXPP_setFloatClamped( value, &con->pivX , -1000.0, 1000.0 );
1248         case EXPP_CONSTR_RB_PIVY:
1249                 return EXPP_setFloatClamped( value, &con->pivY , -1000.0, 1000.0 );
1250         case EXPP_CONSTR_RB_PIVZ:
1251                 return EXPP_setFloatClamped( value, &con->pivZ , -1000.0, 1000.0 );
1252         case EXPP_CONSTR_RB_AXX:
1253                 return EXPP_setFloatClamped( value, &con->axX , -1000.0, 1000.0 );
1254         case EXPP_CONSTR_RB_AXY:
1255                 return EXPP_setFloatClamped( value, &con->axY , -1000.0, 1000.0 );
1256         case EXPP_CONSTR_RB_AXZ:
1257                 return EXPP_setFloatClamped( value, &con->axZ , -1000.0, 1000.0 );
1258         case EXPP_CONSTR_RB_MINLIMIT0:
1259                 return EXPP_setFloatClamped( value, &con->minLimit[0] , -1000.0, 1000.0 );
1260         case EXPP_CONSTR_RB_MINLIMIT1:
1261                 return EXPP_setFloatClamped( value, &con->minLimit[1] , -1000.0, 1000.0 );
1262         case EXPP_CONSTR_RB_MINLIMIT2:
1263                 return EXPP_setFloatClamped( value, &con->minLimit[2] , -1000.0, 1000.0 );
1264         case EXPP_CONSTR_RB_MINLIMIT3:
1265                 return EXPP_setFloatClamped( value, &con->minLimit[3] , -1000.0, 1000.0 );
1266         case EXPP_CONSTR_RB_MINLIMIT4:
1267                 return EXPP_setFloatClamped( value, &con->minLimit[4] , -1000.0, 1000.0 );
1268         case EXPP_CONSTR_RB_MINLIMIT5:
1269                 return EXPP_setFloatClamped( value, &con->minLimit[5] , -1000.0, 1000.0 );
1270         case EXPP_CONSTR_RB_MAXLIMIT0:
1271                 return EXPP_setFloatClamped( value, &con->maxLimit[0] , -1000.0, 1000.0 );
1272         case EXPP_CONSTR_RB_MAXLIMIT1:
1273                 return EXPP_setFloatClamped( value, &con->maxLimit[1] , -1000.0, 1000.0 );
1274         case EXPP_CONSTR_RB_MAXLIMIT2:
1275                 return EXPP_setFloatClamped( value, &con->maxLimit[2] , -1000.0, 1000.0 );
1276         case EXPP_CONSTR_RB_MAXLIMIT3:
1277                 return EXPP_setFloatClamped( value, &con->maxLimit[3] , -1000.0, 1000.0 );
1278         case EXPP_CONSTR_RB_MAXLIMIT4:
1279                 return EXPP_setFloatClamped( value, &con->maxLimit[4] , -1000.0, 1000.0 );
1280         case EXPP_CONSTR_RB_MAXLIMIT5:
1281                 return EXPP_setFloatClamped( value, &con->maxLimit[5] , -1000.0, 1000.0 );
1282         case EXPP_CONSTR_RB_EXTRAFZ:
1283                 return EXPP_setFloatClamped( value, &con->extraFz , -1000.0, 1000.0 );                                          
1284         case EXPP_CONSTR_LIMIT:
1285                 return EXPP_setIValueRange( value, &con->flag, 0, 
1286                         LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
1287         case EXPP_CONSTR_RB_TYPE:
1288                 return EXPP_setIValueRange( value, &con->type, 0, 
1289                         EXPP_CONSTR_RB_BALL | EXPP_CONSTR_RB_HINGE | EXPP_CONSTR_RB_GENERIC6DOF | EXPP_CONSTR_RB_VEHICLE, 'i' );
1290         default:
1291                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1292         }
1293 }
1294
1295 /*
1296  * get data from a constraint
1297  */
1298
1299 static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key )
1300 {
1301         int setting;
1302
1303         if( !PyInt_CheckExact( key ) )
1304                 return EXPP_ReturnPyObjError( PyExc_TypeError,
1305                                 "expected an int arg" );
1306
1307         if( !self->con )
1308                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1309                                 "This constraint has been removed!" );
1310         
1311         setting = PyInt_AsLong( key );
1312         switch( self->con->type ) {
1313                 case CONSTRAINT_TYPE_NULL:
1314                         Py_RETURN_NONE;
1315                 case CONSTRAINT_TYPE_TRACKTO:
1316                         return trackto_getter( self, setting );
1317                 case CONSTRAINT_TYPE_KINEMATIC:
1318                         return kinematic_getter( self, setting );
1319                 case CONSTRAINT_TYPE_FOLLOWPATH:
1320                         return followpath_getter( self, setting );
1321                 case CONSTRAINT_TYPE_ACTION:
1322                         return action_getter( self, setting );
1323                 case CONSTRAINT_TYPE_LOCKTRACK:
1324                         return locktrack_getter( self, setting );
1325                 case CONSTRAINT_TYPE_STRETCHTO:
1326                         return stretchto_getter( self, setting );
1327                 case CONSTRAINT_TYPE_MINMAX:
1328                         return floor_getter( self, setting );
1329                 case CONSTRAINT_TYPE_LOCLIKE:
1330                         return locatelike_getter( self, setting );
1331                 case CONSTRAINT_TYPE_ROTLIKE:
1332                         return rotatelike_getter( self, setting );
1333                 case CONSTRAINT_TYPE_SIZELIKE:
1334                         return sizelike_getter( self, setting );
1335                 case CONSTRAINT_TYPE_ROTLIMIT:
1336                         return rotlimit_getter( self, setting );
1337                 case CONSTRAINT_TYPE_LOCLIMIT:
1338                         return loclimit_getter( self, setting );
1339                 case CONSTRAINT_TYPE_SIZELIMIT:
1340                         return sizelimit_getter( self, setting );
1341                 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1342                         return rigidbody_getter( self, setting );
1343                 case CONSTRAINT_TYPE_CHILDOF:   /* Unimplemented */
1344                 case CONSTRAINT_TYPE_PYTHON:
1345                 default:
1346                         return EXPP_ReturnPyObjError( PyExc_KeyError,
1347                                         "unknown constraint type" );
1348         }
1349 }
1350
1351 static int Constraint_setData( BPy_Constraint * self, PyObject * key, 
1352                 PyObject * arg )
1353 {
1354         int key_int, result;
1355
1356         if( !PyNumber_Check( key ) )
1357                 return EXPP_ReturnIntError( PyExc_TypeError,
1358                                 "expected an int arg" );
1359         if( !self->con )
1360                 return EXPP_ReturnIntError( PyExc_RuntimeError,
1361                                 "This constraint has been removed!" );
1362         
1363         key_int = PyInt_AsLong( key );
1364         switch( self->con->type ) {
1365         case CONSTRAINT_TYPE_KINEMATIC:
1366                 result = kinematic_setter( self, key_int, arg );
1367                 break;
1368         case CONSTRAINT_TYPE_ACTION:
1369                 result = action_setter( self, key_int, arg );
1370                 break;
1371         case CONSTRAINT_TYPE_TRACKTO:
1372                 result = trackto_setter( self, key_int, arg );
1373                 break;
1374         case CONSTRAINT_TYPE_STRETCHTO:
1375                 result = stretchto_setter( self, key_int, arg );
1376                 break;
1377         case CONSTRAINT_TYPE_FOLLOWPATH:
1378                 result = followpath_setter( self, key_int, arg );
1379                 break;
1380         case CONSTRAINT_TYPE_LOCKTRACK:
1381                 result = locktrack_setter( self, key_int, arg );
1382                 break;
1383         case CONSTRAINT_TYPE_MINMAX:
1384                 result = floor_setter( self, key_int, arg );
1385                 break;
1386         case CONSTRAINT_TYPE_LOCLIKE:
1387                 result = locatelike_setter( self, key_int, arg );
1388                 break;
1389         case CONSTRAINT_TYPE_ROTLIKE:
1390                 result = rotatelike_setter( self, key_int, arg );
1391                 break;
1392         case CONSTRAINT_TYPE_SIZELIKE:
1393                 result = sizelike_setter( self, key_int, arg );
1394                 break;
1395         case CONSTRAINT_TYPE_ROTLIMIT:
1396                 result = rotlimit_setter( self, key_int, arg );
1397                 break;
1398         case CONSTRAINT_TYPE_LOCLIMIT:
1399                 result = loclimit_setter( self, key_int, arg );
1400                 break;
1401         case CONSTRAINT_TYPE_SIZELIMIT:
1402                 result = sizelimit_setter( self, key_int, arg);
1403                 break;
1404         case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1405                 result = rigidbody_setter( self, key_int, arg);
1406                 break;
1407         case CONSTRAINT_TYPE_NULL:
1408                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1409         case CONSTRAINT_TYPE_CHILDOF:   /* Unimplemented */
1410         case CONSTRAINT_TYPE_PYTHON:
1411         default:
1412                 return EXPP_ReturnIntError( PyExc_RuntimeError,
1413                                 "unsupported constraint setting" );
1414         }
1415         if( !result && self->pchan )
1416                 update_pose_constraint_flags( self->obj->pose );
1417         return result;
1418 }
1419
1420 /*****************************************************************************/
1421 /* Function:    Constraint_compare                                           */
1422 /* Description: This compares 2 constraint python types, == or != only.      */
1423 /*****************************************************************************/
1424 static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b )
1425 {
1426         return ( a->con == b->con ) ? 0 : -1;
1427 }
1428
1429 /*****************************************************************************/
1430 /* Function:    Constraint_repr                                              */
1431 /* Description: This is a callback function for the BPy_Constraint type. It  */
1432 /*              builds a meaningful string to represent constraint objects.  */
1433 /*****************************************************************************/
1434
1435 static PyObject *Constraint_repr( BPy_Constraint * self )
1436 {
1437         char type[32];
1438
1439         if( !self->con )
1440                 return PyString_FromString( "[Constraint - Removed]");
1441
1442         get_constraint_typestring (type,  self->con);
1443         return PyString_FromFormat( "[Constraint \"%s\", Type \"%s\"]",
1444                         self->con->name, type );
1445 }
1446
1447 /* Three Python Constraint_Type helper functions needed by the Object module: */
1448
1449 /*****************************************************************************/
1450 /* Function:    Constraint_CreatePyObject                                    */
1451 /* Description: This function will create a new BPy_Constraint from an       */
1452 /*              existing Blender constraint structure.                       */
1453 /*****************************************************************************/
1454 PyObject *Constraint_CreatePyObject( bPoseChannel *pchan, Object *obj,
1455                 bConstraint *con )
1456 {
1457         BPy_Constraint *pycon;
1458         pycon = ( BPy_Constraint * ) PyObject_NEW( BPy_Constraint,
1459                         &Constraint_Type );
1460         if( !pycon )
1461                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1462                                               "couldn't create BPy_Constraint object" );
1463
1464         pycon->con = con;
1465
1466         /* one of these two will be NULL */
1467         pycon->obj = obj;       
1468         pycon->pchan = pchan;
1469         return ( PyObject * ) pycon;
1470 }
1471
1472 /*****************************************************************************/
1473 /* Function:    Constraint_FromPyObject                                      */
1474 /* Description: This function returns the Blender constraint from the given  */
1475 /*              PyObject.                                                    */
1476 /*****************************************************************************/
1477 bConstraint *Constraint_FromPyObject( BPy_Constraint * self )
1478 {
1479         return self->con;
1480 }
1481
1482 /*****************************************************************************/
1483 /* Constraint Sequence wrapper                                               */
1484 /*****************************************************************************/
1485
1486 /*
1487  * Initialize the interator
1488  */
1489
1490 static PyObject *ConstraintSeq_getIter( BPy_ConstraintSeq * self )
1491 {
1492         if( self->pchan )
1493                 self->iter = (bConstraint *)self->pchan->constraints.first;
1494         else
1495                 self->iter = (bConstraint *)self->obj->constraints.first;
1496         return EXPP_incr_ret ( (PyObject *) self );
1497 }
1498
1499 /*
1500  * Get the next Constraint
1501  */
1502
1503 static PyObject *ConstraintSeq_nextIter( BPy_ConstraintSeq * self )
1504 {
1505         bConstraint *this = self->iter;
1506         if( this ) {
1507                 self->iter = this->next;
1508                 return Constraint_CreatePyObject( self->pchan, self->obj, this );
1509         }
1510
1511         return EXPP_ReturnPyObjError( PyExc_StopIteration,
1512                         "iterator at end" );
1513 }
1514
1515 /* return the number of constraints */
1516
1517 static int ConstraintSeq_length( BPy_ConstraintSeq * self )
1518 {
1519         return BLI_countlist( self->pchan ?
1520                 &self->pchan->constraints : &self->obj->constraints );
1521 }
1522
1523 /* return a constraint */
1524
1525 static PyObject *ConstraintSeq_item( BPy_ConstraintSeq * self, int i )
1526 {
1527         bConstraint *con = NULL;
1528
1529         /* if index is negative, start counting from the end of the list */
1530         if( i < 0 )
1531                 i += ConstraintSeq_length( self );
1532
1533         /* skip through the list until we get the constraint or end of list */
1534
1535         if( self->pchan )
1536                 con = self->pchan->constraints.first;
1537         else
1538                 con = self->obj->constraints.first;
1539
1540         while( i && con ) {
1541                 --i;
1542                 con = con->next;
1543         }
1544
1545         if( con )
1546                 return Constraint_CreatePyObject( self->pchan, self->obj, con );
1547         else
1548                 return EXPP_ReturnPyObjError( PyExc_IndexError,
1549                                 "array index out of range" );
1550 }
1551
1552 /*****************************************************************************/
1553 /* Python BPy_ConstraintSeq sequence table:                                  */
1554 /*****************************************************************************/
1555 static PySequenceMethods ConstraintSeq_as_sequence = {
1556         ( inquiry ) ConstraintSeq_length,       /* sq_length */
1557         ( binaryfunc ) 0,       /* sq_concat */
1558         ( intargfunc ) 0,       /* sq_repeat */
1559         ( intargfunc ) ConstraintSeq_item,      /* sq_item */
1560         ( intintargfunc ) 0,    /* sq_slice */
1561         ( intobjargproc ) 0,    /* sq_ass_item */
1562         ( intintobjargproc ) 0, /* sq_ass_slice */
1563         ( objobjproc ) 0,       /* sq_contains */
1564         ( binaryfunc ) 0,               /* sq_inplace_concat */
1565         ( intargfunc ) 0,               /* sq_inplace_repeat */
1566 };
1567
1568 /*
1569  * helper function to check for a valid constraint argument
1570  */
1571
1572 static bConstraint *locate_constr( BPy_ConstraintSeq *self, PyObject * args )
1573 {
1574         BPy_Constraint *pyobj;
1575         bConstraint *con;
1576
1577         /* check that argument is a modifier */
1578         if( !PyArg_ParseTuple( args, "O!", &Constraint_Type, &pyobj ) )
1579                 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_TypeError,
1580                                 "expected a constraint as an argument" );
1581
1582         /* check whether constraint has been removed */
1583         if( !pyobj->con )
1584                 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_RuntimeError,
1585                                 "This constraint has been removed!" );
1586
1587         /* verify the constraint is still exists in the stack */
1588         if( self->pchan )
1589                 con = self->pchan->constraints.first;
1590         else
1591                 con = self->obj->constraints.first;
1592         while( con && con != pyobj->con )
1593                 con = con->next;
1594
1595         /* if we didn't find it, exception */
1596         if( !con )
1597                 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_AttributeError,
1598                                 "This constraint is no longer in the object's stack" );
1599
1600         return con;
1601 }
1602
1603
1604 /* create a new constraint at the end of the list */
1605
1606 static PyObject *ConstraintSeq_append( BPy_ConstraintSeq *self, PyObject *args )
1607 {
1608         int type;
1609         bConstraint *con;
1610
1611         if( !PyArg_ParseTuple( args, "i", &type ) )
1612                 EXPP_ReturnPyObjError( PyExc_TypeError, "expected int argument" );
1613
1614         /* type 0 is CONSTRAINT_TYPE_NULL, should we be able to add one of these? */
1615         if( type < CONSTRAINT_TYPE_NULL || type > CONSTRAINT_TYPE_RIGIDBODYJOINT ) 
1616                 return EXPP_ReturnPyObjError( PyExc_ValueError,
1617                                 "int argument out of range" );
1618
1619         con = add_new_constraint( type );
1620         if( self->pchan ) {
1621                 BLI_addtail( &self->pchan->constraints, con );
1622                 update_pose_constraint_flags( self->obj->pose );
1623         }
1624         else
1625                 BLI_addtail( &self->obj->constraints, con );
1626
1627         return Constraint_CreatePyObject( self->pchan, self->obj, con );
1628 }
1629
1630 /* move the constraint up in the stack */
1631
1632 static PyObject *ConstraintSeq_moveUp( BPy_ConstraintSeq *self, PyObject *args )
1633 {
1634         bConstraint *con = locate_constr( self,  args );
1635
1636         /* if we can't locate the constraint, return (exception already set) */
1637         if( !con )
1638                 return (PyObject *)NULL;
1639
1640         const_moveUp( self->obj, con );
1641         Py_RETURN_NONE;
1642 }
1643
1644 /* move the constraint down in the stack */
1645
1646 static PyObject *ConstraintSeq_moveDown( BPy_ConstraintSeq *self, PyObject *args )
1647 {
1648         bConstraint *con = locate_constr( self,  args );
1649
1650         /* if we can't locate the constraint, return (exception already set) */
1651         if( !con )
1652                 return (PyObject *)NULL;
1653
1654         const_moveDown( self->obj, con );
1655         Py_RETURN_NONE;
1656 }
1657
1658 /* remove an existing constraint */
1659
1660 static PyObject *ConstraintSeq_remove( BPy_ConstraintSeq *self, PyObject *args )
1661 {
1662         BPy_Constraint *pyobj;
1663         bConstraint *con = locate_constr( self,  args );
1664
1665         /* if we can't locate the constraint, return (exception already set) */
1666         if( !con )
1667                 return (PyObject *)NULL;
1668
1669         /* do the actual removal */
1670         if( self->pchan )
1671                 BLI_remlink( &self->pchan->constraints, con );
1672         else
1673                 BLI_remlink( &self->obj->constraints, con);
1674         del_constr_func( self->obj, con );
1675
1676         /* erase the link to the constraint */
1677         pyobj = ( BPy_Constraint * )PyTuple_GET_ITEM( args, 0 );
1678         pyobj->con = NULL;
1679
1680         Py_RETURN_NONE;
1681 }
1682
1683 /*****************************************************************************/
1684 /* Function:    ConstraintSeq_dealloc                                        */
1685 /* Description: This is a callback function for the BPy_ConstraintSeq type.  */
1686 /*              It destroys data when the object is deleted.                 */
1687 /*****************************************************************************/
1688 static void ConstraintSeq_dealloc( BPy_Constraint * self )
1689 {
1690         PyObject_DEL( self );
1691 }
1692
1693 /*****************************************************************************/
1694 /* Python BPy_ConstraintSeq methods table:                                   */
1695 /*****************************************************************************/
1696 static PyMethodDef BPy_ConstraintSeq_methods[] = {
1697         /* name, method, flags, doc */
1698         {"append", ( PyCFunction ) ConstraintSeq_append, METH_VARARGS,
1699          "(type) - add a new constraint, where type is the constraint type"},
1700         {"remove", ( PyCFunction ) ConstraintSeq_remove, METH_VARARGS,
1701          "(con) - remove an existing constraint, where con is a constraint from this object."},
1702         {"moveUp", ( PyCFunction ) ConstraintSeq_moveUp, METH_VARARGS,
1703          "(con) - Move constraint up in stack"},
1704         {"moveDown", ( PyCFunction ) ConstraintSeq_moveDown, METH_VARARGS,
1705          "(con) - Move constraint down in stack"},
1706         {NULL, NULL, 0, NULL}
1707 };
1708
1709 /*****************************************************************************/
1710 /* Python ConstraintSeq_Type structure definition:                           */
1711 /*****************************************************************************/
1712 PyTypeObject ConstraintSeq_Type = {
1713         PyObject_HEAD_INIT( NULL )  /* required py macro */
1714         0,                          /* ob_size */
1715         /*  For printing, in format "<module>.<name>" */
1716         "Blender.Constraints",      /* char *tp_name; */
1717         sizeof( BPy_ConstraintSeq ),     /* int tp_basicsize; */
1718         0,                          /* tp_itemsize;  For allocation */
1719
1720         /* Methods to implement standard operations */
1721
1722         ( destructor ) ConstraintSeq_dealloc,/* destructor tp_dealloc; */
1723         NULL,                       /* printfunc tp_print; */
1724         NULL,                       /* getattrfunc tp_getattr; */
1725         NULL,                       /* setattrfunc tp_setattr; */
1726         NULL,                       /* cmpfunc tp_compare; */
1727         ( reprfunc ) NULL,          /* reprfunc tp_repr; */
1728
1729         /* Method suites for standard classes */
1730
1731         NULL,                       /* PyNumberMethods *tp_as_number; */
1732         &ConstraintSeq_as_sequence,        /* PySequenceMethods *tp_as_sequence; */
1733         NULL,                       /* PyMappingMethods *tp_as_mapping; */
1734
1735         /* More standard operations (here for binary compatibility) */
1736
1737         NULL,                       /* hashfunc tp_hash; */
1738         NULL,                       /* ternaryfunc tp_call; */
1739         NULL,                       /* reprfunc tp_str; */
1740         NULL,                       /* getattrofunc tp_getattro; */
1741         NULL,                       /* setattrofunc tp_setattro; */
1742
1743         /* Functions to access object as input/output buffer */
1744         NULL,                       /* PyBufferProcs *tp_as_buffer; */
1745
1746   /*** Flags to define presence of optional/expanded features ***/
1747         Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
1748
1749         NULL,                       /*  char *tp_doc;  Documentation string */
1750   /*** Assigned meaning in release 2.0 ***/
1751         /* call function for all accessible objects */
1752         NULL,                       /* traverseproc tp_traverse; */
1753
1754         /* delete references to contained objects */
1755         NULL,                       /* inquiry tp_clear; */
1756
1757   /***  Assigned meaning in release 2.1 ***/
1758   /*** rich comparisons ***/
1759         NULL,                       /* richcmpfunc tp_richcompare; */
1760
1761   /***  weak reference enabler ***/
1762         0,                          /* long tp_weaklistoffset; */
1763
1764   /*** Added in release 2.2 ***/
1765         /*   Iterators */
1766         ( getiterfunc )ConstraintSeq_getIter, /* getiterfunc tp_iter; */
1767     ( iternextfunc )ConstraintSeq_nextIter, /* iternextfunc tp_iternext; */
1768
1769   /*** Attribute descriptor and subclassing stuff ***/
1770         BPy_ConstraintSeq_methods,         /* struct PyMethodDef *tp_methods; */
1771         NULL,                       /* struct PyMemberDef *tp_members; */
1772         NULL,                       /* struct PyGetSetDef *tp_getset; */
1773         NULL,                       /* struct _typeobject *tp_base; */
1774         NULL,                       /* PyObject *tp_dict; */
1775         NULL,                       /* descrgetfunc tp_descr_get; */
1776         NULL,                       /* descrsetfunc tp_descr_set; */
1777         0,                          /* long tp_dictoffset; */
1778         NULL,                       /* initproc tp_init; */
1779         NULL,                       /* allocfunc tp_alloc; */
1780         NULL,                       /* newfunc tp_new; */
1781         /*  Low-level free-memory routine */
1782         NULL,                       /* freefunc tp_free;  */
1783         /* For PyObject_IS_GC */
1784         NULL,                       /* inquiry tp_is_gc;  */
1785         NULL,                       /* PyObject *tp_bases; */
1786         /* method resolution order */
1787         NULL,                       /* PyObject *tp_mro;  */
1788         NULL,                       /* PyObject *tp_cache; */
1789         NULL,                       /* PyObject *tp_subclasses; */
1790         NULL,                       /* PyObject *tp_weaklist; */
1791         NULL
1792 };
1793
1794 /*****************************************************************************/
1795 /* Function:    PoseConstraintSeq_CreatePyObject                             */
1796 /* Description: This function will create a new BPy_ConstraintSeq from an    */
1797 /*              existing ListBase structure.                                 */
1798 /*****************************************************************************/
1799 PyObject *PoseConstraintSeq_CreatePyObject( bPoseChannel *pchan )
1800 {
1801         BPy_ConstraintSeq *pyseq;
1802         Object *ob;
1803
1804         for( ob = G.main->object.first; ob; ob = ob->id.next ) {
1805                 if( ob->type == OB_ARMATURE ) {
1806                         bPoseChannel *p = ob->pose->chanbase.first;
1807                         while( p ) {
1808                                 if( p == pchan ) {
1809                                         pyseq = ( BPy_ConstraintSeq * ) PyObject_NEW( 
1810                                                         BPy_ConstraintSeq, &ConstraintSeq_Type );
1811                                         if( !pyseq )
1812                                                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1813                                                                 "couldn't create BPy_ConstraintSeq object" );
1814                                         pyseq->pchan = pchan;
1815                                         pyseq->obj = ob;
1816                                         return ( PyObject * ) pyseq;
1817                                 } else
1818                                         p = p->next;
1819                         }
1820                 }
1821         }
1822         return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1823                         "couldn't find ANY armature with the pose!" );
1824
1825 }
1826
1827 /*****************************************************************************/
1828 /* Function:    ObConstraintSeq_CreatePyObject                               */
1829 /* Description: This function will create a new BPy_ConstraintSeq from an    */
1830 /*              existing ListBase structure.                                 */
1831 /*****************************************************************************/
1832 PyObject *ObConstraintSeq_CreatePyObject( Object *obj )
1833 {
1834         BPy_ConstraintSeq *pyseq;
1835         pyseq = ( BPy_ConstraintSeq * ) PyObject_NEW( BPy_ConstraintSeq,
1836                         &ConstraintSeq_Type );
1837         if( !pyseq )
1838                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1839                                               "couldn't create BPy_ConstraintSeq object" );
1840         pyseq->obj = obj;
1841         pyseq->pchan = NULL;
1842         return ( PyObject * ) pyseq;
1843 }
1844
1845 static PyObject *M_Constraint_TypeDict( void )
1846 {
1847         PyObject *S = PyConstant_New(  );
1848
1849         if( S ) {
1850                 BPy_constant *d = ( BPy_constant * ) S;
1851                 PyConstant_Insert( d, "NULL", 
1852                                 PyInt_FromLong( CONSTRAINT_TYPE_NULL ) );
1853                 PyConstant_Insert( d, "TRACKTO",
1854                                 PyInt_FromLong( CONSTRAINT_TYPE_TRACKTO ) );
1855                 PyConstant_Insert( d, "IKSOLVER", 
1856                                 PyInt_FromLong( CONSTRAINT_TYPE_KINEMATIC ) );
1857                 PyConstant_Insert( d, "FOLLOWPATH", 
1858                                 PyInt_FromLong( CONSTRAINT_TYPE_FOLLOWPATH ) );
1859                 PyConstant_Insert( d, "COPYROT", 
1860                                 PyInt_FromLong( CONSTRAINT_TYPE_ROTLIKE ) );
1861                 PyConstant_Insert( d, "COPYLOC", 
1862                                 PyInt_FromLong( CONSTRAINT_TYPE_LOCLIKE ) );
1863                 PyConstant_Insert( d, "COPYSIZE", 
1864                                 PyInt_FromLong( CONSTRAINT_TYPE_SIZELIKE ) );
1865                 PyConstant_Insert( d, "ACTION", 
1866                                 PyInt_FromLong( CONSTRAINT_TYPE_ACTION ) );
1867                 PyConstant_Insert( d, "LOCKTRACK", 
1868                                 PyInt_FromLong( CONSTRAINT_TYPE_LOCKTRACK ) );
1869                 PyConstant_Insert( d, "STRETCHTO", 
1870                                 PyInt_FromLong( CONSTRAINT_TYPE_STRETCHTO ) );
1871                 PyConstant_Insert( d, "FLOOR", 
1872                                 PyInt_FromLong( CONSTRAINT_TYPE_MINMAX ) );
1873                 PyConstant_Insert( d, "LIMITLOC", 
1874                                 PyInt_FromLong( CONSTRAINT_TYPE_LOCLIMIT ) );
1875                 PyConstant_Insert( d, "LIMITROT", 
1876                                 PyInt_FromLong( CONSTRAINT_TYPE_ROTLIMIT ) );
1877                 PyConstant_Insert( d, "LIMITSIZE", 
1878                                 PyInt_FromLong( CONSTRAINT_TYPE_SIZELIMIT ) );
1879                 PyConstant_Insert( d, "RIGIDBODYJOINT", 
1880                                 PyInt_FromLong( CONSTRAINT_TYPE_RIGIDBODYJOINT ) );
1881         }
1882         return S;
1883 }
1884
1885 static PyObject *M_Constraint_SettingsDict( void )
1886 {
1887         PyObject *S = PyConstant_New(  );
1888         
1889         if( S ) {
1890                 BPy_constant *d = ( BPy_constant * ) S;
1891                 PyConstant_Insert( d, "XROT",
1892                                 PyInt_FromLong( EXPP_CONSTR_XROT ) );
1893                 PyConstant_Insert( d, "YROT",
1894                                 PyInt_FromLong( EXPP_CONSTR_YROT ) );
1895                 PyConstant_Insert( d, "ZROT",
1896                                 PyInt_FromLong( EXPP_CONSTR_ZROT ) );
1897
1898                 PyConstant_Insert( d, "UPX",
1899                                 PyInt_FromLong( UP_X ) );
1900                 PyConstant_Insert( d, "UPY",
1901                                 PyInt_FromLong( UP_Y ) );
1902                 PyConstant_Insert( d, "UPZ",
1903                                 PyInt_FromLong( UP_Z ) );
1904
1905                 PyConstant_Insert( d, "TRACKX",
1906                                 PyInt_FromLong( TRACK_X ) );
1907                 PyConstant_Insert( d, "TRACKY",
1908                                 PyInt_FromLong( TRACK_Y ) );
1909                 PyConstant_Insert( d, "TRACKZ",
1910                                 PyInt_FromLong( TRACK_Z ) );
1911                 PyConstant_Insert( d, "TRACKNEGX",
1912                                 PyInt_FromLong( TRACK_nX ) );
1913                 PyConstant_Insert( d, "TRACKNEGY",
1914                                 PyInt_FromLong( TRACK_nY ) );
1915                 PyConstant_Insert( d, "TRACKNEGZ",
1916                                 PyInt_FromLong( TRACK_nZ ) );
1917
1918                 PyConstant_Insert( d, "VOLUMEXZ",
1919                                 PyInt_FromLong( VOLUME_XZ ) );
1920                 PyConstant_Insert( d, "VOLUMEX",
1921                                 PyInt_FromLong( VOLUME_X ) );
1922                 PyConstant_Insert( d, "VOLUMEZ",
1923                                 PyInt_FromLong( VOLUME_Z ) );
1924                 PyConstant_Insert( d, "VOLUMENONE",
1925                                 PyInt_FromLong( NO_VOLUME ) );
1926
1927                 PyConstant_Insert( d, "PLANEX",
1928                                 PyInt_FromLong( PLANE_X ) );
1929                 PyConstant_Insert( d, "PLANEY",
1930                                 PyInt_FromLong( PLANE_Y ) );
1931                 PyConstant_Insert( d, "PLANEZ",
1932                                 PyInt_FromLong( PLANE_Z ) );
1933
1934                 PyConstant_Insert( d, "LOCKX",
1935                                 PyInt_FromLong( LOCK_X ) );
1936                 PyConstant_Insert( d, "LOCKY",
1937                                 PyInt_FromLong( LOCK_Y ) );
1938                 PyConstant_Insert( d, "LOCKZ",
1939                                 PyInt_FromLong( LOCK_Z ) );
1940
1941                 PyConstant_Insert( d, "MAXX",
1942                                 PyInt_FromLong( EXPP_CONSTR_MAXX ) );
1943                 PyConstant_Insert( d, "MAXY",
1944                                 PyInt_FromLong( EXPP_CONSTR_MAXY ) );
1945                 PyConstant_Insert( d, "MAXZ",
1946                                 PyInt_FromLong( EXPP_CONSTR_MAXZ ) );
1947                 PyConstant_Insert( d, "MINX",
1948                                 PyInt_FromLong( EXPP_CONSTR_MINX ) );
1949                 PyConstant_Insert( d, "MINY",
1950                                 PyInt_FromLong( EXPP_CONSTR_MINY ) );
1951                 PyConstant_Insert( d, "MINZ",
1952                                 PyInt_FromLong( EXPP_CONSTR_MINZ ) );
1953
1954                 PyConstant_Insert( d, "COPYX",
1955                                 PyInt_FromLong( LOCLIKE_X ) );
1956                 PyConstant_Insert( d, "COPYY",
1957                                 PyInt_FromLong( LOCLIKE_Y ) );
1958                 PyConstant_Insert( d, "COPYZ",
1959                                 PyInt_FromLong( LOCLIKE_Z ) );
1960
1961                 PyConstant_Insert( d, "TARGET",
1962                                 PyInt_FromLong( EXPP_CONSTR_TARGET ) );
1963                 PyConstant_Insert( d, "STRETCH", 
1964                                 PyInt_FromLong( EXPP_CONSTR_STRETCH ) );
1965                 PyConstant_Insert( d, "ITERATIONS", 
1966                                 PyInt_FromLong( EXPP_CONSTR_ITERATIONS ) );
1967                 PyConstant_Insert( d, "BONE", 
1968                                 PyInt_FromLong( EXPP_CONSTR_BONE ) );
1969                 PyConstant_Insert( d, "CHAINLEN", 
1970                                 PyInt_FromLong( EXPP_CONSTR_CHAINLEN ) );
1971                 PyConstant_Insert( d, "POSWEIGHT", 
1972                                 PyInt_FromLong( EXPP_CONSTR_POSWEIGHT ) );
1973                 PyConstant_Insert( d, "ROTWEIGHT", 
1974                                 PyInt_FromLong( EXPP_CONSTR_ROTWEIGHT ) );
1975                 PyConstant_Insert( d, "ROTATE", 
1976                                 PyInt_FromLong( EXPP_CONSTR_ROTATE ) );
1977                 PyConstant_Insert( d, "USETIP", 
1978                                 PyInt_FromLong( EXPP_CONSTR_USETIP ) );
1979
1980                 PyConstant_Insert( d, "ACTION", 
1981                                 PyInt_FromLong( EXPP_CONSTR_ACTION ) );
1982                 PyConstant_Insert( d, "LOCAL", 
1983                                 PyInt_FromLong( EXPP_CONSTR_LOCAL ) );
1984                 PyConstant_Insert( d, "START", 
1985                                 PyInt_FromLong( EXPP_CONSTR_START ) );
1986                 PyConstant_Insert( d, "END", 
1987                                 PyInt_FromLong( EXPP_CONSTR_END ) );
1988                 PyConstant_Insert( d, "MIN", 
1989                                 PyInt_FromLong( EXPP_CONSTR_MIN ) );
1990                 PyConstant_Insert( d, "MAX", 
1991                                 PyInt_FromLong( EXPP_CONSTR_MAX ) );
1992                 PyConstant_Insert( d, "KEYON", 
1993                                 PyInt_FromLong( EXPP_CONSTR_KEYON ) );
1994
1995                 PyConstant_Insert( d, "TRACK", 
1996                                 PyInt_FromLong( EXPP_CONSTR_TRACK ) );
1997                 PyConstant_Insert( d, "UP", 
1998                                 PyInt_FromLong( EXPP_CONSTR_UP ) );
1999
2000                 PyConstant_Insert( d, "RESTLENGTH",
2001                                 PyInt_FromLong( EXPP_CONSTR_RESTLENGTH ) );
2002                 PyConstant_Insert( d, "VOLVARIATION",
2003                                 PyInt_FromLong( EXPP_CONSTR_VOLVARIATION ) );
2004                 PyConstant_Insert( d, "VOLUMEMODE",
2005                                 PyInt_FromLong( EXPP_CONSTR_VOLUMEMODE ) );
2006                 PyConstant_Insert( d, "PLANE",
2007                                 PyInt_FromLong( EXPP_CONSTR_PLANE ) );
2008
2009                 PyConstant_Insert( d, "FOLLOW",
2010                                 PyInt_FromLong( EXPP_CONSTR_FOLLOW ) );
2011                 PyConstant_Insert( d, "OFFSET",
2012                                 PyInt_FromLong( EXPP_CONSTR_OFFSET ) );
2013                 PyConstant_Insert( d, "FORWARD",
2014                                 PyInt_FromLong( EXPP_CONSTR_FORWARD ) );
2015
2016                 PyConstant_Insert( d, "LOCK",
2017                                 PyInt_FromLong( EXPP_CONSTR_LOCK ) );
2018
2019                 PyConstant_Insert( d, "COPY",
2020                                 PyInt_FromLong( EXPP_CONSTR_COPY ) );
2021                 PyConstant_Insert( d, "LIMIT",
2022                                 PyInt_FromLong( EXPP_CONSTR_LIMIT ) );
2023                 
2024                 PyConstant_Insert( d, "LIMIT_XMIN",
2025                                 PyInt_FromLong( EXPP_CONSTR_LIMXMIN ) );
2026                 PyConstant_Insert( d, "LIMIT_XMAX",
2027                                 PyInt_FromLong( EXPP_CONSTR_LIMXMAX ) );
2028                 PyConstant_Insert( d, "LIMIT_YMIN",
2029                                 PyInt_FromLong( EXPP_CONSTR_LIMYMIN ) );
2030                 PyConstant_Insert( d, "LIMIT_YMAX",
2031                                 PyInt_FromLong( EXPP_CONSTR_LIMYMAX ) );
2032                 PyConstant_Insert( d, "LIMIT_ZMIN",
2033                                 PyInt_FromLong( EXPP_CONSTR_LIMZMIN ) );
2034                 PyConstant_Insert( d, "LIMIT_ZMAX",
2035                                 PyInt_FromLong( EXPP_CONSTR_LIMZMAX ) );
2036                 
2037                 PyConstant_Insert( d, "LIMIT_XROT",
2038                                 PyInt_FromLong( EXPP_CONSTR_LIMXROT ) );
2039                 PyConstant_Insert( d, "LIMIT_YROT",
2040                                 PyInt_FromLong( EXPP_CONSTR_LIMYROT ) );
2041                 PyConstant_Insert( d, "LIMIT_ZROT",
2042                                 PyInt_FromLong( EXPP_CONSTR_LIMZROT ) );
2043                 
2044                 PyConstant_Insert( d, "XMIN",
2045                                 PyInt_FromLong( EXPP_CONSTR_XMIN ) );
2046                 PyConstant_Insert( d, "XMAX",
2047                                 PyInt_FromLong( EXPP_CONSTR_XMAX ) );
2048                 PyConstant_Insert( d, "YMIN",
2049                                 PyInt_FromLong( EXPP_CONSTR_YMIN ) );
2050                 PyConstant_Insert( d, "YMAX",
2051                                 PyInt_FromLong( EXPP_CONSTR_YMAX ) );
2052                 PyConstant_Insert( d, "ZMIN",
2053                                 PyInt_FromLong( EXPP_CONSTR_ZMIN ) );
2054                 PyConstant_Insert( d, "ZMAX",
2055                                 PyInt_FromLong( EXPP_CONSTR_ZMAX ) );
2056                 
2057                 PyConstant_Insert( d, "LIMIT_LOCAL_BONE",
2058                                 PyInt_FromLong( EXPP_CONSTR_LIMLOCALBONE ) );
2059                 PyConstant_Insert( d, "LIMIT_LOCAL_NOPARENT",
2060                                 PyInt_FromLong( EXPP_CONSTR_LIMLOCALNOPAR ) );
2061
2062
2063                 PyConstant_Insert( d, "CONSTR_RB_TYPE",
2064                                 PyInt_FromLong( EXPP_CONSTR_RB_TYPE ) );
2065                 PyConstant_Insert( d, "CONSTR_RB_BALL",
2066                                 PyInt_FromLong( EXPP_CONSTR_RB_BALL ) );
2067                 PyConstant_Insert( d, "CONSTR_RB_HINGE",
2068                                 PyInt_FromLong( EXPP_CONSTR_RB_HINGE ) );
2069                 PyConstant_Insert( d, "CONSTR_RB_GENERIC6DOF",
2070                                 PyInt_FromLong( EXPP_CONSTR_RB_GENERIC6DOF ) );
2071                 PyConstant_Insert( d, "CONSTR_RB_VEHICLE",
2072                                 PyInt_FromLong( EXPP_CONSTR_RB_VEHICLE ) );
2073                 PyConstant_Insert( d, "CONSTR_RB_PIVX",
2074                                 PyInt_FromLong( EXPP_CONSTR_RB_PIVX ) );
2075                 PyConstant_Insert( d, "CONSTR_RB_PIVY",
2076                                 PyInt_FromLong( EXPP_CONSTR_RB_PIVY ) );
2077                 PyConstant_Insert( d, "CONSTR_RB_PIVZ",
2078                                 PyInt_FromLong( EXPP_CONSTR_RB_PIVZ ) );
2079                 PyConstant_Insert( d, "CONSTR_RB_AXX",
2080                                 PyInt_FromLong( EXPP_CONSTR_RB_AXX ) );
2081                 PyConstant_Insert( d, "CONSTR_RB_AXY",
2082                                 PyInt_FromLong( EXPP_CONSTR_RB_AXY ) );
2083                 PyConstant_Insert( d, "CONSTR_RB_AXZ",
2084                                 PyInt_FromLong( EXPP_CONSTR_RB_AXZ ) );
2085                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT0",
2086                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT0 ) );
2087                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT1",
2088                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT1 ) );
2089                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT2",
2090                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT2 ) );
2091                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT3",
2092                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT3 ) );
2093                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT4",
2094                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT4 ) );
2095                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT5",
2096                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT5 ) );
2097                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT0",
2098                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT0 ) );
2099                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT1",
2100                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT1 ) );
2101                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT2",
2102                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT2 ) );
2103                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT3",
2104                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT3 ) );
2105                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT4",
2106                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT4 ) );
2107                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT5",
2108                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT5 ) );                           
2109                 PyConstant_Insert( d, "CONSTR_RB_EXTRAFZ",
2110                                 PyInt_FromLong( EXPP_CONSTR_RB_EXTRAFZ ) );
2111                 PyConstant_Insert( d, "CONSTR_RB_FLAG",
2112                                 PyInt_FromLong( EXPP_CONSTR_RB_FLAG ) );
2113         }
2114         return S;
2115 }
2116
2117 /*****************************************************************************/
2118 /* Function:              Constraint_Init                                    */
2119 /*****************************************************************************/
2120 PyObject *Constraint_Init( void )
2121 {
2122         PyObject *submodule;
2123         PyObject *TypeDict = M_Constraint_TypeDict( );
2124         PyObject *SettingsDict = M_Constraint_SettingsDict( );
2125
2126         if( PyType_Ready( &ConstraintSeq_Type ) < 0
2127                         || PyType_Ready( &Constraint_Type ) < 0 )
2128                 return NULL;
2129
2130         submodule = Py_InitModule3( "Blender.Constraint", NULL,
2131                         "Constraint module for accessing and creating constraint data" );
2132
2133         if( TypeDict )
2134                 PyModule_AddObject( submodule, "Type", TypeDict );
2135         
2136         if( SettingsDict )
2137                 PyModule_AddObject( submodule, "Settings", SettingsDict );
2138         
2139         return submodule;
2140 }