diff options
author | Joshua Leung <aligorith@gmail.com> | 2008-03-16 09:28:40 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2008-03-16 09:28:40 +0300 |
commit | eab07f7322d8c16fed7dfed5cdf683e78ccd2b6d (patch) | |
tree | 5b6cd8bcaa9522eb452a96ca8f506916cbdbe86f /source/blender/python/api2_2x/Constraint.c | |
parent | e3d05088827ae08ca5749e95474a60d673199dcd (diff) |
Constraints Py-Api:
Fixed up Py-API access to PyConstraints. Also updated docs to reflect these changes.
Diffstat (limited to 'source/blender/python/api2_2x/Constraint.c')
-rw-r--r-- | source/blender/python/api2_2x/Constraint.c | 125 |
1 files changed, 101 insertions, 24 deletions
diff --git a/source/blender/python/api2_2x/Constraint.c b/source/blender/python/api2_2x/Constraint.c index 9ca0d8d2545..9b76765902a 100644 --- a/source/blender/python/api2_2x/Constraint.c +++ b/source/blender/python/api2_2x/Constraint.c @@ -1391,11 +1391,40 @@ static PyObject *script_getter( BPy_Constraint * self, int type ) bPythonConstraint *con = (bPythonConstraint *)(self->con->data); switch( type ) { - // FIXME!!! - //case EXPP_CONSTR_TARGET: - // return Object_CreatePyObject( con->tar ); - //case EXPP_CONSTR_BONE: - // return PyString_FromString( con->subtarget ); + case EXPP_CONSTR_TARGET: + case EXPP_CONSTR_BONE: + { + bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_PYTHON); + bConstraintTarget *ct; + PyObject *tlist=NULL, *val; + + if (cti) { + /* change space of targets */ + if (cti->get_constraint_targets) { + ListBase targets = {NULL, NULL}; + int num_tars=0, i=0; + + /* get targets, and create py-list for use temporarily */ + num_tars= cti->get_constraint_targets(self->con, &targets); + if (num_tars) { + tlist= PyList_New(num_tars); + + for (ct=targets.first; ct; ct=ct->next, i++) { + if (type == EXPP_CONSTR_BONE) + val= PyString_FromString(ct->subtarget); + else + val= Object_CreatePyObject(ct->tar); + PyList_SET_ITEM(tlist, i, val); + } + } + + if (cti->flush_constraint_targets) + cti->flush_constraint_targets(self->con, &targets, 1); + } + } + + return tlist; + } case EXPP_CONSTR_SCRIPT: return Text_CreatePyObject( con->text ); case EXPP_CONSTR_PROPS: @@ -1410,25 +1439,73 @@ static int script_setter( BPy_Constraint *self, int type, PyObject *value ) bPythonConstraint *con = (bPythonConstraint *)(self->con->data); switch( type ) { - // FIXME!!! - //case EXPP_CONSTR_TARGET: { - // Object *obj = (( BPy_Object * )value)->object; - // if( !BPy_Object_Check( value ) ) - // return EXPP_ReturnIntError( PyExc_TypeError, - // "expected BPy object argument" ); - // con->tar = obj; - // return 0; - // } - //case EXPP_CONSTR_BONE: { - // char *name = PyString_AsString( value ); - // if( !name ) - // return EXPP_ReturnIntError( PyExc_TypeError, - // "expected string arg" ); - // - // BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) ); - // - // return 0; - // } + case EXPP_CONSTR_TARGET: + case EXPP_CONSTR_BONE: + { + bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_PYTHON); + bConstraintTarget *ct; + int ok= 0; + + if (cti) { + /* change space of targets */ + if (cti->get_constraint_targets) { + ListBase targets = {NULL, NULL}; + int num_tars=0, i=0; + + /* get targets, and extract values from the given list */ + num_tars= cti->get_constraint_targets(self->con, &targets); + if (num_tars) { + if ((PySequence_Check(value) == 0) || (PySequence_Size(value) != num_tars)) { + char errorstr[64]; + sprintf(errorstr, "expected sequence of %d integer(s)", num_tars); + return EXPP_ReturnIntError(PyExc_TypeError, errorstr); + } + + for (ct=targets.first; ct; ct=ct->next, i++) { + PyObject *val= PySequence_ITEM(value, i); + + if (type == EXPP_CONSTR_BONE) { + char *name = PyString_AsString(val); + + if (name == NULL) { + // hrm... should we break here instead? + ok = EXPP_ReturnIntError(PyExc_TypeError, + "expected string arg as member of list"); + Py_DECREF(val); + + break; + } + + BLI_strncpy(ct->subtarget, name, sizeof(ct->subtarget)); + } + else { + Object *obj = (( BPy_Object * )val)->object; + + if ( !BPy_Object_Check(value) ) { + // hrm... should we break here instead? + ok = EXPP_ReturnIntError(PyExc_TypeError, + "expected BPy object argument as member of list"); + Py_DECREF(val); + + break; + } + + ct->tar = obj; + } + + Py_DECREF(val); + } + } + + /* only flush changes to real constraints if all were successful */ + if ((cti->flush_constraint_targets) && (ok == 0)) + cti->flush_constraint_targets(self->con, &targets, 0); + } + } + + return ok; + } + break; case EXPP_CONSTR_SCRIPT: { Text *text = (( BPy_Text * )value)->text; if( !BPy_Object_Check( value ) ) |