Revision: 44368
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44368
Author:   campbellbarton
Date:     2012-02-23 11:27:22 +0000 (Thu, 23 Feb 2012)
Log Message:
-----------
bmesh py api, new elements now take optional 'example' arguments, so the new 
data copies from the existing.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/intern/bmesh_newcore.c
    trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
    trunk/blender/source/blender/python/bmesh/bmesh_py_utils.c

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_newcore.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_newcore.c   2012-02-23 
10:41:31 UTC (rev 44367)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_newcore.c   2012-02-23 
11:27:22 UTC (rev 44368)
@@ -75,7 +75,7 @@
        CustomData_bmesh_set_default(&bm->vdata, &v->head.data);
        
        if (example) {
-               BM_elem_attrs_copy(bm, bm, (BMVert *)example, (BMVert *)v);
+               BM_elem_attrs_copy(bm, bm, (BMVert *)example, v);
        }
 
        BM_CHECK_ELEMENT(bm, v);

Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_types.c  2012-02-23 
10:41:31 UTC (rev 44367)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_types.c  2012-02-23 
11:27:22 UTC (rev 44368)
@@ -794,10 +794,13 @@
 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 @@
                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 @@
                        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 @@
 {
        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 @@
                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 @@
                        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_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 @@
 
                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 @@
                        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 @@
                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 @@
  * ********************* */
 
 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)

Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_utils.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_utils.c  2012-02-23 
10:41:31 UTC (rev 44367)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_utils.c  2012-02-23 
11:27:22 UTC (rev 44368)
@@ -257,35 +257,35 @@
 }
 
 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 @@
        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 @@
 
        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 @@
 };
 
 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)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to