diff options
author | Hans Goudey <h.goudey@me.com> | 2021-07-14 23:07:36 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-07-14 23:07:36 +0300 |
commit | dc0c71d3ae772c9afdec0718ae135b9b91f57e8b (patch) | |
tree | 3c89c71d0a33ecb3a3b4abfb67641051e34608f7 /source/blender/makesrna/intern | |
parent | d7a74a2ad69914602f563852610efff3e8ed6e1c (diff) | |
parent | 093074aefe87259882b56a911d8eeb311408ff14 (diff) |
Merge branch 'master' into temp-geometry-nodes-curve-sample
Diffstat (limited to 'source/blender/makesrna/intern')
22 files changed, 227 insertions, 186 deletions
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 499b5538ad8..38b00afdc8f 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -493,9 +493,10 @@ StructRNA *rna_ID_refine(PointerRNA *ptr) return ID_code_to_RNA_type(GS(id->name)); } -IDProperty *rna_ID_idprops(PointerRNA *ptr, bool create) +IDProperty **rna_ID_idprops(PointerRNA *ptr) { - return IDP_GetProperties(ptr->data, create); + ID *id = (ID *)ptr->data; + return &id->properties; } void rna_ID_fake_user_set(PointerRNA *ptr, bool value) @@ -510,9 +511,9 @@ void rna_ID_fake_user_set(PointerRNA *ptr, bool value) } } -IDProperty *rna_PropertyGroup_idprops(PointerRNA *ptr, bool UNUSED(create)) +IDProperty **rna_PropertyGroup_idprops(PointerRNA *ptr) { - return ptr->data; + return (IDProperty **)&ptr->data; } void rna_PropertyGroup_unregister(Main *UNUSED(bmain), StructRNA *type) @@ -772,7 +773,7 @@ static struct ID *rna_ID_make_local(struct ID *self, Main *bmain, bool clear_pro static AnimData *rna_ID_animation_data_create(ID *id, Main *bmain) { - AnimData *adt = BKE_animdata_add_id(id); + AnimData *adt = BKE_animdata_ensure_id(id); DEG_relations_tag_update(bmain); return adt; } @@ -1162,12 +1163,12 @@ static PointerRNA rna_IDPreview_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_ImagePreview, prv_img); } -static IDProperty *rna_IDPropertyWrapPtr_idprops(PointerRNA *ptr, bool UNUSED(create)) +static IDProperty **rna_IDPropertyWrapPtr_idprops(PointerRNA *ptr) { if (ptr == NULL) { return NULL; } - return ptr->data; + return (IDProperty **)&ptr->data; } static void rna_Library_version_get(PointerRNA *ptr, int *value) diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index a0a84bf4fc9..eb347987f87 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -369,15 +369,32 @@ static bool rna_idproperty_ui_set_default(PointerRNA *ptr, return true; } -IDProperty *RNA_struct_idprops(PointerRNA *ptr, bool create) +IDProperty **RNA_struct_idprops_p(PointerRNA *ptr) { StructRNA *type = ptr->type; + if (type == NULL) { + return NULL; + } + if (type->idproperties == NULL) { + return NULL; + } - if (type && type->idproperties) { - return type->idproperties(ptr, create); + return type->idproperties(ptr); +} + +IDProperty *RNA_struct_idprops(PointerRNA *ptr, bool create) +{ + IDProperty **property_ptr = RNA_struct_idprops_p(ptr); + if (property_ptr == NULL) { + return NULL; } - return NULL; + if (create && *property_ptr == NULL) { + IDPropertyTemplate val = {0}; + *property_ptr = IDP_New(IDP_GROUP, &val, __func__); + } + + return *property_ptr; } bool RNA_struct_idprops_check(StructRNA *srna) @@ -2026,11 +2043,9 @@ bool RNA_property_enum_item_from_value( bool RNA_property_enum_item_from_value_gettexted( bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item) { - bool result; + const bool result = RNA_property_enum_item_from_value(C, ptr, prop, value, r_item); - result = RNA_property_enum_item_from_value(C, ptr, prop, value, r_item); - - if (!(prop->flag & PROP_ENUM_NO_TRANSLATE)) { + if (result && !(prop->flag & PROP_ENUM_NO_TRANSLATE)) { if (BLT_translate_iface()) { r_item->name = BLT_pgettext(prop->translation_context, r_item->name); } diff --git a/source/blender/makesrna/intern/rna_access_compare_override.c b/source/blender/makesrna/intern/rna_access_compare_override.c index 816fc68195f..c4d35140423 100644 --- a/source/blender/makesrna/intern/rna_access_compare_override.c +++ b/source/blender/makesrna/intern/rna_access_compare_override.c @@ -422,7 +422,9 @@ static int rna_property_override_diff(Main *bmain, bool override_changed = false; eRNAOverrideMatch diff_flags = flags; - if (!RNA_property_overridable_get(&prop_a->ptr, prop_a->rawprop)) { + if (!RNA_property_overridable_get(&prop_a->ptr, prop_a->rawprop) || + (!ELEM(RNA_property_type(prop_a->rawprop), PROP_POINTER, PROP_COLLECTION) && + !RNA_property_editable_flag(&prop_a->ptr, prop_a->rawprop))) { diff_flags &= ~RNA_OVERRIDE_COMPARE_CREATE; } const int diff = override_diff(bmain, diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 7114e21beff..49d02524e43 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -260,28 +260,16 @@ static char *rna_Bone_path(PointerRNA *ptr) return BLI_sprintfN("bones[\"%s\"]", name_esc); } -static IDProperty *rna_Bone_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_Bone_idprops(PointerRNA *ptr) { Bone *bone = ptr->data; - - if (create && !bone->prop) { - IDPropertyTemplate val = {0}; - bone->prop = IDP_New(IDP_GROUP, &val, "RNA_Bone ID properties"); - } - - return bone->prop; + return &bone->prop; } -static IDProperty *rna_EditBone_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_EditBone_idprops(PointerRNA *ptr) { EditBone *ebone = ptr->data; - - if (create && !ebone->prop) { - IDPropertyTemplate val = {0}; - ebone->prop = IDP_New(IDP_GROUP, &val, "RNA_EditBone ID properties"); - } - - return ebone->prop; + return &ebone->prop; } static void rna_bone_layer_set(int *layer, const bool *values) diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c index 1af53e95cc9..55f680c736d 100644 --- a/source/blender/makesrna/intern/rna_asset.c +++ b/source/blender/makesrna/intern/rna_asset.c @@ -75,16 +75,10 @@ static void rna_AssetMetaData_tag_remove(AssetMetaData *asset_data, RNA_POINTER_INVALIDATE(tag_ptr); } -static IDProperty *rna_AssetMetaData_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_AssetMetaData_idprops(PointerRNA *ptr) { AssetMetaData *asset_data = ptr->data; - - if (create && !asset_data->properties) { - IDPropertyTemplate val = {0}; - asset_data->properties = IDP_New(IDP_GROUP, &val, "RNA_AssetMetaData group"); - } - - return asset_data->properties; + return &asset_data->properties; } static void rna_AssetMetaData_description_get(PointerRNA *ptr, char *value) diff --git a/source/blender/makesrna/intern/rna_dynamicpaint.c b/source/blender/makesrna/intern/rna_dynamicpaint.c index 0dfd7d74c25..a9d5ef089bb 100644 --- a/source/blender/makesrna/intern/rna_dynamicpaint.c +++ b/source/blender/makesrna/intern/rna_dynamicpaint.c @@ -342,8 +342,8 @@ static void rna_def_canvas_surface(BlenderRNA *brna) {0, NULL, 0, NULL, NULL}, }; - /* Effect type - * Only used by ui to view per effect settings */ + /* Effect type + * Only used by UI to view per effect settings. */ static const EnumPropertyItem prop_dynamicpaint_effecttype[] = { {1, "SPREAD", 0, "Spread", ""}, {2, "DRIP", 0, "Drip", ""}, @@ -351,7 +351,7 @@ static void rna_def_canvas_surface(BlenderRNA *brna) {0, NULL, 0, NULL, NULL}, }; - /* Displacemap file format */ + /* Displace-map file format. */ static const EnumPropertyItem prop_dynamicpaint_image_fileformat[] = { {MOD_DPAINT_IMGFORMAT_PNG, "PNG", 0, "PNG", ""}, # ifdef WITH_OPENEXR @@ -360,7 +360,7 @@ static void rna_def_canvas_surface(BlenderRNA *brna) {0, NULL, 0, NULL, NULL}, }; - /* Displacemap type */ + /* Displace-map type. */ static const EnumPropertyItem prop_dynamicpaint_displace_type[] = { {MOD_DPAINT_DISP_DISPLACE, "DISPLACE", 0, "Displacement", ""}, {MOD_DPAINT_DISP_DEPTH, "DEPTH", 0, "Depth", ""}, diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index bfe9d4bb77c..f15368bcc77 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -276,10 +276,10 @@ void rna_ID_name_get(struct PointerRNA *ptr, char *value); int rna_ID_name_length(struct PointerRNA *ptr); void rna_ID_name_set(struct PointerRNA *ptr, const char *value); struct StructRNA *rna_ID_refine(struct PointerRNA *ptr); -struct IDProperty *rna_ID_idprops(struct PointerRNA *ptr, bool create); +struct IDProperty **rna_ID_idprops(struct PointerRNA *ptr); void rna_ID_fake_user_set(struct PointerRNA *ptr, bool value); void **rna_ID_instance(PointerRNA *ptr); -struct IDProperty *rna_PropertyGroup_idprops(struct PointerRNA *ptr, bool create); +struct IDProperty **rna_PropertyGroup_idprops(struct PointerRNA *ptr); void rna_PropertyGroup_unregister(struct Main *bmain, struct StructRNA *type); struct StructRNA *rna_PropertyGroup_register(struct Main *bmain, struct ReportList *reports, diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index ee60b199d64..479306e8c06 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -54,7 +54,7 @@ typedef void (*ContextPropUpdateFunc)(struct bContext *C, typedef void (*ContextUpdateFunc)(struct bContext *C, struct PointerRNA *ptr); typedef int (*EditableFunc)(struct PointerRNA *ptr, const char **r_info); typedef int (*ItemEditableFunc)(struct PointerRNA *ptr, int index); -typedef struct IDProperty *(*IDPropertiesFunc)(struct PointerRNA *ptr, bool create); +typedef struct IDProperty **(*IDPropertiesFunc)(struct PointerRNA *ptr); typedef struct StructRNA *(*StructRefineFunc)(struct PointerRNA *ptr); typedef char *(*StructPathFunc)(struct PointerRNA *ptr); @@ -559,7 +559,7 @@ struct StructRNA { */ StructInstanceFunc instance; - /* callback to get id properties */ + /** Return the location of the struct's pointer to the root group IDProperty. */ IDPropertiesFunc idproperties; /* functions of this struct */ diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c index b4253ab9236..0414afe1514 100644 --- a/source/blender/makesrna/intern/rna_layer.c +++ b/source/blender/makesrna/intern/rna_layer.c @@ -119,16 +119,10 @@ static char *rna_ViewLayer_path(PointerRNA *ptr) return BLI_sprintfN("view_layers[\"%s\"]", name_esc); } -static IDProperty *rna_ViewLayer_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_ViewLayer_idprops(PointerRNA *ptr) { ViewLayer *view_layer = (ViewLayer *)ptr->data; - - if (create && !view_layer->id_properties) { - IDPropertyTemplate val = {0}; - view_layer->id_properties = IDP_New(IDP_GROUP, &val, "ViewLayer ID properties"); - } - - return view_layer->id_properties; + return &view_layer->id_properties; } static bool rna_LayerCollection_visible_get(LayerCollection *layer_collection, bContext *C) diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c index 3fba8cdb035..9835d664a55 100644 --- a/source/blender/makesrna/intern/rna_mesh_api.c +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -249,7 +249,7 @@ void RNA_api_mesh(StructRNA *srna) func = RNA_def_function(srna, "split_faces", "rna_Mesh_split_faces"); RNA_def_function_ui_description(func, "Split faces based on the edge angle"); RNA_def_boolean( - func, "free_loop_normals", 1, "Free Loop Notmals", "Free loop normals custom data layer"); + func, "free_loop_normals", 1, "Free Loop Normals", "Free loop normals custom data layer"); func = RNA_def_function(srna, "calc_tangents", "rna_Mesh_calc_tangents"); RNA_def_function_flag(func, FUNC_USE_REPORTS); diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 7def9bdb636..e64eaf8c363 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -602,6 +602,7 @@ const EnumPropertyItem rna_enum_axis_flag_xyz_items[] = { # include "BKE_cachefile.h" # include "BKE_context.h" +# include "BKE_deform.h" # include "BKE_mesh_runtime.h" # include "BKE_modifier.h" # include "BKE_object.h" @@ -1250,12 +1251,13 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf( # endif if (ob_src) { - bDeformGroup *dg; + const bDeformGroup *dg; int i; RNA_enum_item_add_separator(&item, &totitem); - for (i = 0, dg = ob_src->defbase.first; dg; i++, dg = dg->next) { + const ListBase *defbase = BKE_object_defgroup_list(ob_src); + for (i = 0, dg = defbase->first; dg; i++, dg = dg->next) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = dg->name; RNA_enum_item_add(&item, &totitem, &tmp_item); @@ -1349,12 +1351,13 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_dst_itemf( Object *ob_dst = CTX_data_active_object(C); /* XXX Is this OK? */ if (ob_dst) { - bDeformGroup *dg; + const bDeformGroup *dg; int i; RNA_enum_item_add_separator(&item, &totitem); - for (i = 0, dg = ob_dst->defbase.first; dg; i++, dg = dg->next) { + const ListBase *defbase = BKE_object_defgroup_list(ob_dst); + for (i = 0, dg = defbase->first; dg; i++, dg = dg->next) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = dg->name; RNA_enum_item_add(&item, &totitem, &tmp_item); @@ -1618,15 +1621,11 @@ static void rna_NodesModifier_node_group_update(Main *bmain, Scene *scene, Point MOD_nodes_update_interface(object, nmd); } -static IDProperty *rna_NodesModifier_properties(PointerRNA *ptr, bool create) +static IDProperty **rna_NodesModifier_properties(PointerRNA *ptr) { NodesModifierData *nmd = ptr->data; NodesModifierSettings *settings = &nmd->settings; - if (create && settings->properties == NULL) { - IDPropertyTemplate val = {0}; - settings->properties = IDP_New(IDP_GROUP, &val, "Nodes Modifier Settings"); - } - return settings->properties; + return &settings->properties; } #else diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 978ea13f92f..582bc40a142 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -2366,16 +2366,10 @@ static StructRNA *rna_FunctionNode_register(Main *bmain, return nt->rna_ext.srna; } -static IDProperty *rna_Node_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_Node_idprops(PointerRNA *ptr) { bNode *node = ptr->data; - - if (create && !node->prop) { - IDPropertyTemplate val = {0}; - node->prop = IDP_New(IDP_GROUP, &val, "RNA_Node ID properties"); - } - - return node->prop; + return &node->prop; } static void rna_Node_parent_set(PointerRNA *ptr, @@ -2834,16 +2828,10 @@ static char *rna_NodeSocket_path(PointerRNA *ptr) } } -static IDProperty *rna_NodeSocket_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_NodeSocket_idprops(PointerRNA *ptr) { bNodeSocket *sock = ptr->data; - - if (create && !sock->prop) { - IDPropertyTemplate val = {0}; - sock->prop = IDP_New(IDP_GROUP, &val, "RNA_NodeSocket ID properties"); - } - - return sock->prop; + return &sock->prop; } static PointerRNA rna_NodeSocket_node_get(PointerRNA *ptr) @@ -3150,16 +3138,10 @@ static char *rna_NodeSocketInterface_path(PointerRNA *ptr) return NULL; } -static IDProperty *rna_NodeSocketInterface_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_NodeSocketInterface_idprops(PointerRNA *ptr) { bNodeSocket *sock = ptr->data; - - if (create && !sock->prop) { - IDPropertyTemplate val = {0}; - sock->prop = IDP_New(IDP_GROUP, &val, "RNA_NodeSocketInterface ID properties"); - } - - return sock->prop; + return &sock->prop; } static void rna_NodeSocketInterface_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr) @@ -3205,7 +3187,7 @@ static void rna_NodeSocketInterfaceStandard_draw(ID *id, struct uiLayout *layout) { PointerRNA ptr; - RNA_pointer_create(id, &RNA_NodeSocket, sock, &ptr); + RNA_pointer_create(id, &RNA_NodeSocketInterface, sock, &ptr); sock->typeinfo->interface_draw(C, layout, &ptr); } @@ -3215,7 +3197,7 @@ static void rna_NodeSocketInterfaceStandard_draw_color(ID *id, float r_color[4]) { PointerRNA ptr; - RNA_pointer_create(id, &RNA_NodeSocket, sock, &ptr); + RNA_pointer_create(id, &RNA_NodeSocketInterface, sock, &ptr); sock->typeinfo->interface_draw_color(C, &ptr, r_color); } @@ -9947,6 +9929,45 @@ static void def_geo_switch(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); } +static void def_geo_curve_primitive_quadrilateral(StructRNA *srna) +{ + PropertyRNA *prop; + + static EnumPropertyItem mode_items[] = { + {GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_RECTANGLE, + "RECTANGLE", + 0, + "Rectangle", + "Create a rectangle"}, + {GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_PARALLELOGRAM, + "PARALLELOGRAM", + 0, + "Parallelogram", + "Create a parallelogram"}, + {GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_TRAPEZOID, + "TRAPEZOID", + 0, + "Trapezoid", + "Create a trapezoid"}, + {GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_KITE, "KITE", 0, "Kite", "Create a Kite / Dart"}, + {GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_POINTS, + "POINTS", + 0, + "Points", + "Create a quadrilateral from four points"}, + {0, NULL, 0, NULL, NULL}, + }; + + RNA_def_struct_sdna_from(srna, "NodeGeometryCurvePrimitiveQuad", "storage"); + + prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "mode"); + RNA_def_property_enum_items(prop, mode_items); + RNA_def_property_enum_default(prop, GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_RECTANGLE); + RNA_def_property_ui_text(prop, "Mode", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); +} + static void def_geo_curve_resample(StructRNA *srna) { PropertyRNA *prop; diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 7c012922c2c..e110459eeea 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -790,9 +790,27 @@ static void rna_Object_dup_collection_set(PointerRNA *ptr, } } +static void rna_Object_vertex_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + Object *ob = (Object *)ptr->data; + if (!BKE_object_supports_vertex_groups(ob)) { + iter->valid = 0; + return; + } + + ListBase *defbase = BKE_object_defgroup_list_mutable(ob); + iter->valid = defbase != NULL; + + rna_iterator_listbase_begin(iter, defbase, NULL); +} + static void rna_VertexGroup_name_set(PointerRNA *ptr, const char *value) { Object *ob = (Object *)ptr->owner_id; + if (!BKE_object_supports_vertex_groups(ob)) { + return; + } + bDeformGroup *dg = (bDeformGroup *)ptr->data; BLI_strncpy_utf8(dg->name, value, sizeof(dg->name)); BKE_object_defgroup_unique_name(dg, ob); @@ -801,15 +819,25 @@ static void rna_VertexGroup_name_set(PointerRNA *ptr, const char *value) static int rna_VertexGroup_index_get(PointerRNA *ptr) { Object *ob = (Object *)ptr->owner_id; + if (!BKE_object_supports_vertex_groups(ob)) { + return -1; + } - return BLI_findindex(&ob->defbase, ptr->data); + const ListBase *defbase = BKE_object_defgroup_list(ob); + return BLI_findindex(defbase, ptr->data); } static PointerRNA rna_Object_active_vertex_group_get(PointerRNA *ptr) { Object *ob = (Object *)ptr->owner_id; + if (!BKE_object_supports_vertex_groups(ob)) { + return PointerRNA_NULL; + } + + const ListBase *defbase = BKE_object_defgroup_list(ob); + return rna_pointer_inherit_refine( - ptr, &RNA_VertexGroup, BLI_findlink(&ob->defbase, ob->actdef - 1)); + ptr, &RNA_VertexGroup, BLI_findlink(defbase, BKE_object_defgroup_active_index_get(ob) - 1)); } static void rna_Object_active_vertex_group_set(PointerRNA *ptr, @@ -817,7 +845,13 @@ static void rna_Object_active_vertex_group_set(PointerRNA *ptr, struct ReportList *reports) { Object *ob = (Object *)ptr->owner_id; - int index = BLI_findindex(&ob->defbase, value.data); + if (!BKE_object_supports_vertex_groups(ob)) { + return; + } + + const ListBase *defbase = BKE_object_defgroup_list(ob); + + int index = BLI_findindex(defbase, value.data); if (index == -1) { BKE_reportf(reports, RPT_ERROR, @@ -827,19 +861,27 @@ static void rna_Object_active_vertex_group_set(PointerRNA *ptr, return; } - ob->actdef = index + 1; + BKE_object_defgroup_active_index_set(ob, index + 1); } static int rna_Object_active_vertex_group_index_get(PointerRNA *ptr) { Object *ob = (Object *)ptr->owner_id; - return ob->actdef - 1; + if (!BKE_object_supports_vertex_groups(ob)) { + return -1; + } + + return BKE_object_defgroup_active_index_get(ob) - 1; } static void rna_Object_active_vertex_group_index_set(PointerRNA *ptr, int value) { Object *ob = (Object *)ptr->owner_id; - ob->actdef = value + 1; + if (!BKE_object_supports_vertex_groups(ob)) { + return; + } + + BKE_object_defgroup_active_index_set(ob, value + 1); } static void rna_Object_active_vertex_group_index_range( @@ -848,15 +890,24 @@ static void rna_Object_active_vertex_group_index_range( Object *ob = (Object *)ptr->owner_id; *min = 0; - *max = max_ii(0, BLI_listbase_count(&ob->defbase) - 1); + if (!BKE_object_supports_vertex_groups(ob)) { + *max = 0; + return; + } + const ListBase *defbase = BKE_object_defgroup_list(ob); + *max = max_ii(0, BLI_listbase_count(defbase) - 1); } void rna_object_vgroup_name_index_get(PointerRNA *ptr, char *value, int index) { Object *ob = (Object *)ptr->owner_id; - bDeformGroup *dg; + if (!BKE_object_supports_vertex_groups(ob)) { + value[0] = '\0'; + return; + } - dg = BLI_findlink(&ob->defbase, index - 1); + const ListBase *defbase = BKE_object_defgroup_list(ob); + const bDeformGroup *dg = BLI_findlink(defbase, index - 1); if (dg) { BLI_strncpy(value, dg->name, sizeof(dg->name)); @@ -869,21 +920,34 @@ void rna_object_vgroup_name_index_get(PointerRNA *ptr, char *value, int index) int rna_object_vgroup_name_index_length(PointerRNA *ptr, int index) { Object *ob = (Object *)ptr->owner_id; - bDeformGroup *dg; + if (!BKE_object_supports_vertex_groups(ob)) { + return 0; + } - dg = BLI_findlink(&ob->defbase, index - 1); + const ListBase *defbase = BKE_object_defgroup_list(ob); + bDeformGroup *dg = BLI_findlink(defbase, index - 1); return (dg) ? strlen(dg->name) : 0; } void rna_object_vgroup_name_index_set(PointerRNA *ptr, const char *value, short *index) { Object *ob = (Object *)ptr->owner_id; + if (!BKE_object_supports_vertex_groups(ob)) { + *index = -1; + return; + } + *index = BKE_object_defgroup_name_index(ob, value) + 1; } void rna_object_vgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) { Object *ob = (Object *)ptr->owner_id; + if (!BKE_object_supports_vertex_groups(ob)) { + result[0] = '\0'; + return; + } + bDeformGroup *dg = BKE_object_defgroup_find_name(ob, value); if (dg) { /* No need for BLI_strncpy_utf8, since this matches an existing group. */ @@ -1960,7 +2024,9 @@ static void rna_Object_vgroup_remove(Object *ob, PointerRNA *defgroup_ptr) { bDeformGroup *defgroup = defgroup_ptr->data; - if (BLI_findindex(&ob->defbase, defgroup) == -1) { + ListBase *defbase = BKE_object_defgroup_list_mutable(ob); + + if (BLI_findindex(defbase, defgroup) == -1) { BKE_reportf(reports, RPT_ERROR, "DeformGroup '%s' not in object '%s'", @@ -2687,7 +2753,6 @@ static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop) prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); - RNA_def_property_int_sdna(prop, NULL, "actdef"); RNA_def_property_int_funcs(prop, "rna_Object_active_vertex_group_index_get", "rna_Object_active_vertex_group_index_set", @@ -3274,7 +3339,15 @@ static void rna_def_object(BlenderRNA *brna) /* vertex groups */ prop = RNA_def_property(srna, "vertex_groups", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "defbase", NULL); + RNA_def_property_collection_funcs(prop, + "rna_Object_vertex_groups_begin", + "rna_iterator_listbase_next", + "rna_iterator_listbase_end", + "rna_iterator_listbase_get", + NULL, + NULL, + NULL, + NULL); RNA_def_property_struct_type(prop, "VertexGroup"); RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); RNA_def_property_ui_text(prop, "Vertex Groups", "Vertex groups of the object"); diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index 8edb80f68c5..de4cfb2b61a 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -1430,9 +1430,10 @@ static void psys_vg_name_get__internal(PointerRNA *ptr, char *value, int index) { Object *ob = (Object *)ptr->owner_id; ParticleSystem *psys = (ParticleSystem *)ptr->data; + const ListBase *defbase = BKE_object_defgroup_list(ob); if (psys->vgroup[index] > 0) { - bDeformGroup *defGroup = BLI_findlink(&ob->defbase, psys->vgroup[index] - 1); + bDeformGroup *defGroup = BLI_findlink(defbase, psys->vgroup[index] - 1); if (defGroup) { strcpy(value, defGroup->name); @@ -1448,7 +1449,8 @@ static int psys_vg_name_len__internal(PointerRNA *ptr, int index) ParticleSystem *psys = (ParticleSystem *)ptr->data; if (psys->vgroup[index] > 0) { - bDeformGroup *defGroup = BLI_findlink(&ob->defbase, psys->vgroup[index] - 1); + const ListBase *defbase = BKE_object_defgroup_list(ob); + bDeformGroup *defGroup = BLI_findlink(defbase, psys->vgroup[index] - 1); if (defGroup) { return strlen(defGroup->name); diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index bb4939a010b..ee509fa92d4 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -224,16 +224,10 @@ static void rna_BoneGroup_name_set(PointerRNA *ptr, const char *value) sizeof(agrp->name)); } -static IDProperty *rna_PoseBone_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_PoseBone_idprops(PointerRNA *ptr) { bPoseChannel *pchan = ptr->data; - - if (create && !pchan->prop) { - IDPropertyTemplate val = {0}; - pchan->prop = IDP_New(IDP_GROUP, &val, "RNA_PoseBone group"); - } - - return pchan->prop; + return &pchan->prop; } static void rna_Pose_ik_solver_set(struct PointerRNA *ptr, int value) diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c index 0c46450759d..b1f0b0d760f 100644 --- a/source/blender/makesrna/intern/rna_sequencer.c +++ b/source/blender/makesrna/intern/rna_sequencer.c @@ -199,7 +199,10 @@ static void rna_SequenceEditor_sequences_all_begin(CollectionPropertyIterator *i bli_iter->data = MEM_callocN(sizeof(SeqIterator), __func__); iter->internal.custom = bli_iter; - SEQ_iterator_ensure(all_strips, bli_iter->data, (Sequence **)&bli_iter->current); + if (!SEQ_iterator_ensure(all_strips, bli_iter->data, (Sequence **)&bli_iter->current)) { + SEQ_collection_free(all_strips); + } + iter->valid = bli_iter->current != NULL; } @@ -220,7 +223,9 @@ static void rna_SequenceEditor_sequences_all_end(CollectionPropertyIterator *ite { BLI_Iterator *bli_iter = iter->internal.custom; SeqIterator *seq_iter = bli_iter->data; - SEQ_collection_free(seq_iter->collection); + if (seq_iter->collection != NULL) { + SEQ_collection_free(seq_iter->collection); + } MEM_freeN(seq_iter); MEM_freeN(bli_iter); } @@ -729,16 +734,10 @@ static char *rna_Sequence_path(PointerRNA *ptr) } } -static IDProperty *rna_Sequence_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_Sequence_idprops(PointerRNA *ptr) { Sequence *seq = ptr->data; - - if (create && !seq->prop) { - IDPropertyTemplate val = {0}; - seq->prop = IDP_New(IDP_GROUP, &val, "Sequence ID properties"); - } - - return seq->prop; + return &seq->prop; } static bool rna_MovieSequence_reload_if_needed(ID *scene_id, Sequence *seq, Main *bmain) diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 56deb873611..7366934695e 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -1041,16 +1041,10 @@ static bool rna_RegionView3D_is_orthographic_side_view_get(PointerRNA *ptr) return RV3D_VIEW_IS_AXIS(rv3d->view); } -static IDProperty *rna_View3DShading_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_View3DShading_idprops(PointerRNA *ptr) { View3DShading *shading = ptr->data; - - if (create && !shading->prop) { - IDPropertyTemplate val = {0}; - shading->prop = IDP_New(IDP_GROUP, &val, "View3DShading ID properties"); - } - - return shading->prop; + return &shading->prop; } static void rna_3DViewShading_type_update(Main *bmain, Scene *scene, PointerRNA *ptr) @@ -2106,7 +2100,7 @@ static void rna_SpaceDopeSheetEditor_action_update(bContext *C, PointerRNA *ptr) switch (saction->mode) { case SACTCONT_ACTION: /* TODO: context selector could help decide this with more control? */ - adt = BKE_animdata_add_id(&obact->id); + adt = BKE_animdata_ensure_id(&obact->id); id = &obact->id; break; case SACTCONT_SHAPEKEY: { @@ -2114,7 +2108,7 @@ static void rna_SpaceDopeSheetEditor_action_update(bContext *C, PointerRNA *ptr) if (key == NULL) { return; } - adt = BKE_animdata_add_id(&key->id); + adt = BKE_animdata_ensure_id(&key->id); id = &key->id; break; } diff --git a/source/blender/makesrna/intern/rna_timeline.c b/source/blender/makesrna/intern/rna_timeline.c index c0bd9fd92a2..223e6389942 100644 --- a/source/blender/makesrna/intern/rna_timeline.c +++ b/source/blender/makesrna/intern/rna_timeline.c @@ -33,16 +33,10 @@ # include "BKE_idprop.h" # include "WM_api.h" -static IDProperty *rna_TimelineMarker_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_TimelineMarker_idprops(PointerRNA *ptr) { TimeMarker *marker = ptr->data; - - if (create && marker->prop == NULL) { - IDPropertyTemplate val = {0}; - marker->prop = IDP_New(IDP_GROUP, &val, "Marker ID properties"); - } - - return marker->prop; + return &marker->prop; } static void rna_TimelineMarker_update(Main *UNUSED(bmain), diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 98bed5a7891..d4ae5f1ecfc 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -452,15 +452,10 @@ static unsigned int rna_UIList_filter_const_FILTER_ITEM_get(PointerRNA *UNUSED(p return UILST_FLT_ITEM; } -static IDProperty *rna_UIList_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_UIList_idprops(PointerRNA *ptr) { uiList *ui_list = (uiList *)ptr->data; - if (create && !ui_list->properties) { - IDPropertyTemplate val = {0}; - ui_list->properties = IDP_New(IDP_GROUP, &val, "RNA_UIList IDproperties group"); - } - - return ui_list->properties; + return &ui_list->properties; } static void uilist_draw_item(uiList *ui_list, diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 81f6bcc5805..fd1c0b7951a 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -809,14 +809,9 @@ static const EnumPropertyItem *rna_lang_enum_properties_itemf(bContext *UNUSED(C } # endif -static IDProperty *rna_AddonPref_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_AddonPref_idprops(PointerRNA *ptr) { - if (create && !ptr->data) { - IDPropertyTemplate val = {0}; - ptr->data = IDP_New(IDP_GROUP, &val, "RNA_AddonPreferences group"); - } - - return ptr->data; + return (IDProperty **)&ptr->data; } static PointerRNA rna_Addon_preferences_get(PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index a563541b968..afbde26e59e 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -568,14 +568,9 @@ static StructRNA *rna_OperatorProperties_refine(PointerRNA *ptr) } } -static IDProperty *rna_OperatorProperties_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_OperatorProperties_idprops(PointerRNA *ptr) { - if (create && !ptr->data) { - IDPropertyTemplate val = {0}; - ptr->data = IDP_New(IDP_GROUP, &val, "RNA_OperatorProperties group"); - } - - return ptr->data; + return (IDProperty **)&ptr->data; } static void rna_Operator_name_get(PointerRNA *ptr, char *value) @@ -1120,13 +1115,9 @@ static PointerRNA rna_wmKeyConfig_preferences_get(PointerRNA *ptr) } } -static IDProperty *rna_wmKeyConfigPref_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_wmKeyConfigPref_idprops(PointerRNA *ptr) { - if (create && !ptr->data) { - IDPropertyTemplate val = {0}; - ptr->data = IDP_New(IDP_GROUP, &val, "RNA_KeyConfigPreferences group"); - } - return ptr->data; + return (IDProperty **)&ptr->data; } static void rna_wmKeyConfigPref_unregister(Main *UNUSED(bmain), StructRNA *type) diff --git a/source/blender/makesrna/intern/rna_wm_gizmo.c b/source/blender/makesrna/intern/rna_wm_gizmo.c index 98920bbd518..076a77d4fb5 100644 --- a/source/blender/makesrna/intern/rna_wm_gizmo.c +++ b/source/blender/makesrna/intern/rna_wm_gizmo.c @@ -293,14 +293,9 @@ static StructRNA *rna_GizmoProperties_refine(PointerRNA *ptr) } } -static IDProperty *rna_GizmoProperties_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_GizmoProperties_idprops(PointerRNA *ptr) { - if (create && !ptr->data) { - IDPropertyTemplate val = {0}; - ptr->data = IDP_New(IDP_GROUP, &val, "RNA_GizmoProperties group"); - } - - return ptr->data; + return (IDProperty **)&ptr->data; } static PointerRNA rna_Gizmo_properties_get(PointerRNA *ptr) @@ -585,14 +580,9 @@ static StructRNA *rna_GizmoGroupProperties_refine(PointerRNA *ptr) } } -static IDProperty *rna_GizmoGroupProperties_idprops(PointerRNA *ptr, bool create) +static IDProperty **rna_GizmoGroupProperties_idprops(PointerRNA *ptr) { - if (create && !ptr->data) { - IDPropertyTemplate val = {0}; - ptr->data = IDP_New(IDP_GROUP, &val, "RNA_GizmoGroupProperties group"); - } - - return ptr->data; + return (IDProperty **)&ptr->data; } static wmGizmo *rna_GizmoGroup_gizmo_new(wmGizmoGroup *gzgroup, |