Core: use template for BKE_id_new

This is the same change as e09ccc9b35 but for `BKE_id_new`.

Pull Request: https://projects.blender.org/blender/blender/pulls/138667
This commit is contained in:
Jacques Lucke
2025-05-09 16:13:25 +02:00
parent ba38a2257e
commit d9b91c73e3
47 changed files with 95 additions and 94 deletions

View File

@@ -41,7 +41,7 @@ class ActionIteratorsTest : public testing::Test {
void SetUp() override
{
bmain = BKE_main_new();
action = static_cast<Action *>(BKE_id_new(bmain, ID_AC, "ACLayeredAction"));
action = BKE_id_new<Action>(bmain, "ACLayeredAction");
}
void TearDown() override
@@ -114,13 +114,12 @@ TEST_F(ActionIteratorsTest, iterate_all_fcurves_of_slot)
TEST_F(ActionIteratorsTest, foreach_action_slot_use_with_references)
{
/* Create a cube and assign the Action + a slot. */
Object *cube = static_cast<Object *>(BKE_id_new(bmain, ID_OB, "OBCube"));
Object *cube = BKE_id_new<Object>(bmain, "OBCube");
Slot *slot_cube = assign_action_ensure_slot_for_keying(*action, cube->id);
ASSERT_NE(slot_cube, nullptr);
/* Create another Action with slot to assign. */
Action &other_action =
static_cast<bAction *>(BKE_id_new(bmain, ID_AC, "ACAnotherAction"))->wrap();
Action &other_action = BKE_id_new<bAction>(bmain, "ACAnotherAction")->wrap();
Slot &another_slot = other_action.slot_add();
std::optional<ActionSlotAssignmentResult> slot_assignment_result;
@@ -162,7 +161,7 @@ TEST_F(ActionIteratorsTest, foreach_action_slot_use_with_references)
TEST_F(ActionIteratorsTest, foreach_action_slot_use_with_rna)
{
/* Create a cube and assign the Action + a slot. */
Object *cube = static_cast<Object *>(BKE_id_new(bmain, ID_OB, "OBCube"));
Object *cube = BKE_id_new<Object>(bmain, "OBCube");
Slot *slot_cube = assign_action_ensure_slot_for_keying(*action, cube->id);
ASSERT_NE(slot_cube, nullptr);
Slot &another_slot = action->slot_add();

View File

@@ -48,7 +48,7 @@ class ActionLegacyTest : public testing::Test {
bAction *create_empty_action()
{
return static_cast<bAction *>(BKE_id_new(bmain, ID_AC, "ACAction"));
return BKE_id_new<bAction>(bmain, "ACAction");
}
FCurve *fcurve_add_legacy(bAction *action, const StringRefNull rna_path, const int array_index)

View File

@@ -64,7 +64,7 @@ class ActionLayersTest : public testing::Test {
void SetUp() override
{
bmain = BKE_main_new();
action = static_cast<Action *>(BKE_id_new(bmain, ID_AC, "ACÄnimåtië"));
action = BKE_id_new<Action>(bmain, "ACÄnimåtië");
cube = BKE_object_add_only_object(bmain, OB_EMPTY, "Küüübus");
suzanne = BKE_object_add_only_object(bmain, OB_EMPTY, "OBSuzanne");
bob = BKE_object_add_only_object(bmain, OB_EMPTY, "OBBob");
@@ -115,7 +115,7 @@ TEST_F(ActionLayersTest, remove_layer)
layer2.strip_add(*action, Strip::Type::Keyframe);
{ /* Test removing a layer that is not owned. */
Action *other_anim = static_cast<Action *>(BKE_id_new(bmain, ID_AC, "ACOtherAnim"));
Action *other_anim = BKE_id_new<Action>(bmain, "ACOtherAnim");
Layer &other_layer = other_anim->layer_add("Another Layer");
EXPECT_FALSE(action->layer_remove(other_layer))
<< "Removing a layer not owned by the Action should be gracefully rejected";
@@ -565,7 +565,7 @@ TEST_F(ActionLayersTest, action_assign_id)
<< "Expecting Suzanne to be registered as animated by the Cube slot.";
{ /* Assign Cube to another action+slot without unassigning first. */
Action *another_anim = static_cast<Action *>(BKE_id_new(bmain, ID_AC, "ACOtherAnim"));
Action *another_anim = BKE_id_new<Action>(bmain, "ACOtherAnim");
Slot &another_slot = another_anim->slot_add();
ASSERT_EQ(assign_action_and_slot(another_anim, &another_slot, cube->id),
ActionSlotAssignmentResult::OK);
@@ -1130,8 +1130,8 @@ TEST_F(ActionLayersTest, conversion_to_layered)
ASSERT_TRUE(bag->fcurve_array[0]->modifiers.first == nullptr);
ASSERT_TRUE(bag->fcurve_array[1]->modifiers.first != nullptr);
Action *long_name_action = static_cast<Action *>(BKE_id_new(
bmain, ID_AC, "name_for_an_action_that_is_exactly_64_chars_which_is_MAX_ID_NAME"));
Action *long_name_action = BKE_id_new<Action>(
bmain, "name_for_an_action_that_is_exactly_64_chars_which_is_MAX_ID_NAME");
action_fcurve_ensure_legacy(bmain, long_name_action, "Long", nullptr, {"location", 0});
converted = convert_to_layered_action(*bmain, *long_name_action);
/* AC gets added automatically by Blender, the long name is shortened to make space for
@@ -1196,7 +1196,7 @@ TEST_F(ActionLayersTest, empty_to_layered)
TEST_F(ActionLayersTest, action_move_slot)
{
Action *action_2 = static_cast<Action *>(BKE_id_new(bmain, ID_AC, "Action 2"));
Action *action_2 = BKE_id_new<Action>(bmain, "Action 2");
EXPECT_TRUE(action->is_empty());
Slot &slot_cube = action->slot_add();
@@ -1250,7 +1250,7 @@ TEST_F(ActionLayersTest, action_move_slot)
TEST_F(ActionLayersTest, action_move_slot_without_channelbag)
{
Action *action_2 = static_cast<Action *>(BKE_id_new(bmain, ID_AC, "Action 2"));
Action *action_2 = BKE_id_new<Action>(bmain, "Action 2");
EXPECT_TRUE(action->is_empty());
Slot &slot_cube = action->slot_add();
@@ -1442,7 +1442,7 @@ class ActionQueryTest : public testing::Test {
Action &action_new()
{
return *static_cast<Action *>(BKE_id_new(bmain, ID_AC, "ACÄnimåtië"));
return *BKE_id_new<Action>(bmain, "ACÄnimåtië");
}
};

View File

@@ -59,7 +59,7 @@ class AnimationEvaluationTest : public testing::Test {
void SetUp() override
{
bmain = BKE_main_new();
action = static_cast<Action *>(BKE_id_new(bmain, ID_AC, "ACÄnimåtië"));
action = BKE_id_new<Action>(bmain, "ACÄnimåtië");
cube = BKE_object_add_only_object(bmain, OB_EMPTY, "Küüübus");

View File

@@ -92,7 +92,7 @@ class KeyframingTest : public testing::Test {
object_with_nla = BKE_object_add_only_object(bmain, OB_EMPTY, "EmptyWithNLA");
object_with_nla_rna_pointer = RNA_id_pointer_create(&object_with_nla->id);
nla_action = static_cast<bAction *>(BKE_id_new(bmain, ID_AC, "NLAAction"));
nla_action = BKE_id_new<bAction>(bmain, "NLAAction");
this->ensure_action_is_legacy(*nla_action);
cube = BKE_object_add_only_object(bmain, OB_MESH, "cube");
@@ -659,7 +659,7 @@ TEST_F(KeyframingTest, insert_keyframes__baklava_legacy_action)
/* Create a legacy Action and assign it the legacy way. */
{
bAction *action = reinterpret_cast<bAction *>(BKE_id_new(bmain, ID_AC, "LegacyAction"));
bAction *action = BKE_id_new<bAction>(bmain, "LegacyAction");
action_fcurve_ensure_legacy(bmain, action, nullptr, nullptr, {"testprop", 47});
BKE_animdata_ensure_id(&object->id)->action = action;
}

View File

@@ -46,7 +46,7 @@ class NLASlottedActionTest : public testing::Test {
void SetUp() override
{
bmain = BKE_main_new();
action = static_cast<Action *>(BKE_id_new(bmain, ID_AC, "ACÄnimåtië"));
action = BKE_id_new<Action>(bmain, "ACÄnimåtië");
action->id.us = 0; /* Nothing references this yet. */
cube = BKE_object_add_only_object(bmain, OB_EMPTY, "Küüübus");
cube->id.us = 0; /* Nothing references this yet. */

View File

@@ -55,7 +55,7 @@ class PoseTest : public testing::Test {
void SetUp() override
{
bmain = BKE_main_new();
pose_action = static_cast<Action *>(BKE_id_new(bmain, ID_AC, "pose_data"));
pose_action = BKE_id_new<Action>(bmain, "pose_data");
Layer &layer = pose_action->layer_add("first_layer");
Strip &strip = layer.strip_add(*pose_action, Strip::Type::Keyframe);
keyframe_data = &strip.data<StripKeyframeData>(*pose_action);

View File

@@ -129,6 +129,13 @@ void BKE_lib_libblock_session_uid_renew(ID *id);
* \param name: can be NULL, in which case we get default name for this ID type.
*/
void *BKE_id_new(Main *bmain, short type, const char *name);
template<typename T> inline T *BKE_id_new(Main *bmain, const char *name)
{
const ID_Type id_type = T::id_type;
return static_cast<T *>(BKE_id_new(bmain, id_type, name));
}
/**
* Same as for #BKE_id_new, but allows creating a data-block for (within) a given owner library.
*

View File

@@ -802,7 +802,7 @@ bAction *BKE_action_add(Main *bmain, const char name[])
{
bAction *act;
act = static_cast<bAction *>(BKE_id_new(bmain, ID_AC, name));
act = BKE_id_new<bAction>(bmain, name);
return act;
}

View File

@@ -23,7 +23,7 @@ TEST(anim_data, BKE_fcurves_id_cb_test)
BKE_idtype_init();
Main *bmain = BKE_main_new();
Action *action = static_cast<Action *>(BKE_id_new(bmain, ID_AC, "ACÄnimåtië"));
Action *action = BKE_id_new<Action>(bmain, "ACÄnimåtië");
Object *cube = BKE_object_add_only_object(bmain, OB_EMPTY, "Küüübus");
Object *suzanne = BKE_object_add_only_object(bmain, OB_EMPTY, "OBSuzanne");

View File

@@ -509,7 +509,7 @@ bArmature *BKE_armature_add(Main *bmain, const char *name)
{
bArmature *arm;
arm = static_cast<bArmature *>(BKE_id_new(bmain, ID_AR, name));
arm = BKE_id_new<bArmature>(bmain, name);
return arm;
}

View File

@@ -64,8 +64,8 @@ class BPathTest : public testing::Test {
bmain = BKE_main_new();
STRNCPY(bmain->filepath, BLENDFILE_PATH);
BKE_id_new(bmain, ID_TXT, nullptr);
BKE_id_new(bmain, ID_MC, nullptr);
BKE_id_new<Text>(bmain, nullptr);
BKE_id_new<MovieClip>(bmain, nullptr);
}
void TearDown() override

View File

@@ -529,7 +529,7 @@ static void brush_defaults(Brush *brush)
Brush *BKE_brush_add(Main *bmain, const char *name, const eObjectMode ob_mode)
{
Brush *brush = (Brush *)BKE_id_new(bmain, ID_BR, name);
Brush *brush = BKE_id_new<Brush>(bmain, name);
brush->ob_mode = ob_mode;

View File

@@ -307,7 +307,7 @@ static void cachefile_handle_free(CacheFile *cache_file)
void *BKE_cachefile_add(Main *bmain, const char *name)
{
CacheFile *cache_file = static_cast<CacheFile *>(BKE_id_new(bmain, ID_CF, name));
CacheFile *cache_file = BKE_id_new<CacheFile>(bmain, name);
return cache_file;
}

View File

@@ -290,7 +290,7 @@ Camera *BKE_camera_add(Main *bmain, const char *name)
{
Camera *cam;
cam = static_cast<Camera *>(BKE_id_new(bmain, ID_CA, name));
cam = BKE_id_new<Camera>(bmain, name);
return cam;
}

View File

@@ -432,7 +432,7 @@ static Collection *collection_add(Main *bmain,
}
/* Create new collection. */
Collection *collection = static_cast<Collection *>(BKE_id_new(bmain, ID_GR, name));
Collection *collection = BKE_id_new<Collection>(bmain, name);
/* We increase collection user count when linking to Collections. */
id_us_min(&collection->id);

View File

@@ -168,7 +168,7 @@ IDTypeInfo IDType_ID_CV = {
Curves *BKE_curves_add(Main *bmain, const char *name)
{
Curves *curves = static_cast<Curves *>(BKE_id_new(bmain, ID_CV, name));
Curves *curves = BKE_id_new<Curves>(bmain, name);
return curves;
}

View File

@@ -2000,7 +2000,7 @@ bool BKE_grease_pencil_drawing_attribute_required(const GreasePencilDrawing * /*
GreasePencil *BKE_grease_pencil_add(Main *bmain, const char *name)
{
GreasePencil *grease_pencil = reinterpret_cast<GreasePencil *>(BKE_id_new(bmain, ID_GP, name));
GreasePencil *grease_pencil = BKE_id_new<GreasePencil>(bmain, name);
return grease_pencil;
}

View File

@@ -40,7 +40,7 @@ TEST(greasepencil, create_grease_pencil_id)
{
GreasePencilIDTestContext ctx;
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(BKE_id_new(ctx.bmain, ID_GP, "GP"));
GreasePencil &grease_pencil = *BKE_id_new<GreasePencil>(ctx.bmain, "GP");
EXPECT_EQ(grease_pencil.drawings().size(), 0);
EXPECT_EQ(grease_pencil.root_group().num_nodes_total(), 0);
}
@@ -51,7 +51,7 @@ TEST(greasepencil, create_grease_pencil_id)
TEST(greasepencil, add_empty_drawings)
{
GreasePencilIDTestContext ctx;
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(BKE_id_new(ctx.bmain, ID_GP, "GP"));
GreasePencil &grease_pencil = *BKE_id_new<GreasePencil>(ctx.bmain, "GP");
grease_pencil.add_empty_drawings(3);
EXPECT_EQ(grease_pencil.drawings().size(), 3);
}
@@ -59,7 +59,7 @@ TEST(greasepencil, add_empty_drawings)
TEST(greasepencil, remove_drawings)
{
GreasePencilIDTestContext ctx;
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(BKE_id_new(ctx.bmain, ID_GP, "GP"));
GreasePencil &grease_pencil = *BKE_id_new<GreasePencil>(ctx.bmain, "GP");
grease_pencil.add_empty_drawings(3);
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(grease_pencil.drawing(1));

View File

@@ -260,7 +260,7 @@ Key *BKE_key_add(Main *bmain, ID *id) /* common function */
Key *key;
char *el;
key = static_cast<Key *>(BKE_id_new(bmain, ID_KE, "Key"));
key = BKE_id_new<Key>(bmain, "Key");
key->type = KEY_NORMAL;
key->from = id;

View File

@@ -393,7 +393,7 @@ Lattice *BKE_lattice_add(Main *bmain, const char *name)
{
Lattice *lt;
lt = static_cast<Lattice *>(BKE_id_new(bmain, ID_LT, name));
lt = BKE_id_new<Lattice>(bmain, name);
return lt;
}

View File

@@ -1598,8 +1598,7 @@ static void lib_override_library_create_post_process(Main *bmain,
if (ID_REAL_USERS(ob_new) != 0) {
continue;
}
default_instantiating_collection = static_cast<Collection *>(
BKE_id_new(bmain, ID_GR, "OVERRIDE_HIDDEN"));
default_instantiating_collection = BKE_id_new<Collection>(bmain, "OVERRIDE_HIDDEN");
id_us_min(&default_instantiating_collection->id);
/* Hide the collection from viewport and render. */
default_instantiating_collection->flag |= COLLECTION_HIDE_VIEWPORT |

View File

@@ -190,7 +190,7 @@ Light *BKE_light_add(Main *bmain, const char *name)
{
Light *la;
la = static_cast<Light *>(BKE_id_new(bmain, ID_LA, name));
la = BKE_id_new<Light>(bmain, name);
return la;
}

View File

@@ -107,7 +107,7 @@ LightProbe *BKE_lightprobe_add(Main *bmain, const char *name)
{
LightProbe *probe;
probe = static_cast<LightProbe *>(BKE_id_new(bmain, ID_LP, name));
probe = BKE_id_new<LightProbe>(bmain, name);
return probe;
}

View File

@@ -67,8 +67,8 @@ TEST_F(BMainMergeTest, basics)
EXPECT_TRUE(BLI_listbase_is_empty(&bmain_src->objects));
BKE_id_new(bmain_dst, ID_GR, "Coll_dst");
Collection *coll = static_cast<Collection *>(BKE_id_new(bmain_src, ID_GR, "Coll_src"));
Object *ob = static_cast<Object *>(BKE_id_new(bmain_src, ID_OB, "Ob_src"));
Collection *coll = BKE_id_new<Collection>(bmain_src, "Coll_src");
Object *ob = BKE_id_new<Object>(bmain_src, "Ob_src");
BKE_collection_object_add(bmain_src, coll, ob);
EXPECT_EQ(1, BLI_listbase_count(&bmain_dst->collections));
@@ -88,8 +88,8 @@ TEST_F(BMainMergeTest, basics)
EXPECT_EQ(nullptr, bmain_src);
bmain_src = BKE_main_new();
Collection *coll_2 = static_cast<Collection *>(BKE_id_new(bmain_src, ID_GR, "Coll_src_2"));
Object *ob_2 = static_cast<Object *>(BKE_id_new(bmain_src, ID_OB, "Ob_src"));
Collection *coll_2 = BKE_id_new<Collection>(bmain_src, "Coll_src_2");
Object *ob_2 = BKE_id_new<Object>(bmain_src, "Ob_src");
BKE_collection_object_add(bmain_src, coll_2, ob_2);
EXPECT_EQ(2, BLI_listbase_count(&bmain_dst->collections));
@@ -142,12 +142,12 @@ TEST_F(BMainMergeTest, linked_data)
STRNCPY(bmain_dst->filepath, DST_PATH);
STRNCPY(bmain_src->filepath, SRC_PATH);
BKE_id_new(bmain_dst, ID_GR, "Coll_dst");
BKE_id_new<Collection>(bmain_dst, "Coll_dst");
Collection *coll_1 = static_cast<Collection *>(BKE_id_new(bmain_src, ID_GR, "Coll_src"));
Object *ob_1 = static_cast<Object *>(BKE_id_new(bmain_src, ID_OB, "Ob_src"));
Collection *coll_1 = BKE_id_new<Collection>(bmain_src, "Coll_src");
Object *ob_1 = BKE_id_new<Object>(bmain_src, "Ob_src");
BKE_collection_object_add(bmain_src, coll_1, ob_1);
Library *lib_src_1 = static_cast<Library *>(BKE_id_new(bmain_src, ID_LI, LIB_PATH));
Library *lib_src_1 = BKE_id_new<Library>(bmain_src, LIB_PATH);
BKE_library_filepath_set(bmain_src, lib_src_1, LIB_PATH);
ob_1->id.lib = lib_src_1;
@@ -178,10 +178,10 @@ TEST_F(BMainMergeTest, linked_data)
bmain_src = BKE_main_new();
STRNCPY(bmain_src->filepath, SRC_PATH);
Collection *coll_2 = static_cast<Collection *>(BKE_id_new(bmain_src, ID_GR, "Coll_src_2"));
Object *ob_2 = static_cast<Object *>(BKE_id_new(bmain_src, ID_OB, "Ob_src_2"));
Collection *coll_2 = BKE_id_new<Collection>(bmain_src, "Coll_src_2");
Object *ob_2 = BKE_id_new<Object>(bmain_src, "Ob_src_2");
BKE_collection_object_add(bmain_src, coll_2, ob_2);
Library *lib_src_2 = static_cast<Library *>(BKE_id_new(bmain_src, ID_LI, LIB_PATH));
Library *lib_src_2 = BKE_id_new<Library>(bmain_src, LIB_PATH);
BKE_library_filepath_set(bmain_src, lib_src_2, LIB_PATH);
std::cout << lib_src_1->runtime->filepath_abs << "\n";
std::cout << lib_src_2->runtime->filepath_abs << "\n";
@@ -214,10 +214,10 @@ TEST_F(BMainMergeTest, linked_data)
bmain_src = BKE_main_new();
STRNCPY(bmain_src->filepath, SRC_PATH);
Collection *coll_3 = static_cast<Collection *>(BKE_id_new(bmain_src, ID_GR, "Coll_src_3"));
Object *ob_3 = static_cast<Object *>(BKE_id_new(bmain_src, ID_OB, "Ob_src"));
Collection *coll_3 = BKE_id_new<Collection>(bmain_src, "Coll_src_3");
Object *ob_3 = BKE_id_new<Object>(bmain_src, "Ob_src");
BKE_collection_object_add(bmain_src, coll_3, ob_3);
Library *lib_src_3 = static_cast<Library *>(BKE_id_new(bmain_src, ID_LI, LIB_PATH_RELATIVE));
Library *lib_src_3 = BKE_id_new<Library>(bmain_src, LIB_PATH_RELATIVE);
BKE_library_filepath_set(bmain_src, lib_src_3, LIB_PATH_RELATIVE);
ob_3->id.lib = lib_src_3;
@@ -254,10 +254,10 @@ TEST_F(BMainMergeTest, linked_data)
bmain_src = BKE_main_new();
STRNCPY(bmain_src->filepath, SRC_PATH);
Collection *coll_4 = static_cast<Collection *>(BKE_id_new(bmain_src, ID_GR, "Coll_src"));
Object *ob_4 = static_cast<Object *>(BKE_id_new(bmain_src, ID_OB, "Ob_src_4"));
Collection *coll_4 = BKE_id_new<Collection>(bmain_src, "Coll_src");
Object *ob_4 = BKE_id_new<Object>(bmain_src, "Ob_src_4");
BKE_collection_object_add(bmain_src, coll_4, ob_4);
Library *lib_src_4 = static_cast<Library *>(BKE_id_new(bmain_src, ID_LI, DST_PATH));
Library *lib_src_4 = BKE_id_new<Library>(bmain_src, DST_PATH);
BKE_library_filepath_set(bmain_src, lib_src_4, DST_PATH);
coll_4->id.lib = lib_src_4;
ob_4->id.lib = lib_src_4;

View File

@@ -304,7 +304,7 @@ Material *BKE_material_add(Main *bmain, const char *name)
{
Material *ma;
ma = static_cast<Material *>(BKE_id_new(bmain, ID_MA, name));
ma = BKE_id_new<Material>(bmain, name);
return ma;
}

View File

@@ -177,7 +177,7 @@ IDTypeInfo IDType_ID_MB = {
MetaBall *BKE_mball_add(Main *bmain, const char *name)
{
MetaBall *mb = static_cast<MetaBall *>(BKE_id_new(bmain, ID_MB, name));
MetaBall *mb = BKE_id_new<MetaBall>(bmain, name);
return mb;
}

View File

@@ -678,7 +678,7 @@ static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata)
Mesh *BKE_mesh_add(Main *bmain, const char *name)
{
return static_cast<Mesh *>(BKE_id_new(bmain, ID_ME, name));
return BKE_id_new<Mesh>(bmain, name);
}
void BKE_mesh_face_offsets_ensure_alloc(Mesh *mesh)

View File

@@ -914,7 +914,7 @@ static MovieClip *movieclip_alloc(Main *bmain, const char *name)
{
MovieClip *clip;
clip = static_cast<MovieClip *>(BKE_id_new(bmain, ID_MC, name));
clip = BKE_id_new<MovieClip>(bmain, name);
return clip;
}

View File

@@ -1319,7 +1319,7 @@ std::optional<int> BKE_paint_get_brush_type_from_paintmode(const Brush *brush,
PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name)
{
PaintCurve *pc = static_cast<PaintCurve *>(BKE_id_new(bmain, ID_PC, name));
PaintCurve *pc = BKE_id_new<PaintCurve>(bmain, name);
return pc;
}
@@ -1366,7 +1366,7 @@ void BKE_palette_clear(Palette *palette)
Palette *BKE_palette_add(Main *bmain, const char *name)
{
Palette *palette = static_cast<Palette *>(BKE_id_new(bmain, ID_PAL, name));
Palette *palette = BKE_id_new<Palette>(bmain, name);
return palette;
}

View File

@@ -4087,7 +4087,7 @@ ParticleSettings *BKE_particlesettings_add(Main *bmain, const char *name)
{
ParticleSettings *part;
part = static_cast<ParticleSettings *>(BKE_id_new(bmain, ID_PA, name));
part = BKE_id_new<ParticleSettings>(bmain, name);
return part;
}

View File

@@ -277,14 +277,14 @@ MutableSpan<float> PointCloud::radius_for_write()
PointCloud *BKE_pointcloud_add(Main *bmain, const char *name)
{
PointCloud *pointcloud = static_cast<PointCloud *>(BKE_id_new(bmain, ID_PT, name));
PointCloud *pointcloud = BKE_id_new<PointCloud>(bmain, name);
return pointcloud;
}
PointCloud *BKE_pointcloud_add_default(Main *bmain, const char *name)
{
PointCloud *pointcloud = static_cast<PointCloud *>(BKE_id_new(bmain, ID_PT, name));
PointCloud *pointcloud = BKE_id_new<PointCloud>(bmain, name);
pointcloud_random(pointcloud);

View File

@@ -1928,7 +1928,7 @@ bool BKE_scene_can_be_removed(const Main *bmain, const Scene *scene)
Scene *BKE_scene_add(Main *bmain, const char *name)
{
Scene *sce = static_cast<Scene *>(BKE_id_new(bmain, ID_SCE, name));
Scene *sce = BKE_id_new<Scene>(bmain, name);
id_us_min(&sce->id);
id_us_ensure_real(&sce->id);

View File

@@ -82,7 +82,7 @@ Speaker *BKE_speaker_add(Main *bmain, const char *name)
{
Speaker *spk;
spk = static_cast<Speaker *>(BKE_id_new(bmain, ID_SPK, name));
spk = BKE_id_new<Speaker>(bmain, name);
return spk;
}

View File

@@ -281,7 +281,7 @@ Text *BKE_text_add(Main *bmain, const char *name)
{
Text *ta;
ta = static_cast<Text *>(BKE_id_new(bmain, ID_TXT, name));
ta = BKE_id_new<Text>(bmain, name);
/* Texts have no users by default... Set the fake user flag to ensure that this text block
* doesn't get deleted by default when cleaning up data blocks. */
id_us_min(&ta->id);

View File

@@ -375,7 +375,7 @@ Tex *BKE_texture_add(Main *bmain, const char *name)
{
Tex *tex;
tex = static_cast<Tex *>(BKE_id_new(bmain, ID_TE, name));
tex = BKE_id_new<Tex>(bmain, name);
return tex;
}

View File

@@ -317,7 +317,7 @@ void BKE_volume_init_grids(Volume *volume)
Volume *BKE_volume_add(Main *bmain, const char *name)
{
Volume *volume = (Volume *)BKE_id_new(bmain, ID_VO, name);
Volume *volume = BKE_id_new<Volume>(bmain, name);
return volume;
}

View File

@@ -40,7 +40,7 @@ class VolumeTest : public ::testing::Test {
TEST_F(VolumeTest, add_grid_with_name_and_find)
{
Volume *volume = static_cast<Volume *>(BKE_id_new(bmain, ID_VO, nullptr));
Volume *volume = BKE_id_new<Volume>(bmain, nullptr);
GVolumeGrid grid{VOLUME_GRID_FLOAT};
grid.get_for_write().set_name("My Grid");
const VolumeGridData *grid_data = grid.release();
@@ -52,8 +52,8 @@ TEST_F(VolumeTest, add_grid_with_name_and_find)
TEST_F(VolumeTest, add_grid_in_two_volumes)
{
Volume *volume_a = static_cast<Volume *>(BKE_id_new(bmain, ID_VO, nullptr));
Volume *volume_b = static_cast<Volume *>(BKE_id_new(bmain, ID_VO, nullptr));
Volume *volume_a = BKE_id_new<Volume>(bmain, nullptr);
Volume *volume_b = BKE_id_new<Volume>(bmain, nullptr);
GVolumeGrid grid{VOLUME_GRID_FLOAT};
grid.get_for_write().set_name("My Grid");
const VolumeGridData *grid_data = grid.release();

View File

@@ -316,7 +316,7 @@ static bool UNUSED_FUNCTION(workspaces_is_screen_used)
WorkSpace *BKE_workspace_add(Main *bmain, const char *name)
{
WorkSpace *new_workspace = static_cast<WorkSpace *>(BKE_id_new(bmain, ID_WS, name));
WorkSpace *new_workspace = BKE_id_new<WorkSpace>(bmain, name);
id_us_ensure_real(&new_workspace->id);
return new_workspace;
}

View File

@@ -211,7 +211,7 @@ World *BKE_world_add(Main *bmain, const char *name)
{
World *wrld;
wrld = static_cast<World *>(BKE_id_new(bmain, ID_WO, name));
wrld = BKE_id_new<World>(bmain, name);
return wrld;
}

View File

@@ -543,8 +543,7 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab
/* Add library data-block itself to 'main' Main, since libraries are **never** linked data.
* Fixes bug where you could end with all ID_LI data-blocks having the same name... */
lib = static_cast<Library *>(
BKE_id_new(static_cast<Main *>(mainlist->first), ID_LI, BLI_path_basename(filepath)));
lib = BKE_id_new<Library>(static_cast<Main *>(mainlist->first), BLI_path_basename(filepath));
/* Important, consistency with main ID reading code from read_libblock(). */
lib->id.us = ID_FAKE_USERS(lib);

View File

@@ -77,7 +77,7 @@ void BlendfileLoadingBaseTest::SetUpTestCase()
/* Allocate a dummy window manager. The real window manager will try and load Python scripts from
* the release directory, which it won't be able to find. */
ASSERT_EQ(G.main->wm.first, nullptr);
wmWindowManager *wm = static_cast<wmWindowManager *>(BKE_id_new(G.main, ID_WM, "WMdummy"));
wmWindowManager *wm = BKE_id_new<wmWindowManager>(G.main, "WMdummy");
wm->runtime = MEM_new<blender::bke::WindowManagerRuntime>(__func__);
}

View File

@@ -51,7 +51,7 @@ class ActionFilterTest : public testing::Test {
bmain = BKE_main_new();
G_MAIN = bmain; /* For BKE_animdata_free(). */
action = &static_cast<bAction *>(BKE_id_new(bmain, ID_AC, "ACÄnimåtië"))->wrap();
action = &BKE_id_new<bAction>(bmain, "ACÄnimåtië")->wrap();
cube = BKE_object_add_only_object(bmain, OB_EMPTY, "Küüübus");
suzanne = BKE_object_add_only_object(bmain, OB_EMPTY, "OBSuzanne");
}

View File

@@ -186,7 +186,7 @@ class KeylistSummaryTest : public testing::Test {
bmain = BKE_main_new();
G_MAIN = bmain; /* For BKE_animdata_free(). */
action = &static_cast<bAction *>(BKE_id_new(bmain, ID_AC, "ACÄnimåtië"))->wrap();
action = &BKE_id_new<bAction>(bmain, "ACÄnimåtië")->wrap();
cube = BKE_object_add_only_object(bmain, OB_EMPTY, "Küüübus");
armature_data = BKE_armature_add(bmain, "ARArmature");

View File

@@ -27,7 +27,7 @@ struct GreasePencilIDTestContext {
{
BKE_idtype_init();
this->bmain = BKE_main_new();
this->grease_pencil = static_cast<GreasePencil *>(BKE_id_new(this->bmain, ID_GP, "GP"));
this->grease_pencil = BKE_id_new<GreasePencil>(this->bmain, "GP");
}
~GreasePencilIDTestContext()
{

View File

@@ -2953,7 +2953,7 @@ static Object *convert_curves_component_to_curves(Base &base,
newob = get_object_for_conversion(base, info, r_new_base);
const Curves *curves_eval = geometry.get_curves();
Curves *new_curves = static_cast<Curves *>(BKE_id_new(info.bmain, ID_CV, newob->id.name + 2));
Curves *new_curves = BKE_id_new<Curves>(info.bmain, newob->id.name + 2);
newob->data = new_curves;
newob->type = OB_CURVES;
@@ -2990,7 +2990,7 @@ static Object *convert_grease_pencil_component_to_curves(Base &base,
if (geometry.has_grease_pencil()) {
newob = get_object_for_conversion(base, info, r_new_base);
Curves *new_curves = static_cast<Curves *>(BKE_id_new(info.bmain, ID_CV, newob->id.name + 2));
Curves *new_curves = BKE_id_new<Curves>(info.bmain, newob->id.name + 2);
newob->data = new_curves;
newob->type = OB_CURVES;
@@ -3370,7 +3370,7 @@ static Object *convert_curves_to_mesh(Base &base, ObjectConversionInfo &info, Ba
if (mesh_eval || curves_eval) {
newob = get_object_for_conversion(base, info, r_new_base);
new_mesh = static_cast<Mesh *>(BKE_id_new(info.bmain, ID_ME, newob->id.name + 2));
new_mesh = BKE_id_new<Mesh>(info.bmain, newob->id.name + 2);
newob->data = new_mesh;
newob->type = OB_MESH;
}
@@ -3422,8 +3422,7 @@ static Object *convert_curves_to_grease_pencil(Base &base,
if (grease_pencil_eval || curves_eval) {
newob = get_object_for_conversion(base, info, r_new_base);
new_grease_pencil = static_cast<GreasePencil *>(
BKE_id_new(info.bmain, ID_GP, newob->id.name + 2));
new_grease_pencil = BKE_id_new<GreasePencil>(info.bmain, newob->id.name + 2);
newob->data = new_grease_pencil;
newob->type = OB_GREASE_PENCIL;
}
@@ -3497,7 +3496,7 @@ static Object *convert_grease_pencil_to_mesh(Base &base,
newob = get_object_for_conversion(base, info, r_new_base);
const Curves *curves_eval = geometry.get_curves();
Curves *new_curves = static_cast<Curves *>(BKE_id_new(info.bmain, ID_CV, newob->id.name + 2));
Curves *new_curves = BKE_id_new<Curves>(info.bmain, newob->id.name + 2);
newob->data = new_curves;
newob->type = OB_CURVES;
@@ -3547,7 +3546,7 @@ static Object *convert_grease_pencil_to_mesh(Base &base,
}
}
Mesh *new_mesh = static_cast<Mesh *>(BKE_id_new(info.bmain, ID_ME, newob->id.name + 2));
Mesh *new_mesh = BKE_id_new<Mesh>(info.bmain, newob->id.name + 2);
newob->data = new_mesh;
newob->type = OB_MESH;

View File

@@ -194,7 +194,7 @@ class GeometryToObjectsBuilder {
const StringRefNull name)
{
return new_object_by_generated_geometry_.lookup_or_add_cb(&src_mesh.id, [&]() {
Mesh *new_mesh = reinterpret_cast<Mesh *>(BKE_id_new(&bmain_, ID_ME, name.c_str()));
Mesh *new_mesh = BKE_id_new<Mesh>(&bmain_, name.c_str());
Object *new_ob = BKE_object_add_only_object(&bmain_, OB_MESH, name.c_str());
new_ob->data = new_mesh;
@@ -212,7 +212,7 @@ class GeometryToObjectsBuilder {
const StringRefNull name)
{
return new_object_by_generated_geometry_.lookup_or_add_cb(&src_curves.id, [&]() {
Curves *new_curves = reinterpret_cast<Curves *>(BKE_id_new(&bmain_, ID_CV, name.c_str()));
Curves *new_curves = BKE_id_new<Curves>(&bmain_, name.c_str());
Object *new_ob = BKE_object_add_only_object(&bmain_, OB_CURVES, name.c_str());
new_ob->data = new_curves;
@@ -228,8 +228,7 @@ class GeometryToObjectsBuilder {
const StringRefNull name)
{
return new_object_by_generated_geometry_.lookup_or_add_cb(&src_pointcloud.id, [&]() {
PointCloud *new_pointcloud = reinterpret_cast<PointCloud *>(
BKE_id_new(&bmain_, ID_PT, name.c_str()));
PointCloud *new_pointcloud = BKE_id_new<PointCloud>(&bmain_, name.c_str());
Object *new_ob = BKE_object_add_only_object(&bmain_, OB_POINTCLOUD, name.c_str());
new_ob->data = new_pointcloud;
@@ -247,8 +246,7 @@ class GeometryToObjectsBuilder {
const StringRefNull name)
{
return new_object_by_generated_geometry_.lookup_or_add_cb(&src_grease_pencil.id, [&]() {
GreasePencil *new_grease_pencil = reinterpret_cast<GreasePencil *>(
BKE_id_new(&bmain_, ID_GP, name.c_str()));
GreasePencil *new_grease_pencil = BKE_id_new<GreasePencil>(&bmain_, name.c_str());
Object *new_ob = BKE_object_add_only_object(&bmain_, OB_GREASE_PENCIL, name.c_str());
new_ob->data = new_grease_pencil;