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-02-23 15:27:22 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-02-23 15:27:22 +0400
commit7bc306c94726bc1e059c9a4c0dc7103136c26ef6 (patch)
treec51bef5b1142b0e655dd2f3ca00b76048d6ae914 /source/blender/python
parentb8e019d8396ed102323df234df8b1cc6b35712a1 (diff)
bmesh py api, new elements now take optional 'example' arguments, so the new data copies from the existing.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.c62
-rw-r--r--source/blender/python/bmesh/bmesh_py_utils.c54
2 files changed, 77 insertions, 39 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index 515a5f05f3b..45daac1005f 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -794,10 +794,13 @@ static PyObject *bpy_bmloop_calc_face_angle(BPy_BMLoop *self)
static PyObject *bpy_bmvert_seq_new(BPy_BMElemSeq *self, PyObject *args)
{
PyObject *py_co = NULL;
+ BPy_BMVert *py_vert_example = NULL; /* optional */
BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "|O:verts.new", py_co)) {
+ if (!PyArg_ParseTuple(args, "|OO!:verts.new",
+ py_co,
+ &BPy_BMVert_Type, &py_vert_example)) {
return NULL;
}
else {
@@ -805,6 +808,10 @@ static PyObject *bpy_bmvert_seq_new(BPy_BMElemSeq *self, PyObject *args)
BMVert *v;
float co[3] = {0.0f, 0.0f, 0.0f};
+ if (py_vert_example) {
+ BPY_BM_CHECK_OBJ(py_vert_example);
+ }
+
if (py_co && mathutils_array_parse(co, 3, 3, py_co, "verts.new(co)") != -1) {
return NULL;
}
@@ -817,6 +824,10 @@ static PyObject *bpy_bmvert_seq_new(BPy_BMElemSeq *self, PyObject *args)
return NULL;
}
+ if (py_vert_example) {
+ BM_elem_attrs_copy(py_vert_example->bm, bm, py_vert_example->v, v);
+ }
+
return BPy_BMVert_CreatePyObject(bm, v);
}
}
@@ -828,12 +839,14 @@ static PyObject *bpy_bmedge_seq_new(BPy_BMElemSeq *self, PyObject *args)
{
BPy_BMVert *v1;
BPy_BMVert *v2;
+ BPy_BMEdge *py_edge_example = NULL; /* optional */
BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "O!O!:edges.new",
- &BPy_BMVert_Type, &v1,
- &BPy_BMVert_Type, &v2))
+ if (!PyArg_ParseTuple(args, "O!O!|O!:edges.new",
+ &BPy_BMVert_Type, &v1,
+ &BPy_BMVert_Type, &v2,
+ &BPy_BMEdge_Type, &py_edge_example))
{
return NULL;
}
@@ -841,6 +854,10 @@ static PyObject *bpy_bmedge_seq_new(BPy_BMElemSeq *self, PyObject *args)
BMesh *bm = self->bm;
BMEdge *e;
+ if (py_edge_example) {
+ BPY_BM_CHECK_OBJ(py_edge_example);
+ }
+
if (v1->v == v2->v) {
PyErr_SetString(PyExc_ValueError,
"edges.new(): both verts are the same");
@@ -864,6 +881,10 @@ static PyObject *bpy_bmedge_seq_new(BPy_BMElemSeq *self, PyObject *args)
return NULL;
}
+ if (py_edge_example) {
+ BM_elem_attrs_copy(py_edge_example->bm, bm, py_edge_example->e, e);
+ }
+
return BPy_BMEdge_CreatePyObject(bm, e);
}
}
@@ -874,10 +895,13 @@ static PyObject *bpy_bmedge_seq_new(BPy_BMElemSeq *self, PyObject *args)
static PyObject *bpy_bmface_seq_new(BPy_BMElemSeq *self, PyObject *args)
{
PyObject *vert_seq;
+ BPy_BMFace *py_face_example = NULL; /* optional */
BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "O:faces.new", &vert_seq)) {
+ if (!PyArg_ParseTuple(args, "O|O!:faces.new",
+ &vert_seq,
+ &BPy_BMFace_Type, &py_face_example)) {
return NULL;
}
else {
@@ -896,6 +920,10 @@ static PyObject *bpy_bmface_seq_new(BPy_BMElemSeq *self, PyObject *args)
BMFace *f;
+ if (py_face_example) {
+ BPY_BM_CHECK_OBJ(py_face_example);
+ }
+
if (!(vert_seq_fast=PySequence_Fast(vert_seq, "faces.new(...)"))) {
return NULL;
}
@@ -966,6 +994,10 @@ static PyObject *bpy_bmface_seq_new(BPy_BMElemSeq *self, PyObject *args)
goto cleanup;
}
+ if (py_face_example) {
+ BM_elem_attrs_copy(py_face_example->bm, bm, py_face_example->f, f);
+ }
+
ret = BPy_BMFace_CreatePyObject(bm, f);
/* pass through */
@@ -1193,7 +1225,7 @@ static Py_ssize_t bpy_bm_seq_length(BPy_BMElemSeq *self)
case BM_FACES_OF_MESH:
return self->bm->totface;
- /* sub-types */
+ /* sub-types */
case BM_VERTS_OF_FACE:
case BM_EDGES_OF_FACE:
case BM_LOOPS_OF_FACE:
@@ -1576,15 +1608,15 @@ void BPy_BM_init_types(void)
* ********************* */
static struct PyModuleDef BPy_BM_types_module_def = {
- PyModuleDef_HEAD_INIT,
- "bmesh.types", /* m_name */
- NULL, /* m_doc */
- 0, /* m_size */
- NULL, /* m_methods */
- NULL, /* m_reload */
- NULL, /* m_traverse */
- NULL, /* m_clear */
- NULL, /* m_free */
+ PyModuleDef_HEAD_INIT,
+ "bmesh.types", /* m_name */
+ NULL, /* m_doc */
+ 0, /* m_size */
+ NULL, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
};
PyObject *BPyInit_bmesh_types(void)
diff --git a/source/blender/python/bmesh/bmesh_py_utils.c b/source/blender/python/bmesh/bmesh_py_utils.c
index 88b875cc489..389b40c0d70 100644
--- a/source/blender/python/bmesh/bmesh_py_utils.c
+++ b/source/blender/python/bmesh/bmesh_py_utils.c
@@ -257,35 +257,35 @@ static PyObject *bpy_bm_utils_edge_split(PyObject *UNUSED(self), PyObject *args)
}
PyDoc_STRVAR(bpy_bm_utils_face_split_doc,
-".. method:: face_split(vert, vert_a, vert_b, )\n"
+".. method:: face_split(face, vert, vert_a, vert_b, edge_example)\n"
"\n"
" Split an edge, return the newly created data.\n"
"\n"
-" :arg edge: The edge to split.\n"
-" :type edge: :class:`bmesh.tupes.BMEdge`\n"
-" :arg vert: One of the verts on the edge, defines the split direction.\n"
-" :type vert: :class:`bmesh.tupes.BMVert`\n"
-" :arg fac: The point on the edge where the new vert will be created [0 - 1].\n"
-" :type fac: float\n"
-" :return: The newly created (edge, vert) pair.\n"
-" :rtype: tuple\n"
+" :arg face: The face to cut.\n"
+" :type face: :class:`bmesh.tupes.BMFace`\n"
+" :arg vert_a: First vertex to cut in the face (face must contain the vert).\n"
+" :type vert_a: :class:`bmesh.tupes.BMVert`\n"
+" :arg vert_b: Second vertex to cut in the face (face must contain the vert).\n"
+" :type vert_b: :class:`bmesh.tupes.BMVert`\n"
+" :arg edge_example: Optional edge argument, newly created edge will copy settings from this one.\n"
+" :type edge_example: :class:`bmesh.tupes.BMEdge`\n"
);
static PyObject *bpy_bm_utils_face_split(PyObject *UNUSED(self), PyObject *args)
{
BPy_BMFace *py_face;
BPy_BMVert *py_vert_a;
BPy_BMVert *py_vert_b;
- float fac;
+ BPy_BMEdge *py_edge_example = NULL; /* optional */
BMesh *bm;
BMFace *f_new = NULL;
BMLoop *l_new = NULL;
- if (!PyArg_ParseTuple(args, "O!O!:face_split",
+ if (!PyArg_ParseTuple(args, "O!O!|O!:face_split",
&BPy_BMFace_Type, &py_face,
&BPy_BMVert_Type, &py_vert_a,
&BPy_BMVert_Type, &py_vert_b,
- &fac))
+ &BPy_BMEdge_Type, &py_edge_example))
{
return NULL;
}
@@ -294,6 +294,10 @@ static PyObject *bpy_bm_utils_face_split(PyObject *UNUSED(self), PyObject *args)
BPY_BM_CHECK_OBJ(py_vert_a);
BPY_BM_CHECK_OBJ(py_vert_b);
+ if (py_edge_example) {
+ BPY_BM_CHECK_OBJ(py_edge_example);
+ }
+
/* this doubles for checking that the verts are in the same mesh */
if (BM_vert_in_face(py_face->f, py_vert_a->v) == FALSE ||
BM_vert_in_face(py_face->f, py_vert_b->v) == FALSE)
@@ -311,7 +315,9 @@ static PyObject *bpy_bm_utils_face_split(PyObject *UNUSED(self), PyObject *args)
bm = py_face->bm;
- f_new = BM_face_split(bm, py_face->f, py_vert_a->v, py_vert_a->v, &l_new, NULL);
+ f_new = BM_face_split(bm, py_face->f,
+ py_vert_a->v, py_vert_a->v,
+ &l_new, py_edge_example ? py_edge_example->e : NULL);
if (f_new && l_new) {
PyObject *ret = PyTuple_New(2);
@@ -337,18 +343,18 @@ static struct PyMethodDef BPy_BM_utils_methods[] = {
};
PyDoc_STRVAR(BPy_BM_doc,
-"This module provides access to blenders bmesh data structures."
-);
+ "This module provides access to blenders bmesh data structures."
+ );
static struct PyModuleDef BPy_BM_types_module_def = {
- PyModuleDef_HEAD_INIT,
- "bmesh.utils", /* m_name */
- BPy_BM_doc, /* m_doc */
- 0, /* m_size */
- BPy_BM_utils_methods, /* m_methods */
- NULL, /* m_reload */
- NULL, /* m_traverse */
- NULL, /* m_clear */
- NULL, /* m_free */
+ PyModuleDef_HEAD_INIT,
+ "bmesh.utils", /* m_name */
+ BPy_BM_doc, /* m_doc */
+ 0, /* m_size */
+ BPy_BM_utils_methods, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
};
PyObject *BPyInit_bmesh_utils(void)