Cleanup: use `rna_enum_` prefix for RNA enums
[blender.git] / source / blender / editors / object / object_select.c
index ff7728d4f68d422c8e8364a4e7118a9b9afa3136..3b02b13e5360f2bbe8f1df58ed3898e7b880880c 100644 (file)
@@ -33,8 +33,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "MEM_guardedalloc.h"
-
 #include "DNA_anim_types.h"
 #include "DNA_group_types.h"
 #include "DNA_material_types.h"
 #include "DNA_property_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_armature_types.h"
+#include "DNA_lamp_types.h"
 
 #include "BLI_math.h"
 #include "BLI_listbase.h"
 #include "BLI_rand.h"
-#include "BLI_string.h"
 #include "BLI_utildefines.h"
 
+#include "BLT_translation.h"
+
 #include "BKE_context.h"
 #include "BKE_group.h"
 #include "BKE_main.h"
@@ -180,8 +180,8 @@ void OBJECT_OT_select_by_type(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_boolean(ot->srna, "extend", FALSE, "Extend", "Extend selection instead of deselecting everything first");
-       ot->prop = RNA_def_enum(ot->srna, "type", object_type_items, 1, "Type", "");
+       RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend selection instead of deselecting everything first");
+       ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_type_items, 1, "Type", "");
 }
 
 /*********************** Selection by Links *********************/
@@ -198,7 +198,7 @@ enum {
 };
 
 static EnumPropertyItem prop_select_linked_types[] = {
-       //{OBJECT_SELECT_LINKED_IPO, "IPO", 0, "Object IPO", ""}, // XXX depreceated animation system stuff...
+       //{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", ""},
@@ -213,7 +213,7 @@ static EnumPropertyItem prop_select_linked_types[] = {
 #if 0
 static int object_select_all_by_ipo(bContext *C, Ipo *ipo)
 {
-       int changed = FALSE;
+       bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
@@ -221,7 +221,7 @@ static int object_select_all_by_ipo(bContext *C, Ipo *ipo)
                        base->flag |= SELECT;
                        base->object->flag = base->flag;
 
-                       changed = TRUE;
+                       changed = true;
                }
        }
        CTX_DATA_END;
@@ -230,9 +230,9 @@ static int object_select_all_by_ipo(bContext *C, Ipo *ipo)
 }
 #endif
 
-static int object_select_all_by_obdata(bContext *C, void *obdata)
+static bool object_select_all_by_obdata(bContext *C, void *obdata)
 {
-       int changed = FALSE;
+       bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
@@ -241,7 +241,7 @@ static int object_select_all_by_obdata(bContext *C, void *obdata)
                                base->flag |= SELECT;
                                base->object->flag = base->flag;
 
-                               changed = TRUE;
+                               changed = true;
                        }
                }
        }
@@ -250,9 +250,9 @@ static int object_select_all_by_obdata(bContext *C, void *obdata)
        return changed;
 }
 
