Rename any instance of scene layer or render layer in code with view layer
[blender.git] / source / blender / editors / object / object_relations.c
index abc89d0e937409337f2aec41573eb05e752c69d9..132d613440c197abfcee50e728efbdb0366f1d0a 100644 (file)
@@ -127,7 +127,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
 {
        Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
-       SceneLayer *sl = CTX_data_scene_layer(C);
+       ViewLayer *sl = CTX_data_view_layer(C);
        Object *obedit = CTX_data_edit_object(C);
        EvaluationContext eval_ctx;
        BMVert *eve;
@@ -247,7 +247,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
                        else {
                                Object workob;
 
-                               ob->parent = BASACT_NEW(sl)->object;
+                               ob->parent = BASACT(sl)->object;
                                if (v3) {
                                        ob->partype = PARVERT3;
                                        ob->par1 = v1 - 1;
@@ -303,23 +303,24 @@ static int make_proxy_invoke(bContext *C, wmOperator *op, const wmEvent *event)
        Object *ob = ED_object_active_context(C);
 
        /* sanity checks */
-       if (!scene || ID_IS_LINKED_DATABLOCK(scene) || !ob)
+       if (!scene || ID_IS_LINKED(scene) || !ob)
                return OPERATOR_CANCELLED;
 
        /* Get object to work on - use a menu if we need to... */
-       if (ob->dup_group && ID_IS_LINKED_DATABLOCK(ob->dup_group)) {
+       if (ob->dup_group && ID_IS_LINKED(ob->dup_group)) {
                /* gives menu with list of objects in group */
                /* proxy_group_objects_menu(C, op, ob, ob->dup_group); */
                WM_enum_search_invoke(C, op, event);
                return OPERATOR_CANCELLED;
        }
-       else if (ID_IS_LINKED_DATABLOCK(ob)) {
+       else if (ID_IS_LINKED(ob)) {
                uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("OK?"), ICON_QUESTION);
                uiLayout *layout = UI_popup_menu_layout(pup);
 
                /* create operator menu item with relevant properties filled in */
+               PointerRNA opptr_dummy;
                uiItemFullO_ptr(layout, op->type, op->type->name, ICON_NONE, NULL,
-                               WM_OP_EXEC_REGION_WIN, UI_ITEM_O_RETURN_PROPS);
+                               WM_OP_EXEC_REGION_WIN, 0, &opptr_dummy);
 
                /* present the menu and be done... */
                UI_popup_menu_end(C, pup);
@@ -341,7 +342,7 @@ static int make_proxy_exec(bContext *C, wmOperator *op)
        Object *ob, *gob = ED_object_active_context(C);
        GroupObject *go;
        Scene *scene = CTX_data_scene(C);
-       SceneLayer *sl = CTX_data_scene_layer(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
        if (gob->dup_group != NULL) {
                go = BLI_findlink(&gob->dup_group->gobject, RNA_enum_get(op->ptr, "object"));
@@ -354,27 +355,25 @@ static int make_proxy_exec(bContext *C, wmOperator *op)
 
        if (ob) {
                Object *newob;
-               BaseLegacy *newbase, *oldbase = BASACT_NEW(sl);
                char name[MAX_ID_NAME + 4];
 
                BLI_snprintf(name, sizeof(name), "%s_proxy", ((ID *)(gob ? gob : ob))->name + 2);
 
                /* Add new object for the proxy */
-               newob = BKE_object_add(bmain, scene, sl, OB_EMPTY, name);
+               newob = BKE_object_add_from(bmain, scene, view_layer, OB_EMPTY, name, gob ? gob : ob);
 
                /* set layers OK */
-               newbase = BASACT_NEW(sl);    /* BKE_object_add sets active... */
-               newbase->lay = oldbase->lay;
-               newob->lay = newbase->lay;
-
-               /* remove base, leave user count of object, it gets linked in BKE_object_make_proxy */
-               if (gob == NULL) {
-                       BKE_scene_base_unlink(scene, oldbase);
-                       MEM_freeN(oldbase);
-               }
-
                BKE_object_make_proxy(newob, ob, gob);
 
+               /* Set back pointer immediately so dependency graph knows that this is
+                * is a proxy and will act accordingly. Otherwise correctness of graph
+                * will depend on order of bases.
+                *
+                * TODO(sergey): We really need to get rid of this bi-directional links
+                * in proxies with something like static overrides.
+                */
+               newob->proxy->proxy_from = newob;
+
                /* depsgraph flushes are needed for the new data */
                DEG_relations_tag_update(bmain);
                DEG_id_tag_update(&newob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
@@ -913,12 +912,13 @@ static int parent_set_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent
 #if 0
        uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_OBJECT);
 #else
-       opptr = uiItemFullO_ptr(layout, ot, IFACE_("Object"), ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+       uiItemFullO_ptr(layout, ot, IFACE_("Object"), ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
        RNA_enum_set(&opptr, "type", PAR_OBJECT);
        RNA_boolean_set(&opptr, "keep_transform", false);
 
-       opptr = uiItemFullO_ptr(layout, ot, IFACE_("Object (Keep Transform)"), ICON_NONE, NULL, WM_OP_EXEC_DEFAULT,
-                               UI_ITEM_O_RETURN_PROPS);
+       uiItemFullO_ptr(
+               layout, ot, IFACE_("Object (Keep Transform)"), ICON_NONE,
+               NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
        RNA_enum_set(&opptr, "type", PAR_OBJECT);
        RNA_boolean_set(&opptr, "keep_transform", true);
 #endif
@@ -1361,7 +1361,7 @@ static int make_links_scene_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
 
-       if (ID_IS_LINKED_DATABLOCK(scene_to)) {
+       if (ID_IS_LINKED(scene_to)) {
                BKE_report(op->reports, RPT_ERROR, "Cannot link objects into a linked scene");
                return OPERATOR_CANCELLED;
        }
@@ -1474,7 +1474,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
                                        case MAKE_LINKS_ANIMDATA:
                                                BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, false);
                                                if (ob_dst->data && ob_src->data) {
-                                                       if (ID_IS_LINKED_DATABLOCK(obdata_id)) {
+                                                       if (ID_IS_LINKED(obdata_id)) {
                                                                is_lib = true;
                                                                break;
                                                        }
@@ -1516,7 +1516,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
                                                Curve *cu_src = ob_src->data;
                                                Curve *cu_dst = ob_dst->data;
 
-                                               if (ID_IS_LINKED_DATABLOCK(obdata_id)) {
+                                               if (ID_IS_LINKED(obdata_id)) {
                                                        is_lib = true;
                                                        break;
                                                }
@@ -1627,7 +1627,7 @@ void OBJECT_OT_make_links_data(wmOperatorType *ot)
 
 static Object *single_object_users_object(Main *bmain, Scene *scene, Object *ob, const bool copy_groups)
 {
-       if (!ID_IS_LINKED_DATABLOCK(ob) && ob->id.us > 1) {
+       if (!ID_IS_LINKED(ob) && ob->id.us > 1) {
                /* base gets copy of object */
                Object *obn = ID_NEW_SET(ob, BKE_object_copy(bmain, ob));
 
@@ -1697,8 +1697,8 @@ static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const in
        SceneCollection *msc = BKE_collection_master(scene);
        single_object_users_scene_collection(bmain, scene, msc, flag, copy_groups);
 
-       /* loop over SceneLayers and assign the pointers accordingly */
-       for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) {
+       /* loop over ViewLayers and assign the pointers accordingly */
+       for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) {
                for (Base *base = sl->object_bases.first; base; base = base->next) {
                        ID_NEW_REMAP(base->object);
                }
@@ -1765,7 +1765,7 @@ static void new_id_matar(Main *bmain, Material **matar, const int totcol)
 
        for (a = 0; a < totcol; a++) {
                id = (ID *)matar[a];
-               if (id && !ID_IS_LINKED_DATABLOCK(id)) {
+               if (id && !ID_IS_LINKED(id)) {
                        if (id->newid) {
                                matar[a] = (Material *)id->newid;
                                id_us_plus(id->newid);
@@ -1779,7 +1779,7 @@ static void new_id_matar(Main *bmain, Material **matar, const int totcol)
        }
 }
 
-static void single_obdata_users(Main *bmain, Scene *scene, SceneLayer *sl, const int flag)
+static void single_obdata_users(Main *bmain, Scene *scene, ViewLayer *sl, const int flag)
 {
        Lamp *la;
        Curve *cu;
@@ -1791,10 +1791,10 @@ static void single_obdata_users(Main *bmain, Scene *scene, SceneLayer *sl, const
 
        FOREACH_OBJECT_FLAG(scene, sl, flag, ob)
        {
-               if (!ID_IS_LINKED_DATABLOCK(ob)) {
+               if (!ID_IS_LINKED(ob)) {
                        id = ob->data;
 
-                       if (id && id->us > 1 && !ID_IS_LINKED_DATABLOCK(id)) {
+                       if (id && id->us > 1 && !ID_IS_LINKED(id)) {
                                DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
 
                                switch (ob->type) {
@@ -1866,24 +1866,24 @@ static void single_obdata_users(Main *bmain, Scene *scene, SceneLayer *sl, const
        }
 }
 
-static void single_object_action_users(Scene *scene, SceneLayer *sl, const int flag)
+static void single_object_action_users(Scene *scene, ViewLayer *sl, const int flag)
 {
        FOREACH_OBJECT_FLAG(scene, sl, flag, ob)
-               if (!ID_IS_LINKED_DATABLOCK(ob)) {
+               if (!ID_IS_LINKED(ob)) {
                        DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
                        BKE_animdata_copy_id_action(&ob->id, false);
                }
        FOREACH_OBJECT_FLAG_END
 }
 
-static void single_mat_users(Main *bmain, Scene *scene, SceneLayer *sl, const int flag, const bool do_textures)
+static void single_mat_users(Main *bmain, Scene *scene, ViewLayer *sl, const int flag, const bool do_textures)
 {
        Material *ma, *man;
        Tex *tex;
        int a, b;
 
        FOREACH_OBJECT_FLAG(scene, sl, flag, ob)
-               if (!ID_IS_LINKED_DATABLOCK(ob)) {
+               if (!ID_IS_LINKED(ob)) {
                        for (a = 1; a <= ob->totcol; a++) {
                                ma = give_current_material(ob, a);
                                if (ma) {
@@ -2037,12 +2037,13 @@ void ED_object_single_users(Main *bmain, Scene *scene, const bool full, const bo
        {
                IDP_RelinkProperty(scene->id.properties);
 
-               for (Base *base = scene->base.first; base; base = base->next) {
-                       Object *ob = base->object;
-                       if (!ID_IS_LINKED_DATABLOCK(ob)) {
+               FOREACH_SCENE_OBJECT(scene, ob)
+               {
+                       if (!ID_IS_LINKED(ob)) {
                                IDP_RelinkProperty(ob->id.properties);
                        }
                }
+               FOREACH_SCENE_OBJECT_END
 
                if (scene->nodetree) {
                        IDP_RelinkProperty(scene->nodetree->id.properties);
@@ -2131,19 +2132,19 @@ static void tag_localizable_objects(bContext *C, const int mode)
  * Instance indirectly referenced zero user objects,
  * otherwise they're lost on reload, see T40595.
  */
-static bool make_local_all__instance_indirect_unused(Main *bmain, Scene *scene, SceneLayer *sl, SceneCollection *sc)
+static bool make_local_all__instance_indirect_unused(Main *bmain, Scene *scene, ViewLayer *sl, SceneCollection *sc)
 {
        Object *ob;
        bool changed = false;
 
        for (ob = bmain->object.first; ob; ob = ob->id.next) {
-               if (ID_IS_LINKED_DATABLOCK(ob) && (ob->id.us == 0)) {
+               if (ID_IS_LINKED(ob) && (ob->id.us == 0)) {
                        Base *base;
 
                        id_us_plus(&ob->id);
 
                        BKE_collection_object_add(scene, sc, ob);
-                       base = BKE_scene_layer_base_find(sl, ob);
+                       base = BKE_view_layer_base_find(sl, ob);
                        base->flag |= BASE_SELECTED;
                        BKE_scene_object_base_flag_sync_from_base(base);
                        DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
@@ -2225,15 +2226,15 @@ static int make_local_exec(bContext *C, wmOperator *op)
 
        /* Note: we (ab)use LIB_TAG_PRE_EXISTING to cherry pick which ID to make local... */
        if (mode == MAKE_LOCAL_ALL) {
-               SceneLayer *sl = CTX_data_scene_layer(C);
-               SceneCollection *sc = CTX_data_scene_collection(C);
+               ViewLayer *view_layer = CTX_data_view_layer(C);
+               SceneCollection *scene_collection = CTX_data_scene_collection(C);
 
                BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
 
-               /* de-select so the user can differentiate newly instanced from existing objects */
-               BKE_scene_base_deselect_all(scene);
+               /* De-select so the user can differentiate newly instanced from existing objects. */
+               BKE_view_layer_base_deselect_all(view_layer);
 
-               if (make_local_all__instance_indirect_unused(bmain, scene, sl, sc)) {
+               if (make_local_all__instance_indirect_unused(bmain, scene, view_layer, scene_collection)) {
                        BKE_report(op->reports, RPT_INFO, "Orphan library objects added to the current scene to avoid loss");
                }
        }
@@ -2333,7 +2334,7 @@ static int make_single_user_exec(bContext *C, wmOperator *op)
 {
        Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
-       SceneLayer *sl = CTX_data_scene_layer(C);
+       ViewLayer *sl = CTX_data_view_layer(C);
        View3D *v3d = CTX_wm_view3d(C); /* ok if this is NULL */
        const int flag = (RNA_enum_get(op->ptr, "type") == MAKE_SINGLE_USER_SELECTED) ? SELECT : 0;
        const bool copy_groups = false;
@@ -2341,7 +2342,7 @@ static int make_single_user_exec(bContext *C, wmOperator *op)
 
        if (RNA_boolean_get(op->ptr, "object")) {
                if (flag == SELECT) {
-                       BKE_scene_layer_selected_objects_tag(sl, OB_DONE);
+                       BKE_view_layer_selected_objects_tag(sl, OB_DONE);
                        single_object_users(bmain, scene, v3d, OB_DONE, copy_groups);
                }
                else {
@@ -2412,7 +2413,7 @@ void OBJECT_OT_make_single_user(wmOperatorType *ot)
 
 static int drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
-       BaseLegacy *base = ED_view3d_give_base_under_cursor(C, event->mval);
+       Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
        Material *ma;
        char name[MAX_ID_NAME - 2];