Merging trunk up to revision 41245.
[blender.git] / source / blender / editors / object / object_select.c
index 3c2d46872cd72fbb8daa173f5a2deb92dcc1da94..d10a6be1988c9b84e3433b15c33627de9c6125e5 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -37,6 +35,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_anim_types.h"
 #include "DNA_group_types.h"
 #include "DNA_material_types.h"
 #include "DNA_modifier_types.h"
@@ -49,8 +48,6 @@
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
-#include "BLF_api.h"
-
 #include "BKE_context.h"
 #include "BKE_group.h"
 #include "BKE_main.h"
@@ -67,6 +64,7 @@
 
 #include "ED_object.h"
 #include "ED_screen.h"
+#include "ED_keyframing.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
@@ -121,6 +119,20 @@ void ED_base_object_activate(bContext *C, Base *base)
 
 /********************** Selection Operators **********************/
 
+static int objects_selectable_poll(bContext *C)
+{
+       /* we don't check for linked scenes here, selection is
+          still allowed then for inspection of scene */
+       Object *obact= CTX_data_active_object(C);
+
+       if(CTX_data_edit_object(C))
+               return 0;
+       if(obact && obact->mode)
+               return 0;
+       
+       return 1;
+}
+
 /************************ Select by Type *************************/
 
 static int object_select_by_type_exec(bContext *C, wmOperator *op)
@@ -152,20 +164,20 @@ static int object_select_by_type_exec(bContext *C, wmOperator *op)
 void OBJECT_OT_select_by_type(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= _("Select By Type");
-       ot->description = _("Select all visible objects that are of a type");
+       ot->name= "Select By Type";
+       ot->description = "Select all visible objects that are of a type";
        ot->idname= "OBJECT_OT_select_by_type";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= object_select_by_type_exec;
-       ot->poll= ED_operator_objectmode;
+       ot->poll= objects_selectable_poll;
        
        /* flags */
        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", object_type_items, 1, "Type", "");
 }
 
@@ -334,20 +346,20 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
 void OBJECT_OT_select_linked(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= _("Select Linked");
-       ot->description = _("Select all visible objects that are linked");
+       ot->name= "Select Linked";
+       ot->description = "Select all visible objects that are linked";
        ot->idname= "OBJECT_OT_select_linked";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= object_select_linked_exec;
-       ot->poll= ED_operator_objectmode;
+       ot->poll= objects_selectable_poll;
        
        /* flags */
        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", "");
 }
 
@@ -365,6 +377,7 @@ static EnumPropertyItem prop_select_grouped_types[] = {
        {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"},
        {0, NULL, 0, NULL, NULL}
 };
 
@@ -576,6 +589,42 @@ static short select_grouped_gameprops(bContext *C, Object *ob)
        return changed;
 }
 
+static short select_grouped_keyingset(bContext *C, Object *UNUSED(ob))
+{
+       KeyingSet *ks = ANIM_scene_get_active_keyingset(CTX_data_scene(C));
+       short changed = 0;
+       
+       /* firstly, validate KeyingSet */
+       if ((ks == NULL) || (ANIM_validate_keyingset(C, NULL, ks) != 0))
+               return 0;
+       
+       /* 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
+       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) {
+                       KS_Path *ksp;
+                       
+                       /* this is the slow way... we could end up with > 500 items here, 
+                        * with none matching, but end up doing this on 1000 objects...
+                        */
+                       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);
+                                       changed = 1;
+                                       break;
+                               }
+                       }
+               }
+       }
+       CTX_DATA_END;
+               
+       return changed;
+}
+
 static int object_select_grouped_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