-static int object_select_all_by_material_texture(bContext *C, int use_texture, Material *mat, Tex *tex)
+static bool object_select_all_by_material_texture(bContext *C, int use_texture, Material *mat, Tex *tex)
 {
-       int changed = FALSE;
+       bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
@@ -267,7 +267,7 @@ static int object_select_all_by_material_texture(bContext *C, int use_texture, M
                                if (!use_texture) {
                                        if (mat1 == mat) {
                                                base->flag |= SELECT;
-                                               changed = TRUE;
+                                               changed = true;
                                        }
                                }
                                else if (mat1 && use_texture) {
@@ -275,7 +275,7 @@ static int object_select_all_by_material_texture(bContext *C, int use_texture, M
                                                if (mat1->mtex[b]) {
                                                        if (tex == mat1->mtex[b]->tex) {
                                                                base->flag |= SELECT;
-                                                               changed = TRUE;
+                                                               changed = true;
                                                                break;
                                                        }
                                                }
@@ -291,9 +291,9 @@ static int object_select_all_by_material_texture(bContext *C, int use_texture, M
        return changed;
 }
 
-static int object_select_all_by_dup_group(bContext *C, Object *ob)
+static bool object_select_all_by_dup_group(bContext *C, Object *ob)
 {
-       int changed = FALSE;
+       bool changed = false;
        Group *dup_group = (ob->transflag & OB_DUPLIGROUP) ? ob->dup_group : NULL;
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
@@ -304,7 +304,7 @@ static int object_select_all_by_dup_group(bContext *C, Object *ob)
                                base->flag |= SELECT;
                                base->object->flag = base->flag;
 
-                               changed = TRUE;
+                               changed = true;
                        }
                }
        }
@@ -313,24 +313,22 @@ static int object_select_all_by_dup_group(bContext *C, Object *ob)
        return changed;
 }
 
-static int object_select_all_by_particle(bContext *C, Object *ob)
+static bool object_select_all_by_particle(bContext *C, Object *ob)
 {
-       int changed = FALSE;
+       ParticleSystem *psys_act = psys_get_current(ob);
+       bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
                if ((base->flag & SELECT) == 0) {
-                       /* loop through other, then actives particles*/
+                       /* loop through other particles*/
                        ParticleSystem *psys;
-                       ParticleSystem *psys_act;
-
+                       
                        for (psys = base->object->particlesystem.first; psys; psys = psys->next) {
-                               for (psys_act = ob->particlesystem.first; psys_act; psys_act = psys_act->next) {
-                                       if (psys->part == psys_act->part) {
-                                               base->flag |= SELECT;
-                                               changed = TRUE;
-                                               break;
-                                       }
+                               if (psys->part == psys_act->part) {
+                                       base->flag |= SELECT;
+                                       changed = true;
+                                       break;
                                }
 
                                if (base->flag & SELECT) {
@@ -346,9 +344,9 @@ static int object_select_all_by_particle(bContext *C, Object *ob)
        return changed;
 }
 
-static int object_select_all_by_library(bContext *C, Library *lib)
+static bool object_select_all_by_library(bContext *C, Library *lib)
 {
-       int changed = FALSE;
+       bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
@@ -357,7 +355,7 @@ static int object_select_all_by_library(bContext *C, Library *lib)
                                base->flag |= SELECT;
                                base->object->flag = base->flag;
 
-                               changed = TRUE;
+                               changed = true;
                        }
                }
        }
@@ -366,9 +364,9 @@ static int object_select_all_by_library(bContext *C, Library *lib)
        return changed;
 }
 
-static int object_select_all_by_library_obdata(bContext *C, Library *lib)
+static bool object_select_all_by_library_obdata(bContext *C, Library *lib)
 {
-       int changed = FALSE;
+       bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
@@ -377,7 +375,7 @@ static int object_select_all_by_library_obdata(bContext *C, Library *lib)
                                base->flag |= SELECT;
                                base->object->flag = base->flag;
 
-                               changed = TRUE;
+                               changed = true;
                        }
                }
        }
