diff options
Diffstat (limited to 'source/blender/editors/object/object_add.c')
-rw-r--r-- | source/blender/editors/object/object_add.c | 130 |
1 files changed, 45 insertions, 85 deletions
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index e4527740164..7f189abe870 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -1416,6 +1416,9 @@ static int object_gpencil_add_exec(bContext *C, wmOperator *op) /* Only created one layer and one material. */ strcpy(md->target_layer, ((bGPDlayer *)gpd->layers.first)->info); md->target_material = BKE_gpencil_material(ob, 1); + if (md->target_material) { + id_us_plus(&md->target_material->id); + } /* Stroke object is drawn in front of meshes by default. */ ob->dtx |= OB_DRAW_IN_FRONT; @@ -1440,41 +1443,6 @@ static int object_gpencil_add_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static const EnumPropertyItem *object_gpencil_add_options(bContext *C, - PointerRNA *UNUSED(ptr), - PropertyRNA *UNUSED(prop), - bool *r_free) -{ - EnumPropertyItem *item = NULL; - const EnumPropertyItem *item_ref = rna_enum_object_gpencil_type_items; - int totitem = 0; - int i = 0; - int orig_count = RNA_enum_items_count(item_ref); - - /* Default types. */ - for (i = 0; i < orig_count; i++) { - if (item_ref[i].value == GP_LRT_OBJECT || item_ref[i].value == GP_LRT_COLLECTION || - item_ref[i].value == GP_LRT_SCENE) { - if (item_ref[i].value == GP_LRT_SCENE) { - /* separator before line art types */ - RNA_enum_item_add_separator(&item, &totitem); - } - else if (item_ref[i].value == GP_LRT_OBJECT) { - Object *ob = CTX_data_active_object(C); - if (!ob || ob->type != OB_MESH) { - continue; - } - } - } - RNA_enum_item_add(&item, &totitem, &item_ref[i]); - } - - RNA_enum_item_end(&item, &totitem); - *r_free = true; - - return item; -} - void OBJECT_OT_gpencil_add(wmOperatorType *ot) { /* identifiers */ @@ -1495,7 +1463,6 @@ void OBJECT_OT_gpencil_add(wmOperatorType *ot) ED_object_add_generic_props(ot, false); ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_gpencil_type_items, 0, "Type", ""); - RNA_def_enum_funcs(ot->prop, object_gpencil_add_options); } /** \} */ @@ -1932,8 +1899,8 @@ void OBJECT_OT_pointcloud_add(wmOperatorType *ot) /* note: now unlinks constraints as well */ void ED_object_base_free_and_unlink(Main *bmain, Scene *scene, Object *ob) { - if (BKE_library_ID_is_indirectly_used(bmain, ob) && ID_REAL_USERS(ob) <= 1 && - ID_EXTRA_USERS(ob) == 0) { + if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 && + BKE_library_ID_is_indirectly_used(bmain, ob)) { /* We cannot delete indirectly used object... */ printf( "WARNING, undeletable object '%s', should have been caught before reaching this " @@ -1947,6 +1914,17 @@ void ED_object_base_free_and_unlink(Main *bmain, Scene *scene, Object *ob) BKE_scene_collections_object_remove(bmain, scene, ob, true); } +/** + * Remove base from a specific scene. + * `ob` must not be indirectly used. + */ +void ED_object_base_free_and_unlink_no_indirect_check(Main *bmain, Scene *scene, Object *ob) +{ + BLI_assert(!BKE_library_ID_is_indirectly_used(bmain, ob)); + DEG_id_tag_update_ex(bmain, &ob->id, ID_RECALC_BASE_FLAGS); + BKE_scene_collections_object_remove(bmain, scene, ob, true); +} + static int object_delete_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); @@ -1954,13 +1932,15 @@ static int object_delete_exec(bContext *C, wmOperator *op) wmWindowManager *wm = CTX_wm_manager(C); const bool use_global = RNA_boolean_get(op->ptr, "use_global"); uint changed_count = 0; + uint tagged_count = 0; if (CTX_data_edit_object(C)) { return OPERATOR_CANCELLED; } + BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); + CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { - const bool is_indirectly_used = BKE_library_ID_is_indirectly_used(bmain, ob); if (ob->id.tag & LIB_TAG_INDIRECT) { /* Can this case ever happen? */ BKE_reportf(op->reports, @@ -1969,7 +1949,9 @@ static int object_delete_exec(bContext *C, wmOperator *op) ob->id.name + 2); continue; } - if (is_indirectly_used && ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0) { + + if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 && + BKE_library_ID_is_indirectly_used(bmain, ob)) { BKE_reportf(op->reports, RPT_WARNING, "Cannot delete object '%s' from scene '%s', indirectly used objects need at " @@ -1985,63 +1967,41 @@ static int object_delete_exec(bContext *C, wmOperator *op) DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); } - /* This is sort of a quick hack to address T51243 - - * Proper thing to do here would be to nuke most of all this custom scene/object/base handling, - * and use generic lib remap/query for that. - * But this is for later (aka 2.8, once layers & co are settled and working). - */ - if (use_global && ob->id.lib == NULL) { - /* We want to nuke the object, let's nuke it the easy way (not for linked data though)... */ - BKE_id_delete(bmain, &ob->id); - changed_count += 1; - continue; - } - - /* remove from Grease Pencil parent */ - /* XXX This is likely not correct? - * Will also remove parent from grease pencil from other scenes, - * even when use_global is false... */ - for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) { - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - if (gpl->parent != NULL) { - if (gpl->parent == ob) { - gpl->parent = NULL; - } - } - } + /* Use multi tagged delete if `use_global=True`, or the object is used only in one scene. */ + if (use_global || ID_REAL_USERS(ob) <= 1) { + ob->id.tag |= LIB_TAG_DOIT; + tagged_count += 1; } + else { + /* Object is used in multiple scenes. Delete the object from the current scene only. */ + ED_object_base_free_and_unlink_no_indirect_check(bmain, scene, ob); + changed_count += 1; - /* remove from current scene only */ - ED_object_base_free_and_unlink(bmain, scene, ob); - changed_count += 1; - - if (use_global) { - Scene *scene_iter; - for (scene_iter = bmain->scenes.first; scene_iter; scene_iter = scene_iter->id.next) { - if (scene_iter != scene && !ID_IS_LINKED(scene_iter)) { - if (is_indirectly_used && ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0) { - BKE_reportf(op->reports, - RPT_WARNING, - "Cannot delete object '%s' from scene '%s', indirectly used objects need " - "at least one user", - ob->id.name + 2, - scene_iter->id.name + 2); - break; + /* FIXME: this will also remove parent from grease pencil from other scenes. */ + /* Remove from Grease Pencil parent */ + for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) { + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + if (gpl->parent != NULL) { + if (gpl->parent == ob) { + gpl->parent = NULL; + } } - ED_object_base_free_and_unlink(bmain, scene_iter, ob); } } } - /* end global */ } CTX_DATA_END; - BKE_reportf(op->reports, RPT_INFO, "Deleted %u object(s)", changed_count); - - if (changed_count == 0) { + if ((changed_count + tagged_count) == 0) { return OPERATOR_CANCELLED; } + if (tagged_count > 0) { + BKE_id_multi_tagged_delete(bmain); + } + + BKE_reportf(op->reports, RPT_INFO, "Deleted %u object(s)", (changed_count + tagged_count)); + /* delete has to handle all open scenes */ BKE_main_id_tag_listbase(&bmain->scenes, LIB_TAG_DOIT, true); LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { |