From 0cdd429b44ce3147bc8bd12bfdff33665b0d43ec Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 26 Mar 2024 15:39:34 -0400 Subject: [PATCH] Cleanup: Use newer API for creating IDProperties in most places There are still a few places that are more complicated where the replacement to `IDP_New` isn't obvious, but this commit replaces most uses of the ugly `IDPropertyTemplate` usage. --- source/blender/blenkernel/intern/action.cc | 8 +- source/blender/blenkernel/intern/asset.cc | 4 +- source/blender/blenkernel/intern/camera.cc | 17 +-- source/blender/blenkernel/intern/idprop.cc | 5 +- source/blender/blenkernel/intern/keyconfig.cc | 8 +- source/blender/blenkernel/intern/object.cc | 14 +-- .../blenloader/intern/versioning_300.cc | 6 +- .../blenloader/intern/versioning_common.cc | 7 +- source/blender/editors/interface/interface.cc | 39 ++----- .../interface/interface_context_menu.cc | 18 ++- .../editors/interface/interface_layout.cc | 3 +- .../editors/interface/interface_templates.cc | 3 +- .../editors/sculpt_paint/paint_image_proj.cc | 29 ++--- source/blender/imbuf/intern/metadata.cc | 5 +- source/blender/io/collada/collada_utils.cpp | 24 +--- source/blender/makesrna/intern/rna_access.cc | 107 +++++------------- source/blender/makesrna/intern/rna_userdef.cc | 4 +- .../makesrna/intern/rna_wm_gizmo_api.cc | 6 +- source/blender/modifiers/intern/MOD_nodes.cc | 5 +- .../nodes/intern/geometry_nodes_execute.cc | 5 +- .../blender/python/generic/idprop_py_api.cc | 24 ++-- .../windowmanager/gizmo/intern/wm_gizmo.cc | 9 +- .../windowmanager/intern/wm_event_system.cc | 3 +- .../windowmanager/intern/wm_operators.cc | 13 +-- .../windowmanager/intern/wm_toolsystem.cc | 9 +- 25 files changed, 121 insertions(+), 254 deletions(-) diff --git a/source/blender/blenkernel/intern/action.cc b/source/blender/blenkernel/intern/action.cc index 6ef2b3a7537..c191b024f32 100644 --- a/source/blender/blenkernel/intern/action.cc +++ b/source/blender/blenkernel/intern/action.cc @@ -247,13 +247,9 @@ static void action_blend_read_data(BlendDataReader *reader, ID *id) static IDProperty *action_asset_type_property(const bAction *action) { + using namespace blender; const bool is_single_frame = BKE_action_has_single_frame(action); - - IDPropertyTemplate idprop = {0}; - idprop.i = is_single_frame; - - IDProperty *property = IDP_New(IDP_INT, &idprop, "is_single_frame"); - return property; + return bke::idprop::create("is_single_frame", int(is_single_frame)).release(); } static void action_asset_metadata_ensure(void *asset_ptr, AssetMetaData *asset_data) diff --git a/source/blender/blenkernel/intern/asset.cc b/source/blender/blenkernel/intern/asset.cc index 8ca0e761152..0cf2694fd22 100644 --- a/source/blender/blenkernel/intern/asset.cc +++ b/source/blender/blenkernel/intern/asset.cc @@ -155,9 +155,9 @@ void BKE_asset_metadata_catalog_id_set(AssetMetaData *asset_data, void BKE_asset_metadata_idprop_ensure(AssetMetaData *asset_data, IDProperty *prop) { + using namespace blender::bke; if (!asset_data->properties) { - IDPropertyTemplate val = {0}; - asset_data->properties = IDP_New(IDP_GROUP, &val, "AssetMetaData.properties"); + asset_data->properties = idprop::create_group("AssetMetaData.properties").release(); } /* Important: The property may already exist. For now just allow always allow a newly allocated * property, and replace the existing one as a way of updating. */ diff --git a/source/blender/blenkernel/intern/camera.cc b/source/blender/blenkernel/intern/camera.cc index ea984dcc965..fa49111e809 100644 --- a/source/blender/blenkernel/intern/camera.cc +++ b/source/blender/blenkernel/intern/camera.cc @@ -124,33 +124,26 @@ static CameraCyclesCompatibilityData camera_write_cycles_compatibility_data_crea if (prop) { return prop; } - IDPropertyTemplate val = {0}; - prop = IDP_New(IDP_GROUP, &val, "cycles"); + prop = blender::bke::idprop::create_group("cycles").release(); IDP_AddToGroup(group, prop); return prop; }; auto cycles_property_int_set = [](IDProperty *idprop, const char *name, int value) { - IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_INT); - if (prop) { + if (IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_INT)) { IDP_Int(prop) = value; } else { - IDPropertyTemplate val = {0}; - val.i = value; - IDP_AddToGroup(idprop, IDP_New(IDP_INT, &val, name)); + IDP_AddToGroup(idprop, blender::bke::idprop::create(name, value).release()); } }; auto cycles_property_float_set = [](IDProperty *idprop, const char *name, float value) { - IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_FLOAT); - if (prop) { + if (IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_FLOAT)) { IDP_Float(prop) = value; } else { - IDPropertyTemplate val = {0}; - val.f = value; - IDP_AddToGroup(idprop, IDP_New(IDP_FLOAT, &val, name)); + IDP_AddToGroup(idprop, blender::bke::idprop::create(name, value).release()); } }; diff --git a/source/blender/blenkernel/intern/idprop.cc b/source/blender/blenkernel/intern/idprop.cc index c46ad2ebcef..4b5ccc6a2c0 100644 --- a/source/blender/blenkernel/intern/idprop.cc +++ b/source/blender/blenkernel/intern/idprop.cc @@ -198,11 +198,8 @@ static void idp_resize_group_array(IDProperty *prop, int newlen, void *newarr) if (newlen >= prop->len) { /* bigger */ IDProperty **array = static_cast(newarr); - IDPropertyTemplate val; - for (int a = prop->len; a < newlen; a++) { - val.i = 0; /* silence MSVC warning about uninitialized var when debugging */ - array[a] = IDP_New(IDP_GROUP, &val, "IDP_ResizeArray group"); + array[a] = blender::bke::idprop::create_group("IDP_ResizeArray group").release(); } } else { diff --git a/source/blender/blenkernel/intern/keyconfig.cc b/source/blender/blenkernel/intern/keyconfig.cc index 29946836912..7a3437fb863 100644 --- a/source/blender/blenkernel/intern/keyconfig.cc +++ b/source/blender/blenkernel/intern/keyconfig.cc @@ -42,8 +42,8 @@ wmKeyConfigPref *BKE_keyconfig_pref_ensure(UserDef *userdef, const char *kc_idna BLI_addtail(&userdef->user_keyconfig_prefs, kpt); } if (kpt->prop == nullptr) { - IDPropertyTemplate val = {0}; - kpt->prop = IDP_New(IDP_GROUP, &val, kc_idname); /* name is unimportant. */ + /* name is unimportant. */ + kpt->prop = blender::bke::idprop::create_group(kc_idname).release(); } return kpt; } @@ -115,9 +115,7 @@ void BKE_keyconfig_pref_set_select_mouse(UserDef *userdef, int value, bool overr wmKeyConfigPref *kpt = BKE_keyconfig_pref_ensure(userdef, WM_KEYCONFIG_STR_DEFAULT); IDProperty *idprop = IDP_GetPropertyFromGroup(kpt->prop, "select_mouse"); if (!idprop) { - IDPropertyTemplate tmp{}; - tmp.i = value; - IDP_AddToGroup(kpt->prop, IDP_New(IDP_INT, &tmp, "select_mouse")); + IDP_AddToGroup(kpt->prop, blender::bke::idprop::create("select_mouse", value).release()); } else if (override) { IDP_Int(idprop) = value; diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc index bb148f668c6..03899264a67 100644 --- a/source/blender/blenkernel/intern/object.cc +++ b/source/blender/blenkernel/intern/object.cc @@ -1044,20 +1044,13 @@ static void object_lib_override_apply_post(ID *id_dst, ID *id_src) static IDProperty *object_asset_dimensions_property(Object *ob) { + using namespace blender::bke; float3 dimensions; BKE_object_dimensions_get(ob, dimensions); if (is_zero_v3(dimensions)) { return nullptr; } - - IDPropertyTemplate idprop{}; - idprop.array.len = 3; - idprop.array.type = IDP_FLOAT; - - IDProperty *property = IDP_New(IDP_ARRAY, &idprop, "dimensions"); - memcpy(IDP_Array(property), dimensions, sizeof(dimensions)); - - return property; + return idprop::create("dimensions", Span(&dimensions.x, 3)).release(); } static void object_asset_metadata_ensure(void *asset_ptr, AssetMetaData *asset_data) @@ -1066,8 +1059,7 @@ static void object_asset_metadata_ensure(void *asset_ptr, AssetMetaData *asset_d BLI_assert(GS(ob->id.name) == ID_OB); /* Update dimensions hint for the asset. */ - IDProperty *dimensions_prop = object_asset_dimensions_property(ob); - if (dimensions_prop) { + if (IDProperty *dimensions_prop = object_asset_dimensions_property(ob)) { BKE_asset_metadata_idprop_ensure(asset_data, dimensions_prop); } } diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index c455a9a4c85..dd8255aae7e 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -1561,6 +1561,7 @@ static void do_version_subsurface_methods(bNode *node) static void version_geometry_nodes_add_attribute_input_settings(NodesModifierData *nmd) { + using namespace blender; if (nmd->settings.properties == nullptr) { return; } @@ -1583,14 +1584,13 @@ static void version_geometry_nodes_add_attribute_input_settings(NodesModifierDat char use_attribute_prop_name[MAX_IDPROP_NAME]; SNPRINTF(use_attribute_prop_name, "%s%s", property->name, "_use_attribute"); - IDPropertyTemplate idprop = {0}; - IDProperty *use_attribute_prop = IDP_New(IDP_INT, &idprop, use_attribute_prop_name); + IDProperty *use_attribute_prop = bke::idprop::create(use_attribute_prop_name, 0).release(); IDP_AddToGroup(nmd->settings.properties, use_attribute_prop); char attribute_name_prop_name[MAX_IDPROP_NAME]; SNPRINTF(attribute_name_prop_name, "%s%s", property->name, "_attribute_name"); - IDProperty *attribute_prop = IDP_New(IDP_STRING, &idprop, attribute_name_prop_name); + IDProperty *attribute_prop = bke::idprop::create(attribute_name_prop_name, "").release(); IDP_AddToGroup(nmd->settings.properties, attribute_prop); } } diff --git a/source/blender/blenloader/intern/versioning_common.cc b/source/blender/blenloader/intern/versioning_common.cc index 6bd20514063..4083a347af2 100644 --- a/source/blender/blenloader/intern/versioning_common.cc +++ b/source/blender/blenloader/intern/versioning_common.cc @@ -389,14 +389,11 @@ int version_cycles_property_int(IDProperty *idprop, const char *name, int defaul void version_cycles_property_int_set(IDProperty *idprop, const char *name, int value) { - IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_INT); - if (prop) { + if (IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_INT)) { IDP_Int(prop) = value; } else { - IDPropertyTemplate val = {0}; - val.i = value; - IDP_AddToGroup(idprop, IDP_New(IDP_INT, &val, name)); + IDP_AddToGroup(idprop, blender::bke::idprop::create(name, value).release()); } } diff --git a/source/blender/editors/interface/interface.cc b/source/blender/editors/interface/interface.cc index eaadcfe50f2..0094b4e0541 100644 --- a/source/blender/editors/interface/interface.cc +++ b/source/blender/editors/interface/interface.cc @@ -1258,9 +1258,8 @@ static std::optional ui_but_event_operator_string_from_menu(const b MenuType *mt = UI_but_menutype_get(but); BLI_assert(mt != nullptr); - /* annoying, create a property */ - const IDPropertyTemplate val = {0}; - IDProperty *prop_menu = IDP_New(IDP_GROUP, &val, __func__); /* Dummy, name is unimportant. */ + /* Dummy, name is unimportant. */ + IDProperty *prop_menu = blender::bke::idprop::create_group(__func__).release(); IDP_AddToGroup(prop_menu, IDP_NewStringMaxSize(mt->idname, sizeof(mt->idname), "name")); const std::optional result = WM_key_event_operator_string( @@ -1273,29 +1272,21 @@ static std::optional ui_but_event_operator_string_from_menu(const b static std::optional ui_but_event_operator_string_from_panel(const bContext *C, uiBut *but) { + using namespace blender; /** Nearly exact copy of #ui_but_event_operator_string_from_menu */ PanelType *pt = UI_but_paneltype_get(but); BLI_assert(pt != nullptr); - /* annoying, create a property */ - const IDPropertyTemplate group_val = {0}; - IDProperty *prop_panel = IDP_New( - IDP_GROUP, &group_val, __func__); /* Dummy, name is unimportant. */ + /* Dummy, name is unimportant. */ + IDProperty *prop_panel = bke::idprop::create_group(__func__).release(); IDP_AddToGroup(prop_panel, IDP_NewStringMaxSize(pt->idname, sizeof(pt->idname), "name")); - IDPropertyTemplate space_type_val = {0}; - space_type_val.i = pt->space_type; - IDP_AddToGroup(prop_panel, IDP_New(IDP_INT, &space_type_val, "space_type")); - IDPropertyTemplate region_type_val = {0}; - region_type_val.i = pt->region_type; - IDP_AddToGroup(prop_panel, IDP_New(IDP_INT, ®ion_type_val, "region_type")); + IDP_AddToGroup(prop_panel, bke::idprop::create("space_type", pt->space_type).release()); + IDP_AddToGroup(prop_panel, bke::idprop::create("region_type", pt->region_type).release()); BLI_SCOPED_DEFER([&]() { IDP_FreeProperty(prop_panel); }); for (int i = 0; i < 2; i++) { /* FIXME(@ideasman42): We can't reasonably search all configurations - long term. */ - IDPropertyTemplate val = {0}; - val.i = i; - - IDP_ReplaceInGroup(prop_panel, IDP_New(IDP_INT, &val, "keep_open")); + IDP_ReplaceInGroup(prop_panel, bke::idprop::create("keep_open", i).release()); if (std::optional result = WM_key_event_operator_string( C, "WM_OT_call_panel", WM_OP_INVOKE_REGION_WIN, prop_panel, true)) { @@ -1456,13 +1447,10 @@ static std::optional ui_but_event_property_operator_string(const bC const StringRefNull data_path = data_path_variations[data_path_index]; if (!data_path.is_empty() || (prop_enum_value_ok && prop_enum_value_id)) { /* Create a property to host the "data_path" property we're sending to the operators. */ - IDProperty *prop_path; - - const IDPropertyTemplate group_val = {0}; - prop_path = IDP_New(IDP_GROUP, &group_val, __func__); + IDProperty *prop_path = blender::bke::idprop::create_group(__func__).release(); BLI_SCOPED_DEFER([&]() { IDP_FreeProperty(prop_path); }); if (!data_path.is_empty()) { - IDP_AddToGroup(prop_path, IDP_NewString(data_path.c_str(), "data_path")); + IDP_AddToGroup(prop_path, bke::idprop::create("data_path", data_path).release()); } if (prop_enum_value_ok) { const EnumPropertyItem *item; @@ -1473,13 +1461,10 @@ static std::optional ui_but_event_property_operator_string(const bC IDProperty *prop_value; if (prop_enum_value_is_int) { const int value = item[index].value; - IDPropertyTemplate val = {}; - val.i = value; - prop_value = IDP_New(IDP_INT, &val, prop_enum_value_id); + prop_value = bke::idprop::create(prop_enum_value_id, value).release(); } else { - const char *id = item[index].identifier; - prop_value = IDP_NewString(id, prop_enum_value_id); + prop_value = bke::idprop::create(prop_enum_value_id, item[index].identifier).release(); } IDP_AddToGroup(prop_path, prop_value); } diff --git a/source/blender/editors/interface/interface_context_menu.cc b/source/blender/editors/interface/interface_context_menu.cc index df21e626d65..300e179677e 100644 --- a/source/blender/editors/interface/interface_context_menu.cc +++ b/source/blender/editors/interface/interface_context_menu.cc @@ -58,6 +58,7 @@ static IDProperty *shortcut_property_from_rna(bContext *C, uiBut *but) { + using namespace blender; /* Compute data path from context to property. */ /* If this returns null, we won't be able to bind shortcuts to these RNA properties. @@ -69,15 +70,14 @@ static IDProperty *shortcut_property_from_rna(bContext *C, uiBut *but) } /* Create ID property of data path, to pass to the operator. */ - const IDPropertyTemplate val = {0}; - IDProperty *prop = IDP_New(IDP_GROUP, &val, __func__); - IDP_AddToGroup(prop, IDP_NewString(final_data_path.value().c_str(), "data_path")); - + IDProperty *prop = bke::idprop::create_group(__func__).release(); + IDP_AddToGroup(prop, bke::idprop::create("data_path", final_data_path.value()).release()); return prop; } static const char *shortcut_get_operator_property(bContext *C, uiBut *but, IDProperty **r_prop) { + using namespace blender; if (but->optype) { /* Operator */ *r_prop = (but->opptr && but->opptr->data) ? @@ -108,17 +108,15 @@ static const char *shortcut_get_operator_property(bContext *C, uiBut *but, IDPro } if (MenuType *mt = UI_but_menutype_get(but)) { - const IDPropertyTemplate val = {0}; - IDProperty *prop = IDP_New(IDP_GROUP, &val, __func__); - IDP_AddToGroup(prop, IDP_NewString(mt->idname, "name")); + IDProperty *prop = bke::idprop::create_group(__func__).release(); + IDP_AddToGroup(prop, bke::idprop::create("name", mt->idname).release()); *r_prop = prop; return "WM_OT_call_menu"; } if (PanelType *pt = UI_but_paneltype_get(but)) { - const IDPropertyTemplate val = {0}; - IDProperty *prop = IDP_New(IDP_GROUP, &val, __func__); - IDP_AddToGroup(prop, IDP_NewString(pt->idname, "name")); + IDProperty *prop = blender::bke::idprop::create_group(__func__).release(); + IDP_AddToGroup(prop, bke::idprop::create("name", pt->idname).release()); *r_prop = prop; return "WM_OT_call_panel"; } diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc index 1c9053095bc..65e8aa5173d 100644 --- a/source/blender/editors/interface/interface_layout.cc +++ b/source/blender/editors/interface/interface_layout.cc @@ -1294,8 +1294,7 @@ static uiBut *uiItemFullO_ptr_ex(uiLayout *layout, opptr->data = properties; } else { - const IDPropertyTemplate val = {0}; - opptr->data = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); + opptr->data = blender::bke::idprop::create_group("wmOperatorProperties").release(); } if (r_opptr) { *r_opptr = *opptr; diff --git a/source/blender/editors/interface/interface_templates.cc b/source/blender/editors/interface/interface_templates.cc index 157090e2f24..1ba0ee584e6 100644 --- a/source/blender/editors/interface/interface_templates.cc +++ b/source/blender/editors/interface/interface_templates.cc @@ -2703,8 +2703,7 @@ static eAutoPropButsReturn template_operator_property_buts_draw_single( eAutoPropButsReturn return_info = eAutoPropButsReturn(0); if (!op->properties) { - const IDPropertyTemplate val = {0}; - op->properties = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); + op->properties = blender::bke::idprop::create_group("wmOperatorProperties").release(); } /* poll() on this operator may still fail, diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.cc b/source/blender/editors/sculpt_paint/paint_image_proj.cc index a64140d13dc..0f54bf673e7 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.cc +++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc @@ -6231,6 +6231,7 @@ static bool texture_paint_image_from_view_poll(bContext *C) static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) { + using namespace blender; Image *image; ImBuf *ibuf; char filename[FILE_MAX]; @@ -6313,27 +6314,21 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) if (image) { /* now for the trickiness. store the view projection here! * re-projection will reuse this */ - IDPropertyTemplate val; IDProperty *idgroup = IDP_EnsureProperties(&image->id); - IDProperty *view_data; - bool is_ortho; - float *array; - val.array.len = PROJ_VIEW_DATA_SIZE; - val.array.type = IDP_FLOAT; - view_data = IDP_New(IDP_ARRAY, &val, PROJ_VIEW_DATA_ID); - - array = (float *)IDP_Array(view_data); - memcpy(array, rv3d->winmat, sizeof(rv3d->winmat)); - array += sizeof(rv3d->winmat) / sizeof(float); - memcpy(array, rv3d->viewmat, sizeof(rv3d->viewmat)); - array += sizeof(rv3d->viewmat) / sizeof(float); - is_ortho = ED_view3d_clip_range_get(depsgraph, v3d, rv3d, &array[0], &array[1], true); + blender::Vector array; + array.extend(Span(reinterpret_cast(rv3d->winmat), 16)); + array.extend(Span(reinterpret_cast(rv3d->viewmat), 16)); + float clip_start; + float clip_end; + const bool is_ortho = ED_view3d_clip_range_get( + depsgraph, v3d, rv3d, &clip_start, &clip_end, true); + array.append(clip_start); + array.append(clip_end); /* using float for a bool is dodgy but since its an extra member in the array... * easier than adding a single bool prop */ - array[2] = is_ortho ? 1.0f : 0.0f; - - IDP_AddToGroup(idgroup, view_data); + array.append(is_ortho ? 1.0f : 0.0f); + IDP_AddToGroup(idgroup, bke::idprop::create(PROJ_VIEW_DATA_ID, array.as_span()).release()); } return OPERATOR_FINISHED; diff --git a/source/blender/imbuf/intern/metadata.cc b/source/blender/imbuf/intern/metadata.cc index 7c1e58c9124..5f0e60eb50b 100644 --- a/source/blender/imbuf/intern/metadata.cc +++ b/source/blender/imbuf/intern/metadata.cc @@ -27,8 +27,7 @@ void IMB_metadata_ensure(IDProperty **metadata) return; } - IDPropertyTemplate val = {0}; - *metadata = IDP_New(IDP_GROUP, &val, "metadata"); + *metadata = blender::bke::idprop::create_group("metadata").release(); } void IMB_metadata_free(IDProperty *metadata) @@ -81,7 +80,7 @@ void IMB_metadata_set_field(IDProperty *metadata, const char *key, const char *v IDP_AssignString(prop, value); } else { - prop = IDP_NewString(value, key); + prop = blender::bke::idprop::create(key, value).release(); IDP_AddToGroup(metadata, prop); } } diff --git a/source/blender/io/collada/collada_utils.cpp b/source/blender/io/collada/collada_utils.cpp index 95c42990830..a69d09653d6 100644 --- a/source/blender/io/collada/collada_utils.cpp +++ b/source/blender/io/collada/collada_utils.cpp @@ -652,22 +652,13 @@ void bc_set_IDPropertyMatrix(EditBone *ebone, const char *key, float mat[4][4]) { IDProperty *idgroup = (IDProperty *)ebone->prop; if (idgroup == nullptr) { - IDPropertyTemplate val = {0}; - idgroup = IDP_New(IDP_GROUP, &val, "RNA_EditBone ID properties"); + idgroup = blender::bke::idprop::create_group("RNA_EditBone ID properties").release(); ebone->prop = idgroup; } - IDPropertyTemplate val = {0}; - val.array.len = 16; - val.array.type = IDP_FLOAT; - - IDProperty *data = IDP_New(IDP_ARRAY, &val, key); - float *array = (float *)IDP_Array(data); - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - array[4 * i + j] = mat[i][j]; - } - } + IDProperty *data = blender::bke::idprop::create( + key, blender::Span(reinterpret_cast(mat), 16)) + .release(); IDP_AddToGroup(idgroup, data); } @@ -682,14 +673,11 @@ static void bc_set_IDProperty(EditBone *ebone, const char *key, float value) { if (ebone->prop == nullptr) { IDPropertyTemplate val = {0}; - ebone->prop = IDP_New(IDP_GROUP, &val, "RNA_EditBone ID properties"); + ebone->prop = blender::bke::idprop::create_group( "RNA_EditBone ID properties").release(); } IDProperty *pgroup = (IDProperty *)ebone->prop; - IDPropertyTemplate val = {0}; - IDProperty *prop = IDP_New(IDP_FLOAT, &val, key); - IDP_Float(prop) = value; - IDP_AddToGroup(pgroup, prop); + IDP_AddToGroup(pgroup, blender::bke::idprop::create(key, value).release()); } #endif diff --git a/source/blender/makesrna/intern/rna_access.cc b/source/blender/makesrna/intern/rna_access.cc index 9f7b65de1ef..fba30aadda0 100644 --- a/source/blender/makesrna/intern/rna_access.cc +++ b/source/blender/makesrna/intern/rna_access.cc @@ -281,8 +281,7 @@ IDProperty *RNA_struct_idprops(PointerRNA *ptr, bool create) } if (create && *property_ptr == nullptr) { - IDPropertyTemplate val = {0}; - *property_ptr = IDP_New(IDP_GROUP, &val, __func__); + *property_ptr = blender::bke::idprop::create_group(__func__).release(); } return *property_ptr; @@ -2454,17 +2453,11 @@ void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value) bprop->set_ex(ptr, prop, value); } else if (prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val = {0}; - IDProperty *group; - - val.i = value; - - group = RNA_struct_idprops(ptr, true); - if (group) { + if (IDProperty *group = RNA_struct_idprops(ptr, true)) { #ifdef USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP - IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier)); + IDP_AddToGroup(group, blender::bke::idprop::create(prop->identifier, int(value)).release()); #else - IDP_AddToGroup(group, IDP_New(IDP_BOOLEAN, &val, prop->identifier)); + IDP_AddToGroup(group, blender::bke::idprop::create_bool(prop->identifier, value).release()); #endif } } @@ -2624,7 +2617,6 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bo } else if (prop->flag & PROP_EDITABLE) { IDPropertyTemplate val = {0}; - IDProperty *group; val.array.len = prop->totarraylength; #ifdef USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP @@ -2633,8 +2625,7 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bo val.array.type = IDP_BOOLEAN; #endif - group = RNA_struct_idprops(ptr, true); - if (group) { + if (IDProperty *group = RNA_struct_idprops(ptr, true)) { idprop = IDP_New(IDP_ARRAY, &val, prop->identifier); IDP_AddToGroup(group, idprop); int *values_dst = static_cast(IDP_Array(idprop)); @@ -2825,16 +2816,9 @@ void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value) iprop->set_ex(ptr, prop, value); } else if (prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val = {0}; - IDProperty *group; - RNA_property_int_clamp(ptr, prop, &value); - - val.i = value; - - group = RNA_struct_idprops(ptr, true); - if (group) { - IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier)); + if (IDProperty *group = RNA_struct_idprops(ptr, true)) { + IDP_AddToGroup(group, blender::bke::idprop::create(prop->identifier, value).release()); } } } @@ -2961,6 +2945,7 @@ int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index) void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values) { + using namespace blender; IntPropertyRNA *iprop = (IntPropertyRNA *)prop; IDProperty *idprop; @@ -2989,19 +2974,11 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v iprop->setarray_ex(ptr, prop, values); } else if (prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val = {0}; - IDProperty *group; - // RNA_property_int_clamp_array(ptr, prop, &value); /* TODO. */ - - val.array.len = prop->totarraylength; - val.array.type = IDP_INT; - - group = RNA_struct_idprops(ptr, true); - if (group) { - idprop = IDP_New(IDP_ARRAY, &val, prop->identifier); - IDP_AddToGroup(group, idprop); - memcpy(IDP_Array(idprop), values, sizeof(int) * idprop->len); + if (IDProperty *group = RNA_struct_idprops(ptr, true)) { + IDP_AddToGroup( + group, + bke::idprop::create(prop->identifier, Span(values, prop->totarraylength)).release()); } } } @@ -3172,16 +3149,9 @@ void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value) fprop->set_ex(ptr, prop, value); } else if (prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val = {0}; - IDProperty *group; - RNA_property_float_clamp(ptr, prop, &value); - - val.f = value; - - group = RNA_struct_idprops(ptr, true); - if (group) { - IDP_AddToGroup(group, IDP_New(IDP_FLOAT, &val, prop->identifier)); + if (IDProperty *group = RNA_struct_idprops(ptr, true)) { + IDP_AddToGroup(group, blender::bke::idprop::create(prop->identifier, value).release()); } } } @@ -3373,19 +3343,12 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa fprop->setarray_ex(ptr, prop, values); } else if (prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val = {0}; - IDProperty *group; - // RNA_property_float_clamp_array(ptr, prop, &value); /* TODO. */ - - val.array.len = prop->totarraylength; - val.array.type = IDP_FLOAT; - - group = RNA_struct_idprops(ptr, true); - if (group) { - idprop = IDP_New(IDP_ARRAY, &val, prop->identifier); - IDP_AddToGroup(group, idprop); - memcpy(IDP_Array(idprop), values, sizeof(float) * idprop->len); + if (IDProperty *group = RNA_struct_idprops(ptr, true)) { + IDP_AddToGroup(group, + blender::bke::idprop::create(prop->identifier, + blender::Span(values, prop->totarraylength)) + .release()); } } } @@ -3938,13 +3901,13 @@ void RNA_property_pointer_set(PointerRNA *ptr, } else { BLI_assert(idprop->type == IDP_GROUP); - - IDPropertyTemplate val{}; - val.id = static_cast(ptr_value.data); IDProperty *group = RNA_struct_idprops(ptr, true); BLI_assert(group != nullptr); - IDP_ReplaceInGroup_ex(group, IDP_New(IDP_ID, &val, idprop->name), idprop); + IDP_ReplaceInGroup_ex( + group, + blender::bke::idprop::create(idprop->name, static_cast(ptr_value.data)).release(), + idprop); } } /* RNA property. */ @@ -3957,14 +3920,11 @@ void RNA_property_pointer_set(PointerRNA *ptr, } /* IDProperty disguised as RNA property (and not yet defined in ptr). */ else if (prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val = {0}; - IDProperty *group; - - val.id = static_cast(ptr_value.data); - - group = RNA_struct_idprops(ptr, true); - if (group) { - IDP_ReplaceInGroup(group, IDP_New(IDP_ID, &val, prop->identifier)); + if (IDProperty *group = RNA_struct_idprops(ptr, true)) { + IDP_ReplaceInGroup( + group, + blender::bke::idprop::create(prop->identifier, static_cast(ptr_value.data)) + .release()); } } } @@ -3988,14 +3948,11 @@ void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop) /* already exists */ } else if (prop->flag & PROP_IDPROPERTY) { - IDPropertyTemplate val = {0}; IDProperty *group; - val.i = 0; - group = RNA_struct_idprops(ptr, true); if (group) { - IDP_AddToGroup(group, IDP_New(IDP_GROUP, &val, prop->identifier)); + IDP_AddToGroup(group, blender::bke::idprop::create_group(prop->identifier).release()); } } else { @@ -4212,10 +4169,9 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA } if ((idprop = rna_idproperty_check(&prop, ptr))) { - IDPropertyTemplate val = {0}; IDProperty *item; - item = IDP_New(IDP_GROUP, &val, ""); + item = blender::bke::idprop::create_group("").release(); if (is_liboverride) { item->flag |= IDP_FLAG_OVERRIDELIBRARY_LOCAL; } @@ -4227,14 +4183,13 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA } else if (prop->flag & PROP_IDPROPERTY) { IDProperty *group, *item; - IDPropertyTemplate val = {0}; group = RNA_struct_idprops(ptr, true); if (group) { idprop = IDP_NewIDPArray(prop->identifier); IDP_AddToGroup(group, idprop); - item = IDP_New(IDP_GROUP, &val, ""); + item = blender::bke::idprop::create_group("").release(); if (is_liboverride) { item->flag |= IDP_FLAG_OVERRIDELIBRARY_LOCAL; } diff --git a/source/blender/makesrna/intern/rna_userdef.cc b/source/blender/makesrna/intern/rna_userdef.cc index 5b66b445129..348e7d934e5 100644 --- a/source/blender/makesrna/intern/rna_userdef.cc +++ b/source/blender/makesrna/intern/rna_userdef.cc @@ -1072,8 +1072,8 @@ static PointerRNA rna_Addon_preferences_get(PointerRNA *ptr) bAddonPrefType *apt = BKE_addon_pref_type_find(addon->module, true); if (apt) { if (addon->prop == nullptr) { - IDPropertyTemplate val = {0}; - addon->prop = IDP_New(IDP_GROUP, &val, addon->module); /* name is unimportant. */ + /* name is unimportant. */ + addon->prop = blender::bke::idprop::create_group(addon->module).release(); } return rna_pointer_inherit_refine(ptr, apt->rna_ext.srna, addon->prop); } diff --git a/source/blender/makesrna/intern/rna_wm_gizmo_api.cc b/source/blender/makesrna/intern/rna_wm_gizmo_api.cc index 536608c7dff..67a3f4884af 100644 --- a/source/blender/makesrna/intern/rna_wm_gizmo_api.cc +++ b/source/blender/makesrna/intern/rna_wm_gizmo_api.cc @@ -162,11 +162,7 @@ static PointerRNA rna_gizmo_target_set_operator(wmGizmo *gz, } /* For the return value to be usable, we need 'PointerRNA.data' to be set. */ - IDProperty *properties; - { - IDPropertyTemplate val = {0}; - properties = IDP_New(IDP_GROUP, &val, "wmGizmoProperties"); - } + IDProperty *properties = blender::bke::idprop::create_group("wmGizmoProperties").release(); return *WM_gizmo_operator_set(gz, part_index, ot, properties); } diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index bc904ff8b41..23b0cbb13aa 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -312,10 +312,7 @@ static void update_id_properties_from_node_group(NodesModifierData *nmd) } IDProperty *old_properties = nmd->settings.properties; - { - IDPropertyTemplate idprop = {0}; - nmd->settings.properties = IDP_New(IDP_GROUP, &idprop, "Nodes Modifier Settings"); - } + nmd->settings.properties = bke::idprop::create_group("Nodes Modifier Settings").release(); IDProperty *new_properties = nmd->settings.properties; nodes::update_input_properties_from_node_tree(*nmd->node_group, old_properties, *new_properties); diff --git a/source/blender/nodes/intern/geometry_nodes_execute.cc b/source/blender/nodes/intern/geometry_nodes_execute.cc index e71e9ae4de2..ddf89ba3062 100644 --- a/source/blender/nodes/intern/geometry_nodes_execute.cc +++ b/source/blender/nodes/intern/geometry_nodes_execute.cc @@ -920,11 +920,10 @@ void update_input_properties_from_node_tree(const bNodeTree &tree, const std::string use_attribute_id = socket_identifier + input_use_attribute_suffix(); const std::string attribute_name_id = socket_identifier + input_attribute_name_suffix(); - IDPropertyTemplate idprop = {0}; - IDProperty *use_attribute_prop = IDP_New(IDP_BOOLEAN, &idprop, use_attribute_id.c_str()); + IDProperty *use_attribute_prop = bke::idprop::create_bool(use_attribute_id, false).release(); IDP_AddToGroup(&properties, use_attribute_prop); - IDProperty *attribute_prop = IDP_New(IDP_STRING, &idprop, attribute_name_id.c_str()); + IDProperty *attribute_prop = bke::idprop::create(attribute_name_id, "").release(); IDP_AddToGroup(&properties, attribute_prop); if (old_properties == nullptr) { diff --git a/source/blender/python/generic/idprop_py_api.cc b/source/blender/python/generic/idprop_py_api.cc index 329b2d4ec90..6cded4bf04b 100644 --- a/source/blender/python/generic/idprop_py_api.cc +++ b/source/blender/python/generic/idprop_py_api.cc @@ -409,26 +409,21 @@ static const char *idp_try_read_name(PyObject *name_obj) static IDProperty *idp_from_PyFloat(const char *name, PyObject *ob) { - IDPropertyTemplate val = {0}; - val.d = PyFloat_AsDouble(ob); - return IDP_New(IDP_DOUBLE, &val, name); + return blender::bke::idprop::create(name, PyFloat_AsDouble(ob)).release(); } static IDProperty *idp_from_PyBool(const char *name, PyObject *ob) { - IDPropertyTemplate val = {0}; - val.i = PyC_Long_AsBool(ob); - return IDP_New(IDP_BOOLEAN, &val, name); + return blender::bke::idprop::create(name, int(PyC_Long_AsBool(ob))).release(); } static IDProperty *idp_from_PyLong(const char *name, PyObject *ob) { - IDPropertyTemplate val = {0}; - val.i = PyC_Long_AsI32(ob); - if (val.i == -1 && PyErr_Occurred()) { + const int value = PyC_Long_AsI32(ob); + if (value == -1 && PyErr_Occurred()) { return nullptr; } - return IDP_New(IDP_INT, &val, name); + return blender::bke::idprop::create(name, value).release(); } static IDProperty *idp_from_PyUnicode(const char *name, PyObject *ob) @@ -642,7 +637,6 @@ static IDProperty *idp_from_PySequence(const char *name, PyObject *ob) static IDProperty *idp_from_PyMapping(const char *name, PyObject *ob) { IDProperty *prop; - const IDPropertyTemplate val = {0}; PyObject *keys, *vals, *key, *pval; int i, len; @@ -652,7 +646,7 @@ static IDProperty *idp_from_PyMapping(const char *name, PyObject *ob) /* We allocate the group first; if we hit any invalid data, * we can delete it easily enough. */ - prop = IDP_New(IDP_GROUP, &val, name); + prop = blender::bke::idprop::create_group(name).release(); len = PyMapping_Length(ob); for (i = 0; i < len; i++) { key = PySequence_GetItem(keys, i); @@ -676,9 +670,9 @@ static IDProperty *idp_from_PyMapping(const char *name, PyObject *ob) static IDProperty *idp_from_DatablockPointer(const char *name, PyObject *ob) { - IDPropertyTemplate val = {0}; - pyrna_id_FromPyObject(ob, &val.id); - return IDP_New(IDP_ID, &val, name); + ID *id = nullptr; + pyrna_id_FromPyObject(ob, &id); + return blender::bke::idprop::create(name, id).release(); } static IDProperty *idp_from_PyObject(PyObject *name_obj, PyObject *ob) diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo.cc b/source/blender/windowmanager/gizmo/intern/wm_gizmo.cc index 31def638da5..87268350473 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo.cc +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo.cc @@ -58,8 +58,7 @@ static wmGizmo *wm_gizmo_create(const wmGizmoType *gzt, PointerRNA *properties) gz->properties = IDP_CopyProperty(static_cast(properties->data)); } else { - IDPropertyTemplate val = {0}; - gz->properties = IDP_New(IDP_GROUP, &val, "wmGizmoProperties"); + gz->properties = blender::bke::idprop::create_group("wmGizmoProperties").release(); } *gz->ptr = RNA_pointer_create(static_cast(G_MAIN->wm.first), gzt->srna, gz->properties); @@ -231,8 +230,7 @@ int WM_gizmo_operator_invoke(bContext *C, wmGizmo *gz, wmGizmoOpElem *gzop, cons bToolRef *tref = WM_toolsystem_ref_from_context(C); if (tref && WM_toolsystem_ref_properties_get_from_operator(tref, gzop->type, &tref_ptr)) { if (gzop->ptr.data == nullptr) { - IDPropertyTemplate val = {0}; - gzop->ptr.data = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); + gzop->ptr.data = blender::bke::idprop::create_group("wmOperatorProperties").release(); } IDP_MergeGroup(static_cast(gzop->ptr.data), static_cast(tref_ptr.data), @@ -603,8 +601,7 @@ void WM_gizmo_properties_create(PointerRNA *ptr, const char *gtstring) void WM_gizmo_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *gtstring) { if (*properties == nullptr) { - IDPropertyTemplate val = {0}; - *properties = IDP_New(IDP_GROUP, &val, "wmOpItemProp"); + *properties = blender::bke::idprop::create_group("wmOpItemProp").release(); } if (*ptr == nullptr) { diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index 7d963daea93..590f12f59ce 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -1376,8 +1376,7 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, op->properties = IDP_CopyProperty(static_cast(properties->data)); } else { - IDPropertyTemplate val = {0}; - op->properties = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); + op->properties = blender::bke::idprop::create_group("wmOperatorProperties").release(); } *op->ptr = RNA_pointer_create(&wm->id, ot->srna, op->properties); diff --git a/source/blender/windowmanager/intern/wm_operators.cc b/source/blender/windowmanager/intern/wm_operators.cc index 9a5ee189293..40a04cbdadc 100644 --- a/source/blender/windowmanager/intern/wm_operators.cc +++ b/source/blender/windowmanager/intern/wm_operators.cc @@ -710,8 +710,7 @@ void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, con } if (*properties == nullptr) { - IDPropertyTemplate val = {0}; - *properties = IDP_New(IDP_GROUP, &val, "wmOpItemProp"); + *properties = blender::bke::idprop::create_group("wmOpItemProp").release(); } if (*ptr == nullptr) { @@ -825,8 +824,7 @@ void WM_operator_properties_free(PointerRNA *ptr) static bool operator_last_properties_init_impl(wmOperator *op, IDProperty *last_properties) { bool changed = false; - IDPropertyTemplate val = {0}; - IDProperty *replaceprops = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); + IDProperty *replaceprops = blender::bke::idprop::create_group("wmOperatorProperties").release(); PropertyRNA *iterprop = RNA_struct_iterator_property(op->type->srna); @@ -894,8 +892,8 @@ bool WM_operator_last_properties_store(wmOperator *op) LISTBASE_FOREACH (wmOperator *, opm, &op->macro) { if (opm->properties) { if (op->type->last_properties == nullptr) { - IDPropertyTemplate temp{}; - op->type->last_properties = IDP_New(IDP_GROUP, &temp, "wmOperatorProperties"); + op->type->last_properties = + blender::bke::idprop::create_group("wmOperatorProperties").release(); } IDProperty *idp_macro = IDP_CopyProperty(opm->properties); STRNCPY(idp_macro->name, opm->type->idname); @@ -1262,8 +1260,7 @@ wmOperator *WM_operator_last_redo(const bContext *C) IDProperty *WM_operator_last_properties_ensure_idprops(wmOperatorType *ot) { if (ot->last_properties == nullptr) { - IDPropertyTemplate val = {0}; - ot->last_properties = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); + ot->last_properties = blender::bke::idprop::create_group("wmOperatorProperties").release(); } return ot->last_properties; } diff --git a/source/blender/windowmanager/intern/wm_toolsystem.cc b/source/blender/windowmanager/intern/wm_toolsystem.cc index 153e3d39ba2..937e22e25f9 100644 --- a/source/blender/windowmanager/intern/wm_toolsystem.cc +++ b/source/blender/windowmanager/intern/wm_toolsystem.cc @@ -869,8 +869,7 @@ static IDProperty *idprops_ensure_named_group(IDProperty *group, const char *idn { IDProperty *prop = IDP_GetPropertyFromGroup(group, idname); if ((prop == nullptr) || (prop->type != IDP_GROUP)) { - IDPropertyTemplate val = {0}; - prop = IDP_New(IDP_GROUP, &val, __func__); + prop = blender::bke::idprop::create_group(__func__).release(); STRNCPY(prop->name, idname); IDP_ReplaceInGroup_ex(group, prop, nullptr); } @@ -889,8 +888,7 @@ IDProperty *WM_toolsystem_ref_properties_get_idprops(bToolRef *tref) IDProperty *WM_toolsystem_ref_properties_ensure_idprops(bToolRef *tref) { if (tref->properties == nullptr) { - IDPropertyTemplate val = {0}; - tref->properties = IDP_New(IDP_GROUP, &val, __func__); + tref->properties = blender::bke::idprop::create_group(__func__).release(); } return idprops_ensure_named_group(tref->properties, tref->idname); } @@ -926,8 +924,7 @@ void WM_toolsystem_ref_properties_init_for_keymap(bToolRef *tref, dst_ptr->data = IDP_CopyProperty(static_cast(dst_ptr->data)); } else { - IDPropertyTemplate val = {0}; - dst_ptr->data = IDP_New(IDP_GROUP, &val, "wmOpItemProp"); + dst_ptr->data = blender::bke::idprop::create_group("wmOpItemProp").release(); } IDProperty *group = WM_toolsystem_ref_properties_get_idprops(tref); if (group != nullptr) {