RNA: Object.select_set use boolean, only select
authorCampbell Barton <ideasman42@gmail.com>
Wed, 7 Nov 2018 21:51:03 +0000 (08:51 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 7 Nov 2018 21:54:55 +0000 (08:54 +1100)
- Was setting active state, making it necessary to backup/restore
  active object in cases where this isn't needed.
  Existing scripts are explicitly setting the active object when needed.

- Use a boolean select arg (toggle selection wasn't used anywhere).

- Add an optional view layer argument since scripts should be able to
  operate outside the user context.

13 files changed:
doc/python_api/examples/bpy.types.Object.py
release/scripts/startup/bl_operators/clip.py
release/scripts/templates_py/batch_export.py
release/scripts/templates_py/operator_modal_view3d_raycast.py
source/blender/makesrna/intern/rna_object_api.c
tests/python/view_layer/test_evaluation_selectability_a.py
tests/python/view_layer/test_evaluation_selectability_b.py
tests/python/view_layer/test_evaluation_selectability_c.py
tests/python/view_layer/test_evaluation_selectability_d.py
tests/python/view_layer/test_evaluation_selectability_e.py
tests/python/view_layer/test_group_e.py
tests/python/view_layer/test_make_single_user.py
tests/python/view_layer/test_scene_copy_e.py

index 46f42c828d70e0e8512860fdf60e4f064f577d36..743322492b4254bd0c89899312025e4abb2b317a 100644 (file)
@@ -25,5 +25,5 @@ view_layer.active_layer_collection.collection.objects.link(light_object)
 light_object.location = (5.0, 5.0, 5.0)
 
 # And finally select it and make it active.
-light_object.select_set('SELECT')
+light_object.select_set(True)
 view_layer.objects.active = light_object
index 96aed07ecea84c5ffb5b210212092d306384ddb4..53bd7ccbb7a032a225b757f60f657f6ed0c33b7c 100644 (file)
@@ -313,7 +313,7 @@ class CLIP_OT_bundles_to_mesh(Operator):
             ob = bpy.data.objects.new(name="Tracks", object_data=mesh)
             ob.matrix_world = matrix
             context.collection.objects.link(ob)
-            ob.select_set('SELECT')
+            ob.select_set(True)
             context.view_layer.objects.active = ob
         else:
             self.report({'WARNING'}, "No usable tracks selected")
index a07491742ec333f8863cd506116b58a462c991b7..54e5d166c3685f8934be4491421c7f8bac304c96 100644 (file)
@@ -18,7 +18,7 @@ bpy.ops.object.select_all(action='DESELECT')
 
 for obj in selection:
 
-    obj.select_set(action='SELECT')
+    obj.select_set(True)
 
     # some exporters only use the active object
     view_layer.objects.active = obj
@@ -31,7 +31,7 @@ for obj in selection:
     # Can be used for multiple formats
     # bpy.ops.export_scene.x3d(filepath=fn + ".x3d", use_selection=True)
 
-    obj.select_set(action='DESELECT')
+    obj.select_set(False)
 
     print("written:", fn)
 
@@ -39,4 +39,4 @@ for obj in selection:
 view_layer.objects.active = obj_active
 
 for obj in selection:
-    obj.select_set(action='SELECT')
+    obj.select_set(True)
index 613501143f725028d64c5ebb631a51a48b11a7d5..103c13dc1c28743f9a38197e2fbdfde9d30d9ca0 100644 (file)
@@ -67,7 +67,7 @@ def main(context, event):
     # now we have the object under the mouse cursor,
     # we could do lots of stuff but for the example just select.
     if best_obj is not None:
-        best_obj.select_set(action='SELECT')
+        best_obj.select_set(True)
         context.view_layer.objects.active = best_obj
 
 
index da0ed8e10a87452ba77b2a028a7569d420795c4f..c34534614f437d113119aaf933c2d3e4afe4c549 100644 (file)
@@ -92,9 +92,13 @@ static const EnumPropertyItem space_items[] = {
 
 #include "MEM_guardedalloc.h"
 
-static void rna_Object_select_set(Object *ob, bContext *C, ReportList *reports, int action)
+static void rna_Object_select_set(
+        Object *ob, bContext *C, ReportList *reports,
+        bool select, ViewLayer *view_layer)
 {
-       ViewLayer *view_layer = CTX_data_view_layer(C);
+       if (view_layer == NULL) {
+               view_layer = CTX_data_view_layer(C);
+       }
        Base *base = BKE_view_layer_base_find(view_layer, ob);
 
        if (!base) {
@@ -102,29 +106,16 @@ static void rna_Object_select_set(Object *ob, bContext *C, ReportList *reports,
                return;
        }
 
-       if (action == 2) { /* TOGGLE */
-               if ((base->flag & BASE_SELECTED) != 0) {
-                       action = 1; /* DESELECT */
-               }
-               else {
-                       action = 0; /* SELECT */
-               }
+       if (select) {
+               BKE_view_layer_base_select(base);
        }
-
-       switch (action) {
-               case 1: /* DESELECT */
-                       base->flag &= ~BASE_SELECTED;
-                       break;
-               case 0: /* SELECT */
-               default:
-                       BKE_view_layer_base_select_and_set_active(view_layer, base);
-                       break;
+       else {
+               base->flag &= ~BASE_SELECTED;
        }
 
        Scene *scene = CTX_data_scene(C);
        DEG_id_tag_update(&scene->id, DEG_TAG_SELECT_UPDATE);
        WM_main_add_notifier(NC_SCENE | ND_OB_SELECT, scene);
-       WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene);
 }
 
 static bool rna_Object_select_get(Object *ob, bContext *C, ReportList *reports)
@@ -497,19 +488,13 @@ void RNA_api_object(StructRNA *srna)
        };
 #endif
 
-       static EnumPropertyItem object_select_items[] = {
-           {0, "SELECT", 0, "Select", "Select object from the active view layer"},
-           {1, "DESELECT", 0, "Deselect", "Deselect object from the active view layer"},
-           {2, "TOGGLE", 0, "Toggle", "Toggle object selection from the active view layer"},
-           {0, NULL, 0, NULL, NULL}
-       };
-
        /* Special wrapper to access the base selection value */
        func = RNA_def_function(srna, "select_set", "rna_Object_select_set");
        RNA_def_function_ui_description(func, "Select the object (for the active view layer)");
        RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
-       parm = RNA_def_enum(func, "action", object_select_items, 0, "Action", "Select mode");
+       parm = RNA_def_boolean(func, "state", 0, "", "");
        RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+       parm = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "Operate on this view layer instead of the context");
 
        func = RNA_def_function(srna, "select_get", "rna_Object_select_get");
        RNA_def_function_ui_description(func, "Get the object selection for the active view layer");
index f862ca55c86616f324981da79f0fc3c3663eaa0c..eaed40869c300a2e3d6144c620de9d194e274cf0 100644 (file)
@@ -38,7 +38,7 @@ class UnitTesting(ViewLayerTesting):
 
         layer_collection_mom.enabled = False
         bpy.context.scene.update()  # update depsgraph
-        cube.select_set('SELECT')
+        cube.select_set(True)
 
         self.assertTrue(cube.visible_get(), "Cube should be visible")
         self.assertTrue(cube.select_get(), "Cube should be selected")
index 91f5dc3de2be52f7888d0f26b7dde2f221f03121..584011c672cfd9ba4da6f7e91d8993e3c03cd782 100644 (file)
@@ -36,7 +36,7 @@ class UnitTesting(ViewLayerTesting):
         layer_collection_mom = layer.collections.link(scene_collection_mom)
         layer_collection_kid = layer.collections.link(scene_collection_kid)
         bpy.context.scene.update()  # update depsgraph
-        cube.select_set('SELECT')
+        cube.select_set(True)
 
         layer_collection_mom.collections[layer_collection_kid.name].enabled = False
         layer_collection_kid.enabled = False
index c1ce5dba81571b1c84cfaf6c22bc5a67091843e2..3eecaa06aeb18b52f391aeff6991c69ce8c652bd 100644 (file)
@@ -38,7 +38,7 @@ class UnitTesting(ViewLayerTesting):
 
         layer_collection_mom.enabled = True
         bpy.context.scene.update()  # update depsgraph
-        cube.select_set('SELECT')
+        cube.select_set(True)
 
         self.assertTrue(cube.visible_get(), "Cube should be visible")
         self.assertTrue(cube.select_get(), "Cube should be selected")
index 1af8a0dbd592426496cdfb28418d1b30f3427d01..c645551c5eda92e11a6f11b241efb237f50f3dcc 100644 (file)
@@ -39,7 +39,7 @@ class UnitTesting(ViewLayerTesting):
         layer_collection_mom.enabled = True
         bpy.context.scene.update()  # update depsgraph
 
-        cube.select_set('SELECT')
+        cube.select_set(True)
         layer_collection_mom.collections[layer_collection_kid.name].selectable = False
 
         bpy.context.scene.update()  # update depsgraph
index 54df1e9b59b7a374ef709118f16346b6a124b2d2..e2f0e911bbecc85fc13d936e6f46f3bb0f6f7c25 100644 (file)
@@ -37,7 +37,7 @@ class UnitTesting(ViewLayerTesting):
         layer_collection_kid = layer.collections.link(scene_collection_kid)
 
         layer_collection_mom.enabled = True
-        cube.select_set('SELECT')
+        cube.select_set(True)
         layer_collection_mom.collections[layer_collection_kid.name].selectable = False
         layer_collection_kid.enabled = False
 
index 566c043572eab7017571760b763028a797d1c374..14385411ecaa8eab2dad6c81b686c57e405da134 100644 (file)
@@ -51,9 +51,9 @@ class UnitTesting(ViewLayerTesting):
         # we could just pass an overridden context
         # but let's do it the old fashion way
         view_layer.objects.active = ob
-        ob.select_set('SELECT')
+        ob.select_set(True)
         self.assertTrue(ob.select_get())
-        empty.select_set('DESELECT')
+        empty.select_set(False)
         self.assertFalse(empty.select_get())
 
         # update depsgraph
index 292c2d506055e63775c7f33cc932fe93301d74c8..973c191f22df4377fa8685c2b76d34acaf825b10 100644 (file)
@@ -36,7 +36,7 @@ class UnitTesting(ViewLayerTesting):
                 master_collection.collections[0])
 
         view_layer.collections.link(master_collection)
-        ob.select_set('SELECT')
+        ob.select_set(True)
 
         # update depsgraph
         scene.update()
index 23d01b6a84b6500235b514ea272c3c53601abc39..a2d314a037aa8875047af6049188f1efa00b5b56 100644 (file)
@@ -26,7 +26,7 @@ class UnitTesting(ViewLayerTesting):
         layer = bpy.context.view_layer
 
         original_cube = layer.objects.get('Cube')
-        original_cube.select_set('SELECT')
+        original_cube.select_set(True)
         self.assertTrue(original_cube.select_get())
 
         bpy.ops.scene.new(type='FULL_COPY')