[Bf-blender-cvs] [5596f79821c] master: LibOverride: Massive edits to 'editable' IDs checks in editors code.

Bastien Montagne noreply at git.blender.org
Tue Mar 29 18:05:44 CEST 2022


Commit: 5596f79821caae3d4c1eb608ce77371904f74b80
Author: Bastien Montagne
Date:   Mon Mar 28 17:34:36 2022 +0200
Branches: master
https://developer.blender.org/rB5596f79821caae3d4c1eb608ce77371904f74b80

LibOverride: Massive edits to 'editable' IDs checks in editors code.

Add new `BKE_id_is_editable` helper in `BKE_lib_id.h`, that supercedes
previous check (simple `ID_IS_LINKED()` macro) for many editing cases.

This allows to also take into account 'system override' (aka
non-editable override) case.

Ref: {T95707}.

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

M	source/blender/blenkernel/BKE_lib_id.h
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/editors/animation/anim_channels_defines.c
M	source/blender/editors/animation/anim_channels_edit.c
M	source/blender/editors/animation/anim_filter.c
M	source/blender/editors/animation/keyframes_draw.c
M	source/blender/editors/armature/pose_edit.c
M	source/blender/editors/armature/pose_lib.c
M	source/blender/editors/armature/pose_lib_2.c
M	source/blender/editors/geometry/geometry_attributes.cc
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/interface/interface_eyedropper_depth.c
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/mesh/mesh_data.c
M	source/blender/editors/object/object_add.cc
M	source/blender/editors/object/object_data_transfer.c
M	source/blender/editors/object/object_edit.c
M	source/blender/editors/object/object_gpencil_modifier.c
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/object/object_relations.c
M	source/blender/editors/object/object_shader_fx.c
M	source/blender/editors/object/object_transform.cc
M	source/blender/editors/object/object_vgroup.c
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/physics/particle_object.c
M	source/blender/editors/physics/rigidbody_constraint.c
M	source/blender/editors/physics/rigidbody_object.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/sculpt_paint/paint_image.cc
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/sculpt_ops.c
M	source/blender/editors/space_outliner/outliner_collections.cc
M	source/blender/editors/space_outliner/outliner_dragdrop.cc
M	source/blender/editors/space_outliner/outliner_draw.cc
M	source/blender/editors/space_outliner/outliner_select.cc
M	source/blender/editors/space_text/text_ops.c
M	source/blender/editors/space_view3d/view3d_gizmo_camera.c
M	source/blender/editors/space_view3d/view3d_navigate_fly.c
M	source/blender/editors/space_view3d/view3d_navigate_walk.c
M	source/blender/editors/space_view3d/view3d_view.c
M	source/blender/editors/transform/transform_convert_object.c
M	source/blender/editors/transform/transform_convert_sculpt.c
M	source/blender/editors/util/ed_util.c
M	source/blender/editors/util/ed_util_ops.cc

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

diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h
index c3122758a72..b81c8ef136f 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -594,6 +594,16 @@ bool BKE_id_is_in_global_main(struct ID *id);
 
 bool BKE_id_can_be_asset(const struct ID *id);
 
+/** Check if that ID can be considered as editable from a high-level (editor) perspective.
+ *
+ * NOTE: This used to be done with a check on whether ID was linked or not, but now with system
+ * overrides this is not enough anymore.
+ *
+ * NOTE: Execution of this function can be somewhat expensive currently. If this becomes an issue,
+ * we should either cache that status info also in virtual override IDs, or address the
+ * long-standing TODO of geting an efficient 'owner_id' access for all embeded ID types. */
+bool BKE_id_is_editable(struct Main *bmain, struct ID *id);
+
 /**
  * Returns ordered list of data-blocks for display in the UI.
  * Result is list of #LinkData of IDs that must be freed.
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 28745f1d2c7..27427b1fb44 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -2165,6 +2165,11 @@ bool BKE_id_can_be_asset(const ID *id)
          BKE_idtype_idcode_is_linkable(GS(id->name));
 }
 
+bool BKE_id_is_editable(Main *bmain, ID *id)
+{
+  return !(ID_IS_LINKED(id) || BKE_lib_override_library_is_system_defined(bmain, id));
+}
+
 /************************* Datablock order in UI **************************/
 
 static int *id_order_get(ID *id)
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index 5169d6904f5..ed0befbcc24 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -5117,8 +5117,9 @@ static void draw_setting_widget(bAnimContext *ac,
           break;
       }
 
