2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-02-25 19:43:51 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bmesh
|
2012-02-25 19:43:51 +00:00
|
|
|
*
|
|
|
|
|
* BMesh inline operator functions.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-03-24 01:24:58 +00:00
|
|
|
#pragma once
|
2012-02-25 19:43:51 +00:00
|
|
|
|
2021-06-28 16:02:52 +10:00
|
|
|
/* Tool Flag API: Tool code must never put junk in header flags (#BMHeader.hflag)
|
|
|
|
|
* instead, use this API to set flags.
|
|
|
|
|
* If you need to store a value per element, use a #GHash or a mapping slot to do it. */
|
2012-02-25 19:43:51 +00:00
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2) BLI_INLINE
|
2016-07-01 19:07:11 +10:00
|
|
|
short _bmo_elem_flag_test(BMesh *bm, const BMFlagLayer *oflags, const short oflag)
|
2012-02-25 20:58:03 +00:00
|
|
|
{
|
2016-07-01 19:07:11 +10:00
|
|
|
BLI_assert(bm->use_toolflags);
|
2015-12-22 15:57:45 +11:00
|
|
|
return oflags[bm->toolflag_index].f & oflag;
|
2012-04-03 02:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2) BLI_INLINE
|
2016-07-01 19:07:11 +10:00
|
|
|
bool _bmo_elem_flag_test_bool(BMesh *bm, const BMFlagLayer *oflags, const short oflag)
|
2012-04-03 02:38:27 +00:00
|
|
|
{
|
2016-07-01 19:07:11 +10:00
|
|
|
BLI_assert(bm->use_toolflags);
|
2015-12-22 15:57:45 +11:00
|
|
|
return (oflags[bm->toolflag_index].f & oflag) != 0;
|
2012-02-25 20:58:03 +00:00
|
|
|
}
|
2012-02-25 19:43:51 +00:00
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_NONNULL(1, 2)
|
2012-03-20 08:42:26 +00:00
|
|
|
BLI_INLINE void _bmo_elem_flag_enable(BMesh *bm, BMFlagLayer *oflags, const short oflag)
|
2012-02-25 20:58:03 +00:00
|
|
|
{
|
2016-07-01 19:07:11 +10:00
|
|
|
BLI_assert(bm->use_toolflags);
|
2015-12-22 15:57:45 +11:00
|
|
|
oflags[bm->toolflag_index].f |= oflag;
|
2012-02-25 20:58:03 +00:00
|
|
|
}
|
2012-02-25 19:43:51 +00:00
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_NONNULL(1, 2)
|
2012-03-20 08:42:26 +00:00
|
|
|
BLI_INLINE void _bmo_elem_flag_disable(BMesh *bm, BMFlagLayer *oflags, const short oflag)
|
2012-02-25 20:58:03 +00:00
|
|
|
{
|
2016-07-01 19:07:11 +10:00
|
|
|
BLI_assert(bm->use_toolflags);
|
2015-12-22 15:57:45 +11:00
|
|
|
oflags[bm->toolflag_index].f &= (short)~oflag;
|
2012-02-25 20:58:03 +00:00
|
|
|
}
|
2012-02-25 19:43:51 +00:00
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_NONNULL(1, 2)
|
2012-03-20 08:42:26 +00:00
|
|
|
BLI_INLINE void _bmo_elem_flag_set(BMesh *bm, BMFlagLayer *oflags, const short oflag, int val)
|
2012-02-25 20:58:03 +00:00
|
|
|
{
|
2016-07-01 19:07:11 +10:00
|
|
|
BLI_assert(bm->use_toolflags);
|
2019-03-27 17:14:36 +11:00
|
|
|
if (val) {
|
|
|
|
|
oflags[bm->toolflag_index].f |= oflag;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
oflags[bm->toolflag_index].f &= (short)~oflag;
|
|
|
|
|
}
|
2012-02-25 20:58:03 +00:00
|
|
|
}
|
2012-02-25 19:43:51 +00:00
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_NONNULL(1, 2)
|
2012-03-20 08:42:26 +00:00
|
|
|
BLI_INLINE void _bmo_elem_flag_toggle(BMesh *bm, BMFlagLayer *oflags, const short oflag)
|
2012-02-25 20:58:03 +00:00
|
|
|
{
|
2016-07-01 19:07:11 +10:00
|
|
|
BLI_assert(bm->use_toolflags);
|
2015-12-22 15:57:45 +11:00
|
|
|
oflags[bm->toolflag_index].f ^= oflag;
|
2012-02-25 19:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_NONNULL(1, 2)
|
2015-04-25 20:15:20 +10:00
|
|
|
BLI_INLINE void BMO_slot_map_int_insert(BMOperator *op,
|
|
|
|
|
BMOpSlot *slot,
|
|
|
|
|
void *element,
|
|
|
|
|
const int val)
|
2012-02-25 19:43:51 +00:00
|
|
|
{
|
2013-09-02 03:13:51 +00:00
|
|
|
union {
|
|
|
|
|
void *ptr;
|
|
|
|
|
int val;
|
|
|
|
|
} t = {NULL};
|
2012-11-27 00:50:59 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_INT);
|
2016-03-05 09:16:12 +11:00
|
|
|
BMO_slot_map_insert(op, slot, element, ((void)(t.val = val), t.ptr));
|
2012-11-26 03:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_NONNULL(1, 2)
|
2015-04-25 20:15:20 +10:00
|
|
|
BLI_INLINE void BMO_slot_map_bool_insert(BMOperator *op,
|
|
|
|
|
BMOpSlot *slot,
|
|
|
|
|
void *element,
|
|
|
|
|
const bool val)
|
2012-11-26 03:16:29 +00:00
|
|
|
{
|
2014-01-03 21:35:29 +11:00
|
|
|
union {
|
|
|
|
|
void *ptr;
|
|
|
|
|
bool val;
|
|
|
|
|
} t = {NULL};
|
2012-11-27 00:50:59 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_BOOL);
|
2016-03-05 09:16:12 +11:00
|
|
|
BMO_slot_map_insert(op, slot, element, ((void)(t.val = val), t.ptr));
|
2012-02-25 19:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_NONNULL(1, 2)
|
2015-04-25 20:15:20 +10:00
|
|
|
BLI_INLINE void BMO_slot_map_float_insert(BMOperator *op,
|
|
|
|
|
BMOpSlot *slot,
|
|
|
|
|
void *element,
|
|
|
|
|
const float val)
|
2012-02-25 19:43:51 +00:00
|
|
|
{
|
2013-09-02 03:13:51 +00:00
|
|
|
union {
|
|
|
|
|
void *ptr;
|
|
|
|
|
float val;
|
|
|
|
|
} t = {NULL};
|
2012-11-28 00:47:33 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_FLT);
|
2016-03-05 09:16:12 +11:00
|
|
|
BMO_slot_map_insert(op, slot, element, ((void)(t.val = val), t.ptr));
|
2012-02-25 19:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-01 12:20:18 +00:00
|
|
|
/* pointer versions of BMO_slot_map_float_get and BMO_slot_map_float_insert.
|
2012-02-25 19:43:51 +00:00
|
|
|
*
|
|
|
|
|
* do NOT use these for non-operator-api-allocated memory! instead
|
|
|
|
|
* use BMO_slot_map_data_get and BMO_slot_map_insert, which copies the data. */
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_NONNULL(1, 2)
|
2015-04-25 20:15:20 +10:00
|
|
|
BLI_INLINE void BMO_slot_map_ptr_insert(BMOperator *op,
|
|
|
|
|
BMOpSlot *slot,
|
|
|
|
|
const void *element,
|
|
|
|
|
void *val)
|
2012-02-25 19:43:51 +00:00
|
|
|
{
|
2012-11-27 00:50:59 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL);
|
2013-09-02 03:13:51 +00:00
|
|
|
BMO_slot_map_insert(op, slot, element, val);
|
2012-02-25 19:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_NONNULL(1, 2)
|
2015-04-25 20:15:20 +10:00
|
|
|
BLI_INLINE void BMO_slot_map_elem_insert(BMOperator *op,
|
|
|
|
|
BMOpSlot *slot,
|
|
|
|
|
const void *element,
|
|
|
|
|
void *val)
|
2012-11-26 03:16:29 +00:00
|
|
|
{
|
2012-11-27 00:50:59 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_ELEM);
|
2013-09-02 03:13:51 +00:00
|
|
|
BMO_slot_map_insert(op, slot, element, val);
|
2012-11-26 03:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* no values */
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_NONNULL(1, 2)
|
2015-04-25 20:15:20 +10:00
|
|
|
BLI_INLINE void BMO_slot_map_empty_insert(BMOperator *op, BMOpSlot *slot, const void *element)
|
2012-11-26 03:16:29 +00:00
|
|
|
{
|
2012-11-27 00:50:59 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_EMPTY);
|
2013-09-02 03:13:51 +00:00
|
|
|
BMO_slot_map_insert(op, slot, element, NULL);
|
2012-11-26 03:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) BLI_INLINE
|
2013-03-04 19:27:51 +00:00
|
|
|
bool BMO_slot_map_contains(BMOpSlot *slot, const void *element)
|
2012-02-25 19:43:51 +00:00
|
|
|
{
|
2012-06-30 09:55:04 +00:00
|
|
|
BLI_assert(slot->slot_type == BMO_OP_SLOT_MAPPING);
|
2012-02-25 19:43:51 +00:00
|
|
|
return BLI_ghash_haskey(slot->data.ghash, element);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) BLI_INLINE
|
2013-09-02 03:13:51 +00:00
|
|
|
void **BMO_slot_map_data_get(BMOpSlot *slot, const void *element)
|
2012-02-25 19:43:51 +00:00
|
|
|
{
|
|
|
|
|
|
2013-09-02 03:13:51 +00:00
|
|
|
return BLI_ghash_lookup_p(slot->data.ghash, element);
|
2012-02-25 19:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) BLI_INLINE
|
2012-11-20 13:29:27 +00:00
|
|
|
float BMO_slot_map_float_get(BMOpSlot *slot, const void *element)
|
2012-02-25 19:43:51 +00:00
|
|
|
{
|
2013-09-02 03:13:51 +00:00
|
|
|
void **data;
|
2012-11-28 00:47:33 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_FLT);
|
2012-11-26 03:16:29 +00:00
|
|
|
|
2013-09-02 03:13:51 +00:00
|
|
|
data = BMO_slot_map_data_get(slot, element);
|
|
|
|
|
if (data) {
|
2018-08-20 13:23:32 +10:00
|
|
|
return *(float *)data;
|
2013-09-02 03:13:51 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
2012-02-25 19:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) BLI_INLINE
|
2012-11-20 13:29:27 +00:00
|
|
|
int BMO_slot_map_int_get(BMOpSlot *slot, const void *element)
|
2012-02-25 19:43:51 +00:00
|
|
|
{
|
2013-09-02 03:13:51 +00:00
|
|
|
void **data;
|
2012-11-27 00:50:59 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_INT);
|
2012-11-26 03:16:29 +00:00
|
|
|
|
2013-09-02 03:13:51 +00:00
|
|
|
data = BMO_slot_map_data_get(slot, element);
|
|
|
|
|
if (data) {
|
2018-08-20 13:23:32 +10:00
|
|
|
return *(int *)data;
|
2013-09-02 03:13:51 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-11-26 03:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) BLI_INLINE
|
2013-01-14 16:42:43 +00:00
|
|
|
bool BMO_slot_map_bool_get(BMOpSlot *slot, const void *element)
|
2012-11-26 03:16:29 +00:00
|
|
|
{
|
2013-09-02 03:13:51 +00:00
|
|
|
void **data;
|
2012-11-27 00:50:59 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_BOOL);
|
2012-11-26 03:16:29 +00:00
|
|
|
|
2013-09-02 03:13:51 +00:00
|
|
|
data = BMO_slot_map_data_get(slot, element);
|
|
|
|
|
if (data) {
|
2018-08-20 13:23:32 +10:00
|
|
|
return *(bool *)data;
|
2013-09-02 03:13:51 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-02-25 19:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) BLI_INLINE
|
2012-11-26 03:47:20 +00:00
|
|
|
void *BMO_slot_map_ptr_get(BMOpSlot *slot, const void *element)
|
2012-11-26 03:16:29 +00:00
|
|
|
{
|
2013-09-02 03:13:51 +00:00
|
|
|
void **val = BMO_slot_map_data_get(slot, element);
|
2012-11-27 00:50:59 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL);
|
2019-03-27 17:14:36 +11:00
|
|
|
if (val) {
|
|
|
|
|
return *val;
|
|
|
|
|
}
|
2012-11-26 03:16:29 +00:00
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-01 19:16:58 +10:00
|
|
|
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) BLI_INLINE
|
2012-11-26 03:16:29 +00:00
|
|
|
void *BMO_slot_map_elem_get(BMOpSlot *slot, const void *element)
|
2012-02-25 19:43:51 +00:00
|
|
|
{
|
2012-11-20 13:29:27 +00:00
|
|
|
void **val = (void **)BMO_slot_map_data_get(slot, element);
|
2012-11-27 00:50:59 +00:00
|
|
|
BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_ELEM);
|
2019-03-27 17:14:36 +11:00
|
|
|
if (val) {
|
|
|
|
|
return *val;
|
|
|
|
|
}
|
2012-02-25 19:43:51 +00:00
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|