Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / object / object_select.c
index 6b53807..bac1ba0 100644 (file)
 #include "DNA_group_types.h"
 #include "DNA_material_types.h"
 #include "DNA_modifier_types.h"
-#include "DNA_property_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_lamp_types.h"
+#include "DNA_workspace_types.h"
 
 #include "BLI_math.h"
 #include "BLI_listbase.h"
 
 #include "BLT_translation.h"
 
+#include "BKE_collection.h"
 #include "BKE_context.h"
-#include "BKE_group.h"
+#include "BKE_layer.h"
 #include "BKE_main.h"
 #include "BKE_material.h"
+#include "BKE_object.h"
 #include "BKE_particle.h"
-#include "BKE_property.h"
+#include "BKE_paint.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
+#include "BKE_workspace.h"
 #include "BKE_library.h"
 #include "BKE_deform.h"
 
+#include "DEG_depsgraph.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
 /* Note: send a NC_SCENE|ND_OB_SELECT notifier yourself! (or
  * or a NC_SCENE|ND_OB_VISIBLE in case of visibility toggling */
 
-void ED_base_object_select(Base *base, short mode)
+void ED_object_base_select(Base *base, eObjectSelect_Mode mode)
 {
+       if (mode == BA_INVERT) {
+               mode = (base->flag & BASE_SELECTED) != 0 ? BA_DESELECT : BA_SELECT;
+       }
+
        if (base) {
-               if (mode == BA_SELECT) {
-                       if (!(base->object->restrictflag & OB_RESTRICT_SELECT))
-                               base->flag |= SELECT;
-               }
-               else if (mode == BA_DESELECT) {
-                       base->flag &= ~SELECT;
+               switch (mode) {
+                       case BA_SELECT:
+                               if ((base->flag & BASE_SELECTABLED) != 0) {
+                                       base->flag |= BASE_SELECTED;
+                               }
+                               break;
+                       case BA_DESELECT:
+                               base->flag &= ~BASE_SELECTED;
+                               break;
+                       case BA_INVERT:
+                               /* Never happens. */
+                               break;
                }
-               base->object->flag = base->flag;
+               BKE_scene_object_base_flag_sync_from_base(base);
        }
 }
 
-/* also to set active NULL */
-void ED_base_object_activate(bContext *C, Base *base)
+/**
+ * Change active base, it includes the notifier
+ */
+void ED_object_base_activate(bContext *C, Base *base)
 {
-       Scene *scene = CTX_data_scene(C);
-
-       /* sets scene->basact */
-       BASACT = base;
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       view_layer->basact = base;
 
        if (base) {
-
-               /* XXX old signals, remember to handle notifiers now! */
-               //              select_actionchannel_by_name(base->object->action, "Object", 1);
-
-               WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
+               WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, view_layer);
        }
-       else
+       else {
                WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, NULL);
+       }
 }
 
 /********************** Selection Operators **********************/
@@ -147,7 +159,7 @@ static int object_select_by_type_exec(bContext *C, wmOperator *op)
        if (extend == 0) {
                CTX_DATA_BEGIN (C, Base *, base, visible_bases)
                {
-                       ED_base_object_select(base, BA_DESELECT);
+                       ED_object_base_select(base, BA_DESELECT);
                }
                CTX_DATA_END;
        }
@@ -155,7 +167,7 @@ static int object_select_by_type_exec(bContext *C, wmOperator *op)
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
                if (base->object->type == obtype) {
-                       ED_base_object_select(base, BA_SELECT);
+                       ED_object_base_select(base, BA_SELECT);
                }
        }
        CTX_DATA_END;
