[Bf-blender-cvs] [b9e54566e3b] master: Cleanup: Add & use enum value for ID Outliner element type

Julian Eisel noreply at git.blender.org
Fri Mar 5 17:47:09 CET 2021


Commit: b9e54566e3b1a49d9757680da64d8e19c136c706
Author: Julian Eisel
Date:   Fri Mar 5 17:38:53 2021 +0100
Branches: master
https://developer.blender.org/rBb9e54566e3b1a49d9757680da64d8e19c136c706

Cleanup: Add & use enum value for ID Outliner element type

Code to check if the Outliner tree-element type was the general ID one
would always check against "0" (explicity or even implicitly). For
somebody unfamiliar with the code this is very confusing. Instead the
value should be given a name, e.g. through an enum.

Adds `TSE_SOME_ID` as the "default" ID tree-element type. Other types
may still represent IDs, as I explained in a comment at the definition.

There may also still be cases where the type is checked against "0". I
noted in the comment that such cases should be cleaned up if found.

===================================================================

M	source/blender/blenkernel/intern/outliner_treehash.c
M	source/blender/editors/space_outliner/outliner_collections.c
M	source/blender/editors/space_outliner/outliner_context.c
M	source/blender/editors/space_outliner/outliner_dragdrop.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/editors/space_outliner/outliner_edit.c
M	source/blender/editors/space_outliner/outliner_select.c
M	source/blender/editors/space_outliner/outliner_sync.c
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/editors/space_outliner/outliner_tree.c
M	source/blender/editors/space_outliner/outliner_utils.c
M	source/blender/editors/space_outliner/tree/tree_display_libraries.cc
M	source/blender/editors/space_outliner/tree/tree_display_orphaned.cc
M	source/blender/editors/space_outliner/tree/tree_display_scenes.cc
M	source/blender/editors/space_outliner/tree/tree_display_view_layer.cc
M	source/blender/editors/space_outliner/tree/tree_element_anim_data.cc
M	source/blender/makesdna/DNA_outliner_types.h

===================================================================

diff --git a/source/blender/blenkernel/intern/outliner_treehash.c b/source/blender/blenkernel/intern/outliner_treehash.c
index 05873d20f7f..b9497d389e7 100644
--- a/source/blender/blenkernel/intern/outliner_treehash.c
+++ b/source/blender/blenkernel/intern/outliner_treehash.c
@@ -101,7 +101,7 @@ static unsigned int tse_hash(const void *ptr)
     unsigned int u_int;
   } hash;
 
-  BLI_assert(tse->type || !tse->nr);
+  BLI_assert((tse->type != TSE_SOME_ID) || !tse->nr);
 
   hash.h_pair[0] = tse->type;
   hash.h_pair[1] = tse->nr;
@@ -193,7 +193,7 @@ static TseGroup *BKE_outliner_treehash_lookup_group(GHash *th, short type, short
 {
   TreeStoreElem tse_template;
   tse_template.type = type;
-  tse_template.nr = type ? nr : 0; /* we're picky! :) */
+  tse_template.nr = (type == TSE_SOME_ID) ? 0 : nr; /* we're picky! :) */
   tse_template.id = id;
 
   BLI_assert(th);
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
index ef5733fe375..d54e35f659c 100644
--- a/source/blender/editors/space_outliner/outliner_collections.c
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -71,7 +71,7 @@ bool outliner_is_collection_tree_element(const TreeElement *te)
            TSE_VIEW_COLLECTION_BASE)) {
     return true;
   }
-  if (tselem->type == 0 && te->idcode == ID_GR) {
+  if ((tselem->type == TSE_SOME_ID) && te->idcode == ID_GR) {
     return true;
   }
 
@@ -94,7 +94,7 @@ Collection *outliner_collection_from_tree_element(const TreeElement *te)
     Scene *scene = (Scene *)tselem->id;
     return scene->master_collection;
   }
