From c202d3865904903a73a18822613f625a3bee344b Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 14 Jul 2021 10:51:28 -0400 Subject: Python API: Add functions to ensure and clear IDProperties This adds id_properties_clear() and id_properties_ensure() functions to RNA structs. This is meant as an initial change based on discussion in review of D9697. However, they may be useful in other situations. The change requires refactoring the internal idproperties callback to return a pointer to the IDProperty pointer, which actually turns out to be quite a nice cleanup. An id_properties attribute could be added in the future potentially. Differential Revision: https://developer.blender.org/D11908 --- source/blender/makesrna/intern/rna_nodetree.c | 32 ++++++--------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'source/blender/makesrna/intern/rna_nodetree.c') diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index d576a5b7db6..cfd83a85d2e 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) @@ -9950,7 +9932,7 @@ static void def_geo_switch(StructRNA *srna) static void def_geo_curve_primitive_quadrilateral(StructRNA *srna) { PropertyRNA *prop; - + static EnumPropertyItem mode_items[] = { {GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_RECTANGLE, "RECTANGLE", -- cgit v1.2.3