@@ -389,13 +387,13 @@ static int object_select_all_by_library_obdata(bContext *C, Library *lib)
 void ED_object_select_linked_by_id(bContext *C, ID *id)
 {
        int idtype = GS(id->name);
-       int changed = FALSE;
+       bool changed = false;
 
        if (OB_DATA_SUPPORT_ID(idtype)) {
                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_texture(C, false, (Material *)id, NULL);
        }
        else if (idtype == ID_LI) {
                changed = object_select_all_by_library(C, (Library *) id);
@@ -411,7 +409,7 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
        Scene *scene = CTX_data_scene(C);
        Object *ob;
        int nr = RNA_enum_get(op->ptr, "type");
-       short changed = FALSE, extend;
+       bool changed = false, extend;
 
        extend = RNA_boolean_get(op->ptr, "extend");
        
@@ -425,7 +423,7 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
        
        ob = OBACT;
        if (ob == NULL) {
-               BKE_report(op->reports, RPT_ERROR, "No Active Object");
+               BKE_report(op->reports, RPT_ERROR, "No active object");
                return OPERATOR_CANCELLED;
        }
        
@@ -436,7 +434,7 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
        else if (nr == OBJECT_SELECT_LINKED_OBDATA) {
-               if (ob->data == 0)
+               if (ob->data == NULL)
                        return OPERATOR_CANCELLED;
 
                changed = object_select_all_by_obdata(C, ob->data);
@@ -444,12 +442,12 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
        else if (nr == OBJECT_SELECT_LINKED_MATERIAL || nr == OBJECT_SELECT_LINKED_TEXTURE) {
                Material *mat = NULL;
                Tex *tex = NULL;
-               int use_texture = FALSE;
+               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;
+                       use_texture = true;
 
                        if (mat->mtex[(int)mat->texact]) tex = mat->mtex[(int)mat->texact]->tex;
                        if (tex == NULL) return OPERATOR_CANCELLED;
@@ -464,7 +462,7 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
                changed = object_select_all_by_dup_group(C, ob);
        }
        else if (nr == OBJECT_SELECT_LINKED_PARTICLE) {
-               if (ob->particlesystem.first == NULL)
+               if (BLI_listbase_is_empty(&ob->particlesystem))
                        return OPERATOR_CANCELLED;
 
                changed = object_select_all_by_particle(C, ob);
@@ -483,7 +481,7 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
 
        if (changed) {
-               WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
+               WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
                return OPERATOR_FINISHED;
        }
        
@@ -506,38 +504,55 @@ void OBJECT_OT_select_linked(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_boolean(ot->srna, "extend", FALSE, "Extend", "Extend selection instead of deselecting everything first");
+       RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend selection instead of deselecting everything first");
        ot->prop = RNA_def_enum(ot->srna, "type", prop_select_linked_types, 0, "Type", "");
 }
 
 /*********************** Selected Grouped ********************/
 
+enum {
+       OBJECT_GRPSEL_CHILDREN_RECURSIVE =  0,
+       OBJECT_GRPSEL_CHILDREN           =  1,
+       OBJECT_GRPSEL_PARENT             =  2,
+       OBJECT_GRPSEL_SIBLINGS           =  3,
+       OBJECT_GRPSEL_TYPE               =  4,
+       OBJECT_GRPSEL_LAYER              =  5,
+       OBJECT_GRPSEL_GROUP              =  6,
+       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,
+};
+
 static EnumPropertyItem prop_select_grouped_types[] = {
-       {1, "CHILDREN_RECURSIVE", 0, "Children", ""},
-       {2, "CHILDREN", 0, "Immediate Children", ""},
-       {3, "PARENT", 0, "Parent", ""},
-       {4, "SIBLINGS", 0, "Siblings", "Shared Parent"},
-       {5, "TYPE", 0, "Type", "Shared object type"},
-       {6, "LAYER", 0, "Layer", "Shared layers"},
-       {7, "GROUP", 0, "Group", "Shared group"},
-       {8, "HOOK", 0, "Hook", ""},
-       {9, "PASS", 0, "Pass", "Render pass Index"},
-       {10, "COLOR", 0, "Color", "Object Color"},
-       {11, "PROPERTIES", 0, "Properties", "Game Properties"},
-       {12, "KEYINGSET", 0, "Keying Set", "Objects included in active Keying Set"},
+       {OBJECT_GRPSEL_CHILDREN_RECURSIVE, "CHILDREN_RECURSIVE", 0, "Children", ""},
+       {OBJECT_GRPSEL_CHILDREN, "CHILDREN", 0, "Immediate Children", ""},
+       {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_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}
 };
 
-static short select_grouped_children(bContext *C, Object *ob, int recursive)
+static bool select_grouped_children(bContext *C, Object *ob, const bool recursive)
 {
-       short changed = 0;
+       bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
                if (ob == base->object->parent) {
                        if (!(base->flag & SELECT)) {
                                ED_base_object_select(base, BA_SELECT);
-                               changed = 1;
+                               changed = true;
                        }
 
                        if (recursive)
@@ -548,12 +563,12 @@ static short select_grouped_children(bContext *C, Object *ob, int recursive)
        return changed;
 }
 
-static short select_grouped_parent(bContext *C) /* Makes parent active and de-selected OBACT */
+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);
 
-       short changed = 0;
+       bool changed = false;
        Base *baspar, *basact = CTX_data_active_base(C);
 
        if (!basact || !(basact->object->parent)) return 0;  /* we know OBACT is valid */
@@ -565,23 +580,23 @@ static short select_grouped_parent(bContext *C) /* Makes parent active and de-se
                ED_base_object_select(basact, BA_DESELECT);
                ED_base_object_select(baspar, BA_SELECT);
                ED_base_object_activate(C, baspar);
-               changed = 1;
+               changed = true;
        }
        return changed;
 }
 
 
 #define GROUP_MENU_MAX  24
-static short select_grouped_group(bContext *C, Object *ob)  /* Select objects in the same group as the active */
+static bool select_grouped_group(bContext *C, Object *ob)  /* Select objects in the same group as the active */
 {
-       short changed = 0;
+       bool changed = false;
        Group *group, *ob_groups[GROUP_MENU_MAX];
        int group_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 (object_in_group(ob, group)) {
+               if (BKE_group_object_exists(group, ob)) {
                        ob_groups[group_count] = group;
                        group_count++;
                }
@@ -593,9 +608,9 @@ static short select_grouped_group(bContext *C, Object *ob)  /* Select objects in
                group = ob_groups[0];
                CTX_DATA_BEGIN (C, Base *, base, visible_bases)
                {
-                       if (!(base->flag & SELECT) && object_in_group(base->object, group)) {
+                       if (!(base->flag & SELECT) && BKE_group_object_exists(group, base->object)) {
                                ED_base_object_select(base, BA_SELECT);
-                               changed = 1;
+                               changed = true;
                        }
                }
                CTX_DATA_END;
@@ -603,24 +618,24 @@ static short select_grouped_group(bContext *C, Object *ob)  /* Select objects in
        }
 
        /* build the menu. */
-       pup = uiPupMenuBegin(C, "Select Group", ICON_NONE);
-       layout = uiPupMenuLayout(pup);
+       pup = UI_popup_menu_begin(C, IFACE_("Select Group"), 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);
+               uiItemStringO(layout, group->id.name + 2, 0, "OBJECT_OT_select_same_group", "group", group->id.name + 2);
        }
 
-       uiPupMenuEnd(C, pup);
-       return changed; // The operator already handle this!
+       UI_popup_menu_end(C, pup);
+       return changed;  /* The operator already handle this! */
 }
 
-static short select_grouped_object_hooks(bContext *C, Object *ob)
+static bool select_grouped_object_hooks(bContext *C, Object *ob)
 {
        Scene *scene = CTX_data_scene(C);
        View3D *v3d = CTX_wm_view3d(C);
 
-       short changed = 0;
+       bool changed = false;
        Base *base;
        ModifierData *md;
        HookModifierData *hmd;
@@ -632,7 +647,7 @@ static short select_grouped_object_hooks(bContext *C, Object *ob)
                                base = BKE_scene_base_find(scene, hmd->object);
                                if (base && (BASE_SELECTABLE(v3d, base))) {
                                        ED_base_object_select(base, BA_SELECT);
-                                       changed = 1;
+                                       changed = true;
                                }
                        }
                }
@@ -642,120 +657,153 @@ static short select_grouped_object_hooks(bContext *C, Object *ob)
 
 /* Select objects with the same parent as the active (siblings),
  * parent can be NULL also */
-static short select_grouped_siblings(bContext *C, Object *ob)
+static bool select_grouped_siblings(bContext *C, Object *ob)
 {
-       short changed = 0;
+       bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
                if ((base->object->parent == ob->parent) && !(base->flag & SELECT)) {
                        ED_base_object_select(base, BA_SELECT);
-                       changed = 1;
+                       changed = true;
                }
        }
        CTX_DATA_END;
        return changed;
 }
+static bool select_grouped_lamptype(bContext *C, Object *ob)
+{
+       Lamp *la = ob->data;
+
+       bool changed = false;
 
-static short select_grouped_type(bContext *C, Object *ob)
+       CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
+       {
+               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);
+                               changed = true;
+                       }
+               }
+       }
+       CTX_DATA_END;
+       return changed;
+}
+static bool select_grouped_type(bContext *C, Object *ob)
 {
-       short changed = 0;
+       bool changed = false;
 
        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 = 1;
+                       changed = true;
                }
        }
        CTX_DATA_END;
        return changed;
 }
 
