svn merge ^/trunk/blender -r55815:55840

This commit is contained in:
Sergey Sharybin
2013-04-06 13:24:34 +00:00
87 changed files with 962 additions and 249 deletions

View File

@@ -33,6 +33,7 @@
#include <Python.h>
#include "BLI_utildefines.h"
#include "BLI_dynstr.h"
#include "MEM_guardedalloc.h"
@@ -68,6 +69,76 @@ static PyObject *bpy_bmesh_op_repr(BPy_BMeshOpFunc *self)
}
/* methods
* ======= */
/* __doc__
* ------- */
static char *bmp_slots_as_args(const BMOSlotType slot_types[BMO_OP_MAX_SLOTS], const bool is_out)
{
DynStr *dyn_str = BLI_dynstr_new();
char *ret;
int i = 0;
while (*slot_types[i].name) {
/* cut off '.out' by using a string size arg */
const int name_len = is_out ?
(strchr(slot_types[i].name, '.') - slot_types[i].name) :
sizeof(slot_types[i].name);
const char *value = "<Unknown>";
switch (slot_types[i].type) {
case BMO_OP_SLOT_BOOL: value = "False"; break;
case BMO_OP_SLOT_INT: value = "0"; break;
case BMO_OP_SLOT_FLT: value = "0.0"; break;
case BMO_OP_SLOT_PTR: value = "None"; break;
case BMO_OP_SLOT_MAT: value = "Matrix()"; break;
case BMO_OP_SLOT_VEC: value = "Vector()"; break;
case BMO_OP_SLOT_ELEMENT_BUF: value =
(slot_types[i].subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) ? "None" : "[]"; break;
case BMO_OP_SLOT_MAPPING: value = "{}"; break;
}
BLI_dynstr_appendf(dyn_str, i ? ", %.*s=%s" : "%.*s=%s", name_len, slot_types[i].name, value);
i++;
};
ret = BLI_dynstr_get_cstring(dyn_str);
BLI_dynstr_free(dyn_str);
return ret;
}
static PyObject *bpy_bmesh_op_doc_get(BPy_BMeshOpFunc *self, void *UNUSED(closure))
{
PyObject *ret;
char *slot_in;
char *slot_out;
int i;
i = BMO_opcode_from_opname(self->opname);
slot_in = bmp_slots_as_args(bmo_opdefines[i]->slot_types_in, false);
slot_out = bmp_slots_as_args(bmo_opdefines[i]->slot_types_out, true);
ret = PyUnicode_FromFormat("%.200s bmesh.ops.%.200s(bmesh, %s)\n -> dict(%s)",
Py_TYPE(self)->tp_name,
self->opname, slot_in, slot_out);
MEM_freeN(slot_in);
MEM_freeN(slot_out);
return ret;
}
static PyGetSetDef bpy_bmesh_op_getseters[] = {
{(char *)"__doc__", (getter)bpy_bmesh_op_doc_get, (setter)NULL, NULL, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
/* Types
* ===== */
PyTypeObject bmesh_op_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
@@ -126,7 +197,7 @@ PyTypeObject bmesh_op_Type = {
/*** Attribute descriptor and subclassing stuff ***/
NULL, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
NULL, /* struct PyGetSetDef *tp_getset; */
bpy_bmesh_op_getseters, /* struct PyGetSetDef *tp_getset; */
NULL, /* struct _typeobject *tp_base; */
NULL, /* PyObject *tp_dict; */
NULL, /* descrgetfunc tp_descr_get; */
@@ -154,20 +225,17 @@ PyTypeObject bmesh_op_Type = {
static PyObject *bpy_bmesh_ops_fakemod_getattro(PyObject *UNUSED(self), PyObject *pyname)
{
const unsigned int tot = bmo_opdefines_total;
unsigned int i;
const char *opname = _PyUnicode_AsString(pyname);
for (i = 0; i < tot; i++) {
if (STREQ(bmo_opdefines[i]->opname, opname)) {
return bpy_bmesh_op_CreatePyObject(opname);
}
if (BMO_opcode_from_opname(opname) != -1) {
return bpy_bmesh_op_CreatePyObject(opname);
}
else {
PyErr_Format(PyExc_AttributeError,
"BMeshOpsModule: operator \"%.200s\" doesn't exist",
opname);
return NULL;
}
PyErr_Format(PyExc_AttributeError,
"BMeshOpsModule: operator \"%.200s\" doesn't exist",
opname);
return NULL;
}
static PyObject *bpy_bmesh_ops_fakemod_dir(PyObject *UNUSED(self))

View File

@@ -1718,6 +1718,22 @@ static PyObject *bpy_bmface_calc_center_mean(BPy_BMFace *self)
return Vector_CreatePyObject(cent, 3, Py_NEW, NULL);
}
PyDoc_STRVAR(bpy_bmface_calc_center_mean_weighted_doc,
".. method:: calc_center_median_weighted()\n"
"\n"
" Return median center of the face weighted by edge lengths.\n"
"\n"
" :return: a 3D vector.\n"
" :rtype: :class:`mathutils.Vector`\n"
);
static PyObject *bpy_bmface_calc_center_mean_weighted(BPy_BMFace *self)
{
float cent[3];
BPY_BM_CHECK_OBJ(self);
BM_face_calc_center_mean_weighted(self->f, cent);
return Vector_CreatePyObject(cent, 3, Py_NEW, NULL);
}
PyDoc_STRVAR(bpy_bmface_calc_center_bounds_doc,
".. method:: calc_center_bounds()\n"
@@ -2573,6 +2589,7 @@ static struct PyMethodDef bpy_bmface_methods[] = {
{"calc_area", (PyCFunction)bpy_bmface_calc_area, METH_NOARGS, bpy_bmface_calc_area_doc},
{"calc_perimeter", (PyCFunction)bpy_bmface_calc_perimeter, METH_NOARGS, bpy_bmface_calc_perimeter_doc},
{"calc_center_median", (PyCFunction)bpy_bmface_calc_center_mean, METH_NOARGS, bpy_bmface_calc_center_mean_doc},
{"calc_center_median_weighted", (PyCFunction)bpy_bmface_calc_center_mean_weighted, METH_NOARGS, bpy_bmface_calc_center_mean_weighted_doc},
{"calc_center_bounds", (PyCFunction)bpy_bmface_calc_center_bounds, METH_NOARGS, bpy_bmface_calc_center_bounds_doc},
{"normal_update", (PyCFunction)bpy_bmface_normal_update, METH_NOARGS, bpy_bmface_normal_update_doc},

View File

@@ -31,20 +31,17 @@
* a context manager.
*/
/* nifty feature. swap out strings for RNA data */
#define USE_RNA_DATABLOCKS
#include <Python.h>
#include <stddef.h>
#include "BLO_readfile.h"
#include "BLI_utildefines.h"
#include "BLI_string.h"
#include "BLI_linklist.h"
#include "BLI_path_util.h"
#include "BLI_listbase.h"
#include "BLO_readfile.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_library.h"
@@ -57,6 +54,9 @@
#include "bpy_util.h"
#include "bpy_library.h"
/* nifty feature. swap out strings for RNA data */
#define USE_RNA_DATABLOCKS
#ifdef USE_RNA_DATABLOCKS
# include "bpy_rna.h"
# include "RNA_access.h"