diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2016-11-24 20:07:19 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2016-11-24 20:07:19 +0300 |
commit | 041e2d3e28c549beb1a40a7ee70597f6a9fc1d7a (patch) | |
tree | 0808cbd0af0b6d2e7528c2662e7dcfc5db189fc9 /source/blender/makesrna/intern | |
parent | be976500fe6d8d7f6df15298ea806caaa42a0009 (diff) |
Base list refcount with Bastien Montagnelayers
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index dcb8ce2892c..e594b68a31e 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -657,6 +657,31 @@ static Base *rna_LayerCollection_object_link(ID *id, LayerCollection *lc, Main * return base; } +static void rna_LayerCollection_object_unlink(ID *id, LayerCollection *lc, ReportList *reports, Object *ob) +{ + Scene *scene = (Scene *)id; + SceneLayer *sl = BKE_scene_layer_from_collection(scene, lc); + Base *base = BKE_scene_layer_collection_base_find(lc, ob); + + if (!base) { + BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in this collection '%s'", ob->id.name + 2, lc->name); + return; + } + + if (((base->flag & SELECT) != 0) && sl->mode != OB_MODE_OBJECT) { + BKE_reportf(reports, RPT_ERROR, "Object '%s' must be in object mode to unlink", ob->id.name + 2); + return; + } + + BKE_scene_layer_base_unlink(scene, lc, base); + id_us_min(&ob->id); + + /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */ + DAG_relations_tag_update(G.main); + + WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene); +} + static int rna_Scene_layer_object_bases_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) { SceneLayer *sl = (SceneLayer *)ptr->data; @@ -5231,6 +5256,12 @@ static void rna_def_layer_collection_objects(BlenderRNA *brna, PropertyRNA *cpro RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); parm = RNA_def_pointer(func, "base", "ObjectBase", "", "The newly created base"); RNA_def_function_return(func, parm); + + func = RNA_def_function(srna, "unlink", "rna_LayerCollection_object_unlink"); + RNA_def_function_ui_description(func, "Unlink object from collection"); + RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS); + parm = RNA_def_pointer(func, "object", "Object", "", "Object to remove from collection"); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); } static void rna_def_layer_nested_collections(BlenderRNA *brna, PropertyRNA *cprop) |