-static short select_grouped_layer(bContext *C, Object *ob)
+static bool select_grouped_layer(bContext *C, Object *ob)
 {
-       char changed = 0;
+       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);
-                       changed = 1;
+                       changed = true;
                }
        }
        CTX_DATA_END;
        return changed;
 }
 
-static short select_grouped_index_object(bContext *C, Object *ob)
+static bool select_grouped_index_object(bContext *C, Object *ob)
 {
-       char changed = 0;
+       bool changed = false;
 
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
                if ((base->object->index == ob->index) && !(base->flag & SELECT)) {
                        ED_base_object_select(base, BA_SELECT);
-                       changed = 1;
+                       changed = true;
                }
        }
        CTX_DATA_END;
        return changed;
 }
 
-static short select_grouped_color(bContext *C, Object *ob)
+static bool select_grouped_color(bContext *C, Object *ob)
 {
-       char changed = 0;
+       bool changed = false;
 
        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 = 1;
+                       changed = true;
                }
        }
        CTX_DATA_END;
        return changed;
 }
 
-static short objects_share_gameprop(Object *a, Object *b)
+static bool objects_share_gameprop(Object *a, Object *b)
 {
        bProperty *prop;
-       /*make a copy of all its properties*/
 
        for (prop = a->prop.first; prop; prop = prop->next) {
-               if (get_ob_property(b, prop->name) )
+               if (BKE_bproperty_object_get(b, prop->name)) {
                        return 1;
+               }
        }
        return 0;
 }
 
