Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-06-27 01:40:01 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-06-27 01:40:01 +0400
commit3e305c1018be797dbf114914459ece402903dd08 (patch)
treea4d634038df2f8bcf9cb2b3eb7b78b054fb5e744 /source/blender/python/bmesh
parent200584e5c6e020dcb77038a0e399ddfebe91ce63 (diff)
bmesh.ops module for bmesh operator access, only remove_doubles and convex_hull at the moment.
Diffstat (limited to 'source/blender/python/bmesh')
-rw-r--r--source/blender/python/bmesh/CMakeLists.txt2
-rw-r--r--source/blender/python/bmesh/bmesh_py_api.c5
-rw-r--r--source/blender/python/bmesh/bmesh_py_ops.c200
-rw-r--r--source/blender/python/bmesh/bmesh_py_ops.h35
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.h9
-rw-r--r--source/blender/python/bmesh/bmesh_py_utils.c8
6 files changed, 255 insertions, 4 deletions
diff --git a/source/blender/python/bmesh/CMakeLists.txt b/source/blender/python/bmesh/CMakeLists.txt
index 40bde7161b6..032a914fb70 100644
--- a/source/blender/python/bmesh/CMakeLists.txt
+++ b/source/blender/python/bmesh/CMakeLists.txt
@@ -33,6 +33,7 @@ set(INC_SYS
set(SRC
bmesh_py_api.c
+ bmesh_py_ops.c
bmesh_py_types.c
bmesh_py_types_customdata.c
bmesh_py_types_meshdata.c
@@ -40,6 +41,7 @@ set(SRC
bmesh_py_utils.c
bmesh_py_api.h
+ bmesh_py_ops.h
bmesh_py_types.h
bmesh_py_types_customdata.h
bmesh_py_types_meshdata.h
diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c
index 4d8d4e3bc23..2cfe5847e55 100644
--- a/source/blender/python/bmesh/bmesh_py_api.c
+++ b/source/blender/python/bmesh/bmesh_py_api.c
@@ -40,6 +40,7 @@
#include "bmesh_py_types_customdata.h"
#include "bmesh_py_types_meshdata.h"
+#include "bmesh_py_ops.h"
#include "bmesh_py_utils.h"
#include "BKE_tessmesh.h"
@@ -143,6 +144,10 @@ PyObject *BPyInit_bmesh(void)
PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
Py_INCREF(submodule);
+ PyModule_AddObject(mod, "ops", (submodule = BPyInit_bmesh_ops()));
+ PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
+ Py_INCREF(submodule);
+
PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils()));
PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
Py_INCREF(submodule);
diff --git a/source/blender/python/bmesh/bmesh_py_ops.c b/source/blender/python/bmesh/bmesh_py_ops.c
new file mode 100644
index 00000000000..5e327e878ef
--- /dev/null
+++ b/source/blender/python/bmesh/bmesh_py_ops.c
@@ -0,0 +1,200 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2012 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/bmesh/bmesh_py_ops.c
+ * \ingroup pybmesh
+ *
+ * This file defines the 'bmesh.ops' module.
+ * Operators from 'opdefines' are wrapped.
+ */
+
+#include <Python.h>
+
+#include "BLI_utildefines.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "../generic/py_capi_utils.h"
+
+#include "../mathutils/mathutils.h"
+
+#include "bmesh.h"
+
+#include "bmesh_py_types.h"
+
+#include "bmesh_py_utils.h" /* own include */
+
+static int bpy_bm_op_as_py_error(BMesh *bm)
+{
+ if (BMO_error_occurred(bm)) {
+ const char *errmsg;
+ if (BMO_error_get(bm, &errmsg, NULL)) {
+ PyErr_Format(PyExc_RuntimeError,
+ "bmesh operator: %.200s",
+ errmsg);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+PyDoc_STRVAR(bpy_bm_ops_convex_hull_doc,
+".. method:: convex_hull(bmesh, filter)\n"
+"\n"
+" Face split with optional intermediate points.\n"
+"\n"
+" :arg bmesh: The face to cut.\n"
+" :type bmesh: :class:`bmesh.types.BMFace`\n"
+" :arg filter: Set containing vertex flags to apply the operator.\n"
+" :type filter: set\n"
+);
+static PyObject *bpy_bm_ops_convex_hull(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ static const char *kwlist[] = {"bmesh", "filter", NULL};
+
+ BPy_BMesh *py_bm;
+ BMesh *bm;
+
+ PyObject *filter;
+ int filter_flags;
+ BMOperator bmop;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!:convex_hull", (char **)kwlist,
+ &BPy_BMesh_Type, &py_bm,
+ &PySet_Type, &filter))
+ {
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(py_bm);
+ bm = py_bm->bm;
+
+ if (filter != NULL && PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter,
+ &filter_flags, "convex_hull") == -1)
+ {
+ return NULL;
+ }
+
+ BMO_op_initf(bm, &bmop,
+ "convex_hull input=%hv",
+ filter_flags);
+ BMO_op_exec(bm, &bmop);
+ BMO_op_finish(bm, &bmop);
+
+ if (bpy_bm_op_as_py_error(bm) == -1) {
+ return NULL;
+ }
+
+ /* TODO, return values */
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(bpy_bm_ops_remove_doubles_doc,
+".. method:: remove_doubles(bmesh, filter, dist)\n"
+"\n"
+" Face split with optional intermediate points.\n"
+"\n"
+" :arg bmesh: The face to cut.\n"
+" :type bmesh: :class:`bmesh.types.BMFace`\n"
+" :arg filter: Set containing vertex flags to apply the operator.\n"
+" :type filter: set\n"
+" :arg dist: Distance limit.\n"
+" :type dist: float\n"
+);
+static PyObject *bpy_bm_ops_remove_doubles(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ static const char *kwlist[] = {"bmesh", "filter", "dist", NULL};
+
+ BPy_BMesh *py_bm;
+ BMesh *bm;
+
+ PyObject *filter;
+ int filter_flags;
+ float dist = 0.0f;
+
+ BMOperator bmop;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!|f:remove_doubles", (char **)kwlist,
+ &BPy_BMesh_Type, &py_bm,
+ &PySet_Type, &filter,
+ &dist))
+ {
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(py_bm);
+ bm = py_bm->bm;
+
+ if (filter != NULL && PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter,
+ &filter_flags, "remove_doubles") == -1)
+ {
+ return NULL;
+ }
+
+ BMO_op_initf(bm, &bmop,
+ "remove_doubles verts=%hv dist=%f",
+ filter_flags, dist);
+ BMO_op_exec(bm, &bmop);
+ BMO_op_finish(bm, &bmop);
+
+ if (bpy_bm_op_as_py_error(bm) == -1) {
+ return NULL;
+ }
+
+ /* TODO, return values */
+ Py_RETURN_NONE;
+}
+
+static struct PyMethodDef BPy_BM_ops_methods[] = {
+ {"convex_hull", (PyCFunction)bpy_bm_ops_convex_hull, METH_VARARGS | METH_KEYWORDS, bpy_bm_ops_convex_hull_doc},
+ {"remove_doubles", (PyCFunction)bpy_bm_ops_remove_doubles, METH_VARARGS | METH_KEYWORDS, bpy_bm_ops_remove_doubles_doc},
+ {NULL, NULL, 0, NULL}
+};
+
+
+PyDoc_STRVAR(BPy_BM_ops_doc,
+ "This module provides access to bmesh operators (EXPEREMENTAL)."
+ );
+static struct PyModuleDef BPy_BM_ops_module_def = {
+ PyModuleDef_HEAD_INIT,
+ "bmesh.ops", /* m_name */
+ BPy_BM_ops_doc, /* m_doc */
+ 0, /* m_size */
+ BPy_BM_ops_methods, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
+};
+
+
+PyObject *BPyInit_bmesh_ops(void)
+{
+ PyObject *submodule;
+
+ submodule = PyModule_Create(&BPy_BM_ops_module_def);
+
+ return submodule;
+}
diff --git a/source/blender/python/bmesh/bmesh_py_ops.h b/source/blender/python/bmesh/bmesh_py_ops.h
new file mode 100644
index 00000000000..56c980b57ea
--- /dev/null
+++ b/source/blender/python/bmesh/bmesh_py_ops.h
@@ -0,0 +1,35 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2012 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/bmesh/bmesh_py_ops.h
+ * \ingroup pybmesh
+ */
+
+#ifndef __BMESH_PY_OPS_H__
+#define __BMESH_PY_OPS_H__
+
+PyObject *BPyInit_bmesh_ops(void);
+
+#endif /* __BMESH_PY_OPS_H__ */
diff --git a/source/blender/python/bmesh/bmesh_py_types.h b/source/blender/python/bmesh/bmesh_py_types.h
index 85bbd5d7b09..947e66bf24e 100644
--- a/source/blender/python/bmesh/bmesh_py_types.h
+++ b/source/blender/python/bmesh/bmesh_py_types.h
@@ -186,4 +186,13 @@ char *BPy_BMElem_StringFromHType(const char htype);
ele; \
ele = BM_iter_step(iter))
+
+#ifdef __PY_CAPI_UTILS_H__
+struct PyC_FlagSet;
+extern struct PyC_FlagSet bpy_bm_scene_vert_edge_face_flags[];
+extern struct PyC_FlagSet bpy_bm_htype_vert_edge_face_flags[];
+extern struct PyC_FlagSet bpy_bm_htype_all_flags[];
+extern struct PyC_FlagSet bpy_bm_hflag_all_flags[];
+#endif
+
#endif /* __BMESH_TYPES_H__ */
diff --git a/source/blender/python/bmesh/bmesh_py_utils.c b/source/blender/python/bmesh/bmesh_py_utils.c
index 6a2ba90a330..4417bc2ce8d 100644
--- a/source/blender/python/bmesh/bmesh_py_utils.c
+++ b/source/blender/python/bmesh/bmesh_py_utils.c
@@ -668,13 +668,13 @@ static struct PyMethodDef BPy_BM_utils_methods[] = {
};
-PyDoc_STRVAR(BPy_BM_doc,
+PyDoc_STRVAR(BPy_BM_utils_doc,
"This module provides access to blenders bmesh data structures."
);
-static struct PyModuleDef BPy_BM_types_module_def = {
+static struct PyModuleDef BPy_BM_utils_module_def = {
PyModuleDef_HEAD_INIT,
"bmesh.utils", /* m_name */
- BPy_BM_doc, /* m_doc */
+ BPy_BM_utils_doc, /* m_doc */
0, /* m_size */
BPy_BM_utils_methods, /* m_methods */
NULL, /* m_reload */
@@ -688,7 +688,7 @@ PyObject *BPyInit_bmesh_utils(void)
{
PyObject *submodule;
- submodule = PyModule_Create(&BPy_BM_types_module_def);
+ submodule = PyModule_Create(&BPy_BM_utils_module_def);
return submodule;
}