@@ -191,7 +203,6 @@ enum {
        OBJECT_SELECT_LINKED_IPO = 1,
        OBJECT_SELECT_LINKED_OBDATA,
        OBJECT_SELECT_LINKED_MATERIAL,
-       OBJECT_SELECT_LINKED_TEXTURE,
        OBJECT_SELECT_LINKED_DUPGROUP,
        OBJECT_SELECT_LINKED_PARTICLE,
        OBJECT_SELECT_LINKED_LIBRARY,
@@ -202,7 +213,6 @@ static const EnumPropertyItem prop_select_linked_types[] = {
        //{OBJECT_SELECT_LINKED_IPO, "IPO", 0, "Object IPO", ""}, // XXX deprecated animation system stuff...
        {OBJECT_SELECT_LINKED_OBDATA, "OBDATA", 0, "Object Data", ""},
        {OBJECT_SELECT_LINKED_MATERIAL, "MATERIAL", 0, "Material", ""},
-       {OBJECT_SELECT_LINKED_TEXTURE, "TEXTURE", 0, "Texture", ""},
        {OBJECT_SELECT_LINKED_DUPGROUP, "DUPGROUP", 0, "Dupligroup", ""},
        {OBJECT_SELECT_LINKED_PARTICLE, "PARTICLE", 0, "Particle System", ""},
        {OBJECT_SELECT_LINKED_LIBRARY, "LIBRARY", 0, "Library", ""},
@@ -210,38 +220,15 @@ static const EnumPropertyItem prop_select_linked_types[] = {
        {0, NULL, 0, NULL, NULL}
 };
 
-// XXX old animation system
-#if 0
-static int object_select_all_by_ipo(bContext *C, Ipo *ipo)
-{
-       bool changed = false;
-
-       CTX_DATA_BEGIN (C, Base *, base, visible_bases)
-       {
-               if (base->object->ipo == ipo) {
-                       base->flag |= SELECT;
-                       base->object->flag = base->flag;
-
-                       changed = true;
-               }
-       }
-       CTX_DATA_END;
-
-       return changed;
-}
-#endif
-
 static bool object_select_all_by_obdata(bContext *C, void *obdata)
 {
        bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
-               if ((base->flag & SELECT) == 0) {
+               if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
                        if (base->object->data == obdata) {
-                               base->flag |= SELECT;
-                               base->object->flag = base->flag;
-
+                               ED_object_base_select(base, BA_SELECT);
                                changed = true;
                        }
                }
@@ -251,40 +238,25 @@ static bool object_select_all_by_obdata(bContext *C, void *obdata)
        return changed;
 }
 
-static bool object_select_all_by_material_texture(bContext *C, int use_texture, Material *mat, Tex *tex)
+static bool object_select_all_by_material(bContext *C, Material *mat)
 {
        bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
-               if ((base->flag & SELECT) == 0) {
+               if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
                        Object *ob = base->object;
                        Material *mat1;
-                       int a, b;
+                       int a;
 
                        for (a = 1; a <= ob->totcol; a++) {
                                mat1 = give_current_material(ob, a);
 
-                               if (!use_texture) {
-                                       if (mat1 == mat) {
-                                               base->flag |= SELECT;
-                                               changed = true;
-                                       }
-                               }
-                               else if (mat1 && use_texture) {
-                                       for (b = 0; b < MAX_MTEX; b++) {
-                                               if (mat1->mtex[b]) {
-                                                       if (tex == mat1->mtex[b]->tex) {
-                                                               base->flag |= SELECT;
-                                                               changed = true;
-                                                               break;
-                                                       }
-                                               }
-                                       }
+                               if (mat1 == mat) {
+                                       ED_object_base_select(base, BA_SELECT);
+                                       changed = true;
                                }
                        }
-
-                       base->object->flag = base->flag;
                }
        }
        CTX_DATA_END;
@@ -295,16 +267,14 @@ static bool object_select_all_by_material_texture(bContext *C, int use_texture,
 static bool object_select_all_by_dup_group(bContext *C, Object *ob)
 {
        bool changed = false;
-       Group *dup_group = (ob->transflag & OB_DUPLIGROUP) ? ob->dup_group : NULL;
+       Collection *dup_group = (ob->transflag & OB_DUPLICOLLECTION) ? ob->dup_group : NULL;
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
-               if ((base->flag & SELECT) == 0) {
-                       Group *dup_group_other = (base->object->transflag & OB_DUPLIGROUP) ? base->object->dup_group : NULL;
+               if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
+                       Collection *dup_group_other = (base->object->transflag & OB_DUPLICOLLECTION) ? base->object->dup_group : NULL;
                        if (dup_group == dup_group_other) {
-                               base->flag |= SELECT;
-                               base->object->flag = base->flag;
-
+                               ED_object_base_select(base, BA_SELECT);
                                changed = true;
                        }
                }
@@ -321,23 +291,21 @@ static bool object_select_all_by_particle(bContext *C, Object *ob)
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
-               if ((base->flag & SELECT) == 0) {
+               if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
                        /* loop through other particles*/
                        ParticleSystem *psys;
 
                        for (psys = base->object->particlesystem.first; psys; psys = psys->next) {
                                if (psys->part == psys_act->part) {
-                                       base->flag |= SELECT;
+                                       ED_object_base_select(base, BA_SELECT);
                                        changed = true;
                                        break;
                                }
 
-                               if (base->flag & SELECT) {
+                               if (base->flag & BASE_SELECTED) {
                                        break;
                                }
                        }
-
-                       base->object->flag = base->flag;
                }
        }
        CTX_DATA_END;
@@ -351,11 +319,9 @@ static bool object_select_all_by_library(bContext *C, Library *lib)
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
-               if ((base->flag & SELECT) == 0) {
+               if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
                        if (lib == base->object->id.lib) {
-                               base->flag |= SELECT;
-                               base->object->flag = base->flag;
-
+                               ED_object_base_select(base, BA_SELECT);
                                changed = true;
                        }
                }
@@ -371,11 +337,9 @@ static bool object_select_all_by_library_obdata(bContext *C, Library *lib)
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
-               if ((base->flag & SELECT) == 0) {
+               if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
                        if (base->object->data && lib == ((ID *)base->object->data)->lib) {
-                               base->flag |= SELECT;
-                               base->object->flag = base->flag;
-
+                               ED_object_base_select(base, BA_SELECT);
                                changed = true;
                        }
                }
@@ -394,7 +358,7 @@ void ED_object_select_linked_by_id(bContext *C, ID *id)
                changed = object_select_all_by_obdata(C, id);
        }
        else if (idtype == ID_MA) {
-               changed = object_select_all_by_material_texture(C, false, (Material *)id, NULL);
+               changed = object_select_all_by_material(C, (Material *)id);
        }
        else if (idtype == ID_LI) {
                changed = object_select_all_by_library(C, (Library *) id);
@@ -408,6 +372,7 @@ void ED_object_select_linked_by_id(bContext *C, ID *id)
 static int object_select_linked_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        Object *ob;
        int nr = RNA_enum_get(op->ptr, "type");
        bool changed = false, extend;
@@ -417,12 +382,12 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
        if (extend == 0) {
                CTX_DATA_BEGIN (C, Base *, base, visible_bases)
                {
-                       ED_base_object_select(base, BA_DESELECT);
+                       ED_object_base_select(base, BA_DESELECT);
                }
                CTX_DATA_END;
        }
 
-       ob = OBACT;
+       ob = OBACT(view_layer);
        if (ob == NULL) {
                BKE_report(op->reports, RPT_ERROR, "No active object");
                return OPERATOR_CANCELLED;
@@ -440,21 +405,13 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
 
                changed = object_select_all_by_obdata(C, ob->data);
        }
-       else if (nr == OBJECT_SELECT_LINKED_MATERIAL || nr == OBJECT_SELECT_LINKED_TEXTURE) {
+       else if (nr == OBJECT_SELECT_LINKED_MATERIAL) {
                Material *mat = NULL;
-               Tex *tex = NULL;
-               bool use_texture = false;
 
                mat = give_current_material(ob, ob->actcol);
                if (mat == NULL) return OPERATOR_CANCELLED;
-               if (nr == OBJECT_SELECT_LINKED_TEXTURE) {
-                       use_texture = true;
 
-                       if (mat->mtex[(int)mat->texact]) tex = mat->mtex[(int)mat->texact]->tex;
-                       if (tex == NULL) return OPERATOR_CANCELLED;
-               }
-
-               changed = object_select_all_by_material_texture(C, use_texture, mat, tex);
+               changed = object_select_all_by_material(C, mat);
        }
        else if (nr == OBJECT_SELECT_LINKED_DUPGROUP) {
                if (ob->dup_group == NULL)
@@ -517,14 +474,12 @@ enum {
        OBJECT_GRPSEL_PARENT             =  2,
        OBJECT_GRPSEL_SIBLINGS           =  3,
        OBJECT_GRPSEL_TYPE               =  4,
-       OBJECT_GRPSEL_LAYER              =  5,
-       OBJECT_GRPSEL_GROUP              =  6,
+       OBJECT_GRPSEL_COLLECTION         =  5,
        OBJECT_GRPSEL_HOOK               =  7,
        OBJECT_GRPSEL_PASS               =  8,
        OBJECT_GRPSEL_COLOR              =  9,
-       OBJECT_GRPSEL_PROPERTIES         = 10,
-       OBJECT_GRPSEL_KEYINGSET          = 11,
-       OBJECT_GRPSEL_LAMP_TYPE          = 12,
+       OBJECT_GRPSEL_KEYINGSET          = 10,
+       OBJECT_GRPSEL_LAMP_TYPE          = 11,
 };
 
 static const EnumPropertyItem prop_select_grouped_types[] = {
@@ -533,12 +488,10 @@ static const EnumPropertyItem prop_select_grouped_types[] = {
        {OBJECT_GRPSEL_PARENT, "PARENT", 0, "Parent", ""},
        {OBJECT_GRPSEL_SIBLINGS, "SIBLINGS", 0, "Siblings", "Shared Parent"},
        {OBJECT_GRPSEL_TYPE, "TYPE", 0, "Type", "Shared object type"},
-       {OBJECT_GRPSEL_LAYER, "LAYER", 0, "Layer", "Shared layers"},
-       {OBJECT_GRPSEL_GROUP, "GROUP", 0, "Group", "Shared group"},
+       {OBJECT_GRPSEL_COLLECTION, "COLLECTION", 0, "Collection", "Shared collection"},
        {OBJECT_GRPSEL_HOOK, "HOOK", 0, "Hook", ""},
        {OBJECT_GRPSEL_PASS, "PASS", 0, "Pass", "Render pass Index"},
        {OBJECT_GRPSEL_COLOR, "COLOR", 0, "Color", "Object Color"},
-       {OBJECT_GRPSEL_PROPERTIES, "PROPERTIES", 0, "Properties", "Game Properties"},
        {OBJECT_GRPSEL_KEYINGSET, "KEYINGSET", 0, "Keying Set", "Objects included in active Keying Set"},
        {OBJECT_GRPSEL_LAMP_TYPE, "LAMP_TYPE", 0, "Lamp Type", "Matching lamp types"},
        {0, NULL, 0, NULL, NULL}
@@ -551,13 +504,14 @@ static bool select_grouped_children(bContext *C, Object *ob, const bool recursiv
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
                if (ob == base->object->parent) {
-                       if (!(base->flag & SELECT)) {
-                               ED_base_object_select(base, BA_SELECT);
+                       if ((base->flag & BASE_SELECTED) == 0) {
+                               ED_object_base_select(base, BA_SELECT);
                                changed = true;
                        }
 
-                       if (recursive)
+                       if (recursive) {
                                changed |= select_grouped_children(C, base->object, 1);
+                       }
                }
        }
        CTX_DATA_END;
@@ -566,51 +520,53 @@ static bool select_grouped_children(bContext *C, Object *ob, const bool recursiv
 
 static bool select_grouped_parent(bContext *C) /* Makes parent active and de-selected OBACT */
 {
-       Scene *scene = CTX_data_scene(C);
-       View3D *v3d = CTX_wm_view3d(C);
-
-       bool changed = false;
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        Base *baspar, *basact = CTX_data_active_base(C);
+       bool changed = false;
 
-       if (!basact || !(basact->object->parent)) return 0;  /* we know OBACT is valid */
+       if (!basact || !(basact->object->parent)) {
+               return 0;  /* we know OBACT is valid */
+       }
 
-       baspar = BKE_scene_base_find(scene, basact->object->parent);
+       baspar = BKE_view_layer_base_find(view_layer, basact->object->parent);
 
        /* can be NULL if parent in other scene */
-       if (baspar && BASE_SELECTABLE(v3d, baspar)) {
-               ED_base_object_select(baspar, BA_SELECT);
-               ED_base_object_activate(C, baspar);
+       if (baspar && BASE_SELECTABLE(baspar)) {
+               ED_object_base_select(baspar, BA_SELECT);
+               ED_object_base_activate(C, baspar);
                changed = true;
        }
        return changed;
 }
 
 
-#define GROUP_MENU_MAX  24
-static bool select_grouped_group(bContext *C, Object *ob)  /* Select objects in the same group as the active */
+#define COLLECTION_MENU_MAX  24
+static bool select_grouped_collection(bContext *C, Object *ob)  /* Select objects in the same group as the active */
 {
        bool changed = false;
-       Group *group, *ob_groups[GROUP_MENU_MAX];
-       int group_count = 0, i;
+       Collection *collection, *ob_collections[COLLECTION_MENU_MAX];
+       int collection_count = 0, i;
        uiPopupMenu *pup;
        uiLayout *layout;
 
-       for (group = CTX_data_main(C)->group.first; group && group_count < GROUP_MENU_MAX; group = group->id.next) {
-               if (BKE_group_object_exists(group, ob)) {
-                       ob_groups[group_count] = group;
-                       group_count++;
+       for (collection = CTX_data_main(C)->collection.first; collection && collection_count < COLLECTION_MENU_MAX; collection = collection->id.next) {
+               if (BKE_collection_has_object(collection, ob)) {
+                       ob_collections[collection_count] = collection;
+                       collection_count++;
                }
        }
 
-       if (!group_count)
+       if (!collection_count)
                return 0;
-       else if (group_count == 1) {
-               group = ob_groups[0];
+       else if (collection_count == 1) {
+               collection = ob_collections[0];
                CTX_DATA_BEGIN (C, Base *, base, visible_bases)
                {
-                       if (!(base->flag & SELECT) && BKE_group_object_exists(group, base->object)) {
-                               ED_base_object_select(base, BA_SELECT);
-                               changed = true;
+                       if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
+                               if (BKE_collection_has_object(collection, base->object)) {
+                                       ED_object_base_select(base, BA_SELECT);
+                                       changed = true;
+                               }
                        }
                }
                CTX_DATA_END;
@@ -618,12 +574,12 @@ static bool select_grouped_group(bContext *C, Object *ob)  /* Select objects in
        }
 
        /* build the menu. */
-       pup = UI_popup_menu_begin(C, IFACE_("Select Group"), ICON_NONE);
+       pup = UI_popup_menu_begin(C, IFACE_("Select Collection"), ICON_NONE);
        layout = UI_popup_menu_layout(pup);
 
-       for (i = 0; i < group_count; i++) {
-               group = ob_groups[i];
-               uiItemStringO(layout, group->id.name + 2, 0, "OBJECT_OT_select_same_group", "group", group->id.name + 2);
+       for (i = 0; i < collection_count; i++) {
+               collection = ob_collections[i];
+               uiItemStringO(layout, collection->id.name + 2, 0, "OBJECT_OT_select_same_collection", "collection", collection->id.name + 2);
        }
 
        UI_popup_menu_end(C, pup);
@@ -632,8 +588,7 @@ static bool select_grouped_group(bContext *C, Object *ob)  /* Select objects in
 
 static bool select_grouped_object_hooks(bContext *C, Object *ob)
 {
-       Scene *scene = CTX_data_scene(C);
-       View3D *v3d = CTX_wm_view3d(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
        bool changed = false;
        Base *base;
@@ -643,10 +598,10 @@ static bool select_grouped_object_hooks(bContext *C, Object *ob)
        for (md = ob->modifiers.first; md; md = md->next) {
                if (md->type == eModifierType_Hook) {
                        hmd = (HookModifierData *) md;
-                       if (hmd->object && !(hmd->object->flag & SELECT)) {
-                               base = BKE_scene_base_find(scene, hmd->object);
-                               if (base && (BASE_SELECTABLE(v3d, base))) {
-                                       ED_base_object_select(base, BA_SELECT);
+                       if (hmd->object) {
+                               base = BKE_view_layer_base_find(view_layer, hmd->object);
+                               if (base && ((base->flag & BASE_SELECTED) == 0) && (BASE_SELECTABLE(base))) {
+                                       ED_object_base_select(base, BA_SELECT);
                                        changed = true;
                                }
                        }
@@ -663,8 +618,8 @@ static bool select_grouped_siblings(bContext *C, Object *ob)
 
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
-               if ((base->object->parent == ob->parent) && !(base->flag & SELECT)) {
-                       ED_base_object_select(base, BA_SELECT);
+               if ((base->object->parent == ob->parent) && ((base->flag & BASE_SELECTED) == 0)) {
+                       ED_object_base_select(base, BA_SELECT);
                        changed = true;
                }
        }
@@ -681,8 +636,8 @@ static bool select_grouped_lamptype(bContext *C, Object *ob)
        {
                if (base->object->type == OB_LAMP) {
                        Lamp *la_test = base->object->data;
-                       if ((la->type == la_test->type) && !(base->flag & SELECT)) {
-                               ED_base_object_select(base, BA_SELECT);
+                       if ((la->type == la_test->type) && ((base->flag & BASE_SELECTED) == 0)) {
+                               ED_object_base_select(base, BA_SELECT);
                                changed = true;
                        }
                }
@@ -696,23 +651,8 @@ static bool select_grouped_type(bContext *C, Object *ob)
 
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
-               if ((base->object->type == ob->type) && !(base->flag & SELECT)) {
-                       ED_base_object_select(base, BA_SELECT);
-                       changed = true;
-               }
-       }
-       CTX_DATA_END;
-       return changed;
-}
-
-static bool select_grouped_layer(bContext *C, Object *ob)
-{
-       bool changed = false;
-
-       CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
-       {
-               if ((base->lay & ob->lay) && !(base->flag & SELECT)) {
-                       ED_base_object_select(base, BA_SELECT);
+               if ((base->object->type == ob->type) && ((base->flag & BASE_SELECTED) == 0)) {
+                       ED_object_base_select(base, BA_SELECT);
                        changed = true;
                }
        }
@@ -726,8 +666,8 @@ static bool select_grouped_index_object(bContext *C, Object *ob)
 
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
-               if ((base->object->index == ob->index) && !(base->flag & SELECT)) {
-                       ED_base_object_select(base, BA_SELECT);
+               if ((base->object->index == ob->index) && ((base->flag & BASE_SELECTED) == 0)) {
+                       ED_object_base_select(base, BA_SELECT);
                        changed = true;
                }
        }
@@ -741,35 +681,8 @@ static bool select_grouped_color(bContext *C, Object *ob)
 
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
-               if (!(base->flag & SELECT) && (compare_v3v3(base->object->col, ob->col, 0.005f))) {
-                       ED_base_object_select(base, BA_SELECT);
-                       changed = true;
-               }
-       }
-       CTX_DATA_END;
-       return changed;
-}
-
-static bool objects_share_gameprop(Object *a, Object *b)
-{
-       bProperty *prop;
-
-       for (prop = a->prop.first; prop; prop = prop->next) {
-               if (BKE_bproperty_object_get(b, prop->name)) {
-                       return 1;
-               }
-       }
-       return 0;
-}
-
-static bool select_grouped_gameprops(bContext *C, Object *ob)
-{
-       bool changed = false;
-
-       CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
-       {
-               if (!(base->flag & SELECT) && (objects_share_gameprop(base->object, ob))) {
-                       ED_base_object_select(base, BA_SELECT);
+               if (((base->flag & BASE_SELECTED) == 0) && (compare_v3v3(base->object->col, ob->col, 0.005f))) {
+                       ED_object_base_select(base, BA_SELECT);
                        changed = true;
                }
        }
@@ -807,7 +720,7 @@ static bool select_grouped_keyingset(bContext *C, Object *UNUSED(ob), ReportList
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
                /* only check for this object if it isn't selected already, to limit time wasted */
-               if ((base->flag & SELECT) == 0) {
+               if ((base->flag & BASE_SELECTED) == 0) {
                        KS_Path *ksp;
 
                        /* this is the slow way... we could end up with > 500 items here,
@@ -816,7 +729,7 @@ static bool select_grouped_keyingset(bContext *C, Object *UNUSED(ob), ReportList
                        for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
                                /* if id matches, select then stop looping (match found) */
                                if (ksp->id == (ID *)base->object) {
-                                       ED_base_object_select(base, BA_SELECT);
+                                       ED_object_base_select(base, BA_SELECT);
                                        changed = true;
                                        break;
                                }
@@ -831,6 +744,7 @@ static bool select_grouped_keyingset(bContext *C, Object *UNUSED(ob), ReportList
 static int object_select_grouped_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        Object *ob;
        const int type = RNA_enum_get(op->ptr, "type");
        bool changed = false, extend;
@@ -840,13 +754,13 @@ static int object_select_grouped_exec(bContext *C, wmOperator *op)
        if (extend == 0) {
                CTX_DATA_BEGIN (C, Base *, base, visible_bases)
                {
-                       ED_base_object_select(base, BA_DESELECT);
+                       ED_object_base_select(base, BA_DESELECT);
                        changed = true;
                }
                CTX_DATA_END;
        }
 
-       ob = OBACT;
+       ob = OBACT(view_layer);
        if (ob == NULL) {
                BKE_report(op->reports, RPT_ERROR, "No active object");
                return OPERATOR_CANCELLED;
@@ -868,11 +782,8 @@ static int object_select_grouped_exec(bContext *C, wmOperator *op)
                case OBJECT_GRPSEL_TYPE:
                        changed |= select_grouped_type(C, ob);
                        break;
-               case OBJECT_GRPSEL_LAYER:
-                       changed |= select_grouped_layer(C, ob);
-                       break;
-               case OBJECT_GRPSEL_GROUP:
-                       changed |= select_grouped_group(C, ob);
+               case OBJECT_GRPSEL_COLLECTION:
+                       changed |= select_grouped_collection(C, ob);
                        break;
                case OBJECT_GRPSEL_HOOK:
                        changed |= select_grouped_object_hooks(C, ob);
@@ -883,9 +794,6 @@ static int object_select_grouped_exec(bContext *C, wmOperator *op)
                case OBJECT_GRPSEL_COLOR:
                        changed |= select_grouped_color(C, ob);
                        break;
-               case OBJECT_GRPSEL_PROPERTIES:
-                       changed |= select_grouped_gameprops(C, ob);
-                       break;
                case OBJECT_GRPSEL_KEYINGSET:
                        changed |= select_grouped_keyingset(C, ob, op->reports);
                        break;
@@ -928,85 +836,6 @@ void OBJECT_OT_select_grouped(wmOperatorType *ot)
        ot->prop = RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", "");
 }
 
-/************************* Select by Layer **********************/
-enum {
-       OB_SEL_LAYERMATCH_EXACT = 1,
-       OB_SEL_LAYERMATCH_SHARED = 2,
-};
-
-static int object_select_by_layer_exec(bContext *C, wmOperator *op)
-{
-       unsigned int layernum;
-       bool extend;
-       int match;
-
-       extend = RNA_boolean_get(op->ptr, "extend");
-       layernum = RNA_int_get(op->ptr, "layers");
-       match = RNA_enum_get(op->ptr, "match");
-
-       if (extend == false) {
-               CTX_DATA_BEGIN (C, Base *, base, visible_bases)
-               {
-                       ED_base_object_select(base, BA_DESELECT);
-               }
-               CTX_DATA_END;
-       }
-
-       CTX_DATA_BEGIN (C, Base *, base, visible_bases)
-       {
-               bool ok = false;
-
-               switch (match) {
-                       case OB_SEL_LAYERMATCH_EXACT:
-                               /* Mask out bits used for local view, only work on real layer ones, see T45783. */
-                               ok = ((base->lay & ((1 << 20) - 1)) == (1 << (layernum - 1)));
-                               break;
-                       case OB_SEL_LAYERMATCH_SHARED:
-                               ok = (base->lay & (1 << (layernum - 1))) != 0;
-                               break;
-                       default:
-                               break;
-               }
-
-               if (ok) {
-                       ED_base_object_select(base, BA_SELECT);
-               }
-       }
-       CTX_DATA_END;
-
-       /* undo? */
-       WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
-
-       return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_select_by_layer(wmOperatorType *ot)
-{
-       static const EnumPropertyItem match_items[] = {
-               {OB_SEL_LAYERMATCH_EXACT, "EXACT", 0, "Exact Match", ""},
-               {OB_SEL_LAYERMATCH_SHARED, "SHARED", 0, "Shared Layers", ""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       /* identifiers */
-       ot->name = "Select by Layer";
-       ot->description = "Select all visible objects on a layer";
-       ot->idname = "OBJECT_OT_select_by_layer";
-
-       /* api callbacks */
-       /*ot->invoke = XXX - need a int grid popup*/
-       ot->exec = object_select_by_layer_exec;
-       ot->poll = objects_selectable_poll;
-
-       /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-       /* properties */
-       RNA_def_enum(ot->srna, "match", match_items, OB_SEL_LAYERMATCH_EXACT, "Match", "");
-       RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend selection instead of deselecting everything first");
-       RNA_def_int(ot->srna, "layers", 1, 1, 20, "Layer", "", 1, 20);
-}
-
 /**************************** (De)select All ****************************/
 
 static int object_select_all_exec(bContext *C, wmOperator *op)
@@ -1020,7 +849,7 @@ static int object_select_all_exec(bContext *C, wmOperator *op)
                action = SEL_SELECT;
                CTX_DATA_BEGIN (C, Base *, base, visible_bases)
                {
-                       if (base->flag & SELECT) {
+                       if ((base->flag & BASE_SELECTED) != 0) {
                                action = SEL_DESELECT;
                                break;
                        }
@@ -1032,17 +861,17 @@ static int object_select_all_exec(bContext *C, wmOperator *op)
        {
                switch (action) {
                        case SEL_SELECT:
-                               ED_base_object_select(base, BA_SELECT);
+                               ED_object_base_select(base, BA_SELECT);
                                break;
                        case SEL_DESELECT:
-                               ED_base_object_select(base, BA_DESELECT);
+                               ED_object_base_select(base, BA_DESELECT);
                                break;
                        case SEL_INVERT:
-                               if (base->flag & SELECT) {
-                                       ED_base_object_select(base, BA_DESELECT);
+                               if ((base->flag & BASE_SELECTED) != 0) {
+                                       ED_object_base_select(base, BA_DESELECT);
                                }
                                else {
-                                       ED_base_object_select(base, BA_SELECT);
+                                       ED_object_base_select(base, BA_SELECT);
                                }
                                break;
                }
@@ -1072,29 +901,32 @@ void OBJECT_OT_select_all(wmOperatorType *ot)
        WM_operator_properties_select_all(ot);
 }
 
-/**************************** Select In The Same Group ****************************/
+/**************************** Select In The Same Collection ****************************/
 
-static int object_select_same_group_exec(bContext *C, wmOperator *op)
+static int object_select_same_collection_exec(bContext *C, wmOperator *op)
 {
        Main *bmain = CTX_data_main(C);
-       Group *group;
-       char group_name[MAX_ID_NAME];
+       Collection *collection;
+       char collection_name[MAX_ID_NAME];
 
        /* passthrough if no objects are visible */
        if (CTX_DATA_COUNT(C, visible_bases) == 0) return OPERATOR_PASS_THROUGH;
 
-       RNA_string_get(op->ptr, "group", group_name);
+       RNA_string_get(op->ptr, "collection", collection_name);
 
-       group = (Group *)BKE_libblock_find_name(bmain, ID_GR, group_name);
+       collection = (Collection *)BKE_libblock_find_name(bmain, ID_GR, collection_name);
 
-       if (!group) {
+       if (!collection) {
                return OPERATOR_PASS_THROUGH;
        }
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
-               if (!(base->flag & SELECT) && BKE_group_object_exists(group, base->object))
-                       ED_base_object_select(base, BA_SELECT);
+               if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
+                       if (BKE_collection_has_object(collection, base->object)) {
+                               ED_object_base_select(base, BA_SELECT);
+                       }
+               }
        }
        CTX_DATA_END;
 
@@ -1103,22 +935,22 @@ static int object_select_same_group_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_select_same_group(wmOperatorType *ot)
+void OBJECT_OT_select_same_collection(wmOperatorType *ot)
 {
 
        /* identifiers */
-       ot->name = "Select Same Group";
-       ot->description = "Select object in the same group";
-       ot->idname = "OBJECT_OT_select_same_group";
+       ot->name = "Select Same Collection";
+       ot->description = "Select object in the same collection";
+       ot->idname = "OBJECT_OT_select_same_collection";
 
        /* api callbacks */
-       ot->exec = object_select_same_group_exec;
+       ot->exec = object_select_same_collection_exec;
        ot->poll = objects_selectable_poll;
 
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
-       RNA_def_string(ot->srna, "group", NULL, MAX_ID_NAME, "Group", "Name of the group to select");
+       RNA_def_string(ot->srna, "collection", NULL, MAX_ID_NAME, "Collection", "Name of the collection to select");
 }
 
 /**************************** Select Mirror ****************************/
@@ -1126,6 +958,7 @@ static int object_select_mirror_exec(bContext *C, wmOperator *op)
 {
        Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        bool extend;
 
        extend = RNA_boolean_get(op->ptr, "extend");
@@ -1139,15 +972,15 @@ static int object_select_mirror_exec(bContext *C, wmOperator *op)
                if (!STREQ(name_flip, primbase->object->id.name + 2)) {
                        Object *ob = (Object *)BKE_libblock_find_name(bmain, ID_OB, name_flip);
                        if (ob) {
-                               Base *secbase = BKE_scene_base_find(scene, ob);
+                               Base *secbase = BKE_view_layer_base_find(view_layer, ob);
 
                                if (secbase) {
-                                       ED_base_object_select(secbase, BA_SELECT);
+                                       ED_object_base_select(secbase, BA_SELECT);
                                }
                        }
                }
 
-               if (extend == false) ED_base_object_select(primbase, BA_DESELECT);
+               if (extend == false) ED_object_base_select(primbase, BA_DESELECT);
 
        }
        CTX_DATA_END;
@@ -1182,9 +1015,9 @@ void OBJECT_OT_select_mirror(wmOperatorType *ot)
 
 static bool object_select_more_less(bContext *C, const bool select)
 {
-       Scene *scene = CTX_data_scene(C);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
-       for (Base *base = scene->base.first; base; base = base->next) {
+       for (Base *base = view_layer->object_bases.first; base; base = base->next) {
                Object *ob = base->object;
                ob->flag &= ~OB_DONE;
                ob->id.tag &= ~LIB_TAG_DOIT;
@@ -1219,13 +1052,13 @@ static bool object_select_more_less(bContext *C, const bool select)
 
        bool changed = false;
        const short select_mode = select ? BA_SELECT : BA_DESELECT;
-       const short select_flag = select ? SELECT : 0;
+       const short select_flag = select ? BASE_SELECTED : 0;
 
        for (ctx_base = ctx_base_list.first; ctx_base; ctx_base = ctx_base->next) {
                Base *base = ctx_base->ptr.data;
                Object *ob = base->object;
-               if ((ob->id.tag & LIB_TAG_DOIT) && ((ob->flag & SELECT) != select_flag)) {
-                       ED_base_object_select(base, select_mode);
+               if ((ob->id.tag & LIB_TAG_DOIT) && ((base->flag & BASE_SELECTED) != select_flag)) {
+                       ED_object_base_select(base, select_mode);
                        changed = true;
                }
        }
@@ -1307,7 +1140,7 @@ static int object_select_random_exec(bContext *C, wmOperator *op)
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
                if (BLI_rng_get_float(rng) < randfac) {
-                       ED_base_object_select(base, select);
+                       ED_object_base_select(base, select);
                }
        }
        CTX_DATA_END;