[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44625] trunk/blender/source: bmesh py api
Campbell Barton
ideasman42 at gmail.com
Sat Mar 3 23:08:08 CET 2012
Revision: 44625
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44625
Author: campbellbarton
Date: 2012-03-03 22:07:58 +0000 (Sat, 03 Mar 2012)
Log Message:
-----------
bmesh py api
* add BLI_rfindlink for reverse index lookup (used so bm.select_history[-1] doesn't have to loop the entire list twice).
* add bm.select_history.active so you can get the last selected item or None without having to check seq length.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_listbase.h
trunk/blender/source/blender/blenlib/intern/listbase.c
trunk/blender/source/blender/python/bmesh/bmesh_py_select.c
trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
trunk/blender/source/blender/python/generic/py_capi_utils.c
trunk/blender/source/tools/spell_check_source.py
Modified: trunk/blender/source/blender/blenlib/BLI_listbase.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_listbase.h 2012-03-03 21:42:21 UTC (rev 44624)
+++ trunk/blender/source/blender/blenlib/BLI_listbase.h 2012-03-03 22:07:58 UTC (rev 44625)
@@ -41,15 +41,16 @@
#endif
void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink);
-void *BLI_findlink(const struct ListBase *listbase, int number);
int BLI_findindex(const struct ListBase *listbase, void *vlink);
int BLI_findstringindex(const struct ListBase *listbase, const char *id, const int offset);
/* find forwards */
+void *BLI_findlink(const struct ListBase *listbase, int number);
void *BLI_findstring(const struct ListBase *listbase, const char *id, const int offset);
void *BLI_findstring_ptr(const struct ListBase *listbase, const char *id, const int offset);
/* find backwards */
+void *BLI_rfindlink(const struct ListBase *listbase, int number);
void *BLI_rfindstring(const struct ListBase *listbase, const char *id, const int offset);
void *BLI_rfindstring_ptr(const struct ListBase *listbase, const char *id, const int offset);
Modified: trunk/blender/source/blender/blenlib/intern/listbase.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/listbase.c 2012-03-03 21:42:21 UTC (rev 44624)
+++ trunk/blender/source/blender/blenlib/intern/listbase.c 2012-03-03 22:07:58 UTC (rev 44625)
@@ -338,6 +338,21 @@
return link;
}
+void *BLI_rfindlink(const ListBase *listbase, int number)
+{
+ Link *link = NULL;
+
+ if (number >= 0) {
+ link = listbase->last;
+ while (link != NULL && number != 0) {
+ number--;
+ link = link->prev;
+ }
+ }
+
+ return link;
+}
+
int BLI_findindex(const ListBase *listbase, void *vlink)
{
Link *link= NULL;
Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_select.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_select.c 2012-03-03 21:42:21 UTC (rev 44624)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_select.c 2012-03-03 22:07:58 UTC (rev 44625)
@@ -23,10 +23,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/python/bmesh/bmesh_py_api.c
+/** \file blender/python/bmesh/bmesh_py_select.c
* \ingroup pybmesh
*
- * This file defines the 'bmesh' module.
+ * This file defines the types for 'BMesh.select_history'
+ * sequence and iterator.
*/
#include <Python.h>
@@ -47,9 +48,24 @@
#include "bmesh_py_api.h" /* own include */
+PyDoc_STRVAR(bpy_bmeditselseq_active_doc,
+"The last selected element or None (read-only).\n\n:type: :class:`BMVert`, :class:`BMEdge` or :class:`BMFace`"
+);
+static PyObject *bpy_bmeditselseq_active_get(BPy_BMEditSelSeq *self, void *UNUSED(closure))
+{
+ BMEditSelection *ese;
+ BPY_BM_CHECK_OBJ(self);
+
+ if ((ese = self->bm->selected.last)) {
+ return BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
+ }
+ else {
+ Py_RETURN_NONE;
+ }
+}
+
static PyGetSetDef bpy_bmeditselseq_getseters[] = {
- // {(char *)"verts", (getter)bpy_bmeditselseq_get, (setter)NULL, (char *)bpy_bmesh_verts_doc, (void *)BM_VERTS_OF_MESH},
-
+ {(char *)"active", (getter)bpy_bmeditselseq_active_get, (setter)NULL, (char *)bpy_bmeditselseq_active_doc, (void *)BM_VERTS_OF_MESH},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
@@ -71,19 +87,25 @@
static PyObject *bpy_bmeditselseq_subscript_int(BPy_BMEditSelSeq *self, int keynum)
{
+ BMEditSelection *ese;
+
BPY_BM_CHECK_OBJ(self);
- if (keynum < 0) keynum += bpy_bmeditselseq_length(self); /* only get length on negative value, may loop entire seq */
- if (keynum >= 0) {
- BMEditSelection *ese = BLI_findlink(&self->bm->selected, keynum);
- if (ese) {
- return BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
- }
+ if (keynum < 0) {
+ ese = BLI_rfindlink(&self->bm->selected, -1 - keynum);
}
+ else {
+ ese = BLI_findlink(&self->bm->selected, keynum);
+ }
- PyErr_Format(PyExc_IndexError,
- "BMElemSeq[index]: index %d out of range", keynum);
- return NULL;
+ if (ese) {
+ return BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
+ }
+ else {
+ PyErr_Format(PyExc_IndexError,
+ "BMElemSeq[index]: index %d out of range", keynum);
+ return NULL;
+ }
}
static PyObject *bpy_bmeditselseq_subscript_slice(BPy_BMEditSelSeq *self, Py_ssize_t start, Py_ssize_t stop)
Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_types.c 2012-03-03 21:42:21 UTC (rev 44624)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_types.c 2012-03-03 22:07:58 UTC (rev 44625)
@@ -1564,7 +1564,7 @@
return NULL;
}
- if ((e=BM_edge_exists(vert_array[0], vert_array[1]))) {
+ if ((e = BM_edge_exists(vert_array[0], vert_array[1]))) {
ret = BPy_BMEdge_CreatePyObject(bm, e);
}
else {
@@ -2572,7 +2572,7 @@
PyObject *seq_fast;
*r_size = 0;
- if (!(seq_fast=PySequence_Fast(seq, error_prefix))) {
+ if (!(seq_fast = PySequence_Fast(seq, error_prefix))) {
return NULL;
}
else {
Modified: trunk/blender/source/blender/python/generic/py_capi_utils.c
===================================================================
--- trunk/blender/source/blender/python/generic/py_capi_utils.c 2012-03-03 21:42:21 UTC (rev 44624)
+++ trunk/blender/source/blender/python/generic/py_capi_utils.c 2012-03-03 22:07:58 UTC (rev 44625)
@@ -50,11 +50,11 @@
Py_ssize_t value_len;
Py_ssize_t i;
- if (!(value_fast=PySequence_Fast(value, error_prefix))) {
+ if (!(value_fast = PySequence_Fast(value, error_prefix))) {
return -1;
}
- value_len= PySequence_Fast_GET_SIZE(value_fast);
+ value_len = PySequence_Fast_GET_SIZE(value_fast);
if (value_len != length) {
Py_DECREF(value);
@@ -69,13 +69,13 @@
if (is_double) {
double *array_double= array;
for (i=0; i<length; i++) {
- array_double[i]= PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i));
+ array_double[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i));
}
}
else {
float *array_float= array;
for (i=0; i<length; i++) {
- array_float[i]= PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i));
+ array_float[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i));
}
}
}
@@ -83,13 +83,13 @@
/* could use is_double for 'long int' but no use now */
int *array_int= array;
for (i=0; i<length; i++) {
- array_int[i]= PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i));
+ array_int[i] = PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i));
}
}
else if (type == &PyBool_Type) {
int *array_bool= array;
for (i=0; i<length; i++) {
- array_bool[i]= (PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i)) != 0);
+ array_bool[i] = (PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i)) != 0);
}
}
else {
Modified: trunk/blender/source/tools/spell_check_source.py
===================================================================
--- trunk/blender/source/tools/spell_check_source.py 2012-03-03 21:42:21 UTC (rev 44624)
+++ trunk/blender/source/tools/spell_check_source.py 2012-03-03 22:07:58 UTC (rev 44625)
@@ -163,8 +163,8 @@
SKIP_COMMENTS = (
"BEGIN GPL LICENSE BLOCK",
)
+ PRINT_NON_ALIGNED = False
-
def strip_doxy_comments(block_split):
for i, l in enumerate(block_split):
@@ -225,7 +225,8 @@
comments.append(Comment(filepath, block, slineno, 'COMMENT'))
else:
- pass
+ if PRINT_NON_ALIGNED:
+ print(filepath + ":" + str(1 + text.count("\n", 0, i)) + ":")
i = i_next
else:
More information about the Bf-blender-cvs
mailing list