-  if (tselem->type == 0 && te->idcode == ID_GR) {
+  if ((tselem->type == TSE_SOME_ID) && (te->idcode == ID_GR)) {
     return (Collection *)tselem->id;
   }
 
@@ -111,7 +111,7 @@ TreeTraversalAction outliner_find_selected_collections(TreeElement *te, void *cu
     return TRAVERSE_CONTINUE;
   }
 
-  if (tselem->type || (tselem->id && GS(tselem->id->name) != ID_GR)) {
+  if ((tselem->type != TSE_SOME_ID) || (tselem->id && GS(tselem->id->name) != ID_GR)) {
     return TRAVERSE_SKIP_CHILDS;
   }
 
@@ -127,7 +127,7 @@ TreeTraversalAction outliner_find_selected_objects(TreeElement *te, void *custom
     return TRAVERSE_CONTINUE;
   }
 
-  if (tselem->type || (tselem->id == NULL) || (GS(tselem->id->name) != ID_OB)) {
+  if ((tselem->type != TSE_SOME_ID) || (tselem->id == NULL) || (GS(tselem->id->name) != ID_OB)) {
     return TRAVERSE_SKIP_CHILDS;
   }
 
@@ -1458,7 +1458,7 @@ static TreeTraversalAction outliner_hide_find_data_to_edit(TreeElement *te, void
       BLI_gset_add(data->collections_to_edit, lc);
     }
   }
-  else if (tselem->type == 0 && te->idcode == ID_OB) {
+  else if ((tselem->type == TSE_SOME_ID) && (te->idcode == ID_OB)) {
     Object *ob = (Object *)tselem->id;
     Base *base = BKE_view_layer_base_find(data->view_layer, ob);
     BLI_gset_add(data->bases_to_edit, base);
diff --git a/source/blender/editors/space_outliner/outliner_context.c b/source/blender/editors/space_outliner/outliner_context.c
index e2b3b79e027..4293d8da73e 100644
--- a/source/blender/editors/space_outliner/outliner_context.c
+++ b/source/blender/editors/space_outliner/outliner_context.c
@@ -34,7 +34,7 @@ static void outliner_context_selected_ids_recursive(const ListBase *subtree,
 {
   LISTBASE_FOREACH (const TreeElement *, te, subtree) {
     const TreeStoreElem *tse = TREESTORE(te);
-    if ((tse->flag & TSE_SELECTED) && (ELEM(tse->type, 0, TSE_LAYER_COLLECTION))) {
+    if ((tse->flag & TSE_SELECTED) && (ELEM(tse->type, TSE_SOME_ID, TSE_LAYER_COLLECTION))) {
       CTX_data_id_list_add(result, tse->id);
     }
     outliner_context_selected_ids_recursive(&te->subtree, result);
diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c
index 3090cab75ae..01fb0fc6f78 100644
--- a/source/blender/editors/space_outliner/outliner_dragdrop.c
+++ b/source/blender/editors/space_outliner/outliner_dragdrop.c
@@ -124,7 +124,7 @@ static ID *outliner_ID_drop_find(bContext *C, const wmEvent *event, short idcode
   TreeElement *te = outliner_drop_find(C, event);
   TreeStoreElem *tselem = (te) ? TREESTORE(te) : NULL;
 
-  if (te && te->idcode == idcode && tselem->type == 0) {
+  if (te && (te->idcode == idcode) && (tselem->type == TSE_SOME_ID)) {
     return tselem->id;
   }
   return NULL;
@@ -215,7 +215,7 @@ static bool is_collection_element(TreeElement *te)
 static bool is_object_element(TreeElement *te)
 {
   TreeStoreElem *tselem = TREESTORE(te);
-  return tselem->type == 0 && te->idcode == ID_OB;
+  return (tselem->type == TSE_SOME_ID) && te->idcode == ID_OB;
 }
 
 static bool is_pchan_element(TreeElement *te)
@@ -281,7 +281,7 @@ static int outliner_get_insert_index(TreeElement *drag_te,
 static bool parent_drop_allowed(TreeElement *te, Object *potential_child)
 {
   TreeStoreElem *tselem = TREESTORE(te);
-  if (te->idcode != ID_OB || tselem->type != 0) {
+  if ((te->idcode != ID_OB) || (tselem->type != TSE_SOME_ID)) {
     return false;
   }
 
@@ -421,7 +421,7 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
   TreeElement *te = outliner_drop_find(C, event);
   TreeStoreElem *tselem = te ? TREESTORE(te) : NULL;
 
-  if (!(te && te->idcode == ID_OB && tselem->type == 0)) {
+  if (!(te && (te->idcode == ID_OB) && (tselem->type == TSE_SOME_ID))) {
     return OPERATOR_CANCELLED;
   }
 
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 008ae727947..690adb09570 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -675,7 +675,7 @@ static void namebutton_fn(bContext *C, void *tsep, char *oldname)
   if (ts && tselem) {
     TreeElement *te = outliner_find_tree_element(&space_outliner->tree, tselem);
 
-    if (tselem->type == 0) {
+    if (tselem->type == TSE_SOME_ID) {
       BLI_libblock_ensure_unique_name(bmain, tselem->id->name);
 
       switch (GS(tselem->id->name)) {
@@ -1100,11 +1100,11 @@ static void outliner_draw_restrictbuts(uiBlock *block,
           UI_but_drawflag_enable(bt, UI_BUT_ICON_REVERSE);
         }
       }
-      else if ((tselem->type == 0 && te->idcode == ID_OB) &&
+      else if (((tselem->type == TSE_SOME_ID) && (te->idcode == ID_OB)) &&
                (te->flag & TE_CHILD_NOT_IN_COLLECTION)) {
         /* Don't show restrict columns for children that are not directly inside the collection. */
       }
-      else if (tselem->type == 0 && te->idcode == ID_OB) {
+      else if ((tselem->type == TSE_SOME_ID) && (te->idcode == ID_OB)) {
         PointerRNA ptr;
         Object *ob = (Object *)tselem->id;
         RNA_id_pointer_create(&ob->id, &ptr);
@@ -1699,7 +1699,7 @@ static void outliner_draw_userbuts(uiBlock *block,
   LISTBASE_FOREACH (TreeElement *, te, lb) {
     TreeStoreElem *tselem = TREESTORE(te);
     if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) {
-      if (tselem->type == 0) {
+      if (tselem->type == TSE_SOME_ID) {
         uiBut *bt;
         ID *id = tselem->id;
         const char *tip = NULL;
@@ -1949,7 +1949,7 @@ static void outliner_draw_mode_column_toggle(uiBlock *block,
                                              TreeStoreElem *tselem,
                                              const bool lock_object_modes)
 {
-  if (tselem->type != 0 || te->idcode != ID_OB) {
+  if ((tselem->type != TSE_SOME_ID) || (te->idcode != ID_OB)) {
     return;
   }
 
@@ -2046,7 +2046,7 @@ TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te)
 {
   TreeElementIcon data = {0};
 
-  if (tselem->type) {
+  if (tselem->type != TSE_SOME_ID) {
     switch (tselem->type) {
       case TSE_ANIM_DATA:
         data.icon = ICON_ANIM_DATA; /* XXX */
@@ -2825,7 +2825,8 @@ int tree_element_id_type_to_index(TreeElement *te)
 {
   TreeStoreElem *tselem = TREESTORE(te);
 
-  const int id_index = tselem->type == 0 ? BKE_idtype_idcode_to_index(te->idcode) : INDEX_ID_GR;
+  const int id_index = (tselem->type == TSE_SOME_ID) ? BKE_idtype_idcode_to_index(te->idcode) :
+                                                       INDEX_ID_GR;
   if (id_index < INDEX_ID_OB) {
     return id_index;
   }
@@ -2862,9 +2863,9 @@ static void outliner_draw_iconrow(bContext *C,
     te->flag &= ~(TE_ICONROW | TE_ICONROW_MERGED);
 
     /* object hierarchy always, further constrained on level */
-    if (level < 1 || (tselem->type == 0 && te->idcode == ID_OB)) {
+    if ((level < 1) || ((tselem->type == TSE_SOME_ID) && (te->idcode == ID_OB))) {
       /* active blocks get white circle */
-      if (tselem->type == 0) {
+      if (tselem->type == TSE_SOME_ID) {
         if (te->idcode == ID_OB) {
           active = (tvc->obact == (Object *)tselem->id) ? OL_DRAWSEL_NORMAL : OL_DRAWSEL_NONE;
         }
@@ -2879,7 +2880,7 @@ static void outliner_draw_iconrow(bContext *C,
         active = tree_element_type_active_state_get(C, tvc, te, tselem);
       }
 
-      if (!ELEM(tselem->type, 0, TSE_LAYER_COLLECTION, TSE_R_LAYER, TSE_GP_LAYER)) {
+      if (!ELEM(tselem->type, TSE_SOME_ID, TSE_LAYER_COLLECTION, TSE_R_LAYER, TSE_GP_LAYER)) {
         outliner_draw_iconrow_doit(block, te, fstyle, xmax, offsx, ys, alpha_fac, active, 1);
       }
       else {
@@ -2954,7 +2955,7 @@ static bool element_should_draw_faded(const TreeViewContext *tvc,
                                       const TreeElement *te,
                                       const TreeStoreElem *tselem)
 {
-  if (tselem->type == 0) {
+  if (tselem->type == TSE_SOME_ID) {
     switch (te->idcode) {
       case ID_OB: {
         const Object *ob = (const Object *)tselem->id;
@@ -3023,7 +3024,7 @@ static void outliner_draw_tree_element(bContext *C,
     GPU_blend(GPU_BLEND_ALPHA);
 
     /* Colors for active/selected data. */
-    if (tselem->type == 0) {
+    if (tselem->type == TSE_SOME_ID) {
       if (te->idcode == ID_OB) {
         Object *ob = (Object *)tselem->id;
         Base *base = (te->directdata) ? (Base *)te->directdata :
@@ -3080,7 +3081,7 @@ static void outliner_draw_t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list