4 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
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
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.
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.
23 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24 * All rights reserved.
26 * This is a new part of Blender.
28 * Contributor(s): Joseph Gilbert, Ken Hughes, Joshua Leung
30 * ***** END GPL/BL DUAL LICENSE BLOCK *****
33 #include "Constraint.h" /*This must come first*/
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 #include "DNA_text_types.h"
42 #include "BKE_global.h"
43 #include "BKE_library.h"
44 #include "BKE_action.h"
45 #include "BKE_armature.h"
46 #include "BKE_constraint.h"
47 #include "BLI_blenlib.h"
48 #include "BIF_editconstraint.h"
49 #include "BSE_editipo.h"
50 #include "MEM_guardedalloc.h"
59 #include "gen_utils.h"
61 enum constraint_constants {
65 EXPP_CONSTR_XSIZE = 10,
66 EXPP_CONSTR_YSIZE = 11,
67 EXPP_CONSTR_ZSIZE = 12,
68 EXPP_CONSTR_XLOC = 20,
69 EXPP_CONSTR_YLOC = 21,
70 EXPP_CONSTR_ZLOC = 22,
72 EXPP_CONSTR_MAXX = TRACK_X,
73 EXPP_CONSTR_MAXY = TRACK_Y,
74 EXPP_CONSTR_MAXZ = TRACK_Z,
75 EXPP_CONSTR_MINX = TRACK_nX,
76 EXPP_CONSTR_MINY = TRACK_nY,
77 EXPP_CONSTR_MINZ = TRACK_nZ,
79 EXPP_CONSTR_TARGET = 100,
81 EXPP_CONSTR_ITERATIONS,
84 EXPP_CONSTR_POSWEIGHT,
85 EXPP_CONSTR_ROTWEIGHT,
99 EXPP_CONSTR_RESTLENGTH,
100 EXPP_CONSTR_VOLVARIATION,
101 EXPP_CONSTR_VOLUMEMODE,
117 EXPP_CONSTR_LIMXMIN = LIMIT_XMIN,
118 EXPP_CONSTR_LIMXMAX = LIMIT_XMAX,
119 EXPP_CONSTR_LIMYMIN = LIMIT_YMIN,
120 EXPP_CONSTR_LIMYMAX = LIMIT_YMAX,
121 EXPP_CONSTR_LIMZMIN = LIMIT_ZMIN,
122 EXPP_CONSTR_LIMZMAX = LIMIT_ZMAX,
124 EXPP_CONSTR_LIMXROT = LIMIT_XROT,
125 EXPP_CONSTR_LIMYROT = LIMIT_YROT,
126 EXPP_CONSTR_LIMZROT = LIMIT_ZROT,
128 EXPP_CONSTR_CLAMPCYCLIC,
143 EXPP_CONSTR_FROMMINX,
144 EXPP_CONSTR_FROMMAXX,
145 EXPP_CONSTR_FROMMINY,
146 EXPP_CONSTR_FROMMAXY,
147 EXPP_CONSTR_FROMMINZ,
148 EXPP_CONSTR_FROMMAXZ,
159 EXPP_CONSTR_OWNSPACE,
160 EXPP_CONSTR_TARSPACE,
164 EXPP_CONSTR_RB_HINGE,
165 EXPP_CONSTR_RB_GENERIC6DOF,
166 EXPP_CONSTR_RB_VEHICLE,
173 EXPP_CONSTR_RB_MINLIMIT0,
174 EXPP_CONSTR_RB_MINLIMIT1,
175 EXPP_CONSTR_RB_MINLIMIT2,
176 EXPP_CONSTR_RB_MINLIMIT3,
177 EXPP_CONSTR_RB_MINLIMIT4,
178 EXPP_CONSTR_RB_MINLIMIT5,
179 EXPP_CONSTR_RB_MAXLIMIT0,
180 EXPP_CONSTR_RB_MAXLIMIT1,
181 EXPP_CONSTR_RB_MAXLIMIT2,
182 EXPP_CONSTR_RB_MAXLIMIT3,
183 EXPP_CONSTR_RB_MAXLIMIT4,
184 EXPP_CONSTR_RB_MAXLIMIT5,
185 EXPP_CONSTR_RB_EXTRAFZ,
190 /*****************************************************************************/
191 /* Python BPy_Constraint methods declarations: */
192 /*****************************************************************************/
193 static PyObject *Constraint_getName( BPy_Constraint * self );
194 static int Constraint_setName( BPy_Constraint * self, PyObject *arg );
195 static PyObject *Constraint_getType( BPy_Constraint * self );
196 static PyObject *Constraint_getInfluence( BPy_Constraint * self );
197 static int Constraint_setInfluence( BPy_Constraint * self, PyObject * arg );
199 static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * arg );
201 static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key );
202 static int Constraint_setData( BPy_Constraint * self, PyObject * key,
205 /*****************************************************************************/
206 /* Python BPy_Constraint methods table: */
207 /*****************************************************************************/
208 static PyMethodDef BPy_Constraint_methods[] = {
209 /* name, method, flags, doc */
210 {"insertKey", ( PyCFunction ) Constraint_insertKey, METH_O,
211 "Insert influence keyframe for constraint"},
212 {NULL, NULL, 0, NULL}
215 /*****************************************************************************/
216 /* Python BPy_Constraint attributes get/set structure: */
217 /*****************************************************************************/
218 static PyGetSetDef BPy_Constraint_getseters[] = {
220 (getter)Constraint_getName, (setter)Constraint_setName,
221 "Constraint name", NULL},
223 (getter)Constraint_getType, (setter)NULL,
224 "Constraint type (read only)", NULL},
226 (getter)Constraint_getInfluence, (setter)Constraint_setInfluence,
227 "Constraint influence", NULL},
228 {NULL,NULL,NULL,NULL,NULL} /* Sentinel */
231 /*****************************************************************************/
232 /* Python Constraint_Type Mapping Methods table: */
233 /*****************************************************************************/
234 static PyMappingMethods Constraint_as_mapping = {
235 NULL, /* mp_length */
236 ( binaryfunc ) Constraint_getData, /* mp_subscript */
237 ( objobjargproc ) Constraint_setData, /* mp_ass_subscript */
240 /*****************************************************************************/
241 /* Python Constraint_Type callback function prototypes: */
242 /*****************************************************************************/
243 static PyObject *Constraint_repr( BPy_Constraint * self );
244 static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b );
246 /*****************************************************************************/
247 /* Python Constraint_Type structure definition: */
248 /*****************************************************************************/
249 PyTypeObject Constraint_Type = {
250 PyObject_HEAD_INIT( NULL ) /* required py macro */
252 /* For printing, in format "<module>.<name>" */
253 "Blender Constraint", /* char *tp_name; */
254 sizeof( BPy_Constraint ), /* int tp_basicsize; */
255 0, /* tp_itemsize; For allocation */
257 /* Methods to implement standard operations */
259 NULL, /* destructor tp_dealloc; */
260 NULL, /* printfunc tp_print; */
261 NULL, /* getattrfunc tp_getattr; */
262 NULL, /* setattrfunc tp_setattr; */
263 ( cmpfunc ) Constraint_compare, /* cmpfunc tp_compare; */
264 ( reprfunc ) Constraint_repr, /* reprfunc tp_repr; */
266 /* Method suites for standard classes */
268 NULL, /* PyNumberMethods *tp_as_number; */
269 NULL, /* PySequenceMethods *tp_as_sequence; */
270 &Constraint_as_mapping, /* PyMappingMethods *tp_as_mapping; */
272 /* More standard operations (here for binary compatibility) */
274 NULL, /* hashfunc tp_hash; */
275 NULL, /* ternaryfunc tp_call; */
276 NULL, /* reprfunc tp_str; */
277 NULL, /* getattrofunc tp_getattro; */
278 NULL, /* setattrofunc tp_setattro; */
280 /* Functions to access object as input/output buffer */
281 NULL, /* PyBufferProcs *tp_as_buffer; */
283 /*** Flags to define presence of optional/expanded features ***/
284 Py_TPFLAGS_DEFAULT, /* long tp_flags; */
286 NULL, /* char *tp_doc; Documentation string */
287 /*** Assigned meaning in release 2.0 ***/
288 /* call function for all accessible objects */
289 NULL, /* traverseproc tp_traverse; */
291 /* delete references to contained objects */
292 NULL, /* inquiry tp_clear; */
294 /*** Assigned meaning in release 2.1 ***/
295 /*** rich comparisons ***/
296 NULL, /* richcmpfunc tp_richcompare; */
298 /*** weak reference enabler ***/
299 0, /* long tp_weaklistoffset; */
301 /*** Added in release 2.2 ***/
303 NULL, /* getiterfunc tp_iter; */
304 NULL, /* iternextfunc tp_iternext; */
306 /*** Attribute descriptor and subclassing stuff ***/
307 BPy_Constraint_methods, /* struct PyMethodDef *tp_methods; */
308 NULL, /* struct PyMemberDef *tp_members; */
309 BPy_Constraint_getseters, /* struct PyGetSetDef *tp_getset; */
310 NULL, /* struct _typeobject *tp_base; */
311 NULL, /* PyObject *tp_dict; */
312 NULL, /* descrgetfunc tp_descr_get; */
313 NULL, /* descrsetfunc tp_descr_set; */
314 0, /* long tp_dictoffset; */
315 NULL, /* initproc tp_init; */
316 NULL, /* allocfunc tp_alloc; */
317 NULL, /* newfunc tp_new; */
318 /* Low-level free-memory routine */
319 NULL, /* freefunc tp_free; */
320 /* For PyObject_IS_GC */
321 NULL, /* inquiry tp_is_gc; */
322 NULL, /* PyObject *tp_bases; */
323 /* method resolution order */
324 NULL, /* PyObject *tp_mro; */
325 NULL, /* PyObject *tp_cache; */
326 NULL, /* PyObject *tp_subclasses; */
327 NULL, /* PyObject *tp_weaklist; */
331 /*****************************************************************************/
332 /* Python BPy_Constraint methods: */
333 /*****************************************************************************/
336 * return the name of this constraint
339 static PyObject *Constraint_getName( BPy_Constraint * self )
342 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
343 "This constraint has been removed!" );
345 return PyString_FromString( self->con->name );
349 * set the name of this constraint
352 static int Constraint_setName( BPy_Constraint * self, PyObject * attr )
354 char *name = PyString_AsString( attr );
356 return EXPP_ReturnIntError( PyExc_TypeError, "expected string arg" );
359 return EXPP_ReturnIntError( PyExc_RuntimeError,
360 "This constraint has been removed!" );
362 BLI_strncpy( self->con->name, name, sizeof( self->con->name ) );
368 * return the influence of this constraint
371 static PyObject *Constraint_getInfluence( BPy_Constraint * self )
374 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
375 "This constraint has been removed!" );
377 return PyFloat_FromDouble( (double)self->con->enforce );
381 * set the influence of this constraint
384 static int Constraint_setInfluence( BPy_Constraint * self, PyObject * value )
387 return EXPP_ReturnIntError( PyExc_RuntimeError,
388 "This constraint has been removed!" );
390 return EXPP_setFloatClamped( value, &self->con->enforce, 0.0, 1.0 );
394 * return the type of this constraint
397 static PyObject *Constraint_getType( BPy_Constraint * self )
400 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
401 "This constraint has been removed!" );
403 return PyInt_FromLong( self->con->type );
407 * add keyframe for influence
408 base on code in add_influence_key_to_constraint_func()
410 static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * value )
413 float cfra = (float)PyFloat_AsDouble(value);
414 char actname[32] = "";
415 Object *ob = self->obj;
416 bConstraint *con = self->con;
419 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
420 "This constraint has been removed!" );
422 /* get frame for inserting key */
423 if( PyFloat_Check(value) )
424 return EXPP_ReturnPyObjError( PyExc_TypeError,
425 "expected a float argument" );
427 /* constraint_active_func(ob_v, con_v); */
428 get_constraint_ipo_context( ob, actname );
429 icu= verify_ipocurve((ID *)ob, ID_CO, actname, con->name, CO_ENFORCE);
432 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
433 "cannot get a curve from this IPO, may be using libdata" );
436 insert_vert_icu( icu, get_action_frame(ob, cfra), con->enforce, 0);
438 insert_vert_icu( icu, cfra, con->enforce, 0);
443 /******************************************************************************/
444 /* Constraint Space Conversion get/set procedures */
445 /* - These are called before/instead of individual constraint */
446 /* get/set procedures when OWNERSPACE or TARGETSPACE are chosen */
447 /* - They are only called from Constraint_g/setData */
448 /******************************************************************************/
450 static PyObject *constspace_getter( BPy_Constraint * self, int type )
452 bConstraint *con= (bConstraint *)(self->con);
454 /* depends on type being asked for
455 * NOTE: not all constraints support all space types
457 if (type == EXPP_CONSTR_OWNSPACE) {
459 /* all of these support this... */
460 case CONSTRAINT_TYPE_PYTHON:
461 case CONSTRAINT_TYPE_LOCLIKE:
462 case CONSTRAINT_TYPE_ROTLIKE:
463 case CONSTRAINT_TYPE_SIZELIKE:
464 case CONSTRAINT_TYPE_TRACKTO:
465 case CONSTRAINT_TYPE_LOCLIMIT:
466 case CONSTRAINT_TYPE_ROTLIMIT:
467 case CONSTRAINT_TYPE_SIZELIMIT:
468 case CONSTRAINT_TYPE_TRANSFORM:
469 return PyInt_FromLong( (long)con->ownspace );
472 else if (type == EXPP_CONSTR_TARSPACE) {
474 /* all of these support this... */
475 case CONSTRAINT_TYPE_PYTHON:
476 case CONSTRAINT_TYPE_ACTION:
477 case CONSTRAINT_TYPE_LOCLIKE:
478 case CONSTRAINT_TYPE_ROTLIKE:
479 case CONSTRAINT_TYPE_SIZELIKE:
480 case CONSTRAINT_TYPE_TRACKTO:
481 case CONSTRAINT_TYPE_TRANSFORM:
482 return PyInt_FromLong( (long)con->tarspace );
486 /* raise error if failed */
487 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
490 static int constspace_setter( BPy_Constraint *self, int type, PyObject *value )
492 bConstraint *con= (bConstraint *)(self->con);
494 /* depends on type being asked for
495 * NOTE: not all constraints support all space types
497 if (type == EXPP_CONSTR_OWNSPACE) {
499 /* all of these support this... */
500 case CONSTRAINT_TYPE_PYTHON:
501 case CONSTRAINT_TYPE_LOCLIKE:
502 case CONSTRAINT_TYPE_ROTLIKE:
503 case CONSTRAINT_TYPE_SIZELIKE:
504 case CONSTRAINT_TYPE_TRACKTO:
505 case CONSTRAINT_TYPE_LOCLIMIT:
506 case CONSTRAINT_TYPE_ROTLIMIT:
507 case CONSTRAINT_TYPE_SIZELIMIT:
508 case CONSTRAINT_TYPE_TRANSFORM:
510 /* only copy depending on ownertype */
512 return EXPP_setIValueClamped( value, &con->ownspace,
513 CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL, 'h' );
516 return EXPP_setIValueClamped( value, &con->ownspace,
517 CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, 'h' );
523 else if (type == EXPP_CONSTR_TARSPACE) {
525 /* all of these support this... */
526 case CONSTRAINT_TYPE_PYTHON:
527 case CONSTRAINT_TYPE_ACTION:
528 case CONSTRAINT_TYPE_LOCLIKE:
529 case CONSTRAINT_TYPE_ROTLIKE:
530 case CONSTRAINT_TYPE_SIZELIKE:
531 case CONSTRAINT_TYPE_TRACKTO:
532 case CONSTRAINT_TYPE_TRANSFORM:
537 tar= get_constraint_target(con, &subtarget);
539 /* only copy depending on target-type */
540 if (tar && subtarget[0]) {
541 return EXPP_setIValueClamped( value, &con->tarspace,
542 CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL, 'h' );
545 return EXPP_setIValueClamped( value, &con->tarspace,
546 CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, 'h' );
553 /* raise error if failed */
554 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
557 /*****************************************************************************/
558 /* Specific constraint get/set procedures */
559 /*****************************************************************************/
561 static PyObject *kinematic_getter( BPy_Constraint * self, int type )
563 bKinematicConstraint *con = (bKinematicConstraint *)(self->con->data);
566 case EXPP_CONSTR_TARGET:
567 return Object_CreatePyObject( con->tar );
568 case EXPP_CONSTR_BONE:
569 return PyString_FromString( con->subtarget );
570 case EXPP_CONSTR_STRETCH:
571 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_STRETCH ) ) ;
572 case EXPP_CONSTR_ITERATIONS:
573 return PyInt_FromLong( (long)con->iterations );
574 case EXPP_CONSTR_CHAINLEN:
575 return PyInt_FromLong( (long)con->rootbone );
576 case EXPP_CONSTR_POSWEIGHT:
577 return PyFloat_FromDouble( (double)con->weight );
578 case EXPP_CONSTR_ROTWEIGHT:
579 return PyFloat_FromDouble( (double)con->orientweight );
580 case EXPP_CONSTR_ROTATE:
581 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_ROT ) ) ;
582 case EXPP_CONSTR_USETIP:
583 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_TIP ) ) ;
585 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
589 static int kinematic_setter( BPy_Constraint *self, int type, PyObject *value )
591 bKinematicConstraint *con = (bKinematicConstraint *)(self->con->data);
594 case EXPP_CONSTR_TARGET: {
595 Object *obj = (( BPy_Object * )value)->object;
596 if( !BPy_Object_Check( value ) )
597 return EXPP_ReturnIntError( PyExc_TypeError,
598 "expected BPy object argument" );
602 case EXPP_CONSTR_BONE: {
603 char *name = PyString_AsString( value );
605 return EXPP_ReturnIntError( PyExc_TypeError,
606 "expected string arg" );
608 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
612 case EXPP_CONSTR_STRETCH:
613 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_STRETCH, 'h' );
614 case EXPP_CONSTR_ITERATIONS:
615 return EXPP_setIValueClamped( value, &con->iterations, 1, 10000, 'h' );
616 case EXPP_CONSTR_CHAINLEN:
617 return EXPP_setIValueClamped( value, &con->rootbone, 0, 255, 'i' );
618 case EXPP_CONSTR_POSWEIGHT:
619 return EXPP_setFloatClamped( value, &con->weight, 0.01f, 1.0 );
620 case EXPP_CONSTR_ROTWEIGHT:
621 return EXPP_setFloatClamped( value, &con->orientweight, 0.01f, 1.0 );
622 case EXPP_CONSTR_ROTATE:
623 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_ROT, 'h' );
624 case EXPP_CONSTR_USETIP:
625 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_TIP, 'h' );
627 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
631 static PyObject *action_getter( BPy_Constraint * self, int type )
633 bActionConstraint *con = (bActionConstraint *)(self->con->data);
636 case EXPP_CONSTR_TARGET:
637 return Object_CreatePyObject( con->tar );
638 case EXPP_CONSTR_BONE:
639 return PyString_FromString( con->subtarget );
640 case EXPP_CONSTR_ACTION:
641 return Action_CreatePyObject( con->act );
642 case EXPP_CONSTR_START:
643 return PyInt_FromLong( (long)con->start );
644 case EXPP_CONSTR_END:
645 return PyInt_FromLong( (long)con->end );
646 case EXPP_CONSTR_MIN:
647 return PyFloat_FromDouble( (double)con->min );
648 case EXPP_CONSTR_MAX:
649 return PyFloat_FromDouble( (double)con->max );
650 case EXPP_CONSTR_KEYON:
651 return PyInt_FromLong( (long)con->type );
653 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
657 static int action_setter( BPy_Constraint *self, int type, PyObject *value )
659 bActionConstraint *con = (bActionConstraint *)(self->con->data);
662 case EXPP_CONSTR_TARGET: {
663 Object *obj = (( BPy_Object * )value)->object;
664 if( !BPy_Object_Check( value ) )
665 return EXPP_ReturnIntError( PyExc_TypeError,
666 "expected BPy object argument" );
670 case EXPP_CONSTR_BONE: {
671 char *name = PyString_AsString( value );
673 return EXPP_ReturnIntError( PyExc_TypeError,
674 "expected string arg" );
676 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
680 case EXPP_CONSTR_ACTION: {
681 bAction *act = (( BPy_Action * )value)->action;
682 if( !BPy_Action_Check( value ) )
683 return EXPP_ReturnIntError( PyExc_TypeError,
684 "expected BPy action argument" );
688 case EXPP_CONSTR_START:
689 return EXPP_setIValueClamped( value, &con->start, 1, MAXFRAME, 'h' );
690 case EXPP_CONSTR_END:
691 return EXPP_setIValueClamped( value, &con->end, 1, MAXFRAME, 'h' );
692 case EXPP_CONSTR_MIN:
694 return EXPP_setFloatClamped( value, &con->min, -180.0, 180.0 );
695 else if (con->type < 20)
696 return EXPP_setFloatClamped( value, &con->min, 0.0001, 1000.0 );
698 return EXPP_setFloatClamped( value, &con->min, -1000.0, 1000.0 );
699 case EXPP_CONSTR_MAX:
701 return EXPP_setFloatClamped( value, &con->max, -180.0, 180.0 );
702 else if (con->type < 20)
703 return EXPP_setFloatClamped( value, &con->max, 0.0001, 1000.0 );
705 return EXPP_setFloatClamped( value, &con->max, -1000.0, 1000.0 );
706 case EXPP_CONSTR_KEYON:
707 return EXPP_setIValueRange( value, &con->type,
708 EXPP_CONSTR_XROT, EXPP_CONSTR_ZLOC, 'h' );
710 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
714 static PyObject *trackto_getter( BPy_Constraint * self, int type )
716 bTrackToConstraint *con = (bTrackToConstraint *)(self->con->data);
719 case EXPP_CONSTR_TARGET:
720 return Object_CreatePyObject( con->tar );
721 case EXPP_CONSTR_BONE:
722 return PyString_FromString( con->subtarget );
723 case EXPP_CONSTR_TRACK:
724 return PyInt_FromLong( (long)con->reserved1 );
726 return PyInt_FromLong( (long)con->reserved2 );
728 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
732 static int trackto_setter( BPy_Constraint *self, int type, PyObject *value )
734 bTrackToConstraint *con = (bTrackToConstraint *)(self->con->data);
737 case EXPP_CONSTR_TARGET: {
738 Object *obj = (( BPy_Object * )value)->object;
739 if( !BPy_Object_Check( value ) )
740 return EXPP_ReturnIntError( PyExc_TypeError,
741 "expected BPy object argument" );
745 case EXPP_CONSTR_BONE: {
746 char *name = PyString_AsString( value );
748 return EXPP_ReturnIntError( PyExc_TypeError,
749 "expected string arg" );
751 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
755 case EXPP_CONSTR_TRACK:
756 return EXPP_setIValueRange( value, &con->reserved1,
757 TRACK_X, TRACK_nZ, 'i' );
759 return EXPP_setIValueRange( value, &con->reserved2,
762 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
766 static PyObject *stretchto_getter( BPy_Constraint * self, int type )
768 bStretchToConstraint *con = (bStretchToConstraint *)(self->con->data);
771 case EXPP_CONSTR_TARGET:
772 return Object_CreatePyObject( con->tar );
773 case EXPP_CONSTR_BONE:
774 return PyString_FromString( con->subtarget );
775 case EXPP_CONSTR_RESTLENGTH:
776 return PyFloat_FromDouble( (double)con->orglength );
777 case EXPP_CONSTR_VOLVARIATION:
778 return PyFloat_FromDouble( (double)con->bulge );
779 case EXPP_CONSTR_VOLUMEMODE:
780 return PyInt_FromLong( (long)con->volmode );
781 case EXPP_CONSTR_PLANE:
782 return PyInt_FromLong( (long)con->plane );
784 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
788 static int stretchto_setter( BPy_Constraint *self, int type, PyObject *value )
790 bStretchToConstraint *con = (bStretchToConstraint *)(self->con->data);
793 case EXPP_CONSTR_TARGET: {
794 Object *obj = (( BPy_Object * )value)->object;
795 if( !BPy_Object_Check( value ) )
796 return EXPP_ReturnIntError( PyExc_TypeError,
797 "expected BPy object argument" );
801 case EXPP_CONSTR_BONE: {
802 char *name = PyString_AsString( value );
804 return EXPP_ReturnIntError( PyExc_TypeError,
805 "expected string arg" );
807 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
811 case EXPP_CONSTR_RESTLENGTH:
812 return EXPP_setFloatClamped( value, &con->orglength, 0.0, 100.0 );
813 case EXPP_CONSTR_VOLVARIATION:
814 return EXPP_setFloatClamped( value, &con->bulge, 0.0, 100.0 );
815 case EXPP_CONSTR_VOLUMEMODE:
816 return EXPP_setIValueRange( value, &con->volmode,
817 VOLUME_XZ, NO_VOLUME, 'h' );
818 case EXPP_CONSTR_PLANE: {
819 int status, oldcode = con->plane;
820 status = EXPP_setIValueRange( value, &con->plane,
821 PLANE_X, PLANE_Z, 'h' );
822 if( !status && con->plane == PLANE_Y ) {
823 con->plane = oldcode;
824 return EXPP_ReturnIntError( PyExc_ValueError,
825 "value must be either PLANEX or PLANEZ" );
830 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
834 static PyObject *followpath_getter( BPy_Constraint * self, int type )
836 bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
839 case EXPP_CONSTR_TARGET:
840 return Object_CreatePyObject( con->tar );
841 case EXPP_CONSTR_FOLLOW:
842 return PyBool_FromLong( (long)( con->followflag & SELECT ) );
843 case EXPP_CONSTR_OFFSET:
844 return PyFloat_FromDouble( (double)con->offset );
845 case EXPP_CONSTR_FORWARD:
846 return PyInt_FromLong( (long)con->trackflag );
848 return PyInt_FromLong( (long)con->upflag );
850 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
854 static int followpath_setter( BPy_Constraint *self, int type, PyObject *value )
856 bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
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" );
867 case EXPP_CONSTR_FOLLOW:
868 return EXPP_setBitfield( value, &con->followflag, SELECT, 'i' );
869 case EXPP_CONSTR_OFFSET:
870 return EXPP_setFloatClamped( value, &con->offset,
871 -MAXFRAMEF, MAXFRAMEF );
872 case EXPP_CONSTR_FORWARD:
873 return EXPP_setIValueRange( value, &con->trackflag,
874 TRACK_X, TRACK_nZ, 'i' );
876 return EXPP_setIValueRange( value, &con->upflag,
879 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
883 static PyObject *clampto_getter( BPy_Constraint * self, int type )
885 bClampToConstraint *con = (bClampToConstraint *)(self->con->data);
888 case EXPP_CONSTR_TARGET:
889 return Object_CreatePyObject( con->tar );
890 case EXPP_CONSTR_CLAMP:
891 return PyInt_FromLong( (long)con->flag );
892 case EXPP_CONSTR_CLAMPCYCLIC:
893 return PyBool_FromLong( (long)(con->flag2 & CLAMPTO_CYCLIC) );
895 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
899 static int clampto_setter( BPy_Constraint *self, int type, PyObject *value )
901 bClampToConstraint *con = (bClampToConstraint *)(self->con->data);
904 case EXPP_CONSTR_TARGET: {
905 Object *obj = (( BPy_Object * )value)->object;
906 if( !BPy_Object_Check( value ) )
907 return EXPP_ReturnIntError( PyExc_TypeError,
908 "expected BPy object argument" );
912 case EXPP_CONSTR_CLAMP:
913 return EXPP_setIValueRange( value, &con->flag,
914 CLAMPTO_AUTO, CLAMPTO_Z, 'i' );
915 case EXPP_CONSTR_CLAMPCYCLIC:
916 return EXPP_setBitfield( value, &con->flag2, CLAMPTO_CYCLIC, 'i' );
918 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
921 static PyObject *locktrack_getter( BPy_Constraint * self, int type )
923 bLockTrackConstraint *con = (bLockTrackConstraint *)(self->con->data);
926 case EXPP_CONSTR_TARGET:
927 return Object_CreatePyObject( con->tar );
928 case EXPP_CONSTR_BONE:
929 return PyString_FromString( con->subtarget );
930 case EXPP_CONSTR_TRACK:
931 return PyInt_FromLong( (long)con->trackflag );
932 case EXPP_CONSTR_LOCK:
933 return PyInt_FromLong( (long)con->lockflag );
935 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
939 static int locktrack_setter( BPy_Constraint *self, int type, PyObject *value )
941 bLockTrackConstraint *con = (bLockTrackConstraint *)(self->con->data);
944 case EXPP_CONSTR_TARGET: {
945 Object *obj = (( BPy_Object * )value)->object;
946 if( !BPy_Object_Check( value ) )
947 return EXPP_ReturnIntError( PyExc_TypeError,
948 "expected BPy object argument" );
952 case EXPP_CONSTR_BONE: {
953 char *name = PyString_AsString( value );
955 return EXPP_ReturnIntError( PyExc_TypeError,
956 "expected string arg" );
958 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
962 case EXPP_CONSTR_TRACK:
963 return EXPP_setIValueRange( value, &con->trackflag,
964 TRACK_X, TRACK_nZ, 'i' );
965 case EXPP_CONSTR_LOCK:
966 return EXPP_setIValueRange( value, &con->lockflag,
967 LOCK_X, LOCK_Z, 'i' );
969 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
973 static PyObject *floor_getter( BPy_Constraint * self, int type )
975 bMinMaxConstraint *con = (bMinMaxConstraint *)(self->con->data);
978 case EXPP_CONSTR_TARGET:
979 return Object_CreatePyObject( con->tar );
980 case EXPP_CONSTR_BONE:
981 return PyString_FromString( con->subtarget );
982 case EXPP_CONSTR_MINMAX:
983 return PyInt_FromLong( (long)con->minmaxflag );
984 case EXPP_CONSTR_OFFSET:
985 return PyFloat_FromDouble( (double)con->offset );
986 case EXPP_CONSTR_STICKY:
987 return PyBool_FromLong( (long)( con->flag & MINMAX_STICKY ) ) ;
989 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
993 static int floor_setter( BPy_Constraint *self, int type, PyObject *value )
995 bMinMaxConstraint *con = (bMinMaxConstraint *)(self->con->data);
998 case EXPP_CONSTR_TARGET: {
999 Object *obj = (( BPy_Object * )value)->object;
1000 if( !BPy_Object_Check( value ) )
1001 return EXPP_ReturnIntError( PyExc_TypeError,
1002 "expected BPy object argument" );
1006 case EXPP_CONSTR_BONE: {
1007 char *name = PyString_AsString( value );
1009 return EXPP_ReturnIntError( PyExc_TypeError,
1010 "expected string arg" );
1012 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1016 case EXPP_CONSTR_MINMAX:
1017 return EXPP_setIValueRange( value, &con->minmaxflag,
1018 EXPP_CONSTR_MAXX, EXPP_CONSTR_MINZ, 'i' );
1019 case EXPP_CONSTR_OFFSET:
1020 return EXPP_setFloatClamped( value, &con->offset, -100.0, 100.0 );
1021 case EXPP_CONSTR_STICKY:
1022 return EXPP_setBitfield( value, &con->flag, MINMAX_STICKY, 'h' );
1024 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1028 static PyObject *locatelike_getter( BPy_Constraint * self, int type )
1030 bLocateLikeConstraint *con = (bLocateLikeConstraint *)(self->con->data);
1033 case EXPP_CONSTR_TARGET:
1034 return Object_CreatePyObject( con->tar );
1035 case EXPP_CONSTR_BONE:
1036 return PyString_FromString( con->subtarget );
1037 case EXPP_CONSTR_COPY:
1038 return PyInt_FromLong( (long)con->flag );
1040 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1044 static int locatelike_setter( BPy_Constraint *self, int type, PyObject *value )
1046 bLocateLikeConstraint *con = (bLocateLikeConstraint *)(self->con->data);
1049 case EXPP_CONSTR_TARGET: {
1050 Object *obj = (( BPy_Object * )value)->object;
1051 if( !BPy_Object_Check( value ) )
1052 return EXPP_ReturnIntError( PyExc_TypeError,
1053 "expected BPy object argument" );
1057 case EXPP_CONSTR_BONE: {
1058 char *name = PyString_AsString( value );
1060 return EXPP_ReturnIntError( PyExc_TypeError,
1061 "expected string arg" );
1063 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1067 case EXPP_CONSTR_COPY:
1068 return EXPP_setIValueRange( value, &con->flag,
1069 0, LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z | LOCLIKE_X_INVERT | LOCLIKE_Y_INVERT | LOCLIKE_Z_INVERT, 'i' );
1071 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1075 static PyObject *rotatelike_getter( BPy_Constraint * self, int type )
1077 bRotateLikeConstraint *con = (bRotateLikeConstraint *)(self->con->data);
1080 case EXPP_CONSTR_TARGET:
1081 return Object_CreatePyObject( con->tar );
1082 case EXPP_CONSTR_BONE:
1083 return PyString_FromString( con->subtarget );
1084 case EXPP_CONSTR_COPY:
1085 return PyInt_FromLong( (long)con->flag );
1087 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1091 static int rotatelike_setter( BPy_Constraint *self, int type, PyObject *value )
1093 bRotateLikeConstraint *con = (bRotateLikeConstraint *)(self->con->data);
1096 case EXPP_CONSTR_TARGET: {
1097 Object *obj = (( BPy_Object * )value)->object;
1098 if( !BPy_Object_Check( value ) )
1099 return EXPP_ReturnIntError( PyExc_TypeError,
1100 "expected BPy object argument" );
1104 case EXPP_CONSTR_BONE: {
1105 char *name = PyString_AsString( value );
1107 return EXPP_ReturnIntError( PyExc_TypeError,
1108 "expected string arg" );
1110 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1114 case EXPP_CONSTR_COPY:
1115 return EXPP_setIValueRange( value, &con->flag,
1116 0, ROTLIKE_X | ROTLIKE_Y | ROTLIKE_Z | ROTLIKE_X_INVERT | ROTLIKE_Y_INVERT | ROTLIKE_Z_INVERT, 'i' );
1118 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1122 static PyObject *sizelike_getter( BPy_Constraint * self, int type )
1124 bSizeLikeConstraint *con = (bSizeLikeConstraint *)(self->con->data);
1127 case EXPP_CONSTR_TARGET:
1128 return Object_CreatePyObject( con->tar );
1129 case EXPP_CONSTR_BONE:
1130 return PyString_FromString( con->subtarget );
1131 case EXPP_CONSTR_COPY:
1132 return PyInt_FromLong( (long)con->flag );
1134 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1138 static int sizelike_setter( BPy_Constraint *self, int type, PyObject *value )
1140 bSizeLikeConstraint *con = (bSizeLikeConstraint *)(self->con->data);
1143 case EXPP_CONSTR_TARGET: {
1144 Object *obj = (( BPy_Object * )value)->object;
1145 if( !BPy_Object_Check( value ) )
1146 return EXPP_ReturnIntError( PyExc_TypeError,
1147 "expected BPy object argument" );
1151 case EXPP_CONSTR_BONE: {
1152 char *name = PyString_AsString( value );
1154 return EXPP_ReturnIntError( PyExc_TypeError,
1155 "expected string arg" );
1157 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1161 case EXPP_CONSTR_COPY:
1162 return EXPP_setIValueRange( value, &con->flag,
1163 0, SIZELIKE_X | SIZELIKE_Y | SIZELIKE_Z, 'i' );
1165 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1169 static PyObject *loclimit_getter( BPy_Constraint * self, int type)
1171 bLocLimitConstraint *con = (bLocLimitConstraint *)(self->con->data);
1174 case EXPP_CONSTR_LIMIT:
1175 return PyInt_FromLong( (long)con->flag );
1176 case EXPP_CONSTR_XMIN:
1177 return PyFloat_FromDouble( (double)con->xmin );
1178 case EXPP_CONSTR_XMAX:
1179 return PyFloat_FromDouble( (double)con->xmax );
1180 case EXPP_CONSTR_YMIN:
1181 return PyFloat_FromDouble( (double)con->ymin );
1182 case EXPP_CONSTR_YMAX:
1183 return PyFloat_FromDouble( (double)con->ymax );
1184 case EXPP_CONSTR_ZMIN:
1185 return PyFloat_FromDouble( (double)con->zmin );
1186 case EXPP_CONSTR_ZMAX:
1187 return PyFloat_FromDouble( (double)con->zmax );
1189 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1193 static int loclimit_setter( BPy_Constraint *self, int type, PyObject *value )
1195 bLocLimitConstraint *con = (bLocLimitConstraint *)(self->con->data);
1198 case EXPP_CONSTR_LIMIT:
1199 return EXPP_setIValueRange( value, &con->flag, 0,
1200 LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX , 'i' );
1201 case EXPP_CONSTR_XMIN:
1202 return EXPP_setFloatClamped( value, &con->xmin, -1000.0, 1000.0 );
1203 case EXPP_CONSTR_XMAX:
1204 return EXPP_setFloatClamped( value, &con->xmax, -1000.0, 1000.0 );
1205 case EXPP_CONSTR_YMIN:
1206 return EXPP_setFloatClamped( value, &con->ymin, -1000.0, 1000.0 );
1207 case EXPP_CONSTR_YMAX:
1208 return EXPP_setFloatClamped( value, &con->ymax, -1000.0, 1000.0 );
1209 case EXPP_CONSTR_ZMIN:
1210 return EXPP_setFloatClamped( value, &con->zmin, -1000.0, 1000.0 );
1211 case EXPP_CONSTR_ZMAX:
1212 return EXPP_setFloatClamped( value, &con->zmax, -1000.0, 1000.0 );
1214 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1218 static PyObject *rotlimit_getter( BPy_Constraint * self, int type )
1220 bRotLimitConstraint *con = (bRotLimitConstraint *)(self->con->data);
1223 case EXPP_CONSTR_LIMIT:
1224 return PyInt_FromLong( (long)con->flag );
1225 case EXPP_CONSTR_XMIN:
1226 return PyFloat_FromDouble( (double)con->xmin );
1227 case EXPP_CONSTR_XMAX:
1228 return PyFloat_FromDouble( (double)con->xmax );
1229 case EXPP_CONSTR_YMIN:
1230 return PyFloat_FromDouble( (double)con->ymin );
1231 case EXPP_CONSTR_YMAX:
1232 return PyFloat_FromDouble( (double)con->ymax );
1233 case EXPP_CONSTR_ZMIN:
1234 return PyFloat_FromDouble( (double)con->zmin );
1235 case EXPP_CONSTR_ZMAX:
1236 return PyFloat_FromDouble( (double)con->zmax );
1238 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1242 static int rotlimit_setter( BPy_Constraint *self, int type, PyObject *value )
1244 bRotLimitConstraint *con = (bRotLimitConstraint *)(self->con->data);
1247 case EXPP_CONSTR_LIMIT:
1248 return EXPP_setIValueRange( value, &con->flag, 0,
1249 LIMIT_XROT | LIMIT_YROT | LIMIT_ZROT, 'i' );
1250 case EXPP_CONSTR_XMIN:
1251 return EXPP_setFloatClamped( value, &con->xmin, -360.0, 360.0 );
1252 case EXPP_CONSTR_XMAX:
1253 return EXPP_setFloatClamped( value, &con->xmax, -360.0, 360.0 );
1254 case EXPP_CONSTR_YMIN:
1255 return EXPP_setFloatClamped( value, &con->ymin, -360.0, 360.0 );
1256 case EXPP_CONSTR_YMAX:
1257 return EXPP_setFloatClamped( value, &con->ymax, -360.0, 360.0 );
1258 case EXPP_CONSTR_ZMIN:
1259 return EXPP_setFloatClamped( value, &con->zmin, -360.0, 360.0 );
1260 case EXPP_CONSTR_ZMAX:
1261 return EXPP_setFloatClamped( value, &con->zmax, -360.0, 360.0 );
1263 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1267 static PyObject *sizelimit_getter( BPy_Constraint * self, int type)
1269 bSizeLimitConstraint *con = (bSizeLimitConstraint *)(self->con->data);
1272 case EXPP_CONSTR_LIMIT:
1273 return PyInt_FromLong( (long)con->flag );
1274 case EXPP_CONSTR_XMIN:
1275 return PyFloat_FromDouble( (double)con->xmin );
1276 case EXPP_CONSTR_XMAX:
1277 return PyFloat_FromDouble( (double)con->xmax );
1278 case EXPP_CONSTR_YMIN:
1279 return PyFloat_FromDouble( (double)con->ymin );
1280 case EXPP_CONSTR_YMAX:
1281 return PyFloat_FromDouble( (double)con->ymax );
1282 case EXPP_CONSTR_ZMIN:
1283 return PyFloat_FromDouble( (double)con->zmin );
1284 case EXPP_CONSTR_ZMAX:
1285 return PyFloat_FromDouble( (double)con->zmax );
1287 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1291 static int sizelimit_setter( BPy_Constraint *self, int type, PyObject *value )
1293 bSizeLimitConstraint *con = (bSizeLimitConstraint *)(self->con->data);
1296 case EXPP_CONSTR_LIMIT:
1297 return EXPP_setIValueRange( value, &con->flag, 0,
1298 LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
1299 case EXPP_CONSTR_XMIN:
1300 return EXPP_setFloatClamped( value, &con->xmin, -1000.0, 1000.0 );
1301 case EXPP_CONSTR_XMAX:
1302 return EXPP_setFloatClamped( value, &con->xmax, -1000.0, 1000.0 );
1303 case EXPP_CONSTR_YMIN:
1304 return EXPP_setFloatClamped( value, &con->ymin, -1000.0, 1000.0 );
1305 case EXPP_CONSTR_YMAX:
1306 return EXPP_setFloatClamped( value, &con->ymax, -1000.0, 1000.0 );
1307 case EXPP_CONSTR_ZMIN:
1308 return EXPP_setFloatClamped( value, &con->zmin, -1000.0, 1000.0 );
1309 case EXPP_CONSTR_ZMAX:
1310 return EXPP_setFloatClamped( value, &con->zmax, -1000.0, 1000.0 );
1312 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1316 static PyObject *script_getter( BPy_Constraint * self, int type )
1318 bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
1321 case EXPP_CONSTR_TARGET:
1322 return Object_CreatePyObject( con->tar );
1323 case EXPP_CONSTR_BONE:
1324 return PyString_FromString( con->subtarget );
1325 case EXPP_CONSTR_SCRIPT:
1326 return Text_CreatePyObject( con->text );
1327 case EXPP_CONSTR_PROPS:
1328 return BPy_Wrap_IDProperty( NULL, con->prop, NULL);
1330 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1334 static int script_setter( BPy_Constraint *self, int type, PyObject *value )
1336 bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
1339 case EXPP_CONSTR_TARGET: {
1340 Object *obj = (( BPy_Object * )value)->object;
1341 if( !BPy_Object_Check( value ) )
1342 return EXPP_ReturnIntError( PyExc_TypeError,
1343 "expected BPy object argument" );
1347 case EXPP_CONSTR_BONE: {
1348 char *name = PyString_AsString( value );
1350 return EXPP_ReturnIntError( PyExc_TypeError,
1351 "expected string arg" );
1353 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1357 case EXPP_CONSTR_SCRIPT: {
1358 Text *text = (( BPy_Text * )value)->text;
1359 if( !BPy_Object_Check( value ) )
1360 return EXPP_ReturnIntError( PyExc_TypeError,
1361 "expected BPy text argument" );
1365 case EXPP_CONSTR_PROPS:
1366 return EXPP_ReturnIntError( PyExc_RuntimeError,
1367 "setting ID-Properties of PyConstraints this way is not supported" );
1369 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1374 static PyObject *rigidbody_getter( BPy_Constraint * self, int type)
1376 bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);
1379 case EXPP_CONSTR_TARGET:
1380 return Object_CreatePyObject( con->tar );
1381 case EXPP_CONSTR_RB_PIVX:
1382 return PyFloat_FromDouble( (double)con->pivX );
1383 case EXPP_CONSTR_RB_PIVY:
1384 return PyFloat_FromDouble( (double)con->pivY );
1385 case EXPP_CONSTR_RB_PIVZ:
1386 return PyFloat_FromDouble( (double)con->pivZ );
1387 case EXPP_CONSTR_RB_AXX:
1388 return PyFloat_FromDouble( (double)con->axX );
1389 case EXPP_CONSTR_RB_AXY:
1390 return PyFloat_FromDouble( (double)con->axY );
1391 case EXPP_CONSTR_RB_AXZ:
1392 return PyFloat_FromDouble( (double)con->axZ );
1393 case EXPP_CONSTR_RB_MINLIMIT0:
1394 return PyFloat_FromDouble( (double)con->minLimit[0] );
1395 case EXPP_CONSTR_RB_MINLIMIT1:
1396 return PyFloat_FromDouble( (double)con->minLimit[1] );
1397 case EXPP_CONSTR_RB_MINLIMIT2:
1398 return PyFloat_FromDouble( (double)con->minLimit[2] );
1399 case EXPP_CONSTR_RB_MINLIMIT3:
1400 return PyFloat_FromDouble( (double)con->minLimit[3] );
1401 case EXPP_CONSTR_RB_MINLIMIT4:
1402 return PyFloat_FromDouble( (double)con->minLimit[4] );
1403 case EXPP_CONSTR_RB_MINLIMIT5:
1404 return PyFloat_FromDouble( (double)con->minLimit[5] );
1405 case EXPP_CONSTR_RB_MAXLIMIT0:
1406 return PyFloat_FromDouble( (double)con->maxLimit[0] );
1407 case EXPP_CONSTR_RB_MAXLIMIT1:
1408 return PyFloat_FromDouble( (double)con->maxLimit[1] );
1409 case EXPP_CONSTR_RB_MAXLIMIT2:
1410 return PyFloat_FromDouble( (double)con->maxLimit[2] );
1411 case EXPP_CONSTR_RB_MAXLIMIT3:
1412 return PyFloat_FromDouble( (double)con->maxLimit[3] );
1413 case EXPP_CONSTR_RB_MAXLIMIT4:
1414 return PyFloat_FromDouble( (double)con->maxLimit[4] );
1415 case EXPP_CONSTR_RB_MAXLIMIT5:
1416 return PyFloat_FromDouble( (double)con->maxLimit[5] );
1417 case EXPP_CONSTR_RB_EXTRAFZ:
1418 return PyFloat_FromDouble( (double)con->extraFz );
1419 case EXPP_CONSTR_LIMIT:
1420 return PyInt_FromLong( (int)con->flag );
1422 case EXPP_CONSTR_RB_TYPE:
1423 return PyInt_FromLong( (int)con->type );
1425 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1430 static int rigidbody_setter( BPy_Constraint *self, int type, PyObject *value )
1432 bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);
1435 case EXPP_CONSTR_TARGET: {
1436 Object *obj = (( BPy_Object * )value)->object;
1437 if( !BPy_Object_Check( value ) )
1438 return EXPP_ReturnIntError( PyExc_TypeError,
1439 "expected BPy object argument" );
1443 case EXPP_CONSTR_RB_PIVX:
1444 return EXPP_setFloatClamped( value, &con->pivX , -1000.0, 1000.0 );
1445 case EXPP_CONSTR_RB_PIVY:
1446 return EXPP_setFloatClamped( value, &con->pivY , -1000.0, 1000.0 );
1447 case EXPP_CONSTR_RB_PIVZ:
1448 return EXPP_setFloatClamped( value, &con->pivZ , -1000.0, 1000.0 );
1449 case EXPP_CONSTR_RB_AXX:
1450 return EXPP_setFloatClamped( value, &con->axX , -1000.0, 1000.0 );
1451 case EXPP_CONSTR_RB_AXY:
1452 return EXPP_setFloatClamped( value, &con->axY , -1000.0, 1000.0 );
1453 case EXPP_CONSTR_RB_AXZ:
1454 return EXPP_setFloatClamped( value, &con->axZ , -1000.0, 1000.0 );
1455 case EXPP_CONSTR_RB_MINLIMIT0:
1456 return EXPP_setFloatClamped( value, &con->minLimit[0] , -1000.0, 1000.0 );
1457 case EXPP_CONSTR_RB_MINLIMIT1:
1458 return EXPP_setFloatClamped( value, &con->minLimit[1] , -1000.0, 1000.0 );
1459 case EXPP_CONSTR_RB_MINLIMIT2:
1460 return EXPP_setFloatClamped( value, &con->minLimit[2] , -1000.0, 1000.0 );
1461 case EXPP_CONSTR_RB_MINLIMIT3:
1462 return EXPP_setFloatClamped( value, &con->minLimit[3] , -1000.0, 1000.0 );
1463 case EXPP_CONSTR_RB_MINLIMIT4:
1464 return EXPP_setFloatClamped( value, &con->minLimit[4] , -1000.0, 1000.0 );
1465 case EXPP_CONSTR_RB_MINLIMIT5:
1466 return EXPP_setFloatClamped( value, &con->minLimit[5] , -1000.0, 1000.0 );
1467 case EXPP_CONSTR_RB_MAXLIMIT0:
1468 return EXPP_setFloatClamped( value, &con->maxLimit[0] , -1000.0, 1000.0 );
1469 case EXPP_CONSTR_RB_MAXLIMIT1:
1470 return EXPP_setFloatClamped( value, &con->maxLimit[1] , -1000.0, 1000.0 );
1471 case EXPP_CONSTR_RB_MAXLIMIT2:
1472 return EXPP_setFloatClamped( value, &con->maxLimit[2] , -1000.0, 1000.0 );
1473 case EXPP_CONSTR_RB_MAXLIMIT3:
1474 return EXPP_setFloatClamped( value, &con->maxLimit[3] , -1000.0, 1000.0 );
1475 case EXPP_CONSTR_RB_MAXLIMIT4:
1476 return EXPP_setFloatClamped( value, &con->maxLimit[4] , -1000.0, 1000.0 );
1477 case EXPP_CONSTR_RB_MAXLIMIT5:
1478 return EXPP_setFloatClamped( value, &con->maxLimit[5] , -1000.0, 1000.0 );
1479 case EXPP_CONSTR_RB_EXTRAFZ:
1480 return EXPP_setFloatClamped( value, &con->extraFz , -1000.0, 1000.0 );
1481 case EXPP_CONSTR_LIMIT:
1482 return EXPP_setIValueRange( value, &con->flag, 0,
1483 LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
1484 case EXPP_CONSTR_RB_TYPE:
1485 return EXPP_setIValueRange( value, &con->type, 0,
1486 EXPP_CONSTR_RB_BALL | EXPP_CONSTR_RB_HINGE | EXPP_CONSTR_RB_GENERIC6DOF | EXPP_CONSTR_RB_VEHICLE, 'i' );
1488 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1492 static PyObject *childof_getter( BPy_Constraint * self, int type )
1494 bChildOfConstraint *con = (bChildOfConstraint *)(self->con->data);
1497 case EXPP_CONSTR_TARGET:
1498 return Object_CreatePyObject( con->tar );
1499 case EXPP_CONSTR_BONE:
1500 return PyString_FromString( con->subtarget );
1501 case EXPP_CONSTR_COPY:
1502 return PyInt_FromLong( (long)con->flag );
1504 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1508 static int childof_setter( BPy_Constraint *self, int type, PyObject *value )
1510 bChildOfConstraint *con = (bChildOfConstraint *)(self->con->data);
1513 case EXPP_CONSTR_TARGET: {
1514 Object *obj = (( BPy_Object * )value)->object;
1515 if( !BPy_Object_Check( value ) )
1516 return EXPP_ReturnIntError( PyExc_TypeError,
1517 "expected BPy object argument" );
1521 case EXPP_CONSTR_BONE: {
1522 char *name = PyString_AsString( value );
1524 return EXPP_ReturnIntError( PyExc_TypeError,
1525 "expected string arg" );
1527 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1531 case EXPP_CONSTR_COPY:
1532 return EXPP_setIValueRange( value, &con->flag,
1533 0, CHILDOF_LOCX| CHILDOF_LOCY | CHILDOF_LOCZ | CHILDOF_ROTX | CHILDOF_ROTY | CHILDOF_ROTZ |
1534 CHILDOF_SIZEX |CHILDOF_SIZEY| CHILDOF_SIZEZ, 'i' );
1536 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1540 static PyObject *transf_getter( BPy_Constraint * self, int type )
1542 bTransformConstraint *con = (bTransformConstraint *)(self->con->data);
1545 case EXPP_CONSTR_TARGET:
1546 return Object_CreatePyObject( con->tar );
1547 case EXPP_CONSTR_BONE:
1548 return PyString_FromString( con->subtarget );
1549 case EXPP_CONSTR_FROM:
1550 return PyInt_FromLong( (long)con->from );
1551 case EXPP_CONSTR_TO:
1552 return PyInt_FromLong( (long)con->to );
1553 case EXPP_CONSTR_MAPX:
1554 return PyInt_FromLong( (long)con->map[0] );
1555 case EXPP_CONSTR_MAPY:
1556 return PyInt_FromLong( (long)con->map[1] );
1557 case EXPP_CONSTR_MAPZ:
1558 return PyInt_FromLong( (long)con->map[2] );
1559 case EXPP_CONSTR_FROMMINX:
1560 return PyFloat_FromDouble( (double)con->from_min[0] );
1561 case EXPP_CONSTR_FROMMAXX:
1562 return PyFloat_FromDouble( (double)con->from_max[0] );
1563 case EXPP_CONSTR_FROMMINY:
1564 return PyFloat_FromDouble( (double)con->from_min[1] );
1565 case EXPP_CONSTR_FROMMAXY:
1566 return PyFloat_FromDouble( (double)con->from_max[1] );
1567 case EXPP_CONSTR_FROMMINZ:
1568 return PyFloat_FromDouble( (double)con->from_min[2] );
1569 case EXPP_CONSTR_FROMMAXZ:
1570 return PyFloat_FromDouble( (double)con->from_max[2] );
1571 case EXPP_CONSTR_TOMINX:
1572 return PyFloat_FromDouble( (double)con->to_min[0] );
1573 case EXPP_CONSTR_TOMAXX:
1574 return PyFloat_FromDouble( (double)con->to_max[0] );
1575 case EXPP_CONSTR_TOMINY:
1576 return PyFloat_FromDouble( (double)con->to_min[1] );
1577 case EXPP_CONSTR_TOMAXY:
1578 return PyFloat_FromDouble( (double)con->to_max[1] );
1579 case EXPP_CONSTR_TOMINZ:
1580 return PyFloat_FromDouble( (double)con->to_min[2] );
1581 case EXPP_CONSTR_TOMAXZ:
1582 return PyFloat_FromDouble( (double)con->to_max[2] );
1583 case EXPP_CONSTR_EXPO:
1584 return PyBool_FromLong( (long)con->expo );
1586 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1590 static int transf_setter( BPy_Constraint *self, int type, PyObject *value )
1592 bTransformConstraint *con = (bTransformConstraint *)(self->con->data);
1593 float fmin, fmax, tmin, tmax;
1595 if (con->from == 2) {
1599 else if (con->from == 1) {
1612 else if (con->to == 1) {
1622 case EXPP_CONSTR_TARGET: {
1623 Object *obj = (( BPy_Object * )value)->object;
1624 if( !BPy_Object_Check( value ) )
1625 return EXPP_ReturnIntError( PyExc_TypeError,
1626 "expected BPy object argument" );
1630 case EXPP_CONSTR_BONE: {
1631 char *name = PyString_AsString( value );
1633 return EXPP_ReturnIntError( PyExc_TypeError,
1634 "expected string arg" );
1636 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1640 case EXPP_CONSTR_FROM:
1641 return EXPP_setIValueClamped( value, &con->from, 0, 3, 'h' );
1642 case EXPP_CONSTR_TO:
1643 return EXPP_setIValueClamped( value, &con->to, 0, 3, 'h' );
1644 case EXPP_CONSTR_MAPX:
1645 return EXPP_setIValueClamped( value, &con->map[0], 0, 3, 'h' );
1646 case EXPP_CONSTR_MAPY:
1647 return EXPP_setIValueClamped( value, &con->map[1], 0, 3, 'h' );
1648 case EXPP_CONSTR_MAPZ:
1649 return EXPP_setIValueClamped( value, &con->map[2], 0, 3, 'h' );
1650 case EXPP_CONSTR_FROMMINX:
1651 return EXPP_setFloatClamped( value, &con->from_min[0], fmin, fmax );
1652 case EXPP_CONSTR_FROMMAXX:
1653 return EXPP_setFloatClamped( value, &con->from_max[0], fmin, fmax );
1654 case EXPP_CONSTR_FROMMINY:
1655 return EXPP_setFloatClamped( value, &con->from_min[1], fmin, fmax );
1656 case EXPP_CONSTR_FROMMAXY:
1657 return EXPP_setFloatClamped( value, &con->from_max[1], fmin, fmax );
1658 case EXPP_CONSTR_FROMMINZ:
1659 return EXPP_setFloatClamped( value, &con->from_min[2], fmin, fmax );
1660 case EXPP_CONSTR_FROMMAXZ:
1661 return EXPP_setFloatClamped( value, &con->from_max[2], fmin, fmax );
1662 case EXPP_CONSTR_TOMINX:
1663 return EXPP_setFloatClamped( value, &con->to_min[0], tmin, tmax );
1664 case EXPP_CONSTR_TOMAXX:
1665 return EXPP_setFloatClamped( value, &con->to_max[0], tmin, tmax );
1666 case EXPP_CONSTR_TOMINY:
1667 return EXPP_setFloatClamped( value, &con->to_min[1], tmin, tmax );
1668 case EXPP_CONSTR_TOMAXY:
1669 return EXPP_setFloatClamped( value, &con->to_max[1], tmin, tmax );
1670 case EXPP_CONSTR_TOMINZ:
1671 return EXPP_setFloatClamped( value, &con->to_min[2], tmin, tmax );
1672 case EXPP_CONSTR_TOMAXZ:
1673 return EXPP_setFloatClamped( value, &con->to_max[2], tmin, tmax );
1674 case EXPP_CONSTR_EXPO:
1675 return EXPP_setBitfield( value, &con->expo, 1, 'h' );
1677 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1682 * get data from a constraint
1685 static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key )
1689 if( !PyInt_Check( key ) )
1690 return EXPP_ReturnPyObjError( PyExc_TypeError,
1691 "expected an int arg" );
1694 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1695 "This constraint has been removed!" );
1697 setting = PyInt_AsLong( key );
1699 /* bypass doing settings of individual constraints, if we're just doing
1700 * constraint space access-stuff
1702 if ((setting==EXPP_CONSTR_OWNSPACE) || (setting==EXPP_CONSTR_TARSPACE)) {
1703 return constspace_getter( self, setting );
1705 switch( self->con->type ) {
1706 case CONSTRAINT_TYPE_NULL:
1708 case CONSTRAINT_TYPE_TRACKTO:
1709 return trackto_getter( self, setting );
1710 case CONSTRAINT_TYPE_KINEMATIC:
1711 return kinematic_getter( self, setting );
1712 case CONSTRAINT_TYPE_FOLLOWPATH:
1713 return followpath_getter( self, setting );
1714 case CONSTRAINT_TYPE_ACTION:
1715 return action_getter( self, setting );
1716 case CONSTRAINT_TYPE_LOCKTRACK:
1717 return locktrack_getter( self, setting );
1718 case CONSTRAINT_TYPE_STRETCHTO:
1719 return stretchto_getter( self, setting );
1720 case CONSTRAINT_TYPE_MINMAX:
1721 return floor_getter( self, setting );
1722 case CONSTRAINT_TYPE_LOCLIKE:
1723 return locatelike_getter( self, setting );
1724 case CONSTRAINT_TYPE_ROTLIKE:
1725 return rotatelike_getter( self, setting );
1726 case CONSTRAINT_TYPE_SIZELIKE:
1727 return sizelike_getter( self, setting );
1728 case CONSTRAINT_TYPE_ROTLIMIT:
1729 return rotlimit_getter( self, setting );
1730 case CONSTRAINT_TYPE_LOCLIMIT:
1731 return loclimit_getter( self, setting );
1732 case CONSTRAINT_TYPE_SIZELIMIT:
1733 return sizelimit_getter( self, setting );
1734 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1735 return rigidbody_getter( self, setting );
1736 case CONSTRAINT_TYPE_CLAMPTO:
1737 return clampto_getter( self, setting );
1738 case CONSTRAINT_TYPE_PYTHON:
1739 return script_getter( self, setting );
1740 case CONSTRAINT_TYPE_CHILDOF:
1741 return childof_getter( self, setting );
1742 case CONSTRAINT_TYPE_TRANSFORM:
1743 return transf_getter( self, setting );
1745 return EXPP_ReturnPyObjError( PyExc_KeyError,
1746 "unknown constraint type" );
1750 static int Constraint_setData( BPy_Constraint * self, PyObject * key,
1753 int key_int, result;
1755 if( !PyNumber_Check( key ) )
1756 return EXPP_ReturnIntError( PyExc_TypeError,
1757 "expected an int arg" );
1759 return EXPP_ReturnIntError( PyExc_RuntimeError,
1760 "This constraint has been removed!" );
1762 key_int = PyInt_AsLong( key );
1764 /* bypass doing settings of individual constraints, if we're just doing
1765 * constraint space access-stuff
1767 if ((key_int==EXPP_CONSTR_OWNSPACE) || (key_int==EXPP_CONSTR_TARSPACE)) {
1768 result = constspace_setter( self, key_int, arg );
1771 switch( self->con->type ) {
1772 case CONSTRAINT_TYPE_KINEMATIC:
1773 result = kinematic_setter( self, key_int, arg );
1775 case CONSTRAINT_TYPE_ACTION:
1776 result = action_setter( self, key_int, arg );
1778 case CONSTRAINT_TYPE_TRACKTO:
1779 result = trackto_setter( self, key_int, arg );
1781 case CONSTRAINT_TYPE_STRETCHTO:
1782 result = stretchto_setter( self, key_int, arg );
1784 case CONSTRAINT_TYPE_FOLLOWPATH:
1785 result = followpath_setter( self, key_int, arg );
1787 case CONSTRAINT_TYPE_LOCKTRACK:
1788 result = locktrack_setter( self, key_int, arg );
1790 case CONSTRAINT_TYPE_MINMAX:
1791 result = floor_setter( self, key_int, arg );
1793 case CONSTRAINT_TYPE_LOCLIKE:
1794 result = locatelike_setter( self, key_int, arg );
1796 case CONSTRAINT_TYPE_ROTLIKE:
1797 result = rotatelike_setter( self, key_int, arg );
1799 case CONSTRAINT_TYPE_SIZELIKE:
1800 result = sizelike_setter( self, key_int, arg );
1802 case CONSTRAINT_TYPE_ROTLIMIT:
1803 result = rotlimit_setter( self, key_int, arg );
1805 case CONSTRAINT_TYPE_LOCLIMIT:
1806 result = loclimit_setter( self, key_int, arg );
1808 case CONSTRAINT_TYPE_SIZELIMIT:
1809 result = sizelimit_setter( self, key_int, arg);
1811 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1812 result = rigidbody_setter( self, key_int, arg);
1814 case CONSTRAINT_TYPE_CLAMPTO:
1815 result = clampto_setter( self, key_int, arg);
1817 case CONSTRAINT_TYPE_PYTHON:
1818 result = script_setter( self, key_int, arg);
1820 case CONSTRAINT_TYPE_CHILDOF:
1821 result = childof_setter( self, key_int, arg);
1823 case CONSTRAINT_TYPE_TRANSFORM:
1824 result = transf_setter( self, key_int, arg);
1826 case CONSTRAINT_TYPE_NULL:
1827 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1829 return EXPP_ReturnIntError( PyExc_RuntimeError,
1830 "unsupported constraint setting" );
1833 if( !result && self->pchan )
1834 update_pose_constraint_flags( self->obj->pose );
1838 /*****************************************************************************/
1839 /* Function: Constraint_compare */
1840 /* Description: This compares 2 constraint python types, == or != only. */
1841 /*****************************************************************************/
1842 static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b )
1844 return ( a->con == b->con ) ? 0 : -1;
1847 /*****************************************************************************/
1848 /* Function: Constraint_repr */
1849 /* Description: This is a callback function for the BPy_Constraint type. It */
1850 /* builds a meaningful string to represent constraint objects. */
1851 /*****************************************************************************/
1853 static PyObject *Constraint_repr( BPy_Constraint * self )
1858 return PyString_FromString( "[Constraint - Removed]");
1860 get_constraint_typestring (type, self->con);
1861 return PyString_FromFormat( "[Constraint \"%s\", Type \"%s\"]",
1862 self->con->name, type );
1865 /* Three Python Constraint_Type helper functions needed by the Object module: */
1867 /*****************************************************************************/
1868 /* Function: Constraint_CreatePyObject */
1869 /* Description: This function will create a new BPy_Constraint from an */
1870 /* existing Blender constraint structure. */
1871 /*****************************************************************************/
1872 PyObject *Constraint_CreatePyObject( bPoseChannel *pchan, Object *obj,
1875 BPy_Constraint *pycon;
1876 pycon = ( BPy_Constraint * ) PyObject_NEW( BPy_Constraint,
1879 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1880 "couldn't create BPy_Constraint object" );
1884 /* one of these two will be NULL */
1886 pycon->pchan = pchan;
1887 return ( PyObject * ) pycon;
1890 /*****************************************************************************/
1891 /* Function: Constraint_FromPyObject */
1892 /* Description: This function returns the Blender constraint from the given */
1894 /*****************************************************************************/
1895 bConstraint *Constraint_FromPyObject( BPy_Constraint * self )
1900 /*****************************************************************************/
1901 /* Constraint Sequence wrapper */
1902 /*****************************************************************************/
1905 * Initialize the interator
1908 static PyObject *ConstraintSeq_getIter( BPy_ConstraintSeq * self )
1911 self->iter = (bConstraint *)self->pchan->constraints.first;
1913 self->iter = (bConstraint *)self->obj->constraints.first;
1914 return EXPP_incr_ret ( (PyObject *) self );
1918 * Get the next Constraint
1921 static PyObject *ConstraintSeq_nextIter( BPy_ConstraintSeq * self )
1923 bConstraint *this = self->iter;
1925 self->iter = this->next;
1926 return Constraint_CreatePyObject( self->pchan, self->obj, this );
1929 return EXPP_ReturnPyObjError( PyExc_StopIteration,
1930 "iterator at end" );
1933 /* return the number of constraints */
1935 static int ConstraintSeq_length( BPy_ConstraintSeq * self )
1937 return BLI_countlist( self->pchan ?
1938 &self->pchan->constraints : &self->obj->constraints );
1941 /* return a constraint */
1943 static PyObject *ConstraintSeq_item( BPy_ConstraintSeq * self, int i )
1945 bConstraint *con = NULL;
1947 /* if index is negative, start counting from the end of the list */
1949 i += ConstraintSeq_length( self );
1951 /* skip through the list until we get the constraint or end of list */
1954 con = self->pchan->constraints.first;
1956 con = self->obj->constraints.first;
1964 return Constraint_CreatePyObject( self->pchan, self->obj, con );
1966 return EXPP_ReturnPyObjError( PyExc_IndexError,
1967 "array index out of range" );
1970 /*****************************************************************************/
1971 /* Python BPy_ConstraintSeq sequence table: */
1972 /*****************************************************************************/
1973 static PySequenceMethods ConstraintSeq_as_sequence = {
1974 ( inquiry ) ConstraintSeq_length, /* sq_length */
1975 ( binaryfunc ) 0, /* sq_concat */
1976 ( intargfunc ) 0, /* sq_repeat */
1977 ( intargfunc ) ConstraintSeq_item, /* sq_item */
1978 ( intintargfunc ) 0, /* sq_slice */
1979 ( intobjargproc ) 0, /* sq_ass_item */
1980 ( intintobjargproc ) 0, /* sq_ass_slice */
1981 ( objobjproc ) 0, /* sq_contains */
1982 ( binaryfunc ) 0, /* sq_inplace_concat */
1983 ( intargfunc ) 0, /* sq_inplace_repeat */
1987 * helper function to check for a valid constraint argument
1990 static bConstraint *locate_constr( BPy_ConstraintSeq *self, BPy_Constraint * value )
1994 /* check that argument is a modifier */
1995 if (!BPy_Constraint_Check(value))
1996 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_TypeError,
1997 "expected a constraint as an argument" );
1999 /* check whether constraint has been removed */
2001 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_RuntimeError,
2002 "This constraint has been removed!" );
2004 /* verify the constraint is still exists in the stack */
2006 con = self->pchan->constraints.first;
2008 con = self->obj->constraints.first;
2009 while( con && con != value->con )
2012 /* if we didn't find it, exception */
2014 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_AttributeError,
2015 "This constraint is no longer in the object's stack" );
2021 /* create a new constraint at the end of the list */
2023 static PyObject *ConstraintSeq_append( BPy_ConstraintSeq *self, PyObject *value )
2025 int type = (int)PyInt_AsLong(value);
2028 /* type 0 is CONSTRAINT_TYPE_NULL, should we be able to add one of these?
2029 * if the value is not an int it will be -1 */
2030 if( type < CONSTRAINT_TYPE_NULL || type > CONSTRAINT_TYPE_RIGIDBODYJOINT )
2031 return EXPP_ReturnPyObjError( PyExc_ValueError,
2032 "arg not in int or out of range" );
2034 con = add_new_constraint( type );
2036 BLI_addtail( &self->pchan->constraints, con );
2037 update_pose_constraint_flags( self->obj->pose );
2040 BLI_addtail( &self->obj->constraints, con );
2042 return Constraint_CreatePyObject( self->pchan, self->obj, con );
2045 /* move the constraint up in the stack */
2047 static PyObject *ConstraintSeq_moveUp( BPy_ConstraintSeq *self, BPy_Constraint *value )
2049 bConstraint *con = locate_constr( self, value );
2051 /* if we can't locate the constraint, return (exception already set) */
2053 return (PyObject *)NULL;
2055 const_moveUp( self->obj, con );
2059 /* move the constraint down in the stack */
2061 static PyObject *ConstraintSeq_moveDown( BPy_ConstraintSeq *self, BPy_Constraint *value )
2063 bConstraint *con = locate_constr( self, value );
2065 /* if we can't locate the constraint, return (exception already set) */
2067 return (PyObject *)NULL;
2069 const_moveDown( self->obj, con );
2073 /* remove an existing constraint */
2075 static PyObject *ConstraintSeq_remove( BPy_ConstraintSeq *self, BPy_Constraint *value )
2077 bConstraint *con = locate_constr( self, value );
2079 /* if we can't locate the constraint, return (exception already set) */
2081 return (PyObject *)NULL;
2083 /* do the actual removal */
2085 BLI_remlink( &self->pchan->constraints, con );
2087 BLI_remlink( &self->obj->constraints, con);
2088 del_constr_func( self->obj, con );
2090 /* erase the link to the constraint */
2096 /*****************************************************************************/
2097 /* Function: ConstraintSeq_dealloc */
2098 /* Description: This is a callback function for the BPy_ConstraintSeq type. */
2099 /* It destroys data when the object is deleted. */
2100 /*****************************************************************************/
2101 static void ConstraintSeq_dealloc( BPy_Constraint * self )
2103 PyObject_DEL( self );
2106 /*****************************************************************************/
2107 /* Python BPy_ConstraintSeq methods table: */
2108 /*****************************************************************************/
2109 static PyMethodDef BPy_ConstraintSeq_methods[] = {
2110 /* name, method, flags, doc */
2111 {"append", ( PyCFunction ) ConstraintSeq_append, METH_O,
2112 "(type) - add a new constraint, where type is the constraint type"},
2113 {"remove", ( PyCFunction ) ConstraintSeq_remove, METH_O,
2114 "(con) - remove an existing constraint, where con is a constraint from this object."},
2115 {"moveUp", ( PyCFunction ) ConstraintSeq_moveUp, METH_O,
2116 "(con) - Move constraint up in stack"},
2117 {"moveDown", ( PyCFunction ) ConstraintSeq_moveDown, METH_O,
2118 "(con) - Move constraint down in stack"},
2119 {NULL, NULL, 0, NULL}
2122 /*****************************************************************************/
2123 /* Python ConstraintSeq_Type structure definition: */
2124 /*****************************************************************************/
2125 PyTypeObject ConstraintSeq_Type = {
2126 PyObject_HEAD_INIT( NULL ) /* required py macro */
2128 /* For printing, in format "<module>.<name>" */
2129 "Blender.Constraints", /* char *tp_name; */
2130 sizeof( BPy_ConstraintSeq ), /* int tp_basicsize; */
2131 0, /* tp_itemsize; For allocation */
2133 /* Methods to implement standard operations */
2135 ( destructor ) ConstraintSeq_dealloc,/* destructor tp_dealloc; */
2136 NULL, /* printfunc tp_print; */
2137 NULL, /* getattrfunc tp_getattr; */
2138 NULL, /* setattrfunc tp_setattr; */
2139 NULL, /* cmpfunc tp_compare; */
2140 ( reprfunc ) NULL, /* reprfunc tp_repr; */
2142 /* Method suites for standard classes */
2144 NULL, /* PyNumberMethods *tp_as_number; */
2145 &ConstraintSeq_as_sequence, /* PySequenceMethods *tp_as_sequence; */
2146 NULL, /* PyMappingMethods *tp_as_mapping; */
2148 /* More standard operations (here for binary compatibility) */
2150 NULL, /* hashfunc tp_hash; */
2151 NULL, /* ternaryfunc tp_call; */
2152 NULL, /* reprfunc tp_str; */
2153 NULL, /* getattrofunc tp_getattro; */
2154 NULL, /* setattrofunc tp_setattro; */
2156 /* Functions to access object as input/output buffer */
2157 NULL, /* PyBufferProcs *tp_as_buffer; */
2159 /*** Flags to define presence of optional/expanded features ***/
2160 Py_TPFLAGS_DEFAULT, /* long tp_flags; */
2162 NULL, /* char *tp_doc; Documentation string */
2163 /*** Assigned meaning in release 2.0 ***/
2164 /* call function for all accessible objects */
2165 NULL, /* traverseproc tp_traverse; */
2167 /* delete references to contained objects */
2168 NULL, /* inquiry tp_clear; */
2170 /*** Assigned meaning in release 2.1 ***/
2171 /*** rich comparisons ***/
2172 NULL, /* richcmpfunc tp_richcompare; */
2174 /*** weak reference enabler ***/
2175 0, /* long tp_weaklistoffset; */
2177 /*** Added in release 2.2 ***/
2179 ( getiterfunc )ConstraintSeq_getIter, /* getiterfunc tp_iter; */
2180 ( iternextfunc )ConstraintSeq_nextIter, /* iternextfunc tp_iternext; */
2182 /*** Attribute descriptor and subclassing stuff ***/
2183 BPy_ConstraintSeq_methods, /* struct PyMethodDef *tp_methods; */
2184 NULL, /* struct PyMemberDef *tp_members; */
2185 NULL, /* struct PyGetSetDef *tp_getset; */
2186 NULL, /* struct _typeobject *tp_base; */
2187 NULL, /* PyObject *tp_dict; */
2188 NULL, /* descrgetfunc tp_descr_get; */
2189 NULL, /* descrsetfunc tp_descr_set; */
2190 0, /* long tp_dictoffset; */
2191 NULL, /* initproc tp_init; */
2192 NULL, /* allocfunc tp_alloc; */
2193 NULL, /* newfunc tp_new; */
2194 /* Low-level free-memory routine */
2195 NULL, /* freefunc tp_free; */
2196 /* For PyObject_IS_GC */
2197 NULL, /* inquiry tp_is_gc; */
2198 NULL, /* PyObject *tp_bases; */
2199 /* method resolution order */
2200 NULL, /* PyObject *tp_mro; */
2201 NULL, /* PyObject *tp_cache; */
2202 NULL, /* PyObject *tp_subclasses; */
2203 NULL, /* PyObject *tp_weaklist; */
2207 /*****************************************************************************/
2208 /* Function: PoseConstraintSeq_CreatePyObject */
2209 /* Description: This function will create a new BPy_ConstraintSeq from an */
2210 /* existing ListBase structure. */
2211 /*****************************************************************************/
2212 PyObject *PoseConstraintSeq_CreatePyObject( bPoseChannel *pchan )
2214 BPy_ConstraintSeq *pyseq;
2217 for( ob = G.main->object.first; ob; ob = ob->id.next ) {
2218 if( ob->type == OB_ARMATURE ) {
2219 bPoseChannel *p = ob->pose->chanbase.first;
2222 pyseq = ( BPy_ConstraintSeq * ) PyObject_NEW(
2223 BPy_ConstraintSeq, &ConstraintSeq_Type );
2225 return EXPP_ReturnPyObjError( PyExc_MemoryError,
2226 "couldn't create BPy_ConstraintSeq object" );
2227 pyseq->pchan = pchan;
2229 return ( PyObject * ) pyseq;
2235 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2236 "couldn't find ANY armature with the pose!" );
2240 /*****************************************************************************/
2241 /* Function: ObConstraintSeq_CreatePyObject */
2242 /* Description: This function will create a new BPy_ConstraintSeq from an */
2243 /* existing ListBase structure. */
2244 /*****************************************************************************/
2245 PyObject *ObConstraintSeq_CreatePyObject( Object *obj )
2247 BPy_ConstraintSeq *pyseq;
2248 pyseq = ( BPy_ConstraintSeq * ) PyObject_NEW( BPy_ConstraintSeq,
2249 &ConstraintSeq_Type );
2251 return EXPP_ReturnPyObjError( PyExc_MemoryError,
2252 "couldn't create BPy_ConstraintSeq object" );
2254 pyseq->pchan = NULL;
2255 return ( PyObject * ) pyseq;
2258 static PyObject *M_Constraint_TypeDict( void )
2260 PyObject *S = PyConstant_New( );
2263 BPy_constant *d = ( BPy_constant * ) S;
2264 PyConstant_Insert( d, "NULL",
2265 PyInt_FromLong( CONSTRAINT_TYPE_NULL ) );
2266 PyConstant_Insert( d, "TRACKTO",
2267 PyInt_FromLong( CONSTRAINT_TYPE_TRACKTO ) );
2268 PyConstant_Insert( d, "IKSOLVER",
2269 PyInt_FromLong( CONSTRAINT_TYPE_KINEMATIC ) );
2270 PyConstant_Insert( d, "FOLLOWPATH",
2271 PyInt_FromLong( CONSTRAINT_TYPE_FOLLOWPATH ) );
2272 PyConstant_Insert( d, "COPYROT",
2273 PyInt_FromLong( CONSTRAINT_TYPE_ROTLIKE ) );
2274 PyConstant_Insert( d, "COPYLOC",
2275 PyInt_FromLong( CONSTRAINT_TYPE_LOCLIKE ) );
2276 PyConstant_Insert( d, "COPYSIZE",
2277 PyInt_FromLong( CONSTRAINT_TYPE_SIZELIKE ) );
2278 PyConstant_Insert( d, "ACTION",
2279 PyInt_FromLong( CONSTRAINT_TYPE_ACTION ) );
2280 PyConstant_Insert( d, "LOCKTRACK",
2281 PyInt_FromLong( CONSTRAINT_TYPE_LOCKTRACK ) );
2282 PyConstant_Insert( d, "STRETCHTO",
2283 PyInt_FromLong( CONSTRAINT_TYPE_STRETCHTO ) );
2284 PyConstant_Insert( d, "FLOOR",
2285 PyInt_FromLong( CONSTRAINT_TYPE_MINMAX ) );
2286 PyConstant_Insert( d, "LIMITLOC",
2287 PyInt_FromLong( CONSTRAINT_TYPE_LOCLIMIT ) );
2288 PyConstant_Insert( d, "LIMITROT",
2289 PyInt_FromLong( CONSTRAINT_TYPE_ROTLIMIT ) );
2290 PyConstant_Insert( d, "LIMITSIZE",
2291 PyInt_FromLong( CONSTRAINT_TYPE_SIZELIMIT ) );
2292 PyConstant_Insert( d, "RIGIDBODYJOINT",
2293 PyInt_FromLong( CONSTRAINT_TYPE_RIGIDBODYJOINT ) );
2294 PyConstant_Insert( d, "CLAMPTO",
2295 PyInt_FromLong( CONSTRAINT_TYPE_CLAMPTO ) );
2296 PyConstant_Insert( d, "PYTHON",
2297 PyInt_FromLong( CONSTRAINT_TYPE_PYTHON ) );
2298 PyConstant_Insert( d, "CHILDOF",
2299 PyInt_FromLong( CONSTRAINT_TYPE_CHILDOF ) );
2300 PyConstant_Insert( d, "TRANSFORM",
2301 PyInt_FromLong( CONSTRAINT_TYPE_TRANSFORM ) );
2306 static PyObject *M_Constraint_SettingsDict( void )
2308 PyObject *S = PyConstant_New( );
2311 BPy_constant *d = ( BPy_constant * ) S;
2312 PyConstant_Insert( d, "XROT",
2313 PyInt_FromLong( EXPP_CONSTR_XROT ) );
2314 PyConstant_Insert( d, "YROT",
2315 PyInt_FromLong( EXPP_CONSTR_YROT ) );
2316 PyConstant_Insert( d, "ZROT",
2317 PyInt_FromLong( EXPP_CONSTR_ZROT ) );
2318 PyConstant_Insert( d, "XSIZE",
2319 PyInt_FromLong( EXPP_CONSTR_XSIZE ) );
2320 PyConstant_Insert( d, "YSIZE",
2321 PyInt_FromLong( EXPP_CONSTR_YSIZE ) );
2322 PyConstant_Insert( d, "ZSIZE",
2323 PyInt_FromLong( EXPP_CONSTR_ZSIZE ) );
2324 PyConstant_Insert( d, "XLOC",
2325 PyInt_FromLong( EXPP_CONSTR_XLOC ) );
2326 PyConstant_Insert( d, "YLOC",
2327 PyInt_FromLong( EXPP_CONSTR_YLOC ) );
2328 PyConstant_Insert( d, "ZLOC",
2329 PyInt_FromLong( EXPP_CONSTR_ZLOC ) );
2331 PyConstant_Insert( d, "UPX",
2332 PyInt_FromLong( UP_X ) );
2333 PyConstant_Insert( d, "UPY",
2334 PyInt_FromLong( UP_Y ) );
2335 PyConstant_Insert( d, "UPZ",
2336 PyInt_FromLong( UP_Z ) );
2338 PyConstant_Insert( d, "TRACKX",
2339 PyInt_FromLong( TRACK_X ) );
2340 PyConstant_Insert( d, "TRACKY",
2341 PyInt_FromLong( TRACK_Y ) );
2342 PyConstant_Insert( d, "TRACKZ",
2343 PyInt_FromLong( TRACK_Z ) );
2344 PyConstant_Insert( d, "TRACKNEGX",
2345 PyInt_FromLong( TRACK_nX ) );
2346 PyConstant_Insert( d, "TRACKNEGY",
2347 PyInt_FromLong( TRACK_nY ) );
2348 PyConstant_Insert( d, "TRACKNEGZ",
2349 PyInt_FromLong( TRACK_nZ ) );
2351 PyConstant_Insert( d, "VOLUMEXZ",
2352 PyInt_FromLong( VOLUME_XZ ) );
2353 PyConstant_Insert( d, "VOLUMEX",
2354 PyInt_FromLong( VOLUME_X ) );
2355 PyConstant_Insert( d, "VOLUMEZ",
2356 PyInt_FromLong( VOLUME_Z ) );
2357 PyConstant_Insert( d, "VOLUMENONE",
2358 PyInt_FromLong( NO_VOLUME ) );
2360 PyConstant_Insert( d, "PLANEX",
2361 PyInt_FromLong( PLANE_X ) );
2362 PyConstant_Insert( d, "PLANEY",
2363 PyInt_FromLong( PLANE_Y ) );
2364 PyConstant_Insert( d, "PLANEZ",
2365 PyInt_FromLong( PLANE_Z ) );
2367 PyConstant_Insert( d, "LOCKX",
2368 PyInt_FromLong( LOCK_X ) );
2369 PyConstant_Insert( d, "LOCKY",
2370 PyInt_FromLong( LOCK_Y ) );
2371 PyConstant_Insert( d, "LOCKZ",
2372 PyInt_FromLong( LOCK_Z ) );
2374 PyConstant_Insert( d, "MAXX",
2375 PyInt_FromLong( EXPP_CONSTR_MAXX ) );
2376 PyConstant_Insert( d, "MAXY",
2377 PyInt_FromLong( EXPP_CONSTR_MAXY ) );
2378 PyConstant_Insert( d, "MAXZ",
2379 PyInt_FromLong( EXPP_CONSTR_MAXZ ) );
2380 PyConstant_Insert( d, "MINX",
2381 PyInt_FromLong( EXPP_CONSTR_MINX ) );
2382 PyConstant_Insert( d, "MINY",
2383 PyInt_FromLong( EXPP_CONSTR_MINY ) );
2384 PyConstant_Insert( d, "MINZ",
2385 PyInt_FromLong( EXPP_CONSTR_MINZ ) );
2387 PyConstant_Insert( d, "COPYX",
2388 PyInt_FromLong( LOCLIKE_X ) );
2389 PyConstant_Insert( d, "COPYY",
2390 PyInt_FromLong( LOCLIKE_Y ) );
2391 PyConstant_Insert( d, "COPYZ",
2392 PyInt_FromLong( LOCLIKE_Z ) );
2393 PyConstant_Insert( d, "COPYXINVERT",
2394 PyInt_FromLong( LOCLIKE_X_INVERT ) );
2395 PyConstant_Insert( d, "COPYYINVERT",
2396 PyInt_FromLong( LOCLIKE_Y_INVERT ) );
2397 PyConstant_Insert( d, "COPYZINVERT",
2398 PyInt_FromLong( LOCLIKE_Z_INVERT ) );
2400 PyConstant_Insert( d, "PARLOCX",
2401 PyInt_FromLong( CHILDOF_LOCX ) );
2402 PyConstant_Insert( d, "PARLOCY",
2403 PyInt_FromLong( CHILDOF_LOCY ) );
2404 PyConstant_Insert( d, "PARLOCZ",
2405 PyInt_FromLong( CHILDOF_LOCZ ) );
2406 PyConstant_Insert( d, "PARROTX",
2407 PyInt_FromLong( CHILDOF_ROTX ) );
2408 PyConstant_Insert( d, "PARROTY",
2409 PyInt_FromLong( CHILDOF_ROTY ) );
2410 PyConstant_Insert( d, "PARROTZ",
2411 PyInt_FromLong( CHILDOF_ROTZ ) );
2412 PyConstant_Insert( d, "PARSIZEX",
2413 PyInt_FromLong( CHILDOF_LOCX ) );
2414 PyConstant_Insert( d, "PARSIZEY",
2415 PyInt_FromLong( CHILDOF_SIZEY ) );
2416 PyConstant_Insert( d, "PARSIZEZ",
2417 PyInt_FromLong( CHILDOF_SIZEZ ) );
2419 PyConstant_Insert( d, "CLAMPAUTO",
2420 PyInt_FromLong( CLAMPTO_AUTO ) );
2421 PyConstant_Insert( d, "CLAMPX",
2422 PyInt_FromLong( CLAMPTO_X ) );
2423 PyConstant_Insert( d, "CLAMPY",
2424 PyInt_FromLong( CLAMPTO_Y ) );
2425 PyConstant_Insert( d, "CLAMPZ",
2426 PyInt_FromLong( CLAMPTO_Z ) );
2427 PyConstant_Insert( d, "CLAMPCYCLIC",
2428 PyInt_FromLong( EXPP_CONSTR_CLAMPCYCLIC ));
2430 PyConstant_Insert( d, "TARGET",
2431 PyInt_FromLong( EXPP_CONSTR_TARGET ) );
2432 PyConstant_Insert( d, "STRETCH",
2433 PyInt_FromLong( EXPP_CONSTR_STRETCH ) );
2434 PyConstant_Insert( d, "ITERATIONS",
2435 PyInt_FromLong( EXPP_CONSTR_ITERATIONS ) );
2436 PyConstant_Insert( d, "BONE",
2437 PyInt_FromLong( EXPP_CONSTR_BONE ) );
2438 PyConstant_Insert( d, "CHAINLEN",
2439 PyInt_FromLong( EXPP_CONSTR_CHAINLEN ) );
2440 PyConstant_Insert( d, "POSWEIGHT",
2441 PyInt_FromLong( EXPP_CONSTR_POSWEIGHT ) );
2442 PyConstant_Insert( d, "ROTWEIGHT",
2443 PyInt_FromLong( EXPP_CONSTR_ROTWEIGHT ) );
2444 PyConstant_Insert( d, "ROTATE",
2445 PyInt_FromLong( EXPP_CONSTR_ROTATE ) );
2446 PyConstant_Insert( d, "USETIP",
2447 PyInt_FromLong( EXPP_CONSTR_USETIP ) );
2449 PyConstant_Insert( d, "ACTION",
2450 PyInt_FromLong( EXPP_CONSTR_ACTION ) );
2451 PyConstant_Insert( d, "START",
2452 PyInt_FromLong( EXPP_CONSTR_START ) );
2453 PyConstant_Insert( d, "END",
2454 PyInt_FromLong( EXPP_CONSTR_END ) );
2455 PyConstant_Insert( d, "MIN",
2456 PyInt_FromLong( EXPP_CONSTR_MIN ) );
2457 PyConstant_Insert( d, "MAX",
2458 PyInt_FromLong( EXPP_CONSTR_MAX ) );
2459 PyConstant_Insert( d, "KEYON",
2460 PyInt_FromLong( EXPP_CONSTR_KEYON ) );
2462 PyConstant_Insert( d, "TRACK",
2463 PyInt_FromLong( EXPP_CONSTR_TRACK ) );
2464 PyConstant_Insert( d, "UP",
2465 PyInt_FromLong( EXPP_CONSTR_UP ) );
2467 PyConstant_Insert( d, "RESTLENGTH",
2468 PyInt_FromLong( EXPP_CONSTR_RESTLENGTH ) );
2469 PyConstant_Insert( d, "VOLVARIATION",
2470 PyInt_FromLong( EXPP_CONSTR_VOLVARIATION ) );
2471 PyConstant_Insert( d, "VOLUMEMODE",
2472 PyInt_FromLong( EXPP_CONSTR_VOLUMEMODE ) );
2473 PyConstant_Insert( d, "PLANE",
2474 PyInt_FromLong( EXPP_CONSTR_PLANE ) );
2476 PyConstant_Insert( d, "FOLLOW",
2477 PyInt_FromLong( EXPP_CONSTR_FOLLOW ) );
2478 PyConstant_Insert( d, "OFFSET",
2479 PyInt_FromLong( EXPP_CONSTR_OFFSET ) );
2480 PyConstant_Insert( d, "FORWARD",
2481 PyInt_FromLong( EXPP_CONSTR_FORWARD ) );
2483 PyConstant_Insert( d, "LOCK",
2484 PyInt_FromLong( EXPP_CONSTR_LOCK ) );
2486 PyConstant_Insert( d, "COPY",
2487 PyInt_FromLong( EXPP_CONSTR_COPY ) );
2488 PyConstant_Insert( d, "LIMIT",
2489 PyInt_FromLong( EXPP_CONSTR_LIMIT ) );
2490 PyConstant_Insert( d, "CLAMP",
2491 PyInt_FromLong( EXPP_CONSTR_CLAMP ) );
2493 PyConstant_Insert( d, "LIMIT_XMIN",
2494 PyInt_FromLong( EXPP_CONSTR_LIMXMIN ) );
2495 PyConstant_Insert( d, "LIMIT_XMAX",
2496 PyInt_FromLong( EXPP_CONSTR_LIMXMAX ) );
2497 PyConstant_Insert( d, "LIMIT_YMIN",
2498 PyInt_FromLong( EXPP_CONSTR_LIMYMIN ) );
2499 PyConstant_Insert( d, "LIMIT_YMAX",
2500 PyInt_FromLong( EXPP_CONSTR_LIMYMAX ) );
2501 PyConstant_Insert( d, "LIMIT_ZMIN",
2502 PyInt_FromLong( EXPP_CONSTR_LIMZMIN ) );
2503 PyConstant_Insert( d, "LIMIT_ZMAX",
2504 PyInt_FromLong( EXPP_CONSTR_LIMZMAX ) );
2506 PyConstant_Insert( d, "LIMIT_XROT",
2507 PyInt_FromLong( EXPP_CONSTR_LIMXROT ) );
2508 PyConstant_Insert( d, "LIMIT_YROT",
2509 PyInt_FromLong( EXPP_CONSTR_LIMYROT ) );
2510 PyConstant_Insert( d, "LIMIT_ZROT",
2511 PyInt_FromLong( EXPP_CONSTR_LIMZROT ) );
2513 PyConstant_Insert( d, "XMIN",
2514 PyInt_FromLong( EXPP_CONSTR_XMIN ) );
2515 PyConstant_Insert( d, "XMAX",
2516 PyInt_FromLong( EXPP_CONSTR_XMAX ) );
2517 PyConstant_Insert( d, "YMIN",
2518 PyInt_FromLong( EXPP_CONSTR_YMIN ) );
2519 PyConstant_Insert( d, "YMAX",
2520 PyInt_FromLong( EXPP_CONSTR_YMAX ) );
2521 PyConstant_Insert( d, "ZMIN",
2522 PyInt_FromLong( EXPP_CONSTR_ZMIN ) );
2523 PyConstant_Insert( d, "ZMAX",
2524 PyInt_FromLong( EXPP_CONSTR_ZMAX ) );
2526 PyConstant_Insert( d, "SCRIPT",
2527 PyInt_FromLong( EXPP_CONSTR_SCRIPT ) );
2528 PyConstant_Insert( d, "PROPERTIES",
2529 PyInt_FromLong( EXPP_CONSTR_PROPS ) );
2531 PyConstant_Insert( d, "FROM",
2532 PyInt_FromLong( EXPP_CONSTR_FROM ) );
2533 PyConstant_Insert( d, "TO",
2534 PyInt_FromLong( EXPP_CONSTR_TO ) );
2535 PyConstant_Insert( d, "EXTRAPOLATE",
2536 PyInt_FromLong( EXPP_CONSTR_EXPO ) );
2537 PyConstant_Insert( d, "MAPX",
2538 PyInt_FromLong( EXPP_CONSTR_MAPX ) );
2539 PyConstant_Insert( d, "MAPY",
2540 PyInt_FromLong( EXPP_CONSTR_MAPY ) );
2541 PyConstant_Insert( d, "MAPZ",
2542 PyInt_FromLong( EXPP_CONSTR_MAPZ ) );
2543 PyConstant_Insert( d, "FROM_MINX",
2544 PyInt_FromLong( EXPP_CONSTR_FROMMINX ) );
2545 PyConstant_Insert( d, "FROM_MAXX",
2546 PyInt_FromLong( EXPP_CONSTR_FROMMAXX ) );
2547 PyConstant_Insert( d, "FROM_MINY",
2548 PyInt_FromLong( EXPP_CONSTR_FROMMINY ) );
2549 PyConstant_Insert( d, "FROM_MAXY",
2550 PyInt_FromLong( EXPP_CONSTR_FROMMAXY ) );
2551 PyConstant_Insert( d, "FROM_MINZ",
2552 PyInt_FromLong( EXPP_CONSTR_FROMMINZ ) );
2553 PyConstant_Insert( d, "FROM_MAXZ",
2554 PyInt_FromLong( EXPP_CONSTR_FROMMAXZ ) );
2555 PyConstant_Insert( d, "TO_MINX",
2556 PyInt_FromLong( EXPP_CONSTR_TOMINX ) );
2557 PyConstant_Insert( d, "TO_MAXX",
2558 PyInt_FromLong( EXPP_CONSTR_TOMAXX ) );
2559 PyConstant_Insert( d, "TO_MINY",
2560 PyInt_FromLong( EXPP_CONSTR_TOMINY ) );
2561 PyConstant_Insert( d, "TO_MAXY",
2562 PyInt_FromLong( EXPP_CONSTR_TOMAXY ) );
2563 PyConstant_Insert( d, "TO_MINZ",
2564 PyInt_FromLong( EXPP_CONSTR_TOMINZ ) );
2565 PyConstant_Insert( d, "TO_MAXZ",
2566 PyInt_FromLong( EXPP_CONSTR_TOMAXZ ) );
2568 PyConstant_Insert( d, "LOC",
2569 PyInt_FromLong( 0 ) );
2570 PyConstant_Insert( d, "ROT",
2571 PyInt_FromLong( 1 ) );
2572 PyConstant_Insert( d, "SCALE",
2573 PyInt_FromLong( 2 ) );
2575 PyConstant_Insert( d, "CONSTR_RB_TYPE",
2576 PyInt_FromLong( EXPP_CONSTR_RB_TYPE ) );
2577 PyConstant_Insert( d, "CONSTR_RB_BALL",
2578 PyInt_FromLong( EXPP_CONSTR_RB_BALL ) );
2579 PyConstant_Insert( d, "CONSTR_RB_HINGE",
2580 PyInt_FromLong( EXPP_CONSTR_RB_HINGE ) );
2581 PyConstant_Insert( d, "CONSTR_RB_GENERIC6DOF",
2582 PyInt_FromLong( EXPP_CONSTR_RB_GENERIC6DOF ) );
2583 PyConstant_Insert( d, "CONSTR_RB_VEHICLE",
2584 PyInt_FromLong( EXPP_CONSTR_RB_VEHICLE ) );
2585 PyConstant_Insert( d, "CONSTR_RB_PIVX",
2586 PyInt_FromLong( EXPP_CONSTR_RB_PIVX ) );
2587 PyConstant_Insert( d, "CONSTR_RB_PIVY",
2588 PyInt_FromLong( EXPP_CONSTR_RB_PIVY ) );
2589 PyConstant_Insert( d, "CONSTR_RB_PIVZ",
2590 PyInt_FromLong( EXPP_CONSTR_RB_PIVZ ) );
2591 PyConstant_Insert( d, "CONSTR_RB_AXX",
2592 PyInt_FromLong( EXPP_CONSTR_RB_AXX ) );
2593 PyConstant_Insert( d, "CONSTR_RB_AXY",
2594 PyInt_FromLong( EXPP_CONSTR_RB_AXY ) );
2595 PyConstant_Insert( d, "CONSTR_RB_AXZ",
2596 PyInt_FromLong( EXPP_CONSTR_RB_AXZ ) );
2597 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT0",
2598 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT0 ) );
2599 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT1",
2600 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT1 ) );
2601 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT2",
2602 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT2 ) );
2603 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT3",
2604 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT3 ) );
2605 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT4",
2606 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT4 ) );
2607 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT5",
2608 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT5 ) );
2609 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT0",
2610 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT0 ) );
2611 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT1",
2612 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT1 ) );
2613 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT2",
2614 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT2 ) );
2615 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT3",
2616 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT3 ) );
2617 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT4",
2618 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT4 ) );
2619 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT5",
2620 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT5 ) );
2621 PyConstant_Insert( d, "CONSTR_RB_EXTRAFZ",
2622 PyInt_FromLong( EXPP_CONSTR_RB_EXTRAFZ ) );
2623 PyConstant_Insert( d, "CONSTR_RB_FLAG",
2624 PyInt_FromLong( EXPP_CONSTR_RB_FLAG ) );
2627 PyConstant_Insert( d, "OWNERSPACE",
2628 PyInt_FromLong( EXPP_CONSTR_OWNSPACE ) );
2629 PyConstant_Insert( d, "TARGETSPACE",
2630 PyInt_FromLong( EXPP_CONSTR_TARSPACE ) );
2632 PyConstant_Insert( d, "SPACE_WORLD",
2633 PyInt_FromLong( CONSTRAINT_SPACE_WORLD) );
2634 PyConstant_Insert( d, "SPACE_LOCAL",
2635 PyInt_FromLong( CONSTRAINT_SPACE_LOCAL ) );
2636 PyConstant_Insert( d, "SPACE_POSE",
2637 PyInt_FromLong( CONSTRAINT_SPACE_POSE) );
2638 PyConstant_Insert( d, "SPACE_PARLOCAL",
2639 PyInt_FromLong( CONSTRAINT_SPACE_PARLOCAL ) );
2644 /*****************************************************************************/
2645 /* Function: Constraint_Init */
2646 /*****************************************************************************/
2647 PyObject *Constraint_Init( void )
2649 PyObject *submodule;
2650 PyObject *TypeDict = M_Constraint_TypeDict( );
2651 PyObject *SettingsDict = M_Constraint_SettingsDict( );
2653 if( PyType_Ready( &ConstraintSeq_Type ) < 0
2654 || PyType_Ready( &Constraint_Type ) < 0 )
2657 submodule = Py_InitModule3( "Blender.Constraint", NULL,
2658 "Constraint module for accessing and creating constraint data" );
2661 PyModule_AddObject( submodule, "Type", TypeDict );
2664 PyModule_AddObject( submodule, "Settings", SettingsDict );