-static short select_grouped_gameprops(bContext *C, Object *ob)
+static bool select_grouped_gameprops(bContext *C, Object *ob)
 {
-       char changed = 0;
+       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);
-                       changed = 1;
+                       changed = true;
                }
        }
        CTX_DATA_END;
        return changed;
 }
 
-static short select_grouped_keyingset(bContext *C, Object *UNUSED(ob))
+static bool select_grouped_keyingset(bContext *C, Object *UNUSED(ob), ReportList *reports)
 {
        KeyingSet *ks = ANIM_scene_get_active_keyingset(CTX_data_scene(C));
-       short changed = 0;
+       bool changed = false;
        
        /* firstly, validate KeyingSet */
-       if ((ks == NULL) || (ANIM_validate_keyingset(C, NULL, ks) != 0))
-               return 0;
+       if (ks == NULL) {
+               BKE_report(reports, RPT_ERROR, "No active Keying Set to use");
+               return false;
+       }
+       else if (ANIM_validate_keyingset(C, NULL, ks) != 0) {
+               if (ks->paths.first == NULL) {
+                       if ((ks->flag & KEYINGSET_ABSOLUTE) == 0) {
+                               BKE_report(reports, RPT_ERROR, 
+                                          "Use another Keying Set, as the active one depends on the currently "
+                                          "selected objects or cannot find any targets due to unsuitable context");
+                       }
+                       else {
+                               BKE_report(reports, RPT_ERROR, "Keying Set does not contain any paths");
+                       }
+               }
+               return false;
+       }
        
        /* select each object that Keying Set refers to */
-       // TODO: perhaps to be more in line with the rest of these, we should only take objects 
-       // if the passed in object is included in this too
+       /* TODO: perhaps to be more in line with the rest of these, we should only take objects
+        * if the passed in object is included in this too */
        CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
                /* only check for this object if it isn't selected already, to limit time wasted */
@@ -769,7 +817,7 @@ static short select_grouped_keyingset(bContext *C, Object *UNUSED(ob))
                                /* if id matches, select then stop looping (match found) */
                                if (ksp->id == (ID *)base->object) {
                                        ED_base_object_select(base, BA_SELECT);
-                                       changed = 1;
+                                       changed = true;
                                        break;
                                }
                        }
@@ -784,44 +832,79 @@ static int object_select_grouped_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
        Object *ob;
-       int nr = RNA_enum_get(op->ptr, "type");
-       short changed = 0, extend;
+       const int type = RNA_enum_get(op->ptr, "type");
+       bool changed = false, extend;
 
        extend = RNA_boolean_get(op->ptr, "extend");
-       
+
        if (extend == 0) {
                CTX_DATA_BEGIN (C, Base *, base, visible_bases)
                {
                        ED_base_object_select(base, BA_DESELECT);
-                       changed = 1;
+                       changed = true;
                }
                CTX_DATA_END;
        }
-       
+
        ob = OBACT;
        if (ob == NULL) {
-               BKE_report(op->reports, RPT_ERROR, "No Active Object");
+               BKE_report(op->reports, RPT_ERROR, "No active object");
                return OPERATOR_CANCELLED;
        }
