bmesh py api: use generic checking macros to see if an object if from the same bmesh.
- was such a common operation so this saves having exceptions set inline all over the place.
This commit is contained in:
@@ -582,17 +582,10 @@ static int bpy_bmfaceseq_active_set(BPy_BMElem *self, PyObject *value, void *UNU
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (BPy_BMFace_Check(value)) {
|
else if (BPy_BMFace_Check(value)) {
|
||||||
BPY_BM_CHECK_INT(value);
|
BPY_BM_CHECK_SOURCE_INT(value, bm, "faces.active = f");
|
||||||
|
|
||||||
if (((BPy_BMFace *)value)->bm != bm) {
|
bm->act_face = ((BPy_BMFace *)value)->f;
|
||||||
PyErr_SetString(PyExc_ValueError,
|
return 0;
|
||||||
"faces.active = f: f is from another mesh");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
bm->act_face = ((BPy_BMFace *)value)->f;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
@@ -1281,13 +1274,7 @@ static PyObject *bpy_bmvert_copy_from_face_interp(BPy_BMVert *self, PyObject *ar
|
|||||||
else {
|
else {
|
||||||
BMesh *bm = self->bm;
|
BMesh *bm = self->bm;
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(py_face);
|
BPY_BM_CHECK_SOURCE_OBJ(py_face, bm, "copy_from_face_interp()");
|
||||||
|
|
||||||
if (py_face->bm != bm) {
|
|
||||||
PyErr_SetString(PyExc_ValueError,
|
|
||||||
"BMVert.copy_from_face_interp(face): face is from another mesh");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
BM_vert_interp_from_face(bm, self->v, py_face->f);
|
BM_vert_interp_from_face(bm, self->v, py_face->f);
|
||||||
|
|
||||||
@@ -1421,13 +1408,7 @@ static PyObject *bpy_bmedge_other_vert(BPy_BMEdge *self, BPy_BMVert *value)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(value);
|
BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "BMEdge.other_vert(vert)");
|
||||||
|
|
||||||
if (self->bm != value->bm) {
|
|
||||||
PyErr_SetString(PyExc_ValueError,
|
|
||||||
"BMEdge.other_vert(vert): vert is from another mesh");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
other = BM_edge_other_vert(self->e, value->v);
|
other = BM_edge_other_vert(self->e, value->v);
|
||||||
|
|
||||||
@@ -1481,13 +1462,7 @@ static PyObject *bpy_bmface_copy_from_face_interp(BPy_BMFace *self, PyObject *ar
|
|||||||
else {
|
else {
|
||||||
BMesh *bm = self->bm;
|
BMesh *bm = self->bm;
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(py_face);
|
BPY_BM_CHECK_SOURCE_OBJ(py_face, bm, "BMFace.copy_from_face_interp(face)");
|
||||||
|
|
||||||
if (py_face->bm != bm) {
|
|
||||||
PyErr_SetString(PyExc_ValueError,
|
|
||||||
"BMFace.copy_from_face_interp(face): face is from another mesh");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
BM_face_interp_from_face(bm, self->f, py_face->f);
|
BM_face_interp_from_face(bm, self->f, py_face->f);
|
||||||
|
|
||||||
@@ -1653,13 +1628,7 @@ static PyObject *bpy_bmloop_copy_from_face_interp(BPy_BMLoop *self, PyObject *ar
|
|||||||
else {
|
else {
|
||||||
BMesh *bm = self->bm;
|
BMesh *bm = self->bm;
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(py_face);
|
BPY_BM_CHECK_SOURCE_OBJ(py_face, bm, "BMLoop.copy_from_face_interp(face)");
|
||||||
|
|
||||||
if (py_face->bm != bm) {
|
|
||||||
PyErr_SetString(PyExc_ValueError,
|
|
||||||
"BMLoop.copy_from_face_interp(face): face is from another mesh");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
BM_loop_interp_from_face(bm, self->l, py_face->f, do_vertex, do_multires);
|
BM_loop_interp_from_face(bm, self->l, py_face->f, do_vertex, do_multires);
|
||||||
|
|
||||||
@@ -1955,13 +1924,7 @@ static PyObject *bpy_bmvertseq_remove(BPy_BMElemSeq *self, BPy_BMVert *value)
|
|||||||
else {
|
else {
|
||||||
BMesh *bm = self->bm;
|
BMesh *bm = self->bm;
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(value);
|
BPY_BM_CHECK_SOURCE_OBJ(value, bm, "verts.remove(vert)");
|
||||||
|
|
||||||
if (value->bm != bm) {
|
|
||||||
PyErr_SetString(PyExc_ValueError,
|
|
||||||
"verts.remove(vert): vert is from another mesh");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
BM_vert_kill(bm, value->v);
|
BM_vert_kill(bm, value->v);
|
||||||
bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
|
bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
|
||||||
@@ -1985,13 +1948,7 @@ static PyObject *bpy_bmedgeseq_remove(BPy_BMElemSeq *self, BPy_BMEdge *value)
|
|||||||
else {
|
else {
|
||||||
BMesh *bm = self->bm;
|
BMesh *bm = self->bm;
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(value);
|
BPY_BM_CHECK_SOURCE_OBJ(value, bm, "edges.remove(edges)");
|
||||||
|
|
||||||
if (value->bm != bm) {
|
|
||||||
PyErr_SetString(PyExc_ValueError,
|
|
||||||
"edges.remove(edge): edge is from another mesh");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
BM_edge_kill(bm, value->e);
|
BM_edge_kill(bm, value->e);
|
||||||
bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
|
bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
|
||||||
@@ -2015,13 +1972,7 @@ static PyObject *bpy_bmfaceseq_remove(BPy_BMElemSeq *self, BPy_BMFace *value)
|
|||||||
else {
|
else {
|
||||||
BMesh *bm = self->bm;
|
BMesh *bm = self->bm;
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(value);
|
BPY_BM_CHECK_SOURCE_OBJ(value, bm, "faces.remove(face)");
|
||||||
|
|
||||||
if (value->bm != bm) {
|
|
||||||
PyErr_SetString(PyExc_ValueError,
|
|
||||||
"faces.remove(face): face is from another mesh");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
BM_face_kill(bm, value->f);
|
BM_face_kill(bm, value->f);
|
||||||
bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
|
bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
|
||||||
@@ -3450,6 +3401,21 @@ int bpy_bm_generic_valid_check(BPy_BMGeneric *self)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bpy_bm_generic_valid_check_source(BPy_BMGeneric *self, BMesh *bm_source, const char *error_prefix)
|
||||||
|
{
|
||||||
|
int ret = bpy_bm_generic_valid_check(self);
|
||||||
|
if (LIKELY(ret == 0)) {
|
||||||
|
if (UNLIKELY(self->bm != bm_source)) {
|
||||||
|
/* could give more info here */
|
||||||
|
PyErr_Format(PyExc_ValueError,
|
||||||
|
"%.200s: BMesh data of type %.200s is from another mesh",
|
||||||
|
error_prefix, Py_TYPE(self)->tp_name);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void bpy_bm_generic_invalidate(BPy_BMGeneric *self)
|
void bpy_bm_generic_invalidate(BPy_BMGeneric *self)
|
||||||
{
|
{
|
||||||
self->bm = NULL;
|
self->bm = NULL;
|
||||||
|
|||||||
@@ -158,9 +158,6 @@ PyObject *BPy_BMIter_CreatePyObject(BMesh *bm);
|
|||||||
|
|
||||||
PyObject *BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele); /* just checks type and creates v/e/f/l */
|
PyObject *BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele); /* just checks type and creates v/e/f/l */
|
||||||
|
|
||||||
int bpy_bm_generic_valid_check(BPy_BMGeneric *self);
|
|
||||||
void bpy_bm_generic_invalidate(BPy_BMGeneric *self);
|
|
||||||
|
|
||||||
void *BPy_BMElem_PySeq_As_Array(BMesh **r_bm, PyObject *seq, Py_ssize_t min, Py_ssize_t max, Py_ssize_t *r_size,
|
void *BPy_BMElem_PySeq_As_Array(BMesh **r_bm, PyObject *seq, Py_ssize_t min, Py_ssize_t max, Py_ssize_t *r_size,
|
||||||
const char htype,
|
const char htype,
|
||||||
const char do_unique_check, const char do_bm_check,
|
const char do_unique_check, const char do_bm_check,
|
||||||
@@ -171,9 +168,20 @@ int BPy_BMElem_CheckHType(PyTypeObject *type, const char htype);
|
|||||||
char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32]);
|
char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32]);
|
||||||
char *BPy_BMElem_StringFromHType(const char htype);
|
char *BPy_BMElem_StringFromHType(const char htype);
|
||||||
|
|
||||||
|
void bpy_bm_generic_invalidate(BPy_BMGeneric *self);
|
||||||
|
int bpy_bm_generic_valid_check(BPy_BMGeneric *self);
|
||||||
|
int bpy_bm_generic_valid_check_source(BPy_BMGeneric *self, BMesh *bm_source, const char *error_prefix);
|
||||||
|
|
||||||
#define BPY_BM_CHECK_OBJ(obj) if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return NULL; } (void)0
|
#define BPY_BM_CHECK_OBJ(obj) \
|
||||||
#define BPY_BM_CHECK_INT(obj) if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return -1; } (void)0
|
if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return NULL; } (void)0
|
||||||
|
#define BPY_BM_CHECK_INT(obj) \
|
||||||
|
if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return -1; } (void)0
|
||||||
|
|
||||||
|
/* macros like BPY_BM_CHECK_OBJ/BPY_BM_CHECK_INT that ensure we're from the right BMesh */
|
||||||
|
#define BPY_BM_CHECK_SOURCE_OBJ(obj, bm, errmsg) \
|
||||||
|
if (UNLIKELY(bpy_bm_generic_valid_check_source((BPy_BMGeneric *)obj, bm, errmsg) == -1)) { return NULL; } (void)0
|
||||||
|
#define BPY_BM_CHECK_SOURCE_INT(obj, bm, errmsg) \
|
||||||
|
if (UNLIKELY(bpy_bm_generic_valid_check_source((BPy_BMGeneric *)obj, bm, errmsg) == -1)) { return -1; } (void)0
|
||||||
|
|
||||||
#define BPY_BM_IS_VALID(obj) (LIKELY((obj)->bm != NULL))
|
#define BPY_BM_IS_VALID(obj) (LIKELY((obj)->bm != NULL))
|
||||||
|
|
||||||
|
|||||||
@@ -262,16 +262,10 @@ static PyObject *bpy_bmlayeritem_copy_from(BPy_BMLayerItem *self, BPy_BMLayerIte
|
|||||||
}
|
}
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(self);
|
BPY_BM_CHECK_OBJ(self);
|
||||||
BPY_BM_CHECK_OBJ(value);
|
BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "layer.copy_from()");
|
||||||
|
|
||||||
if (self->bm != value->bm) {
|
if ((self->htype != value->htype) ||
|
||||||
PyErr_SetString(PyExc_ValueError,
|
(self->type != value->type))
|
||||||
"layer.copy_from(): layer is from another mesh");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if ((self->htype != value->htype) ||
|
|
||||||
(self->type != value->type))
|
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"layer.copy_from(other): layer type mismatch");
|
"layer.copy_from(other): layer type mismatch");
|
||||||
|
|||||||
@@ -114,13 +114,7 @@ static PyObject *bpy_bmeditselseq_add(BPy_BMEditSelSeq *self, BPy_BMElem *value)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(value);
|
BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "select_history.add()");
|
||||||
|
|
||||||
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);
|
BM_select_history_store(self->bm, value->ele);
|
||||||
|
|
||||||
@@ -145,11 +139,9 @@ static PyObject *bpy_bmeditselseq_remove(BPy_BMEditSelSeq *self, BPy_BMElem *val
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(value);
|
BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "select_history.remove()");
|
||||||
|
|
||||||
if ((self->bm != value->bm) ||
|
if (BM_select_history_remove(self->bm, value->ele) == FALSE) {
|
||||||
(BM_select_history_remove(self->bm, value->ele) == FALSE))
|
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"Element not found in selection history");
|
"Element not found in selection history");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -557,16 +557,10 @@ static PyObject *bpy_bm_utils_face_vert_separate(PyObject *UNUSED(self), PyObjec
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
BPY_BM_CHECK_OBJ(py_face);
|
|
||||||
BPY_BM_CHECK_OBJ(py_vert);
|
|
||||||
|
|
||||||
bm = py_face->bm;
|
bm = py_face->bm;
|
||||||
|
|
||||||
if (bm != py_vert->bm) {
|
BPY_BM_CHECK_OBJ(py_face);
|
||||||
PyErr_SetString(PyExc_ValueError,
|
BPY_BM_CHECK_SOURCE_OBJ(py_vert, bm, "face_vert_separate()");
|
||||||
"mesh elements are from different meshes");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
l = BM_face_vert_share_loop(py_face->f, py_vert->v);
|
l = BM_face_vert_share_loop(py_face->f, py_vert->v);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user