[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52559] trunk/blender/source/blender: py/ bmesh api - support for converting from/to BMO_OP_SLOT_MAPPING type.
Campbell Barton
ideasman42 at gmail.com
Mon Nov 26 09:44:41 CET 2012
Revision: 52559
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52559
Author: campbellbarton
Date: 2012-11-26 08:44:37 +0000 (Mon, 26 Nov 2012)
Log Message:
-----------
py/bmesh api - support for converting from/to BMO_OP_SLOT_MAPPING type.
Modified Paths:
--------------
trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h
trunk/blender/source/blender/bmesh/intern/bmesh_operator_api_inline.h
trunk/blender/source/blender/bmesh/intern/bmesh_operators.c
trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c
trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
trunk/blender/source/blender/python/bmesh/bmesh_py_types.h
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h 2012-11-26 08:00:15 UTC (rev 52558)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h 2012-11-26 08:44:37 UTC (rev 52559)
@@ -414,7 +414,7 @@
int BMO_slot_map_count(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name);
void BMO_slot_map_insert(BMOperator *op, BMOpSlot *slot,
- const void *element, void *data, int len);
+ const void *element, const void *data, const int len);
/* Counts the number of edges with tool flag toolflag around
*/
@@ -502,6 +502,9 @@
int len;
} BMOElemMapping;
+/* pointer after BMOElemMapping */
+#define BMO_OP_SLOT_MAPPING_DATA(var) (void *)(((BMOElemMapping *)var) + 1)
+
extern const int BMO_OPSLOT_TYPEINFO[BMO_OP_SLOT_TOTAL_TYPES];
#ifdef __cplusplus
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operator_api_inline.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operator_api_inline.h 2012-11-26 08:00:15 UTC (rev 52558)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operator_api_inline.h 2012-11-26 08:44:37 UTC (rev 52559)
@@ -70,14 +70,14 @@
}
BLI_INLINE void BMO_slot_map_int_insert(BMOperator *op, BMOpSlot *slot,
- void *element, int val)
+ void *element, const int val)
{
BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_INT);
BMO_slot_map_insert(op, slot, element, &val, sizeof(int));
}
BLI_INLINE void BMO_slot_map_bool_insert(BMOperator *op, BMOpSlot *slot,
- void *element, int val)
+ void *element, const int val)
{
BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_BOOL);
BLI_assert(val == FALSE || val == TRUE);
@@ -85,7 +85,7 @@
}
BLI_INLINE void BMO_slot_map_float_insert(BMOperator *op, BMOpSlot *slot,
- void *element, float val)
+ void *element, const float val)
{
BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_FLOAT);
BMO_slot_map_insert(op, slot, element, &val, sizeof(float));
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operators.c 2012-11-26 08:00:15 UTC (rev 52558)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operators.c 2012-11-26 08:44:37 UTC (rev 52559)
@@ -314,7 +314,7 @@
dstmap->element = srcmap->element;
dstmap->len = srcmap->len;
- memcpy(dstmap + 1, srcmap + 1, srcmap->len);
+ memcpy(BMO_OP_SLOT_MAPPING_DATA(dstmap), BMO_OP_SLOT_MAPPING_DATA(srcmap), srcmap->len);
BLI_ghash_insert(slot_dst->data.ghash, dstmap->element, dstmap);
}
@@ -596,7 +596,7 @@
* value, it doesn't store a reference to it. */
void BMO_slot_map_insert(BMOperator *op, BMOpSlot *slot,
- const void *element, void *data, int len)
+ const void *element, const void *data, const int len)
{
BMOElemMapping *mapping;
BLI_assert(slot->slot_type == BMO_OP_SLOT_MAPPING);
@@ -606,7 +606,7 @@
mapping->element = (BMHeader *) element;
mapping->len = len;
- memcpy(mapping + 1, data, len);
+ memcpy(BMO_OP_SLOT_MAPPING_DATA(mapping), data, len);
if (!slot->data.ghash) {
slot->data.ghash = BLI_ghash_ptr_new("bmesh slot map hash");
@@ -1279,7 +1279,7 @@
void *ret = BLI_ghashIterator_getKey(&iter->giter);
map = BLI_ghashIterator_getValue(&iter->giter);
- iter->val = map + 1;
+ iter->val = BMO_OP_SLOT_MAPPING_DATA(map);
BLI_ghashIterator_step(&iter->giter);
Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c 2012-11-26 08:00:15 UTC (rev 52558)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c 2012-11-26 08:44:37 UTC (rev 52559)
@@ -305,6 +305,179 @@
break;
}
+ case BMO_OP_SLOT_MAPPING:
+ {
+ /* first check types */
+ if (slot->slot_subtype != BMO_OP_SLOT_SUBTYPE_MAP_EMPTY) {
+ if (!PyDict_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a dict, not %.200s",
+ self->opname, slot_name, Py_TYPE(value)->tp_name);
+ return NULL;
+ }
+ }
+ else {
+ if (!PySet_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a set, not %.200s",
+ self->opname, slot_name, Py_TYPE(value)->tp_name);
+ return NULL;
+ }
+ }
+
+ switch (slot->slot_subtype) {
+
+ /* this could be a static function */
+#define BPY_BM_MAPPING_KEY_CHECK(arg_key) \
+ if (!BPy_BMElem_Check(arg_key)) { \
+ PyErr_Format(PyExc_TypeError, \
+ "%.200s: keyword \"%.200s\" expected " \
+ "a dict with bmesh element keys, not %.200s", \
+ self->opname, slot_name, Py_TYPE(arg_key)->tp_name); \
+ return NULL; \
+ } \
+ else if (((BPy_BMGeneric *)arg_key)->bm == NULL) { \
+ PyErr_Format(PyExc_TypeError, \
+ "%.200s: keyword \"%.200s\" invalidated element key in dict", \
+ self->opname, slot_name); \
+ return NULL; \
+ } (void)0
+
+
+ case BMO_OP_SLOT_SUBTYPE_MAP_ELEM:
+ {
+ if (PyDict_Size(value) > 0) {
+ PyObject *arg_key, *arg_value;
+ Py_ssize_t arg_pos = 0;
+ while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
+ /* TODO, check the elements come from the right mesh? */
+ BPY_BM_MAPPING_KEY_CHECK(arg_key);
+
+ if (!BPy_BMElem_Check(arg_value)) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a dict with bmesh element values, not %.200s",
+ self->opname, slot_name, Py_TYPE(arg_value)->tp_name);
+ return NULL;
+ }
+ else if (((BPy_BMGeneric *)arg_value)->bm == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" invalidated element value in dict",
+ self->opname, slot_name);
+ return NULL;
+ }
+
+ BMO_slot_map_elem_insert(&bmop, slot,
+ ((BPy_BMElem *)arg_key)->ele, ((BPy_BMElem *)arg_value)->ele);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_FLOAT:
+ {
+ if (PyDict_Size(value) > 0) {
+ PyObject *arg_key, *arg_value;
+ Py_ssize_t arg_pos = 0;
+ while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
+ float value_f;
+ /* TODO, check the elements come from the right mesh? */
+ BPY_BM_MAPPING_KEY_CHECK(arg_key);
+ value_f = PyFloat_AsDouble(arg_value);
+
+ if (value_f == -1.0f && PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a dict with float values, not %.200s",
+ self->opname, slot_name, Py_TYPE(arg_value)->tp_name);
+ return NULL;
+ }
+
+ BMO_slot_map_float_insert(&bmop, slot,
+ ((BPy_BMElem *)arg_key)->ele, value_f);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_INT:
+ {
+ if (PyDict_Size(value) > 0) {
+ PyObject *arg_key, *arg_value;
+ Py_ssize_t arg_pos = 0;
+ while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
+ int value_i;
+ /* TODO, check the elements come from the right mesh? */
+ BPY_BM_MAPPING_KEY_CHECK(arg_key);
+ value_i = PyLong_AsLong(arg_value);
+
+ if (value_i == -1 && PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a dict with int values, not %.200s",
+ self->opname, slot_name, Py_TYPE(arg_value)->tp_name);
+ return NULL;
+ }
+
+ BMO_slot_map_int_insert(&bmop, slot,
+ ((BPy_BMElem *)arg_key)->ele, value_i);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_BOOL:
+ {
+ if (PyDict_Size(value) > 0) {
+ PyObject *arg_key, *arg_value;
+ Py_ssize_t arg_pos = 0;
+ while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
+ int value_i;
+ /* TODO, check the elements come from the right mesh? */
+ BPY_BM_MAPPING_KEY_CHECK(arg_key);
+ value_i = PyLong_AsLong(arg_value);
+
+ if (value_i == -1 && PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected "
+ "a dict with bool values, not %.200s",
+ self->opname, slot_name, Py_TYPE(arg_value)->tp_name);
+ return NULL;
+ }
+
+ BMO_slot_map_bool_insert(&bmop, slot,
+ ((BPy_BMElem *)arg_key)->ele, value_i != 0);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_EMPTY:
+ {
+ if (PySet_Size(value) > 0) {
+ PyObject *arg_key;
+ Py_ssize_t arg_pos = 0;
+ Py_ssize_t arg_hash = 0;
+ while (_PySet_NextEntry(value, &arg_pos, &arg_key, &arg_hash)) {
+ /* TODO, check the elements come from the right mesh? */
+ BPY_BM_MAPPING_KEY_CHECK(arg_key);
+
+ BMO_slot_map_empty_insert(&bmop, slot,
+ ((BPy_BMElem *)arg_key)->ele);
+ }
+ }
+ break;
+ }
+ case BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL:
+ default:
+ {
+ /* can't convert from these */
+ PyErr_Format(PyExc_NotImplementedError,
+ "This arguments mapping subtype %d is not supported", slot->slot_subtype);
+ break;
+ }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list