-       
-       if      (nr == 1) changed |= select_grouped_children(C, ob, 1);
-       else if (nr == 2) changed |= select_grouped_children(C, ob, 0);
-       else if (nr == 3) changed |= select_grouped_parent(C);
-       else if (nr == 4) changed |= select_grouped_siblings(C, ob);
-       else if (nr == 5) changed |= select_grouped_type(C, ob);
-       else if (nr == 6) changed |= select_grouped_layer(C, ob);
-       else if (nr == 7) changed |= select_grouped_group(C, ob);
-       else if (nr == 8) changed |= select_grouped_object_hooks(C, ob);
-       else if (nr == 9) changed |= select_grouped_index_object(C, ob);
-       else if (nr == 10) changed |= select_grouped_color(C, ob);
-       else if (nr == 11) changed |= select_grouped_gameprops(C, ob);
-       else if (nr == 12) changed |= select_grouped_keyingset(C, ob);
-       
+
+       switch (type) {
+               case OBJECT_GRPSEL_CHILDREN_RECURSIVE:
+                       changed |= select_grouped_children(C, ob, true);
+                       break;
+               case OBJECT_GRPSEL_CHILDREN:
+                       changed |= select_grouped_children(C, ob, false);
+                       break;
+               case OBJECT_GRPSEL_PARENT:
+                       changed |= select_grouped_parent(C);
+                       break;
+               case OBJECT_GRPSEL_SIBLINGS:
+                       changed |= select_grouped_siblings(C, ob);
+                       break;
+               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);
+                       break;
+               case OBJECT_GRPSEL_HOOK:
+                       changed |= select_grouped_object_hooks(C, ob);
+                       break;
+               case OBJECT_GRPSEL_PASS:
+                       changed |= select_grouped_index_object(C, ob);
+                       break;
+               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;
+               case OBJECT_GRPSEL_LAMP_TYPE:
+                       if (ob->type != OB_LAMP) {
+                               BKE_report(op->reports, RPT_ERROR, "Active object must be a lamp");
+                               break;
+                       }
+                       changed |= select_grouped_lamptype(C, ob);
+                       break;
+               default:
+                       break;
+       }
+
        if (changed) {
-               WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
+               WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
                return OPERATOR_FINISHED;
        }
-       
+
        return OPERATOR_CANCELLED;
 }
 
@@ -841,22 +924,27 @@ void OBJECT_OT_select_grouped(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_boolean(ot->srna, "extend", FALSE, "Extend", "Extend selection instead of deselecting everything first");
+       RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend selection instead of deselecting everything first");
        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;
-       short extend, match;
+       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 == 0) {
+       if (extend == false) {
                CTX_DATA_BEGIN (C, Base *, base, visible_bases)
                {
                        ED_base_object_select(base, BA_DESELECT);
@@ -866,15 +954,23 @@ static int object_select_by_layer_exec(bContext *C, wmOperator *op)
                
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
-               int ok = 0;
+               bool ok = false;
 
-               if (match == 1) /* exact */
-                       ok = (base->lay == (1 << (layernum - 1)));
-               else /* shared layers */
-                       ok = (base->lay & (1 << (layernum - 1)));
+               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)
+               if (ok) {
                        ED_base_object_select(base, BA_SELECT);
+               }
        }
        CTX_DATA_END;
        
@@ -887,8 +983,8 @@ static int object_select_by_layer_exec(bContext *C, wmOperator *op)
 void OBJECT_OT_select_by_layer(wmOperatorType *ot)
 {
        static EnumPropertyItem match_items[] = {
-               {1, "EXACT", 0, "Exact Match", ""},
-               {2, "SHARED", 0, "Shared Layers", ""},
+               {OB_SEL_LAYERMATCH_EXACT, "EXACT", 0, "Exact Match", ""},
+               {OB_SEL_LAYERMATCH_SHARED, "SHARED", 0, "Shared Layers", ""},
                {0, NULL, 0, NULL, NULL}
        };
 
@@ -906,8 +1002,8 @@ void OBJECT_OT_select_by_layer(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_enum(ot->srna, "match", match_items, 0, "Match", "");
-       RNA_def_boolean(ot->srna, "extend", FALSE, "Extend", "Extend selection instead of deselecting everything first");
+       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);
 }
 
@@ -988,17 +1084,15 @@ static int object_select_same_group_exec(bContext *C, wmOperator *op)
 
        RNA_string_get(op->ptr, "group", group_name);
 
-       for (group = CTX_data_main(C)->group.first; group; group = group->id.next) {
-               if (!strcmp(group->id.name, group_name))
-                       break;
-       }
+       group = (Group *)BKE_libblock_find_name(ID_GR, group_name);
 
-       if (!group)
+       if (!group) {
                return OPERATOR_PASS_THROUGH;
+       }
 
        CTX_DATA_BEGIN (C, Base *, base, visible_bases)
        {
-               if (!(base->flag & SELECT) && object_in_group(base->object, group))
+               if (!(base->flag & SELECT) && BKE_group_object_exists(group, base->object))
                        ED_base_object_select(base, BA_SELECT);
        }
        CTX_DATA_END;
@@ -1023,25 +1117,25 @@ void OBJECT_OT_select_same_group(wmOperatorType *ot)
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
-       RNA_def_string(ot->srna, "group", "", MAX_ID_NAME, "Group", "Name of the group to select");
+       RNA_def_string(ot->srna, "group", NULL, MAX_ID_NAME, "Group", "Name of the group to select");
 }
 
 /**************************** Select Mirror ****************************/
 static int object_select_mirror_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
