[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44862] trunk/blender: bmesh py api: finished todo - editable select_history
Campbell Barton
ideasman42 at gmail.com
Wed Mar 14 05:46:19 CET 2012
Revision: 44862
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44862
Author: campbellbarton
Date: 2012-03-14 04:46:12 +0000 (Wed, 14 Mar 2012)
Log Message:
-----------
bmesh py api: finished todo - editable select_history
eg:
bm.select_history = vert, face, edge
bm.select_history.add(edge)
Modified Paths:
--------------
trunk/blender/doc/python_api/rst/include__bmesh.rst
trunk/blender/doc/python_api/sphinx_doc_gen.py
trunk/blender/source/blender/bmesh/intern/bmesh_marking.c
trunk/blender/source/blender/bmesh/intern/bmesh_marking.h
trunk/blender/source/blender/python/bmesh/bmesh_py_select.c
trunk/blender/source/blender/python/bmesh/bmesh_py_select.h
trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
trunk/blender/source/blender/python/bmesh/bmesh_py_types.h
trunk/blender/source/blender/python/bmesh/bmesh_py_utils.c
Modified: trunk/blender/doc/python_api/rst/include__bmesh.rst
===================================================================
--- trunk/blender/doc/python_api/rst/include__bmesh.rst 2012-03-14 03:57:29 UTC (rev 44861)
+++ trunk/blender/doc/python_api/rst/include__bmesh.rst 2012-03-14 04:46:12 UTC (rev 44862)
@@ -33,7 +33,6 @@
.. todo::
* add access to BMesh **walkers**
- * add access selection history (readonly access done)
* add a way to re-tessellate an editmode bmesh.
Modified: trunk/blender/doc/python_api/sphinx_doc_gen.py
===================================================================
--- trunk/blender/doc/python_api/sphinx_doc_gen.py 2012-03-14 03:57:29 UTC (rev 44861)
+++ trunk/blender/doc/python_api/sphinx_doc_gen.py 2012-03-14 04:46:12 UTC (rev 44862)
@@ -94,12 +94,13 @@
usage=SCRIPT_HELP_MSG
)
- # optional arguments
+ # optional arguments
parser.add_argument("-o", "--output",
dest="output_dir",
type=str,
default=SCRIPT_DIR,
- help="Path of the API docs (default=<script dir>)",
+ # XXX, THIS ISNT WORKING, EXAMPLE SCRIPTS WILL NOT BE FOUND
+ help="Path of the API docs (default=<script dir>).",
required=False)
parser.add_argument("-B", "--sphinx-build",
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_marking.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_marking.c 2012-03-14 03:57:29 UTC (rev 44861)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_marking.c 2012-03-14 04:46:12 UTC (rev 44862)
@@ -720,14 +720,18 @@
bm->selected.first = bm->selected.last = NULL;
}
+void BM_select_history_store_notest(BMesh *bm, BMElem *ele)
+{
+ BMEditSelection *ese = (BMEditSelection *) MEM_callocN(sizeof(BMEditSelection), "BMEdit Selection");
+ ese->htype = ((BMHeader *)ele)->htype;
+ ese->ele = ele;
+ BLI_addtail(&(bm->selected), ese);
+}
+
void BM_select_history_store(BMesh *bm, BMElem *ele)
{
- BMEditSelection *ese;
if (!BM_select_history_check(bm, ele)) {
- ese = (BMEditSelection *) MEM_callocN(sizeof(BMEditSelection), "BMEdit Selection");
- ese->htype = ((BMHeader *)ele)->htype;
- ese->ele = ele;
- BLI_addtail(&(bm->selected), ese);
+ BM_select_history_store_notest(bm, ele);
}
}
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_marking.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_marking.h 2012-03-14 03:57:29 UTC (rev 44861)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_marking.h 2012-03-14 04:46:12 UTC (rev 44862)
@@ -71,6 +71,7 @@
int BM_select_history_check(BMesh *bm, const BMElem *ele);
int BM_select_history_remove(BMesh *bm, BMElem *ele);
+void BM_select_history_store_notest(BMesh *bm, BMElem *ele);
void BM_select_history_store(BMesh *bm, BMElem *ele);
void BM_select_history_validate(BMesh *bm);
void BM_select_history_clear(BMesh *em);
Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_select.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_select.c 2012-03-14 03:57:29 UTC (rev 44861)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_select.c 2012-03-14 04:46:12 UTC (rev 44862)
@@ -28,6 +28,9 @@
*
* This file defines the types for 'BMesh.select_history'
* sequence and iterator.
+ *
+ * select_history is very loosely based on pytons set() type,
+ * since items can only exist once. however they do have an order.
*/
#include <Python.h>
@@ -93,6 +96,37 @@
Py_RETURN_NONE;
}
+PyDoc_STRVAR(bpy_bmeditselseq_add_doc,
+".. method:: add(element)\n"
+"\n"
+" Add an element to the selection history (no action taken if its already added).\n"
+);
+static PyObject *bpy_bmeditselseq_add(BPy_BMEditSelSeq *self, BPy_BMElem *value)
+{
+ BPY_BM_CHECK_OBJ(self);
+
+ if ((BPy_BMVert_Check(value) ||
+ BPy_BMEdge_Check(value) ||
+ BPy_BMFace_Check(value)) == FALSE)
+ {
+ PyErr_Format(PyExc_TypeError,
+ "Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name);
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(value);
+
+ if (self->bm != value->bm) {
+ PyErr_SetString(PyExc_ValueError,
+ "Element is not from this mesh");
+ return NULL;
+ }
+
+ BM_select_history_store(self->bm, value->ele)
+
+ Py_RETURN_NONE;
+}
+
PyDoc_STRVAR(bpy_bmeditselseq_remove_doc,
".. method:: remove(element)\n"
"\n"
@@ -127,6 +161,8 @@
static struct PyMethodDef bpy_bmeditselseq_methods[] = {
{"validate", (PyCFunction)bpy_bmeditselseq_validate, METH_NOARGS, bpy_bmeditselseq_validate_doc},
{"clear", (PyCFunction)bpy_bmeditselseq_clear, METH_NOARGS, bpy_bmeditselseq_clear_doc},
+
+ {"add", (PyCFunction)bpy_bmeditselseq_add, METH_O, bpy_bmeditselseq_add_doc},
{"remove", (PyCFunction)bpy_bmeditselseq_remove, METH_O, bpy_bmeditselseq_remove_doc},
{NULL, NULL, 0, NULL}
};
@@ -381,3 +417,38 @@
PyType_Ready(&BPy_BMEditSelSeq_Type);
PyType_Ready(&BPy_BMEditSelIter_Type);
}
+
+
+/* utility function */
+
+/**
+ * \note doesnt actually check selection.
+ */
+int BPy_BMEditSel_Assign(BPy_BMesh *self, PyObject *value)
+{
+ BMesh *bm;
+ Py_ssize_t value_len;
+ Py_ssize_t i;
+ BMElem **value_array = NULL;
+
+ BPY_BM_CHECK_INT(self);
+
+ bm = self->bm;
+
+ value_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX,
+ &value_len, BM_VERT | BM_EDGE | BM_FACE,
+ TRUE, TRUE, "BMesh.select_history = value");
+
+ if (value_array == NULL) {
+ return -1;
+ }
+
+ BM_select_history_clear(bm);
+
+ for (i = 0; i < value_len; i++) {
+ BM_select_history_store_notest(bm, value_array[i]);
+ }
+
+ PyMem_FREE(value_array);
+ return 0;
+}
Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_select.h
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_select.h 2012-03-14 03:57:29 UTC (rev 44861)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_select.h 2012-03-14 04:46:12 UTC (rev 44862)
@@ -30,6 +30,8 @@
#ifndef __BMESH_PY_SELECT_H__
#define __BMESH_PY_SELECT_H__
+struct BPy_BMesh;
+
extern PyTypeObject BPy_BMEditSelSeq_Type;
extern PyTypeObject BPy_BMEditSelIter_Type;
@@ -51,5 +53,6 @@
PyObject *BPy_BMEditSel_CreatePyObject(BMesh *bm);
PyObject *BPy_BMEditSelIter_CreatePyObject(BMesh *bm);
+int BPy_BMEditSel_Assign(struct BPy_BMesh *self, PyObject *value);
#endif /* __BMESH_PY_SELECT_H__ */
Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_types.c 2012-03-14 03:57:29 UTC (rev 44861)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_types.c 2012-03-14 04:46:12 UTC (rev 44862)
@@ -302,12 +302,11 @@
return BPy_BMEditSel_CreatePyObject(self->bm);
}
-static int bpy_bmesh_select_history_set(BPy_BMesh *self, PyObject *UNUSED(value))
+static int bpy_bmesh_select_history_set(BPy_BMesh *self, PyObject *value)
{
BPY_BM_CHECK_INT(self);
- PyErr_SetString(PyExc_NotImplementedError, "not yet functional");
- return -1;
+ return BPy_BMEditSel_Assign(self, value);
}
/* Vert
@@ -1045,7 +1044,7 @@
Py_ssize_t vert_seq_len; /* always 2 */
vert_array = BPy_BMElem_PySeq_As_Array(&bm, vert_seq, 2, 2,
- &vert_seq_len, &BPy_BMVert_Type,
+ &vert_seq_len, BM_VERT,
TRUE, TRUE, "BMVert.copy_from_vert_interp(...)");
if (vert_array == NULL) {
@@ -1532,7 +1531,7 @@
}
vert_array = BPy_BMElem_PySeq_As_Array(&bm, vert_seq, 2, 2,
- &vert_seq_len, &BPy_BMVert_Type,
+ &vert_seq_len, BM_VERT,
TRUE, TRUE, "edges.new(...)");
if (vert_array == NULL) {
@@ -1599,7 +1598,7 @@
}
vert_array = BPy_BMElem_PySeq_As_Array(&bm, vert_seq, 3, PY_SSIZE_T_MAX,
- &vert_seq_len, &BPy_BMVert_Type,
+ &vert_seq_len, BM_VERT,
TRUE, TRUE, "faces.new(...)");
if (vert_array == NULL) {
@@ -1821,7 +1820,7 @@
PyObject *ret = NULL;
vert_array = BPy_BMElem_PySeq_As_Array(&bm, vert_seq, 2, 2,
- &vert_seq_len, &BPy_BMVert_Type,
+ &vert_seq_len, BM_VERT,
TRUE, TRUE, "edges.get(...)");
if (vert_array == NULL) {
@@ -1863,7 +1862,7 @@
PyObject *ret = NULL;
vert_array = BPy_BMElem_PySeq_As_Array(&bm, vert_seq, 1, PY_SSIZE_T_MAX,
- &vert_seq_len, &BPy_BMVert_Type,
+ &vert_seq_len, BM_VERT,
TRUE, TRUE, "faces.get(...)");
if (vert_array == NULL) {
@@ -2849,7 +2848,7 @@
* The 'bm_r' value is assigned when empty, and used when set.
*/
void *BPy_BMElem_PySeq_As_Array(BMesh **r_bm, PyObject *seq, Py_ssize_t min, Py_ssize_t max, Py_ssize_t *r_size,
- PyTypeObject *type,
+ const char htype,
const char do_unique_check, const char do_bm_check,
const char *error_prefix)
{
@@ -2883,16 +2882,16 @@
for (i = 0; i < seq_len; i++) {
item = (BPy_BMElem *)PySequence_Fast_GET_ITEM(seq_fast, i);
- if (Py_TYPE(item) != type) {
+ if (!BPy_BMElem_CheckHType(Py_TYPE(item), htype)) {
PyErr_Format(PyExc_TypeError,
- "%s: expected '%.200s', not '%.200s'",
- error_prefix, type->tp_name, Py_TYPE(item)->tp_name);
+ "%s: expected %.200s, not '%.200s'",
+ error_prefix, BPy_BMElem_StringFromHType(htype), Py_TYPE(item)->tp_name);
goto err_cleanup;
}
else if (!BPY_BM_IS_VALID(item)) {
PyErr_Format(PyExc_TypeError,
"%s: %d %s has been removed",
- error_prefix, i, type->tp_name);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list