Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-11-08 00:51:03 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-11-08 00:54:55 +0300
commitf12d2adc870e4bc032f49b9edae85c3b0366b406 (patch)
tree26b1b336bcbdbe37559df3a94febfe3aaa1e4a8e
parentc121bc62193ab22b37cf3d8cf7bd1d21205f1f3c (diff)
RNA: Object.select_set use boolean, only select
- 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.
-rw-r--r--doc/python_api/examples/bpy.types.Object.py2
-rw-r--r--release/scripts/startup/bl_operators/clip.py2
-rw-r--r--release/scripts/templates_py/batch_export.py6
-rw-r--r--release/scripts/templates_py/operator_modal_view3d_raycast.py2
-rw-r--r--source/blender/makesrna/intern/rna_object_api.c39
-rw-r--r--tests/python/view_layer/test_evaluation_selectability_a.py2
-rw-r--r--tests/python/view_layer/test_evaluation_selectability_b.py2
-rw-r--r--tests/python/view_layer/test_evaluation_selectability_c.py2
-rw-r--r--tests/python/view_layer/test_evaluation_selectability_d.py2
-rw-r--r--tests/python/view_layer/test_evaluation_selectability_e.py2
-rw-r--r--tests/python/view_layer/test_group_e.py4
-rw-r--r--tests/python/view_layer/test_make_single_user.py2
-rw-r--r--tests/python/view_layer/test_scene_copy_e.py2
13 files changed, 27 insertions, 42 deletions
diff --git a/doc/python_api/examples/bpy.types.Object.py b/doc/python_api/examples/bpy.types.Object.py
index 46f42c828d7..743322492b4 100644
--- a/doc/python_api/examples/bpy.types.Object.py
+++ b/doc/python_api/examples/bpy.types.Object.py
@@ -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
diff --git a/release/scripts/startup/bl_operators/clip.py b/release/scripts/startup/bl_operators/clip.py
index 96aed07ecea..53bd7ccbb7a 100644
--- a/release/scripts/startup/bl_operators/clip.py
+++ b/release/scripts/startup/bl_operators/clip.py
@@ -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")
diff --git a/release/scripts/templates_py/batch_export.py b/release/scripts/templates_py/batch_export.py
index a07491742ec..54e5d166c36 100644
--- a/release/scripts/templates_py/batch_export.py
+++ b/release/scripts/templates_py/batch_export.py
@@ -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)
diff --git a/release/scripts/templates_py/operator_modal_view3d_raycast.py b/release/scripts/templates_py/operator_modal_view3d_raycast.py
index 613501143f7..103c13dc1c2 100644
--- a/release/scripts/templates_py/operator_modal_view3d_raycast.py
+++ b/release/scripts/templates_py/operator_modal_view3d_raycast.py
@@ -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
diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c
index da0ed8e10a8..c34534614f4 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -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");
diff --git a/tests/python/view_layer/test_evaluation_selectability_a.py b/tests/python/view_layer/test_evaluation_selectability_a.py
index f862ca55c86..eaed40869c3 100644
--- a/tests/python/view_layer/test_evaluation_selectability_a.py
+++ b/tests/python/view_layer/test_evaluation_selectability_a.py
@@ -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")
diff --git a/tests/python/view_layer/test_evaluation_selectability_b.py b/tests/python/view_layer/test_evaluation_selectability_b.py
index 91f5dc3de2b..584011c672c 100644
--- a/tests/python/view_layer/test_evaluation_selectability_b.py
+++ b/tests/python/view_layer/test_evaluation_selectability_b.py
@@ -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
diff --git a/tests/python/view_layer/test_evaluation_selectability_c.py b/tests/python/view_layer/test_evaluation_selectability_c.py
index c1ce5dba815..3eecaa06aeb 100644
--- a/tests/python/view_layer/test_evaluation_selectability_c.py
+++ b/tests/python/view_layer/test_evaluation_selectability_c.py
@@ -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")
diff --git a/tests/python/view_layer/test_evaluation_selectability_d.py b/tests/python/view_layer/test_evaluation_selectability_d.py
index 1af8a0dbd59..c645551c5ed 100644
--- a/tests/python/view_layer/test_evaluation_selectability_d.py
+++ b/tests/python/view_layer/test_evaluation_selectability_d.py
@@ -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
diff --git a/tests/python/view_layer/test_evaluation_selectability_e.py b/tests/python/view_layer/test_evaluation_selectability_e.py
index 54df1e9b59b..e2f0e911bbe 100644
--- a/tests/python/view_layer/test_evaluation_selectability_e.py
+++ b/tests/python/view_layer/test_evaluation_selectability_e.py
@@ -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
diff --git a/tests/python/view_layer/test_group_e.py b/tests/python/view_layer/test_group_e.py
index 566c043572e..14385411eca 100644
--- a/tests/python/view_layer/test_group_e.py
+++ b/tests/python/view_layer/test_group_e.py
@@ -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
diff --git a/tests/python/view_layer/test_make_single_user.py b/tests/python/view_layer/test_make_single_user.py
index 292c2d50605..973c191f22d 100644
--- a/tests/python/view_layer/test_make_single_user.py
+++ b/tests/python/view_layer/test_make_single_user.py
@@ -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()
diff --git a/tests/python/view_layer/test_scene_copy_e.py b/tests/python/view_layer/test_scene_copy_e.py
index 23d01b6a84b..a2d314a037a 100644
--- a/tests/python/view_layer/test_scene_copy_e.py
+++ b/tests/python/view_layer/test_scene_copy_e.py
@@ -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')