Refactor: Use object select API - ED_object_base_select
authorDalai Felinto <dfelinto@gmail.com>
Tue, 23 Apr 2019 20:22:27 +0000 (17:22 -0300)
committerDalai Felinto <dfelinto@gmail.com>
Tue, 30 Apr 2019 19:48:07 +0000 (16:48 -0300)
We had a mix of BKE_view_layer_base_select (harmless), and places where
we simply set the BASE_SELECTED flag with no regard to its selectable
state.

source/blender/blenkernel/BKE_layer.h
source/blender/blenkernel/intern/layer.c
source/blender/editors/gpencil/gpencil_convert.c
source/blender/editors/object/object_constraint.c
source/blender/editors/object/object_relations.c
source/blender/editors/object/object_select.c
source/blender/editors/space_outliner/outliner_tools.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/transform/transform_conversions.c
source/blender/makesrna/intern/rna_object_api.c

index 98fb59814fa79df8d89c611561f840867e8805c2..cc6c43c51f6c433cb7d1b7f0d813f3033ef2fc59 100644 (file)
@@ -68,7 +68,6 @@ struct ViewLayer *BKE_view_layer_find_from_collection(const struct Scene *scene,
 struct Base *BKE_view_layer_base_find(struct ViewLayer *view_layer, struct Object *ob);
 void BKE_view_layer_base_deselect_all(struct ViewLayer *view_layer);
 
-void BKE_view_layer_base_select(struct Base *selbase);
 void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, struct Base *selbase);
 
 void BKE_view_layer_copy_data(struct Scene *scene_dst,
index 6f43a57584d865ca3c366960e6de04db48df36ef..3cb4462aaf2c1a4f252f45ed94331725637429ad 100644 (file)
@@ -345,19 +345,14 @@ void BKE_view_layer_base_deselect_all(ViewLayer *view_layer)
   }
 }
 
-void BKE_view_layer_base_select(Base *selbase)
+void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, Base *selbase)
 {
+  view_layer->basact = selbase;
   if ((selbase->flag & BASE_SELECTABLE) != 0) {
     selbase->flag |= BASE_SELECTED;
   }
 }
 
-void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, Base *selbase)
-{
-  view_layer->basact = selbase;
-  BKE_view_layer_base_select(selbase);
-}
-
 /**************************** Copy View Layer and Layer Collections ***********************/
 
 static void layer_collections_copy_data(ViewLayer *view_layer_dst,
index 63ccad66b4bf06d8e888905d429687b432c8143e..5afa379e04f9c766fa34daa7321e95eb184d851b 100644 (file)
@@ -79,6 +79,7 @@
 #include "ED_view3d.h"
 #include "ED_clip.h"
 #include "ED_keyframing.h"
+#include "ED_object.h"
 
 #include "gpencil_intern.h"
 
@@ -1395,9 +1396,7 @@ static void gp_layer_to_curve(bContext *C,
     }
   }
 
-  /* set the layer and select */
-  base_new->flag |= BASE_SELECTED;
-  BKE_scene_object_base_flag_sync_from_base(base_new);
+  ED_object_base_select(base_new, BA_SELECT);
 }
 
 /* --- */
index 5b9b430406464bf9ea89445e21782118adbb632e..6a587bd6e2a2a43dbf65154929ddcb8ea35e6957 100644 (file)
@@ -1843,7 +1843,7 @@ static bool get_new_constraint_target(
 
     /* restore, BKE_object_add sets active */
     BASACT(view_layer) = base;
-    base->flag |= BASE_SELECTED;
+    ED_object_base_select(base, BA_SELECT);
 
     /* make our new target the new object */
     *tar_ob = obt;
index a62c0add521789d82a3989687df4d526e611da01..e15d85a795384a9263d2cb4d594e4dd122779d0b 100644 (file)
@@ -2158,8 +2158,7 @@ static bool make_local_all__instance_indirect_unused(Main *bmain,
 
       BKE_collection_object_add(bmain, collection, ob);
       base = BKE_view_layer_base_find(view_layer, ob);
-      base->flag |= BASE_SELECTED;
-      BKE_scene_object_base_flag_sync_from_base(base);
+      ED_object_base_select(base, BA_SELECT);
       DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
 
       changed = true;
index f0508b5f35cd2b3941e52355e23912da47cdc15d..2568db4abe986083ea1437cce9bcefaeb1bd931f 100644 (file)
@@ -87,7 +87,7 @@
  * \{ */
 
 /**
- * simple API for object selection, rather than just using the flag
+ * Simple API for object selection, rather than just using the flag
  * this takes into account the 'restrict selection in 3d view' flag.
  * deselect works always, the restriction just prevents selection
  *
index 650827a17c7d51feb1f41c9ccb22a09769b8c05f..68688b64b3e2b64b175c534d204d37af4cdaa7e0 100644 (file)
@@ -452,8 +452,8 @@ static void object_select_cb(bContext *C,
   Object *ob = (Object *)tselem->id;
   Base *base = BKE_view_layer_base_find(view_layer, ob);
 
-  if (base && ((base->flag & BASE_VISIBLE) != 0)) {
-    base->flag |= BASE_SELECTED;
+  if (base) {
+    ED_object_base_select(base, BA_SELECT);
   }
 }
 
index bac24b80c3e9aeaa73654492e7212a0068f74013..0e1b9d742687a8fb0548639d5017e2801d0112a5 100644 (file)
@@ -1911,8 +1911,7 @@ static bool ed_object_select_pick(bContext *C,
                   }
                 }
 
-                basact->flag |= BASE_SELECTED;
-                BKE_scene_object_base_flag_sync_from_base(basact);
+                ED_object_base_select(basact, BA_SELECT);
 
                 retval = true;
 
@@ -1945,8 +1944,7 @@ static bool ed_object_select_pick(bContext *C,
 
           /* we make the armature selected:
            * not-selected active object in posemode won't work well for tools */
-          basact->flag |= BASE_SELECTED;
-          BKE_scene_object_base_flag_sync_from_base(basact);
+          ED_object_base_select(basact, BA_SELECT);
 
           retval = true;
           WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, basact->object);
index 2b74f3849f7f5e6ce075027a5b0e4acc40838140..b5b956441b3a6cb6c13a24e13eff066e9698bf5f 100644 (file)
@@ -6479,7 +6479,7 @@ static void clear_trans_object_base_flags(TransInfo *t)
 
   for (base = view_layer->object_bases.first; base; base = base->next) {
     if (base->flag_legacy & BA_WAS_SEL) {
-      base->flag |= BASE_SELECTED;
+      ED_object_base_select(base, BA_SELECT);
     }
 
     base->flag_legacy &= ~(BA_WAS_SEL | BA_SNAP_FIX_DEPS_FIASCO | BA_TEMP_TAG |
index 02b700a03c1f6d5fbc5cd9363e4591940bd761cc..21300f22b95104cb9f61ddce4090961b02e14abc 100644 (file)
@@ -106,12 +106,7 @@ static void rna_Object_select_set(
     return;
   }
 
-  if (select) {
-    BKE_view_layer_base_select(base);
-  }
-  else {
-    base->flag &= ~BASE_SELECTED;
-  }
+  ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT);
 
   Scene *scene = CTX_data_scene(C);
   DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);