-       short extend;
+       bool extend;
        
        extend = RNA_boolean_get(op->ptr, "extend");
        
        CTX_DATA_BEGIN (C, Base *, primbase, selected_bases)
        {
-               char tmpname[MAXBONENAME];
+               char name_flip[MAXBONENAME];
 
-               flip_side_name(tmpname, primbase->object->id.name + 2, TRUE);
+               BKE_deform_flip_side_name(name_flip, primbase->object->id.name + 2, true);
                
-               if (strcmp(tmpname, primbase->object->id.name + 2) != 0) { /* names differ */
-                       Object *ob = (Object *)BKE_libblock_find_name(ID_OB, tmpname);
+               if (!STREQ(name_flip, primbase->object->id.name + 2)) {
+                       Object *ob = (Object *)BKE_libblock_find_name(ID_OB, name_flip);
                        if (ob) {
                                Base *secbase = BKE_scene_base_find(scene, ob);
 
@@ -1051,13 +1145,13 @@ static int object_select_mirror_exec(bContext *C, wmOperator *op)
                        }
                }
                
-               if (extend == 0) ED_base_object_select(primbase, BA_DESELECT);
+               if (extend == false) ED_base_object_select(primbase, BA_DESELECT);
                
        }
        CTX_DATA_END;
        
        /* undo? */
-       WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
+       WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
        
        return OPERATOR_FINISHED;
 }
@@ -1085,28 +1179,22 @@ void OBJECT_OT_select_mirror(wmOperatorType *ot)
 
 static int object_select_random_exec(bContext *C, wmOperator *op)
 {      
-       float percent;
-       short extend;
-       
-       extend = RNA_boolean_get(op->ptr, "extend");
-       
-       if (extend == 0) {
-               CTX_DATA_BEGIN (C, Base *, base, visible_bases)
-               {
-                       ED_base_object_select(base, BA_DESELECT);
-               }
-               CTX_DATA_END;
-       }
-       percent = RNA_float_get(op->ptr, "percent") / 100.0f;
-               
-       CTX_DATA_BEGIN (C, Base *, base, visible_bases)
+       const float randfac = RNA_float_get(op->ptr, "percent") / 100.0f;
+       const int seed = RNA_int_get(op->ptr, "seed");
+       const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT);
+
+       RNG *rng = BLI_rng_new_srandom(seed);
+
+       CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
        {
-               if (BLI_frand() < percent) {
-                       ED_base_object_select(base, BA_SELECT);
+               if (BLI_rng_get_float(rng) < randfac) {
+                       ED_base_object_select(base, select);
                }
        }
        CTX_DATA_END;
-       
+
+       BLI_rng_free(rng);
+
        WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
        
        return OPERATOR_FINISHED;
@@ -1128,6 +1216,5 @@ void OBJECT_OT_select_random(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of objects to select randomly", 0.f, 100.0f);
-       RNA_def_boolean(ot->srna, "extend", FALSE, "Extend Selection", "Extend selection instead of deselecting everything first");
+       WM_operator_properties_select_random(ot);
 }