-      if ((ale->fcurve_owner_id != NULL && ID_IS_LINKED(ale->fcurve_owner_id)) ||
-          (ale->id != NULL && ID_IS_LINKED(ale->id))) {
+      if ((ale->fcurve_owner_id != NULL &&
+           (ID_IS_LINKED(ale->fcurve_owner_id) || ID_IS_OVERRIDE_LIBRARY(ale->fcurve_owner_id))) ||
+          (ale->id != NULL && (ID_IS_LINKED(ale->id) || ID_IS_OVERRIDE_LIBRARY(ale->id)))) {
         if (setting != ACHANNEL_SETTING_EXPAND) {
           UI_but_flag_enable(but, UI_BUT_DISABLED);
         }
diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c
index 08379be36fa..31d90c8bfec 100644
--- a/source/blender/editors/animation/anim_channels_edit.c
+++ b/source/blender/editors/animation/anim_channels_edit.c
@@ -2789,8 +2789,9 @@ static bool rename_anim_channels(bAnimContext *ac, int channel_index)
   }
 
   /* don't allow renaming linked channels */
-  if ((ale->fcurve_owner_id != NULL && ID_IS_LINKED(ale->fcurve_owner_id)) ||
-      (ale->id != NULL && ID_IS_LINKED(ale->id))) {
+  if ((ale->fcurve_owner_id != NULL &&
+       (ID_IS_LINKED(ale->fcurve_owner_id) || ID_IS_OVERRIDE_LIBRARY(ale->fcurve_owner_id))) ||
+      (ale->id != NULL && (ID_IS_LINKED(ale->id) || ID_IS_OVERRIDE_LIBRARY(ale->id)))) {
     ANIM_animdata_freelist(&anim_data);
     return false;
   }
diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c
index 0389e57627a..a75944fa2f2 100644
--- a/source/blender/editors/animation/anim_filter.c
+++ b/source/blender/editors/animation/anim_filter.c
@@ -1462,7 +1462,7 @@ static size_t animfilter_action(bAnimContext *ac,
   /* don't include anything from this action if it is linked in from another file,
    * and we're getting stuff for editing...
    */
-  if ((filter_mode & ANIMFILTER_FOREDIT) && ID_IS_LINKED(act)) {
+  if ((filter_mode & ANIMFILTER_FOREDIT) && (ID_IS_LINKED(act) || ID_IS_OVERRIDE_LIBRARY(act))) {
     return 0;
   }
 
diff --git a/source/blender/editors/animation/keyframes_draw.c b/source/blender/editors/animation/keyframes_draw.c
index f40c1b983d7..58d093c678d 100644
--- a/source/blender/editors/animation/keyframes_draw.c
+++ b/source/blender/editors/animation/keyframes_draw.c
@@ -659,7 +659,8 @@ void draw_fcurve_channel(AnimKeylistDrawList *draw_list,
 {
   const bool locked = (fcu->flag & FCURVE_PROTECTED) ||
                       ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) ||
-                      ((adt && adt->action) && ID_IS_LINKED(adt->action));
+                      ((adt && adt->action) &&
+                       (ID_IS_LINKED(adt->action) || ID_IS_OVERRIDE_LIBRARY(adt->action)));
 
   AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
       draw_list, ANIM_KEYLIST_FCURVE, ypos, yscale_fac, saction_flag);
@@ -676,7 +677,8 @@ void draw_agroup_channel(AnimKeylistDrawList *draw_list,
                          int saction_flag)
 {
   bool locked = (agrp->flag & AGRP_PROTECTED) ||
-                ((adt && adt->action) && ID_IS_LINKED(adt->action));
+                ((adt && adt->action) &&
+                 (ID_IS_LINKED(adt->action) || ID_IS_OVERRIDE_LIBRARY(adt->action)));
 
   AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
       draw_list, ANIM_KEYLIST_AGROUP, ypos, yscale_fac, saction_flag);
@@ -692,7 +694,7 @@ void draw_action_channel(AnimKeylistDrawList *draw_list,
                          float yscale_fac,
                          int saction_flag)
 {
-  const bool locked = (act && ID_IS_LINKED(act));
+  const bool locked = (act && (ID_IS_LINKED(act) || ID_IS_OVERRIDE_LIBRARY(act)));
   saction_flag &= ~SACTION_SHOW_EXTREMES;
 
   AnimKeylistDrawListElem *draw_elem = ed_keylist_draw_list_add_elem(
diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c
index 90ee7c83436..2ad7a373012 100644
--- a/source/blender/editors/armature/pose_edit.c
+++ b/source/blender/editors/armature/pose_edit.c
@@ -23,6 +23,7 @@
 #include "BKE_deform.h"
 #include "BKE_global.h"
 #include "BKE_layer.h"
+#include "BKE_lib_id.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
 #include "BKE_report.h"
@@ -78,7 +79,7 @@ Object *ED_pose_object_from_context(bContext *C)
 
 bool ED_object_posemode_enter_ex(struct Main *bmain, Object *ob)
 {
-  BLI_assert(!ID_IS_LINKED(ob));
+  BLI_assert(BKE_id_is_editable(bmain, &ob->id));
   bool ok = false;
 
   switch (ob->type) {
@@ -99,11 +100,11 @@ bool ED_object_posemode_enter_ex(struct Main *bmain, Object *ob)
 bool ED_object_posemode_enter(bContext *C, Object *ob)
 {
   ReportList *reports = CTX_wm_reports(C);
-  if (ID_IS_LINKED(ob)) {
+  struct Main *bmain = CTX_data_main(C);
+  if (!BKE_id_is_editable(bmain, &ob->id)) {
     BKE_report(reports, RPT_WARNING, "Cannot pose libdata");
     return false;
   }
-  struct Main *bmain = CTX_data_main(C);
   bool ok = ED_object_posemode_enter_ex(bmain, ob);
   if (ok) {
     WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_POSE, NULL);
diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c
index 9796f6771d2..4b3ece64bf9 100644
--- a/source/blender/editors/armature/pose_lib.c
+++ b/source/blender/editors/armature/pose_lib.c
@@ -170,7 +170,7 @@ static bool has_poselib_pose_data_poll(bContext *C)
 static bool has_poselib_pose_data_for_editing_poll(bContext *C)
 {
   Object *ob = get_poselib_object(C);
-  return (ob && ob->poselib && !ID_IS_LINKED(ob->poselib));
+  return (ob && ob->poselib && BKE_id_is_editable(CTX_data_main(C), &ob->poselib->id));
 }
 
 /* ----------------------------------- */
@@ -377,7 +377,7 @@ static bool poselib_add_poll(bContext *C)
   if (ED_operator_posemode(C)) {
     Object *ob = get_poselib_object(C);
     if (ob) {
-      if ((ob->poselib == NULL) || !ID_IS_LINKED(ob->poselib)) {
+      if ((ob->poselib == NULL) || BKE_id_is_editable(CTX_data_main(C), &ob->poselib->id)) {
         return true;
       }
     }
diff --git a/source/blender/editors/armature/pose_lib_2.c b/source/blender/editors/armature/pose_lib_2.c
index ced99f16794..9ee289145c4 100644
--- a/source/blender/editors/armature/pose_lib_2.c
+++ b/source/blender/editors/armature/pose_lib_2.c
@@ -103,7 +103,8 @@ static void poselib_keytag_pose(bContext *C, Scene *scene, PoseBlendData *pbd)
   }
 
   AnimData *adt = BKE_animdata_from_id(&pbd->ob->id);
-  if (adt != NULL && adt->action != NULL && ID_IS_LINKED(&adt->action->id)) {
+  if (adt != NULL && adt->action != NULL &&
+      !BKE_id_is_editable(CTX_data_main(C), &adt->action->id)) {
     /* Changes to linked-in Actions are not allowed. */
     return;
   }
diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc
index 6225a68f53c..5d9d02db660 100644
--- a/source/blender/editors/geometry/geometry_attributes.cc
+++ b/source/blender/editors/geometry/geometry_attributes.cc
@@ -15,6 +15,7 @@
 #include "BKE_context.h"
 #include "BKE_deform.h"
 #include "BKE_geometry_set.hh"
+#include "BKE_lib_id.h"
 #include "BKE_object_deform.h"
 #include "BKE_report.h"
 
@@ -41,8 +42,9 @@ namespace blender::ed::geometry {
 static bool geometry_attributes_poll(bContext *C)
 {
   Object *ob = ED_object_context(C);
+  Main *bmain = CTX_data_main(C);
   ID *data = (ob) ? static_cast<ID *>(ob->data) : nullptr;
-  return (ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data)) &&
+  return (ob && BKE_id_is_editable(bmain, &ob->id) && data && BKE_id_is_editable(bmain, data)) &&
          BKE_id_attributes_supported(data);
 }
 
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 338a7c8a51d..6843c42d2d0 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -2195,8 +2195,9 @@ static bool gpencil_vertex_group_poll(bContext *C)
   Object *ob = CTX_data_active_object(C);
 
   if ((ob) && (ob->type == OB_GPENCIL)) {
+    Main *bmain = CTX_data_main(C);
     const bGPdata *gpd = (const bGPdata *)ob->data;
-    if (!ID_IS_LINKED(ob) && !ID_IS_LINKED(ob->data) &&
+    if (BKE_id_is_editabl

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list