===Python API===
authorKen Hughes <khughes@pacific.edu>
Fri, 12 May 2006 04:34:02 +0000 (04:34 +0000)
committerKen Hughes <khughes@pacific.edu>
Fri, 12 May 2006 04:34:02 +0000 (04:34 +0000)
Added NULL constraint (and fixed bug that didn't allow appending FLOOR
constraint), and added support for Constraint.Settings.LOCAL key support in
COPYLOC, COPYROT and COPYSIZE constraints when target object is an armature.

source/blender/python/api2_2x/Constraint.c
source/blender/python/api2_2x/doc/Constraint.py

index 5572411ea85388a812ff0c0201c839547d28fe03..8fcb155c9d6688a0b19709a7bc10025c684f88ea 100644 (file)
@@ -41,6 +41,7 @@
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_action.h"
+#include "BKE_armature.h"
 #include "BLI_blenlib.h"
 #include "BIF_editconstraint.h"
 #include "BSE_editipo.h"
@@ -826,6 +827,10 @@ static PyObject *locatelike_getter( BPy_Constraint * self, int type )
                return PyString_FromString( con->subtarget );
        case EXPP_CONSTR_COPY:
                return PyInt_FromLong( (long)con->flag );
+       case EXPP_CONSTR_LOCAL:
+               if( get_armature( con->tar ) )
+                       return PyBool_FromLong( (long)( self->con->flag & CONSTRAINT_LOCAL ) ) ;
+               Py_RETURN_NONE;
        default:
                return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
        }
@@ -857,6 +862,12 @@ static int locatelike_setter( BPy_Constraint *self, int type, PyObject *value )
        case EXPP_CONSTR_COPY:
                return EXPP_setIValueRange( value, &con->flag,
                                0, LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z, 'i' );
+       case EXPP_CONSTR_LOCAL:
+               if( !get_armature( con->tar ) )
+                       return EXPP_ReturnIntError( PyExc_RuntimeError,
+                                       "only armature targets have LOCAL key" );
+               return EXPP_setBitfield( value, &self->con->flag,
+                               CONSTRAINT_LOCAL, 'h' );
        default:
                return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
        }
@@ -873,6 +884,10 @@ static PyObject *rotatelike_getter( BPy_Constraint * self, int type )
                return PyString_FromString( con->subtarget );
        case EXPP_CONSTR_COPY:
                return PyInt_FromLong( (long)con->flag );
+       case EXPP_CONSTR_LOCAL:
+               if( get_armature( con->tar ) )
+                       return PyBool_FromLong( (long)( self->con->flag & SELECT ) ) ;
+               Py_RETURN_NONE;
        default:
                return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
        }
@@ -904,6 +919,11 @@ static int rotatelike_setter( BPy_Constraint *self, int type, PyObject *value )
        case EXPP_CONSTR_COPY:
                return EXPP_setIValueRange( value, &con->flag,
                                0, LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z, 'i' );
+       case EXPP_CONSTR_LOCAL:
+               if( !get_armature( con->tar ) )
+                       return EXPP_ReturnIntError( PyExc_RuntimeError,
+                                       "only armature targets have LOCAL key" );
+               return EXPP_setBitfield( value, &self->con->flag, SELECT, 'h' );
        default:
                return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
        }
@@ -920,6 +940,10 @@ static PyObject *sizelike_getter( BPy_Constraint * self, int type )
                return PyString_FromString( con->subtarget );
        case EXPP_CONSTR_COPY:
                return PyInt_FromLong( (long)con->flag );
+       case EXPP_CONSTR_LOCAL:
+               if( get_armature( con->tar ) )
+                       return PyBool_FromLong( (long)( self->con->flag & SELECT ) ) ;
+               Py_RETURN_NONE;
        default:
                return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
        }
@@ -951,6 +975,11 @@ static int sizelike_setter( BPy_Constraint *self, int type, PyObject *value )
        case EXPP_CONSTR_COPY:
                return EXPP_setIValueRange( value, &con->flag,
                                0, LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z, 'i' );
+       case EXPP_CONSTR_LOCAL:
+               if( !get_armature( con->tar ) )
+                       return EXPP_ReturnIntError( PyExc_RuntimeError,
+                                       "only armature targets have LOCAL key" );
+               return EXPP_setBitfield( value, &self->con->flag, SELECT, 'h' );
        default:
                return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
        }
@@ -1052,6 +1081,8 @@ static int Constraint_setData( BPy_Constraint * self, PyObject * key,
        case CONSTRAINT_TYPE_SIZELIKE:
                result = sizelike_setter( self, key_int, arg );
                break;
+       case CONSTRAINT_TYPE_NULL:
+               return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
        case CONSTRAINT_TYPE_CHILDOF:   /* Unimplemented */
        case CONSTRAINT_TYPE_ROTLIMIT:
        case CONSTRAINT_TYPE_LOCLIMIT:
@@ -1236,7 +1267,7 @@ static PyObject *ConstraintSeq_append( BPy_ConstraintSeq *self, PyObject *args )
                EXPP_ReturnPyObjError( PyExc_TypeError, "expected int argument" );
 
        /* type 0 is CONSTRAINT_TYPE_NULL, should we be able to add one of these? */
-       if( type <= CONSTRAINT_TYPE_NULL || type >= CONSTRAINT_TYPE_MINMAX ) 
+       if( type < CONSTRAINT_TYPE_NULL || type > CONSTRAINT_TYPE_MINMAX ) 
                return EXPP_ReturnPyObjError( PyExc_ValueError,
                                "int argument out of range" );
 
index bdc5e56728c33e70a70c7d66ad08d34346a20f1c..be42bd7e2b195e796e49ac8e940e1f124c50826b 100644 (file)
@@ -31,7 +31,7 @@ Or to print all the constraints attached to each bone in a pose::
 @var Type: Constant Constraint dict used by L{ConstraintSeq.append()} and 
   for comparison with L{Constraint.type}.  Values are
   TRACKTO, IKSOLVER, FOLLOWPATH, COPYROT, COPYLOC, COPYSIZE, ACTION,
-  LOCKTRACK, STRETCHTO, FLOOR
+  LOCKTRACK, STRETCHTO, FLOOR, NULL
 
 @type Settings: readonly dictionary
 @var Settings: Constant dict used for changing constraint settings.
@@ -82,6 +82,7 @@ Or to print all the constraints attached to each bone in a pose::
   - Used by Copy Location (COPYLOC), Copy Rotation (COPYROT), and Copy Size
   (COPYSIZE) constraint:
     - COPY (bitfield): any combination of COPYX, COPYY and COPYZ
+    - LOCAL (bool): Only for constraints which Armature targets.
 
 """