| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * ***** 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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  |  * The Original Code is Copyright (C) 2012 Blender Foundation. | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Campbell Barton | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | /** \file blender/python/bmesh/bmesh_py_api.c
 | 
					
						
							|  |  |  |  *  \ingroup pybmesh | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  |  * This file defines the 'bmesh' module. | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 01:24:58 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | #include "bmesh.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "bmesh_py_types.h"
 | 
					
						
							| 
									
										
										
										
											2012-03-15 06:08:27 +00:00
										 |  |  | #include "bmesh_py_types_select.h"
 | 
					
						
							| 
									
										
										
										
											2012-03-16 05:03:13 +00:00
										 |  |  | #include "bmesh_py_types_customdata.h"
 | 
					
						
							| 
									
										
										
										
											2012-03-17 06:40:44 +00:00
										 |  |  | #include "bmesh_py_types_meshdata.h"
 | 
					
						
							| 
									
										
										
										
											2012-03-16 05:03:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | #include "bmesh_py_utils.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_tessmesh.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "bmesh_py_api.h" /* own include */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-10 20:41:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(bpy_bm_new_doc, | 
					
						
							|  |  |  | ".. method:: new()\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :return: Return a new, empty BMesh.\n" | 
					
						
							|  |  |  | "   :rtype: :class:`bmesh.types.BMesh`\n" | 
					
						
							| 
									
										
										
										
											2012-03-10 20:41:19 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *bpy_bm_new(PyObject *UNUSED(self)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 19:58:56 +00:00
										 |  |  | 	bm = BM_mesh_create(&bm_mesh_allocsize_default); | 
					
						
							| 
									
										
										
										
											2012-03-10 20:41:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 05:58:22 +00:00
										 |  |  | 	return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_NOP); | 
					
						
							| 
									
										
										
										
											2012-03-10 20:41:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 02:45:27 +00:00
										 |  |  | PyDoc_STRVAR(bpy_bm_from_edit_mesh_doc, | 
					
						
							|  |  |  | ".. method:: from_edit_mesh(mesh)\n" | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | "   Return a BMesh from this mesh, currently the mesh must already be in editmode.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: the BMesh assosiated with this mesh.\n" | 
					
						
							|  |  |  | "   :rtype: :class:`bmesh.types.BMesh`\n" | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2012-03-11 02:45:27 +00:00
										 |  |  | static PyObject *bpy_bm_from_edit_mesh(PyObject *UNUSED(self), PyObject *value) | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-10 20:41:19 +00:00
										 |  |  | 	BMesh *bm; | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | 	Mesh *me = PyC_RNA_AsPointer(value, "Mesh"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-10 20:41:19 +00:00
										 |  |  | 	if (me == NULL) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-04 11:10:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 02:45:27 +00:00
										 |  |  | 	if (me->edit_btmesh == NULL) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "The mesh must be in editmode"); | 
					
						
							| 
									
										
										
										
											2012-03-10 20:41:19 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 02:45:27 +00:00
										 |  |  | 	bm = me->edit_btmesh->bm; | 
					
						
							| 
									
										
										
										
											2012-03-10 20:41:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 05:58:22 +00:00
										 |  |  | 	return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_IS_WRAPPED); | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct PyMethodDef BPy_BM_methods[] = { | 
					
						
							| 
									
										
										
										
											2012-03-11 02:45:27 +00:00
										 |  |  |     {"new",            (PyCFunction)bpy_bm_new,            METH_NOARGS,  bpy_bm_new_doc}, | 
					
						
							|  |  |  |     {"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O,       bpy_bm_from_edit_mesh_doc}, | 
					
						
							| 
									
										
										
										
											2012-03-10 20:41:19 +00:00
										 |  |  |     {NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(BPy_BM_doc, | 
					
						
							| 
									
										
										
										
											2012-03-09 21:23:15 +00:00
										 |  |  | "This module provides access to blenders bmesh data structures.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Submodules:\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "* :mod:`bmesh.utils`\n" | 
					
						
							|  |  |  | "* :mod:`bmesh.types`\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 02:45:27 +00:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2012-03-13 06:22:43 +00:00
										 |  |  | ".. include:: include__bmesh.rst\n" | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | static struct PyModuleDef BPy_BM_module_def = { | 
					
						
							|  |  |  | 	PyModuleDef_HEAD_INIT, | 
					
						
							| 
									
										
										
										
											2012-02-22 10:41:07 +00:00
										 |  |  | 	"bmesh",  /* m_name */ | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | 	BPy_BM_doc,  /* m_doc */ | 
					
						
							|  |  |  | 	0,  /* m_size */ | 
					
						
							|  |  |  | 	BPy_BM_methods,  /* m_methods */ | 
					
						
							|  |  |  | 	NULL,  /* m_reload */ | 
					
						
							|  |  |  | 	NULL,  /* m_traverse */ | 
					
						
							|  |  |  | 	NULL,  /* m_clear */ | 
					
						
							|  |  |  | 	NULL,  /* m_free */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject *BPyInit_bmesh(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | 	PyObject *mod; | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | 	PyObject *submodule; | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | 	PyObject *sys_modules = PySys_GetObject("modules"); /* not pretty */ | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BPy_BM_init_types(); | 
					
						
							| 
									
										
										
										
											2012-03-16 05:03:13 +00:00
										 |  |  | 	BPy_BM_init_types_select(); | 
					
						
							|  |  |  | 	BPy_BM_init_types_customdata(); | 
					
						
							| 
									
										
										
										
											2012-03-17 06:40:44 +00:00
										 |  |  | 	BPy_BM_init_types_meshdata(); | 
					
						
							| 
									
										
										
										
											2012-02-29 14:05:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | 	mod = PyModule_Create(&BPy_BM_module_def); | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | 	/* bmesh.types */ | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | 	PyModule_AddObject(mod, "types", (submodule = BPyInit_bmesh_types())); | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | 	PyDict_SetItemString(sys_modules, "bmesh.types", submodule); | 
					
						
							|  |  |  | 	Py_INCREF(submodule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | 	PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils())); | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | 	PyDict_SetItemString(sys_modules, "bmesh.utils", submodule); | 
					
						
							|  |  |  | 	Py_INCREF(submodule); | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | 	return mod; | 
					
						
							| 
									
										
										
										
											2012-02-22 09:19:53 +00:00
										 |  |  | } |