@@ -610,6 +659,7 @@ static int object_select_grouped_exec(bContext *C, wmOperator *op)
        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);
        
        if (changed) {
                WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
@@ -622,20 +672,20 @@ static int object_select_grouped_exec(bContext *C, wmOperator *op)
 void OBJECT_OT_select_grouped(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= _("Select Grouped");
-       ot->description = _("Select all visible objects grouped by various properties");
+       ot->name= "Select Grouped";
+       ot->description = "Select all visible objects grouped by various properties";
        ot->idname= "OBJECT_OT_select_grouped";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= object_select_grouped_exec;
-       ot->poll= ED_operator_objectmode;
+       ot->poll= objects_selectable_poll;
        
        /* flags */
        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", "");
 }
 
@@ -671,21 +721,21 @@ static int object_select_by_layer_exec(bContext *C, wmOperator *op)
 void OBJECT_OT_select_by_layer(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= _("Select by Layer");
-       ot->description = _("Select all visible objects on a layer");
+       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= ED_operator_objectmode;
+       ot->poll= objects_selectable_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       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);
+       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);
 }
 
 /************************** Select Inverse *************************/
@@ -716,7 +766,7 @@ void OBJECT_OT_select_inverse(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= object_select_inverse_exec;
-       ot->poll= ED_operator_objectmode;
+       ot->poll= objects_selectable_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -777,7 +827,7 @@ void OBJECT_OT_select_all(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= object_select_all_exec;
-       ot->poll= ED_operator_objectmode;
+       ot->poll= objects_selectable_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -826,12 +876,12 @@ void OBJECT_OT_select_same_group(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= object_select_same_group_exec;
-       ot->poll= ED_operator_objectmode;
+       ot->poll= objects_selectable_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
-       RNA_def_string(ot->srna, "group", "", 32, "Group", "Name of the group to select.");
+       RNA_def_string(ot->srna, "group", "", 32, "Group", "Name of the group to select");
 }
 
 /**************************** Select Mirror ****************************/
@@ -873,18 +923,18 @@ void OBJECT_OT_select_mirror(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= _("Select Mirror");
-       ot->description = _("Select the Mirror objects of the selected object eg. L.sword -> R.sword");
+       ot->name= "Select Mirror";
+       ot->description = "Select the Mirror objects of the selected object eg. L.sword -> R.sword";
        ot->idname= "OBJECT_OT_select_mirror";
        
        /* api callbacks */
        ot->exec= object_select_mirror_exec;
-       ot->poll= ED_operator_objectmode;
+       ot->poll= objects_selectable_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       RNA_def_boolean(ot->srna, "extend", 0, _("Extend"), _("Extend selection instead of deselecting everything first."));
+       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first");
 }
 
 
@@ -930,19 +980,19 @@ void OBJECT_OT_select_name(wmOperatorType *ot)
 {
 
        /* identifiers */
-       ot->name= _("Select Name");
-       ot->description = _("Select an object with this name");
+       ot->name= "Select Name";
+       ot->description = "Select an object with this name";
        ot->idname= "OBJECT_OT_select_name";
 
        /* api callbacks */
        ot->exec= object_select_name_exec;
-       ot->poll= ED_operator_objectmode;
+       ot->poll= objects_selectable_poll;
 
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
-       RNA_def_string(ot->srna, "name", "", 0, _("Name"), _("Object name to select."));
-       RNA_def_boolean(ot->srna, "extend", 0, _("Extend"), _("Extend selection instead of deselecting everything first."));
+       RNA_def_string(ot->srna, "name", "", 0, "Name", "Object name to select");
+       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first");
 }
 
 /**************************** Select Random ****************************/
@@ -977,21 +1027,21 @@ static int object_select_random_exec(bContext *C, wmOperator *op)
 void OBJECT_OT_select_random(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= _("Select Random");
-       ot->description = _("Set select on random visible objects");
+       ot->name= "Select Random";
+       ot->description = "Set select on random visible objects";
        ot->idname= "OBJECT_OT_select_random";
        
        /* api callbacks */
        /*ot->invoke= object_select_random_invoke XXX - need a number popup ;*/
        ot->exec = object_select_random_exec;
-       ot->poll= ED_operator_objectmode;
+       ot->poll= objects_selectable_poll;
        
        /* flags */
        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."));
+       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");
 }